bsp_stk_leds.c

Go to the documentation of this file.
00001 /***************************************************************************/
00018 #include "em_device.h"
00019 #include "em_cmu.h"
00020 #include "em_gpio.h"
00021 #include "bsp.h"
00022 
00023 #if defined( BSP_GPIO_LEDS )
00024 
00026 typedef struct
00027 {
00028   GPIO_Port_TypeDef   port;
00029   unsigned int        pin;
00030 } tLedArray;
00031 
00032 static const tLedArray ledArray[ BSP_NO_OF_LEDS ] = BSP_GPIO_LEDARRAY_INIT;
00033 
00034 int BSP_LedsInit(void)
00035 {
00036   int i;
00037 
00038   CMU_ClockEnable(cmuClock_HFPER, true);
00039   CMU_ClockEnable(cmuClock_GPIO, true);
00040   for ( i=0; i<BSP_NO_OF_LEDS; i++ )
00041   {
00042     GPIO_PinModeSet(ledArray[i].port, ledArray[i].pin, gpioModePushPull, 0);
00043   }
00044   return BSP_STATUS_OK;
00045 }
00046 
00047 uint32_t BSP_LedsGet(void)
00048 {
00049   int i;
00050   uint32_t retVal, mask;
00051 
00052   for ( i=0, retVal=0, mask=0x1; i<BSP_NO_OF_LEDS; i++, mask <<= 1 )
00053   {
00054     if (GPIO_PinOutGet(ledArray[i].port, ledArray[i].pin))
00055       retVal |= mask;
00056   }
00057   return retVal;
00058 }
00059 
00060 int BSP_LedsSet(uint32_t leds)
00061 {
00062   int i;
00063   uint32_t mask;
00064 
00065   for ( i=0, mask=0x1; i<BSP_NO_OF_LEDS; i++, mask <<= 1 )
00066   {
00067     if ( leds & mask )
00068       GPIO_PinOutSet(ledArray[i].port, ledArray[i].pin);
00069     else
00070       GPIO_PinOutClear(ledArray[i].port, ledArray[i].pin);
00071   }
00072   return BSP_STATUS_OK;
00073 }
00074 
00075 int BSP_LedClear(int ledNo)
00076 {
00077   if ((ledNo >= 0) && (ledNo < BSP_NO_OF_LEDS))
00078   {
00079     GPIO_PinOutClear(ledArray[ledNo].port, ledArray[ledNo].pin);
00080     return BSP_STATUS_OK;
00081   }
00082   return BSP_STATUS_ILLEGAL_PARAM;
00083 }
00084 
00085 int BSP_LedGet(int ledNo)
00086 {
00087   int retVal = BSP_STATUS_ILLEGAL_PARAM;
00088 
00089   if ((ledNo >= 0) && (ledNo < BSP_NO_OF_LEDS))
00090   {
00091     retVal = (int)GPIO_PinOutGet(ledArray[ledNo].port, ledArray[ledNo].pin);
00092   }
00093   return retVal;
00094 }
00095 
00096 int BSP_LedSet(int ledNo)
00097 {
00098   if ((ledNo >= 0) && (ledNo < BSP_NO_OF_LEDS))
00099   {
00100     GPIO_PinOutSet(ledArray[ledNo].port, ledArray[ledNo].pin);
00101     return BSP_STATUS_OK;
00102   }
00103   return BSP_STATUS_ILLEGAL_PARAM;
00104 }
00105 
00106 int BSP_LedToggle(int ledNo)
00107 {
00108   if ((ledNo >= 0) && (ledNo < BSP_NO_OF_LEDS))
00109   {
00110     GPIO_PinOutToggle(ledArray[ledNo].port, ledArray[ledNo].pin);
00111     return BSP_STATUS_OK;
00112   }
00113   return BSP_STATUS_ILLEGAL_PARAM;
00114 }
00115 
00117 #endif  /* BSP_GPIO_LEDS */