led.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2017-09-14 Haley the first version
  9. */
  10. #include <rtthread.h>
  11. #include <rtdevice.h>
  12. #include "board.h"
  13. #define AM_GPIO_LED0 46
  14. #define AM_GPIO_LED1 47
  15. #define AM_GPIO_LED2 48
  16. #define AM_GPIO_LED3 49
  17. /**
  18. * @brief Turns on the requested LED.
  19. *
  20. * @param LEDNum is the LED number for the light to turn on.
  21. *
  22. * This function turns on a single LED.
  23. *
  24. * @return None.
  25. */
  26. void rt_hw_led_on(rt_uint8_t LEDNum)
  27. {
  28. #ifdef RT_USING_PIN
  29. if(LEDNum == 0)
  30. rt_pin_write(AM_GPIO_LED0, PIN_LOW);
  31. else if(LEDNum == 1)
  32. rt_pin_write(AM_GPIO_LED1, PIN_LOW);
  33. else if(LEDNum == 2)
  34. rt_pin_write(AM_GPIO_LED2, PIN_LOW);
  35. else if(LEDNum == 3)
  36. rt_pin_write(AM_GPIO_LED3, PIN_LOW);
  37. #endif
  38. }
  39. /**
  40. * @brief Turns off the requested LED.
  41. *
  42. * @param LEDNum is the LED number for the light to turn off.
  43. *
  44. * This function turns off a single LED.
  45. *
  46. * @return None.
  47. */
  48. void rt_hw_led_off(rt_uint8_t LEDNum)
  49. {
  50. #ifdef RT_USING_PIN
  51. if(LEDNum == 0)
  52. rt_pin_write(AM_GPIO_LED0, PIN_HIGH);
  53. else if(LEDNum == 1)
  54. rt_pin_write(AM_GPIO_LED1, PIN_HIGH);
  55. else if(LEDNum == 2)
  56. rt_pin_write(AM_GPIO_LED2, PIN_HIGH);
  57. else if(LEDNum == 3)
  58. rt_pin_write(AM_GPIO_LED3, PIN_HIGH);
  59. #endif
  60. }
  61. /**
  62. * @brief Configures the necessary pins for an array of LEDs
  63. *
  64. * @param None.
  65. *
  66. * This function configures a GPIO to drive an LED in a low-power way.
  67. *
  68. * @return None.
  69. */
  70. int rt_hw_led_init(void)
  71. {
  72. #ifdef RT_USING_PIN
  73. #if defined(RT_USING_LED0)
  74. /* config led */
  75. rt_pin_mode(AM_GPIO_LED0, PIN_MODE_OUTPUT);
  76. /* turns off the led */
  77. rt_hw_led_off(0);
  78. #endif /* RT_USING_LED0 */
  79. #if defined(RT_USING_LED1)
  80. /* config led */
  81. rt_pin_mode(AM_GPIO_LED1, PIN_MODE_OUTPUT);
  82. /* turns off the led */
  83. rt_hw_led_off(1);
  84. #endif /* RT_USING_LED1 */
  85. #if defined(RT_USING_LED2)
  86. /* config led */
  87. rt_pin_mode(AM_GPIO_LED2, PIN_MODE_OUTPUT);
  88. /* turns off the led */
  89. rt_hw_led_off(2);
  90. #endif /* RT_USING_LED0 */
  91. #if defined(RT_USING_LED3)
  92. /* config led */
  93. rt_pin_mode(AM_GPIO_LED3, PIN_MODE_OUTPUT);
  94. /* turns off the led */
  95. rt_hw_led_off(3);
  96. #endif /* RT_USING_LED1 */
  97. #endif
  98. rt_kprintf("led_init!\n");
  99. return 0;
  100. }
  101. #ifdef RT_USING_COMPONENTS_INIT
  102. INIT_DEVICE_EXPORT(rt_hw_led_init);
  103. #endif
  104. #ifdef RT_USING_FINSH
  105. #include <finsh.h>
  106. void led(rt_uint32_t led, rt_uint32_t state)
  107. {
  108. /* set led status */
  109. switch (state)
  110. {
  111. case 0:
  112. rt_hw_led_off(led);
  113. break;
  114. case 1:
  115. rt_hw_led_on(led);
  116. break;
  117. default:
  118. break;
  119. }
  120. }
  121. FINSH_FUNCTION_EXPORT(led, turn led (0 - 3) on (1) or off (0).)
  122. #endif
  123. /*@}*/