diff options
author | Joshua Diamond <josh@windowoffire.com> | 2021-02-14 19:59:26 -0500 |
---|---|---|
committer | Joshua Diamond <josh@windowoffire.com> | 2021-02-14 19:59:26 -0500 |
commit | f1a3ce49ccdfee79fbad76fd13bcf4448318eb6b (patch) | |
tree | 8725ba276f485dc62a40d8f6d1ebe1bbc84e6fb3 /quantum | |
parent | c80e5f9f8868ccaa8cb990be6f4da3f1011c2b78 (diff) | |
parent | 6f44c2ec31a6aeacd9e90060a9670be03be372fe (diff) |
Merge branch 'master' into develop
Diffstat (limited to 'quantum')
-rw-r--r-- | quantum/config_common.h | 351 | ||||
-rw-r--r-- | quantum/led_matrix.c | 132 | ||||
-rw-r--r-- | quantum/led_matrix.h | 42 | ||||
-rw-r--r-- | quantum/led_matrix_types.h | 69 | ||||
-rw-r--r-- | quantum/quantum.h | 90 | ||||
-rw-r--r-- | quantum/rgb_matrix_types.h | 16 |
6 files changed, 160 insertions, 540 deletions
diff --git a/quantum/config_common.h b/quantum/config_common.h index bfaf7389e2..fa1ff2a5f5 100644 --- a/quantum/config_common.h +++ b/quantum/config_common.h @@ -16,357 +16,14 @@ #pragma once +#ifndef __ASSEMBLER__ +# include "pin_defs.h" +#endif + /* diode directions */ #define COL2ROW 0 #define ROW2COL 1 -// useful for direct pin mapping -#define NO_PIN (pin_t)(~0) - -#ifdef __AVR__ -# ifndef __ASSEMBLER__ -# include <avr/io.h> -# endif -# define PORT_SHIFTER 4 // this may be 4 for all AVR chips - -// If you want to add more to this list, reference the PINx definitions in these header -// files: https://github.com/vancegroup-mirrors/avr-libc/tree/master/avr-libc/include/avr - -# if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega16U4__) -# define ADDRESS_BASE 0x00 -# define PINB_ADDRESS 0x3 -# define PINC_ADDRESS 0x6 -# define PIND_ADDRESS 0x9 -# define PINE_ADDRESS 0xC -# define PINF_ADDRESS 0xF -# elif defined(__AVR_AT90USB162__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__) -# define ADDRESS_BASE 0x00 -# define PINB_ADDRESS 0x3 -# define PINC_ADDRESS 0x6 -# define PIND_ADDRESS 0x9 -# elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) -# define ADDRESS_BASE 0x00 -# define PINA_ADDRESS 0x0 -# define PINB_ADDRESS 0x3 -# define PINC_ADDRESS 0x6 -# define PIND_ADDRESS 0x9 -# define PINE_ADDRESS 0xC -# define PINF_ADDRESS 0xF -# elif defined(__AVR_ATmega32A__) -# define ADDRESS_BASE 0x10 -# define PIND_ADDRESS 0x0 -# define PINC_ADDRESS 0x3 -# define PINB_ADDRESS 0x6 -# define PINA_ADDRESS 0x9 -# elif defined(__AVR_ATtiny85__) -# define ADDRESS_BASE 0x10 -# define PINB_ADDRESS 0x6 -# else -# error "Pins are not defined" -# endif - -/* I/O pins */ -# define PINDEF(port, pin) ((PIN##port##_ADDRESS << PORT_SHIFTER) | pin) - -# ifdef PORTA -# define A0 PINDEF(A, 0) -# define A1 PINDEF(A, 1) -# define A2 PINDEF(A, 2) -# define A3 PINDEF(A, 3) -# define A4 PINDEF(A, 4) -# define A5 PINDEF(A, 5) -# define A6 PINDEF(A, 6) -# define A7 PINDEF(A, 7) -# endif -# ifdef PORTB -# define B0 PINDEF(B, 0) -# define B1 PINDEF(B, 1) -# define B2 PINDEF(B, 2) -# define B3 PINDEF(B, 3) -# define B4 PINDEF(B, 4) -# define B5 PINDEF(B, 5) -# define B6 PINDEF(B, 6) -# define B7 PINDEF(B, 7) -# endif -# ifdef PORTC -# define C0 PINDEF(C, 0) -# define C1 PINDEF(C, 1) -# define C2 PINDEF(C, 2) -# define C3 PINDEF(C, 3) -# define C4 PINDEF(C, 4) -# define C5 PINDEF(C, 5) -# define C6 PINDEF(C, 6) -# define C7 PINDEF(C, 7) -# endif -# ifdef PORTD -# define D0 PINDEF(D, 0) -# define D1 PINDEF(D, 1) -# define D2 PINDEF(D, 2) -# define D3 PINDEF(D, 3) -# define D4 PINDEF(D, 4) -# define D5 PINDEF(D, 5) -# define D6 PINDEF(D, 6) -# define D7 PINDEF(D, 7) -# endif -# ifdef PORTE -# define E0 PINDEF(E, 0) -# define E1 PINDEF(E, 1) -# define E2 PINDEF(E, 2) -# define E3 PINDEF(E, 3) -# define E4 PINDEF(E, 4) -# define E5 PINDEF(E, 5) -# define E6 PINDEF(E, 6) -# define E7 PINDEF(E, 7) -# endif -# ifdef PORTF -# define F0 PINDEF(F, 0) -# define F1 PINDEF(F, 1) -# define F2 PINDEF(F, 2) -# define F3 PINDEF(F, 3) -# define F4 PINDEF(F, 4) -# define F5 PINDEF(F, 5) -# define F6 PINDEF(F, 6) -# define F7 PINDEF(F, 7) -# endif - -# ifndef __ASSEMBLER__ -# define _PIN_ADDRESS(p, offset) _SFR_IO8(ADDRESS_BASE + ((p) >> PORT_SHIFTER) + (offset)) -// Port X Input Pins Address -# define PINx_ADDRESS(p) _PIN_ADDRESS(p, 0) -// Port X Data Direction Register, 0:input 1:output -# define DDRx_ADDRESS(p) _PIN_ADDRESS(p, 1) -// Port X Data Register -# define PORTx_ADDRESS(p) _PIN_ADDRESS(p, 2) -# endif - -#elif defined(PROTOCOL_CHIBIOS) -// Defines mapping for Proton C replacement -# ifdef CONVERT_TO_PROTON_C -// Left side (front) -# define D3 PAL_LINE(GPIOA, 9) -# define D2 PAL_LINE(GPIOA, 10) -// GND -// GND -# define D1 PAL_LINE(GPIOB, 7) -# define D0 PAL_LINE(GPIOB, 6) -# define D4 PAL_LINE(GPIOB, 5) -# define C6 PAL_LINE(GPIOB, 4) -# define D7 PAL_LINE(GPIOB, 3) -# define E6 PAL_LINE(GPIOB, 2) -# define B4 PAL_LINE(GPIOB, 1) -# define B5 PAL_LINE(GPIOB, 0) - -// Right side (front) -// RAW -// GND -// RESET -// VCC -# define F4 PAL_LINE(GPIOA, 2) -# define F5 PAL_LINE(GPIOA, 1) -# define F6 PAL_LINE(GPIOA, 0) -# define F7 PAL_LINE(GPIOB, 8) -# define B1 PAL_LINE(GPIOB, 13) -# define B3 PAL_LINE(GPIOB, 14) -# define B2 PAL_LINE(GPIOB, 15) -# define B6 PAL_LINE(GPIOB, 9) - -// LEDs (only D5/C13 uses an actual LED) -# ifdef CONVERT_TO_PROTON_C_RXLED -# define D5 PAL_LINE(GPIOC, 14) -# define B0 PAL_LINE(GPIOC, 13) -# else -# define D5 PAL_LINE(GPIOC, 13) -# define B0 PAL_LINE(GPIOC, 14) -# endif -# else -# define A0 PAL_LINE(GPIOA, 0) -# define A1 PAL_LINE(GPIOA, 1) -# define A2 PAL_LINE(GPIOA, 2) -# define A3 PAL_LINE(GPIOA, 3) -# define A4 PAL_LINE(GPIOA, 4) -# define A5 PAL_LINE(GPIOA, 5) -# define A6 PAL_LINE(GPIOA, 6) -# define A7 PAL_LINE(GPIOA, 7) -# define A8 PAL_LINE(GPIOA, 8) -# define A9 PAL_LINE(GPIOA, 9) -# define A10 PAL_LINE(GPIOA, 10) -# define A11 PAL_LINE(GPIOA, 11) -# define A12 PAL_LINE(GPIOA, 12) -# define A13 PAL_LINE(GPIOA, 13) -# define A14 PAL_LINE(GPIOA, 14) -# define A15 PAL_LINE(GPIOA, 15) -# define B0 PAL_LINE(GPIOB, 0) -# define B1 PAL_LINE(GPIOB, 1) -# define B2 PAL_LINE(GPIOB, 2) -# define B3 PAL_LINE(GPIOB, 3) -# define B4 PAL_LINE(GPIOB, 4) -# define B5 PAL_LINE(GPIOB, 5) -# define B6 PAL_LINE(GPIOB, 6) -# define B7 PAL_LINE(GPIOB, 7) -# define B8 PAL_LINE(GPIOB, 8) -# define B9 PAL_LINE(GPIOB, 9) -# define B10 PAL_LINE(GPIOB, 10) -# define B11 PAL_LINE(GPIOB, 11) -# define B12 PAL_LINE(GPIOB, 12) -# define B13 PAL_LINE(GPIOB, 13) -# define B14 PAL_LINE(GPIOB, 14) -# define B15 PAL_LINE(GPIOB, 15) -# define B16 PAL_LINE(GPIOB, 16) -# define B17 PAL_LINE(GPIOB, 17) -# define B18 PAL_LINE(GPIOB, 18) -# define B19 PAL_LINE(GPIOB, 19) -# define C0 PAL_LINE(GPIOC, 0) -# define C1 PAL_LINE(GPIOC, 1) -# define C2 PAL_LINE(GPIOC, 2) -# define C3 PAL_LINE(GPIOC, 3) -# define C4 PAL_LINE(GPIOC, 4) -# define C5 PAL_LINE(GPIOC, 5) -# define C6 PAL_LINE(GPIOC, 6) -# define C7 PAL_LINE(GPIOC, 7) -# define C8 PAL_LINE(GPIOC, 8) -# define C9 PAL_LINE(GPIOC, 9) -# define C10 PAL_LINE(GPIOC, 10) -# define C11 PAL_LINE(GPIOC, 11) -# define C12 PAL_LINE(GPIOC, 12) -# define C13 PAL_LINE(GPIOC, 13) -# define C14 PAL_LINE(GPIOC, 14) -# define C15 PAL_LINE(GPIOC, 15) -# define D0 PAL_LINE(GPIOD, 0) -# define D1 PAL_LINE(GPIOD, 1) -# define D2 PAL_LINE(GPIOD, 2) -# define D3 PAL_LINE(GPIOD, 3) -# define D4 PAL_LINE(GPIOD, 4) -# define D5 PAL_LINE(GPIOD, 5) -# define D6 PAL_LINE(GPIOD, 6) -# define D7 PAL_LINE(GPIOD, 7) -# define D8 PAL_LINE(GPIOD, 8) -# define D9 PAL_LINE(GPIOD, 9) -# define D10 PAL_LINE(GPIOD, 10) -# define D11 PAL_LINE(GPIOD, 11) -# define D12 PAL_LINE(GPIOD, 12) -# define D13 PAL_LINE(GPIOD, 13) -# define D14 PAL_LINE(GPIOD, 14) -# define D15 PAL_LINE(GPIOD, 15) -# define E0 PAL_LINE(GPIOE, 0) -# define E1 PAL_LINE(GPIOE, 1) -# define E2 PAL_LINE(GPIOE, 2) -# define E3 PAL_LINE(GPIOE, 3) -# define E4 PAL_LINE(GPIOE, 4) -# define E5 PAL_LINE(GPIOE, 5) -# define E6 PAL_LINE(GPIOE, 6) -# define E7 PAL_LINE(GPIOE, 7) -# define E8 PAL_LINE(GPIOE, 8) -# define E9 PAL_LINE(GPIOE, 9) -# define E10 PAL_LINE(GPIOE, 10) -# define E11 PAL_LINE(GPIOE, 11) -# define E12 PAL_LINE(GPIOE, 12) -# define E13 PAL_LINE(GPIOE, 13) -# define E14 PAL_LINE(GPIOE, 14) -# define E15 PAL_LINE(GPIOE, 15) -# define F0 PAL_LINE(GPIOF, 0) -# define F1 PAL_LINE(GPIOF, 1) -# define F2 PAL_LINE(GPIOF, 2) -# define F3 PAL_LINE(GPIOF, 3) -# define F4 PAL_LINE(GPIOF, 4) -# define F5 PAL_LINE(GPIOF, 5) -# define F6 PAL_LINE(GPIOF, 6) -# define F7 PAL_LINE(GPIOF, 7) -# define F8 PAL_LINE(GPIOF, 8) -# define F9 PAL_LINE(GPIOF, 9) -# define F10 PAL_LINE(GPIOF, 10) -# define F11 PAL_LINE(GPIOF, 11) -# define F12 PAL_LINE(GPIOF, 12) -# define F13 PAL_LINE(GPIOF, 13) -# define F14 PAL_LINE(GPIOF, 14) -# define F15 PAL_LINE(GPIOF, 15) -# define G0 PAL_LINE(GPIOG, 0) -# define G1 PAL_LINE(GPIOG, 1) -# define G2 PAL_LINE(GPIOG, 2) -# define G3 PAL_LINE(GPIOG, 3) -# define G4 PAL_LINE(GPIOG, 4) -# define G5 PAL_LINE(GPIOG, 5) -# define G6 PAL_LINE(GPIOG, 6) -# define G7 PAL_LINE(GPIOG, 7) -# define G8 PAL_LINE(GPIOG, 8) -# define G9 PAL_LINE(GPIOG, 9) -# define G10 PAL_LINE(GPIOG, 10) -# define G11 PAL_LINE(GPIOG, 11) -# define G12 PAL_LINE(GPIOG, 12) -# define G13 PAL_LINE(GPIOG, 13) -# define G14 PAL_LINE(GPIOG, 14) -# define G15 PAL_LINE(GPIOG, 15) -# define H0 PAL_LINE(GPIOH, 0) -# define H1 PAL_LINE(GPIOH, 1) -# define H2 PAL_LINE(GPIOH, 2) -# define H3 PAL_LINE(GPIOH, 3) -# define H4 PAL_LINE(GPIOH, 4) -# define H5 PAL_LINE(GPIOH, 5) -# define H6 PAL_LINE(GPIOH, 6) -# define H7 PAL_LINE(GPIOH, 7) -# define H8 PAL_LINE(GPIOH, 8) -# define H9 PAL_LINE(GPIOH, 9) -# define H10 PAL_LINE(GPIOH, 10) -# define H11 PAL_LINE(GPIOH, 11) -# define H12 PAL_LINE(GPIOH, 12) -# define H13 PAL_LINE(GPIOH, 13) -# define H14 PAL_LINE(GPIOH, 14) -# define H15 PAL_LINE(GPIOH, 15) -# define I0 PAL_LINE(GPIOI, 0) -# define I1 PAL_LINE(GPIOI, 1) -# define I2 PAL_LINE(GPIOI, 2) -# define I3 PAL_LINE(GPIOI, 3) -# define I4 PAL_LINE(GPIOI, 4) -# define I5 PAL_LINE(GPIOI, 5) -# define I6 PAL_LINE(GPIOI, 6) -# define I7 PAL_LINE(GPIOI, 7) -# define I8 PAL_LINE(GPIOI, 8) -# define I9 PAL_LINE(GPIOI, 9) -# define I10 PAL_LINE(GPIOI, 10) -# define I11 PAL_LINE(GPIOI, 11) -# define I12 PAL_LINE(GPIOI, 12) -# define I13 PAL_LINE(GPIOI, 13) -# define I14 PAL_LINE(GPIOI, 14) -# define I15 PAL_LINE(GPIOI, 15) -# define J0 PAL_LINE(GPIOJ, 0) -# define J1 PAL_LINE(GPIOJ, 1) -# define J2 PAL_LINE(GPIOJ, 2) -# define J3 PAL_LINE(GPIOJ, 3) -# define J4 PAL_LINE(GPIOJ, 4) -# define J5 PAL_LINE(GPIOJ, 5) -# define J6 PAL_LINE(GPIOJ, 6) -# define J7 PAL_LINE(GPIOJ, 7) -# define J8 PAL_LINE(GPIOJ, 8) -# define J9 PAL_LINE(GPIOJ, 9) -# define J10 PAL_LINE(GPIOJ, 10) -# define J11 PAL_LINE(GPIOJ, 11) -# define J12 PAL_LINE(GPIOJ, 12) -# define J13 PAL_LINE(GPIOJ, 13) -# define J14 PAL_LINE(GPIOJ, 14) -# define J15 PAL_LINE(GPIOJ, 15) -// Keyboards can `#define KEYBOARD_REQUIRES_GPIOK` if they need to access GPIO-K pins. These conflict with a whole -// bunch of layout definitions, so it's intentionally left out unless absolutely required -- in that case, the -// keyboard designer should use a different symbol when defining their layout macros. -# ifdef KEYBOARD_REQUIRES_GPIOK -# define K0 PAL_LINE(GPIOK, 0) -# define K1 PAL_LINE(GPIOK, 1) -# define K2 PAL_LINE(GPIOK, 2) -# define K3 PAL_LINE(GPIOK, 3) -# define K4 PAL_LINE(GPIOK, 4) -# define K5 PAL_LINE(GPIOK, 5) -# define K6 PAL_LINE(GPIOK, 6) -# define K7 PAL_LINE(GPIOK, 7) -# define K8 PAL_LINE(GPIOK, 8) -# define K9 PAL_LINE(GPIOK, 9) -# define K10 PAL_LINE(GPIOK, 10) -# define K11 PAL_LINE(GPIOK, 11) -# define K12 PAL_LINE(GPIOK, 12) -# define K13 PAL_LINE(GPIOK, 13) -# define K14 PAL_LINE(GPIOK, 14) -# define K15 PAL_LINE(GPIOK, 15) -# endif -# endif -#endif - #define API_SYSEX_MAX_SIZE 32 #include "song_list.h" diff --git a/quantum/led_matrix.c b/quantum/led_matrix.c index eb523990a6..c3538e94df 100644 --- a/quantum/led_matrix.c +++ b/quantum/led_matrix.c @@ -27,7 +27,7 @@ #include <string.h> #include <math.h> -led_config_t led_matrix_config; +led_eeconfig_t led_matrix_eeconfig; #ifndef MAX # define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) @@ -70,40 +70,32 @@ void eeconfig_update_led_matrix(uint32_t config_value) { eeprom_update_dword(EEC void eeconfig_update_led_matrix_default(void) { dprintf("eeconfig_update_led_matrix_default\n"); - led_matrix_config.enable = 1; - led_matrix_config.mode = LED_MATRIX_UNIFORM_BRIGHTNESS; - led_matrix_config.val = 128; - led_matrix_config.speed = 0; - eeconfig_update_led_matrix(led_matrix_config.raw); + led_matrix_eeconfig.enable = 1; + led_matrix_eeconfig.mode = LED_MATRIX_UNIFORM_BRIGHTNESS; + led_matrix_eeconfig.val = 128; + led_matrix_eeconfig.speed = 0; + eeconfig_update_led_matrix(led_matrix_eeconfig.raw); } void eeconfig_debug_led_matrix(void) { - dprintf("led_matrix_config eeprom\n"); - dprintf("led_matrix_config.enable = %d\n", led_matrix_config.enable); - dprintf("led_matrix_config.mode = %d\n", led_matrix_config.mode); - dprintf("led_matrix_config.val = %d\n", led_matrix_config.val); - dprintf("led_matrix_config.speed = %d\n", led_matrix_config.speed); + dprintf("led_matrix_eeconfig eeprom\n"); + dprintf("led_matrix_eeconfig.enable = %d\n", led_matrix_eeconfig.enable); + dprintf("led_matrix_eeconfig.mode = %d\n", led_matrix_eeconfig.mode); + dprintf("led_matrix_eeconfig.val = %d\n", led_matrix_eeconfig.val); + dprintf("led_matrix_eeconfig.speed = %d\n", led_matrix_eeconfig.speed); } -// Last led hit -#ifndef LED_HITS_TO_REMEMBER -# define LED_HITS_TO_REMEMBER 8 -#endif uint8_t g_last_led_hit[LED_HITS_TO_REMEMBER] = {255}; uint8_t g_last_led_count = 0; -void map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i, uint8_t *led_count) { - led_matrix led; - *led_count = 0; - - for (uint8_t i = 0; i < LED_DRIVER_LED_COUNT; i++) { - // map_index_to_led(i, &led); - led = g_leds[i]; - if (row == led.matrix_co.row && column == led.matrix_co.col) { - led_i[*led_count] = i; - (*led_count)++; - } +uint8_t map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i) { + uint8_t led_count = 0; + uint8_t led_index = g_led_config.matrix_co[row][column]; + if (led_index != NO_LED) { + led_i[led_count] = led_index; + led_count++; } + return led_count; } void led_matrix_update_pwm_buffers(void) { led_matrix_driver.flush(); } @@ -114,8 +106,8 @@ void led_matrix_set_index_value_all(uint8_t value) { led_matrix_driver.set_value bool process_led_matrix(uint16_t keycode, keyrecord_t *record) { if (record->event.pressed) { - uint8_t led[8], led_count; - map_row_column_to_led(record->event.key.row, record->event.key.col, led, &led_count); + uint8_t led[8]; + uint8_t led_count = map_row_column_to_led(record->event.key.row, record->event.key.col, led); if (led_count > 0) { for (uint8_t i = LED_HITS_TO_REMEMBER; i > 1; i--) { g_last_led_hit[i - 1] = g_last_led_hit[i - 2]; @@ -127,8 +119,8 @@ bool process_led_matrix(uint16_t keycode, keyrecord_t *record) { g_any_key_hit = 0; } else { #ifdef LED_MATRIX_KEYRELEASES - uint8_t led[8], led_count; - map_row_column_to_led(record->event.key.row, record->event.key.col, led, &led_count); + uint8_t led[8]; + uint8_t led_count = map_row_column_to_led(record->event.key.row, record->event.key.col, led); for (uint8_t i = 0; i < led_count; i++) g_key_hit[led[i]] = 255; g_any_key_hit = 255; @@ -143,12 +135,12 @@ void led_matrix_set_suspend_state(bool state) { g_suspend_state = state; } void led_matrix_all_off(void) { led_matrix_set_index_value_all(0); } // Uniform brightness -void led_matrix_uniform_brightness(void) { led_matrix_set_index_value_all(LED_MATRIX_MAXIMUM_BRIGHTNESS / BACKLIGHT_LEVELS * led_matrix_config.val); } +void led_matrix_uniform_brightness(void) { led_matrix_set_index_value_all(LED_MATRIX_MAXIMUM_BRIGHTNESS / BACKLIGHT_LEVELS * led_matrix_eeconfig.val); } void led_matrix_custom(void) {} void led_matrix_task(void) { - if (!led_matrix_config.enable) { + if (!led_matrix_eeconfig.enable) { led_matrix_all_off(); led_matrix_indicators(); return; @@ -170,7 +162,7 @@ void led_matrix_task(void) { // Ideally we would also stop sending zeros to the LED driver PWM buffers // while suspended and just do a software shutdown. This is a cheap hack for now. bool suspend_backlight = ((g_suspend_state && LED_DISABLE_WHEN_USB_SUSPENDED) || (LED_DISABLE_AFTER_TIMEOUT > 0 && g_any_key_hit > LED_DISABLE_AFTER_TIMEOUT * 60 * 20)); - uint8_t effect = suspend_backlight ? 0 : led_matrix_config.mode; + uint8_t effect = suspend_backlight ? 0 : led_matrix_eeconfig.mode; // this gets ticked at 20 Hz. // each effect can opt to do calculations @@ -211,8 +203,8 @@ __attribute__((weak)) void led_matrix_indicators_user(void) {} // else // { // // This needs updated to something like -// // uint8_t led[8], led_count; -// // map_row_column_to_led(row,column,led,&led_count); +// // uint8_t led[8]; +// // uint8_t led_count = map_row_column_to_led(row, column, led); // // for(uint8_t i = 0; i < led_count; i++) // map_row_column_to_led(row, column, index); // } @@ -235,12 +227,12 @@ void led_matrix_init(void) { eeconfig_update_led_matrix_default(); } - led_matrix_config.raw = eeconfig_read_led_matrix(); + led_matrix_eeconfig.raw = eeconfig_read_led_matrix(); - if (!led_matrix_config.mode) { - dprintf("led_matrix_init_drivers led_matrix_config.mode = 0. Write default values to EEPROM.\n"); + if (!led_matrix_eeconfig.mode) { + dprintf("led_matrix_init_drivers led_matrix_eeconfig.mode = 0. Write default values to EEPROM.\n"); eeconfig_update_led_matrix_default(); - led_matrix_config.raw = eeconfig_read_led_matrix(); + led_matrix_eeconfig.raw = eeconfig_read_led_matrix(); } eeconfig_debug_led_matrix(); // display current eeprom values @@ -270,8 +262,8 @@ static uint8_t decrement(uint8_t value, uint8_t step, uint8_t min, uint8_t max) // } // void backlight_set_key_value(uint8_t row, uint8_t column, uint8_t value) { -// uint8_t led[8], led_count; -// map_row_column_to_led(row,column,led,&led_count); +// uint8_t led[8]; +// uint8_t led_count = map_row_column_to_led(row, column, led); // for(uint8_t i = 0; i < led_count; i++) { // if (led[i] < LED_DRIVER_LED_COUNT) { // void *address = backlight_get_custom_key_value_eeprom_address(led[i]); @@ -283,74 +275,74 @@ static uint8_t decrement(uint8_t value, uint8_t step, uint8_t min, uint8_t max) uint32_t led_matrix_get_tick(void) { return g_tick; } void led_matrix_toggle(void) { - led_matrix_config.enable ^= 1; - eeconfig_update_led_matrix(led_matrix_config.raw); + led_matrix_eeconfig.enable ^= 1; + eeconfig_update_led_matrix(led_matrix_eeconfig.raw); } void led_matrix_enable(void) { - led_matrix_config.enable = 1; - eeconfig_update_led_matrix(led_matrix_config.raw); + led_matrix_eeconfig.enable = 1; + eeconfig_update_led_matrix(led_matrix_eeconfig.raw); } -void led_matrix_enable_noeeprom(void) { led_matrix_config.enable = 1; } +void led_matrix_enable_noeeprom(void) { led_matrix_eeconfig.enable = 1; } void led_matrix_disable(void) { - led_matrix_config.enable = 0; - eeconfig_update_led_matrix(led_matrix_config.raw); + led_matrix_eeconfig.enable = 0; + eeconfig_update_led_matrix(led_matrix_eeconfig.raw); } -void led_matrix_disable_noeeprom(void) { led_matrix_config.enable = 0; } +void led_matrix_disable_noeeprom(void) { led_matrix_eeconfig.enable = 0; } void led_matrix_step(void) { - led_matrix_config.mode++; - if (led_matrix_config.mode >= LED_MATRIX_EFFECT_MAX) { - led_matrix_config.mode = 1; + led_matrix_eeconfig.mode++; + if (led_matrix_eeconfig.mode >= LED_MATRIX_EFFECT_MAX) { + led_matrix_eeconfig.mode = 1; } - eeconfig_update_led_matrix(led_matrix_config.raw); + eeconfig_update_led_matrix(led_matrix_eeconfig.raw); } void led_matrix_step_reverse(void) { - led_matrix_config.mode--; - if (led_matrix_config.mode < 1) { - led_matrix_config.mode = LED_MATRIX_EFFECT_MAX - 1; + led_matrix_eeconfig.mode--; + if (led_matrix_eeconfig.mode < 1) { + led_matrix_eeconfig.mode = LED_MATRIX_EFFECT_MAX - 1; } - eeconfig_update_led_matrix(led_matrix_config.raw); + eeconfig_update_led_matrix(led_matrix_eeconfig.raw); } void led_matrix_increase_val(void) { - led_matrix_config.val = increment(led_matrix_config.val, 8, 0, LED_MATRIX_MAXIMUM_BRIGHTNESS); - eeconfig_update_led_matrix(led_matrix_config.raw); + led_matrix_eeconfig.val = increment(led_matrix_eeconfig.val, 8, 0, LED_MATRIX_MAXIMUM_BRIGHTNESS); + eeconfig_update_led_matrix(led_matrix_eeconfig.raw); } void led_matrix_decrease_val(void) { - led_matrix_config.val = decrement(led_matrix_config.val, 8, 0, LED_MATRIX_MAXIMUM_BRIGHTNESS); - eeconfig_update_led_matrix(led_matrix_config.raw); + led_matrix_eeconfig.val = decrement(led_matrix_eeconfig.val, 8, 0, LED_MATRIX_MAXIMUM_BRIGHTNESS); + eeconfig_update_led_matrix(led_matrix_eeconfig.raw); } void led_matrix_increase_speed(void) { - led_matrix_config.speed = increment(led_matrix_config.speed, 1, 0, 3); - eeconfig_update_led_matrix(led_matrix_config.raw); // EECONFIG needs to be increased to support this + led_matrix_eeconfig.speed = increment(led_matrix_eeconfig.speed, 1, 0, 3); + eeconfig_update_led_matrix(led_matrix_eeconfig.raw); // EECONFIG needs to be increased to support this } void led_matrix_decrease_speed(void) { - led_matrix_config.speed = decrement(led_matrix_config.speed, 1, 0, 3); - eeconfig_update_led_matrix(led_matrix_config.raw); // EECONFIG needs to be increased to support this + led_matrix_eeconfig.speed = decrement(led_matrix_eeconfig.speed, 1, 0, 3); + eeconfig_update_led_matrix(led_matrix_eeconfig.raw); // EECONFIG needs to be increased to support this } void led_matrix_mode(uint8_t mode, bool eeprom_write) { - led_matrix_config.mode = mode; + led_matrix_eeconfig.mode = mode; if (eeprom_write) { - eeconfig_update_led_matrix(led_matrix_config.raw); + eeconfig_update_led_matrix(led_matrix_eeconfig.raw); } } -uint8_t led_matrix_get_mode(void) { return led_matrix_config.mode; } +uint8_t led_matrix_get_mode(void) { return led_matrix_eeconfig.mode; } -void led_matrix_set_value_noeeprom(uint8_t val) { led_matrix_config.val = val; } +void led_matrix_set_value_noeeprom(uint8_t val) { led_matrix_eeconfig.val = val; } void led_matrix_set_value(uint8_t val) { led_matrix_set_value_noeeprom(val); - eeconfig_update_led_matrix(led_matrix_config.raw); + eeconfig_update_led_matrix(led_matrix_eeconfig.raw); } void backlight_set(uint8_t val) { led_matrix_set_value(val); } diff --git a/quantum/led_matrix.h b/quantum/led_matrix.h index 7dcdf1d482..85bae43c15 100644 --- a/quantum/led_matrix.h +++ b/quantum/led_matrix.h @@ -19,46 +19,12 @@ #pragma once +#include "led_matrix_types.h" + #ifndef BACKLIGHT_ENABLE # error You must define BACKLIGHT_ENABLE with LED_MATRIX_ENABLE #endif -typedef struct Point { - uint8_t x; - uint8_t y; -} __attribute__((packed)) Point; - -typedef struct led_matrix { - union { - uint8_t raw; - struct { - uint8_t row : 4; // 16 max - uint8_t col : 4; // 16 max - }; - } matrix_co; - Point point; - uint8_t modifier : 1; -} __attribute__((packed)) led_matrix; - -extern const led_matrix g_leds[LED_DRIVER_LED_COUNT]; - -typedef struct { - uint8_t index; - uint8_t value; -} led_indicator; - -typedef union { - uint32_t raw; - struct { - bool enable : 1; - uint8_t mode : 6; - uint8_t hue : 8; // Unused by led_matrix - uint8_t sat : 8; // Unused by led_matrix - uint8_t val : 8; - uint8_t speed : 8; // EECONFIG needs to be increased to support this - }; -} led_config_t; - enum led_matrix_effects { LED_MATRIX_UNIFORM_BRIGHTNESS = 1, // All new effects go above this line @@ -122,3 +88,7 @@ typedef struct { } led_matrix_driver_t; extern const led_matrix_driver_t led_matrix_driver; + +extern led_eeconfig_t led_matrix_eeconfig; + +extern led_config_t g_led_config; diff --git a/quantum/led_matrix_types.h b/quantum/led_matrix_types.h new file mode 100644 index 0000000000..2602bf2bf6 --- /dev/null +++ b/quantum/led_matrix_types.h @@ -0,0 +1,69 @@ +/* Copyright 2021 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#pragma once + +#include <stdint.h> +#include <stdbool.h> + +#if defined(__GNUC__) +# define PACKED __attribute__((__packed__)) +#else +# define PACKED +#endif + +#if defined(_MSC_VER) +# pragma pack(push, 1) +#endif + +// Last led hit +#ifndef LED_HITS_TO_REMEMBER +# define LED_HITS_TO_REMEMBER 8 +#endif // LED_HITS_TO_REMEMBER + +typedef struct PACKED { + uint8_t x; + uint8_t y; +} point_t; + +#define LED_FLAG_ALL 0xFF +#define LED_FLAG_NONE 0x00 +#define LED_FLAG_MODIFIER 0x01 +#define LED_FLAG_KEYLIGHT 0x04 +#define LED_FLAG_INDICATOR 0x08 + +#define NO_LED 255 + +typedef struct PACKED { + uint8_t matrix_co[MATRIX_ROWS][MATRIX_COLS]; + point_t point[LED_DRIVER_LED_COUNT]; + uint8_t flags[LED_DRIVER_LED_COUNT]; +} led_config_t; + +typedef union { + uint32_t raw; + struct PACKED { + uint8_t enable : 2; + uint8_t mode : 6; + uint16_t reserved; + uint8_t val; + uint8_t speed; // EECONFIG needs to be increased to support this + }; +} led_eeconfig_t; + +#if defined(_MSC_VER) +# pragma pack(pop) +#endif diff --git a/quantum/quantum.h b/quantum/quantum.h index b7bf5be312..36a983d575 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -55,6 +55,8 @@ #include "timer.h" #include "sync_timer.h" #include "config_common.h" +#include "gpio.h" +#include "atomic_util.h" #include "led.h" #include "action_util.h" #include "action_tapping.h" @@ -199,20 +201,6 @@ extern layer_state_t layer_state; // Function substitutions to ease GPIO manipulation #if defined(__AVR__) -typedef uint8_t pin_t; - -# define setPinInput(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF)) -# define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF)) -# define setPinInputLow(pin) _Static_assert(0, "AVR processors cannot implement an input as pull low") -# define setPinOutput(pin) (DDRx_ADDRESS(pin) |= _BV((pin)&0xF)) - -# define writePinHigh(pin) (PORTx_ADDRESS(pin) |= _BV((pin)&0xF)) -# define writePinLow(pin) (PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF)) -# define writePin(pin, level) ((level) ? writePinHigh(pin) : writePinLow(pin)) - -# define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF))) - -# define togglePin(pin) (PORTx_ADDRESS(pin) ^= _BV((pin)&0xF)) /* The AVR series GPIOs have a one clock read delay for changes in the digital input signal. * But here's more margin to make it two clocks. */ @@ -221,25 +209,8 @@ typedef uint8_t pin_t; # endif # define waitInputPinDelay() wait_cpuclock(GPIO_INPUT_PIN_DELAY) -#elif defined(PROTOCOL_CHIBIOS) -typedef ioline_t pin_t; - -# define setPinInput(pin) palSetLineMode(pin, PAL_MODE_INPUT) -# define setPinInputHigh(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLUP) -# define setPinInputLow(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLDOWN) -# define setPinOutput(pin) palSetLineMode(pin, PAL_MODE_OUTPUT_PUSHPULL) - -# define writePinHigh(pin) palSetLine(pin) -# define writePinLow(pin) palClearLine(pin) -# define writePin(pin, level) ((level) ? (writePinHigh(pin)) : (writePinLow(pin))) - -# define readPin(pin) palReadLine(pin) +#elif defined(__ARMEL__) || defined(__ARMEB__) -# define togglePin(pin) palToggleLine(pin) - -#endif - -#if defined(__ARMEL__) || defined(__ARMEB__) /* For GPIOs on ARM-based MCUs, the input pins are sampled by the clock of the bus * to which the GPIO is connected. * The connected buses differ depending on the various series of MCUs. @@ -258,63 +229,8 @@ typedef ioline_t pin_t; # endif # endif # define waitInputPinDelay() wait_cpuclock(GPIO_INPUT_PIN_DELAY) -#endif - -// Atomic macro to help make GPIO and other controls atomic. -#ifdef IGNORE_ATOMIC_BLOCK -/* do nothing atomic macro */ -# define ATOMIC_BLOCK for (uint8_t __ToDo = 1; __ToDo; __ToDo = 0) -# define ATOMIC_BLOCK_RESTORESTATE ATOMIC_BLOCK -# define ATOMIC_BLOCK_FORCEON ATOMIC_BLOCK - -#elif defined(__AVR__) -/* atomic macro for AVR */ -# include <util/atomic.h> - -# define ATOMIC_BLOCK_RESTORESTATE ATOMIC_BLOCK(ATOMIC_RESTORESTATE) -# define ATOMIC_BLOCK_FORCEON ATOMIC_BLOCK(ATOMIC_FORCEON) - -#elif defined(PROTOCOL_CHIBIOS) || defined(PROTOCOL_ARM_ATSAM) -/* atomic macro for ChibiOS / ARM ATSAM */ -# if defined(PROTOCOL_ARM_ATSAM) -# include "arm_atsam_protocol.h" -# endif - -static __inline__ uint8_t __interrupt_disable__(void) { -# if defined(PROTOCOL_CHIBIOS) - chSysLock(); -# endif -# if defined(PROTOCOL_ARM_ATSAM) - __disable_irq(); -# endif - return 1; -} - -static __inline__ void __interrupt_enable__(const uint8_t *__s) { -# if defined(PROTOCOL_CHIBIOS) - chSysUnlock(); -# endif -# if defined(PROTOCOL_ARM_ATSAM) - __enable_irq(); -# endif - __asm__ volatile("" ::: "memory"); - (void)__s; -} - -# define ATOMIC_BLOCK(type) for (type, __ToDo = __interrupt_disable__(); __ToDo; __ToDo = 0) -# define ATOMIC_FORCEON uint8_t sreg_save __attribute__((__cleanup__(__interrupt_enable__))) = 0 - -# define ATOMIC_BLOCK_RESTORESTATE _Static_assert(0, "ATOMIC_BLOCK_RESTORESTATE dose not implement") -# define ATOMIC_BLOCK_FORCEON ATOMIC_BLOCK(ATOMIC_FORCEON) - -/* Other platform */ -#else - -# define ATOMIC_BLOCK_RESTORESTATE _Static_assert(0, "ATOMIC_BLOCK_RESTORESTATE dose not implement") -# define ATOMIC_BLOCK_FORCEON _Static_assert(0, "ATOMIC_BLOCK_FORCEON dose not implement") #endif - #define SEND_STRING(string) send_string_P(PSTR(string)) #define SEND_STRING_DELAY(string, interval) send_string_with_delay_P(PSTR(string), interval) diff --git a/quantum/rgb_matrix_types.h b/quantum/rgb_matrix_types.h index f7ebec1d5d..7b8171fb23 100644 --- a/quantum/rgb_matrix_types.h +++ b/quantum/rgb_matrix_types.h @@ -1,3 +1,19 @@ +/* Copyright 2021 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + #pragma once #include <stdint.h> |