diff options
| author | Joakim Tufvegren <jocke@barbanet.com> | 2020-09-20 01:25:20 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-19 16:25:20 -0700 |
| commit | 6eab8a0b619b55ca612d9cf048d365b1ba442328 (patch) | |
| tree | e780c33a47110df854ff12c471f7bd46f85d27d4 /keyboards | |
| parent | 08ef4b4a96e5b6b5bd857a6570fdddd9d6fcaac7 (diff) | |
| download | qmk_firmware-6eab8a0b619b55ca612d9cf048d365b1ba442328.tar.gz qmk_firmware-6eab8a0b619b55ca612d9cf048d365b1ba442328.zip | |
[Keyboard] Make WPM sync between halves on Ergodox Infinity (#9526)
* Make WPM able to sync between keyboard halves on Ergodox Infinity.
* Fix mixed indentation in ergodox_infinity.c.
Diffstat (limited to 'keyboards')
| -rw-r--r-- | keyboards/ergodox_infinity/ergodox_infinity.c | 85 |
1 files changed, 57 insertions, 28 deletions
diff --git a/keyboards/ergodox_infinity/ergodox_infinity.c b/keyboards/ergodox_infinity/ergodox_infinity.c index 9fda7991f..c69c1eb36 100644 --- a/keyboards/ergodox_infinity/ergodox_infinity.c +++ b/keyboards/ergodox_infinity/ergodox_infinity.c | |||
| @@ -6,6 +6,17 @@ | |||
| 6 | #include "lcd_backlight.h" | 6 | #include "lcd_backlight.h" |
| 7 | #endif | 7 | #endif |
| 8 | 8 | ||
| 9 | #ifdef WPM_ENABLE | ||
| 10 | # include "serial_link/protocol/transport.h" | ||
| 11 | # include "wpm.h" | ||
| 12 | |||
| 13 | MASTER_TO_ALL_SLAVES_OBJECT(current_wpm, uint8_t); | ||
| 14 | static remote_object_t* remote_objects[] = { | ||
| 15 | REMOTE_OBJECT(current_wpm), | ||
| 16 | }; | ||
| 17 | static uint8_t last_sent_wpm = 0; | ||
| 18 | #endif | ||
| 19 | |||
| 9 | void init_serial_link_hal(void) { | 20 | void init_serial_link_hal(void) { |
| 10 | PORTA->PCR[1] = PORTx_PCRn_PE | PORTx_PCRn_PS | PORTx_PCRn_PFE | PORTx_PCRn_MUX(2); | 21 | PORTA->PCR[1] = PORTx_PCRn_PE | PORTx_PCRn_PS | PORTx_PCRn_PFE | PORTx_PCRn_MUX(2); |
| 11 | PORTA->PCR[2] = PORTx_PCRn_DSE | PORTx_PCRn_SRE | PORTx_PCRn_MUX(2); | 22 | PORTA->PCR[2] = PORTx_PCRn_DSE | PORTx_PCRn_SRE | PORTx_PCRn_MUX(2); |
| @@ -39,30 +50,30 @@ void init_serial_link_hal(void) { | |||
| 39 | // Which will reduce the brightness range | 50 | // Which will reduce the brightness range |
| 40 | #define PRESCALAR_DEFINE 0 | 51 | #define PRESCALAR_DEFINE 0 |
| 41 | void lcd_backlight_hal_init(void) { | 52 | void lcd_backlight_hal_init(void) { |
| 42 | // Setup Backlight | 53 | // Setup Backlight |
| 43 | SIM->SCGC6 |= SIM_SCGC6_FTM0; | 54 | SIM->SCGC6 |= SIM_SCGC6_FTM0; |
| 44 | FTM0->CNT = 0; // Reset counter | 55 | FTM0->CNT = 0; // Reset counter |
| 45 | 56 | ||
| 46 | // PWM Period | 57 | // PWM Period |
| 47 | // 16-bit maximum | 58 | // 16-bit maximum |
| 48 | FTM0->MOD = 0xFFFF; | 59 | FTM0->MOD = 0xFFFF; |
| 49 | 60 | ||
| 50 | // Set FTM to PWM output - Edge Aligned, Low-true pulses | 61 | // Set FTM to PWM output - Edge Aligned, Low-true pulses |
| 51 | #define CNSC_MODE FTM_SC_CPWMS | FTM_SC_PS(4) | FTM_SC_CLKS(0) | 62 | #define CNSC_MODE FTM_SC_CPWMS | FTM_SC_PS(4) | FTM_SC_CLKS(0) |
| 52 | CHANNEL_RED.CnSC = CNSC_MODE; | 63 | CHANNEL_RED.CnSC = CNSC_MODE; |
| 53 | CHANNEL_GREEN.CnSC = CNSC_MODE; | 64 | CHANNEL_GREEN.CnSC = CNSC_MODE; |
| 54 | CHANNEL_BLUE.CnSC = CNSC_MODE; | 65 | CHANNEL_BLUE.CnSC = CNSC_MODE; |
| 55 | 66 | ||
| 56 | // System clock, /w prescalar setting | 67 | // System clock, /w prescalar setting |
| 57 | FTM0->SC = FTM_SC_CLKS(1) | FTM_SC_PS(PRESCALAR_DEFINE); | 68 | FTM0->SC = FTM_SC_CLKS(1) | FTM_SC_PS(PRESCALAR_DEFINE); |
| 58 | 69 | ||
| 59 | CHANNEL_RED.CnV = 0; | 70 | CHANNEL_RED.CnV = 0; |
| 60 | CHANNEL_GREEN.CnV = 0; | 71 | CHANNEL_GREEN.CnV = 0; |
| 61 | CHANNEL_BLUE.CnV = 0; | 72 | CHANNEL_BLUE.CnV = 0; |
| 62 | 73 | ||
| 63 | RGB_PORT_GPIO->PDDR |= (1 << RED_PIN); | 74 | RGB_PORT_GPIO->PDDR |= (1 << RED_PIN); |
| 64 | RGB_PORT_GPIO->PDDR |= (1 << GREEN_PIN); | 75 | RGB_PORT_GPIO->PDDR |= (1 << GREEN_PIN); |
| 65 | RGB_PORT_GPIO->PDDR |= (1 << BLUE_PIN); | 76 | RGB_PORT_GPIO->PDDR |= (1 << BLUE_PIN); |
| 66 | 77 | ||
| 67 | #define RGB_MODE PORTx_PCRn_SRE | PORTx_PCRn_DSE | PORTx_PCRn_MUX(4) | 78 | #define RGB_MODE PORTx_PCRn_SRE | PORTx_PCRn_DSE | PORTx_PCRn_MUX(4) |
| 68 | RGB_PORT->PCR[RED_PIN] = RGB_MODE; | 79 | RGB_PORT->PCR[RED_PIN] = RGB_MODE; |
| @@ -94,9 +105,9 @@ static uint16_t cie_lightness(uint16_t v) { | |||
| 94 | } | 105 | } |
| 95 | 106 | ||
| 96 | void lcd_backlight_hal_color(uint16_t r, uint16_t g, uint16_t b) { | 107 | void lcd_backlight_hal_color(uint16_t r, uint16_t g, uint16_t b) { |
| 97 | CHANNEL_RED.CnV = cie_lightness(r); | 108 | CHANNEL_RED.CnV = cie_lightness(r); |
| 98 | CHANNEL_GREEN.CnV = cie_lightness(g); | 109 | CHANNEL_GREEN.CnV = cie_lightness(g); |
| 99 | CHANNEL_BLUE.CnV = cie_lightness(b); | 110 | CHANNEL_BLUE.CnV = cie_lightness(b); |
| 100 | } | 111 | } |
| 101 | 112 | ||
| 102 | __attribute__ ((weak)) | 113 | __attribute__ ((weak)) |
| @@ -109,21 +120,39 @@ void matrix_scan_user(void) { | |||
| 109 | 120 | ||
| 110 | 121 | ||
| 111 | void matrix_init_kb(void) { | 122 | void matrix_init_kb(void) { |
| 112 | // put your keyboard start-up code here | 123 | // put your keyboard start-up code here |
| 113 | // runs once when the firmware starts up | 124 | // runs once when the firmware starts up |
| 114 | 125 | ||
| 115 | matrix_init_user(); | 126 | matrix_init_user(); |
| 116 | // The backlight always has to be initialized, otherwise it will stay lit | 127 | // The backlight always has to be initialized, otherwise it will stay lit |
| 117 | #ifndef VISUALIZER_ENABLE | 128 | #ifndef VISUALIZER_ENABLE |
| 118 | lcd_backlight_hal_init(); | 129 | lcd_backlight_hal_init(); |
| 130 | #endif | ||
| 131 | #ifdef WPM_ENABLE | ||
| 132 | add_remote_objects(remote_objects, sizeof(remote_objects) / sizeof(remote_object_t*)); | ||
| 119 | #endif | 133 | #endif |
| 120 | } | 134 | } |
| 121 | 135 | ||
| 122 | void matrix_scan_kb(void) { | 136 | void matrix_scan_kb(void) { |
| 123 | // put your looping keyboard code here | 137 | // put your looping keyboard code here |
| 124 | // runs every cycle (a lot) | 138 | // runs every cycle (a lot) |
| 125 | 139 | ||
| 126 | matrix_scan_user(); | 140 | #ifdef WPM_ENABLE |
| 141 | if (is_serial_link_master()) { | ||
| 142 | uint8_t current_wpm = get_current_wpm(); | ||
| 143 | if (current_wpm != last_sent_wpm) { | ||
| 144 | *begin_write_current_wpm() = current_wpm; | ||
| 145 | end_write_current_wpm(); | ||
| 146 | last_sent_wpm = current_wpm; | ||
| 147 | } | ||
| 148 | } else if (is_serial_link_connected()) { | ||
| 149 | uint8_t* new_wpm = read_current_wpm(); | ||
| 150 | if (new_wpm) { | ||
| 151 | set_current_wpm(*new_wpm); | ||
| 152 | } | ||
| 153 | } | ||
| 154 | #endif | ||
| 155 | matrix_scan_user(); | ||
| 127 | } | 156 | } |
| 128 | 157 | ||
| 129 | bool is_keyboard_master(void) { | 158 | bool is_keyboard_master(void) { |
