summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoakim Tufvegren <jocke@barbanet.com>2020-09-20 01:25:20 +0200
committerGitHub <noreply@github.com>2020-09-19 16:25:20 -0700
commit6eab8a0b619b55ca612d9cf048d365b1ba442328 (patch)
treee780c33a47110df854ff12c471f7bd46f85d27d4
parent08ef4b4a96e5b6b5bd857a6570fdddd9d6fcaac7 (diff)
[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.
-rw-r--r--keyboards/ergodox_infinity/ergodox_infinity.c85
1 files changed, 57 insertions, 28 deletions
diff --git a/keyboards/ergodox_infinity/ergodox_infinity.c b/keyboards/ergodox_infinity/ergodox_infinity.c
index 9fda7991f1..c69c1eb36f 100644
--- a/keyboards/ergodox_infinity/ergodox_infinity.c
+++ b/keyboards/ergodox_infinity/ergodox_infinity.c
@@ -6,6 +6,17 @@
#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);
@@ -39,30 +50,30 @@ void init_serial_link_hal(void) {
// Which will reduce the brightness range
#define PRESCALAR_DEFINE 0
void lcd_backlight_hal_init(void) {
- // Setup Backlight
+ // Setup Backlight
SIM->SCGC6 |= SIM_SCGC6_FTM0;
FTM0->CNT = 0; // Reset counter
- // PWM Period
- // 16-bit maximum
- FTM0->MOD = 0xFFFF;
+ // PWM Period
+ // 16-bit maximum
+ FTM0->MOD = 0xFFFF;
- // Set FTM to PWM output - Edge Aligned, Low-true pulses
+ // 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_GREEN.CnSC = CNSC_MODE;
- CHANNEL_BLUE.CnSC = CNSC_MODE;
+ CHANNEL_RED.CnSC = CNSC_MODE;
+ CHANNEL_GREEN.CnSC = CNSC_MODE;
+ CHANNEL_BLUE.CnSC = CNSC_MODE;
- // System clock, /w prescalar setting
- FTM0->SC = FTM_SC_CLKS(1) | FTM_SC_PS(PRESCALAR_DEFINE);
+ // System clock, /w prescalar setting
+ FTM0->SC = FTM_SC_CLKS(1) | FTM_SC_PS(PRESCALAR_DEFINE);
- CHANNEL_RED.CnV = 0;
- CHANNEL_GREEN.CnV = 0;
- CHANNEL_BLUE.CnV = 0;
+ CHANNEL_RED.CnV = 0;
+ CHANNEL_GREEN.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);
+ 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;
@@ -94,9 +105,9 @@ static uint16_t cie_lightness(uint16_t v) {
}
void lcd_backlight_hal_color(uint16_t r, uint16_t g, uint16_t b) {
- CHANNEL_RED.CnV = cie_lightness(r);
- CHANNEL_GREEN.CnV = cie_lightness(g);
- CHANNEL_BLUE.CnV = cie_lightness(b);
+ CHANNEL_RED.CnV = cie_lightness(r);
+ CHANNEL_GREEN.CnV = cie_lightness(g);
+ CHANNEL_BLUE.CnV = cie_lightness(b);
}
__attribute__ ((weak))
@@ -109,21 +120,39 @@ void matrix_scan_user(void) {
void matrix_init_kb(void) {
- // put your keyboard start-up code here
- // runs once when the firmware starts up
+ // 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
+ matrix_init_user();
+ // The backlight always has to be initialized, otherwise it will stay lit
#ifndef VISUALIZER_ENABLE
- lcd_backlight_hal_init();
+ lcd_backlight_hal_init();
+#endif
+#ifdef WPM_ENABLE
+ add_remote_objects(remote_objects, sizeof(remote_objects) / sizeof(remote_object_t*));
#endif
}
void matrix_scan_kb(void) {
- // put your looping keyboard code here
- // runs every cycle (a lot)
-
- matrix_scan_user();
+ // 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) {