User manual
LPCXpresso Experiment Kit - User’s Guide
Page 98
Copyright 2013 © Embedded Artists AB
#define LS_MODE_ON 0x01
#define LS_MODE_BLINK0 0x02
#define LS_MODE_BLINK1 0x03
/******************************************************************************
* Local variables
*****************************************************************************/
static uint16_t blink0Shadow = 0;
static uint16_t blink1Shadow = 0;
static uint16_t ledStateShadow = 0;
/******************************************************************************
* Local Functions
*****************************************************************************/
static void setLsStates(uint16_t states, uint8_t* ls, uint8_t mode)
{
#define IS_LED_SET(bit, x) ( ( ((x) & (bit)) != 0 ) ? 1 : 0 )
int i = 0;
for (i = 0; i < 4; i++) {
ls[i] |= ( (IS_LED_SET(0x0001, states)*mode << 0)
| (IS_LED_SET(0x0002, states)*mode << 2)
| (IS_LED_SET(0x0004, states)*mode << 4)
| (IS_LED_SET(0x0008, states)*mode << 6) );
states >>= 4;
}
}
static void setLeds(void)
{
uint8_t buf[5];
uint8_t ls[4] = {0,0,0,0};
uint16_t states = ledStateShadow;
/* LEDs in On/Off state */
setLsStates(states, ls, LS_MODE_ON);
/* set the LEDs that should blink */
setLsStates(blink0Shadow, ls, LS_MODE_BLINK0);
setLsStates(blink1Shadow, ls, LS_MODE_BLINK1);
buf[0] = PCA9532_LS0 | PCA9532_AUTO_INC;
buf[1] = ls[0];
buf[2] = ls[1];
buf[3] = ls[2];
buf[4] = ls[3];
I2CWrite(PCA9532_I2C_ADDR, buf, 5);
}
/******************************************************************************
* Public Functions
*****************************************************************************/
/******************************************************************************
*
* Description:
* Set LED states (on or off).
*
* Params:
* [in] ledOnMask - The LEDs that should be turned on. This mask has
* priority over ledOffMask
* [in] ledOffMask - The LEDs that should be turned off.
*
*****************************************************************************/
void pca9532_setLeds (uint16_t ledOnMask, uint16_t ledOffMask)
{
/* turn off leds */
ledStateShadow &= (~(ledOffMask) & 0xffff);
/* ledOnMask has priority over ledOffMask */
ledStateShadow |= ledOnMask;
/* turn off blinking */
blink0Shadow &= (~(ledOffMask) & 0xffff);