Move LED control register commands to ledDriverStates.

This commit is contained in:
László Monda
2017-05-31 23:29:02 +02:00
parent 24addf1648
commit 0e41e403a9
2 changed files with 54 additions and 49 deletions

View File

@@ -3,70 +3,68 @@
uint8_t ledsBuffer[BUFFER_SIZE] = {FRAME_REGISTER_PWM_FIRST};
led_driver_state_t ledDriverStates[LED_DRIVER_MAX_COUNT] = {
{
.i2cAddress = I2C_ADDRESS_LED_DRIVER_RIGHT
.i2cAddress = I2C_ADDRESS_LED_DRIVER_RIGHT,
.setupLedControlRegistersCommand = {
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
}
},
{
.i2cAddress = I2C_ADDRESS_LED_DRIVER_LEFT
.i2cAddress = I2C_ADDRESS_LED_DRIVER_LEFT,
.setupLedControlRegistersCommand = {
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 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
};
uint8_t setFunctionFrameBuffer[] = {LED_DRIVER_REGISTER_FRAME, LED_DRIVER_FRAME_FUNCTION};
uint8_t setShutdownModeNormalBuffer[] = {LED_DRIVER_REGISTER_SHUTDOWN, SHUTDOWN_MODE_NORMAL};
uint8_t setFrame1Buffer[] = {LED_DRIVER_REGISTER_FRAME, LED_DRIVER_FRAME_1};
void LedSlaveDriver_Init() {
ledControlBufferLeft[7] |= 0b00000010; // Enable the LED of the ISO key.
ledDriverStates[ledDriverId_Left].setupLedControlRegistersCommand[7] |= 0b00000010; // Enable the LED of the ISO key.
SetLeds(0xff);
}
void LedSlaveDriver_Update(uint8_t ledDriverId) {
uint8_t *ledDriverPhase = &ledDriverStates[ledDriverId].phase;
uint8_t ledDriverAddress = ledDriverStates[ledDriverId].i2cAddress;
uint8_t *ledControlBuffer = ledDriverId ? ledControlBufferLeft : ledControlBufferRight;
uint8_t *ledControlBuffer = ledDriverStates[ledDriverId].setupLedControlRegistersCommand;
switch (*ledDriverPhase) {
case LedDriverPhase_SetFunctionFrame:
@@ -82,7 +80,7 @@ void LedSlaveDriver_Update(uint8_t ledDriverId) {
*ledDriverPhase = LedDriverPhase_InitLedControlRegisters;
break;
case LedDriverPhase_InitLedControlRegisters:
I2cAsyncWrite(ledDriverAddress, ledControlBuffer, sizeof(ledControlBufferLeft));
I2cAsyncWrite(ledDriverAddress, ledControlBuffer, LED_CONTROL_REGISTERS_COMMAND_LENGTH);
*ledDriverPhase = LedDriverPhase_Initialized;
break;
case LedDriverPhase_Initialized:

View File

@@ -10,9 +10,15 @@
#define LED_DRIVER_MAX_COUNT 2
#define BUFFER_SIZE (LED_DRIVER_LED_COUNT + 1)
#define LED_CONTROL_REGISTERS_COMMAND_LENGTH 19
// Typedefs:
typedef enum {
ledDriverId_Right,
ledDriverId_Left,
} led_driver_id_t;
typedef enum {
LedDriverPhase_SetFunctionFrame,
LedDriverPhase_SetShutdownModeNormal,
@@ -26,6 +32,7 @@
uint8_t frames[LED_DRIVER_LED_COUNT];
uint8_t ledIndex;
uint8_t i2cAddress;
uint8_t setupLedControlRegistersCommand[LED_CONTROL_REGISTERS_COMMAND_LENGTH];
} led_driver_state_t;
// Functions: