diff options
author | Florian Didron <fd@librem.one> | 2019-11-20 09:41:42 +0900 |
---|---|---|
committer | Drashna Jael're <drashna@live.com> | 2019-12-05 16:03:54 -0800 |
commit | 1f926d5431f31d05fbd08e645d72527105709185 (patch) | |
tree | 1d2bcbbf5db10d3eddd249c3ac4835d4b6734e64 | |
parent | 0e3739a2130dc50d93c4f2ed53ea4e53fa4a1cc4 (diff) |
feat: update examples + pairing process
-rw-r--r-- | keyboards/ergodox_ez/ergodox_ez.c | 65 | ||||
-rw-r--r-- | keyboards/ergodox_ez/keymaps/webusb/keymap.c | 345 | ||||
-rw-r--r-- | keyboards/planck/ez/ez.c | 59 | ||||
-rw-r--r-- | keyboards/planck/keymaps/webusb/keymap.c | 352 | ||||
-rw-r--r-- | quantum/quantum.c | 2 | ||||
-rw-r--r-- | tmk_core/common/webusb.c | 32 | ||||
-rw-r--r-- | tmk_core/common/webusb.h | 13 | ||||
-rw-r--r-- | tmk_core/protocol/chibios/usb_main.c | 9 | ||||
-rw-r--r-- | tmk_core/protocol/lufa/lufa.c | 16 |
9 files changed, 359 insertions, 534 deletions
diff --git a/keyboards/ergodox_ez/ergodox_ez.c b/keyboards/ergodox_ez/ergodox_ez.c index 3fd4e30833..6f56fd8e12 100644 --- a/keyboards/ergodox_ez/ergodox_ez.c +++ b/keyboards/ergodox_ez/ergodox_ez.c @@ -1,5 +1,9 @@ #include QMK_KEYBOARD_H +#ifdef WEBUSB_ENABLE +#include "webusb.h" +#endif + extern inline void ergodox_board_led_on(void); extern inline void ergodox_right_led_1_on(void); extern inline void ergodox_right_led_2_on(void); @@ -336,6 +340,17 @@ void keyboard_post_init_kb(void) { bool process_record_kb(uint16_t keycode, keyrecord_t *record) { +#ifdef WEBUSB_ENABLE + if(webusb_state.paired == true) { + uint8_t event[5]; + event[0] = WEBUSB_STATUS_OK; + event[1] = record->event.pressed ? WEBUSB_EVT_KEYDOWN : WEBUSB_EVT_KEYUP; + event[2] = record->event.key.col; + event[3] = record->event.key.row; + event[4] = WEBUSB_STOP_BIT; + webusb_send(event, sizeof(event)); + } +#endif switch (keycode) { case LED_LEVEL: if (record->event.pressed) { @@ -387,3 +402,53 @@ void eeconfig_init_kb(void) { // EEPROM is getting reset! eeconfig_update_kb(keyboard_config.raw); eeconfig_init_user(); } + +#ifdef WEBUSB_ENABLE +static uint16_t loops = 0; +static bool is_on = false; + +void matrix_scan_kb(void) { + if(webusb_state.pairing == true) { + if(loops == 0) { + ergodox_right_led_1_off(); + ergodox_right_led_2_off(); + ergodox_right_led_3_off(); + } + if(loops % WEBUSB_BLINK_STEPS == 0) { + if(is_on) { + ergodox_right_led_2_off(); + } + else { + ergodox_right_led_2_on(); + } + is_on ^= 1; + } + if(loops > WEBUSB_BLINK_END) { + webusb_state.pairing = false; + layer_state_set_user(layer_state); + loops = 0; + } + loops++; + } + else if(loops > 0) { + loops = 0; + layer_state_set_user(layer_state); + } + matrix_scan_user(); +} + +uint32_t layer_state_set_kb(uint32_t state) { + state = layer_state_set_user(state); + uint8_t layer = biton32(state); + if(webusb_state.paired == true) { + uint8_t event[4]; + event[0] = WEBUSB_STATUS_OK; + event[1] = WEBUSB_EVT_LAYER; + event[2] = layer; + event[3] = WEBUSB_STOP_BIT; + webusb_send(event, sizeof(event)); + } + return state; +} +#endif + diff --git a/keyboards/ergodox_ez/keymaps/webusb/keymap.c b/keyboards/ergodox_ez/keymaps/webusb/keymap.c index 3fe5916937..58d281de6e 100644 --- a/keyboards/ergodox_ez/keymaps/webusb/keymap.c +++ b/keyboards/ergodox_ez/keymaps/webusb/keymap.c @@ -1,242 +1,147 @@ #include QMK_KEYBOARD_H #include "version.h" -#include "webusb.h" +#include "keymap_german.h" +#include "keymap_nordic.h" +#include "keymap_french.h" +#include "keymap_spanish.h" +#include "keymap_hungarian.h" +#include "keymap_swedish.h" +#include "keymap_br_abnt2.h" +#include "keymap_canadian_multilingual.h" +#include "keymap_german_ch.h" +#include "keymap_jp.h" -#define BASE 0 // default layer -#define SYMB 1 // symbols -#define MDIA 2 // media keys +#define KC_MAC_UNDO LGUI(KC_Z) +#define KC_MAC_CUT LGUI(KC_X) +#define KC_MAC_COPY LGUI(KC_C) +#define KC_MAC_PASTE LGUI(KC_V) +#define KC_PC_UNDO LCTL(KC_Z) +#define KC_PC_CUT LCTL(KC_X) +#define KC_PC_COPY LCTL(KC_C) +#define KC_PC_PASTE LCTL(KC_V) +#define ES_LESS_MAC KC_GRAVE +#define ES_GRTR_MAC LSFT(KC_GRAVE) +#define ES_BSLS_MAC ALGR(KC_6) enum custom_keycodes { - EPRM = SAFE_RANGE, - VRSN, - RGB_SLD + RGB_SLD = EZ_SAFE_RANGE, + HSV_172_255_255, + HSV_86_255_128, + HSV_27_255_255, }; -// Ping pong: when receiving bytes from the host we send it back -void webusb_receive(uint8_t *data, uint8_t length) { - webusb_send(data, length); -} - const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { -/* Keymap 0: Basic layer - * - * ,--------------------------------------------------. ,--------------------------------------------------. - * | = | 1 | 2 | 3 | 4 | 5 | LEFT | | RIGHT| 6 | 7 | 8 | 9 | 0 | - | - * |--------+------+------+------+------+-------------| |------+------+------+------+------+------+--------| - * | Del | Q | W | E | R | T | L1 | | L1 | Y | U | I | O | P | \ | - * |--------+------+------+------+------+------| | | |------+------+------+------+------+--------| - * | BkSp | A | S | D | F | G |------| |------| H | J | K | L |; / L2|' / Cmd | - * |--------+------+------+------+------+------| Hyper| | Meh |------+------+------+------+------+--------| - * | LShift |Z/Ctrl| X | C | V | B | | | | N | M | , | . |//Ctrl| RShift | - * `--------+------+------+------+------+-------------' `-------------+------+------+------+------+--------' - * |Grv/L1| '" |AltShf| Left | Right| | Up | Down | [ | ] | ~L1 | - * `----------------------------------' `----------------------------------' - * ,-------------. ,-------------. - * | App | LGui | | Alt |Ctrl/Esc| - * ,------|------|------| |------+--------+------. - * | | | Home | | PgUp | | | - * | Space|Backsp|------| |------| Tab |Enter | - * | |ace | End | | PgDn | | | - * `--------------------' `----------------------' - */ -[BASE] = LAYOUT_ergodox( - // left hand - KC_EQL, KC_1, KC_2, KC_3, KC_4, KC_5, KC_LEFT, - KC_DELT, KC_Q, KC_W, KC_E, KC_R, KC_T, TG(SYMB), - KC_BSPC, KC_A, KC_S, KC_D, KC_F, KC_G, - KC_LSFT, CTL_T(KC_Z), KC_X, KC_C, KC_V, KC_B, ALL_T(KC_NO), - LT(SYMB,KC_GRV), KC_QUOT, LALT(KC_LSFT), KC_LEFT, KC_RGHT, - ALT_T(KC_APP), KC_LGUI, - KC_HOME, - KC_SPC, KC_BSPC, KC_END, - // right hand - KC_RGHT, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, - TG(SYMB), KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSLS, - KC_H, KC_J, KC_K, KC_L, LT(MDIA, KC_SCLN), GUI_T(KC_QUOT), - MEH_T(KC_NO), KC_N, KC_M, KC_COMM, KC_DOT, CTL_T(KC_SLSH), KC_RSFT, - KC_UP, KC_DOWN, KC_LBRC, KC_RBRC, TT(SYMB), - KC_LALT, CTL_T(KC_ESC), - KC_PGUP, - KC_PGDN, KC_TAB, KC_ENT -), -/* Keymap 1: Symbol Layer - * - * ,---------------------------------------------------. ,--------------------------------------------------. - * |Version | F1 | F2 | F3 | F4 | F5 | | | | F6 | F7 | F8 | F9 | F10 | F11 | - * |---------+------+------+------+------+------+------| |------+------+------+------+------+------+--------| - * | | ! | @ | { | } | | | | | | Up | 7 | 8 | 9 | * | F12 | - * |---------+------+------+------+------+------| | | |------+------+------+------+------+--------| - * | | # | $ | ( | ) | ` |------| |------| Down | 4 | 5 | 6 | + | | - * |---------+------+------+------+------+------| | | |------+------+------+------+------+--------| - * | | % | ^ | [ | ] | ~ | | | | & | 1 | 2 | 3 | \ | | - * `---------+------+------+------+------+-------------' `-------------+------+------+------+------+--------' - * | EPRM | | | | | | | . | 0 | = | | - * `-----------------------------------' `----------------------------------' - * ,-------------. ,-------------. - * |Animat| | |Toggle|Solid | - * ,------|------|------| |------+------+------. - * |Bright|Bright| | | |Hue- |Hue+ | - * |ness- |ness+ |------| |------| | | - * | | | | | | | | - * `--------------------' `--------------------' - */ -[SYMB] = LAYOUT_ergodox( - // left hand - WEBUSB_PAIR, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_TRNS, - KC_TRNS, KC_EXLM, KC_AT, KC_LCBR, KC_RCBR, KC_PIPE, KC_TRNS, - KC_TRNS, KC_HASH, KC_DLR, KC_LPRN, KC_RPRN, KC_GRV, - KC_TRNS, KC_PERC, KC_CIRC, KC_LBRC, KC_RBRC, KC_TILD, KC_TRNS, - EPRM, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - RGB_MOD, KC_TRNS, - KC_TRNS, - RGB_VAD, RGB_VAI, KC_TRNS, - // right hand - KC_TRNS, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, - KC_TRNS, KC_UP, KC_7, KC_8, KC_9, KC_ASTR, KC_F12, - KC_DOWN, KC_4, KC_5, KC_6, KC_PLUS, KC_TRNS, - KC_TRNS, KC_AMPR, KC_1, KC_2, KC_3, KC_BSLS, KC_TRNS, - KC_TRNS, KC_DOT, KC_0, KC_EQL, KC_TRNS, - RGB_TOG, RGB_SLD, - KC_TRNS, - KC_TRNS, RGB_HUD, RGB_HUI -), -/* Keymap 2: Media and mouse keys - * - * ,--------------------------------------------------. ,--------------------------------------------------. - * | | | | | | | | | | | | | | | | - * |--------+------+------+------+------+-------------| |------+------+------+------+------+------+--------| - * | | | | MsUp | | | | | | | | | | | | - * |--------+------+------+------+------+------| | | |------+------+------+------+------+--------| - * | | |MsLeft|MsDown|MsRght| |------| |------| | | | | | Play | - * |--------+------+------+------+------+------| | | |------+------+------+------+------+--------| - * | | | | | | | | | | | | Prev | Next | | | - * `--------+------+------+------+------+-------------' `-------------+------+------+------+------+--------' - * | | | | Lclk | Rclk | |VolUp |VolDn | Mute | | | - * `----------------------------------' `----------------------------------' - * ,-------------. ,-------------. - * | | | | | | - * ,------|------|------| |------+------+------. - * | | | | | | |Brwser| - * | | |------| |------| |Back | - * | | | | | | | | - * `--------------------' `--------------------' - */ -[MDIA] = LAYOUT_ergodox( - // left hand - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_MS_U, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_MS_L, KC_MS_D, KC_MS_R, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_BTN1, KC_BTN2, - KC_TRNS, KC_TRNS, - KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, - // right hand - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MPLY, - KC_TRNS, KC_TRNS, KC_TRNS, KC_MPRV, KC_MNXT, KC_TRNS, KC_TRNS, - KC_VOLU, KC_VOLD, KC_MUTE, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, - KC_TRNS, - KC_TRNS, KC_TRNS, KC_WBAK -), + [0] = LAYOUT_ergodox_pretty( + WEBUSB_PAIR, KC_1, KC_2, KC_3, KC_4, KC_5, KC_LEFT, KC_RIGHT, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINUS, + KC_DELETE, KC_Q, KC_W, KC_E, KC_R, KC_T, TG(1), TG(1), KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSLASH, + KC_BSPACE, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, LT(2,KC_SCOLON),LGUI_T(KC_QUOTE), + KC_LSHIFT, LCTL_T(KC_Z), KC_X, KC_C, KC_V, KC_B, KC_HYPR, KC_MEH, KC_N, KC_M, KC_COMMA, KC_DOT, RCTL_T(KC_SLASH),KC_RSHIFT, + LT(1,KC_GRAVE), KC_QUOTE, LALT(KC_LSHIFT),KC_LEFT, KC_RIGHT, KC_UP, KC_DOWN, KC_LBRACKET, KC_RBRACKET, MO(1), + LALT_T(KC_APPLICATION),KC_LGUI, KC_LALT, LCTL_T(KC_ESCAPE), + KC_HOME, KC_PGUP, + KC_SPACE, KC_BSPACE, KC_END, KC_PGDOWN, KC_TAB, KC_ENTER + ), + [1] = LAYOUT_ergodox_pretty( + KC_ESCAPE, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_TRANSPARENT, KC_TRANSPARENT, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, + KC_TRANSPARENT, KC_EXLM, KC_AT, KC_LCBR, KC_RCBR, KC_PIPE, KC_TRANSPARENT, KC_TRANSPARENT, KC_UP, KC_7, KC_8, KC_9, KC_ASTR, KC_F12, + KC_TRANSPARENT, KC_HASH, KC_DLR, KC_LPRN, KC_RPRN, KC_GRAVE, KC_DOWN, KC_4, KC_5, KC_6, KC_PLUS, KC_TRANSPARENT, + KC_TRANSPARENT, KC_PERC, KC_CIRC, KC_LBRACKET, KC_RBRACKET, KC_TILD, KC_TRANSPARENT, KC_TRANSPARENT, KC_AMPR, KC_1, KC_2, KC_3, KC_BSLASH, KC_TRANSPARENT, + KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_DOT, KC_0, KC_EQUAL, KC_TRANSPARENT, + RGB_MOD, HSV_172_255_255,RGB_TOG, RGB_SLD, + HSV_86_255_128, KC_TRANSPARENT, + RGB_VAD, RGB_VAI, HSV_27_255_255, KC_TRANSPARENT, RGB_HUD, RGB_HUI + ), + [2] = LAYOUT_ergodox_pretty( + KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, + KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_MS_UP, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, + KC_TRANSPARENT, KC_TRANSPARENT, KC_MS_LEFT, KC_MS_DOWN, KC_MS_RIGHT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_MEDIA_PLAY_PAUSE, + KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_MEDIA_PREV_TRACK,KC_MEDIA_NEXT_TRACK,KC_TRANSPARENT, KC_TRANSPARENT, + KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_MS_BTN1, KC_MS_BTN2, KC_AUDIO_VOL_UP,KC_AUDIO_VOL_DOWN,KC_AUDIO_MUTE, KC_TRANSPARENT, KC_TRANSPARENT, + KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, + KC_TRANSPARENT, KC_TRANSPARENT, + KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_WWW_BACK + ), }; + +bool suspended = false; + bool process_record_user(uint16_t keycode, keyrecord_t *record) { - if (record->event.pressed) { - switch (keycode) { - case EPRM: - eeconfig_init(); + switch (keycode) { + case RGB_SLD: + if (record->event.pressed) { + rgblight_mode(1); + } return false; - case VRSN: - SEND_STRING (QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION); + case HSV_172_255_255: + if (record->event.pressed) { + #ifdef RGBLIGHT_ENABLE + rgblight_enable(); + rgblight_mode(1); + rgblight_sethsv(172,255,255); + #endif + } return false; - #ifdef RGBLIGHT_ENABLE - case RGB_SLD: - rgblight_mode(1); + case HSV_86_255_128: + if (record->event.pressed) { + #ifdef RGBLIGHT_ENABLE + rgblight_enable(); + rgblight_mode(1); + rgblight_sethsv(86,255,128); + #endif + } + return false; + case HSV_27_255_255: + if (record->event.pressed) { + #ifdef RGBLIGHT_ENABLE + rgblight_enable(); + rgblight_mode(1); + rgblight_sethsv(27,255,255); + #endif + } return false; - #endif } - } return true; } -// Runs just one time when the keyboard initializes. -void matrix_init_user(void) { -#ifdef RGBLIGHT_COLOR_LAYER_0 - rgblight_setrgb(RGBLIGHT_COLOR_LAYER_0); -#endif -}; +uint32_t layer_state_set_user(uint32_t state) { -// Runs whenever there is a layer state change. -layer_state_t layer_state_set_user(layer_state_t state) { - ergodox_board_led_off(); - ergodox_right_led_1_off(); - ergodox_right_led_2_off(); - ergodox_right_led_3_off(); + uint8_t layer = biton32(state); - uint8_t layer = biton32(state); - switch (layer) { - case 0: - #ifdef RGBLIGHT_COLOR_LAYER_0 - rgblight_setrgb(RGBLIGHT_COLOR_LAYER_0); - #else - #ifdef RGBLIGHT_ENABLE - rgblight_init(); - #endif - #endif - break; - case 1: - ergodox_right_led_1_on(); - #ifdef RGBLIGHT_COLOR_LAYER_1 - rgblight_setrgb(RGBLIGHT_COLOR_LAYER_1); - #endif - break; - case 2: - ergodox_right_led_2_on(); - #ifdef RGBLIGHT_COLOR_LAYER_2 - rgblight_setrgb(RGBLIGHT_COLOR_LAYER_2); - #endif - break; - case 3: - ergodox_right_led_3_on(); - #ifdef RGBLIGHT_COLOR_LAYER_3 - rgblight_setrgb(RGBLIGHT_COLOR_LAYER_3); - #endif - break; - case 4: - ergodox_right_led_1_on(); - ergodox_right_led_2_on(); - #ifdef RGBLIGHT_COLOR_LAYER_4 - rgblight_setrgb(RGBLIGHT_COLOR_LAYER_4); - #endif - break; - case 5: - ergodox_right_led_1_on(); - ergodox_right_led_3_on(); - #ifdef RGBLIGHT_COLOR_LAYER_5 - rgblight_setrgb(RGBLIGHT_COLOR_LAYER_5); - #endif - break; - case 6: - ergodox_right_led_2_on(); - ergodox_right_led_3_on(); - #ifdef RGBLIGHT_COLOR_LAYER_6 - rgblight_setrgb(RGBLIGHT_COLOR_LAYER_6); - #endif - break; - case 7: - ergodox_right_led_1_on(); - ergodox_right_led_2_on(); - ergodox_right_led_3_on(); - #ifdef RGBLIGHT_COLOR_LAYER_7 - rgblight_setrgb(RGBLIGHT_COLOR_LAYER_7); - #endif - break; - default: - break; - } + ergodox_board_led_off(); + ergodox_right_led_1_off(); + ergodox_right_led_2_off(); + ergodox_right_led_3_off(); + switch (layer) { + case 1: + ergodox_right_led_1_on(); + break; + case 2: + ergodox_right_led_2_on(); + break; + case 3: + ergodox_right_led_3_on(); + break; + case 4: + ergodox_right_led_1_on(); + ergodox_right_led_2_on(); + break; + case 5: + ergodox_right_led_1_on(); + ergodox_right_led_3_on(); + break; + case 6: + ergodox_right_led_2_on(); + ergodox_right_led_3_on(); + break; + case 7: + ergodox_right_led_1_on(); + ergodox_right_led_2_on(); + ergodox_right_led_3_on(); + break; + default: + break; + } + return state; - return state; }; diff --git a/keyboards/planck/ez/ez.c b/keyboards/planck/ez/ez.c index 79310da10a..f34af7a290 100644 --- a/keyboards/planck/ez/ez.c +++ b/keyboards/planck/ez/ez.c @@ -16,6 +16,9 @@ #include "ez.h" #include "ch.h" #include "hal.h" +#ifdef WEBUSB_ENABLE +#include "webusb.h" +#endif keyboard_config_t keyboard_config; @@ -247,6 +250,16 @@ uint32_t layer_state_set_kb(uint32_t state) { planck_ez_right_led_off(); state = layer_state_set_user(state); uint8_t layer = biton32(state); +#ifdef WEBUSB_ENABLE + if(webusb_state.paired == true) { + uint8_t event[4]; + event[0] = WEBUSB_STATUS_OK; + event[1] = WEBUSB_EVT_LAYER; + event[2] = layer; + event[3] = WEBUSB_STOP_BIT; + webusb_send(event, sizeof(event)); + } +#endif switch (layer) { case 1: planck_ez_left_led_on(); @@ -265,6 +278,17 @@ uint32_t layer_state_set_kb(uint32_t state) { } bool process_record_kb(uint16_t keycode, keyrecord_t *record) { +#ifdef WEBUSB_ENABLE + if(webusb_state.paired == true) { + uint8_t event[5]; + event[0] = WEBUSB_STATUS_OK; + event[1] = record->event.pressed ? WEBUSB_EVT_KEYDOWN : WEBUSB_EVT_KEYUP; + event[2] = record->event.key.col; + event[3] = record->event.key.row; + event[4] = WEBUSB_STOP_BIT; + webusb_send(event, sizeof(event)); + } +#endif switch (keycode) { case LED_LEVEL: if (record->event.pressed) { @@ -325,3 +349,38 @@ bool music_mask_kb(uint16_t keycode) { } } #endif +#ifdef WEBUSB_ENABLE +static uint16_t loops = 0; +static bool is_on = false; + +void matrix_scan_kb(void) { + if(webusb_state.pairing == true) { + if(loops == 0) { + //lights off + } + if(loops % WEBUSB_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 > WEBUSB_BLINK_END * 2) { + webusb_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 diff --git a/keyboards/planck/keymaps/webusb/keymap.c b/keyboards/planck/keymaps/webusb/keymap.c index b25a562d8c..9a7c2f4d85 100644 --- a/keyboards/planck/keymaps/webusb/keymap.c +++ b/keyboards/planck/keymaps/webusb/keymap.c @@ -1,263 +1,67 @@ -/* Copyright 2015-2017 Jack Humbert - * - * - * 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 QMK_KEYBOARD_H +#ifdef AUDIO_ENABLE #include "muse.h" -#include "webusb.h" +#endif +#include "eeprom.h" +#include "keymap_german.h" +#include "keymap_nordic.h" +#include "keymap_french.h" +#include "keymap_spanish.h" +#include "keymap_hungarian.h" +#include "keymap_swedish.h" +#include "keymap_br_abnt2.h" +#include "keymap_canadian_multilingual.h" +#include "keymap_german_ch.h" +#include "keymap_jp.h" + +#define KC_MAC_UNDO LGUI(KC_Z) +#define KC_MAC_CUT LGUI(KC_X) +#define KC_MAC_COPY LGUI(KC_C) +#define KC_MAC_PASTE LGUI(KC_V) +#define KC_PC_UNDO LCTL(KC_Z) +#define KC_PC_CUT LCTL(KC_X) +#define KC_PC_COPY LCTL(KC_C) +#define KC_PC_PASTE LCTL(KC_V) +#define ES_LESS_MAC KC_GRAVE +#define ES_GRTR_MAC LSFT(KC_GRAVE) +#define ES_BSLS_MAC ALGR(KC_6) -extern keymap_config_t keymap_config; +enum planck_keycodes { + RGB_SLD = EZ_SAFE_RANGE, +}; enum planck_layers { - _QWERTY, - _COLEMAK, - _DVORAK, + _BASE, _LOWER, _RAISE, - _PLOVER, - _ADJUST + _ADJUST, }; -enum planck_keycodes { - QWERTY = SAFE_RANGE, - COLEMAK, - DVORAK, - PLOVER, - BACKLIT, - EXT_PLV -}; #define LOWER MO(_LOWER) #define RAISE MO(_RAISE) -// Ping pong: when receiving bytes from the host we send it back -void webusb_receive(uint8_t *data, uint8_t length) { - webusb_send(data, length); -} - +#define LOWER MO(_LOWER) +#define RAISE MO(_RAISE) const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [_BASE] = LAYOUT_planck_grid(KC_TAB,KC_Q,KC_W,KC_E,KC_R,KC_T,KC_Y,KC_U,KC_I,KC_O,KC_P,KC_BSPACE,KC_ESCAPE,KC_A,KC_S,KC_D,KC_F,KC_G,KC_H,KC_J,KC_K,KC_L,KC_SCOLON,KC_QUOTE,KC_LSHIFT,KC_Z,KC_X,KC_C,KC_V,KC_B,KC_N,KC_M,KC_COMMA,KC_DOT,KC_SLASH,KC_ENTER,KC_HYPR,KC_LCTRL,KC_LALT,KC_LGUI,LOWER,KC_SPACE,KC_NO,RAISE,KC_LEFT,KC_DOWN,KC_UP,KC_RIGHT), -/* Qwerty - * ,-----------------------------------------------------------------------------------. - * | Tab | Q | W | E | R | T | Y | U | I | O | P | Bksp | - * |------+------+------+------+------+-------------+------+------+------+------+------| - * | Esc | A | S | D | F | G | H | J | K | L | ; | " | - * |------+------+------+------+------+------|------+------+------+------+------+------| - * | Shift| Z | X | C | V | B | N | M | , | . | / |Enter | - * |------+------+------+------+------+------+------+------+------+------+------+------| - * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right | - * `-----------------------------------------------------------------------------------' - */ -[_QWERTY] = LAYOUT_planck_grid( - KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC, - KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, - KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT , - BACKLIT, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT -), - -/* Colemak - * ,-----------------------------------------------------------------------------------. - * | Tab | Q | W | F | P | G | J | L | U | Y | ; | Bksp | - * |------+------+------+------+------+-------------+------+------+------+------+------| - * | Esc | A | R | S | T | D | H | N | E | I | O | " | - * |------+------+------+------+------+------|------+------+------+------+------+------| - * | Shift| Z | X | C | V | B | K | M | , | . | / |Enter | - * |------+------+------+------+------+------+------+------+------+------+------+------| - * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right | - * `-----------------------------------------------------------------------------------' - */ -[_COLEMAK] = LAYOUT_planck_grid( - KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC, - KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT, - KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT , - BACKLIT, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT -), - -/* Dvorak - * ,-----------------------------------------------------------------------------------. - * | Tab | " | , | . | P | Y | F | G | C | R | L | Bksp | - * |------+------+------+------+------+-------------+------+------+------+------+------| - * | Esc | A | O | E | U | I | D | H | T | N | S | / | - * |------+------+------+------+------+------|------+------+------+------+------+------| - * | Shift| ; | Q | J | K | X | B | M | W | V | Z |Enter | - * |------+------+------+------+------+------+------+------+------+------+------+------| - * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right | - * `-----------------------------------------------------------------------------------' - */ -[_DVORAK] = LAYOUT_planck_grid( - KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC, - KC_ESC, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH, - KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_ENT , - BACKLIT, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT -), + [_LOWER] = LAYOUT_planck_grid(KC_TILD,KC_EXLM,KC_AT,KC_HASH,KC_DLR,KC_PERC,KC_CIRC,KC_AMPR,KC_ASTR,KC_LPRN,KC_RPRN,KC_TRANSPARENT,KC_DELETE,KC_F1,KC_F2,KC_F3,KC_F4,KC_F5,KC_F6,KC_UNDS,KC_PLUS,KC_LCBR,KC_RCBR,KC_PIPE,KC_TRANSPARENT,KC_F7,KC_F8,KC_F9,KC_F10,KC_F11,KC_F12,KC_NONUS_HASH,KC_NONUS_BSLASH,KC_HOME,KC_END,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_NO,KC_TRANSPARENT,KC_MEDIA_NEXT_TRACK,KC_AUDIO_VOL_DOWN,KC_AUDIO_VOL_UP,KC_MEDIA_PLAY_PAUSE), -/* Lower - * ,-----------------------------------------------------------------------------------. - * | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | Bksp | - * |------+------+------+------+------+-------------+------+------+------+------+------| - * | Del | F1 | F2 | F3 | F4 | F5 | F6 | _ | + | { | } | | | - * |------+------+------+------+------+------|------+------+------+------+------+------| - * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO ~ |ISO | | Home | End | | - * |------+------+------+------+------+------+------+------+------+------+------+------| - * | | | | | | | | Next | Vol- | Vol+ | Play | - * `-----------------------------------------------------------------------------------' - */ -[_LOWER] = LAYOUT_planck_grid( - KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC, - KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE, - _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, S(KC_NUHS), S(KC_NUBS), KC_HOME, KC_END, _______, - _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY -), + [_RAISE] = LAYOUT_planck_grid(KC_GRAVE,KC_1,KC_2,KC_3,KC_4,KC_5,KC_6,KC_7,KC_8,KC_9,KC_0,KC_TRANSPARENT,KC_DELETE,KC_F1,KC_F2,KC_F3,KC_F4,KC_F5,KC_F6,KC_MINUS,KC_EQUAL,KC_LBRACKET,KC_RBRACKET,KC_BSLASH,KC_TRANSPARENT,KC_F7,KC_F8,KC_F9,KC_F10,KC_F11,KC_F12,KC_NONUS_HASH,KC_NONUS_BSLASH,KC_PGUP,KC_PGDOWN,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_NO,KC_TRANSPARENT,KC_MEDIA_NEXT_TRACK,KC_AUDIO_VOL_DOWN,KC_AUDIO_VOL_UP,KC_MEDIA_PLAY_PAUSE), -/* Raise - * ,-----------------------------------------------------------------------------------. - * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp | - * |------+------+------+------+------+-------------+------+------+------+------+------| - * | Del | F1 | F2 | F3 | F4 | F5 | F6 | - | = | [ | ] | \ | - * |------+------+------+------+------+------|------+------+------+------+------+------| - * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO # |ISO / |Pg Up |Pg Dn | | - * |------+------+------+------+------+------+------+------+------+------+------+------| - * | | | | | | | | Next | Vol- | Vol+ | Play | - * `-----------------------------------------------------------------------------------' - */ -[_RAISE] = LAYOUT_planck_grid( - KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC, - KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS, - _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_NUHS, KC_NUBS, KC_PGUP, KC_PGDN, _______, - _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY -), - -/* Plover layer (http://opensteno.org) - * ,-----------------------------------------------------------------------------------. - * | # | # | # | # | # | # | # | # | # | # | # | # | - * |------+------+------+------+------+-------------+------+------+------+------+------| - * | | S | T | P | H | * | * | F | P | L | T | D | - * |------+------+------+------+------+------|------+------+------+------+------+------| - * | | S | K | W | R | * | * | R | B | G | S | Z | - * |------+------+------+------+------+------+------+------+------+------+------+------| - * | Exit | | | A | O | | E | U | | | | - * `-----------------------------------------------------------------------------------' - */ -[_PLOVER] = LAYOUT_planck_grid( - KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1 , - XXXXXXX, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, - XXXXXXX, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, - EXT_PLV, XXXXXXX, XXXXXXX, KC_C, KC_V, XXXXXXX, XXXXXXX, KC_N, KC_M, XXXXXXX, XXXXXXX, XXXXXXX -), - -/* Adjust (Lower + Raise) - * ,-----------------------------------------------------------------------------------. - * | | Reset| | | | | | | | | | Del | - * |------+------+------+------+------+-------------+------+------+------+------+------| - * | | | |Aud on|Audoff|AGnorm|AGswap|Qwerty|Colemk|Dvorak|Plover| | - * |------+------+------+------+------+------|------+------+------+------+------+------| - * | |Voice-|Voice+|Mus on|Musoff|MIDIon|MIDIof| | | | | | - * |------+------+------+------+------+------+------+------+------+------+------+------| - * | | | | | | | | | | | | - * `-----------------------------------------------------------------------------------' - */ -[_ADJUST] = LAYOUT_planck_grid( - WEBUSB_PAIR, RESET, DEBUG, RGB_TOG, RGB_MOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, KC_DEL , - _______, _______, MU_MOD, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, COLEMAK, DVORAK, PLOVER, _______, - _______, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, TERM_ON, TERM_OFF, _______, _______, _______, - _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ -) + [_ADJUST] = LAYOUT_planck_grid(WEBUSB_PAIR,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_DELETE,KC_TRANSPARENT,AU_ON,AU_OFF,AU_TOG,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,RESET,KC_TRANSPARENT,KC_TRANSPARENT,MU_ON,MU_OFF,MU_TOG,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_NO,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT), }; -#ifdef AUDIO_ENABLE - float plover_song[][2] = SONG(PLOVER_SOUND); - float plover_gb_song[][2] = SONG(PLOVER_GOODBYE_SOUND); -#endif - -layer_state_t layer_state_set_user(layer_state_t state) { - return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST); -} - bool process_record_user(uint16_t keycode, keyrecord_t *record) { switch (keycode) { - case QWERTY: - if (record->event.pressed) { - print("mode just switched to qwerty and this is a huge string\n"); - set_single_persistent_default_layer(_QWERTY); - } - return false; - break; - case COLEMAK: - if (record->event.pressed) { - set_single_persistent_default_layer(_COLEMAK); - } - return false; - break; - case DVORAK: - if (record->event.pressed) { - set_single_persistent_default_layer(_DVORAK); - } - return false; - break; - case BACKLIT: - if (record->event.pressed) { - register_code(KC_RSFT); - #ifdef BACKLIGHT_ENABLE - backlight_step(); - #endif - #ifdef KEYBOARD_planck_rev5 - PORTE &= ~(1<<6); - #endif - } else { - unregister_code(KC_RSFT); - #ifdef KEYBOARD_planck_rev5 - PORTE |= (1<<6); - #endif - } - return false; - break; - case PLOVER: - if (record->event.pressed) { - #ifdef AUDIO_ENABLE - stop_all_notes(); - PLAY_SONG(plover_song); - #endif - layer_off(_RAISE); - layer_off(_LOWER); - layer_off(_ADJUST); - layer_on(_PLOVER); - if (!eeconfig_is_enabled()) { - eeconfig_init(); - } - keymap_config.raw = eeconfig_read_keymap(); - keymap_config.nkro = 1; - eeconfig_update_keymap(keymap_config.raw); - } - return false; - break; - case EXT_PLV: - if (record->event.pressed) { - #ifdef AUDIO_ENABLE - PLAY_SONG(plover_gb_song); - #endif - layer_off(_PLOVER); - } - return false; - break; } return true; } +#ifdef AUDIO_ENABLE bool muse_mode = false; uint8_t last_muse_note = 0; uint16_t muse_counter = 0; @@ -281,66 +85,39 @@ void encoder_update(bool clockwise) { } } else { if (clockwise) { - #ifdef MOUSEKEY_ENABLE - register_code(KC_MS_WH_DOWN); - unregister_code(KC_MS_WH_DOWN); - #else - register_code(KC_PGDN); - unregister_code(KC_PGDN); - #endif +#ifdef MOUSEKEY_ENABLE + register_code(KC_MS_WH_DOWN); + unregister_code(KC_MS_WH_DOWN); +#else + register_code(KC_PGDN); + unregister_code(KC_PGDN); +#endif } else { - #ifdef MOUSEKEY_ENABLE - register_code(KC_MS_WH_UP); - unregister_code(KC_MS_WH_UP); - #else - register_code(KC_PGUP); - unregister_code(KC_PGUP); - #endif +#ifdef MOUSEKEY_ENABLE + register_code(KC_MS_WH_UP); + unregister_code(KC_MS_WH_UP); +#else + register_code(KC_PGUP); + unregister_code(KC_PGUP); +#endif } } } -void dip_switch_update_user(uint8_t index, bool active) { - switch (index) { - case 0: - if (active) { - #ifdef AUDIO_ENABLE - PLAY_SONG(plover_song); - #endif - layer_on(_ADJUST); - } else { - #ifdef AUDIO_ENABLE - PLAY_SONG(plover_gb_song); - #endif - layer_off(_ADJUST); - } - break; - case 1: - if (active) { - muse_mode = true; - } else { - muse_mode = false; - #ifdef AUDIO_ENABLE - stop_all_notes(); - #endif - } - } -} - void matrix_scan_user(void) { - #ifdef AUDIO_ENABLE - if (muse_mode) { - if (muse_counter == 0) { - uint8_t muse_note = muse_offset + SCALE[muse_clock_pulse()]; - if (muse_note != last_muse_note) { - stop_note(compute_freq_for_midi_note(last_muse_note)); - play_note(compute_freq_for_midi_note(muse_note), 0xF); - last_muse_note = muse_note; - } +#ifdef AUDIO_ENABLE + if (muse_mode) { + if (muse_counter == 0) { + uint8_t muse_note = muse_offset + SCALE[muse_clock_pulse()]; + if (muse_note != last_muse_note) { + stop_note(compute_freq_for_midi_note(last_muse_note)); + play_note(compute_freq_for_midi_note(muse_note), 0xF); + last_muse_note = muse_note; } - muse_counter = (muse_counter + 1) % muse_tempo; } - #endif + muse_counter = (muse_counter + 1) % muse_tempo; + } +#endif } bool music_mask_user(uint16_t keycode) { @@ -352,3 +129,8 @@ bool music_mask_user(uint16_t keycode) { return true; } } +#endif + +uint32_t layer_state_set_user(uint32_t state) { + return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST); +} diff --git a/quantum/quantum.c b/quantum/quantum.c index 27d08996be..82c7a5265b 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -720,7 +720,7 @@ bool process_record_quantum(keyrecord_t *record) { #ifdef WEBUSB_ENABLE case WEBUSB_PAIR: if (record->event.pressed) { - webusb_state.paired = true; + webusb_state.pairing = true; } return false; #endif diff --git a/tmk_core/common/webusb.c b/tmk_core/common/webusb.c index 5183d77543..82e8fe1c83 100644 --- a/tmk_core/common/webusb.c +++ b/tmk_core/common/webusb.c @@ -6,16 +6,28 @@ webusb_state_t webusb_state = { .pairing = false, }; -void webusb_set_pairing_state() { - webusb_state.pairing = true; - uint8_t tick = 0; - do { - tick++; - wait_ms(1000); - //TODO Blink some leds - } while(webusb_state.paired == false && tick <= 30); - webusb_state.pairing = false; -} +void webusb_receive(uint8_t *data, uint8_t length) { + uint8_t command = data[0]; + + if(command == WEBUSB_CMD_PAIR && webusb_state.pairing == true) { + uint8_t event[3]; + webusb_state.pairing = false; + webusb_state.paired = true; + event[0] = WEBUSB_STATUS_OK; + event[1] = WEBUSB_EVT_PAIRED; + event[2] = WEBUSB_STOP_BIT; + webusb_send(event, sizeof(event)); + return; + } + + if(webusb_state.paired == true) { + switch(command) { + //Handle commands in here + } + } else { + webusb_error(WEBUSB_STATUS_NOT_PAIRED); + } +}; void webusb_error(uint8_t code) { uint8_t buffer[1]; diff --git a/tmk_core/common/webusb.h b/tmk_core/common/webusb.h index 35d9610fc9..c49a9f48a8 100644 --- a/tmk_core/common/webusb.h +++ b/tmk_core/common/webusb.h @@ -3,6 +3,10 @@ #include <stdint.h> #include <stdbool.h> +#define WEBUSB_STOP_BIT -2 +#define WEBUSB_BLINK_STEPS 512 +#define WEBUSB_BLINK_END WEBUSB_BLINK_STEPS * 60 + void webusb_receive(uint8_t *data, uint8_t length); void webusb_send(uint8_t *data, uint8_t length); void webusb_error(uint8_t); @@ -21,4 +25,13 @@ enum Webusb_Status_Code { WEBUSB_STATUS_UNKNOWN_COMMAND, }; +enum Webusb_Command_Code { + WEBUSB_CMD_PAIR +}; +enum Webusb_Event_Code { + WEBUSB_EVT_PAIRED, + WEBUSB_EVT_KEYDOWN, + WEBUSB_EVT_KEYUP, + WEBUSB_EVT_LAYER +}; diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c index 8a249e19e3..57b9d74d38 100644 --- a/tmk_core/protocol/chibios/usb_main.c +++ b/tmk_core/protocol/chibios/usb_main.c @@ -871,7 +871,7 @@ void raw_hid_task(void) { #ifdef WEBUSB_ENABLE void webusb_send(uint8_t *data, uint8_t length) { chnWrite(&drivers.webusb_driver.driver, data, length); } -__attribute__((weak)) void webusb_receive(uint8_t *data, uint8_t length) { +__attribute__((weak)) void webusb_receive_kb(uint8_t *data, uint8_t length) { // Users should #include "raw_hid.h" in their own code // and implement this function there. Leave this as weak linkage // so users can opt to not handle data coming in. @@ -883,12 +883,7 @@ void webusb_task(void) { do { size_t size = chnReadTimeout(&drivers.webusb_driver.driver, buffer, sizeof(buffer), TIME_IMMEDIATE); if (size > 0) { - if(webusb_state.paired == true) { - webusb_receive(buffer, size); - } - else { - webusb_error(WEBUSB_STATUS_NOT_PAIRED); - } + webusb_receive(buffer, size); } } while (size > 0); } diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index c68c3c2e5b..660633fd12 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -280,19 +280,18 @@ void webusb_send(uint8_t *data, uint8_t length) { Endpoint_SelectEndpoint(WEBUSB_IN_EPNUM); - if (Endpoint_IsINReady()) { - Endpoint_Write_Stream_LE(data, length, NULL); - Endpoint_ClearIN(); - } + Endpoint_Write_Stream_LE(data, length, NULL); + Endpoint_ClearIN(); } -__attribute__((weak)) void webusb_receive(uint8_t *data, uint8_t length) { } +__attribute__((weak)) void webusb_receive_kb(uint8_t *data, uint8_t length) { } static void webusb_task(void) { // Create a temporary buffer to hold the read in data from the host uint8_t data[WEBUSB_EPSIZE]; bool data_read = false; + // Device must be connected and configured for the task to run if (USB_DeviceState != DEVICE_STATE_Configured) return; @@ -311,12 +310,7 @@ static void webusb_task(void) { Endpoint_ClearOUT(); if (data_read) { - if(webusb_state.paired == true) { - webusb_receive(data, sizeof(data)); - } - else { - webusb_error(WEBUSB_STATUS_NOT_PAIRED); - } + webusb_receive(data, sizeof(data)); } } } |