rt-thread/bsp/apollo2/board/led.c

147 lines
2.8 KiB
C
Raw Normal View History

2017-09-18 17:45:46 +08:00
/*
2021-03-29 07:20:47 +08:00
* Copyright (c) 2006-2021, RT-Thread Development Team
2017-09-18 17:45:46 +08:00
*
2021-03-29 07:20:47 +08:00
* SPDX-License-Identifier: Apache-2.0
2017-09-18 17:45:46 +08:00
*
* Change Logs:
* Date Author Notes
* 2017-09-14 Haley the first version
*/
#include <rtthread.h>
#include <rtdevice.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)
{
2017-09-20 11:14:45 +08:00
#ifdef RT_USING_PIN
2017-09-18 17:45:46 +08:00
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);
2017-09-20 11:14:45 +08:00
#endif
2017-09-18 17:45:46 +08:00
}
/**
* @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)
{
2017-09-20 11:14:45 +08:00
#ifdef RT_USING_PIN
2017-09-18 17:45:46 +08:00
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);
2017-09-20 11:14:45 +08:00
#endif
2017-09-18 17:45:46 +08:00
}
/**
* @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)
{
2017-09-20 11:14:45 +08:00
#ifdef RT_USING_PIN
2017-09-18 17:45:46 +08:00
#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 */
2017-09-20 11:14:45 +08:00
#endif
rt_kprintf("led_init!\n");
2017-09-18 17:45:46 +08:00
return 0;
}
2017-09-20 11:14:45 +08:00
#ifdef RT_USING_COMPONENTS_INIT
INIT_DEVICE_EXPORT(rt_hw_led_init);
2017-09-18 17:45:46 +08:00
#endif
#ifdef RT_USING_FINSH
#include <finsh.h>
2017-09-18 17:45:46 +08:00
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
/*@}*/