Merge pull request #51 from UltimateHackingKeyboard/led-display

Add code to drive the LED display
This commit is contained in:
László Monda
2017-07-14 23:18:28 +02:00
committed by GitHub
15 changed files with 132 additions and 29 deletions

View File

@@ -64,7 +64,7 @@ void InitLedDriver(void) {
GPIO_WritePinOutput(LED_DRIVER_SDB_GPIO, LED_DRIVER_SDB_PIN, 1);
}
void InitPeripherials(void)
void InitPeripherals(void)
{
InitLedDriver();
InitTestLed();

View File

@@ -10,6 +10,6 @@
// Functions:
void InitPeripherials(void);
void InitPeripherals(void);
#endif

View File

@@ -28,7 +28,7 @@ volatile bool DisableKeyMatrixScanState;
int main(void)
{
InitClock();
InitPeripherials();
InitPeripherals();
KeyMatrix_Init(&keyMatrix);
while (1) {

View File

@@ -1,6 +1,7 @@
#include "config/parse_keymap.h"
#include "key_action.h"
#include "current_keymap.h"
#include "led_display.h"
static bool isDryRun;
@@ -180,13 +181,15 @@ parser_error_t ParseKeymap(serialized_buffer_t *buffer) {;
const char *description = readString(buffer, &descriptionLen);
uint16_t layerCount = readCompactLength(buffer);
(void)abbreviation;
(void)name;
(void)description;
if (layerCount != LAYER_COUNT) {
return ParserError_InvalidLayerCount;
}
isDryRun = !isDefault;
if (!isDryRun) {
LedDisplay_SetText(abbreviationLen, abbreviation);
}
for (uint16_t layerIdx = 0; layerIdx < layerCount; layerIdx++) {
errorCode = parseLayer(buffer, layerIdx);
if (errorCode != ParserError_Success) {

View File

@@ -4,7 +4,7 @@
#include "peripherals/reset_button.h"
#include "i2c.h"
#include "i2c_watchdog.h"
#include "led_driver.h"
#include "peripherals/led_driver.h"
#include "peripherals/merge_sensor.h"
#include "led_pwm.h"
#include "slave_scheduler.h"
@@ -50,8 +50,9 @@ void InitI2c() {
I2C_MasterInit(I2C_EEPROM_BUS_BASEADDR, &masterConfig, sourceClock);
}
void InitPeripherials(void)
void InitPeripherals(void)
{
InitLedDriver();
InitResetButton();
InitMergeSensor();
ADC_Init();

View File

@@ -5,6 +5,6 @@
// Functions:
extern void InitPeripherials();
extern void InitPeripherals();
#endif

View File

@@ -1,13 +1,93 @@
#include "led_display.h"
#include "slave_drivers/slave_driver_led_driver.h"
#include "layer.h"
#define LAYER_LED_FIRST FRAME_REGISTER_PWM_FIRST + 13
#define LAYER_LED_DISTANCE 16
static const uint16_t capitalLetterToSegmentSet[] = {
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) {
for (uint8_t i = 0; i < LAYER_COUNT; i++) {
// LedDriver_WriteRegister(I2C_ADDRESS_LED_DRIVER_LEFT, LAYER_LED_FIRST + (i * LAYER_LED_DISTANCE), LedDisplayBrightness * (layerId == i + 1));
static uint16_t characterToSegmentSet(char character) {
switch (character) {
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;
}

View File

@@ -1,10 +1,23 @@
#ifndef __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

View File

@@ -2,7 +2,7 @@
#include "init_clock.h"
#include "init_peripherals.h"
#include "usb_composite_device.h"
#include "led_driver.h"
#include "peripherals/led_driver.h"
#include "key_action.h"
#include "slave_scheduler.h"
#include "peripherals/test_led.h"
@@ -62,15 +62,14 @@ void UpdateUsbReports()
}
void main() {
InitPeripherials();
InitClock();
InitPeripherals();
if (Wormhole.magicNumber == WORMHOLE_MAGIC_NUMBER && Wormhole.enumerationMode == EnumerationMode_BusPal) {
Wormhole.magicNumber = 0;
init_hardware();
handleUsbBusPalCommand();
} else {
LedDriver_InitAllLeds(1);
InitSlaveScheduler();
KeyMatrix_Init(&KeyMatrix);
UpdateUsbReports();

View File

@@ -1,7 +1,7 @@
#include "led_driver.h"
#include "peripherals/led_driver.h"
#include "i2c_addresses.h"
void LedDriver_InitAllLeds(char isEnabled)
void InitLedDriver()
{
CLOCK_EnableClock(LED_DRIVER_SDB_CLOCK);
PORT_SetPinMux(LED_DRIVER_SDB_PORT, LED_DRIVER_SDB_PIN, kPORT_MuxAsGpio);

View File

@@ -44,6 +44,6 @@
// Functions:
extern void LedDriver_InitAllLeds(char isEnabled);
extern void InitLedDriver();
#endif

View File

@@ -1,7 +1,8 @@
#include "slave_drivers/slave_driver_led_driver.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,
.setupLedControlRegistersCommand = {
@@ -58,15 +59,16 @@ uint8_t setFrame1Buffer[] = {LED_DRIVER_REGISTER_FRAME, LED_DRIVER_FRAME_1};
uint8_t updatePwmRegistersBuffer[PWM_REGISTER_BUFFER_LENGTH];
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->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);
LedDisplay_SetText(3, "ABC");
}
void LedSlaveDriver_Update(uint8_t ledDriverId) {
led_driver_state_t *currentLedDriverState = ledDriverStates + ledDriverId;
led_driver_state_t *currentLedDriverState = LedDriverStates + ledDriverId;
uint8_t *ledDriverPhase = &currentLedDriverState->phase;
uint8_t ledDriverAddress = currentLedDriverState->i2cAddress;
uint8_t *ledIndex = &currentLedDriverState->ledIndex;
@@ -106,6 +108,6 @@ void LedSlaveDriver_Update(uint8_t ledDriverId) {
void SetLeds(uint8_t ledBrightness)
{
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);
}
}

View File

@@ -4,7 +4,7 @@
// Includes:
#include "fsl_common.h"
#include "led_driver.h"
#include "peripherals/led_driver.h"
// Macros:
@@ -37,6 +37,10 @@
uint8_t setupLedControlRegistersCommand[LED_CONTROL_REGISTERS_COMMAND_LENGTH];
} led_driver_state_t;
// Variables:
extern led_driver_state_t LedDriverStates[LED_DRIVER_MAX_COUNT];
// Functions:
extern void LedSlaveDriver_Init(uint8_t ledDriverId);

View File

@@ -2,7 +2,7 @@
#include "system_properties.h"
#include "peripherals/test_led.h"
#include "i2c_addresses.h"
#include "led_driver.h"
#include "peripherals/led_driver.h"
#include "peripherals/merge_sensor.h"
#include "config/parse_config.h"
#include "config/config_state.h"

View File

@@ -134,6 +134,7 @@ void UpdateActiveUsbReports()
static uint8_t previousModifiers = 0;
uint8_t activeLayer = getActiveLayer();
LedDisplay_SetLayer(activeLayer);
for (uint8_t slotId=0; slotId<SLOT_COUNT; slotId++) {
for (uint8_t keyId=0; keyId<MAX_KEY_COUNT_PER_MODULE; keyId++) {