Merge pull request #51 from UltimateHackingKeyboard/led-display
Add code to drive the LED display
This commit is contained in:
@@ -64,7 +64,7 @@ void InitLedDriver(void) {
|
|||||||
GPIO_WritePinOutput(LED_DRIVER_SDB_GPIO, LED_DRIVER_SDB_PIN, 1);
|
GPIO_WritePinOutput(LED_DRIVER_SDB_GPIO, LED_DRIVER_SDB_PIN, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitPeripherials(void)
|
void InitPeripherals(void)
|
||||||
{
|
{
|
||||||
InitLedDriver();
|
InitLedDriver();
|
||||||
InitTestLed();
|
InitTestLed();
|
||||||
|
|||||||
@@ -10,6 +10,6 @@
|
|||||||
|
|
||||||
// Functions:
|
// Functions:
|
||||||
|
|
||||||
void InitPeripherials(void);
|
void InitPeripherals(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@ volatile bool DisableKeyMatrixScanState;
|
|||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
InitClock();
|
InitClock();
|
||||||
InitPeripherials();
|
InitPeripherals();
|
||||||
KeyMatrix_Init(&keyMatrix);
|
KeyMatrix_Init(&keyMatrix);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "config/parse_keymap.h"
|
#include "config/parse_keymap.h"
|
||||||
#include "key_action.h"
|
#include "key_action.h"
|
||||||
#include "current_keymap.h"
|
#include "current_keymap.h"
|
||||||
|
#include "led_display.h"
|
||||||
|
|
||||||
static bool isDryRun;
|
static bool isDryRun;
|
||||||
|
|
||||||
@@ -180,13 +181,15 @@ parser_error_t ParseKeymap(serialized_buffer_t *buffer) {;
|
|||||||
const char *description = readString(buffer, &descriptionLen);
|
const char *description = readString(buffer, &descriptionLen);
|
||||||
uint16_t layerCount = readCompactLength(buffer);
|
uint16_t layerCount = readCompactLength(buffer);
|
||||||
|
|
||||||
(void)abbreviation;
|
|
||||||
(void)name;
|
(void)name;
|
||||||
(void)description;
|
(void)description;
|
||||||
if (layerCount != LAYER_COUNT) {
|
if (layerCount != LAYER_COUNT) {
|
||||||
return ParserError_InvalidLayerCount;
|
return ParserError_InvalidLayerCount;
|
||||||
}
|
}
|
||||||
isDryRun = !isDefault;
|
isDryRun = !isDefault;
|
||||||
|
if (!isDryRun) {
|
||||||
|
LedDisplay_SetText(abbreviationLen, abbreviation);
|
||||||
|
}
|
||||||
for (uint16_t layerIdx = 0; layerIdx < layerCount; layerIdx++) {
|
for (uint16_t layerIdx = 0; layerIdx < layerCount; layerIdx++) {
|
||||||
errorCode = parseLayer(buffer, layerIdx);
|
errorCode = parseLayer(buffer, layerIdx);
|
||||||
if (errorCode != ParserError_Success) {
|
if (errorCode != ParserError_Success) {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "peripherals/reset_button.h"
|
#include "peripherals/reset_button.h"
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
#include "i2c_watchdog.h"
|
#include "i2c_watchdog.h"
|
||||||
#include "led_driver.h"
|
#include "peripherals/led_driver.h"
|
||||||
#include "peripherals/merge_sensor.h"
|
#include "peripherals/merge_sensor.h"
|
||||||
#include "led_pwm.h"
|
#include "led_pwm.h"
|
||||||
#include "slave_scheduler.h"
|
#include "slave_scheduler.h"
|
||||||
@@ -50,8 +50,9 @@ void InitI2c() {
|
|||||||
I2C_MasterInit(I2C_EEPROM_BUS_BASEADDR, &masterConfig, sourceClock);
|
I2C_MasterInit(I2C_EEPROM_BUS_BASEADDR, &masterConfig, sourceClock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitPeripherials(void)
|
void InitPeripherals(void)
|
||||||
{
|
{
|
||||||
|
InitLedDriver();
|
||||||
InitResetButton();
|
InitResetButton();
|
||||||
InitMergeSensor();
|
InitMergeSensor();
|
||||||
ADC_Init();
|
ADC_Init();
|
||||||
|
|||||||
@@ -5,6 +5,6 @@
|
|||||||
|
|
||||||
// Functions:
|
// Functions:
|
||||||
|
|
||||||
extern void InitPeripherials();
|
extern void InitPeripherals();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+86
-6
@@ -1,13 +1,93 @@
|
|||||||
#include "led_display.h"
|
#include "led_display.h"
|
||||||
|
#include "slave_drivers/slave_driver_led_driver.h"
|
||||||
#include "layer.h"
|
#include "layer.h"
|
||||||
|
|
||||||
#define LAYER_LED_FIRST FRAME_REGISTER_PWM_FIRST + 13
|
static const uint16_t capitalLetterToSegmentSet[] = {
|
||||||
#define LAYER_LED_DISTANCE 16
|
0b0000000011110111,
|
||||||
|
0b0001001010001111,
|
||||||
|
0b0000000000111001,
|
||||||
|
0b0001001000001111,
|
||||||
|
0b0000000011111001,
|
||||||
|
0b0000000011110001,
|
||||||
|
0b0000000010111101,
|
||||||
|
0b0000000011110110,
|
||||||
|
0b0001001000001001,
|
||||||
|
0b0000000000001110,
|
||||||
|
0b0010010001110000,
|
||||||
|
0b0000000000111000,
|
||||||
|
0b0000010100110110,
|
||||||
|
0b0010000100110110,
|
||||||
|
0b0000000000111111,
|
||||||
|
0b0000000011110011,
|
||||||
|
0b0010000000111111,
|
||||||
|
0b0010000011110011,
|
||||||
|
0b0000000011101101,
|
||||||
|
0b0001001000000001,
|
||||||
|
0b0000000000111110,
|
||||||
|
0b0000110000110000,
|
||||||
|
0b0010100000110110,
|
||||||
|
0b0010110100000000,
|
||||||
|
0b0001010100000000,
|
||||||
|
0b0000110000001001,
|
||||||
|
};
|
||||||
|
|
||||||
uint8_t LedDisplayBrightness = 0xff;
|
static const uint16_t digitToSegmentSet[] = {
|
||||||
|
0b0000110000111111,
|
||||||
|
0b0000010000000110,
|
||||||
|
0b0000100010001011,
|
||||||
|
0b0000000011001111,
|
||||||
|
0b0000000011100110,
|
||||||
|
0b0010000001101001,
|
||||||
|
0b0000000011110111,
|
||||||
|
0b0001010000000001,
|
||||||
|
0b0000000011111111,
|
||||||
|
0b0000000011101111,
|
||||||
|
};
|
||||||
|
|
||||||
void LedDisplay_SetLayerLed(uint8_t layerId) {
|
static uint16_t characterToSegmentSet(char character) {
|
||||||
for (uint8_t i = 0; i < LAYER_COUNT; i++) {
|
switch (character) {
|
||||||
// LedDriver_WriteRegister(I2C_ADDRESS_LED_DRIVER_LEFT, LAYER_LED_FIRST + (i * LAYER_LED_DISTANCE), LedDisplayBrightness * (layerId == i + 1));
|
case 'A' ... 'Z':
|
||||||
|
return capitalLetterToSegmentSet[character - 'A'];
|
||||||
|
case '0' ... '9':
|
||||||
|
return digitToSegmentSet[character - '0'];
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LedDisplay_SetText(uint8_t length, const char* text) {
|
||||||
|
uint64_t allSegmentSets = 0;
|
||||||
|
|
||||||
|
switch (length) {
|
||||||
|
case 3:
|
||||||
|
allSegmentSets = (uint64_t)characterToSegmentSet(text[2]) << 28;
|
||||||
|
case 2:
|
||||||
|
allSegmentSets |= characterToSegmentSet(text[1]) << 14;
|
||||||
|
case 1:
|
||||||
|
allSegmentSets |= characterToSegmentSet(text[0]);
|
||||||
|
}
|
||||||
|
LedDriverStates[LedDriverId_Left].ledValues[11] = allSegmentSets & 0b00000001 ? 255 : 0;
|
||||||
|
LedDriverStates[LedDriverId_Left].ledValues[12] = allSegmentSets & 0b00000010 ? 255 : 0;
|
||||||
|
allSegmentSets >>= 2;
|
||||||
|
for (uint8_t i = 24; i <= 136; i += 16) {
|
||||||
|
for (uint8_t j = 0; j < 5; j++) {
|
||||||
|
LedDriverStates[LedDriverId_Left].ledValues[i + j] = allSegmentSets & 1 << j ? 255 : 0;
|
||||||
|
}
|
||||||
|
allSegmentSets >>= 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LedDisplay_SetLayer(uint8_t layerId) {
|
||||||
|
uint8_t layerLedValues[3] = { 0 };
|
||||||
|
|
||||||
|
if (layerId >= LAYER_ID_MOD && layerId <= LAYER_ID_MOUSE) {
|
||||||
|
layerLedValues[layerId - 1] = 0xFF;
|
||||||
|
}
|
||||||
|
LedDriverStates[LedDriverId_Left].ledValues[13] = layerLedValues[0];
|
||||||
|
LedDriverStates[LedDriverId_Left].ledValues[29] = layerLedValues[1];
|
||||||
|
LedDriverStates[LedDriverId_Left].ledValues[45] = layerLedValues[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
void LedDisplay_SetIcon(led_display_icon_t icon, bool isEnabled) {
|
||||||
|
LedDriverStates[LedDriverId_Left].ledValues[8 + icon] = isEnabled ? 255 : 0;
|
||||||
|
}
|
||||||
|
|||||||
+16
-3
@@ -1,10 +1,23 @@
|
|||||||
#ifndef __LED_DISPLAY_H__
|
#ifndef __LED_DISPLAY_H__
|
||||||
#define __LED_DISPLAY_H__
|
#define __LED_DISPLAY_H__
|
||||||
|
|
||||||
#include "led_driver.h"
|
// Includes:
|
||||||
|
|
||||||
extern uint8_t LedDisplayBrightness;
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
void LedDisplay_SetLayerLed(uint8_t layerId);
|
// Typedefs:
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
LedDisplayIcon_CapsLock,
|
||||||
|
LedDisplayIcon_Agent,
|
||||||
|
LedDisplayIcon_Adaptive,
|
||||||
|
} led_display_icon_t;
|
||||||
|
|
||||||
|
// Functions:
|
||||||
|
|
||||||
|
void LedDisplay_SetText(uint8_t length, const char* text);
|
||||||
|
void LedDisplay_SetLayer(uint8_t layerId);
|
||||||
|
void LedDisplay_SetIcon(led_display_icon_t icon, bool isEnabled);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+2
-3
@@ -2,7 +2,7 @@
|
|||||||
#include "init_clock.h"
|
#include "init_clock.h"
|
||||||
#include "init_peripherals.h"
|
#include "init_peripherals.h"
|
||||||
#include "usb_composite_device.h"
|
#include "usb_composite_device.h"
|
||||||
#include "led_driver.h"
|
#include "peripherals/led_driver.h"
|
||||||
#include "key_action.h"
|
#include "key_action.h"
|
||||||
#include "slave_scheduler.h"
|
#include "slave_scheduler.h"
|
||||||
#include "peripherals/test_led.h"
|
#include "peripherals/test_led.h"
|
||||||
@@ -62,15 +62,14 @@ void UpdateUsbReports()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
InitPeripherials();
|
|
||||||
InitClock();
|
InitClock();
|
||||||
|
InitPeripherals();
|
||||||
|
|
||||||
if (Wormhole.magicNumber == WORMHOLE_MAGIC_NUMBER && Wormhole.enumerationMode == EnumerationMode_BusPal) {
|
if (Wormhole.magicNumber == WORMHOLE_MAGIC_NUMBER && Wormhole.enumerationMode == EnumerationMode_BusPal) {
|
||||||
Wormhole.magicNumber = 0;
|
Wormhole.magicNumber = 0;
|
||||||
init_hardware();
|
init_hardware();
|
||||||
handleUsbBusPalCommand();
|
handleUsbBusPalCommand();
|
||||||
} else {
|
} else {
|
||||||
LedDriver_InitAllLeds(1);
|
|
||||||
InitSlaveScheduler();
|
InitSlaveScheduler();
|
||||||
KeyMatrix_Init(&KeyMatrix);
|
KeyMatrix_Init(&KeyMatrix);
|
||||||
UpdateUsbReports();
|
UpdateUsbReports();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "led_driver.h"
|
#include "peripherals/led_driver.h"
|
||||||
#include "i2c_addresses.h"
|
#include "i2c_addresses.h"
|
||||||
|
|
||||||
void LedDriver_InitAllLeds(char isEnabled)
|
void InitLedDriver()
|
||||||
{
|
{
|
||||||
CLOCK_EnableClock(LED_DRIVER_SDB_CLOCK);
|
CLOCK_EnableClock(LED_DRIVER_SDB_CLOCK);
|
||||||
PORT_SetPinMux(LED_DRIVER_SDB_PORT, LED_DRIVER_SDB_PIN, kPORT_MuxAsGpio);
|
PORT_SetPinMux(LED_DRIVER_SDB_PORT, LED_DRIVER_SDB_PIN, kPORT_MuxAsGpio);
|
||||||
@@ -44,6 +44,6 @@
|
|||||||
|
|
||||||
// Functions:
|
// Functions:
|
||||||
|
|
||||||
extern void LedDriver_InitAllLeds(char isEnabled);
|
extern void InitLedDriver();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
#include "slave_drivers/slave_driver_led_driver.h"
|
#include "slave_drivers/slave_driver_led_driver.h"
|
||||||
#include "slave_scheduler.h"
|
#include "slave_scheduler.h"
|
||||||
|
#include "led_display.h"
|
||||||
|
|
||||||
led_driver_state_t ledDriverStates[LED_DRIVER_MAX_COUNT] = {
|
led_driver_state_t LedDriverStates[LED_DRIVER_MAX_COUNT] = {
|
||||||
{
|
{
|
||||||
.i2cAddress = I2C_ADDRESS_LED_DRIVER_RIGHT,
|
.i2cAddress = I2C_ADDRESS_LED_DRIVER_RIGHT,
|
||||||
.setupLedControlRegistersCommand = {
|
.setupLedControlRegistersCommand = {
|
||||||
@@ -58,15 +59,16 @@ uint8_t setFrame1Buffer[] = {LED_DRIVER_REGISTER_FRAME, LED_DRIVER_FRAME_1};
|
|||||||
uint8_t updatePwmRegistersBuffer[PWM_REGISTER_BUFFER_LENGTH];
|
uint8_t updatePwmRegistersBuffer[PWM_REGISTER_BUFFER_LENGTH];
|
||||||
|
|
||||||
void LedSlaveDriver_Init(uint8_t ledDriverId) {
|
void LedSlaveDriver_Init(uint8_t ledDriverId) {
|
||||||
led_driver_state_t *currentLedDriverState = ledDriverStates + ledDriverId;
|
led_driver_state_t *currentLedDriverState = LedDriverStates + ledDriverId;
|
||||||
currentLedDriverState->phase = LedDriverPhase_SetFunctionFrame;
|
currentLedDriverState->phase = LedDriverPhase_SetFunctionFrame;
|
||||||
currentLedDriverState->ledIndex = 0;
|
currentLedDriverState->ledIndex = 0;
|
||||||
ledDriverStates[LedDriverId_Left].setupLedControlRegistersCommand[7] |= 0b00000010; // Enable the LED of the ISO key.
|
LedDriverStates[LedDriverId_Left].setupLedControlRegistersCommand[7] |= 0b00000010; // Enable the LED of the ISO key.
|
||||||
SetLeds(0xff);
|
SetLeds(0xff);
|
||||||
|
LedDisplay_SetText(3, "ABC");
|
||||||
}
|
}
|
||||||
|
|
||||||
void LedSlaveDriver_Update(uint8_t ledDriverId) {
|
void LedSlaveDriver_Update(uint8_t ledDriverId) {
|
||||||
led_driver_state_t *currentLedDriverState = ledDriverStates + ledDriverId;
|
led_driver_state_t *currentLedDriverState = LedDriverStates + ledDriverId;
|
||||||
uint8_t *ledDriverPhase = ¤tLedDriverState->phase;
|
uint8_t *ledDriverPhase = ¤tLedDriverState->phase;
|
||||||
uint8_t ledDriverAddress = currentLedDriverState->i2cAddress;
|
uint8_t ledDriverAddress = currentLedDriverState->i2cAddress;
|
||||||
uint8_t *ledIndex = ¤tLedDriverState->ledIndex;
|
uint8_t *ledIndex = ¤tLedDriverState->ledIndex;
|
||||||
@@ -106,6 +108,6 @@ void LedSlaveDriver_Update(uint8_t ledDriverId) {
|
|||||||
void SetLeds(uint8_t ledBrightness)
|
void SetLeds(uint8_t ledBrightness)
|
||||||
{
|
{
|
||||||
for (uint8_t i=0; i<LED_DRIVER_MAX_COUNT; i++) {
|
for (uint8_t i=0; i<LED_DRIVER_MAX_COUNT; i++) {
|
||||||
memset(&ledDriverStates[i].ledValues, ledBrightness, LED_DRIVER_LED_COUNT);
|
memset(&LedDriverStates[i].ledValues, ledBrightness, LED_DRIVER_LED_COUNT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
// Includes:
|
// Includes:
|
||||||
|
|
||||||
#include "fsl_common.h"
|
#include "fsl_common.h"
|
||||||
#include "led_driver.h"
|
#include "peripherals/led_driver.h"
|
||||||
|
|
||||||
// Macros:
|
// Macros:
|
||||||
|
|
||||||
@@ -37,6 +37,10 @@
|
|||||||
uint8_t setupLedControlRegistersCommand[LED_CONTROL_REGISTERS_COMMAND_LENGTH];
|
uint8_t setupLedControlRegistersCommand[LED_CONTROL_REGISTERS_COMMAND_LENGTH];
|
||||||
} led_driver_state_t;
|
} led_driver_state_t;
|
||||||
|
|
||||||
|
// Variables:
|
||||||
|
|
||||||
|
extern led_driver_state_t LedDriverStates[LED_DRIVER_MAX_COUNT];
|
||||||
|
|
||||||
// Functions:
|
// Functions:
|
||||||
|
|
||||||
extern void LedSlaveDriver_Init(uint8_t ledDriverId);
|
extern void LedSlaveDriver_Init(uint8_t ledDriverId);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include "system_properties.h"
|
#include "system_properties.h"
|
||||||
#include "peripherals/test_led.h"
|
#include "peripherals/test_led.h"
|
||||||
#include "i2c_addresses.h"
|
#include "i2c_addresses.h"
|
||||||
#include "led_driver.h"
|
#include "peripherals/led_driver.h"
|
||||||
#include "peripherals/merge_sensor.h"
|
#include "peripherals/merge_sensor.h"
|
||||||
#include "config/parse_config.h"
|
#include "config/parse_config.h"
|
||||||
#include "config/config_state.h"
|
#include "config/config_state.h"
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ void UpdateActiveUsbReports()
|
|||||||
static uint8_t previousModifiers = 0;
|
static uint8_t previousModifiers = 0;
|
||||||
uint8_t activeLayer = getActiveLayer();
|
uint8_t activeLayer = getActiveLayer();
|
||||||
|
|
||||||
|
LedDisplay_SetLayer(activeLayer);
|
||||||
for (uint8_t slotId=0; slotId<SLOT_COUNT; slotId++) {
|
for (uint8_t slotId=0; slotId<SLOT_COUNT; slotId++) {
|
||||||
for (uint8_t keyId=0; keyId<MAX_KEY_COUNT_PER_MODULE; keyId++) {
|
for (uint8_t keyId=0; keyId<MAX_KEY_COUNT_PER_MODULE; keyId++) {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user