led.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 "board.h"
  27. #define AM_GPIO_LED0 46
  28. #define AM_GPIO_LED1 47
  29. #define AM_GPIO_LED2 48
  30. #define AM_GPIO_LED3 49
  31. /**
  32. * @brief Turns on the requested LED.
  33. *
  34. * @param LEDNum is the LED number for the light to turn on.
  35. *
  36. * This function turns on a single LED.
  37. *
  38. * @return None.
  39. */
  40. void rt_hw_led_on(rt_uint8_t LEDNum)
  41. {
  42. #ifdef RT_USING_PIN
  43. if(LEDNum == 0)
  44. rt_pin_write(AM_GPIO_LED0, PIN_LOW);
  45. else if(LEDNum == 1)
  46. rt_pin_write(AM_GPIO_LED1, PIN_LOW);
  47. else if(LEDNum == 2)
  48. rt_pin_write(AM_GPIO_LED2, PIN_LOW);
  49. else if(LEDNum == 3)
  50. rt_pin_write(AM_GPIO_LED3, PIN_LOW);
  51. #endif
  52. }
  53. /**
  54. * @brief Turns off the requested LED.
  55. *
  56. * @param LEDNum is the LED number for the light to turn off.
  57. *
  58. * This function turns off a single LED.
  59. *
  60. * @return None.
  61. */
  62. void rt_hw_led_off(rt_uint8_t LEDNum)
  63. {
  64. #ifdef RT_USING_PIN
  65. if(LEDNum == 0)
  66. rt_pin_write(AM_GPIO_LED0, PIN_HIGH);
  67. else if(LEDNum == 1)
  68. rt_pin_write(AM_GPIO_LED1, PIN_HIGH);
  69. else if(LEDNum == 2)
  70. rt_pin_write(AM_GPIO_LED2, PIN_HIGH);
  71. else if(LEDNum == 3)
  72. rt_pin_write(AM_GPIO_LED3, PIN_HIGH);
  73. #endif
  74. }
  75. /**
  76. * @brief Configures the necessary pins for an array of LEDs
  77. *
  78. * @param None.
  79. *
  80. * This function configures a GPIO to drive an LED in a low-power way.
  81. *
  82. * @return None.
  83. */
  84. int rt_hw_led_init(void)
  85. {
  86. #ifdef RT_USING_PIN
  87. #if defined(RT_USING_LED0)
  88. /* config led */
  89. rt_pin_mode(AM_GPIO_LED0, PIN_MODE_OUTPUT);
  90. /* turns off the led */
  91. rt_hw_led_off(0);
  92. #endif /* RT_USING_LED0 */
  93. #if defined(RT_USING_LED1)
  94. /* config led */
  95. rt_pin_mode(AM_GPIO_LED1, PIN_MODE_OUTPUT);
  96. /* turns off the led */
  97. rt_hw_led_off(1);
  98. #endif /* RT_USING_LED1 */
  99. #if defined(RT_USING_LED2)
  100. /* config led */
  101. rt_pin_mode(AM_GPIO_LED2, PIN_MODE_OUTPUT);
  102. /* turns off the led */
  103. rt_hw_led_off(2);
  104. #endif /* RT_USING_LED0 */
  105. #if defined(RT_USING_LED3)
  106. /* config led */
  107. rt_pin_mode(AM_GPIO_LED3, PIN_MODE_OUTPUT);
  108. /* turns off the led */
  109. rt_hw_led_off(3);
  110. #endif /* RT_USING_LED1 */
  111. #endif
  112. rt_kprintf("led_init!\n");
  113. return 0;
  114. }
  115. #ifdef RT_USING_COMPONENTS_INIT
  116. INIT_DEVICE_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. /*@}*/