Skip to content

Commit

Permalink
Merge branch 'master' of github.com:UltimateHackingKeyboard/firmware
Browse files Browse the repository at this point in the history
  • Loading branch information
mondalaci committed Oct 21, 2022
2 parents a7af15a + e338b23 commit a2ad729
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 124 deletions.
34 changes: 17 additions & 17 deletions right/src/slave_drivers/is31fl3xxx_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,9 @@ void LedSlaveDriver_Init(uint8_t ledDriverId)
currentLedDriverState->ledIndex = 0;
}

status_t LedSlaveDriver_Update(uint8_t ledDriverId)
slave_result_t LedSlaveDriver_Update(uint8_t ledDriverId)
{
status_t status = kStatus_Uhk_IdleSlave;
slave_result_t res = { .status = kStatus_Uhk_IdleSlave, .hold = false };
uint8_t *ledValues = LedDriverValues[ledDriverId];
led_driver_state_t *currentLedDriverState = ledDriverStates + ledDriverId;
uint8_t *ledDriverPhase = &currentLedDriverState->phase;
Expand All @@ -248,22 +248,22 @@ status_t LedSlaveDriver_Update(uint8_t ledDriverId)

switch (*ledDriverPhase) {
case LedDriverPhase_UnlockCommandRegister1:
status = I2cAsyncWrite(ledDriverAddress, unlockCommandRegisterOnce, sizeof(unlockCommandRegisterOnce));
res.status = I2cAsyncWrite(ledDriverAddress, unlockCommandRegisterOnce, sizeof(unlockCommandRegisterOnce));
*ledDriverPhase = LedDriverPhase_SetFunctionFrame;
break;
case LedDriverPhase_SetFunctionFrame:
if (ledDriverId == LedDriverId_Left && !Slaves[SlaveId_LeftKeyboardHalf].isConnected) {
break;
}
if (currentLedDriverState->ledDriverIc == LedDriverIc_IS31FL3731) {
status = I2cAsyncWrite(ledDriverAddress, setFunctionFrameBuffer, sizeof(setFunctionFrameBuffer));
res.status = I2cAsyncWrite(ledDriverAddress, setFunctionFrameBuffer, sizeof(setFunctionFrameBuffer));
} else {
status = I2cAsyncWrite(ledDriverAddress, setFrame4Buffer, sizeof(setFrame4Buffer));
res.status = I2cAsyncWrite(ledDriverAddress, setFrame4Buffer, sizeof(setFrame4Buffer));
}
*ledDriverPhase = LedDriverPhase_SetShutdownModeNormal;
break;
case LedDriverPhase_SetShutdownModeNormal:
status = I2cAsyncWrite(ledDriverAddress, currentLedDriverState->setShutdownModeNormalBuffer, currentLedDriverState->setShutdownModeNormalBufferLength);
res.status = I2cAsyncWrite(ledDriverAddress, currentLedDriverState->setShutdownModeNormalBuffer, currentLedDriverState->setShutdownModeNormalBufferLength);
switch (currentLedDriverState->ledDriverIc) {
case LedDriverIc_IS31FL3199:
*ledDriverPhase = LedDriverPhase_InitLedValues;
Expand All @@ -277,36 +277,36 @@ status_t LedSlaveDriver_Update(uint8_t ledDriverId)
}
break;
case LedDriverPhase_SetGlobalCurrent:
status = I2cAsyncWrite(ledDriverAddress, setGlobalCurrentBuffer, sizeof(setGlobalCurrentBuffer));
res.status = I2cAsyncWrite(ledDriverAddress, setGlobalCurrentBuffer, sizeof(setGlobalCurrentBuffer));
*ledDriverPhase = LedDriverPhase_UnlockCommandRegister2;
break;
case LedDriverPhase_UnlockCommandRegister2:
status = I2cAsyncWrite(ledDriverAddress, unlockCommandRegisterOnce, sizeof(unlockCommandRegisterOnce));
res.status = I2cAsyncWrite(ledDriverAddress, unlockCommandRegisterOnce, sizeof(unlockCommandRegisterOnce));
*ledDriverPhase = LedDriverPhase_SetFrame1;
break;
case LedDriverPhase_SetFrame1:
status = I2cAsyncWrite(ledDriverAddress, setFrame1Buffer, sizeof(setFrame1Buffer));
res.status = I2cAsyncWrite(ledDriverAddress, setFrame1Buffer, sizeof(setFrame1Buffer));
*ledDriverPhase = LedDriverPhase_InitLedControlRegisters;
break;
case LedDriverPhase_InitLedControlRegisters:
status = I2cAsyncWrite(ledDriverAddress, currentLedDriverState->setupLedControlRegistersCommand, currentLedDriverState->setupLedControlRegistersCommandLength);
res.status = I2cAsyncWrite(ledDriverAddress, currentLedDriverState->setupLedControlRegistersCommand, currentLedDriverState->setupLedControlRegistersCommandLength);
*ledDriverPhase = currentLedDriverState->ledDriverIc == LedDriverIc_IS31FL3731
? LedDriverPhase_InitLedValues
: LedDriverPhase_UnlockCommandRegister3;
break;
case LedDriverPhase_UnlockCommandRegister3:
status = I2cAsyncWrite(ledDriverAddress, unlockCommandRegisterOnce, sizeof(unlockCommandRegisterOnce));
res.status = I2cAsyncWrite(ledDriverAddress, unlockCommandRegisterOnce, sizeof(unlockCommandRegisterOnce));
*ledDriverPhase = LedDriverPhase_SetFrame2;
break;
case LedDriverPhase_SetFrame2:
status = I2cAsyncWrite(ledDriverAddress, setFrame2Buffer, sizeof(setFrame2Buffer));
res.status = I2cAsyncWrite(ledDriverAddress, setFrame2Buffer, sizeof(setFrame2Buffer));
*ledDriverPhase = LedDriverPhase_InitLedValues;
break;
case LedDriverPhase_InitLedValues:
updatePwmRegistersBuffer[0] = frameRegisterPwmFirst + *ledIndex;
uint8_t chunkSize = MIN(ledCount - *ledIndex, PMW_REGISTER_UPDATE_CHUNK_SIZE);
memcpy(updatePwmRegistersBuffer+1, ledValues + *ledIndex, chunkSize);
status = I2cAsyncWrite(ledDriverAddress, updatePwmRegistersBuffer, chunkSize + 1);
res.status = I2cAsyncWrite(ledDriverAddress, updatePwmRegistersBuffer, chunkSize + 1);
*ledIndex += chunkSize;
if (*ledIndex >= ledCount) {
*ledIndex = 0;
Expand All @@ -317,7 +317,7 @@ status_t LedSlaveDriver_Update(uint8_t ledDriverId)
}
break;
case LedDriverPhase_SetLedBrightness:
status = I2cAsyncWrite(ledDriverAddress, setLedBrightness, sizeof(setLedBrightness));
res.status = I2cAsyncWrite(ledDriverAddress, setLedBrightness, sizeof(setLedBrightness));
*ledDriverPhase = LedDriverPhase_UpdateChangedLedValues;
break;
case LedDriverPhase_UpdateChangedLedValues: {
Expand Down Expand Up @@ -356,7 +356,7 @@ status_t LedSlaveDriver_Update(uint8_t ledDriverId)
uint8_t length = endLedIndex - startLedIndex + 1;
memcpy(updatePwmRegistersBuffer+1, ledValues + startLedIndex, length);
memcpy(currentLedDriverState->targetLedValues + startLedIndex, ledValues + startLedIndex, length);
status = I2cAsyncWrite(ledDriverAddress, updatePwmRegistersBuffer, length+1);
res.status = I2cAsyncWrite(ledDriverAddress, updatePwmRegistersBuffer, length+1);
*ledIndex += length;
if (*ledIndex >= ledCount) {
*ledIndex = 0;
Expand All @@ -368,10 +368,10 @@ status_t LedSlaveDriver_Update(uint8_t ledDriverId)
break;
}
case LedDriverPhase_UpdateData:
status = I2cAsyncWrite(ledDriverAddress, updateDataBuffer, sizeof(updateDataBuffer));
res.status = I2cAsyncWrite(ledDriverAddress, updateDataBuffer, sizeof(updateDataBuffer));
*ledDriverPhase = LedDriverPhase_UpdateChangedLedValues;
break;
}

return status;
return res;
}
3 changes: 2 additions & 1 deletion right/src/slave_drivers/is31fl3xxx_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "fsl_common.h"
#include "peripherals/led_driver.h"
#include "slave_scheduler.h"

// Macros:

Expand Down Expand Up @@ -81,6 +82,6 @@
void LedSlaveDriver_DisableLeds(void);
void LedSlaveDriver_UpdateLeds(void);
void LedSlaveDriver_Init(uint8_t ledDriverId);
status_t LedSlaveDriver_Update(uint8_t ledDriverId);
slave_result_t LedSlaveDriver_Update(uint8_t ledDriverId);

#endif
26 changes: 15 additions & 11 deletions right/src/slave_drivers/kboot_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,29 @@ void KbootSlaveDriver_Init(uint8_t kbootInstanceId)
{
}

status_t KbootSlaveDriver_Update(uint8_t kbootInstanceId)
slave_result_t KbootSlaveDriver_Update(uint8_t kbootInstanceId)
{
status_t status = kStatus_Uhk_IdleSlave;
slave_result_t res = { .status = kStatus_Uhk_IdleSlave, .hold = false };

switch (KbootDriverState.command) {
case KbootCommand_Idle:
break;
case KbootCommand_Ping:
switch (KbootDriverState.phase) {
case KbootPhase_SendPing:
status = tx(pingCommand, sizeof(pingCommand));
res.status = tx(pingCommand, sizeof(pingCommand));
KbootDriverState.phase = KbootPhase_CheckPingStatus;
break;
case KbootPhase_CheckPingStatus:
KbootDriverState.status = Slaves[SlaveId_KbootDriver].previousStatus;
KbootDriverState.phase = KbootDriverState.status == kStatus_Success
? KbootPhase_ReceivePingResponse
: KbootPhase_SendPing;
return kStatus_Uhk_IdleCycle;
res.status = kStatus_Uhk_IdleCycle;
res.hold = true;
break;
case KbootPhase_ReceivePingResponse:
status = rx(KBOOT_PACKAGE_LENGTH_PING_RESPONSE);
res.status = rx(KBOOT_PACKAGE_LENGTH_PING_RESPONSE);
KbootDriverState.phase = KbootPhase_CheckPingResponseStatus;
break;
case KbootPhase_CheckPingResponseStatus:
Expand All @@ -52,31 +54,33 @@ status_t KbootSlaveDriver_Update(uint8_t kbootInstanceId)
KbootDriverState.command = KbootCommand_Idle;
} else {
KbootDriverState.phase = KbootPhase_SendPing;
return kStatus_Uhk_IdleCycle;
res.status = kStatus_Uhk_IdleCycle;
res.hold = true;
}
break;
}
break;
case KbootCommand_Reset:
switch (KbootDriverState.phase) {
case KbootPhase_SendReset:
status = tx(resetCommand, sizeof(resetCommand));
res.status = tx(resetCommand, sizeof(resetCommand));
KbootDriverState.phase = KbootPhase_ReceiveResetAck;
break;
case KbootPhase_ReceiveResetAck:
status = rx(KBOOT_PACKAGE_LENGTH_ACK);
res.status = rx(KBOOT_PACKAGE_LENGTH_ACK);
KbootDriverState.phase = KbootPhase_ReceiveResetGenericResponse;
break;
case KbootPhase_ReceiveResetGenericResponse:
status = rx(KBOOT_PACKAGE_LENGTH_GENERIC_RESPONSE);
res.status = rx(KBOOT_PACKAGE_LENGTH_GENERIC_RESPONSE);
KbootDriverState.phase = KbootPhase_CheckResetSendAck;
break;
case KbootPhase_CheckResetSendAck:
status = tx(ackMessage, sizeof(ackMessage));
res.status = tx(ackMessage, sizeof(ackMessage));
KbootDriverState.command = KbootCommand_Idle;
break;
}
break;
}

return status;
return res;
}
3 changes: 2 additions & 1 deletion right/src/slave_drivers/kboot_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// Includes:

#include "fsl_common.h"
#include "slave_scheduler.h"

// Macros:

Expand Down Expand Up @@ -52,6 +53,6 @@
// Functions:

void KbootSlaveDriver_Init(uint8_t kbootInstanceId);
status_t KbootSlaveDriver_Update(uint8_t kbootInstanceId);
slave_result_t KbootSlaveDriver_Update(uint8_t kbootInstanceId);

#endif
Loading

0 comments on commit a2ad729

Please sign in to comment.