Add uhk_slave_t.disconnect() callback so that upon disconnecting the left keyboard half, the left LED driver IC can be marked as disconnected too, so it'll be reinitialized upon reconnect. This usually didn't happen because LED states are cached so the LED drivers are rarely spoken to.
This commit is contained in:
@@ -141,3 +141,10 @@ status_t UhkModuleSlaveDriver_Update(uint8_t uhkModuleDriverId)
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
void UhkModuleSlaveDriver_Disconnect(uint8_t uhkModuleDriverId)
|
||||
{
|
||||
if (uhkModuleDriverId == SlaveId_LeftKeyboardHalf) {
|
||||
Slaves[SlaveId_LeftLedDriver].isConnected = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,5 +57,6 @@
|
||||
|
||||
void UhkModuleSlaveDriver_Init(uint8_t uhkModuleDriverId);
|
||||
status_t UhkModuleSlaveDriver_Update(uint8_t uhkModuleDriverId);
|
||||
void UhkModuleSlaveDriver_Disconnect(uint8_t uhkModuleDriverId);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -13,7 +13,7 @@ static uint8_t previousSlaveId;
|
||||
static uint8_t currentSlaveId;
|
||||
|
||||
uhk_slave_t Slaves[] = {
|
||||
{ .init = UhkModuleSlaveDriver_Init, .update = UhkModuleSlaveDriver_Update, .perDriverId = UhkModuleDriverId_LeftKeyboardHalf },
|
||||
{ .init = UhkModuleSlaveDriver_Init, .update = UhkModuleSlaveDriver_Update, .perDriverId = UhkModuleDriverId_LeftKeyboardHalf, .disconnect = UhkModuleSlaveDriver_Disconnect },
|
||||
{ .init = UhkModuleSlaveDriver_Init, .update = UhkModuleSlaveDriver_Update, .perDriverId = UhkModuleDriverId_LeftAddon },
|
||||
{ .init = UhkModuleSlaveDriver_Init, .update = UhkModuleSlaveDriver_Update, .perDriverId = UhkModuleDriverId_RightAddon },
|
||||
{ .init = LedSlaveDriver_Init, .update = LedSlaveDriver_Update, .perDriverId = LedDriverId_Right },
|
||||
@@ -31,7 +31,11 @@ static void masterCallback(I2C_Type *base, i2c_master_handle_t *handle, status_t
|
||||
uhk_slave_t *currentSlave = Slaves + currentSlaveId;
|
||||
|
||||
if (isFirstIteration) {
|
||||
bool wasPreviousSlaveConnected = previousSlave->isConnected;
|
||||
previousSlave->isConnected = previousStatus == kStatus_Success;
|
||||
if (wasPreviousSlaveConnected && !previousSlave->isConnected && previousSlave->disconnect) {
|
||||
previousSlave->disconnect(previousSlaveId);
|
||||
}
|
||||
isFirstIteration = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,11 +17,13 @@
|
||||
|
||||
typedef void (slave_init_t)(uint8_t);
|
||||
typedef status_t (slave_update_t)(uint8_t);
|
||||
typedef void (slave_disconnect_t)(uint8_t);
|
||||
|
||||
typedef struct {
|
||||
uint8_t perDriverId; // Identifies the slave instance on a per-driver basis
|
||||
slave_init_t *init;
|
||||
slave_update_t *update;
|
||||
slave_disconnect_t *disconnect;
|
||||
bool isConnected;
|
||||
} uhk_slave_t;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user