bsp_stk_leds.c

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