EFM32 Giant Gecko Software Documentation  efm32gg-doc-4.2.1
bsp_stk_leds.c
Go to the documentation of this file.
1 /***************************************************************************/
18 #include "em_device.h"
19 #include "em_cmu.h"
20 #include "em_gpio.h"
21 #include "bsp.h"
22 
23 #if defined( BSP_GPIO_LEDS )
24 
26 typedef struct
27 {
28  GPIO_Port_TypeDef port;
29  unsigned int pin;
30 } tLedArray;
31 
32 static const tLedArray ledArray[ BSP_NO_OF_LEDS ] = BSP_GPIO_LEDARRAY_INIT;
33 
34 int BSP_LedsInit(void)
35 {
36  int i;
37 
40  for ( i=0; i<BSP_NO_OF_LEDS; i++ )
41  {
42  GPIO_PinModeSet(ledArray[i].port, ledArray[i].pin, gpioModePushPull, 0);
43  }
44  return BSP_STATUS_OK;
45 }
46 
47 uint32_t BSP_LedsGet(void)
48 {
49  int i;
50  uint32_t retVal, mask;
51 
52  for ( i=0, retVal=0, mask=0x1; i<BSP_NO_OF_LEDS; i++, mask <<= 1 )
53  {
54  if (GPIO_PinOutGet(ledArray[i].port, ledArray[i].pin))
55  retVal |= mask;
56  }
57  return retVal;
58 }
59 
60 int BSP_LedsSet(uint32_t leds)
61 {
62  int i;
63  uint32_t mask;
64 
65  for ( i=0, mask=0x1; i<BSP_NO_OF_LEDS; i++, mask <<= 1 )
66  {
67  if ( leds & mask )
68  GPIO_PinOutSet(ledArray[i].port, ledArray[i].pin);
69  else
70  GPIO_PinOutClear(ledArray[i].port, ledArray[i].pin);
71  }
72  return BSP_STATUS_OK;
73 }
74 
75 int BSP_LedClear(int ledNo)
76 {
77  if ((ledNo >= 0) && (ledNo < BSP_NO_OF_LEDS))
78  {
79  GPIO_PinOutClear(ledArray[ledNo].port, ledArray[ledNo].pin);
80  return BSP_STATUS_OK;
81  }
83 }
84 
85 int BSP_LedGet(int ledNo)
86 {
87  int retVal = BSP_STATUS_ILLEGAL_PARAM;
88 
89  if ((ledNo >= 0) && (ledNo < BSP_NO_OF_LEDS))
90  {
91  retVal = (int)GPIO_PinOutGet(ledArray[ledNo].port, ledArray[ledNo].pin);
92  }
93  return retVal;
94 }
95 
96 int BSP_LedSet(int ledNo)
97 {
98  if ((ledNo >= 0) && (ledNo < BSP_NO_OF_LEDS))
99  {
100  GPIO_PinOutSet(ledArray[ledNo].port, ledArray[ledNo].pin);
101  return BSP_STATUS_OK;
102  }
104 }
105 
106 int BSP_LedToggle(int ledNo)
107 {
108  if ((ledNo >= 0) && (ledNo < BSP_NO_OF_LEDS))
109  {
110  GPIO_PinOutToggle(ledArray[ledNo].port, ledArray[ledNo].pin);
111  return BSP_STATUS_OK;
112  }
114 }
115 
117 #endif /* BSP_GPIO_LEDS */
Clock management unit (CMU) API.
Board support package API definitions.
GPIO_Port_TypeDef
Definition: em_gpio.h:232
__STATIC_INLINE void GPIO_PinOutToggle(GPIO_Port_TypeDef port, unsigned int pin)
Toggle a single pin in GPIO port data out register.
Definition: em_gpio.h:771
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
#define BSP_STATUS_OK
Definition: bsp.h:40
void GPIO_PinModeSet(GPIO_Port_TypeDef port, unsigned int pin, GPIO_Mode_TypeDef mode, unsigned int out)
Set the mode for a GPIO pin.
Definition: em_gpio.c:226
General Purpose IO (GPIO) peripheral API.
__STATIC_INLINE void GPIO_PinOutSet(GPIO_Port_TypeDef port, unsigned int pin)
Set a single pin in GPIO data out register to 1.
Definition: em_gpio.h:745
void CMU_ClockEnable(CMU_Clock_TypeDef clock, bool enable)
Enable/disable a clock.
Definition: em_cmu.c:1369
#define BSP_STATUS_ILLEGAL_PARAM
Definition: bsp.h:41
__STATIC_INLINE unsigned int GPIO_PinOutGet(GPIO_Port_TypeDef port, unsigned int pin)
Get current setting for a pin in a GPIO port data out register.
Definition: em_gpio.h:722
__STATIC_INLINE void GPIO_PinOutClear(GPIO_Port_TypeDef port, unsigned int pin)
Set a single pin in GPIO data out port register to 0.
Definition: em_gpio.h:698