EFM32 Happy Gecko Software Documentation  efm32hg-doc-5.1.2
bsp_dk_leds.c
Go to the documentation of this file.
1 /***************************************************************************/
18 #include "bsp.h"
19 
20 #if defined( BSP_DK_LEDS )
21 /***************************************************************************/
26 /***************************************************************************/
31 /**************************************************************************/
37 int BSP_LedsInit(void)
38 {
39  BSP_RegisterWrite(BSP_LED_PORT, 0);
40  return BSP_STATUS_OK;
41 }
42 
43 /**************************************************************************/
48 uint32_t BSP_LedsGet(void)
49 {
50  return BSP_RegisterRead(BSP_LED_PORT) & BSP_LED_MASK;
51 }
52 
53 /**************************************************************************/
60 int BSP_LedsSet(uint32_t leds)
61 {
62  BSP_RegisterWrite(BSP_LED_PORT, leds & BSP_LED_MASK);
63  return BSP_STATUS_OK;
64 }
65 
66 /**************************************************************************/
72 int BSP_LedClear(int ledNo)
73 {
74  uint32_t tmp;
75 
76  if ((ledNo >= 0) && (ledNo < BSP_NO_OF_LEDS))
77  {
78  tmp = BSP_RegisterRead(BSP_LED_PORT) & BSP_LED_MASK;
79  tmp &= ~( 1 << ledNo );
80  BSP_RegisterWrite(BSP_LED_PORT, tmp);
81  return BSP_STATUS_OK;
82  }
84 }
85 
86 /**************************************************************************/
93 int BSP_LedGet(int ledNo)
94 {
95  if ((ledNo >= 0) && (ledNo < BSP_NO_OF_LEDS))
96  {
97  if ( BSP_RegisterRead(BSP_LED_PORT) & BSP_LED_MASK & (1 << ledNo) )
98  return 1;
99 
100  return 0;
101  }
103 }
104 
105 /**************************************************************************/
111 int BSP_LedSet(int ledNo)
112 {
113  uint32_t tmp;
114 
115  if ((ledNo >= 0) && (ledNo < BSP_NO_OF_LEDS))
116  {
117  tmp = BSP_RegisterRead(BSP_LED_PORT) & BSP_LED_MASK;
118  tmp |= 1 << ledNo;
119  BSP_RegisterWrite(BSP_LED_PORT, tmp);
120  return BSP_STATUS_OK;
121  }
123 }
124 
125 /**************************************************************************/
131 int BSP_LedToggle(int ledNo)
132 {
133  uint32_t tmp;
134 
135  if ((ledNo >= 0) && (ledNo < BSP_NO_OF_LEDS))
136  {
137  tmp = BSP_RegisterRead(BSP_LED_PORT) & BSP_LED_MASK;
138  tmp ^= 1 << ledNo;
139  BSP_RegisterWrite(BSP_LED_PORT, tmp);
140  return BSP_STATUS_OK;
141  }
143 }
144 
147 #endif /* BSP_DK_LEDS */
Board support package API definitions.
int BSP_LedsInit(void)
Initialize LED drivers.
Definition: bsp_dk_leds.c:37
#define BSP_STATUS_OK
Definition: bsp.h:45
uint16_t BSP_RegisterRead(volatile uint16_t *addr)
Read from a board controller register.
Definition: bsp_dk_3201.c:687
int BSP_LedsSet(uint32_t leds)
Update all LED's.
Definition: bsp_dk_leds.c:60
int BSP_LedSet(int ledNo)
Turn on a single LED.
Definition: bsp_dk_leds.c:111
int BSP_LedToggle(int ledNo)
Toggle a single LED.
Definition: bsp_dk_leds.c:131
uint32_t BSP_LedsGet(void)
Get status of all LED's.
Definition: bsp_dk_leds.c:48
#define BSP_STATUS_ILLEGAL_PARAM
Definition: bsp.h:46
int BSP_RegisterWrite(volatile uint16_t *addr, uint16_t data)
Write to a board controller register.
Definition: bsp_dk_3201.c:704
int BSP_LedGet(int ledNo)
Get current status of a single LED.
Definition: bsp_dk_leds.c:93
int BSP_LedClear(int ledNo)
Turn off a single LED.
Definition: bsp_dk_leds.c:72