Refactor sync LED driver control register initialization to async.

This commit is contained in:
László Monda
2017-03-18 01:12:44 +01:00
parent 5d3bc37ffc
commit a89f0b675f
5 changed files with 70 additions and 49 deletions

View File

@@ -16,6 +16,7 @@ bool BridgeSlaveUhkModuleHandler(uint8_t uhkModuleId) {
bridge_slave_t bridgeSlaves[] = {
{ .slaveHandler = BridgeSlaveUhkModuleHandler, .moduleId = 0 },
{ .slaveHandler = BridgeSlaveLedDriverHandler, .moduleId = 0 },
{ .slaveHandler = BridgeSlaveLedDriverHandler, .moduleId = 1 },
};
static void bridgeProtocolCallback(I2C_Type *base, i2c_master_handle_t *handle, status_t status, void *userData)

View File

@@ -4,9 +4,69 @@
#define BUFFER_SIZE (LED_DRIVER_LED_COUNT + 1)
uint8_t ledsBuffer[BUFFER_SIZE] = {FRAME_REGISTER_PWM_FIRST};
uint8_t ledDriverStates[2] = {0};
uint8_t buffer[LED_DRIVER_BUFFER_LENGTH];
uint8_t initLedControlRegistersMessage = {FRAME_REGISTER_LED_CONTROL_FIRST, };
uint8_t ledControlBufferLeft[] = {
FRAME_REGISTER_LED_CONTROL_FIRST,
0b01111111, // key row 1
0b00111111, // display row 1
0b01011111, // keys row 2
0b00111111, // display row 2
0b01011111, // keys row 3
0b00111111, // display row 3
0b01111101, // keys row 4
0b00011111, // display row 4
0b00101111, // keys row 5
0b00011111, // display row 5
0b00000000, // keys row 6
0b00011111, // display row 6
0b00000000, // keys row 7
0b00011111, // display row 7
0b00000000, // keys row 8
0b00011111, // display row 8
0b00000000, // keys row 9
0b00011111, // display row 9
};
uint8_t ledControlBufferRight[] = {
FRAME_REGISTER_LED_CONTROL_FIRST,
0b01111111, // key row 1
0b00000000, // no display
0b01111111, // keys row 2
0b00000000, // no display
0b01111111, // keys row 3
0b00000000, // no display
0b01111111, // keys row 4
0b00000000, // no display
0b01111010, // keys row 5
0b00000000, // no display
0b00000000, // keys row 6
0b00000000, // no display
0b00000000, // keys row 7
0b00000000, // no display
0b00000000, // keys row 8
0b00000000, // no display
0b00000000, // keys row 9
0b00000000, // no display
};
bool BridgeSlaveLedDriverHandler(uint8_t ledDriverId) {
I2cAsyncWrite(I2C_ADDRESS_LED_DRIVER_LEFT, ledsBuffer, BUFFER_SIZE);
uint8_t *ledDriverState = ledDriverStates + ledDriverId;
uint8_t ledDriverAddress = ledDriverId ? I2C_ADDRESS_LED_DRIVER_LEFT : I2C_ADDRESS_LED_DRIVER_RIGHT;
uint8_t *ledControlBuffer = ledDriverId ? ledControlBufferLeft : ledControlBufferRight;
switch (*ledDriverState) {
case LedDriverState_InitLedControlRegisters:
I2cAsyncWrite(ledDriverAddress, ledControlBuffer, sizeof(ledControlBufferLeft));
*ledDriverState = LedDriverState_Initialized;
break;
case LedDriverState_Initialized:
I2cAsyncWrite(I2C_ADDRESS_LED_DRIVER_LEFT, ledsBuffer, BUFFER_SIZE);
break;
}
return true;
}

View File

@@ -5,6 +5,13 @@
#include "fsl_common.h"
// Typedefs:
typedef enum {
LedDriverState_InitLedControlRegisters,
LedDriverState_Initialized,
} LedDriverState;
// Functions:
extern bool BridgeSlaveLedDriverHandler(uint8_t ledDriverId);

View File

@@ -31,53 +31,5 @@ void LedDriver_SetAllLedsTo(uint8_t val)
for (i=FRAME_REGISTER_PWM_FIRST; i<=FRAME_REGISTER_PWM_LAST; i++) {
LedDriver_WriteRegister(address, i, val);
}
uint8_t ledControlBufferRight[] = {
FRAME_REGISTER_LED_CONTROL_FIRST,
0b01111111, // key row 1
0b00000000, // no display
0b01111111, // keys row 2
0b00000000, // no display
0b01111111, // keys row 3
0b00000000, // no display
0b01111111, // keys row 4
0b00000000, // no display
0b01111010, // keys row 5
0b00000000, // no display
0b00000000, // keys row 6
0b00000000, // no display
0b00000000, // keys row 7
0b00000000, // no display
0b00000000, // keys row 8
0b00000000, // no display
0b00000000, // keys row 9
0b00000000, // no display
};
I2cWrite(I2C_MAIN_BUS_BASEADDR, I2C_ADDRESS_LED_DRIVER_RIGHT,
ledControlBufferRight, sizeof(ledControlBufferRight));
uint8_t ledControlBufferLeft[] = {
FRAME_REGISTER_LED_CONTROL_FIRST,
0b01111111, // key row 1
0b00111111, // display row 1
0b01011111, // keys row 2
0b00111111, // display row 2
0b01011111, // keys row 3
0b00111111, // display row 3
0b01111101, // keys row 4
0b00011111, // display row 4
0b00101111, // keys row 5
0b00011111, // display row 5
0b00000000, // keys row 6
0b00011111, // display row 6
0b00000000, // keys row 7
0b00011111, // display row 7
0b00000000, // keys row 8
0b00011111, // display row 8
0b00000000, // keys row 9
0b00011111, // display row 9
};
I2cWrite(I2C_MAIN_BUS_BASEADDR, I2C_ADDRESS_LED_DRIVER_LEFT,
ledControlBufferLeft, sizeof(ledControlBufferLeft));
}
}

View File

@@ -30,6 +30,7 @@
#define LED_DRIVER_FRAME_FUNCTION 0x0B
#define LED_DRIVER_LED_COUNT (2*8*9)
#define LED_DRIVER_BUFFER_LENGTH (LED_DRIVER_LED_COUNT + 1)
#define FRAME_REGISTER_LED_CONTROL_FIRST 0x00
#define FRAME_REGISTER_LED_CONTROL_LAST 0x11