summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--keyboards/ergodox_ez/ergodox_ez.c32
-rw-r--r--keyboards/planck/ez/ez.c35
-rw-r--r--quantum/oryx.c203
-rw-r--r--quantum/oryx.h27
-rw-r--r--tmk_core/protocol/chibios/usb_main.c1
-rw-r--r--tmk_core/protocol/lufa/lufa.c1
6 files changed, 43 insertions, 256 deletions
diff --git a/keyboards/ergodox_ez/ergodox_ez.c b/keyboards/ergodox_ez/ergodox_ez.c
index 0432ec79ab..7dbe0bed18 100644
--- a/keyboards/ergodox_ez/ergodox_ez.c
+++ b/keyboards/ergodox_ez/ergodox_ez.c
@@ -389,11 +389,6 @@ void eeconfig_init_kb(void) { // EEPROM is getting reset!
eeconfig_init_user();
}
-#ifdef ORYX_ENABLE
-static uint16_t loops = 0;
-static bool is_on = false;
-#endif
-
#ifdef DYNAMIC_MACRO_ENABLE
static bool is_dynamic_recording = false;
static uint16_t dynamic_loop_timer;
@@ -411,33 +406,6 @@ void dynamic_macro_record_end_user(int8_t direction) {
#endif
void matrix_scan_kb(void) {
-#ifdef ORYX_ENABLE
- if(rawhid_state.pairing == true) {
- if(loops == 0) {
- ergodox_right_led_1_off();
- ergodox_right_led_2_off();
- ergodox_right_led_3_off();
- }
- if(loops % PAIRING_BLINK_STEPS == 0) {
- if(is_on) {
- ergodox_right_led_2_off();
- } else {
- ergodox_right_led_2_on();
- }
- is_on ^= 1;
- }
- if(loops > PAIRING_BLINK_END) {
- rawhid_state.pairing = false;
- layer_state_set_user(layer_state);
- loops = 0;
- }
- loops++;
- } else if(loops > 0) {
- loops = 0;
- layer_state_set_user(layer_state);
- }
-#endif
-
#ifdef DYNAMIC_MACRO_ENABLE
if (is_dynamic_recording) {
ergodox_right_led_1_off();
diff --git a/keyboards/planck/ez/ez.c b/keyboards/planck/ez/ez.c
index 93a17be293..b387926968 100644
--- a/keyboards/planck/ez/ez.c
+++ b/keyboards/planck/ez/ez.c
@@ -301,11 +301,6 @@ bool music_mask_kb(uint16_t keycode) {
}
#endif
-#ifdef ORYX_ENABLE
-static uint16_t loops = 0;
-static bool is_on = false;
-#endif
-
#ifdef DYNAMIC_MACRO_ENABLE
static bool is_dynamic_recording = false;
static uint16_t dynamic_loop_timer;
@@ -323,36 +318,6 @@ void dynamic_macro_record_end_user(int8_t direction) {
#endif
void matrix_scan_kb(void) {
-#ifdef ORYX_ENABLE
- if(rawhid_state.pairing == true) {
- if(loops == 0) {
- //lights off
- }
- if(loops % PAIRING_BLINK_STEPS == 0) {
- if(is_on) {
- planck_ez_left_led_on();
- planck_ez_right_led_off();
- }
- else {
- planck_ez_left_led_off();
- planck_ez_right_led_on();
- }
- is_on ^= 1;
- }
- if(loops > PAIRING_BLINK_END * 2) {
- rawhid_state.pairing = false;
- loops = 0;
- planck_ez_left_led_off();
- planck_ez_right_led_off();
- }
- loops++;
- }
- else if(loops > 0) {
- loops = 0;
- planck_ez_left_led_off();
- planck_ez_right_led_off();
- }
-#endif
#ifdef DYNAMIC_MACRO_ENABLE
if (is_dynamic_recording) {
if (timer_elapsed(dynamic_loop_timer) > 1)
diff --git a/quantum/oryx.c b/quantum/oryx.c
index ebcf36ab21..5cc38c20f4 100644
--- a/quantum/oryx.c
+++ b/quantum/oryx.c
@@ -1,14 +1,11 @@
#include <string.h>
#include "oryx.h"
-#include "eeprom.h"
#ifdef KEYBOARD_voyager
# include "voyager.h"
#endif
-rawhid_state_t rawhid_state = {.pairing = false, .paired = false};
+rawhid_state_t rawhid_state = {.paired = false, .rgb_control = false};
-keypos_t keyboard_pairing_sequence[PAIRING_SEQUENCE_SIZE];
-keypos_t host_pairing_sequence[PAIRING_SEQUENCE_SIZE];
uint8_t pairing_input_index = 0;
void oryx_error(uint8_t code) {
@@ -18,10 +15,35 @@ void oryx_error(uint8_t code) {
raw_hid_send(event, RAW_EPSIZE);
}
+void oryx_layer_event(void) {
+ uint8_t layer;
+ uint8_t event[RAW_EPSIZE];
+ layer = get_highest_layer(layer_state);
+ event[0] = ORYX_EVT_LAYER;
+ event[1] = layer;
+ event[2] = ORYX_STOP_BIT;
+ raw_hid_send(event, sizeof(event));
+}
+
+void pairing_failed_event(void) {
+ rawhid_state.paired = false;
+ uint8_t event[RAW_EPSIZE];
+ event[0] = ORYX_EVT_PAIRING_FAILED;
+ event[1] = ORYX_STOP_BIT;
+ raw_hid_send(event, sizeof(event));
+}
+
+void pairing_success_event(void) {
+ rawhid_state.paired = true;
+ uint8_t event[RAW_EPSIZE];
+ event[0] = ORYX_EVT_PAIRING_SUCCESS;
+ event[1] = ORYX_STOP_BIT;
+ raw_hid_send(event, sizeof(event));
+}
+
void raw_hid_receive(uint8_t *data, uint8_t length) {
uint8_t command = data[0];
uint8_t *param = &data[1];
- uint8_t cmd_index = 0;
switch (command) {
case ORYX_CMD_GET_FW_VERSION: {
@@ -40,18 +62,17 @@ void raw_hid_receive(uint8_t *data, uint8_t length) {
}
case ORYX_CMD_PAIRING_INIT:
- pairing_init_handler();
- store_pairing_sequence(&keyboard_pairing_sequence[0]);
+ if (rawhid_state.paired == true)
+ pairing_failed_event();
+ else
+ pairing_success_event();
break;
case ORYX_CMD_PAIRING_VALIDATE:
- for (uint8_t i = 0; i < PAIRING_SEQUENCE_SIZE; i++) {
- keypos_t pos;
- pos.col = param[cmd_index++];
- pos.row = param[cmd_index++];
- host_pairing_sequence[i] = pos;
- }
- pairing_validate_eeprom_handler();
+ if (rawhid_state.paired == true)
+ pairing_failed_event();
+ else
+ pairing_success_event();
break;
case ORYX_SET_LAYER:
@@ -137,7 +158,7 @@ void raw_hid_receive(uint8_t *data, uint8_t length) {
}
break;
case ORYX_UPDATE_BRIGHTNESS:
-#if defined(RGB_MATRIX_ENABLE) && !defined(KEYBOARD_ergodox_ez_glow)
+#if defined(RGB_MATRIX_ENABLE) && !defined(PROTOCOL_LUFA)
if (param[0]) {
rgb_matrix_increase_val_noeeprom();
} else {
@@ -152,158 +173,8 @@ void raw_hid_receive(uint8_t *data, uint8_t length) {
}
}
-void pairing_validate_eeprom_handler(void) {
- bool match = false;
- uint8_t event[RAW_EPSIZE];
- uint8_t stored_sequences[sizeof(uint16_t) * PAIRING_SEQUENCE_SIZE * PAIRING_SEQUENCE_NUM_STORED];
-
- eeprom_read_block(&stored_sequences, (uint8_t *)EECONFIG_SIZE, PAIRING_STORAGE_SIZE);
- match = true;
-
- if (match == true) {
- event[0] = ORYX_EVT_PAIRING_SUCCESS;
- rawhid_state.paired = true;
-
- } else {
- event[0] = ORYX_EVT_PAIRING_FAILED;
- rawhid_state.paired = false;
- }
- event[1] = ORYX_STOP_BIT;
- rawhid_state.pairing = false;
- raw_hid_send(event, sizeof(event));
-}
-
-bool store_pairing_sequence(keypos_t *pairing_sequence) {
- uint8_t stored_sequences[sizeof(uint16_t) * PAIRING_SEQUENCE_SIZE * PAIRING_SEQUENCE_NUM_STORED];
-
- eeprom_read_block(&stored_sequences, (uint8_t *)EECONFIG_SIZE, PAIRING_STORAGE_SIZE);
-
- uint8_t shiftLen = sizeof(&pairing_sequence);
-
- for (int8_t i = PAIRING_STORAGE_SIZE; i >= 0; i--) {
- if (i > shiftLen) {
- stored_sequences[i] = stored_sequences[i - 1];
- } else {
- stored_sequences[i] = 0;
- }
- }
- eeprom_update_block(stored_sequences, (uint8_t *)EECONFIG_SIZE, PAIRING_STORAGE_SIZE);
- return true;
-}
-
-void pairing_init_handler(void) {
- create_pairing_code();
- uint8_t event[RAW_EPSIZE];
- uint8_t event_index = 0;
- event[event_index++] = ORYX_EVT_PAIRING_INPUT;
- for (uint8_t i = 0; i < PAIRING_SEQUENCE_SIZE; i++) {
- event[event_index++] = keyboard_pairing_sequence[i].col;
- event[event_index++] = keyboard_pairing_sequence[i].row;
- }
- event[event_index++] = ORYX_STOP_BIT;
- rawhid_state.pairing = true;
- raw_hid_send(event, RAW_EPSIZE);
-}
-
-bool compare_sequences(keypos_t a[PAIRING_SEQUENCE_SIZE], keypos_t b[PAIRING_SEQUENCE_SIZE]) {
- bool valid = true;
- for (uint8_t i = 0; i < PAIRING_SEQUENCE_SIZE; i++) {
- if (a[i].row != b[i].row) {
- valid = false;
- break;
- }
- if (a[i].col != b[i].col) {
- valid = false;
- break;
- }
- }
- return valid;
-}
-
-void pairing_validate_handler() {
- uint8_t event[RAW_EPSIZE];
- bool valid = compare_sequences(keyboard_pairing_sequence, host_pairing_sequence);
-
- if (valid == true) {
- event[0] = ORYX_EVT_PAIRING_SUCCESS;
- rawhid_state.paired = true;
-
- } else {
- event[0] = ORYX_EVT_PAIRING_FAILED;
- rawhid_state.paired = false;
- }
-
- event[1] = ORYX_STOP_BIT;
- rawhid_state.pairing = false;
- raw_hid_send(event, sizeof(event));
-}
-
-keypos_t get_random_keypos(void) {
- uint8_t col = rand() % MATRIX_COLS;
- uint8_t row = rand() % MATRIX_ROWS;
- keypos_t pos = {.col = col, .row = row};
-
- uint16_t keycode = keymap_key_to_keycode(0, pos);
- if (keycode >= KC_A && keycode <= KC_SLASH) {
- return pos;
- } else {
- return get_random_keypos();
- }
-}
-
-keypos_t *pairing_sequence(void) {
- // The pairing sequence is derived from Oryx's layout id declared
- // in the generated source config file with the FIRMWARE_VERSION define.
- keypos_t *sequence = (keypos_t *)&host_pairing_sequence[0];
- for (uint8_t i = 0; i < PAIRING_SEQUENCE_SIZE; i++) {
- }
-
- return sequence;
-}
-
-void create_pairing_code(void) {
- for (uint8_t i = 0; i < PAIRING_SEQUENCE_SIZE; i++) {
- keypos_t pos = get_random_keypos();
- keyboard_pairing_sequence[i] = pos;
- }
-}
-
-void pairing_key_input_event(void) {
- uint8_t event[RAW_EPSIZE];
- event[0] = ORYX_EVT_PAIRING_KEY_INPUT;
- raw_hid_send(event, sizeof(event));
-}
-
-void oryx_layer_event(void) {
- uint8_t layer;
- uint8_t event[RAW_EPSIZE];
- layer = get_highest_layer(layer_state);
- event[0] = ORYX_EVT_LAYER;
- event[1] = layer;
- event[2] = ORYX_STOP_BIT;
- raw_hid_send(event, sizeof(event));
-}
bool process_record_oryx(uint16_t keycode, keyrecord_t *record) {
- // In pairing mode, key events are absorbed, and the host pairing sequence is filled.
- // Once filled, the keyboard and host sequence are compaired, pairing state set to false
- // and the proper pairing validation event is sent to the host
- if (rawhid_state.pairing == true) {
- // The host pairing sequence is filled on key up only
- if (!record->event.pressed) {
- if (pairing_input_index < PAIRING_SEQUENCE_SIZE) {
- host_pairing_sequence[pairing_input_index++] = record->event.key;
- pairing_key_input_event();
- }
- wait_ms(1000);
- if (pairing_input_index == PAIRING_SEQUENCE_SIZE) {
- rawhid_state.pairing = false;
- pairing_input_index = 0;
- pairing_validate_handler();
- }
- }
- return false;
- }
// While paired, the keyboard sends keystrokes positions to the host
if (rawhid_state.paired == true) {
uint8_t event[RAW_EPSIZE];
@@ -318,7 +189,9 @@ bool process_record_oryx(uint16_t keycode, keyrecord_t *record) {
void layer_state_set_oryx(layer_state_t state) {
if (rawhid_state.paired) {
+#ifdef PROTOCOL_LUFA
wait_ms(50);
+#endif
uint8_t event[RAW_EPSIZE];
event[0] = ORYX_EVT_LAYER;
event[1] = get_highest_layer(state);
diff --git a/quantum/oryx.h b/quantum/oryx.h
index 063353468e..7caf039f5c 100644
--- a/quantum/oryx.h
+++ b/quantum/oryx.h
@@ -21,13 +21,8 @@ Once the host has paired, it can freely use the commands define in the Oryx_Comm
# define RAW_EPSIZE 32
#endif
-#define ORYX_PROTOCOL_VERSION = 0x01
+#define ORYX_PROTOCOL_VERSION = 0x02
#define ORYX_STOP_BIT -2
-#define PAIRING_BLINK_STEPS 512
-#define PAIRING_BLINK_END PAIRING_BLINK_STEPS * 60
-#define PAIRING_SEQUENCE_SIZE 3
-#define PAIRING_SEQUENCE_NUM_STORED 3
-#define PAIRING_STORAGE_SIZE PAIRING_SEQUENCE_SIZE* PAIRING_SEQUENCE_NUM_STORED * sizeof(uint16_t)
enum Oryx_Command_Code {
ORYX_CMD_GET_FW_VERSION,
@@ -69,32 +64,20 @@ enum Oryx_Error_Code {
extern bool oryx_state_live_training_enabled;
typedef struct {
- bool pairing;
bool paired;
bool rgb_control;
} rawhid_state_t;
extern rawhid_state_t rawhid_state;
-void create_pairing_code(void);
-void oryx_error(uint8_t code);
-bool store_pairing_sequence(keypos_t* pairing_sequence);
-keypos_t get_random_keypos(void);
-void pairing_init_handler(void);
-void pairing_validate_handler(void);
-void pairing_validate_eeprom_handler(void);
-void pairing_init_event(void);
-bool compare_sequences(keypos_t a[PAIRING_SEQUENCE_SIZE], keypos_t b[PAIRING_SEQUENCE_SIZE]);
-void pairing_key_input_event(void);
-void pairing_failed_event(void);
-void pairing_succesful_event(void);
-keypos_t* pairing_sequence(void);
+void oryx_error(uint8_t code);
+void pairing_failed_event(void);
+void pairing_succesful_event(void);
void oryx_layer_event(void);
-bool is_oryx_live_training_enabled(void);
bool process_record_oryx(uint16_t keycode, keyrecord_t* record);
void layer_state_set_oryx(layer_state_t state);
#if defined(RGB_MATRIX_ENABLE) && !defined(KEYBOARD_ergodox_ez_glow)
RGB webhid_leds[DRIVER_LED_TOTAL];
-#endif \ No newline at end of file
+#endif
diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c
index f9124f6b9d..8784e51786 100644
--- a/tmk_core/protocol/chibios/usb_main.c
+++ b/tmk_core/protocol/chibios/usb_main.c
@@ -1103,7 +1103,6 @@ void raw_hid_send(uint8_t *data, uint8_t length) {
# ifdef ORYX_ENABLE
if (chnWriteTimeout(&drivers.raw_driver.driver, data, length, TIME_IMMEDIATE) != length) {
- rawhid_state.pairing = false;
rawhid_state.paired = false;
}
# else
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index 112d0964c9..89ecb6c1f0 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -159,7 +159,6 @@ void raw_hid_send(uint8_t *data, uint8_t length) {
if (Endpoint_IsINReady()) {
// Write data
if (Endpoint_Write_Stream_LE(data, RAW_EPSIZE, NULL)) {
- rawhid_state.pairing = false;
rawhid_state.paired = false;
}
// Finalize the stream transfer to send the last packet