diff options
Diffstat (limited to 'keyboards/ergodox_infinity')
-rw-r--r-- | keyboards/ergodox_infinity/config.h | 54 | ||||
-rw-r--r-- | keyboards/ergodox_infinity/ergodox_infinity.c | 348 | ||||
-rw-r--r-- | keyboards/ergodox_infinity/ergodox_infinity.h | 4 | ||||
-rw-r--r-- | keyboards/ergodox_infinity/keymaps/default/keymap.c | 4 | ||||
-rw-r--r-- | keyboards/ergodox_infinity/led.c | 26 | ||||
-rw-r--r-- | keyboards/ergodox_infinity/matrix.c | 184 | ||||
-rw-r--r-- | keyboards/ergodox_infinity/rules.mk | 34 | ||||
-rw-r--r-- | keyboards/ergodox_infinity/visualizer.c | 3 |
8 files changed, 325 insertions, 332 deletions
diff --git a/keyboards/ergodox_infinity/config.h b/keyboards/ergodox_infinity/config.h index a64f3f4a13..e0208ba4d3 100644 --- a/keyboards/ergodox_infinity/config.h +++ b/keyboards/ergodox_infinity/config.h @@ -54,7 +54,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. /* key matrix size */ #define MATRIX_ROWS 18 #define MATRIX_COLS 5 -#define LOCAL_MATRIX_ROWS 9 + +// For some reason, the rows are colums in the schematic, and vice versa +#define MATRIX_ROW_PINS { B2, B3, B18, B19, C0, C9, C10, C11, D0 } +#define MATRIX_COL_PINS { D1, D4, D5, D6, D7 } +#define UNUSED_PINS + +/* COL2ROW, ROW2COL */ +#define DIODE_DIRECTION ROW2COL + +/* Serial config (for communication between halves) */ +#define SERIAL_USART_DRIVER SD1 // Only true for the master half +#define SERIAL_USART_CONFIG { (SERIAL_USART_SPEED), } // Only field is speed +#define SERIAL_USART_FULL_DUPLEX +#define SERIAL_USART_TIMEOUT 50 /* number of backlight levels */ #define BACKLIGHT_LEVELS 3 @@ -62,16 +75,49 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define LED_BRIGHTNESS_LO 100 #define LED_BRIGHTNESS_HI 255 +/* LED matrix driver */ +#define LED_DRIVER_ADDR_1 0x74 +#define LED_DRIVER_COUNT 1 +#define DRIVER_LED_TOTAL 76 +#define LED_MATRIX_SPLIT { 38, 38 } +#define LED_DISABLE_WHEN_USB_SUSPENDED + +/* i2c (for LED matrix) */ +#define I2C1_CLOCK_SPEED 400000 +#define I2C1_SCL_PAL_MODE PAL_MODE_ALTERNATIVE_2 +#define I2C1_SDA_PAL_MODE PAL_MODE_ALTERNATIVE_2 +#define I2C1_BANK GPIOB +#define I2C1_SCL 0 +#define I2C1_SDA 1 + +#ifdef ST7565_ENABLE +/* LCD driver */ +# define ST7565_A0_PIN C7 +# define ST7565_RST_PIN C8 +# define ST7565_SS_PIN C4 +# define ST7565_SPI_CLK_DIVISOR 2 +# define ST7565_CONTRAST 22 +# define ST7565_DISPLAY_WIDTH 128 +# define ST7565_DISPLAY_HEIGHT 32 + +/* SPI (for LCD) */ +# define SPI_DRIVER SPID1 +# define SPI_SCK_PIN C5 +# define SPI_SCK_PAL_MODE PAL_MODE_ALTERNATIVE_2 +# define SPI_MOSI_PIN C6 +# define SPI_MOSI_PAL_MODE PAL_MODE_ALTERNATIVE_2 +# define SPI_MISO_PIN A4 // Just an unused pin, the "normal" MISO pin (C7) is used for other things +# define SPI_MISO_PAL_MODE PAL_MODE_ALTERNATIVE_7 // Default for A4 +#endif + /* define if matrix has ghost */ //#define MATRIX_HAS_GHOST /* Set 0 if debouncing isn't needed */ #define DEBOUNCE 5 -#define SERIAL_LINK_BAUD 562500 -#define SERIAL_LINK_THREAD_PRIORITY (NORMALPRIO - 1) - #define VISUALIZER_USER_DATA_SIZE 16 + /* * Feature disable options * These options are also useful to firmware size reduction. diff --git a/keyboards/ergodox_infinity/ergodox_infinity.c b/keyboards/ergodox_infinity/ergodox_infinity.c index 97b628470b..90aa522427 100644 --- a/keyboards/ergodox_infinity/ergodox_infinity.c +++ b/keyboards/ergodox_infinity/ergodox_infinity.c @@ -1,29 +1,13 @@ #include QMK_KEYBOARD_H #include <ch.h> #include <hal.h> +#include <string.h> +#include "eeconfig.h" #include "serial_link/system/serial_link.h" #ifdef VISUALIZER_ENABLE -#include "lcd_backlight.h" +# include "lcd_backlight.h" #endif -#ifdef WPM_ENABLE -# include "serial_link/protocol/transport.h" -# include "wpm.h" - -MASTER_TO_ALL_SLAVES_OBJECT(current_wpm, uint8_t); -static remote_object_t* remote_objects[] = { - REMOTE_OBJECT(current_wpm), -}; -static uint8_t last_sent_wpm = 0; -#endif - -void init_serial_link_hal(void) { - PORTA->PCR[1] = PORTx_PCRn_PE | PORTx_PCRn_PS | PORTx_PCRn_PFE | PORTx_PCRn_MUX(2); - PORTA->PCR[2] = PORTx_PCRn_DSE | PORTx_PCRn_SRE | PORTx_PCRn_MUX(2); - PORTE->PCR[0] = PORTx_PCRn_PE | PORTx_PCRn_PS | PORTx_PCRn_PFE | PORTx_PCRn_MUX(3); - PORTE->PCR[1] = PORTx_PCRn_DSE | PORTx_PCRn_SRE | PORTx_PCRn_MUX(3); -} - #define RED_PIN 1 #define GREEN_PIN 2 #define BLUE_PIN 3 @@ -52,7 +36,7 @@ void init_serial_link_hal(void) { void lcd_backlight_hal_init(void) { // Setup Backlight SIM->SCGC6 |= SIM_SCGC6_FTM0; - FTM0->CNT = 0; // Reset counter + FTM0->CNT = 0; // Reset counter // PWM Period // 16-bit maximum @@ -60,25 +44,25 @@ void lcd_backlight_hal_init(void) { // Set FTM to PWM output - Edge Aligned, Low-true pulses #define CNSC_MODE FTM_SC_CPWMS | FTM_SC_PS(4) | FTM_SC_CLKS(0) - CHANNEL_RED.CnSC = CNSC_MODE; + CHANNEL_RED.CnSC = CNSC_MODE; CHANNEL_GREEN.CnSC = CNSC_MODE; - CHANNEL_BLUE.CnSC = CNSC_MODE; + CHANNEL_BLUE.CnSC = CNSC_MODE; // System clock, /w prescalar setting FTM0->SC = FTM_SC_CLKS(1) | FTM_SC_PS(PRESCALAR_DEFINE); - CHANNEL_RED.CnV = 0; + CHANNEL_RED.CnV = 0; CHANNEL_GREEN.CnV = 0; - CHANNEL_BLUE.CnV = 0; + CHANNEL_BLUE.CnV = 0; RGB_PORT_GPIO->PDDR |= (1 << RED_PIN); RGB_PORT_GPIO->PDDR |= (1 << GREEN_PIN); RGB_PORT_GPIO->PDDR |= (1 << BLUE_PIN); #define RGB_MODE PORTx_PCRn_SRE | PORTx_PCRn_DSE | PORTx_PCRn_MUX(4) - RGB_PORT->PCR[RED_PIN] = RGB_MODE; + RGB_PORT->PCR[RED_PIN] = RGB_MODE; RGB_PORT->PCR[GREEN_PIN] = RGB_MODE; - RGB_PORT->PCR[BLUE_PIN] = RGB_MODE; + RGB_PORT->PCR[BLUE_PIN] = RGB_MODE; } static uint16_t cie_lightness(uint16_t v) { @@ -89,12 +73,11 @@ static uint16_t cie_lightness(uint16_t v) { // Y = (L* / 902.3) if L* <= 8 // Y = ((L* + 16) / 116)^3 if L* > 8 - float l = 100.0f * (v / 65535.0f); + float l = 100.0f * (v / 65535.0f); float y = 0.0f; if (l <= 8.0f) { - y = l / 902.3; - } - else { + y = l / 902.3; + } else { y = ((l + 16.0f) / 116.0f); y = y * y * y; if (y > 1.0f) { @@ -104,109 +87,89 @@ static uint16_t cie_lightness(uint16_t v) { return y * 65535.0f; } +#ifdef VISUALIZER_ENABLE void lcd_backlight_hal_color(uint16_t r, uint16_t g, uint16_t b) { - CHANNEL_RED.CnV = cie_lightness(r); +#else +void ergodox_infinity_lcd_color(uint16_t r, uint16_t g, uint16_t b) { +#endif + CHANNEL_RED.CnV = cie_lightness(r); CHANNEL_GREEN.CnV = cie_lightness(g); - CHANNEL_BLUE.CnV = cie_lightness(b); + CHANNEL_BLUE.CnV = cie_lightness(b); } -__attribute__ ((weak)) -void matrix_init_user(void) { -} +__attribute__ ((weak)) void matrix_init_user(void) {} -__attribute__ ((weak)) -void matrix_scan_user(void) { -} +__attribute__ ((weak)) void matrix_scan_user(void) {} +void keyboard_pre_init_kb() { +#ifdef LED_MATRIX_ENABLE + // Turn on LED controller + setPinOutput(B16); + writePinHigh(B16); +#endif +#ifndef VISUALIZER_ENABLE + // The backlight always has to be initialized, otherwise it will stay lit + lcd_backlight_hal_init(); +# ifdef ST7565_ENABLE + ergodox_infinity_lcd_color(UINT16_MAX / 2, UINT16_MAX / 2, UINT16_MAX / 2); +# endif +#endif + keyboard_pre_init_user(); +} + void matrix_init_kb(void) { // put your keyboard start-up code here // runs once when the firmware starts up - matrix_init_user(); - // The backlight always has to be initialized, otherwise it will stay lit -#ifndef VISUALIZER_ENABLE - lcd_backlight_hal_init(); -#endif -#ifdef WPM_ENABLE - add_remote_objects(remote_objects, sizeof(remote_objects) / sizeof(remote_object_t*)); +#ifdef LED_MATRIX_ENABLE + /* + * Since K20x is stuck with a 32 byte EEPROM (see tmk_core/common/chibios/eeprom_teensy.c), + * and neither led_matrix_eeconfig.speed or .flags fit in this boundary, just force their values to default on boot. + */ +# if !defined(LED_MATRIX_STARTUP_SPD) +# define LED_MATRIX_STARTUP_SPD UINT8_MAX / 2 +# endif + led_matrix_set_speed(LED_MATRIX_STARTUP_SPD); + led_matrix_set_flags(LED_FLAG_ALL); #endif + + matrix_init_user(); } void matrix_scan_kb(void) { // put your looping keyboard code here // runs every cycle (a lot) -#ifdef WPM_ENABLE - if (is_serial_link_master()) { - uint8_t current_wpm = get_current_wpm(); - if (current_wpm != last_sent_wpm) { - *begin_write_current_wpm() = current_wpm; - end_write_current_wpm(); - last_sent_wpm = current_wpm; - } - } else if (is_serial_link_connected()) { - uint8_t* new_wpm = read_current_wpm(); - if (new_wpm) { - set_current_wpm(*new_wpm); - } - } -#endif matrix_scan_user(); } -bool is_keyboard_master(void) { - return is_serial_link_master(); -} +__attribute__ ((weak)) void ergodox_board_led_on(void) {} -__attribute__ ((weak)) -void ergodox_board_led_on(void){ -} +__attribute__ ((weak)) void ergodox_right_led_1_on(void) {} -__attribute__ ((weak)) -void ergodox_right_led_1_on(void){ -} +__attribute__ ((weak)) void ergodox_right_led_2_on(void) {} -__attribute__ ((weak)) -void ergodox_right_led_2_on(void){ -} - -__attribute__ ((weak)) -void ergodox_right_led_3_on(void){ -} +__attribute__ ((weak)) void ergodox_right_led_3_on(void) {} -__attribute__ ((weak)) -void ergodox_board_led_off(void){ -} +__attribute__ ((weak)) void ergodox_board_led_off(void) {} -__attribute__ ((weak)) -void ergodox_right_led_1_off(void){ -} +__attribute__ ((weak)) void ergodox_right_led_1_off(void) {} -__attribute__ ((weak)) -void ergodox_right_led_2_off(void){ -} +__attribute__ ((weak)) void ergodox_right_led_2_off(void) {} -__attribute__ ((weak)) -void ergodox_right_led_3_off(void){ -} +__attribute__ ((weak)) void ergodox_right_led_3_off(void) {} -__attribute__ ((weak)) -void ergodox_right_led_1_set(uint8_t n) { -} +__attribute__ ((weak)) void ergodox_right_led_1_set(uint8_t n) {} -__attribute__ ((weak)) -void ergodox_right_led_2_set(uint8_t n) { -} +__attribute__ ((weak)) void ergodox_right_led_2_set(uint8_t n) {} -__attribute__ ((weak)) -void ergodox_right_led_3_set(uint8_t n) { -} +__attribute__ ((weak)) void ergodox_right_led_3_set(uint8_t n) {} #ifdef SWAP_HANDS_ENABLE __attribute__ ((weak)) const keypos_t PROGMEM hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = { - {{0, 9}, {1, 9}, {2, 9}, {3, 9}, {4, 9}}, + {{0, 9}, {1, 9}, {2, 9}, {3, 9}, {4, 9}}, {{0, 10}, {1, 10}, {2, 10}, {3, 10}, {4, 10}}, {{0, 11}, {1, 11}, {2, 11}, {3, 11}, {4, 11}}, {{0, 12}, {1, 12}, {2, 12}, {3, 12}, {4, 12}}, @@ -226,3 +189,192 @@ const keypos_t PROGMEM hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = { {{0, 8}, {1, 8}, {2, 8}, {3, 8}, {4, 8}}, }; #endif + +#ifdef LED_MATRIX_ENABLE +const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = { +// The numbers in the comments are the led numbers DXX on the PCB +/* Refer to IS31 manual for these locations + * driver + * | LED address + * | | */ +// Left half +// 45 44 43 42 41 40 39 + { 0, C2_2 }, { 0, C1_2 }, { 0, C5_1 }, { 0, C4_1 }, { 0, C3_1 }, { 0, C2_1 }, { 0, C1_1 }, +// 52 51 50 49 48 47 46 + { 0, C4_3 }, { 0, C3_3 }, { 0, C2_3 }, { 0, C1_3 }, { 0, C5_2 }, { 0, C4_2 }, { 0, C3_2 }, +// 58 57 56 55 54 53 + { 0, C5_4 }, { 0, C4_4 }, { 0, C3_4 }, { 0, C2_4 }, { 0, C1_4 }, { 0, C5_3 }, +// 67 66 65 64 63 62 61 + { 0, C4_6 }, { 0, C3_6 }, { 0, C2_6 }, { 0, C1_6 }, { 0, C5_5 }, { 0, C4_5 }, { 0, C3_5 }, +// 76 75 74 73 72 + { 0, C4_8 }, { 0, C3_8 }, { 0, C2_8 }, { 0, C1_8 }, { 0, C4_7 }, +// 60 59 + { 0, C2_5 }, { 0, C1_5 }, +// 68 + { 0, C5_6 }, +// 71 70 69 + { 0, C3_7 }, { 0, C2_7 }, { 0, C1_7 }, +// Right half (mirrored) +// Due to how LED_MATRIX_SPLIT is implemented, only the first half of g_is31_leds is actually used. +// Luckily, the right half has the same LED pinouts, just mirrored. +// 45 44 43 42 41 40 39 + { 0, C2_2 }, { 0, C1_2 }, { 0, C5_1 }, { 0, C4_1 }, { 0, C3_1 }, { 0, C2_1 }, { 0, C1_1 }, +// 52 51 50 49 48 47 46 + { 0, C4_3 }, { 0, C3_3 }, { 0, C2_3 }, { 0, C1_3 }, { 0, C5_2 }, { 0, C4_2 }, { 0, C3_2 }, +// 58 57 56 55 54 53 + { 0, C5_4 }, { 0, C4_4 }, { 0, C3_4 }, { 0, C2_4 }, { 0, C1_4 }, { 0, C5_3 }, +// 67 66 65 64 63 62 61 + { 0, C4_6 }, { 0, C3_6 }, { 0, C2_6 }, { 0, C1_6 }, { 0, C5_5 }, { 0, C4_5 }, { 0, C3_5 }, +// 76 75 74 73 72 + { 0, C4_8 }, { 0, C3_8 }, { 0, C2_8 }, { 0, C1_8 }, { 0, C4_7 }, +// 60 59 + { 0, C2_5 }, { 0, C1_5 }, +// 68 + { 0, C5_6 }, +// 71 70 69 + { 0, C3_7 }, { 0, C2_7 }, { 0, C1_7 }, +}; + +led_config_t g_led_config = { + { + // Key Matrix to LED Index + // Left half + { NO_LED, NO_LED, NO_LED, 33, 34 }, + { NO_LED, NO_LED, NO_LED, 32, 37 }, + { 6, 13, NO_LED, 26, 36 }, + { 5, 12, 19, 25, 35 }, + { 4, 11, 18, 24, 31 }, + { 3, 10, 17, 23, 30 }, + { 2, 9, 16, 22, 29 }, + { 1, 8, 15, 21, 28 }, + { 0, 7, 14, 20, 27 }, + // Right half + { NO_LED, NO_LED, NO_LED, 71, 72 }, + { NO_LED, NO_LED, NO_LED, 70, 75 }, + { 44, 51, NO_LED, 64, 74 }, + { 43, 50, 57, 63, 73 }, + { 42, 49, 56, 62, 69 }, + { 41, 48, 55, 61, 68 }, + { 40, 47, 54, 60, 67 }, + { 39, 46, 53, 59, 66 }, + { 38, 45, 52, 58, 65 }, + }, { + // LED Index to Physical Position (assumes a reasonable gap between halves) + // Left half + { 0, 3 }, { 15, 3 }, { 27, 1 }, { 39, 0 }, { 51, 1 }, { 63, 2 }, { 75, 2 }, + { 0, 13 }, { 15, 13 }, { 27, 11 }, { 39, 10 }, { 51, 11 }, { 63, 12 }, { 78, 17 }, + { 0, 23 }, { 15, 23 }, { 27, 21 }, { 39, 20 }, { 51, 21 }, { 63, 22 }, + { 0, 33 }, { 15, 33 }, { 27, 31 }, { 39, 30 }, { 51, 31 }, { 63, 32 }, { 78, 32 }, + { 4, 43 }, { 15, 43 }, { 27, 41 }, { 39, 40 }, { 51, 41 }, + { 89, 41 }, { 100, 46 }, + { 95, 55 }, + { 72, 54 }, { 83, 59 }, { 90, 64 }, + // Right half (mirrored) + { 224, 3 }, { 209, 3 }, { 197, 1 }, { 185, 0 }, { 173, 1 }, { 161, 2 }, { 149, 2 }, + { 224, 13 }, { 209, 13 }, { 197, 11 }, { 185, 10 }, { 173, 11 }, { 161, 12 }, { 146, 17 }, + { 224, 23 }, { 209, 23 }, { 197, 21 }, { 185, 20 }, { 173, 21 }, { 161, 22 }, + { 224, 33 }, { 209, 33 }, { 197, 31 }, { 185, 30 }, { 173, 31 }, { 161, 32 }, { 146, 32 }, + { 220, 43 }, { 209, 43 }, { 197, 41 }, { 185, 40 }, { 173, 41 }, + { 135, 41 }, { 124, 46 }, + { 129, 55 }, + { 152, 54 }, { 141, 59 }, { 134, 64 }, + }, { + // LED Index to Flag + // Left half + 1, 4, 4, 4, 4, 4, 1, + 1, 4, 4, 4, 4, 4, 1, + 1, 4, 4, 4, 4, 4, + 1, 4, 4, 4, 4, 4, 1, + 1, 1, 1, 1, 1, + 1, 1, + 1, + 1, 1, 1, + // Right half (mirrored) + 1, 4, 4, 4, 4, 4, 1, + 1, 4, 4, 4, 4, 4, 1, + 1, 4, 4, 4, 4, 4, + 1, 4, 4, 4, 4, 4, 1, + 1, 1, 1, 1, 1, + 1, 1, + 1, + 1, 1, 1, + } +}; +#endif + +#ifdef ST7565_ENABLE +__attribute__((weak)) void st7565_on_user(void) { + ergodox_infinity_lcd_color(UINT16_MAX / 2, UINT16_MAX / 2, UINT16_MAX / 2); +} + +__attribute__((weak)) void st7565_off_user(void) { + ergodox_infinity_lcd_color(0, 0, 0); +} + +static void format_layer_bitmap_string(char* buffer, uint8_t offset) { + for (int i = 0; i < 16 && i + offset < MAX_LAYER; i++) { + if (i == 0 || i == 4 || i == 8 || i == 12) { + *buffer = ' '; + ++buffer; + } + + uint8_t layer = i + offset; + if (layer_state_cmp(default_layer_state, layer)) { + *buffer = 'D'; + } else if (layer_state_is(layer)) { + *buffer = '1'; + } else { + *buffer = '_'; + } + ++buffer; + } + *buffer = 0; +} + +__attribute__((weak)) void st7565_task_user(void) { + if (is_keyboard_master()) { + // Draw led and layer status + led_t leds = host_keyboard_led_state(); + if(leds.num_lock) { st7565_write("Num ", false); } + if(leds.caps_lock) { st7565_write("Cap ", false); } + if(leds.scroll_lock) { st7565_write("Scrl ", false); } + if(leds.compose) { st7565_write("Com ", false); } + if(leds.kana) { st7565_write("Kana", false); } + st7565_advance_page(true); + + char layer_buffer[16 + 5]; // 3 spaces and one null terminator + st7565_set_cursor(0, 1); + format_layer_bitmap_string(layer_buffer, 0); + st7565_write_ln(layer_buffer, false); + format_layer_bitmap_string(layer_buffer, 16); + st7565_write_ln(layer_buffer, false); + st7565_write_ln(" 1=On D=Default", false); + } else { + // Draw logo + static const char qmk_logo[] = { + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, 0x93, 0x94, + 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, + 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0x00 + }; + + st7565_write(qmk_logo, false); + st7565_write(" Infinity Ergodox ", false); + } +} +#endif + +#if defined(SPLIT_KEYBOARD) +void usart_master_init(SerialDriver **driver) { + PORTA->PCR[1] = PORTx_PCRn_PE | PORTx_PCRn_PS | PORTx_PCRn_PFE | PORTx_PCRn_MUX(2); + PORTA->PCR[2] = PORTx_PCRn_DSE | PORTx_PCRn_SRE | PORTx_PCRn_MUX(2); + + // driver is set to SD1 in config.h +} + +void usart_slave_init(SerialDriver **driver) { + PORTE->PCR[0] = PORTx_PCRn_PE | PORTx_PCRn_PS | PORTx_PCRn_PFE | PORTx_PCRn_MUX(3); + PORTE->PCR[1] = PORTx_PCRn_DSE | PORTx_PCRn_SRE | PORTx_PCRn_MUX(3); + + *driver = &SD2; +} +#endif diff --git a/keyboards/ergodox_infinity/ergodox_infinity.h b/keyboards/ergodox_infinity/ergodox_infinity.h index 79f01b1849..81ac1f338a 100644 --- a/keyboards/ergodox_infinity/ergodox_infinity.h +++ b/keyboards/ergodox_infinity/ergodox_infinity.h @@ -80,6 +80,10 @@ inline void ergodox_led_all_set(uint8_t n) { ergodox_right_led_3_set(n); } +#ifndef VISUALIZER_ENABLE +void ergodox_infinity_lcd_color(uint16_t r, uint16_t g, uint16_t b); +#endif + /* * LEFT HAND: LINES 88-95 * RIGHT HAND: LINES 97-104 diff --git a/keyboards/ergodox_infinity/keymaps/default/keymap.c b/keyboards/ergodox_infinity/keymaps/default/keymap.c index cd9b476bbd..ce8a3661e7 100644 --- a/keyboards/ergodox_infinity/keymaps/default/keymap.c +++ b/keyboards/ergodox_infinity/keymaps/default/keymap.c @@ -167,7 +167,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { // Runs just one time when the keyboard initializes. void matrix_init_user(void) { -}; +} // Runs constantly in the background, in a loop. @@ -192,4 +192,4 @@ void matrix_scan_user(void) { break; } -}; +} diff --git a/keyboards/ergodox_infinity/led.c b/keyboards/ergodox_infinity/led.c deleted file mode 100644 index 0b50247d7a..0000000000 --- a/keyboards/ergodox_infinity/led.c +++ /dev/null @@ -1,26 +0,0 @@ -/* -Copyright 2012 Jun Wako <wakojun@gmail.com> - -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/>. -*/ - -#include <hal.h> - -#include "led.h" - - -void led_set(uint8_t usb_led) { - //TODO: Add led emulation if there's no customized visualization - (void)usb_led; -} diff --git a/keyboards/ergodox_infinity/matrix.c b/keyboards/ergodox_infinity/matrix.c deleted file mode 100644 index 7baacd24d0..0000000000 --- a/keyboards/ergodox_infinity/matrix.c +++ /dev/null @@ -1,184 +0,0 @@ -/* -Copyright 2016 Fred Sundvik <fsundvik@gmail.com> -Jun Wako <wakojun@gmail.com> - -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/>. -*/ -#include <stdint.h> -#include <stdbool.h> -#include <string.h> -#include <hal.h> -#include "timer.h" -#include "wait.h" -#include "print.h" -#include "debug.h" -#include "matrix.h" -#include "eeconfig.h" -#include "serial_link/system/serial_link.h" - - -/* - * Infinity ErgoDox Pinusage: - * Column pins are input with internal pull-down. Row pins are output and strobe with high. - * Key is high or 1 when it turns on. - * - * col: { PTD1, PTD4, PTD5, PTD6, PTD7 } - * row: { PTB2, PTB3, PTB18, PTB19, PTC0, PTC9, PTC10, PTC11, PTD0 } - */ -/* matrix state(1:on, 0:off) */ -static matrix_row_t matrix[MATRIX_ROWS]; -static matrix_row_t matrix_debouncing[LOCAL_MATRIX_ROWS]; -static bool debouncing = false; -static uint16_t debouncing_time = 0; - - -void matrix_init(void) -{ - /* Row(sense) */ - palSetPadMode(GPIOD, 1, PAL_MODE_INPUT_PULLDOWN); - palSetPadMode(GPIOD, 4, PAL_MODE_INPUT_PULLDOWN); - palSetPadMode(GPIOD, 5, PAL_MODE_INPUT_PULLDOWN); - palSetPadMode(GPIOD, 6, PAL_MODE_INPUT_PULLDOWN); - palSetPadMode(GPIOD, 7, PAL_MODE_INPUT_PULLDOWN); - - /* Column(strobe) */ - palSetPadMode(GPIOB, 2, PAL_MODE_OUTPUT_PUSHPULL); - palSetPadMode(GPIOB, 3, PAL_MODE_OUTPUT_PUSHPULL); - palSetPadMode(GPIOB, 18, PAL_MODE_OUTPUT_PUSHPULL); - palSetPadMode(GPIOB, 19, PAL_MODE_OUTPUT_PUSHPULL); - palSetPadMode(GPIOC, 0, PAL_MODE_OUTPUT_PUSHPULL); - palSetPadMode(GPIOC, 9, PAL_MODE_OUTPUT_PUSHPULL); - palSetPadMode(GPIOC, 10, PAL_MODE_OUTPUT_PUSHPULL); - palSetPadMode(GPIOC, 11, PAL_MODE_OUTPUT_PUSHPULL); - palSetPadMode(GPIOD, 0, PAL_MODE_OUTPUT_PUSHPULL); - - memset(matrix, 0, MATRIX_ROWS * sizeof(matrix_row_t)); - memset(matrix_debouncing, 0, LOCAL_MATRIX_ROWS * sizeof(matrix_row_t)); - - matrix_init_quantum(); -} - -uint8_t matrix_scan(void) -{ - for (int row = 0; row < LOCAL_MATRIX_ROWS; row++) { - matrix_row_t data = 0; - - // strobe row - switch (row) { - case 0: palSetPad(GPIOB, 2); break; - case 1: palSetPad(GPIOB, 3); break; - case 2: palSetPad(GPIOB, 18); break; - case 3: palSetPad(GPIOB, 19); break; - case 4: palSetPad(GPIOC, 0); break; - case 5: palSetPad(GPIOC, 9); break; - case 6: palSetPad(GPIOC, 10); break; - case 7: palSetPad(GPIOC, 11); break; - case 8: palSetPad(GPIOD, 0); break; - } - - // need wait to settle pin state - // if you wait too short, or have a too high update rate - // the keyboard might freeze, or there might not be enough - // processing power to update the LCD screen properly. - // 20us, or two ticks at 100000Hz seems to be OK - wait_us(20); - - // read col data: { PTD1, PTD4, PTD5, PTD6, PTD7 } - data = ((palReadPort(GPIOD) & 0xF0) >> 3) | - ((palReadPort(GPIOD) & 0x02) >> 1); - - // un-strobe row - switch (row) { - case 0: palClearPad(GPIOB, 2); break; - case 1: palClearPad(GPIOB, 3); break; - case 2: palClearPad(GPIOB, 18); break; - case 3: palClearPad(GPIOB, 19); break; - case 4: palClearPad(GPIOC, 0); break; - case 5: palClearPad(GPIOC, 9); break; - case 6: palClearPad(GPIOC, 10); break; - case 7: palClearPad(GPIOC, 11); break; - case 8: palClearPad(GPIOD, 0); break; - } - - if (matrix_debouncing[row] != data) { - matrix_debouncing[row] = data; - debouncing = true; - debouncing_time = timer_read(); - } - } - - uint8_t offset = 0; -#if (defined(EE_HANDS) || defined(MASTER_IS_ON_RIGHT)) -#ifdef EE_HANDS - if (is_serial_link_master() && !eeconfig_read_handedness()) { -#else - if (is_serial_link_master()) { -#endif - offset = MATRIX_ROWS - LOCAL_MATRIX_ROWS; - } -#endif - - if (debouncing && timer_elapsed(debouncing_time) > DEBOUNCE) { - for (int row = 0; row < LOCAL_MATRIX_ROWS; row++) { - matrix[offset + row] = matrix_debouncing[row]; - } - debouncing = false; - } - matrix_scan_quantum(); - return 1; -} - -bool matrix_is_on(uint8_t row, uint8_t col) -{ - return (matrix[row] & (1<<col)); -} - -matrix_row_t matrix_get_row(uint8_t row) -{ - return matrix[row]; -} - -void matrix_print(void) -{ - xprintf("\nr/c 01234567\n"); - for (uint8_t row = 0; row < MATRIX_ROWS; row++) { - xprintf("%X0: ", row); - matrix_row_t data = matrix_get_row(row); - for (int col = 0; col < MATRIX_COLS; col++) { - if (data & (1<<col)) - xprintf("1"); - else - xprintf("0"); - } - xprintf("\n"); - } -} - -void matrix_set_remote(matrix_row_t* rows, uint8_t index) { - uint8_t offset = 0; -#ifdef EE_HANDS - if (eeconfig_read_handedness()) { - offset = LOCAL_MATRIX_ROWS * (index + 1); - } else { - offset = MATRIX_ROWS - LOCAL_MATRIX_ROWS * (index + 2); - } -#elif defined(MASTER_IS_ON_RIGHT) - offset = MATRIX_ROWS - LOCAL_MATRIX_ROWS * (index + 2); -#else - offset = LOCAL_MATRIX_ROWS * (index + 1); -#endif - for (int row = 0; row < LOCAL_MATRIX_ROWS; row++) { - matrix[offset + row] = rows[row]; - } -} diff --git a/keyboards/ergodox_infinity/rules.mk b/keyboards/ergodox_infinity/rules.mk index b9ead9e87c..6c490ca0d8 100644 --- a/keyboards/ergodox_infinity/rules.mk +++ b/keyboards/ergodox_infinity/rules.mk @@ -4,6 +4,13 @@ MCU = MK20DX256 # Bootloader selection BOOTLOADER = kiibohd +# Board: it should exist either in <chibios>/os/hal/boards/ +# or <this_dir>/boards +# This board was copied from PJRC_TEENSY_3_1. The only difference should be a +# hack to ensure the watchdog has started before trying to disable it, and an +# override to disable restart of USB driver after returning from suspend. +BOARD = IC_TEENSY_3_1 + # Build Options # comment out to disable the options. # @@ -12,32 +19,27 @@ MOUSEKEY_ENABLE = yes # Mouse keys EXTRAKEY_ENABLE = yes # Audio control and System control CONSOLE_ENABLE = no # Console for debug COMMAND_ENABLE = yes # Commands for debug and configuration -CUSTOM_MATRIX = yes # Custom matrix file for the ErgoDox EZ SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend NKRO_ENABLE = yes # USB Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work UNICODE_ENABLE = yes # Unicode SWAP_HANDS_ENABLE= yes # Allow swapping hands of keyboard -CUSTOM_MATRIX = yes # Custom matrix file -SERIAL_LINK_ENABLE = yes -VISUALIZER_ENABLE = yes -LCD_ENABLE = yes -BACKLIGHT_ENABLE = yes -BACKLIGHT_DRIVER = custom -LCD_BACKLIGHT_ENABLE = yes MIDI_ENABLE = no RGBLIGHT_ENABLE = no +SPLIT_KEYBOARD = yes +SERIAL_DRIVER = usart + +ST7565_ENABLE = yes + +LED_MATRIX_ENABLE = yes +LED_MATRIX_DRIVER = IS31FL3731 + +# Config for Visualizer (set VISUALIZER_ENABLE = yes and ST7565_ENABLE = no to use) +LCD_ENABLE = yes +LCD_BACKLIGHT_ENABLE = yes LCD_DRIVER = st7565 LCD_WIDTH = 128 LCD_HEIGHT = 32 -LED_DRIVER = is31fl3731c -LED_WIDTH = 7 -LED_HEIGHT = 7 - -# project specific files -SRC = matrix.c \ - led.c - LAYOUTS = ergodox diff --git a/keyboards/ergodox_infinity/visualizer.c b/keyboards/ergodox_infinity/visualizer.c index 4b16021abc..1ea891e830 100644 --- a/keyboards/ergodox_infinity/visualizer.c +++ b/keyboards/ergodox_infinity/visualizer.c @@ -30,7 +30,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "visualizer_keyframes.h" #include "lcd_keyframes.h" #include "lcd_backlight_keyframes.h" -#include "system/serial_link.h" #include "default_animations.h" static const uint32_t logo_background_color = LCD_COLOR(0x00, 0x00, 0xFF); @@ -177,7 +176,7 @@ static void update_emulated_leds(visualizer_state_t* state, visualizer_keyboard_ uint8_t new_index; uint8_t old_index; - if (is_serial_link_master()) { + if (is_keyboard_master()) { new_index = get_led_index_master(user_data_new); old_index = get_led_index_master(user_data_old); } |