PageRenderTime 30ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/configs/stm32l476vg-disco/src/stm32_autoleds.c

https://bitbucket.org/hg42/nuttx
C | 178 lines | 69 code | 29 blank | 80 comment | 2 complexity | 9e7a959cef556ff2fad96fbbf647e0f3 MD5 | raw file
Possible License(s): 0BSD
  1. /****************************************************************************
  2. * configs/stm32l476vg-disco/src/stm32_autoleds.c
  3. *
  4. * Copyright (C) 2016 Gregory Nutt. All rights reserved.
  5. * Author: dev@ziggurat29.com
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ****************************************************************************/
  35. /****************************************************************************
  36. * Included Files
  37. ****************************************************************************/
  38. #include <nuttx/config.h>
  39. #include <stdint.h>
  40. #include <stdbool.h>
  41. #include <debug.h>
  42. #include <nuttx/board.h>
  43. #include <arch/board/board.h>
  44. #include "chip.h"
  45. #include "up_arch.h"
  46. #include "up_internal.h"
  47. #include "stm32l4.h"
  48. #include "stm32l476vg-disco.h"
  49. #ifdef CONFIG_ARCH_LEDS
  50. /****************************************************************************
  51. * Public Functions
  52. ****************************************************************************/
  53. /****************************************************************************
  54. * Name: board_autoled_initialize
  55. ****************************************************************************/
  56. void board_autoled_initialize(void)
  57. {
  58. /* Configure LD4,5 GPIO for output */
  59. stm32l4_configgpio(GPIO_LED_RED);
  60. stm32l4_configgpio(GPIO_LED_GRN);
  61. }
  62. /****************************************************************************
  63. * Name: board_autoled_on
  64. ****************************************************************************/
  65. void board_autoled_on(int led)
  66. {
  67. switch (led)
  68. {
  69. /* 0: LED_STARTED, LED_HEAPALLOCATE, LED_IRQSENABLED
  70. *
  71. * Since the LEDs were initially all OFF and since this state only
  72. * occurs one time, nothing need be done.
  73. */
  74. default:
  75. case LED_STARTED:
  76. case LED_HEAPALLOCATE:
  77. case LED_IRQSENABLED:
  78. break;
  79. /* 1: LED_STACKCREATED
  80. *
  81. * This case will also occur only once.
  82. */
  83. case LED_STACKCREATED:
  84. break;
  85. /* 2: LED_INIRQ, LED_SIGNAL, LED_ASSERTION
  86. *
  87. * This case will occur many times.
  88. */
  89. case LED_INIRQ:
  90. case LED_SIGNAL:
  91. case LED_ASSERTION:
  92. stm32l4_gpiowrite(GPIO_LED_RED, true);
  93. break;
  94. /* 3: LED_PANIC: GPIO_LED_GRN=OFF RX=ON
  95. *
  96. * This case will also occur many times.
  97. */
  98. case LED_PANIC:
  99. stm32l4_gpiowrite(GPIO_LED_GRN, false);
  100. stm32l4_gpiowrite(GPIO_LED_RED, true);
  101. break;
  102. case LED_IDLE:
  103. stm32l4_gpiowrite(GPIO_LED_GRN, true);
  104. stm32l4_gpiowrite(GPIO_LED_RED, false);
  105. break;
  106. }
  107. }
  108. /****************************************************************************
  109. * Name: board_autoled_off
  110. ****************************************************************************/
  111. void board_autoled_off(int led)
  112. {
  113. switch (led)
  114. {
  115. /* 0: LED_STARTED, LED_HEAPALLOCATE, LED_IRQSENABLED:
  116. * 1: LED_STACKCREATED:
  117. *
  118. * These cases should never happen.
  119. */
  120. default:
  121. case LED_STARTED:
  122. case LED_HEAPALLOCATE:
  123. case LED_IRQSENABLED:
  124. case LED_STACKCREATED:
  125. break;
  126. /* 2: LED_INIRQ, LED_SIGNAL, LED_ASSERTION:
  127. *
  128. * This case will occur many times.
  129. */
  130. case LED_INIRQ:
  131. case LED_SIGNAL:
  132. case LED_ASSERTION:
  133. stm32l4_gpiowrite(GPIO_LED_RED, false);
  134. break;
  135. /* 3: LED_PANIC: GPIO_LED_GRN=OFF RX=OFF
  136. *
  137. * This case will also occur many times.
  138. */
  139. case LED_PANIC:
  140. stm32l4_gpiowrite(GPIO_LED_GRN, false);
  141. stm32l4_gpiowrite(GPIO_LED_RED, false);
  142. break;
  143. case LED_IDLE:
  144. stm32l4_gpiowrite(GPIO_LED_GRN, false);
  145. stm32l4_gpiowrite(GPIO_LED_RED, false);
  146. break;
  147. }
  148. }
  149. #endif /* CONFIG_ARCH_LEDS */