Modified pin driver and some format
This commit is contained in:
parent
c19fb2ab58
commit
19fcea5229
|
@ -1,22 +1,27 @@
|
|||
/*
|
||||
* File : application.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2015, RT-Thread Development Team
|
||||
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017-09-14 Haley the first version
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup APOLLO2
|
||||
*/
|
||||
/*@{*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <stdint.h>
|
||||
#ifdef RT_USING_FINSH
|
||||
|
@ -24,9 +29,8 @@
|
|||
#include <shell.h>
|
||||
#endif
|
||||
|
||||
#include "hw_led.h"
|
||||
#include "led.h"
|
||||
|
||||
ALIGN(RT_ALIGN_SIZE)
|
||||
static rt_uint8_t led_stack[ 512 ];
|
||||
static struct rt_thread led_thread;
|
||||
|
||||
|
@ -34,9 +38,6 @@ static void led_thread_entry(void* parameter)
|
|||
{
|
||||
unsigned int count=0;
|
||||
|
||||
rt_hw_led_init(0);
|
||||
rt_hw_led_init(1);
|
||||
|
||||
while (1)
|
||||
{
|
||||
/* led1 on */
|
||||
|
@ -56,18 +57,8 @@ static void led_thread_entry(void* parameter)
|
|||
}
|
||||
}
|
||||
|
||||
void rt_init_thread_entry(void* parameter)
|
||||
int main(void)
|
||||
{
|
||||
#ifdef RT_USING_COMPONENTS_INIT
|
||||
/* initialization RT-Thread Components */
|
||||
rt_components_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
int rt_application_init(void)
|
||||
{
|
||||
rt_thread_t init_thread;
|
||||
|
||||
rt_err_t result;
|
||||
|
||||
/* init led thread */
|
||||
|
@ -77,18 +68,13 @@ int rt_application_init(void)
|
|||
RT_NULL,
|
||||
(rt_uint8_t*)&led_stack[0],
|
||||
sizeof(led_stack),
|
||||
7,
|
||||
RT_THREAD_PRIORITY_MAX/3,
|
||||
5);
|
||||
if (result == RT_EOK)
|
||||
{
|
||||
rt_thread_startup(&led_thread);
|
||||
}
|
||||
|
||||
init_thread = rt_thread_create("init", rt_init_thread_entry, RT_NULL, 1024,
|
||||
RT_THREAD_PRIORITY_MAX / 3, 20);
|
||||
if (init_thread != RT_NULL)
|
||||
rt_thread_startup(init_thread);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,93 +0,0 @@
|
|||
/*
|
||||
* File : startup.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2015, RT-Thread Develop Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://openlab.rt-thread.com/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017-09-11 Haley the first version
|
||||
*/
|
||||
|
||||
#include <rthw.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
#include "board.h"
|
||||
|
||||
/**
|
||||
* @addtogroup Apollo2
|
||||
*/
|
||||
|
||||
/*@{*/
|
||||
|
||||
extern int rt_application_init(void);
|
||||
|
||||
#ifdef __CC_ARM
|
||||
extern int Image$$RW_IRAM1$$ZI$$Limit;
|
||||
#define AM_SRAM_BEGIN (&Image$$RW_IRAM1$$ZI$$Limit)
|
||||
#elif __ICCARM__
|
||||
#pragma section="HEAP"
|
||||
#define AM_SRAM_BEGIN (__segment_end("HEAP"))
|
||||
#else
|
||||
extern int __bss_end;
|
||||
#define NRF_SRAM_BEGIN (&__bss_end)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function will startup RT-Thread RTOS.
|
||||
*/
|
||||
void rtthread_startup(void)
|
||||
{
|
||||
/* init board */
|
||||
rt_hw_board_init();
|
||||
|
||||
/* show version */
|
||||
rt_show_version();
|
||||
|
||||
/* init tick */
|
||||
rt_system_tick_init();
|
||||
|
||||
/* init kernel object */
|
||||
rt_system_object_init();
|
||||
|
||||
/* init timer system */
|
||||
rt_system_timer_init();
|
||||
|
||||
#ifdef RT_USING_HEAP
|
||||
rt_system_heap_init((void*)AM_SRAM_BEGIN, (void*)AM_SRAM_END);
|
||||
#endif
|
||||
|
||||
/* init scheduler system */
|
||||
rt_system_scheduler_init();
|
||||
|
||||
/* init application */
|
||||
rt_application_init();
|
||||
|
||||
/* init timer thread */
|
||||
rt_system_timer_thread_init();
|
||||
|
||||
/* init idle thread */
|
||||
rt_thread_idle_init();
|
||||
|
||||
/* start scheduler */
|
||||
rt_system_scheduler_start();
|
||||
|
||||
/* never reach here */
|
||||
return ;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
/* disable interrupt first */
|
||||
// rt_hw_interrupt_disable();
|
||||
|
||||
/* startup RT-Thread RTOS */
|
||||
rtthread_startup();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*@}*/
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* File : gpio.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017-09-16 Haley the first version
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
#include "am_mcu_apollo.h"
|
||||
|
||||
#ifdef RT_USING_PIN
|
||||
|
||||
void am_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode)
|
||||
{
|
||||
if (mode == PIN_MODE_OUTPUT)
|
||||
{
|
||||
/* output setting */
|
||||
am_hal_gpio_pin_config(pin, AM_HAL_GPIO_OUTPUT);
|
||||
}
|
||||
else if (mode == PIN_MODE_INPUT)
|
||||
{
|
||||
/* input setting: not pull. */
|
||||
am_hal_gpio_pin_config(pin, AM_HAL_GPIO_INPUT);
|
||||
}
|
||||
else if (mode == PIN_MODE_INPUT_PULLUP)
|
||||
{
|
||||
/* input setting: pull up. */
|
||||
am_hal_gpio_pin_config(pin, AM_HAL_GPIO_OPENDRAIN);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* input setting:default. */
|
||||
am_hal_gpio_pin_config(pin, AM_HAL_GPIO_INPUT);
|
||||
}
|
||||
}
|
||||
|
||||
void am_pin_write(rt_device_t dev, rt_base_t pin, rt_base_t value)
|
||||
{
|
||||
if (value == PIN_LOW)
|
||||
{
|
||||
am_hal_gpio_out_bit_clear(pin);
|
||||
}
|
||||
else
|
||||
{
|
||||
am_hal_gpio_out_bit_set(pin);
|
||||
}
|
||||
}
|
||||
|
||||
int am_pin_read(rt_device_t dev, rt_base_t pin)
|
||||
{
|
||||
int value = PIN_LOW;
|
||||
|
||||
if (am_hal_gpio_input_bit_read(pin) == 0)
|
||||
{
|
||||
value = PIN_LOW;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = PIN_HIGH;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
const static struct rt_pin_ops _am_pin_ops =
|
||||
{
|
||||
am_pin_mode,
|
||||
am_pin_write,
|
||||
am_pin_read,
|
||||
};
|
||||
|
||||
int hw_pin_init(void)
|
||||
{
|
||||
rt_device_pin_register("pin", &_am_pin_ops, RT_NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
INIT_BOARD_EXPORT(hw_pin_init);
|
||||
#endif
|
||||
|
||||
/*@}*/
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* File : gpio.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017-09-16 Haley the first version
|
||||
*/
|
||||
|
||||
#ifndef __GPIO_H
|
||||
#define __GPIO_H
|
||||
|
||||
int hw_pin_init(void);
|
||||
|
||||
#endif // __GPIO_H
|
|
@ -1,302 +0,0 @@
|
|||
/*
|
||||
* File : hw_led.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2017, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017-09-14 Haley the first version
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include "am_mcu_apollo.h"
|
||||
#include "hw_led.h"
|
||||
|
||||
#define AM_GPIO_LED0 46
|
||||
#define AM_GPIO_LED1 47
|
||||
#define AM_GPIO_LED2 48
|
||||
#define AM_GPIO_LED3 49
|
||||
|
||||
#define AM_NUM_LEDS 4
|
||||
|
||||
rt_hw_led_t am_psLEDs[AM_NUM_LEDS] =
|
||||
{
|
||||
{AM_GPIO_LED0, AM_LED_ON_LOW | AM_LED_POL_DIRECT_DRIVE_M},
|
||||
{AM_GPIO_LED1, AM_LED_ON_LOW | AM_LED_POL_DIRECT_DRIVE_M},
|
||||
{AM_GPIO_LED2, AM_LED_ON_LOW | AM_LED_POL_DIRECT_DRIVE_M},
|
||||
{AM_GPIO_LED3, AM_LED_ON_LOW | AM_LED_POL_DIRECT_DRIVE_M},
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Configures the necessary pins for an array of LEDs
|
||||
*
|
||||
* @param LEDNum is the LED number.
|
||||
*
|
||||
* This function configures a GPIO to drive an LED in a low-power way.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void rt_hw_led_init(rt_uint32_t LEDNum)
|
||||
{
|
||||
rt_hw_led_t *psLED = am_psLEDs + LEDNum;
|
||||
|
||||
/* Handle Direct Drive Versus 3-State (with pull-up or no buffer) */
|
||||
if ( AM_LED_POL_DIRECT_DRIVE_M & psLED->Polarity )
|
||||
{
|
||||
/* Configure the pin as a push-pull GPIO output */
|
||||
am_hal_gpio_pin_config(psLED->GPIONumber, AM_HAL_GPIO_OUTPUT);
|
||||
|
||||
/* Enable the output driver, and set the output value to the LEDs "ON" state */
|
||||
am_hal_gpio_out_enable_bit_set(psLED->GPIONumber);
|
||||
am_hal_gpio_out_bit_replace(psLED->GPIONumber,
|
||||
psLED->Polarity &
|
||||
AM_LED_POL_DIRECT_DRIVE_M);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Configure the pin as a tri-state GPIO */
|
||||
am_hal_gpio_pin_config(psLED->GPIONumber, AM_HAL_GPIO_3STATE);
|
||||
|
||||
/* Disable the output driver, and set the output value to the LEDs "ON" state */
|
||||
am_hal_gpio_out_enable_bit_clear(psLED->GPIONumber);
|
||||
am_hal_gpio_out_bit_replace(psLED->GPIONumber,
|
||||
psLED->Polarity &
|
||||
AM_LED_POL_DIRECT_DRIVE_M );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures the necessary pins for an array of LEDs
|
||||
*
|
||||
* @param NumLEDs is the total number of LEDs in the array.
|
||||
*
|
||||
* This function configures the GPIOs for an array of LEDs.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void rt_hw_led_array_init(rt_uint32_t NumLEDs)
|
||||
{
|
||||
/* Loop through the list of LEDs, configuring each one individually */
|
||||
for ( int i = 0; i < NumLEDs; i++ )
|
||||
{
|
||||
rt_hw_led_init(i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disables an array of LEDs
|
||||
*
|
||||
* @param NumLEDs is the total number of LEDs in the array.
|
||||
*
|
||||
* This function disables the GPIOs for an array of LEDs.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void rt_hw_led_array_disable(rt_uint32_t NumLEDs)
|
||||
{
|
||||
rt_hw_led_t *psLEDs = am_psLEDs;
|
||||
|
||||
/* Loop through the list of LEDs, configuring each one individually */
|
||||
for ( int i = 0; i < NumLEDs; i++ )
|
||||
{
|
||||
am_hal_gpio_pin_config((psLEDs + i)->GPIONumber, AM_HAL_GPIO_DISABLE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Turns on the requested LED.
|
||||
*
|
||||
* @param LEDNum is the LED number for the light to turn on.
|
||||
*
|
||||
* This function turns on a single LED.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void rt_hw_led_on(rt_uint32_t LEDNum)
|
||||
{
|
||||
rt_hw_led_t *psLEDs = am_psLEDs;
|
||||
|
||||
/* Handle Direct Drive Versus 3-State (with pull-up or no buffer) */
|
||||
if ( AM_LED_POL_DIRECT_DRIVE_M & psLEDs[LEDNum].Polarity )
|
||||
{
|
||||
/* Set the output to the correct state for the LED */
|
||||
am_hal_gpio_out_bit_replace(psLEDs[LEDNum].GPIONumber,
|
||||
psLEDs[LEDNum].Polarity &
|
||||
AM_LED_POL_POLARITY_M );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Turn on the output driver for the LED */
|
||||
am_hal_gpio_out_enable_bit_set(psLEDs[LEDNum].GPIONumber);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Turns off the requested LED.
|
||||
*
|
||||
* @param LEDNum is the LED number for the light to turn off.
|
||||
*
|
||||
* This function turns off a single LED.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void rt_hw_led_off(rt_uint32_t LEDNum)
|
||||
{
|
||||
rt_hw_led_t *psLEDs = am_psLEDs;
|
||||
|
||||
/* Handle Direct Drive Versus 3-State (with pull-up or no buffer) */
|
||||
if ( AM_LED_POL_DIRECT_DRIVE_M & psLEDs[LEDNum].Polarity )
|
||||
{
|
||||
/* Set the output to the correct state for the LED */
|
||||
am_hal_gpio_out_bit_replace(psLEDs[LEDNum].GPIONumber,
|
||||
!(psLEDs[LEDNum].Polarity &
|
||||
AM_LED_POL_POLARITY_M) );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Turn off the output driver for the LED */
|
||||
am_hal_gpio_out_enable_bit_clear(psLEDs[LEDNum].GPIONumber);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Toggles the requested LED.
|
||||
*
|
||||
* @param LEDNum is the LED number for the light to toggle.
|
||||
*
|
||||
* This function toggles a single LED.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void rt_hw_led_toggle(rt_uint32_t LEDNum)
|
||||
{
|
||||
rt_hw_led_t *psLEDs = am_psLEDs;
|
||||
|
||||
/* Handle Direct Drive Versus 3-State (with pull-up or no buffer) */
|
||||
if ( AM_LED_POL_DIRECT_DRIVE_M & psLEDs[LEDNum].Polarity )
|
||||
{
|
||||
am_hal_gpio_out_bit_toggle(psLEDs[LEDNum].GPIONumber);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Check to see if the LED pin is enabled */
|
||||
if ( am_hal_gpio_out_enable_bit_get(psLEDs[LEDNum].GPIONumber) )
|
||||
{
|
||||
/* If it was enabled, turn if off */
|
||||
am_hal_gpio_out_enable_bit_clear(psLEDs[LEDNum].GPIONumber);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If it was not enabled, turn if on */
|
||||
am_hal_gpio_out_enable_bit_set(psLEDs[LEDNum].GPIONumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the state of the requested LED.
|
||||
*
|
||||
* @param LEDNum is the LED to check.
|
||||
*
|
||||
* This function checks the state of a single LED.
|
||||
*
|
||||
* @return 1(true) if the LED is on.
|
||||
*/
|
||||
int rt_hw_led_get(rt_uint32_t LEDNum)
|
||||
{
|
||||
rt_hw_led_t *psLEDs = am_psLEDs;
|
||||
|
||||
/* Handle Direct Drive Versus 3-State (with pull-up or no buffer) */
|
||||
if ( AM_LED_POL_DIRECT_DRIVE_M & psLEDs[LEDNum].Polarity )
|
||||
{
|
||||
/* Mask to the GPIO bit position for this GPIO number */
|
||||
uint64_t ui64Mask = 0x01l << psLEDs[LEDNum].GPIONumber;
|
||||
|
||||
/* Extract the state of this bit and return it */
|
||||
return !!(am_hal_gpio_input_read() & ui64Mask);
|
||||
}
|
||||
else
|
||||
{
|
||||
return am_hal_gpio_out_enable_bit_get(
|
||||
psLEDs[LEDNum].GPIONumber);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Display a binary value using LEDs.
|
||||
*
|
||||
* @param NumLEDs is the number of LEDs in the array.
|
||||
* @param Value is the value to display on the LEDs.
|
||||
*
|
||||
* This function displays a value in binary across an array of LEDs.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void rt_hw_led_array_out(rt_uint32_t NumLEDs, rt_uint32_t Value)
|
||||
{
|
||||
for ( int i = 0; i < NumLEDs; i++ )
|
||||
{
|
||||
if ( Value & (1 << i) )
|
||||
{
|
||||
rt_hw_led_on(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_hw_led_off(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef RT_USING_FINSH
|
||||
#include <finsh.h>
|
||||
static rt_uint8_t led_inited = 0;
|
||||
void led(rt_uint32_t led, rt_uint32_t value)
|
||||
{
|
||||
/* init led configuration if it's not inited. */
|
||||
if (!led_inited)
|
||||
{
|
||||
// rt_hw_led_init(0);
|
||||
// rt_hw_led_init(1);
|
||||
led_inited = 1;
|
||||
}
|
||||
|
||||
if ( led == 0 )
|
||||
{
|
||||
/* set led status */
|
||||
switch (value)
|
||||
{
|
||||
case 0:
|
||||
rt_hw_led_off(0);
|
||||
break;
|
||||
case 1:
|
||||
rt_hw_led_on(0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( led == 1 )
|
||||
{
|
||||
/* set led status */
|
||||
switch (value)
|
||||
{
|
||||
case 0:
|
||||
rt_hw_led_off(1);
|
||||
break;
|
||||
case 1:
|
||||
rt_hw_led_on(1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
FINSH_FUNCTION_EXPORT(led, set led[0 - 1] on[1] or off[0].)
|
||||
#endif
|
||||
|
||||
/*@}*/
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* File : hw_led.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2017, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017-09-14 Haley the first version
|
||||
*/
|
||||
|
||||
#ifndef __HW_LED_H
|
||||
#define __HW_LED_H
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
/**
|
||||
* @brief LED polarity macros
|
||||
*
|
||||
*/
|
||||
#define AM_LED_POL_POLARITY_M 0x1
|
||||
#define AM_LED_ON_HIGH 0x1
|
||||
#define AM_LED_ON_LOW 0x0
|
||||
|
||||
/**
|
||||
* @brief LED direct drive indicator macro
|
||||
* Or this in with the polarity value to use the GPIO DATA register instead of
|
||||
* the GPIO DATA ENABLE register to directly drive an LED buffer.
|
||||
*/
|
||||
#define AM_LED_POL_DIRECT_DRIVE_M 0x2
|
||||
|
||||
|
||||
/**
|
||||
* @brief Structure for keeping track of LEDs
|
||||
*
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
rt_uint32_t GPIONumber;
|
||||
rt_uint32_t Polarity;
|
||||
}
|
||||
rt_hw_led_t;
|
||||
|
||||
/**
|
||||
* @brief External function definitions
|
||||
*
|
||||
*/
|
||||
void rt_hw_led_init(rt_uint32_t LEDNum);
|
||||
void rt_hw_led_array_init(rt_uint32_t NumLEDs);
|
||||
void rt_hw_led_array_disable(rt_uint32_t NumLEDs);
|
||||
void rt_hw_led_on(rt_uint32_t LEDNum);
|
||||
void rt_hw_led_off(rt_uint32_t LEDNum);
|
||||
void rt_hw_led_toggle(rt_uint32_t LEDNum);
|
||||
int rt_hw_led_get(rt_uint32_t LEDNum);
|
||||
void rt_hw_led_array_out(rt_uint32_t NumLEDs, rt_uint32_t Value);
|
||||
|
||||
#endif // __HW_LED_H
|
|
@ -1,23 +0,0 @@
|
|||
/*
|
||||
* File : hw_uart.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2017, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017-09-14 Haley the first version
|
||||
*/
|
||||
|
||||
#ifndef __HW_UART_H_
|
||||
#define __HW_UART_H_
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
void rt_hw_uart_init(void);
|
||||
void rt_hw_uart_send_string(char *pcString);
|
||||
|
||||
#endif // __HW_UART_H_
|
|
@ -0,0 +1,152 @@
|
|||
/*
|
||||
* File :_led.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017-09-14 Haley the first version
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
#include "am_mcu_apollo.h"
|
||||
#include "board.h"
|
||||
|
||||
#define AM_GPIO_LED0 46
|
||||
#define AM_GPIO_LED1 47
|
||||
#define AM_GPIO_LED2 48
|
||||
#define AM_GPIO_LED3 49
|
||||
|
||||
/**
|
||||
* @brief Turns on the requested LED.
|
||||
*
|
||||
* @param LEDNum is the LED number for the light to turn on.
|
||||
*
|
||||
* This function turns on a single LED.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void rt_hw_led_on(rt_uint8_t LEDNum)
|
||||
{
|
||||
if(LEDNum == 0)
|
||||
rt_pin_write(AM_GPIO_LED0, PIN_LOW);
|
||||
|
||||
else if(LEDNum == 1)
|
||||
rt_pin_write(AM_GPIO_LED1, PIN_LOW);
|
||||
|
||||
else if(LEDNum == 2)
|
||||
rt_pin_write(AM_GPIO_LED2, PIN_LOW);
|
||||
|
||||
else if(LEDNum == 3)
|
||||
rt_pin_write(AM_GPIO_LED3, PIN_LOW);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Turns off the requested LED.
|
||||
*
|
||||
* @param LEDNum is the LED number for the light to turn off.
|
||||
*
|
||||
* This function turns off a single LED.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void rt_hw_led_off(rt_uint8_t LEDNum)
|
||||
{
|
||||
if(LEDNum == 0)
|
||||
rt_pin_write(AM_GPIO_LED0, PIN_HIGH);
|
||||
|
||||
else if(LEDNum == 1)
|
||||
rt_pin_write(AM_GPIO_LED1, PIN_HIGH);
|
||||
|
||||
else if(LEDNum == 2)
|
||||
rt_pin_write(AM_GPIO_LED2, PIN_HIGH);
|
||||
|
||||
else if(LEDNum == 3)
|
||||
rt_pin_write(AM_GPIO_LED3, PIN_HIGH);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures the necessary pins for an array of LEDs
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* This function configures a GPIO to drive an LED in a low-power way.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
int rt_hw_led_init(void)
|
||||
{
|
||||
#if defined(RT_USING_LED0)
|
||||
/* config led */
|
||||
rt_pin_mode(AM_GPIO_LED0, PIN_MODE_OUTPUT);
|
||||
|
||||
/* turns off the led */
|
||||
rt_hw_led_off(0);
|
||||
#endif /* RT_USING_LED0 */
|
||||
|
||||
#if defined(RT_USING_LED1)
|
||||
/* config led */
|
||||
rt_pin_mode(AM_GPIO_LED1, PIN_MODE_OUTPUT);
|
||||
|
||||
/* turns off the led */
|
||||
rt_hw_led_off(1);
|
||||
#endif /* RT_USING_LED1 */
|
||||
|
||||
#if defined(RT_USING_LED2)
|
||||
/* config led */
|
||||
rt_pin_mode(AM_GPIO_LED2, PIN_MODE_OUTPUT);
|
||||
|
||||
/* turns off the led */
|
||||
rt_hw_led_off(2);
|
||||
#endif /* RT_USING_LED0 */
|
||||
|
||||
#if defined(RT_USING_LED3)
|
||||
/* config led */
|
||||
rt_pin_mode(AM_GPIO_LED3, PIN_MODE_OUTPUT);
|
||||
|
||||
/* turns off the led */
|
||||
rt_hw_led_off(3);
|
||||
#endif /* RT_USING_LED1 */
|
||||
|
||||
return 0;
|
||||
}
|
||||
#ifdef RT_USING_PIN
|
||||
INIT_BOARD_EXPORT(rt_hw_led_init);
|
||||
#endif
|
||||
|
||||
#ifdef RT_USING_FINSH
|
||||
#include <finsh.h>
|
||||
void led(rt_uint32_t led, rt_uint32_t state)
|
||||
{
|
||||
/* set led status */
|
||||
switch (state)
|
||||
{
|
||||
case 0:
|
||||
rt_hw_led_off(led);
|
||||
break;
|
||||
case 1:
|
||||
rt_hw_led_on(led);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
FINSH_FUNCTION_EXPORT(led, turn led (0 - 3) on (1) or off (0).)
|
||||
#endif
|
||||
|
||||
/*@}*/
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* File : led.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017-09-14 Haley the first version
|
||||
*/
|
||||
|
||||
#ifndef __HW_LED_H
|
||||
#define __HW_LED_H
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
/**
|
||||
* @brief External function definitions
|
||||
*
|
||||
*/
|
||||
void rt_hw_led_init(void);
|
||||
void rt_hw_led_on(rt_uint8_t LEDNum);
|
||||
void rt_hw_led_off(rt_uint8_t LEDNum);
|
||||
|
||||
#endif // __HW_LED_H
|
|
@ -1,21 +1,30 @@
|
|||
/*
|
||||
* File : hw_uart.c
|
||||
* File : uart.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2017, RT-Thread Development Team
|
||||
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017-09-15 Haley the first version
|
||||
*/
|
||||
|
||||
#include "am_mcu_apollo.h"
|
||||
#include "hw_uart.h"
|
||||
#include "board.h"
|
||||
#include <rtdevice.h>
|
||||
#include "am_mcu_apollo.h"
|
||||
#include "board.h"
|
||||
|
||||
/* USART0 */
|
||||
#define AM_UART0_INST 0
|
||||
|
@ -220,7 +229,7 @@ static int am_getc(struct rt_serial_device *serial)
|
|||
RT_ASSERT(uart != RT_NULL);
|
||||
|
||||
ch = -1;
|
||||
if (am_hal_uart_flags_get(uart->uart_device) & AM_HAL_UART_FR_RX_FULL)
|
||||
if ((am_hal_uart_flags_get(uart->uart_device) & AM_HAL_UART_FR_RX_EMPTY) == 0)
|
||||
{
|
||||
am_hal_uart_char_receive_polled(uart->uart_device, &c);
|
||||
ch = c & 0xff;
|
||||
|
@ -253,7 +262,7 @@ static void uart_isr(struct rt_serial_device *serial)
|
|||
|
||||
if (status & (AM_HAL_UART_INT_RX_TMOUT))
|
||||
{
|
||||
rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_TIMEOUT);
|
||||
rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_IND);
|
||||
}
|
||||
|
||||
if (status & AM_HAL_UART_INT_RX)
|
||||
|
@ -263,7 +272,7 @@ static void uart_isr(struct rt_serial_device *serial)
|
|||
|
||||
if (status & AM_HAL_UART_INT_TX)
|
||||
{
|
||||
//rt_hw_serial_isr(serial, RT_SERIAL_EVENT_TX_DONE);
|
||||
// rt_hw_serial_isr(serial, RT_SERIAL_EVENT_TX_DONE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -350,17 +359,16 @@ static void RCC_Configuration(struct am_uart* uart)
|
|||
am_hal_uart_enable(uart->uart_device);
|
||||
|
||||
/* Enable the UART FIFO */
|
||||
//am_hal_uart_fifo_config(uart->uart_device, AM_HAL_UART_TX_FIFO_1_2 | AM_HAL_UART_RX_FIFO_1_2);
|
||||
am_hal_uart_fifo_config(uart->uart_device, AM_HAL_UART_TX_FIFO_1_2 | AM_HAL_UART_RX_FIFO_1_2);
|
||||
}
|
||||
|
||||
static void NVIC_Configuration(struct am_uart* uart)
|
||||
{
|
||||
/* Enable interrupts */
|
||||
am_hal_uart_int_enable(uart->uart_device, AM_HAL_UART_INT_RX);
|
||||
am_hal_uart_int_enable(uart->uart_device, AM_HAL_UART_INT_RX_TMOUT | AM_HAL_UART_INT_RX);
|
||||
|
||||
/* Enable the uart interrupt in the NVIC */
|
||||
am_hal_interrupt_enable(uart->uart_interrupt);
|
||||
am_hal_uart_int_clear(uart->uart_device, 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
/**
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* File : uart.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017-09-14 Haley the first version
|
||||
*/
|
||||
|
||||
#ifndef __UART_H_
|
||||
#define __UART_H_
|
||||
|
||||
void rt_hw_uart_init(void);
|
||||
|
||||
#endif // __UART_H_
|
Loading…
Reference in New Issue