drv_led.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * File : drv_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. */
  23. #include "board.h"
  24. #include "drv_led.h"
  25. #include <drivers/pin.h>
  26. //the pin number can be find in :goip.c pins[].
  27. //in nucleo-l476rg board,the green led is attached to PA5 which the number is 21.
  28. #define LED 21
  29. /**
  30. * This function light up LED
  31. *
  32. * @param led LED number (6)
  33. */
  34. void led_set(int led)
  35. {
  36. if (led == 0)
  37. {
  38. rt_pin_write(LED, 1);
  39. }
  40. }
  41. /**
  42. * This function return LED status, on or off
  43. *
  44. * @param led LED number (0-1)
  45. */
  46. int led_get(int led)
  47. {
  48. int ret = 0;
  49. if (led == 0)
  50. {
  51. ret = rt_pin_read(LED);
  52. }
  53. return ret;
  54. }
  55. /**
  56. * This function turn off LED
  57. *
  58. * @param led LED number (0-1)
  59. */
  60. void led_clear(int led)
  61. {
  62. if (led == 0)
  63. {
  64. rt_pin_write(LED, 0);
  65. }
  66. }
  67. /**
  68. * This function toggle LED, switch from on to off or vice versa
  69. *
  70. * @param led LED number (0-1)
  71. */
  72. void led_toggle(int led)
  73. {
  74. int ret = 0;
  75. ret = rt_pin_read(LED);
  76. if(ret==1)
  77. {
  78. ret=0;
  79. }
  80. else if(ret==0)
  81. {
  82. ret=1;
  83. }
  84. if (led == 0)
  85. {
  86. rt_pin_write(LED, ret);
  87. }
  88. }
  89. /**
  90. * This function light up LEDs according value of 2 least significat bits
  91. *
  92. * @param value Bit pattern
  93. */
  94. void led_value(int value)
  95. {
  96. rt_pin_write(LED, value);
  97. }
  98. /**
  99. * This function initialize LED interface
  100. */
  101. void led_init(void)
  102. {
  103. rt_pin_mode(LED, PIN_MODE_OUTPUT);
  104. }
  105. /**
  106. * This function initialize LED interface
  107. */
  108. void led_deinit(void)
  109. {
  110. rt_pin_mode(LED, PIN_MODE_INPUT);
  111. }