led.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * File :_led.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2017-09-14 Haley the first version
  23. */
  24. #include <rtthread.h>
  25. #include <rtdevice.h>
  26. #include "am_mcu_apollo.h"
  27. #include "board.h"
  28. #define AM_GPIO_LED0 46
  29. #define AM_GPIO_LED1 47
  30. #define AM_GPIO_LED2 48
  31. #define AM_GPIO_LED3 49
  32. /**
  33. * @brief Turns on the requested LED.
  34. *
  35. * @param LEDNum is the LED number for the light to turn on.
  36. *
  37. * This function turns on a single LED.
  38. *
  39. * @return None.
  40. */
  41. void rt_hw_led_on(rt_uint8_t LEDNum)
  42. {
  43. #ifdef RT_USING_PIN
  44. if(LEDNum == 0)
  45. rt_pin_write(AM_GPIO_LED0, PIN_LOW);
  46. else if(LEDNum == 1)
  47. rt_pin_write(AM_GPIO_LED1, PIN_LOW);
  48. else if(LEDNum == 2)
  49. rt_pin_write(AM_GPIO_LED2, PIN_LOW);
  50. else if(LEDNum == 3)
  51. rt_pin_write(AM_GPIO_LED3, PIN_LOW);
  52. #endif
  53. }
  54. /**
  55. * @brief Turns off the requested LED.
  56. *
  57. * @param LEDNum is the LED number for the light to turn off.
  58. *
  59. * This function turns off a single LED.
  60. *
  61. * @return None.
  62. */
  63. void rt_hw_led_off(rt_uint8_t LEDNum)
  64. {
  65. #ifdef RT_USING_PIN
  66. if(LEDNum == 0)
  67. rt_pin_write(AM_GPIO_LED0, PIN_HIGH);
  68. else if(LEDNum == 1)
  69. rt_pin_write(AM_GPIO_LED1, PIN_HIGH);
  70. else if(LEDNum == 2)
  71. rt_pin_write(AM_GPIO_LED2, PIN_HIGH);
  72. else if(LEDNum == 3)
  73. rt_pin_write(AM_GPIO_LED3, PIN_HIGH);
  74. #endif
  75. }
  76. /**
  77. * @brief Configures the necessary pins for an array of LEDs
  78. *
  79. * @param None.
  80. *
  81. * This function configures a GPIO to drive an LED in a low-power way.
  82. *
  83. * @return None.
  84. */
  85. int rt_hw_led_init(void)
  86. {
  87. #ifdef RT_USING_PIN
  88. #if defined(RT_USING_LED0)
  89. /* config led */
  90. rt_pin_mode(AM_GPIO_LED0, PIN_MODE_OUTPUT);
  91. /* turns off the led */
  92. rt_hw_led_off(0);
  93. #endif /* RT_USING_LED0 */
  94. #if defined(RT_USING_LED1)
  95. /* config led */
  96. rt_pin_mode(AM_GPIO_LED1, PIN_MODE_OUTPUT);
  97. /* turns off the led */
  98. rt_hw_led_off(1);
  99. #endif /* RT_USING_LED1 */
  100. #if defined(RT_USING_LED2)
  101. /* config led */
  102. rt_pin_mode(AM_GPIO_LED2, PIN_MODE_OUTPUT);
  103. /* turns off the led */
  104. rt_hw_led_off(2);
  105. #endif /* RT_USING_LED0 */
  106. #if defined(RT_USING_LED3)
  107. /* config led */
  108. rt_pin_mode(AM_GPIO_LED3, PIN_MODE_OUTPUT);
  109. /* turns off the led */
  110. rt_hw_led_off(3);
  111. #endif /* RT_USING_LED1 */
  112. #endif
  113. return 0;
  114. }
  115. #ifdef RT_USING_COMPONENTS_INIT
  116. INIT_BOARD_EXPORT(rt_hw_led_init);
  117. #endif
  118. #ifdef RT_USING_FINSH
  119. #include <finsh.h>
  120. void led(rt_uint32_t led, rt_uint32_t state)
  121. {
  122. /* set led status */
  123. switch (state)
  124. {
  125. case 0:
  126. rt_hw_led_off(led);
  127. break;
  128. case 1:
  129. rt_hw_led_on(led);
  130. break;
  131. default:
  132. break;
  133. }
  134. }
  135. FINSH_FUNCTION_EXPORT(led, turn led (0 - 3) on (1) or off (0).)
  136. #endif
  137. /*@}*/