Extract LedDriverValues from LedDriverStates to make them public, and make LedDriverStates values private.
This commit is contained in:
@@ -66,13 +66,13 @@ void LedDisplay_SetText(uint8_t length, const char* text) {
|
||||
allSegmentSets |= characterToSegmentSet(text[0]);
|
||||
}
|
||||
|
||||
LedDriverStates[LedDriverId_Left].sourceLedValues[11] = allSegmentSets & 0b00000001 ? LED_BRIGHTNESS_LEVEL : 0;
|
||||
LedDriverStates[LedDriverId_Left].sourceLedValues[12] = allSegmentSets & 0b00000010 ? LED_BRIGHTNESS_LEVEL : 0;
|
||||
LedDriverValues[LedDriverId_Left][11] = allSegmentSets & 0b00000001 ? LED_BRIGHTNESS_LEVEL : 0;
|
||||
LedDriverValues[LedDriverId_Left][12] = allSegmentSets & 0b00000010 ? LED_BRIGHTNESS_LEVEL : 0;
|
||||
allSegmentSets >>= 2;
|
||||
|
||||
for (uint8_t i = 24; i <= 136; i += 16) {
|
||||
for (uint8_t j = 0; j < 5; j++) {
|
||||
LedDriverStates[LedDriverId_Left].sourceLedValues[i + j] = allSegmentSets & 1 << j ? LED_BRIGHTNESS_LEVEL : 0;
|
||||
LedDriverValues[LedDriverId_Left][i + j] = allSegmentSets & 1 << j ? LED_BRIGHTNESS_LEVEL : 0;
|
||||
}
|
||||
allSegmentSets >>= 5;
|
||||
}
|
||||
@@ -80,14 +80,14 @@ void LedDisplay_SetText(uint8_t length, const char* text) {
|
||||
|
||||
void LedDisplay_SetLayer(uint8_t layerId) {
|
||||
for (uint8_t i = 13; i <= 45; i += 16) {
|
||||
LedDriverStates[LedDriverId_Left].sourceLedValues[i] = 0;
|
||||
LedDriverValues[LedDriverId_Left][i] = 0;
|
||||
}
|
||||
|
||||
if (layerId >= LAYER_ID_MOD && layerId <= LAYER_ID_MOUSE) {
|
||||
LedDriverStates[LedDriverId_Left].sourceLedValues[16 * layerId - 3] = LED_BRIGHTNESS_LEVEL;
|
||||
LedDriverValues[LedDriverId_Left][16 * layerId - 3] = LED_BRIGHTNESS_LEVEL;
|
||||
}
|
||||
}
|
||||
|
||||
void LedDisplay_SetIcon(led_display_icon_t icon, bool isEnabled) {
|
||||
LedDriverStates[LedDriverId_Left].sourceLedValues[8 + icon] = isEnabled ? LED_BRIGHTNESS_LEVEL : 0;
|
||||
LedDriverValues[LedDriverId_Left][8 + icon] = isEnabled ? LED_BRIGHTNESS_LEVEL : 0;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
#include "slave_scheduler.h"
|
||||
#include "led_display.h"
|
||||
|
||||
led_driver_state_t LedDriverStates[LED_DRIVER_MAX_COUNT] = {
|
||||
uint8_t LedDriverValues[LED_DRIVER_MAX_COUNT][LED_DRIVER_LED_COUNT];
|
||||
|
||||
static led_driver_state_t ledDriverStates[LED_DRIVER_MAX_COUNT] = {
|
||||
{
|
||||
.i2cAddress = I2C_ADDRESS_IS31FL3731_RIGHT,
|
||||
.setupLedControlRegistersCommand = {
|
||||
@@ -61,19 +63,20 @@ uint8_t updatePwmRegistersBuffer[PWM_REGISTER_BUFFER_LENGTH];
|
||||
|
||||
void LedSlaveDriver_Init(uint8_t ledDriverId) {
|
||||
if (ledDriverId == ISO_KEY_LED_DRIVER_ID && IS_ISO) {
|
||||
LedDriverStates[LedDriverId_Left].setupLedControlRegistersCommand[ISO_KEY_CONTROL_REGISTER_POS] |= 1 << ISO_KEY_CONTROL_REGISTER_BIT;
|
||||
ledDriverStates[LedDriverId_Left].setupLedControlRegistersCommand[ISO_KEY_CONTROL_REGISTER_POS] |= 1 << ISO_KEY_CONTROL_REGISTER_BIT;
|
||||
}
|
||||
|
||||
led_driver_state_t *currentLedDriverState = LedDriverStates + ledDriverId;
|
||||
led_driver_state_t *currentLedDriverState = ledDriverStates + ledDriverId;
|
||||
currentLedDriverState->phase = LedDriverPhase_SetFunctionFrame;
|
||||
currentLedDriverState->ledIndex = 0;
|
||||
memset(LedDriverStates[ledDriverId].sourceLedValues, LED_BRIGHTNESS_LEVEL, LED_DRIVER_LED_COUNT);
|
||||
memset(LedDriverValues[ledDriverId], LED_BRIGHTNESS_LEVEL, LED_DRIVER_LED_COUNT);
|
||||
LedDisplay_SetText(3, "ABC");
|
||||
}
|
||||
|
||||
status_t LedSlaveDriver_Update(uint8_t ledDriverId) {
|
||||
status_t status = kStatus_Uhk_IdleSlave;
|
||||
led_driver_state_t *currentLedDriverState = LedDriverStates + ledDriverId;
|
||||
uint8_t *ledValues = LedDriverValues[ledDriverId];
|
||||
led_driver_state_t *currentLedDriverState = ledDriverStates + ledDriverId;
|
||||
uint8_t *ledDriverPhase = ¤tLedDriverState->phase;
|
||||
uint8_t ledDriverAddress = currentLedDriverState->i2cAddress;
|
||||
uint8_t *ledIndex = ¤tLedDriverState->ledIndex;
|
||||
@@ -101,19 +104,18 @@ status_t LedSlaveDriver_Update(uint8_t ledDriverId) {
|
||||
case LedDriverPhase_InitLedValues:
|
||||
updatePwmRegistersBuffer[0] = FRAME_REGISTER_PWM_FIRST + *ledIndex;
|
||||
uint8_t chunkSize = MIN(LED_DRIVER_LED_COUNT - *ledIndex, PMW_REGISTER_UPDATE_CHUNK_SIZE);
|
||||
memcpy(updatePwmRegistersBuffer+1, currentLedDriverState->sourceLedValues + *ledIndex, chunkSize);
|
||||
memcpy(updatePwmRegistersBuffer+1, ledValues + *ledIndex, chunkSize);
|
||||
status = I2cAsyncWrite(ledDriverAddress, updatePwmRegistersBuffer, chunkSize + 1);
|
||||
*ledIndex += chunkSize;
|
||||
if (*ledIndex >= LED_DRIVER_LED_COUNT) {
|
||||
*ledIndex = 0;
|
||||
#ifndef LED_DRIVER_FORCE_UPDATE
|
||||
memcpy(currentLedDriverState->targetLedValues, currentLedDriverState->sourceLedValues, LED_DRIVER_LED_COUNT);
|
||||
memcpy(currentLedDriverState->targetLedValues, ledValues, LED_DRIVER_LED_COUNT);
|
||||
*ledDriverPhase = LedDriverPhase_UpdateChangedLedValues;
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case LedDriverPhase_UpdateChangedLedValues: {
|
||||
uint8_t *sourceLedValues = currentLedDriverState->sourceLedValues;
|
||||
uint8_t *targetLedValues = currentLedDriverState->targetLedValues;
|
||||
|
||||
uint8_t lastLedChunkStartIndex = LED_DRIVER_LED_COUNT - PMW_REGISTER_UPDATE_CHUNK_SIZE;
|
||||
@@ -121,7 +123,7 @@ status_t LedSlaveDriver_Update(uint8_t ledDriverId) {
|
||||
|
||||
uint8_t count;
|
||||
for (count=0; count<LED_DRIVER_LED_COUNT; count++) {
|
||||
if (sourceLedValues[startLedIndex] != targetLedValues[startLedIndex]) {
|
||||
if (ledValues[startLedIndex] != targetLedValues[startLedIndex]) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -140,15 +142,15 @@ status_t LedSlaveDriver_Update(uint8_t ledDriverId) {
|
||||
uint8_t maxEndLedIndex = startLedIndex + maxChunkSize - 1;
|
||||
uint8_t endLedIndex = startLedIndex;
|
||||
for (uint8_t index=startLedIndex; index<=maxEndLedIndex; index++) {
|
||||
if (sourceLedValues[index] != targetLedValues[index]) {
|
||||
if (ledValues[index] != targetLedValues[index]) {
|
||||
endLedIndex = index;
|
||||
}
|
||||
}
|
||||
|
||||
updatePwmRegistersBuffer[0] = FRAME_REGISTER_PWM_FIRST + startLedIndex;
|
||||
uint8_t length = endLedIndex - startLedIndex + 1;
|
||||
memcpy(updatePwmRegistersBuffer+1, currentLedDriverState->sourceLedValues + startLedIndex, length);
|
||||
memcpy(currentLedDriverState->targetLedValues + startLedIndex, currentLedDriverState->sourceLedValues + startLedIndex, length);
|
||||
memcpy(updatePwmRegistersBuffer+1, ledValues + startLedIndex, length);
|
||||
memcpy(currentLedDriverState->targetLedValues + startLedIndex, ledValues + startLedIndex, length);
|
||||
status = I2cAsyncWrite(ledDriverAddress, updatePwmRegistersBuffer, length+1);
|
||||
*ledIndex += length;
|
||||
if (*ledIndex >= LED_DRIVER_LED_COUNT) {
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
|
||||
typedef struct {
|
||||
led_driver_phase_t phase;
|
||||
uint8_t sourceLedValues[LED_DRIVER_LED_COUNT];
|
||||
uint8_t targetLedValues[LED_DRIVER_LED_COUNT];
|
||||
uint8_t ledIndex;
|
||||
uint8_t i2cAddress;
|
||||
@@ -46,7 +45,7 @@
|
||||
|
||||
// Variables:
|
||||
|
||||
extern led_driver_state_t LedDriverStates[LED_DRIVER_MAX_COUNT];
|
||||
extern uint8_t LedDriverValues[LED_DRIVER_MAX_COUNT][LED_DRIVER_LED_COUNT];
|
||||
|
||||
// Functions:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user