Rename the bridge_slaves directory to slave_drivers.

This commit is contained in:
László Monda
2017-05-04 23:43:12 +02:00
parent f1f5c4141d
commit 03a18e7acb
7 changed files with 5 additions and 5 deletions

View File

@@ -0,0 +1,89 @@
#include "bridge_slave_led_driver.h"
#include "led_driver.h"
#define BUFFER_SIZE (LED_DRIVER_LED_COUNT + 1)
uint8_t ledsBuffer[BUFFER_SIZE] = {FRAME_REGISTER_PWM_FIRST};
uint8_t ledDriverStates[2] = {0};
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};
bool BridgeSlaveLedDriverHandler(uint8_t ledDriverId) {
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_SetFunctionFrame:
I2cAsyncWrite(ledDriverAddress, setFunctionFrameBuffer, sizeof(setFunctionFrameBuffer));
*ledDriverState = LedDriverState_SetShutdownModeNormal;
break;
case LedDriverState_SetShutdownModeNormal:
I2cAsyncWrite(ledDriverAddress, setShutdownModeNormalBuffer, sizeof(setShutdownModeNormalBuffer));
*ledDriverState = LedDriverState_SetFrame1;
break;
case LedDriverState_SetFrame1:
I2cAsyncWrite(ledDriverAddress, setFrame1Buffer, sizeof(setFrame1Buffer));
*ledDriverState = LedDriverState_InitLedControlRegisters;
break;
case LedDriverState_InitLedControlRegisters:
I2cAsyncWrite(ledDriverAddress, ledControlBuffer, sizeof(ledControlBufferLeft));
*ledDriverState = LedDriverState_Initialized;
break;
case LedDriverState_Initialized:
I2cAsyncWrite(ledDriverAddress, ledsBuffer, BUFFER_SIZE);
break;
}
return true;
}
void SetLeds(uint8_t ledBrightness)
{
memset(ledsBuffer+1, ledBrightness, LED_DRIVER_LED_COUNT);
}

View File

@@ -0,0 +1,23 @@
#ifndef __BRIDGE_SLAVE_LED_DRIVER_H__
#define __BRIDGE_SLAVE_LED_DRIVER_H__
// Includes:
#include "fsl_common.h"
// Typedefs:
typedef enum {
LedDriverState_SetFunctionFrame,
LedDriverState_SetShutdownModeNormal,
LedDriverState_SetFrame1,
LedDriverState_InitLedControlRegisters,
LedDriverState_Initialized,
} LedDriverState;
// Functions:
extern bool BridgeSlaveLedDriverHandler(uint8_t ledDriverId);
extern void SetLeds(uint8_t ledBrightness);
#endif

View File

@@ -0,0 +1,71 @@
#include "i2c_addresses.h"
#include "i2c.h"
#include "bridge_slave_uhk_module.h"
#include "bridge_protocol.h"
#include "main.h"
#include "peripherals/test_led.h"
#include "test_states.h"
uhk_module_state_t UhkModuleStates[UHK_MODULE_MAX_COUNT];
uhk_module_field_t currentUhkModuleField = UhkModuleField_SendKeystatesRequestCommand;
uhk_module_state_t uhkModuleExternalStates[UHK_MODULE_MAX_COUNT];
uint8_t txBuffer[2];
void InitUhkModules()
{
for (uint8_t moduleId=0; moduleId<UHK_MODULE_MAX_COUNT; moduleId++) {
uhk_module_state_t* uhkModuleState = UhkModuleStates + moduleId;
uhkModuleState->isTestLedOn = true;
uhkModuleState->ledPwmBrightness = 0x64;
}
}
bool BridgeSlaveUhkModuleHandler(uint8_t uhkModuleId)
{
uhk_module_state_t *uhkModuleInternalState = UhkModuleStates + uhkModuleId;
//uhk_module_state_t *uhkModuleExternalState = uhkModuleExternalStates + uhkModuleId;
switch (currentUhkModuleField) {
case UhkModuleField_SendKeystatesRequestCommand:
txBuffer[0] = BridgeCommand_GetKeyStates;
I2cAsyncWrite(I2C_ADDRESS_LEFT_KEYBOARD_HALF, txBuffer, 1);
currentUhkModuleField = UhkModuleField_ReceiveKeystates;
break;
case UhkModuleField_ReceiveKeystates:
I2cAsyncRead(I2C_ADDRESS_LEFT_KEYBOARD_HALF, CurrentKeyStates[SLOT_ID_LEFT_KEYBOARD_HALF], LEFT_KEYBOARD_HALF_KEY_COUNT);
currentUhkModuleField = UhkModuleField_SendPwmBrightnessCommand;
break;
case UhkModuleField_SendPwmBrightnessCommand:
txBuffer[0] = BridgeCommand_SetLedPwmBrightness;
txBuffer[1] = uhkModuleInternalState->ledPwmBrightness;
I2cAsyncWrite(I2C_ADDRESS_LEFT_KEYBOARD_HALF, txBuffer, 2);
currentUhkModuleField = UhkModuleField_SendTestLedCommand;
break;
case UhkModuleField_SendTestLedCommand:
txBuffer[0] = BridgeCommand_SetTestLed;
txBuffer[1] = uhkModuleInternalState->isTestLedOn;
I2cAsyncWrite(I2C_ADDRESS_LEFT_KEYBOARD_HALF, txBuffer, 2);
currentUhkModuleField = UhkModuleField_SendDisableKeyMatrixScanState;
break;
case UhkModuleField_SendDisableKeyMatrixScanState:
txBuffer[0] = BridgeCommand_SetDisableKeyMatrixScanState;
txBuffer[1] = TestStates.disableKeyMatrixScan;
I2cAsyncWrite(I2C_ADDRESS_LEFT_KEYBOARD_HALF, txBuffer, 2);
currentUhkModuleField = UhkModuleField_SendLedPwmBrightness;
break;
case UhkModuleField_SendLedPwmBrightness:
txBuffer[0] = BridgeCommand_SetDisableKeyMatrixScanState;
txBuffer[1] = TestStates.disableKeyMatrixScan;
I2cAsyncWrite(I2C_ADDRESS_LEFT_KEYBOARD_HALF, txBuffer, 2);
currentUhkModuleField = UhkModuleField_DisableLedSdb;
break;
case UhkModuleField_DisableLedSdb:
txBuffer[0] = BridgeCommand_SetDisableLedSdb;
txBuffer[1] = TestStates.disableLedSdb;
I2cAsyncWrite(I2C_ADDRESS_LEFT_KEYBOARD_HALF, txBuffer, 2);
currentUhkModuleField = UhkModuleField_SendKeystatesRequestCommand;
break;
}
return true;
}

View File

@@ -0,0 +1,38 @@
#ifndef __BRIDGE_SLAVE_UHK_MODULE_H__
#define __BRIDGE_SLAVE_UHK_MODULE_H__
// Includes:
#include "fsl_common.h"
// Macros:
#define UHK_MODULE_MAX_COUNT 1
// Typedefs:
typedef enum {
UhkModuleField_SendKeystatesRequestCommand,
UhkModuleField_ReceiveKeystates,
UhkModuleField_SendPwmBrightnessCommand,
UhkModuleField_SendTestLedCommand,
UhkModuleField_SendDisableKeyMatrixScanState,
UhkModuleField_SendLedPwmBrightness,
UhkModuleField_DisableLedSdb,
} uhk_module_field_t;
typedef struct {
uint8_t ledPwmBrightness;
bool isTestLedOn;
} uhk_module_state_t;
// Variables:
extern uhk_module_state_t UhkModuleStates[UHK_MODULE_MAX_COUNT];
// Functions:
extern void InitUhkModules();
extern bool BridgeSlaveUhkModuleHandler(uint8_t uhkModuleId);
#endif