From be666b2d8a7b30f29a4d29b9d65af012816a43d7 Mon Sep 17 00:00:00 2001 From: Konstantin Đorđević Date: Sat, 5 Jan 2019 17:31:24 +0100 Subject: Add underscores to names of brightness control constants in report.h (#4764) --- tmk_core/common/report.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tmk_core/common') diff --git a/tmk_core/common/report.h b/tmk_core/common/report.h index eb9afb727e..e7c31bd376 100644 --- a/tmk_core/common/report.h +++ b/tmk_core/common/report.h @@ -48,8 +48,8 @@ along with this program. If not, see . #define TRANSPORT_STOP 0x00B7 #define TRANSPORT_STOP_EJECT 0x00CC #define TRANSPORT_PLAY_PAUSE 0x00CD -#define BRIGHTNESSUP 0x006F -#define BRIGHTNESSDOWN 0x0070 +#define BRIGHTNESS_UP 0x006F +#define BRIGHTNESS_DOWN 0x0070 /* application launch */ #define AL_CC_CONFIG 0x0183 #define AL_EMAIL 0x018A @@ -192,8 +192,8 @@ typedef struct { (key == KC_WWW_FORWARD ? AC_FORWARD : \ (key == KC_WWW_STOP ? AC_STOP : \ (key == KC_WWW_REFRESH ? AC_REFRESH : \ - (key == KC_BRIGHTNESS_UP ? BRIGHTNESSUP : \ - (key == KC_BRIGHTNESS_DOWN ? BRIGHTNESSDOWN : \ + (key == KC_BRIGHTNESS_UP ? BRIGHTNESS_UP : \ + (key == KC_BRIGHTNESS_DOWN ? BRIGHTNESS_DOWN : \ (key == KC_WWW_FAVORITES ? AC_BOOKMARKS : 0))))))))))))))))))))))) uint8_t has_anykey(report_keyboard_t* keyboard_report); -- cgit v1.2.3 From 2bfac351edebc6e141d3291448512b0e228e5c47 Mon Sep 17 00:00:00 2001 From: yiancar Date: Mon, 7 Jan 2019 01:22:19 +0000 Subject: Final HS60v2 changes. (#4790) * initial commit, this now mostly works - RGB controls work - Dynamic keymap still broken due to eeprom - Via works * STM32 eeprom update - Update EEPROM emulation library to handle 8bit data like AVR. - This library also allows for multiple page pairs resulting in greater EEPROM size flexibility * hs60 changes * HS60 hhkb added * Update keyboards/hs60/v2/config.h Co-Authored-By: yiancar --- drivers/issi/is31fl3733.c | 2 +- keyboards/hs60/v2/config.h | 89 ++-- keyboards/hs60/v2/keymaps/ansi/config.h | 2 + keyboards/hs60/v2/keymaps/ansi/keymap.c | 22 +- keyboards/hs60/v2/keymaps/ansi/readme.md | 6 +- keyboards/hs60/v2/keymaps/default/keymap.c | 20 +- keyboards/hs60/v2/keymaps/default/readme.md | 6 +- keyboards/hs60/v2/keymaps/hhkb/config.h | 13 + keyboards/hs60/v2/keymaps/hhkb/keymap.c | 34 +- keyboards/hs60/v2/keymaps/hhkb/readme.md | 6 + keyboards/hs60/v2/mcuconf.h | 2 +- keyboards/hs60/v2/rules.mk | 18 +- keyboards/hs60/v2/v2.c | 621 +----------------------- keyboards/hs60/v2/v2.h | 7 +- keyboards/zeal60/rgb_backlight.c | 285 ++++++++++- tmk_core/common/chibios/eeprom_stm32.c | 710 +++++----------------------- tmk_core/common/chibios/eeprom_stm32.h | 68 ++- tmk_core/common/chibios/flash_stm32.c | 15 + tmk_core/common/chibios/flash_stm32.h | 1 + tmk_core/common/eeconfig.c | 4 +- tmk_core/common/eeconfig.h | 21 +- tmk_core/common/eeprom.h | 1 - tmk_core/protocol/chibios/main.c | 2 +- 23 files changed, 611 insertions(+), 1344 deletions(-) create mode 100644 keyboards/hs60/v2/keymaps/hhkb/readme.md (limited to 'tmk_core/common') diff --git a/drivers/issi/is31fl3733.c b/drivers/issi/is31fl3733.c index c198ec5174..c18ed7ca30 100644 --- a/drivers/issi/is31fl3733.c +++ b/drivers/issi/is31fl3733.c @@ -24,10 +24,10 @@ #include "wait.h" #endif +#include "is31fl3733.h" #include #include "i2c_master.h" #include "progmem.h" -#include "rgb_matrix.h" // This is a 7-bit address, that gets left-shifted and bit 0 // set to 0 for write, 1 for read (as per I2C protocol) diff --git a/keyboards/hs60/v2/config.h b/keyboards/hs60/v2/config.h index 192f7d6f25..bc1681ffd1 100644 --- a/keyboards/hs60/v2/config.h +++ b/keyboards/hs60/v2/config.h @@ -20,9 +20,9 @@ along with this program. If not, see . #include "config_common.h" /* USB Device descriptor parameter */ -#define VENDOR_ID 0xFEED -#define PRODUCT_ID 0x0258 -#define DEVICE_VER 0x0001 +#define VENDOR_ID 0x8968 +#define PRODUCT_ID 0x4853 +#define DEVICE_VER 0x0002 #define MANUFACTURER Yiancar-Designs #define PRODUCT HS60 V2 #define DESCRIPTION GH60 compatible, tool free RGB keyboard @@ -39,7 +39,7 @@ along with this program. If not, see . #define DIODE_DIRECTION COL2ROW /* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */ -#define DEBOUNCE 0 +#define DEBOUNCING_DELAY 5 /* define if matrix has ghost (lacks anti-ghosting diodes) */ //#define MATRIX_HAS_GHOST @@ -70,48 +70,63 @@ along with this program. If not, see . */ //#define FORCE_NKRO -/* - * Magic Key Options - * - * Magic keys are hotkey commands that allow control over firmware functions of - * the keyboard. They are best used in combination with the HID Listen program, - * found here: https://www.pjrc.com/teensy/hid_listen.html - * - * The options below allow the magic key functionality to be changed. This is - * useful if your keyboard/keypad is missing keys and you want magic key support. - * - */ - /* key combination for magic key command */ #define IS_COMMAND() ( \ keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \ ) -/* - * Feature disable options - * These options are also useful to firmware size reduction. - */ +/* Backlight options */ -/* disable debug print */ -//#define NO_DEBUG +#define RGB_BACKLIGHT_ENABLED 1 -/* disable print */ -//#define NO_PRINT +#define RGB_BACKLIGHT_HS60 -/* Backlight options */ +// they aren't really used if RGB_BACKLIGHT_HS60 defined +#define RGB_BACKLIGHT_USE_SPLIT_BACKSPACE 0 +#define RGB_BACKLIGHT_USE_SPLIT_LEFT_SHIFT 0 +#define RGB_BACKLIGHT_USE_SPLIT_RIGHT_SHIFT 0 +#define RGB_BACKLIGHT_USE_7U_SPACEBAR 0 +#define RGB_BACKLIGHT_USE_ISO_ENTER 0 +#define RGB_BACKLIGHT_DISABLE_HHKB_BLOCKER_LEDS 0 -#define RGB_DISABLE_AFTER_TIMEOUT 0 // number of ticks to wait until disabling effects -#define RGB_DISABLE_WHEN_USB_SUSPENDED false // turn off effects when suspended -#define RGB_MATRIX_SKIP_FRAMES 3 +// disable backlight when USB suspended (PC sleep/hibernate/shutdown) +#define RGB_BACKLIGHT_DISABLE_WHEN_USB_SUSPENDED 0 -#define DRIVER_ADDR_1 0b1010000 -#define DRIVER_ADDR_2 0b1010000 // this is here for compliancy reasons. +// disable backlight after timeout in minutes, 0 = no timeout +#define RGB_BACKLIGHT_DISABLE_AFTER_TIMEOUT 0 -#define DRIVER_COUNT 2 -#ifdef HS60_ANSI -#define DRIVER_1_LED_TOTAL 61 -#else -#define DRIVER_1_LED_TOTAL 62 -#endif +// the default effect (RGB test) +#define RGB_BACKLIGHT_EFFECT 255 -#define DRIVER_LED_TOTAL DRIVER_1_LED_TOTAL +#define DRIVER_COUNT 2 +#define DRIVER_LED_TOTAL 64 + +// These define which keys in the matrix are alphas/mods +// Used for backlight effects so colors are different for +// alphas vs. mods +// Each value is for a row, bit 0 is column 0 +// Alpha=0 Mod=1 +#define RGB_BACKLIGHT_ALPHAS_MODS_ROW_0 0b0010000000000001 +#define RGB_BACKLIGHT_ALPHAS_MODS_ROW_1 0b0000000000000001 +#define RGB_BACKLIGHT_ALPHAS_MODS_ROW_2 0b0010000000000001 +#define RGB_BACKLIGHT_ALPHAS_MODS_ROW_3 0b0010000000000001 +#define RGB_BACKLIGHT_ALPHAS_MODS_ROW_4 0b0011110000000111 + +// TODO: refactor with new user EEPROM code (coming soon) +#define EEPROM_MAGIC 0x451F +#define EEPROM_MAGIC_ADDR 32 +// Bump this every time we change what we store +// This will automatically reset the EEPROM with defaults +// and avoid loading invalid data from the EEPROM +#define EEPROM_VERSION 0x08 +#define EEPROM_VERSION_ADDR 34 + +// Backlight config starts after EEPROM version +#define RGB_BACKLIGHT_CONFIG_EEPROM_ADDR 35 +// Dynamic keymap starts after backlight config (35+31) +#define DYNAMIC_KEYMAP_EEPROM_ADDR 66 +#define DYNAMIC_KEYMAP_LAYER_COUNT 4 +// Dynamic macro starts after dynamic keymaps (66+(4*5*14*2)) = (66+560) +#define DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR 626 +#define DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE 398 +#define DYNAMIC_KEYMAP_MACRO_COUNT 16 diff --git a/keyboards/hs60/v2/keymaps/ansi/config.h b/keyboards/hs60/v2/keymaps/ansi/config.h index f51cc16d85..96adaf5688 100644 --- a/keyboards/hs60/v2/keymaps/ansi/config.h +++ b/keyboards/hs60/v2/keymaps/ansi/config.h @@ -19,3 +19,5 @@ along with this program. If not, see . /* Include overwrites for specific keymap */ #define HS60_ANSI +#undef PRODUCT_ID +#define PRODUCT_ID 0x4854 diff --git a/keyboards/hs60/v2/keymaps/ansi/keymap.c b/keyboards/hs60/v2/keymaps/ansi/keymap.c index 923af9e2ce..ba649470b4 100644 --- a/keyboards/hs60/v2/keymaps/ansi/keymap.c +++ b/keyboards/hs60/v2/keymaps/ansi/keymap.c @@ -26,11 +26,25 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, MO(1) , KC_APP, KC_RCTL), [1] = LAYOUT_60_ansi( /* FN */ - KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL ,\ - KC_TRNS, KC_TRNS, KC_UP, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, RESET , KC_TRNS,\ - KC_TRNS, KC_LEFT, KC_DOWN, KC_RGHT, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,\ - KC_TRNS, RGB_TOG, RGB_MOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, RGB_SPI, RGB_SPD, KC_TRNS,\ + KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL ,\ + KC_TRNS, KC_TRNS, KC_UP, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, RESET, KC_TRNS,\ + KC_TRNS, KC_LEFT, KC_DOWN, KC_RGHT, S1_DEC, S1_INC, S2_DEC, S2_INC, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,\ + KC_TRNS, EF_DEC, EF_INC, H1_DEC, H1_INC, H2_DEC, H2_INC, BR_DEC, BR_INC, ES_DEC, ES_INC, KC_TRNS,\ KC_VOLU, KC_VOLD, KC_MUTE, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS), + +[2] = LAYOUT_60_ansi( /* Empty for dynamic keymaps */ + 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_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_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_TRNS, KC_TRNS, KC_TRNS, KC_TRNS), + +[3] = LAYOUT_60_ansi( /* Empty for dynamic keymaps */ + 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_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_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_TRNS, KC_TRNS, KC_TRNS, KC_TRNS), }; void matrix_init_user(void) { diff --git a/keyboards/hs60/v2/keymaps/ansi/readme.md b/keyboards/hs60/v2/keymaps/ansi/readme.md index fa811319d3..650871a5e6 100644 --- a/keyboards/hs60/v2/keymaps/ansi/readme.md +++ b/keyboards/hs60/v2/keymaps/ansi/readme.md @@ -1,6 +1,6 @@ -The default keymap for ANSI HS60 -================================ +The default keymap for ANSI HS60 V2 +=================================== -![Layout image](https://imgur.com/CSyPw0J.png) +![Layout image](https://i.imgur.com/m8t5CfE.png) Default layer is normal ANSI and Fn layer is used for RGB functions, Volume control and arrow cluster \ No newline at end of file diff --git a/keyboards/hs60/v2/keymaps/default/keymap.c b/keyboards/hs60/v2/keymaps/default/keymap.c index 2a5e823618..c1e575769f 100644 --- a/keyboards/hs60/v2/keymaps/default/keymap.c +++ b/keyboards/hs60/v2/keymaps/default/keymap.c @@ -26,11 +26,25 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, MO(1) , KC_APP, KC_RCTL), [1] = LAYOUT_60_iso( /* FN */ - KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL ,\ + KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL ,\ KC_TRNS, KC_TRNS, KC_UP, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, RESET , \ - KC_TRNS, KC_LEFT, KC_DOWN, KC_RGHT, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,\ - KC_TRNS, RGB_TOG, RGB_MOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, RGB_SPI, RGB_SPD, KC_TRNS, KC_TRNS,\ + KC_TRNS, KC_LEFT, KC_DOWN, KC_RGHT, S1_DEC, S1_INC, S2_DEC, S2_INC, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,\ + KC_TRNS, KC_TRNS, EF_DEC, EF_INC, H1_DEC, H1_INC, H2_DEC, H2_INC, BR_DEC, BR_INC, ES_DEC, ES_INC, KC_TRNS,\ KC_VOLU, KC_VOLD, KC_MUTE, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS), + +[2] = LAYOUT_60_iso( /* Empty for dynamic keymaps */ + 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_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_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_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS), + +[3] = LAYOUT_60_iso( /* Empty for dynamic keymaps */ + 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_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_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_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS), }; void matrix_init_user(void) { diff --git a/keyboards/hs60/v2/keymaps/default/readme.md b/keyboards/hs60/v2/keymaps/default/readme.md index 9125cb349e..f0b29900e6 100644 --- a/keyboards/hs60/v2/keymaps/default/readme.md +++ b/keyboards/hs60/v2/keymaps/default/readme.md @@ -1,6 +1,6 @@ -The default keymap for ISO HS60 -=============================== +The default keymap for ISO HS60 V2 +================================== -![Layout image](https://imgur.com/HXj4tYL.png) +![Layout image](https://imgur.com/6go4vQV.png) Default layer is normal ISO and Fn layer is used for RGB functions, Volume control and arrow cluster \ No newline at end of file diff --git a/keyboards/hs60/v2/keymaps/hhkb/config.h b/keyboards/hs60/v2/keymaps/hhkb/config.h index 3db403ecc5..fc1b6d8f47 100644 --- a/keyboards/hs60/v2/keymaps/hhkb/config.h +++ b/keyboards/hs60/v2/keymaps/hhkb/config.h @@ -19,3 +19,16 @@ along with this program. If not, see . /* Include overwrites for specific keymap */ #define HS60_HHKB +#undef PRODUCT_ID +#define PRODUCT_ID 0x4855 + +#undef RGB_BACKLIGHT_ALPHAS_MODS_ROW_0 +#undef RGB_BACKLIGHT_ALPHAS_MODS_ROW_1 +#undef RGB_BACKLIGHT_ALPHAS_MODS_ROW_2 +#undef RGB_BACKLIGHT_ALPHAS_MODS_ROW_3 +#undef RGB_BACKLIGHT_ALPHAS_MODS_ROW_4 +#define RGB_BACKLIGHT_ALPHAS_MODS_ROW_0 0b0000000000000001 +#define RGB_BACKLIGHT_ALPHAS_MODS_ROW_1 0b0000000000000001 +#define RGB_BACKLIGHT_ALPHAS_MODS_ROW_2 0b0011000000000001 +#define RGB_BACKLIGHT_ALPHAS_MODS_ROW_3 0b0011000000000001 +#define RGB_BACKLIGHT_ALPHAS_MODS_ROW_4 0b0011100000000111 diff --git a/keyboards/hs60/v2/keymaps/hhkb/keymap.c b/keyboards/hs60/v2/keymaps/hhkb/keymap.c index d52fc4bac9..9641eedb49 100644 --- a/keyboards/hs60/v2/keymaps/hhkb/keymap.c +++ b/keyboards/hs60/v2/keymaps/hhkb/keymap.c @@ -19,18 +19,32 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [0] = LAYOUT_60_hhkb( /* Base */ - KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_GRV, KC_BSLS, \ - KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSPC, \ - KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, \ - KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, MO(1), \ - KC_LCTL, KC_LGUI,KC_LALT, KC_SPC, KC_RALT, KC_RGUI, KC_RCTL ), + KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_GRV, KC_BSLS,\ + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSPC,\ + KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, \ + KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, MO(1),\ + KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, KC_RGUI, KC_RCTL ), [1] = LAYOUT_60_hhkb( /* FN */ - RESET, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_TRNS, KC_TRNS,\ - KC_TRNS, RGB_TOG, RGB_MOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, RGB_SPI, RGB_SPD, KC_UP, KC_TRNS, KC_DEL, \ - KC_TRNS, KC_VOLD, KC_VOLU, KC_MUTE, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_HOME, KC_PGUP, KC_LEFT, KC_RGHT, KC_TRNS, \ - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_END, KC_PGDN, KC_DOWN, KC_TRNS, KC_TRNS, \ - KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS ) + RESET, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_TRNS, KC_TRNS,\ + KC_TRNS, EF_DEC, EF_INC, H1_DEC, H1_INC, H2_DEC, H2_INC, BR_DEC, BR_INC, ES_DEC, ES_INC, KC_UP, KC_TRNS, KC_DEL, \ + KC_TRNS, KC_VOLD, KC_VOLU, KC_MUTE, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_HOME, KC_PGUP, KC_LEFT, KC_RGHT, KC_TRNS, \ + KC_TRNS, KC_TRNS, S1_DEC, S1_INC, S2_DEC, S2_INC, KC_TRNS, KC_TRNS, KC_END, KC_PGDN, KC_DOWN, KC_TRNS, KC_TRNS,\ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS ), + +[2] = LAYOUT_60_hhkb( /* Empty for dynamic keymaps */ + 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_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_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_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS ), + +[3] = LAYOUT_60_hhkb( /* Empty for dynamic keymaps */ + 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_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_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_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS ), }; void matrix_init_user(void) { diff --git a/keyboards/hs60/v2/keymaps/hhkb/readme.md b/keyboards/hs60/v2/keymaps/hhkb/readme.md new file mode 100644 index 0000000000..69b812c607 --- /dev/null +++ b/keyboards/hs60/v2/keymaps/hhkb/readme.md @@ -0,0 +1,6 @@ +The default keymap for HHKB HS60 V2 +=================================== + +![Layout image](https://imgur.com/usbrQWL.png) + +Default layer is normal HHKB with 7U space. Fn layer is used for RGB functions, Volume control and arrow cluster \ No newline at end of file diff --git a/keyboards/hs60/v2/mcuconf.h b/keyboards/hs60/v2/mcuconf.h index 226da48d59..ce608f904e 100644 --- a/keyboards/hs60/v2/mcuconf.h +++ b/keyboards/hs60/v2/mcuconf.h @@ -139,7 +139,7 @@ #define STM32_GPT_USE_TIM1 FALSE #define STM32_GPT_USE_TIM2 FALSE #define STM32_GPT_USE_TIM3 FALSE -#define STM32_GPT_USE_TIM4 FALSE +#define STM32_GPT_USE_TIM4 TRUE #define STM32_GPT_USE_TIM6 TRUE #define STM32_GPT_USE_TIM7 TRUE #define STM32_GPT_USE_TIM8 TRUE diff --git a/keyboards/hs60/v2/rules.mk b/keyboards/hs60/v2/rules.mk index 51e3cf0a3e..a2850a8305 100644 --- a/keyboards/hs60/v2/rules.mk +++ b/keyboards/hs60/v2/rules.mk @@ -1,4 +1,9 @@ # project specific files +SRC = keyboards/zeal60/zeal60.c \ + keyboards/zeal60/rgb_backlight.c \ + drivers/issi/is31fl3733.c \ + quantum/color.c \ + drivers/arm/i2c_master.c ## chip/board settings # the next two should match the directories in @@ -44,15 +49,18 @@ DFU_ARGS = -d 0483:df11 -a 0 -s 0x08000000:leave # Build Options # comment out to disable the options. # -BACKLIGHT_ENABLE = no -BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration +BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality +BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration MOUSEKEY_ENABLE = yes # Mouse keys EXTRAKEY_ENABLE = yes # Audio control and System control CONSOLE_ENABLE = no # Console for debug COMMAND_ENABLE = no # Commands for debug and configuration -#SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend +SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend NKRO_ENABLE = yes # USB Nkey Rollover -AUDIO_ENABLE = no -RGB_MATRIX_ENABLE = IS31FL3733 # Use RGB matrix +AUDIO_ENABLE = no # Audio output on port C6 NO_USB_STARTUP_CHECK = no # Disable initialization only when usb is plugged in #SERIAL_LINK_ENABLE = yes + +RAW_ENABLE = yes +DYNAMIC_KEYMAP_ENABLE = yes +CIE1931_CURVE = yes diff --git a/keyboards/hs60/v2/v2.c b/keyboards/hs60/v2/v2.c index 4289c1fed5..2e12538e9b 100644 --- a/keyboards/hs60/v2/v2.c +++ b/keyboards/hs60/v2/v2.c @@ -13,623 +13,6 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#include "v2.h" - -//#include "is31fl3733.h" - -// Please ignore this is for upcoming features -/*#ifdef RAW_ENABLE - -void raw_hid_receive( uint8_t *data, uint8_t length ) -{ - uint8_t command = data[0]; - switch ( command ) - { - case id_protocol_version: - { - msg_protocol_version *msg = (msg_protocol_version*)&data[1]; - msg->version = PROTOCOL_VERSION; - break; - } -#if USE_KEYMAPS_IN_EEPROM - case id_keymap_keycode_load: - { - msg_keymap_keycode_load *msg = (msg_keymap_keycode_load*)&data[1]; - msg->keycode = keymap_keycode_load( msg->layer, msg->row, msg->column ); - break; - } - case id_keymap_keycode_save: - { - msg_keymap_keycode_save *msg = (msg_keymap_keycode_save*)&data[1]; - keymap_keycode_save( msg->layer, msg->row, msg->column, msg->keycode); - break; - } - case id_keymap_default_save: - { - keymap_default_save(); - break; - } -#endif // USE_KEYMAPS_IN_EEPROM - case id_backlight_config_set_values: - { - msg_backlight_config_set_values *msg = (msg_backlight_config_set_values*)&data[1]; - backlight_config_set_values(msg); - backlight_config_save(); - break; - } - case id_backlight_config_set_alphas_mods: - { - msg_backlight_config_set_alphas_mods *msg = (msg_backlight_config_set_alphas_mods*)&data[1]; - backlight_config_set_alphas_mods( msg->alphas_mods ); - backlight_config_save(); - break; - } - case id_backlight_set_key_color: - { - msg_backlight_set_key_color *msg = (msg_backlight_set_key_color*)&data[1]; - backlight_set_key_color(msg->row, msg->column, msg->hsv); - break; - } - case id_system_get_state: - { - msg_system_state *msg = (msg_system_state*)&data[1]; - msg->value = backlight_get_tick(); - break; - } - default: - { - // Unhandled message. - data[0] = id_unhandled; - break; - } - } - - // Return same buffer with values changed - raw_hid_send( data, length ); - -} - -#endif*/ - -#ifdef HS60_ANSI - -const is31_led g_is31_leds[DRIVER_LED_TOTAL] = { -/* Refer to IS31 manual for these locations - * driver - * | R location - * | | G location - * | | | B location - * | | | | */ - {0, B_1, A_1, C_1}, //MX1 - {0, E_1, D_1, F_1}, //MX2 - {0, H_1, G_1, I_1}, //MX3 - {0, K_1, J_1, L_1}, //MX4 - {0, B_2, A_2, C_2}, //MX6 - {0, E_2, D_2, F_2}, //MX7 - {0, H_2, G_2, I_2}, //MX8 - {0, K_2, J_2, L_2}, //MX14 - {0, B_3, A_3, C_3}, //MX11 - {0, E_3, D_3, F_3}, //MX12 - {0, H_3, G_3, I_3}, //MX13 - {0, K_3, J_3, L_3}, //MX19 - {0, B_4, A_4, C_4}, //MX16 - {0, E_4, D_4, F_4}, //MX17 - {0, H_4, G_4, I_4}, //MX18 - {0, K_4, J_4, L_4}, //MX23 - {0, B_5, A_5, C_5}, //MX20 - {0, E_5, D_5, F_5}, //MX21 - {0, H_5, G_5, I_5}, //MX22 - {0, K_5, J_5, L_5}, //MX27 - {0, B_6, A_6, C_6}, //MX24 - {0, E_6, D_6, F_6}, //MX25 - {0, H_6, G_6, I_6}, //MX26 - {0, K_6, J_6, L_6}, //MX31 - {0, B_7, A_7, C_7}, //MX28 - {0, E_7, D_7, F_7}, //MX29 - {0, H_7, G_7, I_7}, //MX30 - {0, K_7, J_7, L_7}, //MX36 - {0, B_8, A_8, C_8}, //MX33 - {0, E_8, D_8, F_8}, //MX34 - {0, H_8, G_8, I_8}, //MX35 - {0, K_8, J_8, L_8}, //MX40 - {0, B_9, A_9, C_9}, //MX37 - {0, E_9, D_9, F_9}, //MX38 - {0, H_9, G_9, I_9}, //MX39 - {0, K_9, J_9, L_9}, //MX44 - {0, B_10, A_10, C_10}, //MX41 - {0, E_10, D_10, F_10}, //MX42 - {0, H_10, G_10, I_10}, //MX43 - {0, K_10, J_10, L_10}, //MX48 - {0, B_11, A_11, C_11}, //MX45 - {0, E_11, D_11, F_11}, //MX46 - {0, H_11, G_11, I_11}, //MX47 - {0, K_11, J_11, L_11}, //MX53 - {0, B_12, A_12, C_12}, //MX50 - {0, E_12, D_12, F_12}, //MX51 - {0, H_12, G_12, I_12}, //MX52 - - {0, B_13, A_13, C_13}, //MX55 - {0, E_13, D_13, F_13}, //MX56 - - {0, K_13, J_13, L_13}, //MX61 - {0, B_14, A_14, C_14}, //MX59 - {0, E_14, D_14, F_14}, //MX57 - {0, H_14, G_14, I_14}, //MX60 - {0, K_14, J_14, L_14}, //MX62 - {0, B_15, A_15, C_15}, //MX5 - {0, E_15, D_15, F_15}, //MX10 - {0, H_15, G_15, I_15}, //MX15 - {0, K_15, J_15, L_15}, //MX32 - - {0, E_16, D_16, F_16}, //MX49 - {0, H_16, G_16, I_16}, //MX54 - {0, K_16, J_16, L_16}, //MX58 -}; - -const rgb_led g_rgb_leds[DRIVER_LED_TOTAL] = { -// -// MX1, MX6, MX11, MX16, MX20, MX24, MX28, MX33, MX37, MX41, MX45, MX50, MX55, MX59, -// MX2, MX7, MX12, MX17, MX21, MX25, MX29, MX34, MX38, MX42, MX46, MX51, MX56, ---, -// MX3, MX8, MX13, MX18, MX22, MX26, MX30, MX35, MX39, MX43, MX47, MX52, MX57, MX60, -// MX4, ---, MX14, MX19, MX23, MX27, MX31, MX36, MX40, MX44, MX48, MX53, ---, MX61, -// MX5, MX10, MX15, ---, ---, ---, MX32, ---, ---, ---, MX49, MX54, MX58, MX62 -/* {row | col << 4} - * | {x=0..224, y=0..64} - * | | modifier - * | | | */ - {{0|(0<<4)}, { 0, 0}, 1}, //MX1 - {{1|(0<<4)}, { 0, 16}, 1}, //MX2 - {{2|(0<<4)}, { 0, 32}, 1}, //MX3 - {{3|(0<<4)}, { 0, 48}, 1}, //MX4 - {{0|(1<<4)}, { 17, 0}, 0}, //MX6 - {{1|(1<<4)}, { 17, 16}, 0}, //MX7 - {{2|(1<<4)}, { 17, 32}, 0}, //MX8 - {{3|(2<<4)}, { 34, 48}, 0}, //MX14 - {{0|(2<<4)}, { 34, 0}, 0}, //MX11 - {{1|(2<<4)}, { 34, 16}, 0}, //MX12 - {{2|(2<<4)}, { 34, 32}, 0}, //MX13 - {{3|(3<<4)}, { 51, 48}, 0}, //MX19 - {{0|(3<<4)}, { 51, 0}, 0}, //MX16 - {{1|(3<<4)}, { 51, 16}, 0}, //MX17 - {{2|(3<<4)}, { 51, 32}, 0}, //MX18 - {{3|(4<<4)}, { 68, 48}, 0}, //MX23 - {{0|(4<<4)}, { 68, 0}, 0}, //MX20 - {{1|(4<<4)}, { 68, 16}, 0}, //MX21 - {{2|(4<<4)}, { 68, 32}, 0}, //MX22 - {{3|(5<<4)}, { 85, 48}, 0}, //MX27 - {{0|(5<<4)}, { 85, 0}, 0}, //MX24 - {{1|(5<<4)}, { 85, 16}, 0}, //MX25 - {{2|(5<<4)}, { 85, 32}, 0}, //MX26 - {{3|(6<<4)}, {102, 48}, 0}, //MX31 - {{0|(6<<4)}, {102, 0}, 0}, //MX28 - {{1|(6<<4)}, {102, 16}, 0}, //MX29 - {{2|(6<<4)}, {102, 32}, 0}, //MX30 - {{3|(7<<4)}, {119, 48}, 0}, //MX36 - {{0|(7<<4)}, {119, 0}, 0}, //MX33 - {{1|(7<<4)}, {119, 16}, 0}, //MX34 - {{2|(7<<4)}, {119, 32}, 0}, //MX35 - {{3|(8<<4)}, {136, 48}, 0}, //MX40 - {{0|(8<<4)}, {136, 0}, 0}, //MX37 - {{1|(8<<4)}, {136, 16}, 0}, //MX38 - {{2|(8<<4)}, {136, 32}, 0}, //MX39 - {{3|(9<<4)}, {153, 48}, 0}, //MX44 - {{0|(9<<4)}, {153, 0}, 0}, //MX41 - {{1|(9<<4)}, {153, 16}, 0}, //MX42 - {{2|(9<<4)}, {153, 32}, 0}, //MX43 - {{3|(10<<4)}, {170, 48}, 0}, //MX48 - {{0|(10<<4)}, {170, 0}, 0}, //MX45 - {{1|(10<<4)}, {170, 16}, 0}, //MX46 - {{2|(10<<4)}, {170, 32}, 0}, //MX47 - {{3|(11<<4)}, {187, 48}, 0}, //MX53 - {{0|(11<<4)}, {187, 0}, 0}, //MX50 - {{1|(11<<4)}, {187, 16}, 0}, //MX51 - {{2|(11<<4)}, {187, 32}, 0}, //MX52 - - {{0|(12<<4)}, {204, 0}, 0}, //MX55 - {{1|(12<<4)}, {204, 16}, 0}, //MX56 - - {{3|(13<<4)}, {221, 48}, 1}, //MX61 - {{0|(13<<4)}, {221, 0}, 1}, //MX59 - {{2|(12<<4)}, {221, 16}, 0}, //MX57 - {{2|(13<<4)}, {221, 32}, 1}, //MX60 - {{4|(13<<4)}, {221, 64}, 1}, //MX62 - {{4|(0<<4)}, { 0, 64}, 1}, //MX5 - {{4|(1<<4)}, { 17, 64}, 1}, //MX10 - {{4|(2<<4)}, { 34, 64}, 1}, //MX15 - {{4|(5<<4)}, {102, 64}, 0}, //MX32 - - {{4|(10<<4)}, {170, 64}, 1}, //MX49 - {{4|(11<<4)}, {187, 64}, 1}, //MX54 - {{4|(12<<4)}, {204, 64}, 1} //MX58 -}; - -#elif defined(HS60_HHKB) - -const is31_led g_is31_leds[DRIVER_LED_TOTAL] = { -/* Refer to IS31 manual for these locations - * driver - * | R location - * | | G location - * | | | B location - * | | | | */ - {0, B_1, A_1, C_1}, //MX1 - {0, E_1, D_1, F_1}, //MX2 - {0, H_1, G_1, I_1}, //MX3 - {0, K_1, J_1, L_1}, //MX4 - {0, B_2, A_2, C_2}, //MX6 - {0, E_2, D_2, F_2}, //MX7 - {0, H_2, G_2, I_2}, //MX8 - {0, K_2, J_2, L_2}, //MX14 - {0, B_3, A_3, C_3}, //MX11 - {0, E_3, D_3, F_3}, //MX12 - {0, H_3, G_3, I_3}, //MX13 - {0, K_3, J_3, L_3}, //MX19 - {0, B_4, A_4, C_4}, //MX16 - {0, E_4, D_4, F_4}, //MX17 - {0, H_4, G_4, I_4}, //MX18 - {0, K_4, J_4, L_4}, //MX23 - {0, B_5, A_5, C_5}, //MX20 - {0, E_5, D_5, F_5}, //MX21 - {0, H_5, G_5, I_5}, //MX22 - {0, K_5, J_5, L_5}, //MX27 - {0, B_6, A_6, C_6}, //MX24 - {0, E_6, D_6, F_6}, //MX25 - {0, H_6, G_6, I_6}, //MX26 - {0, K_6, J_6, L_6}, //MX31 - {0, B_7, A_7, C_7}, //MX28 - {0, E_7, D_7, F_7}, //MX29 - {0, H_7, G_7, I_7}, //MX30 - {0, K_7, J_7, L_7}, //MX36 - {0, B_8, A_8, C_8}, //MX33 - {0, E_8, D_8, F_8}, //MX34 - {0, H_8, G_8, I_8}, //MX35 - {0, K_8, J_8, L_8}, //MX40 - {0, B_9, A_9, C_9}, //MX37 - {0, E_9, D_9, F_9}, //MX38 - {0, H_9, G_9, I_9}, //MX39 - {0, K_9, J_9, L_9}, //MX44 - {0, B_10, A_10, C_10}, //MX41 - {0, E_10, D_10, F_10}, //MX42 - {0, H_10, G_10, I_10}, //MX43 - {0, K_10, J_10, L_10}, //MX48 - {0, B_11, A_11, C_11}, //MX45 - {0, E_11, D_11, F_11}, //MX46 - {0, H_11, G_11, I_11}, //MX47 - {0, K_11, J_11, L_11}, //MX53 - {0, B_12, A_12, C_12}, //MX50 - {0, E_12, D_12, F_12}, //MX51 - {0, H_12, G_12, I_12}, //MX52 - {0, K_12, J_12, L_12}, //MX64 - {0, B_13, A_13, C_13}, //MX55 - {0, E_13, D_13, F_13}, //MX56 - {0, H_13, G_13, I_13}, //MX63 - {0, K_13, J_13, L_13}, //MX61 - {0, B_14, A_14, C_14}, //MX59 - {0, E_14, D_14, F_14}, //MX57 - {0, H_14, G_14, I_14}, //MX60 - {0, K_14, J_14, L_14}, //MX62 - {0, B_15, A_15, C_15}, //MX5 - {0, E_15, D_15, F_15}, //MX10 - {0, H_15, G_15, I_15}, //MX15 - {0, K_15, J_15, L_15}, //MX32 - - - {0, H_16, G_16, I_16}, //MX54 - {0, K_16, J_16, L_16}, //MX58 -}; - -const rgb_led g_rgb_leds[DRIVER_LED_TOTAL] = { -// -// MX1, MX6, MX11, MX16, MX20, MX24, MX28, MX33, MX37, MX41, MX45, MX50, MX55, MX59, -// MX2, MX7, MX12, MX17, MX21, MX25, MX29, MX34, MX38, MX42, MX46, MX51, MX56, MX64, -// MX3, MX8, MX13, MX18, MX22, MX26, MX30, MX35, MX39, MX43, MX47, MX52, MX57, MX60, -// MX4, ----, MX14, MX19, MX23, MX27, MX31, MX36, MX40, MX44, MX48, MX53, MX63, MX61, -// MX5, MX10, MX15, ----, ----, ----, MX32, ----, ---, ----, ----, MX54, MX58, MX62 -/* {row | col << 4} - * | {x=0..224, y=0..64} - * | | modifier - * | | | */ - {{0|(0<<4)}, { 0, 0}, 1}, //MX1 - {{1|(0<<4)}, { 0, 16}, 1}, //MX2 - {{2|(0<<4)}, { 0, 32}, 1}, //MX3 - {{3|(0<<4)}, { 0, 48}, 1}, //MX4 - {{0|(1<<4)}, { 17, 0}, 0}, //MX6 - {{1|(1<<4)}, { 17, 16}, 0}, //MX7 - {{2|(1<<4)}, { 17, 32}, 0}, //MX8 - {{3|(2<<4)}, { 34, 48}, 0}, //MX14 - {{0|(2<<4)}, { 34, 0}, 0}, //MX11 - {{1|(2<<4)}, { 34, 16}, 0}, //MX12 - {{2|(2<<4)}, { 34, 32}, 0}, //MX13 - {{3|(3<<4)}, { 51, 48}, 0}, //MX19 - {{0|(3<<4)}, { 51, 0}, 0}, //MX16 - {{1|(3<<4)}, { 51, 16}, 0}, //MX17 - {{2|(3<<4)}, { 51, 32}, 0}, //MX18 - {{3|(4<<4)}, { 68, 48}, 0}, //MX23 - {{0|(4<<4)}, { 68, 0}, 0}, //MX20 - {{1|(4<<4)}, { 68, 16}, 0}, //MX21 - {{2|(4<<4)}, { 68, 32}, 0}, //MX22 - {{3|(5<<4)}, { 85, 48}, 0}, //MX27 - {{0|(5<<4)}, { 85, 0}, 0}, //MX24 - {{1|(5<<4)}, { 85, 16}, 0}, //MX25 - {{2|(5<<4)}, { 85, 32}, 0}, //MX26 - {{3|(6<<4)}, {102, 48}, 0}, //MX31 - {{0|(6<<4)}, {102, 0}, 0}, //MX28 - {{1|(6<<4)}, {102, 16}, 0}, //MX29 - {{2|(6<<4)}, {102, 32}, 0}, //MX30 - {{3|(7<<4)}, {119, 48}, 0}, //MX36 - {{0|(7<<4)}, {119, 0}, 0}, //MX33 - {{1|(7<<4)}, {119, 16}, 0}, //MX34 - {{2|(7<<4)}, {119, 32}, 0}, //MX35 - {{3|(8<<4)}, {136, 48}, 0}, //MX40 - {{0|(8<<4)}, {136, 0}, 0}, //MX37 - {{1|(8<<4)}, {136, 16}, 0}, //MX38 - {{2|(8<<4)}, {136, 32}, 0}, //MX39 - {{3|(9<<4)}, {153, 48}, 0}, //MX44 - {{0|(9<<4)}, {153, 0}, 0}, //MX41 - {{1|(9<<4)}, {153, 16}, 0}, //MX42 - {{2|(9<<4)}, {153, 32}, 0}, //MX43 - {{3|(10<<4)}, {170, 48}, 0}, //MX48 - {{0|(10<<4)}, {170, 0}, 0}, //MX45 - {{1|(10<<4)}, {170, 16}, 0}, //MX46 - {{2|(10<<4)}, {170, 32}, 0}, //MX47 - {{3|(11<<4)}, {187, 48}, 0}, //MX53 - {{0|(11<<4)}, {187, 0}, 0}, //MX50 - {{1|(11<<4)}, {187, 16}, 0}, //MX51 - {{2|(11<<4)}, {187, 32}, 0}, //MX52 - {{1|(13<<4)}, {221, 0}, 1}, //MX64 - {{0|(12<<4)}, {204, 0}, 0}, //MX55 - {{1|(12<<4)}, {204, 16}, 0}, //MX56 - {{3|(12<<4)}, {204, 48}, 0}, //MX63 - {{3|(13<<4)}, {212, 48}, 1}, //MX61 - {{0|(13<<4)}, {221, 0}, 0}, //MX59 - {{2|(12<<4)}, {221, 16}, 0}, //MX57 - {{2|(13<<4)}, {221, 32}, 1}, //MX60 - {{4|(13<<4)}, {221, 64}, 1}, //MX62 - {{4|(0<<4)}, { 0, 64}, 1}, //MX5 - {{4|(1<<4)}, { 17, 64}, 1}, //MX10 - {{4|(2<<4)}, { 34, 64}, 1}, //MX15 - {{4|(5<<4)}, {102, 64}, 0}, //MX32 - - - {{4|(11<<4)}, {187, 64}, 1}, //MX54 - {{4|(12<<4)}, {204, 64}, 1} //MX58 -}; - -#else //ISO layout - -const is31_led g_is31_leds[DRIVER_LED_TOTAL] = { -/* Refer to IS31 manual for these locations - * driver - * | R location - * | | G location - * | | | B location - * | | | | */ - {0, B_1, A_1, C_1}, //MX1 - {0, E_1, D_1, F_1}, //MX2 - {0, H_1, G_1, I_1}, //MX3 - {0, K_1, J_1, L_1}, //MX4 - {0, B_2, A_2, C_2}, //MX6 - {0, E_2, D_2, F_2}, //MX7 - {0, H_2, G_2, I_2}, //MX8 - {0, K_2, J_2, L_2}, //MX14 - {0, B_3, A_3, C_3}, //MX11 - {0, E_3, D_3, F_3}, //MX12 - {0, H_3, G_3, I_3}, //MX13 - {0, K_3, J_3, L_3}, //MX19 - {0, B_4, A_4, C_4}, //MX16 - {0, E_4, D_4, F_4}, //MX17 - {0, H_4, G_4, I_4}, //MX18 - {0, K_4, J_4, L_4}, //MX23 - {0, B_5, A_5, C_5}, //MX20 - {0, E_5, D_5, F_5}, //MX21 - {0, H_5, G_5, I_5}, //MX22 - {0, K_5, J_5, L_5}, //MX27 - {0, B_6, A_6, C_6}, //MX24 - {0, E_6, D_6, F_6}, //MX25 - {0, H_6, G_6, I_6}, //MX26 - {0, K_6, J_6, L_6}, //MX31 - {0, B_7, A_7, C_7}, //MX28 - {0, E_7, D_7, F_7}, //MX29 - {0, H_7, G_7, I_7}, //MX30 - {0, K_7, J_7, L_7}, //MX36 - {0, B_8, A_8, C_8}, //MX33 - {0, E_8, D_8, F_8}, //MX34 - {0, H_8, G_8, I_8}, //MX35 - {0, K_8, J_8, L_8}, //MX40 - {0, B_9, A_9, C_9}, //MX37 - {0, E_9, D_9, F_9}, //MX38 - {0, H_9, G_9, I_9}, //MX39 - {0, K_9, J_9, L_9}, //MX44 - {0, B_10, A_10, C_10}, //MX41 - {0, E_10, D_10, F_10}, //MX42 - {0, H_10, G_10, I_10}, //MX43 - {0, K_10, J_10, L_10}, //MX48 - {0, B_11, A_11, C_11}, //MX45 - {0, E_11, D_11, F_11}, //MX46 - {0, H_11, G_11, I_11}, //MX47 - {0, K_11, J_11, L_11}, //MX53 - {0, B_12, A_12, C_12}, //MX50 - {0, E_12, D_12, F_12}, //MX51 - {0, H_12, G_12, I_12}, //MX52 - {0, K_12, J_12, L_12}, //MX9 - {0, B_13, A_13, C_13}, //MX55 - {0, E_13, D_13, F_13}, //MX56 - - {0, K_13, J_13, L_13}, //MX61 - {0, B_14, A_14, C_14}, //MX59 - {0, E_14, D_14, F_14}, //MX57 - {0, H_14, G_14, I_14}, //MX60 - {0, K_14, J_14, L_14}, //MX62 - {0, B_15, A_15, C_15}, //MX5 - {0, E_15, D_15, F_15}, //MX10 - {0, H_15, G_15, I_15}, //MX15 - {0, K_15, J_15, L_15}, //MX32 - - {0, E_16, D_16, F_16}, //MX49 - {0, H_16, G_16, I_16}, //MX54 - {0, K_16, J_16, L_16}, //MX58 -}; - -const rgb_led g_rgb_leds[DRIVER_LED_TOTAL] = { -// -// MX1, MX6, MX11, MX16, MX20, MX24, MX28, MX33, MX37, MX41, MX45, MX50, MX55, MX59, -// MX2, MX7, MX12, MX17, MX21, MX25, MX29, MX34, MX38, MX42, MX46, MX51, MX56, ---, -// MX3, MX8, MX13, MX18, MX22, MX26, MX30, MX35, MX39, MX43, MX47, MX52, MX57, MX60, -// MX4, ---, MX14, MX19, MX23, MX27, MX31, MX36, MX40, MX44, MX48, MX53, ---, MX61, -// MX5, MX10, MX15, ---, ---, ---, MX32, ---, ---, ---, MX49, MX54, MX58, MX62 -/* {row | col << 4} - * | {x=0..224, y=0..64} - * | | modifier - * | | | */ - {{0|(0<<4)}, { 0, 0}, 1}, //MX1 - {{1|(0<<4)}, { 0, 16}, 1}, //MX2 - {{2|(0<<4)}, { 0, 32}, 1}, //MX3 - {{3|(0<<4)}, { 0, 48}, 1}, //MX4 - {{0|(1<<4)}, { 17, 0}, 0}, //MX6 - {{1|(1<<4)}, { 17, 16}, 0}, //MX7 - {{2|(1<<4)}, { 17, 32}, 0}, //MX8 - {{3|(2<<4)}, { 34, 48}, 0}, //MX14 - {{0|(2<<4)}, { 34, 0}, 0}, //MX11 - {{1|(2<<4)}, { 34, 16}, 0}, //MX12 - {{2|(2<<4)}, { 34, 32}, 0}, //MX13 - {{3|(3<<4)}, { 51, 48}, 0}, //MX19 - {{0|(3<<4)}, { 51, 0}, 0}, //MX16 - {{1|(3<<4)}, { 51, 16}, 0}, //MX17 - {{2|(3<<4)}, { 51, 32}, 0}, //MX18 - {{3|(4<<4)}, { 68, 48}, 0}, //MX23 - {{0|(4<<4)}, { 68, 0}, 0}, //MX20 - {{1|(4<<4)}, { 68, 16}, 0}, //MX21 - {{2|(4<<4)}, { 68, 32}, 0}, //MX22 - {{3|(5<<4)}, { 85, 48}, 0}, //MX27 - {{0|(5<<4)}, { 85, 0}, 0}, //MX24 - {{1|(5<<4)}, { 85, 16}, 0}, //MX25 - {{2|(5<<4)}, { 85, 32}, 0}, //MX26 - {{3|(6<<4)}, {102, 48}, 0}, //MX31 - {{0|(6<<4)}, {102, 0}, 0}, //MX28 - {{1|(6<<4)}, {102, 16}, 0}, //MX29 - {{2|(6<<4)}, {102, 32}, 0}, //MX30 - {{3|(7<<4)}, {119, 48}, 0}, //MX36 - {{0|(7<<4)}, {119, 0}, 0}, //MX33 - {{1|(7<<4)}, {119, 16}, 0}, //MX34 - {{2|(7<<4)}, {119, 32}, 0}, //MX35 - {{3|(8<<4)}, {136, 48}, 0}, //MX40 - {{0|(8<<4)}, {136, 0}, 0}, //MX37 - {{1|(8<<4)}, {136, 16}, 0}, //MX38 - {{2|(8<<4)}, {136, 32}, 0}, //MX39 - {{3|(9<<4)}, {153, 48}, 0}, //MX44 - {{0|(9<<4)}, {153, 0}, 0}, //MX41 - {{1|(9<<4)}, {153, 16}, 0}, //MX42 - {{2|(9<<4)}, {153, 32}, 0}, //MX43 - {{3|(10<<4)}, {170, 48}, 0}, //MX48 - {{0|(10<<4)}, {170, 0}, 0}, //MX45 - {{1|(10<<4)}, {170, 16}, 0}, //MX46 - {{2|(10<<4)}, {170, 32}, 0}, //MX47 - {{3|(11<<4)}, {187, 48}, 0}, //MX53 - {{0|(11<<4)}, {187, 0}, 0}, //MX50 - {{1|(11<<4)}, {187, 16}, 0}, //MX51 - {{2|(11<<4)}, {187, 32}, 0}, //MX52 - {{3|(2<<4)}, { 17, 32}, 1}, //MX9 - {{0|(12<<4)}, {204, 0}, 0}, //MX55 - {{1|(12<<4)}, {204, 16}, 0}, //MX56 - - {{3|(13<<4)}, {221, 48}, 1}, //MX61 - {{0|(13<<4)}, {221, 0}, 1}, //MX59 - {{2|(12<<4)}, {204, 32}, 0}, //MX57 - {{2|(13<<4)}, {221, 24}, 1}, //MX60 - {{4|(13<<4)}, {221, 64}, 1}, //MX62 - {{4|(0<<4)}, { 0, 64}, 1}, //MX5 - {{4|(1<<4)}, { 17, 64}, 1}, //MX10 - {{4|(2<<4)}, { 34, 64}, 1}, //MX15 - {{4|(5<<4)}, {102, 64}, 0}, //MX32 - - {{4|(10<<4)}, {170, 64}, 1}, //MX49 - {{4|(11<<4)}, {187, 64}, 1}, //MX54 - {{4|(12<<4)}, {204, 64}, 1} //MX58 -}; - +#ifndef RGB_BACKLIGHT_HS60 +#error RGB_BACKLIGHT_M60_A not defined, recheck config.h #endif - -void bootmagic_lite(void) -{ - // The lite version of TMK's bootmagic made by Wilba. - // 100% less potential for accidentally making the - // keyboard do stupid things. - - // We need multiple scans because debouncing can't be turned off. - matrix_scan(); - wait_ms(10); - matrix_scan(); - - // If the Esc and space bar are held down on power up, - // reset the EEPROM valid state and jump to bootloader. - // Assumes Esc is at [0,0] and spacebar is at [4,6]. - // This isn't very generalized, but we need something that doesn't - // rely on user's keymaps in firmware or EEPROM. - if ( ( matrix_get_row(0) & (1<<0) ) && - ( matrix_get_row(4) & (1<<6) ) ) - { - // Set the TMK/QMK EEPROM state as invalid. - eeconfig_disable(); - //eeprom_set_valid(false); - // Jump to bootloader. - bootloader_jump(); - } -} - -void matrix_init_kb(void) { - // put your keyboard start-up code here - // runs once when the firmware starts up - - bootmagic_lite(); - - // Please ignore this is for upcoming features - // If the EEPROM has the magic, the data is good. - // OK to load from EEPROM. - /*if (eeprom_is_valid()) - { - backlight_config_load(); - - // TODO: do something to "turn on" keymaps in EEPROM? - } - else - { - // If the EEPROM has not been saved before, or is out of date, - // save the default values to the EEPROM. Default values - // come from construction of the zeal_backlight_config instance. - backlight_config_save(); - - // Clear the LED colors stored in EEPROM - for ( int row=0; row < MATRIX_ROWS; row++ ) - { - HSV hsv; - for ( int column=0; column < MATRIX_COLS; column++ ) - { - hsv.h = rand() & 0xFF; - hsv.s = rand() & 0x7F; - hsv.v = 255; - backlight_set_key_color( row, column, hsv ); - } - } - #ifdef USE_KEYMAPS_IN_EEPROM - keymap_default_save(); - #endif - // Save the magic number last, in case saving was interrupted - eeprom_set_valid(true); - }*/ - - matrix_init_user(); -} - -void matrix_scan_kb(void) { - - matrix_scan_user(); -} - -bool process_record_kb(uint16_t keycode, keyrecord_t *record) { - - return process_record_user(keycode, record); -} - -void led_set_kb(uint8_t usb_led) { - //backlight_set_indicator_state(usb_led); -} \ No newline at end of file diff --git a/keyboards/hs60/v2/v2.h b/keyboards/hs60/v2/v2.h index 86aeb68a74..0a35acdea7 100644 --- a/keyboards/hs60/v2/v2.h +++ b/keyboards/hs60/v2/v2.h @@ -13,12 +13,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef HS60_H -#define HS60_H +#pragma once #define XXX KC_NO #include "quantum.h" +#include "../../zeal60/rgb_backlight_keycodes.h" +#include "../../zeal60/zeal60_keycodes.h" // This a shortcut to help you visually see your layout. @@ -63,5 +64,3 @@ { K30, XXX, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, K3D }, \ { K40, K41, K42, XXX, XXX, XXX, K46, XXX, XXX, XXX, XXX, K4B, K4C, K4D } \ } - -#endif \ No newline at end of file diff --git a/keyboards/zeal60/rgb_backlight.c b/keyboards/zeal60/rgb_backlight.c index 64b95059e1..a965a13bbd 100644 --- a/keyboards/zeal60/rgb_backlight.c +++ b/keyboards/zeal60/rgb_backlight.c @@ -15,27 +15,44 @@ */ #if RGB_BACKLIGHT_ENABLED -#if defined (RGB_BACKLIGHT_ZEAL60) || defined (RGB_BACKLIGHT_ZEAL65) || defined (RGB_BACKLIGHT_M60_A) || defined(RGB_BACKLIGHT_M6_B) || defined(RGB_BACKLIGHT_KOYU) +#if defined (RGB_BACKLIGHT_ZEAL60) || defined (RGB_BACKLIGHT_ZEAL65) || defined (RGB_BACKLIGHT_M60_A) || defined(RGB_BACKLIGHT_M6_B) || defined(RGB_BACKLIGHT_KOYU) || defined(RGB_BACKLIGHT_HS60) #else #error None of the following was defined: RGB_BACKLIGHT_ZEAL60, RGB_BACKLIGHT_ZEAL65, RGB_BACKLIGHT_M60_A, RGB_BACKLIGHT_M6_B, RGB_BACKLIGHT_KOYU #endif +#ifndef MAX + #define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) +#endif + +#ifndef MIN + #define MIN(a,b) ((a) < (b)? (a): (b)) +#endif + #include "quantum.h" #include "rgb_backlight.h" #include "rgb_backlight_api.h" #include "rgb_backlight_keycodes.h" +#if !defined(RGB_BACKLIGHT_HS60) #include #include #include +#include "drivers/avr/i2c_master.h" +#else +#include "ch.h" +#include "hal.h" +#include "drivers/arm/i2c_master.h" +#include "tmk_core/common/eeprom.h" +#endif #include "progmem.h" - #include "quantum/color.h" -#include "drivers/avr/i2c_master.h" #if defined (RGB_BACKLIGHT_M6_B) #include "drivers/issi/is31fl3218.h" #define BACKLIGHT_LED_COUNT 6 +#elif defined (RGB_BACKLIGHT_HS60) +#include "drivers/issi/is31fl3733.h" +#define BACKLIGHT_LED_COUNT 64 #else #include "drivers/issi/is31fl3731.h" #define BACKLIGHT_LED_COUNT 72 @@ -84,7 +101,88 @@ uint8_t g_key_hit[BACKLIGHT_LED_COUNT]; // Ticks since any key was last hit. uint32_t g_any_key_hit = 0; -#if !defined(RGB_BACKLIGHT_M6_B) +#if defined(RGB_BACKLIGHT_HS60) + +// This is a 7-bit address, that gets left-shifted and bit 0 +// set to 0 for write, 1 for read (as per I2C protocol) +// ADDR_2 is not needed. it is here as a dummy +#define ISSI_ADDR_1 0x50 +#define ISSI_ADDR_2 0x50 + +const is31_led g_is31_leds[DRIVER_LED_TOTAL] = { +/* Refer to IS31 manual for these locations + * driver + * | R location + * | | G location + * | | | B location + * | | | | */ + {0, B_1, A_1, C_1}, //LA1 + {0, E_1, D_1, F_1}, //LA2 + {0, H_1, G_1, I_1}, //LA3 + {0, K_1, J_1, L_1}, //LA4 + {0, B_2, A_2, C_2}, //LA5 + {0, E_2, D_2, F_2}, //LA6 + {0, H_2, G_2, I_2}, //LA7 + {0, K_2, J_2, L_2}, //LA8 + {0, B_3, A_3, C_3}, //LA9 + {0, E_3, D_3, F_3}, //LA10 + {0, H_3, G_3, I_3}, //LA11 + {0, K_3, J_3, L_3}, //LA12 + {0, B_4, A_4, C_4}, //LA13 + {0, E_4, D_4, F_4}, //LA14 + {0, H_4, G_4, I_4}, //LA15 + {0, K_4, J_4, L_4}, //LA16 + {0, B_5, A_5, C_5}, //LA17 + {0, E_5, D_5, F_5}, //LA18 + {0, H_5, G_5, I_5}, //LA19 + {0, K_5, J_5, L_5}, //LA20 + {0, B_6, A_6, C_6}, //LA21 + {0, E_6, D_6, F_6}, //LA22 + {0, H_6, G_6, I_6}, //LA23 + {0, K_6, J_6, L_6}, //LA24 + {0, B_7, A_7, C_7}, //LA25 + {0, E_7, D_7, F_7}, //LA26 + {0, H_7, G_7, I_7}, //LA27 + {0, K_7, J_7, L_7}, //LA28 + {0, B_8, A_8, C_8}, //LA29 + {0, E_8, D_8, F_8}, //LA30 + {0, H_8, G_8, I_8}, //LA31 + {0, K_8, J_8, L_8}, //LA32 + {0, B_9, A_9, C_9}, //LA33 + {0, E_9, D_9, F_9}, //LA34 + {0, H_9, G_9, I_9}, //LA35 + {0, K_9, J_9, L_9}, //LA36 + {0, B_10, A_10, C_10}, //LA37 + {0, E_10, D_10, F_10}, //LA38 + {0, H_10, G_10, I_10}, //LA39 + {0, K_10, J_10, L_10}, //LA40 + {0, B_11, A_11, C_11}, //LA41 + {0, E_11, D_11, F_11}, //LA42 + {0, H_11, G_11, I_11}, //LA43 + {0, K_11, J_11, L_11}, //LA44 + {0, B_12, A_12, C_12}, //LA45 + {0, E_12, D_12, F_12}, //LA46 + {0, H_12, G_12, I_12}, //LA47 + {0, K_12, J_12, L_12}, //LA48 + {0, B_13, A_13, C_13}, //LA49 + {0, E_13, D_13, F_13}, //LA50 + {0, H_13, G_13, I_13}, //LA51 + {0, K_13, J_13, L_13}, //LA52 + {0, B_14, A_14, C_14}, //LA53 + {0, E_14, D_14, F_14}, //LA54 + {0, H_14, G_14, I_14}, //LA55 + {0, K_14, J_14, L_14}, //LA56 + {0, B_15, A_15, C_15}, //LA57 + {0, E_15, D_15, F_15}, //LA58 + {0, H_15, G_15, I_15}, //LA59 + {0, K_15, J_15, L_15}, //LA60 + {0, B_16, A_16, C_16}, //LA61 + {0, E_16, D_16, F_16}, //LA62 + {0, H_16, G_16, I_16}, //LA63 + {0, K_16, J_16, L_16}, //LA64 +}; + +#elif !defined(RGB_BACKLIGHT_M6_B) // This is a 7-bit address, that gets left-shifted and bit 0 // set to 0 for write, 1 for read (as per I2C protocol) #define ISSI_ADDR_1 0x74 @@ -272,6 +370,85 @@ const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = { {0,27}, {0,64}, {0,101}, {0,137}, {0,174}, {255,233}, {228,201}, {235,255}, {237,255}, {195,128}, {206,136}, {215,152}, {222,175}, {205,234}, {209,255}, {214,255}, {219,255}, {223,255} }; +#elif defined (RGB_BACKLIGHT_HS60) && defined (HS60_ANSI) +const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = { + // LA1..LA47 + {0,0}, {4,16}, {6,32}, {10,48}, {16,0}, {24,16}, {28,32}, {36,48}, {32,0}, {40,16}, {44,32}, {52,48}, + {48,0}, {56,16}, {60,32}, {68,48}, {64,0}, {72,16}, {76,32}, {84,48}, {80,0}, {88,16}, {92,32}, {100,48}, + {96,0}, {104,16}, {108,32}, {116,48}, {112,0}, {120,16}, {124,32}, {132,48}, {128,0}, {136,16}, {140,32}, + {148,48}, {144,0}, {152,16}, {156,32}, {164,48}, {160,0}, {168,16}, {172,32}, {180,48}, {176,0}, {184, 16}, {188,32}, + {255,255},// LA48 does not exist, dummy + // LA49..LA50 + {192,0}, {200,16}, + {255,255},// LA51 does not exit, dummy + // LA52..LA60 + {210,48}, {216,0}, {220,16}, {214,32}, {222,64}, {2,64}, {22,64}, {42,64}, {102,64}, + {255,255},// LA61 does not exit, dummy + {162,64}, {182,64}, {202,64} +}; +const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = { + // LA1..LA47 + {96,255}, {109,255}, {128,242}, {148,255}, {93,255}, {105,238}, {128,192}, {154,216}, {89,255}, {101,208}, {128,155}, {159,188}, + {85,255}, {96,181}, {128,119}, {165,163}, {81,255}, {89,157}, {128,82}, {173,143}, {75,255}, {81,139}, {128,46}, {183,131}, + {70,255}, {70,129}, {129,9}, {195,128}, {64,255}, {58,129}, {255,27}, {206,136}, {58,255}, {47,139}, {255,64}, {215,152}, + {53,255}, {39,157}, {255,101}, {222,175}, {47,255}, {32,181}, {255,137}, {228,201}, {43,255}, {27,208}, {255, 174}, + {255,255},// LA48 does not exist, dummy + // LA49..LA50 + {39,255}, {23,238}, + {255,255},// LA51 does not exit, dummy + // LA52..LA60 + {235,255}, {33,255}, {19,255}, {255,233}, {224,255}, {160,255}, {164,255}, {169,255}, {188,255}, + {255,255},// LA61 does not exit, dummy + {209,255}, {215,255}, {220,255} +}; +#elif defined (RGB_BACKLIGHT_HS60) && defined (HS60_HHKB) +const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = { + // LA1..LA60 + {0,0}, {4,16}, {6,32}, {10,48}, {16,0}, {24,16}, {28,32}, {36,48}, {32,0}, {40,16}, {44,32}, {52,48}, + {48,0}, {56,16}, {60,32}, {68,48}, {64,0}, {72,16}, {76,32}, {84,48}, {80,0}, {88,16}, {92,32}, {100,48}, + {96,0}, {104,16}, {108,32}, {116,48}, {112,0}, {120,16}, {124,32}, {132,48}, {128,0}, {136,16}, {140,32}, + {148,48}, {144,0}, {152,16}, {156,32}, {164,48}, {160,0}, {168,16}, {172,32}, {180,48}, {176,0}, {184, 16}, {188,32}, + {224,0}, {192,0}, {200,16}, {202,48}, {224,48}, {208,0}, {220,16}, {214,32}, {220,64}, {4,64}, {24,64}, {44,64}, {112,64}, + {255,255}, {255,255}, // LA61..LA62 does not exit, dummy + // LA63..LA64 + {180,64}, {200,64} +}; +const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = { + // LA1..LA60 + {96,255}, {109,255}, {128,242}, {148,255}, {93,255}, {105,238}, {128,192}, {154,216}, {89,255}, {101,208}, {128,155}, {159,188}, + {85,255}, {96,181}, {128,119}, {165,163}, {81,255}, {89,157}, {128,82}, {173,143}, {75,255}, {81,139}, {128,46}, {183,131}, + {70,255}, {70,129}, {129,9}, {195,128}, {64,255}, {58,129}, {255,27}, {206,136}, {58,255}, {47,139}, {255,64}, {215,152}, + {53,255}, {39,157}, {255,101}, {222,175}, {47,255}, {32,181}, {255,137}, {228,201}, {43,255}, {27,208}, {255, 174}, {32,255}, + {39,255}, {23,238}, {233,242}, {237,255}, {35,255}, {19,255}, {255,233}, {223,255}, {161,255}, {165,255}, {170,255}, {192,255}, + {255,255}, {255,255}, // LA61..LA62 does not exit, dummy + // LA63..LA64 + {214,255}, {219,255} +}; +#elif defined (RGB_BACKLIGHT_HS60) //HS60_ISO +const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = { + // LA1..LA50 + {0,0}, {4,16}, {6,32}, {2,48}, {16,0}, {24,16}, {28,32}, {36,48}, {32,0}, {40,16}, {44,32}, {52,48}, {48,0}, + {56,16}, {60,32}, {68,48}, {64,0}, {72,16}, {76,32}, {84,48}, {80,0}, {88,16}, {92,32}, {100,48}, {96,0}, {104,16}, + {108,32}, {116,48}, {112,0}, {120,16}, {124,32}, {132,48}, {128,0}, {136,16}, {140,32}, {148,48}, {144,0}, {152,16}, + {156,32}, {164,48}, {160,0}, {168,16}, {172,32}, {180,48}, {176,0}, {184, 16}, {188,32}, {20,48}, {192,0}, {200,16}, + {255,255},// LA51 does not exit, dummy + // LA52..LA60 + {210,48}, {216,0}, {220,16}, {222,24}, {222,64}, {2,64}, {22,64}, {42,64}, {102,64}, + {255,255},// LA61 does not exit, dummy + {162,64}, {182,64}, {202,64} +}; +const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = { + // LA1..LA50 + {96,255}, {109,255}, {128,242}, {147,255}, {93,255}, {105,238}, {128,192}, {154,216}, {89,255}, {101,208}, {128,155}, {159,188}, {85,255}, + {96,181}, {128,119}, {165,163}, {81,255}, {89,157}, {128,82}, {173,143}, {75,255}, {81,139}, {128,46}, {183,131}, {70,255}, {70,129}, + {129,9}, {195,128}, {64,255}, {58,129}, {255,27}, {206,136}, {58,255}, {47,139}, {255,64}, {215,152}, {53,255}, {39,157}, {255,101}, + {222,175}, {47,255}, {32,181}, {255,137}, {228,201}, {43,255}, {27,208}, {255, 174}, {150,246}, {39,255}, {23,238}, + {255,255},// LA51 does not exit, dummy + // LA52..LA60 + {235,255}, {33,255}, {19,255}, {10,255}, {224,255}, {160,255}, {164,255}, {169,255}, {188,255}, + {255,255},// LA61 does not exit, dummy + {209,255}, {215,255}, {220,255} +}; #elif defined (RGB_BACKLIGHT_M6_B) // M6-B is really simple: // 0 3 5 @@ -397,6 +574,48 @@ const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = { { 36+16, 36+15, 36+5, 36+4, 36+3, 36+2, 36+1, 54+9, 54+10, 54+11, 54+12, 54+6, 54+7, 54+8 }, { 36+17, 36+8, 36+7, 36+6, 255, 255, 255, 36+0, 255, 54+13, 54+14, 54+15, 54+16, 54+17 } }; +#elif defined (RGB_BACKLIGHT_HS60) && defined (HS60_ANSI) +// +// LA1, LA5, LA9, LA13, LA17, LA21, LA25, LA29, LA33, LA37, LA41, LA45, LA49, LA53, +// LA2, LA6, LA10, LA14, LA18, LA22, LA26, LA30, LA34, LA38, LA42, LA46, LA50, ---, +// LA3, LA7, LA11, LA15, LA19, LA23, LA27, LA31, LA35, LA39, LA43, LA47, LA54, LA55, +// LA4, ---, LA8, LA12, LA16, LA20, LA24, LA28, LA32, LA36, LA40, LA44, ---, LA52, +// LA57, LA58, LA59, ---, ---, ---, LA60, ---, ---, ---, LA62, LA63, LA64, LA56 +const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = { + { 1-1, 5-1, 9-1, 13-1, 17-1, 21-1, 25-1, 29-1, 33-1, 37-1, 41-1, 45-1, 49-1, 53-1 }, + { 2-1, 6-1, 10-1, 14-1, 18-1, 22-1, 26-1, 30-1, 34-1, 38-1, 42-1, 46-1, 50-1, 255 }, + { 3-1, 7-1, 11-1, 15-1, 19-1, 23-1, 27-1, 31-1, 35-1, 39-1, 43-1, 47-1, 54-1, 55-1 }, + { 4-1, 255, 8-1, 12-1, 16-1, 20-1, 24-1, 28-1, 32-1, 36-1, 40-1, 44-1, 255, 52-1 }, + { 57-1, 58-1, 59-1, 255, 255, 255, 60-1, 255, 255, 255, 62-1, 63-1, 64-1, 56-1 } +}; +#elif defined (RGB_BACKLIGHT_HS60) && defined (HS60_HHKB) +// +// LA1, LA5, LA9, LA13, LA17, LA21, LA25, LA29, LA33, LA37, LA41, LA45, LA49, LA53, +// LA2, LA6, LA10, LA14, LA18, LA22, LA26, LA30, LA34, LA38, LA42, LA46, LA50, LA48, +// LA3, LA7, LA11, LA15, LA19, LA23, LA27, LA31, LA35, LA39, LA43, LA47, LA54, LA55, +// LA4, ---, LA8, LA12, LA16, LA20, LA24, LA28, LA32, LA36, LA40, LA44, LA51, LA52, +// LA57, LA58, LA59, ---, ---, ---, LA60, ---, ---, ---, ---, LA63, LA64, LA56 +const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = { + { 1-1, 5-1, 9-1, 13-1, 17-1, 21-1, 25-1, 29-1, 33-1, 37-1, 41-1, 45-1, 49-1, 53-1 }, + { 2-1, 6-1, 10-1, 14-1, 18-1, 22-1, 26-1, 30-1, 34-1, 38-1, 42-1, 46-1, 50-1, 48-1 }, + { 3-1, 7-1, 11-1, 15-1, 19-1, 23-1, 27-1, 31-1, 35-1, 39-1, 43-1, 47-1, 54-1, 55-1 }, + { 4-1, 255, 8-1, 12-1, 16-1, 20-1, 24-1, 28-1, 32-1, 36-1, 40-1, 44-1, 51-1, 52-1 }, + { 57-1, 58-1, 59-1, 255, 255, 255, 60-1, 255, 255, 255, 255, 63-1, 64-1, 56-1 } +}; +#elif defined (RGB_BACKLIGHT_HS60) //HS60_ISO +// +// LA1, LA5, LA9, LA13, LA17, LA21, LA25, LA29, LA33, LA37, LA41, LA45, LA49, LA53, +// LA2, LA6, LA10, LA14, LA18, LA22, LA26, LA30, LA34, LA38, LA42, LA46, LA50, ---, +// LA3, LA7, LA11, LA15, LA19, LA23, LA27, LA31, LA35, LA39, LA43, LA47, LA54, LA55, +// LA4, LA48, LA8, LA12, LA16, LA20, LA24, LA28, LA32, LA36, LA40, LA44, ---, LA52, +// LA57, LA58, LA59, ---, ---, ---, LA60, ---, ---, ---, LA62, LA63, LA64, LA56 +const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = { + { 1-1, 5-1, 9-1, 13-1, 17-1, 21-1, 25-1, 29-1, 33-1, 37-1, 41-1, 45-1, 49-1, 53-1 }, + { 2-1, 6-1, 10-1, 14-1, 18-1, 22-1, 26-1, 30-1, 34-1, 38-1, 42-1, 46-1, 50-1, 255 }, + { 3-1, 7-1, 11-1, 15-1, 19-1, 23-1, 27-1, 31-1, 35-1, 39-1, 43-1, 47-1, 54-1, 55-1 }, + { 4-1, 48-1, 8-1, 12-1, 16-1, 20-1, 24-1, 28-1, 32-1, 36-1, 40-1, 44-1, 255, 52-1 }, + { 57-1, 58-1, 59-1, 255, 255, 255, 60-1, 255, 255, 255, 62-1, 63-1, 64-1, 56-1 } +}; #elif defined (RGB_BACKLIGHT_M6_B) // M6-B is really simple: // 0 3 5 @@ -419,6 +638,9 @@ void backlight_update_pwm_buffers(void) { #if defined (RGB_BACKLIGHT_M6_B) IS31FL3218_update_pwm_buffers(); +#elif defined (RGB_BACKLIGHT_HS60) + IS31FL3733_update_pwm_buffers( ISSI_ADDR_1, ISSI_ADDR_2 ); + IS31FL3733_update_led_control_registers( ISSI_ADDR_1, ISSI_ADDR_2 ); #else IS31FL3731_update_pwm_buffers( ISSI_ADDR_1, ISSI_ADDR_2 ); IS31FL3731_update_led_control_registers( ISSI_ADDR_1, ISSI_ADDR_2 ); @@ -429,6 +651,8 @@ void backlight_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ) { #if defined (RGB_BACKLIGHT_M6_B) IS31FL3218_set_color( index, red, green, blue ); +#elif defined (RGB_BACKLIGHT_HS60) + IS31FL3733_set_color( index, red, green, blue ); #else IS31FL3731_set_color( index, red, green, blue ); #endif @@ -438,6 +662,8 @@ void backlight_set_color_all( uint8_t red, uint8_t green, uint8_t blue ) { #if defined (RGB_BACKLIGHT_M6_B) IS31FL3218_set_color_all( red, green, blue ); +#elif defined (RGB_BACKLIGHT_HS60) + IS31FL3733_set_color_all( red, green, blue ); #else IS31FL3731_set_color_all( red, green, blue ); #endif @@ -452,6 +678,7 @@ void backlight_set_key_hit(uint8_t row, uint8_t column) g_any_key_hit = 0; } +#if !defined(RGB_BACKLIGHT_HS60) // This is (F_CPU/1024) / 20 Hz // = 15625 Hz / 20 Hz // = 781 @@ -487,6 +714,29 @@ void backlight_timer_disable(void) { TIMSK3 &= ~_BV(OCIE3A); } +#else //STM32, use GPT with TIM4. Enable in halconf.h +static void gpt_backlight_timer_task(GPTDriver *gptp); +// Timer setup at 200Khz, callback at 10k ticks = 20Hz +static GPTConfig gpt4cfg1 = { + .frequency = 200000U, + .callback = gpt_backlight_timer_task +}; + +void backlight_timer_init(void) +{ + gptStart(&GPTD4, &gpt4cfg1); +} + +void backlight_timer_enable(void) +{ + gptStartContinuous(&GPTD4, 10000); +} + +void backlight_timer_disable(void) +{ + gptStopTimer(&GPTD4); +} +#endif //!defined(RGB_BACKLIGHT_HS60) void backlight_set_suspend_state(bool state) { @@ -921,7 +1171,11 @@ void backlight_effect_indicators(void) } } +#if !defined(RGB_BACKLIGHT_HS60) ISR(TIMER3_COMPA_vect) +#else //STM32 interrupt +static void gpt_backlight_timer_task(GPTDriver *gptp) +#endif { // delay 1 second before driving LEDs or doing anything else static uint8_t startup_tick = 0; @@ -1378,6 +1632,27 @@ void backlight_init_drivers(void) #if defined(RGB_BACKLIGHT_M6_B) IS31FL3218_init(); +#elif defined(RGB_BACKLIGHT_HS60) + IS31FL3733_init( ISSI_ADDR_1 ); + + for ( int index = 0; index < BACKLIGHT_LED_COUNT; index++ ) + { +#if defined (HS60_ANSI) + bool enabled = !( ( index == 48-1 ) || //LA48 + ( index == 51-1 ) || //LA51 + ( index == 61-1 ) ); //LA61 +#elif defined (HS60_HHKB) + bool enabled = !( ( index == 61-1 ) || //LA61 + ( index == 62-1 ) ); //LA62 +#else //HS60_ISO + bool enabled = !( ( index == 51-1 ) || //LA51 + ( index == 61-1 ) ); //LA61 +#endif + // This only caches it for later + IS31FL3733_set_led_control_register( index, enabled, enabled, enabled ); + } + // This actually updates the LED drivers + IS31FL3733_update_led_control_registers( ISSI_ADDR_1, ISSI_ADDR_2 ); #else IS31FL3731_init( ISSI_ADDR_1 ); IS31FL3731_init( ISSI_ADDR_2 ); @@ -1668,7 +1943,6 @@ void backlight_test_led( uint8_t index, bool red, bool green, bool blue ) } } } -#endif // defined(RGB_DEBUGGING_ONLY) void backlight_debug_led( bool state ) { @@ -1685,5 +1959,6 @@ void backlight_debug_led( bool state ) PORTE &= ~(1<<6); } } +#endif // defined(RGB_DEBUGGING_ONLY) #endif // BACKLIGHT_ENABLED diff --git a/tmk_core/common/chibios/eeprom_stm32.c b/tmk_core/common/chibios/eeprom_stm32.c index a869985501..a15430d676 100755 --- a/tmk_core/common/chibios/eeprom_stm32.c +++ b/tmk_core/common/chibios/eeprom_stm32.c @@ -10,664 +10,206 @@ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * - * This files are free to use from https://github.com/rogerclarkmelbourne/Arduino_STM32 and - * https://github.com/leaflabs/libmaple + * This files are free to use from http://engsta.com/stm32-flash-memory-eeprom-emulator/ by + * Artur F. * * Modifications for QMK and STM32F303 by Yiancar */ +#include +#include #include "eeprom_stm32.h" +/***************************************************************************** + * Allows to use the internal flash to store non volatile data. To initialize + * the functionality use the EEPROM_Init() function. Be sure that by reprogramming + * of the controller just affected pages will be deleted. In other case the non + * volatile data will be lost. +******************************************************************************/ + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Functions -----------------------------------------------------------------*/ + +uint8_t DataBuf[FEE_PAGE_SIZE]; +/***************************************************************************** +* Delete Flash Space used for user Data, deletes the whole space between +* RW_PAGE_BASE_ADDRESS and the last uC Flash Page +******************************************************************************/ +uint16_t EEPROM_Init(void) { + // unlock flash + FLASH_Unlock(); - FLASH_Status EE_ErasePage(uint32_t); - - uint16_t EE_CheckPage(uint32_t, uint16_t); - uint16_t EE_CheckErasePage(uint32_t, uint16_t); - uint16_t EE_Format(void); - uint32_t EE_FindValidPage(void); - uint16_t EE_GetVariablesCount(uint32_t, uint16_t); - uint16_t EE_PageTransfer(uint32_t, uint32_t, uint16_t); - uint16_t EE_VerifyPageFullWriteVariable(uint16_t, uint16_t); - - uint32_t PageBase0 = EEPROM_PAGE0_BASE; - uint32_t PageBase1 = EEPROM_PAGE1_BASE; - uint32_t PageSize = EEPROM_PAGE_SIZE; - uint16_t Status = EEPROM_NOT_INIT; - -// See http://www.st.com/web/en/resource/technical/document/application_note/CD00165693.pdf - -/** - * @brief Check page for blank - * @param page base address - * @retval Success or error - * EEPROM_BAD_FLASH: page not empty after erase - * EEPROM_OK: page blank - */ -uint16_t EE_CheckPage(uint32_t pageBase, uint16_t status) -{ - uint32_t pageEnd = pageBase + (uint32_t)PageSize; - - // Page Status not EEPROM_ERASED and not a "state" - if ((*(__IO uint16_t*)pageBase) != EEPROM_ERASED && (*(__IO uint16_t*)pageBase) != status) - return EEPROM_BAD_FLASH; - for(pageBase += 4; pageBase < pageEnd; pageBase += 4) - if ((*(__IO uint32_t*)pageBase) != 0xFFFFFFFF) // Verify if slot is empty - return EEPROM_BAD_FLASH; - return EEPROM_OK; -} - -/** - * @brief Erase page with increment erase counter (page + 2) - * @param page base address - * @retval Success or error - * FLASH_COMPLETE: success erase - * - Flash error code: on write Flash error - */ -FLASH_Status EE_ErasePage(uint32_t pageBase) -{ - FLASH_Status FlashStatus; - uint16_t data = (*(__IO uint16_t*)(pageBase)); - if ((data == EEPROM_ERASED) || (data == EEPROM_VALID_PAGE) || (data == EEPROM_RECEIVE_DATA)) - data = (*(__IO uint16_t*)(pageBase + 2)) + 1; - else - data = 0; - - FlashStatus = FLASH_ErasePage(pageBase); - if (FlashStatus == FLASH_COMPLETE) - FlashStatus = FLASH_ProgramHalfWord(pageBase + 2, data); - - return FlashStatus; -} + // Clear Flags + //FLASH_ClearFlag(FLASH_SR_EOP|FLASH_SR_PGERR|FLASH_SR_WRPERR); -/** - * @brief Check page for blank and erase it - * @param page base address - * @retval Success or error - * - Flash error code: on write Flash error - * - EEPROM_BAD_FLASH: page not empty after erase - * - EEPROM_OK: page blank - */ -uint16_t EE_CheckErasePage(uint32_t pageBase, uint16_t status) -{ - uint16_t FlashStatus; - if (EE_CheckPage(pageBase, status) != EEPROM_OK) - { - FlashStatus = EE_ErasePage(pageBase); - if (FlashStatus != FLASH_COMPLETE) - return FlashStatus; - return EE_CheckPage(pageBase, status); - } - return EEPROM_OK; + return FEE_DENSITY_BYTES; } +/***************************************************************************** +* Erase the whole reserved Flash Space used for user Data +******************************************************************************/ +void EEPROM_Erase (void) { -/** - * @brief Find valid Page for write or read operation - * @param Page0: Page0 base address - * Page1: Page1 base address - * @retval Valid page address (PAGE0 or PAGE1) or NULL in case of no valid page was found - */ -uint32_t EE_FindValidPage(void) -{ - uint16_t status0 = (*(__IO uint16_t*)PageBase0); // Get Page0 actual status - uint16_t status1 = (*(__IO uint16_t*)PageBase1); // Get Page1 actual status - - if (status0 == EEPROM_VALID_PAGE && status1 == EEPROM_ERASED) - return PageBase0; - if (status1 == EEPROM_VALID_PAGE && status0 == EEPROM_ERASED) - return PageBase1; - - return 0; -} + int page_num = 0; -/** - * @brief Calculate unique variables in EEPROM - * @param start: address of first slot to check (page + 4) - * @param end: page end address - * @param address: 16 bit virtual address of the variable to excluse (or 0XFFFF) - * @retval count of variables - */ -uint16_t EE_GetVariablesCount(uint32_t pageBase, uint16_t skipAddress) -{ - uint16_t varAddress, nextAddress; - uint32_t idx; - uint32_t pageEnd = pageBase + (uint32_t)PageSize; - uint16_t count = 0; - - for (pageBase += 6; pageBase < pageEnd; pageBase += 4) - { - varAddress = (*(__IO uint16_t*)pageBase); - if (varAddress == 0xFFFF || varAddress == skipAddress) - continue; - - count++; - for(idx = pageBase + 4; idx < pageEnd; idx += 4) - { - nextAddress = (*(__IO uint16_t*)idx); - if (nextAddress == varAddress) - { - count--; - break; - } - } - } - return count; + // delete all pages from specified start page to the last page + do { + FLASH_ErasePage(FEE_PAGE_BASE_ADDRESS + (page_num * FEE_PAGE_SIZE)); + page_num++; + } while (page_num < FEE_DENSITY_PAGES); } +/***************************************************************************** +* Writes once data byte to flash on specified address. If a byte is already +* written, the whole page must be copied to a buffer, the byte changed and +* the manipulated buffer written after PageErase. +*******************************************************************************/ +uint16_t EEPROM_WriteDataByte (uint16_t Address, uint8_t DataByte) { -/** - * @brief Transfers last updated variables data from the full Page to an empty one. - * @param newPage: new page base address - * @param oldPage: old page base address - * @param SkipAddress: 16 bit virtual address of the variable (or 0xFFFF) - * @retval Success or error status: - * - FLASH_COMPLETE: on success - * - EEPROM_OUT_SIZE: if valid new page is full - * - Flash error code: on write Flash error - */ -uint16_t EE_PageTransfer(uint32_t newPage, uint32_t oldPage, uint16_t SkipAddress) -{ - uint32_t oldEnd, newEnd; - uint32_t oldIdx, newIdx, idx; - uint16_t address, data, found; - FLASH_Status FlashStatus; - - // Transfer process: transfer variables from old to the new active page - newEnd = newPage + ((uint32_t)PageSize); - - // Find first free element in new page - for (newIdx = newPage + 4; newIdx < newEnd; newIdx += 4) - if ((*(__IO uint32_t*)newIdx) == 0xFFFFFFFF) // Verify if element - break; // contents are 0xFFFFFFFF - if (newIdx >= newEnd) - return EEPROM_OUT_SIZE; - - oldEnd = oldPage + 4; - oldIdx = oldPage + (uint32_t)(PageSize - 2); - - for (; oldIdx > oldEnd; oldIdx -= 4) - { - address = *(__IO uint16_t*)oldIdx; - if (address == 0xFFFF || address == SkipAddress) - continue; // it's means that power off after write data - - found = 0; - for (idx = newPage + 6; idx < newIdx; idx += 4) - if ((*(__IO uint16_t*)(idx)) == address) - { - found = 1; - break; - } - - if (found) - continue; - - if (newIdx < newEnd) - { - data = (*(__IO uint16_t*)(oldIdx - 2)); - - FlashStatus = FLASH_ProgramHalfWord(newIdx, data); - if (FlashStatus != FLASH_COMPLETE) - return FlashStatus; + FLASH_Status FlashStatus = FLASH_COMPLETE; - FlashStatus = FLASH_ProgramHalfWord(newIdx + 2, address); - if (FlashStatus != FLASH_COMPLETE) - return FlashStatus; + uint32_t page; + int i; - newIdx += 4; - } - else - return EEPROM_OUT_SIZE; + // exit if desired address is above the limit (e.G. under 2048 Bytes for 4 pages) + if (Address > FEE_DENSITY_BYTES) { + return 0; } - // Erase the old Page: Set old Page status to EEPROM_EEPROM_ERASED status - data = EE_CheckErasePage(oldPage, EEPROM_ERASED); - if (data != EEPROM_OK) - return data; + // calculate which page is affected (Pagenum1/Pagenum2...PagenumN) + page = (FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address)) & 0x00000FFF; - // Set new Page status - FlashStatus = FLASH_ProgramHalfWord(newPage, EEPROM_VALID_PAGE); - if (FlashStatus != FLASH_COMPLETE) - return FlashStatus; + if (page % FEE_PAGE_SIZE) page = page + FEE_PAGE_SIZE; + page = (page / FEE_PAGE_SIZE) - 1; - return EEPROM_OK; -} + // if current data is 0xFF, the byte is empty, just overwrite with the new one + if ((*(__IO uint16_t*)(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address))) == FEE_EMPTY_WORD) { -/** - * @brief Verify if active page is full and Writes variable in EEPROM. - * @param Address: 16 bit virtual address of the variable - * @param Data: 16 bit data to be written as variable value - * @retval Success or error status: - * - FLASH_COMPLETE: on success - * - EEPROM_PAGE_FULL: if valid page is full (need page transfer) - * - EEPROM_NO_VALID_PAGE: if no valid page was found - * - EEPROM_OUT_SIZE: if EEPROM size exceeded - * - Flash error code: on write Flash error - */ -uint16_t EE_VerifyPageFullWriteVariable(uint16_t Address, uint16_t Data) -{ - FLASH_Status FlashStatus; - uint32_t idx, pageBase, pageEnd, newPage; - uint16_t count; - - // Get valid Page for write operation - pageBase = EE_FindValidPage(); - if (pageBase == 0) - return EEPROM_NO_VALID_PAGE; - - // Get the valid Page end Address - pageEnd = pageBase + PageSize; // Set end of page - - for (idx = pageEnd - 2; idx > pageBase; idx -= 4) - { - if ((*(__IO uint16_t*)idx) == Address) // Find last value for address - { - count = (*(__IO uint16_t*)(idx - 2)); // Read last data - if (count == Data) - return EEPROM_OK; - if (count == 0xFFFF) - { - FlashStatus = FLASH_ProgramHalfWord(idx - 2, Data); // Set variable data - if (FlashStatus == FLASH_COMPLETE) - return EEPROM_OK; - } - break; - } + FlashStatus = FLASH_ProgramHalfWord(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address), (uint16_t)(0x00FF & DataByte)); } + else { - // Check each active page address starting from begining - for (idx = pageBase + 4; idx < pageEnd; idx += 4) - if ((*(__IO uint32_t*)idx) == 0xFFFFFFFF) // Verify if element - { // contents are 0xFFFFFFFF - FlashStatus = FLASH_ProgramHalfWord(idx, Data); // Set variable data - if (FlashStatus != FLASH_COMPLETE) - return FlashStatus; - FlashStatus = FLASH_ProgramHalfWord(idx + 2, Address); // Set variable virtual address - if (FlashStatus != FLASH_COMPLETE) - return FlashStatus; - return EEPROM_OK; - } - - // Empty slot not found, need page transfer - // Calculate unique variables in page - count = EE_GetVariablesCount(pageBase, Address) + 1; - if (count >= (PageSize / 4 - 1)) - return EEPROM_OUT_SIZE; - - if (pageBase == PageBase1) - newPage = PageBase0; // New page address where variable will be moved to - else - newPage = PageBase1; - - // Set the new Page status to RECEIVE_DATA status - FlashStatus = FLASH_ProgramHalfWord(newPage, EEPROM_RECEIVE_DATA); - if (FlashStatus != FLASH_COMPLETE) - return FlashStatus; - - // Write the variable passed as parameter in the new active page - FlashStatus = FLASH_ProgramHalfWord(newPage + 4, Data); - if (FlashStatus != FLASH_COMPLETE) - return FlashStatus; - - FlashStatus = FLASH_ProgramHalfWord(newPage + 6, Address); - if (FlashStatus != FLASH_COMPLETE) - return FlashStatus; - - return EE_PageTransfer(newPage, pageBase, Address); -} - -/*EEPROMClass::EEPROMClass(void) -{ - PageBase0 = EEPROM_PAGE0_BASE; - PageBase1 = EEPROM_PAGE1_BASE; - PageSize = EEPROM_PAGE_SIZE; - Status = EEPROM_NOT_INIT; -}*/ -/* -uint16_t EEPROM_init(uint32_t pageBase0, uint32_t pageBase1, uint32_t pageSize) -{ - PageBase0 = pageBase0; - PageBase1 = pageBase1; - PageSize = pageSize; - return EEPROM_init(); -}*/ + // Copy Page to a buffer + memcpy(DataBuf, (uint8_t*)FEE_PAGE_BASE_ADDRESS + (page * FEE_PAGE_SIZE), FEE_PAGE_SIZE); // !!! Calculate base address for the desired page -uint16_t EEPROM_init(void) -{ - uint16_t status0 = 6, status1 = 6; - FLASH_Status FlashStatus; + // check if new data is differ to current data, return if not, proceed if yes + if (DataByte == *(__IO uint8_t*)(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address))) { + return 0; + } - FLASH_Unlock(); - Status = EEPROM_NO_VALID_PAGE; + // manipulate desired data byte in temp data array if new byte is differ to the current + DataBuf[FEE_ADDR_OFFSET(Address)] = DataByte; - status0 = (*(__IO uint16_t *)PageBase0); - status1 = (*(__IO uint16_t *)PageBase1); + //Erase Page + FlashStatus = FLASH_ErasePage(FEE_PAGE_BASE_ADDRESS + page); - switch (status0) - { -/* - Page0 Page1 - ----- ----- - EEPROM_ERASED EEPROM_VALID_PAGE Page1 valid, Page0 erased - EEPROM_RECEIVE_DATA Page1 need set to valid, Page0 erased - EEPROM_ERASED make EE_Format - any Error: EEPROM_NO_VALID_PAGE -*/ - case EEPROM_ERASED: - if (status1 == EEPROM_VALID_PAGE) // Page0 erased, Page1 valid - Status = EE_CheckErasePage(PageBase0, EEPROM_ERASED); - else if (status1 == EEPROM_RECEIVE_DATA) // Page0 erased, Page1 receive - { - FlashStatus = FLASH_ProgramHalfWord(PageBase1, EEPROM_VALID_PAGE); - if (FlashStatus != FLASH_COMPLETE) - Status = FlashStatus; - else - Status = EE_CheckErasePage(PageBase0, EEPROM_ERASED); - } - else if (status1 == EEPROM_ERASED) // Both in erased state so format EEPROM - Status = EEPROM_format(); - break; -/* - Page0 Page1 - ----- ----- - EEPROM_RECEIVE_DATA EEPROM_VALID_PAGE Transfer Page1 to Page0 - EEPROM_ERASED Page0 need set to valid, Page1 erased - any EEPROM_NO_VALID_PAGE -*/ - case EEPROM_RECEIVE_DATA: - if (status1 == EEPROM_VALID_PAGE) // Page0 receive, Page1 valid - Status = EE_PageTransfer(PageBase0, PageBase1, 0xFFFF); - else if (status1 == EEPROM_ERASED) // Page0 receive, Page1 erased - { - Status = EE_CheckErasePage(PageBase1, EEPROM_ERASED); - if (Status == EEPROM_OK) - { - FlashStatus = FLASH_ProgramHalfWord(PageBase0, EEPROM_VALID_PAGE); - if (FlashStatus != FLASH_COMPLETE) - Status = FlashStatus; - else - Status = EEPROM_OK; + // Write new data (whole page) to flash if data has beed changed + for(i = 0; i < (FEE_PAGE_SIZE / 2); i++) { + if ((__IO uint16_t)(0xFF00 | DataBuf[FEE_ADDR_OFFSET(i)]) != 0xFFFF) { + FlashStatus = FLASH_ProgramHalfWord((FEE_PAGE_BASE_ADDRESS + (page * FEE_PAGE_SIZE)) + (i * 2), (uint16_t)(0xFF00 | DataBuf[FEE_ADDR_OFFSET(i)])); } } - break; -/* - Page0 Page1 - ----- ----- - EEPROM_VALID_PAGE EEPROM_VALID_PAGE Error: EEPROM_NO_VALID_PAGE - EEPROM_RECEIVE_DATA Transfer Page0 to Page1 - any Page0 valid, Page1 erased -*/ - case EEPROM_VALID_PAGE: - if (status1 == EEPROM_VALID_PAGE) // Both pages valid - Status = EEPROM_NO_VALID_PAGE; - else if (status1 == EEPROM_RECEIVE_DATA) - Status = EE_PageTransfer(PageBase1, PageBase0, 0xFFFF); - else - Status = EE_CheckErasePage(PageBase1, EEPROM_ERASED); - break; -/* - Page0 Page1 - ----- ----- - any EEPROM_VALID_PAGE Page1 valid, Page0 erased - EEPROM_RECEIVE_DATA Page1 valid, Page0 erased - any EEPROM_NO_VALID_PAGE -*/ - default: - if (status1 == EEPROM_VALID_PAGE) - Status = EE_CheckErasePage(PageBase0, EEPROM_ERASED); // Check/Erase Page0 - else if (status1 == EEPROM_RECEIVE_DATA) - { - FlashStatus = FLASH_ProgramHalfWord(PageBase1, EEPROM_VALID_PAGE); - if (FlashStatus != FLASH_COMPLETE) - Status = FlashStatus; - else - Status = EE_CheckErasePage(PageBase0, EEPROM_ERASED); - } - break; - } - return Status; -} - -/** - * @brief Erases PAGE0 and PAGE1 and writes EEPROM_VALID_PAGE / 0 header to PAGE0 - * @param PAGE0 and PAGE1 base addresses - * @retval Status of the last operation (Flash write or erase) done during EEPROM formating - */ -uint16_t EEPROM_format(void) -{ - uint16_t status; - FLASH_Status FlashStatus; - FLASH_Unlock(); - - // Erase Page0 - status = EE_CheckErasePage(PageBase0, EEPROM_VALID_PAGE); - if (status != EEPROM_OK) - return status; - if ((*(__IO uint16_t*)PageBase0) == EEPROM_ERASED) - { - // Set Page0 as valid page: Write VALID_PAGE at Page0 base address - FlashStatus = FLASH_ProgramHalfWord(PageBase0, EEPROM_VALID_PAGE); - if (FlashStatus != FLASH_COMPLETE) - return FlashStatus; } - // Erase Page1 - return EE_CheckErasePage(PageBase1, EEPROM_ERASED); -} - -/** - * @brief Returns the erase counter for current page - * @param Data: Global variable contains the read variable value - * @retval Success or error status: - * - EEPROM_OK: if erases counter return. - * - EEPROM_NO_VALID_PAGE: if no valid page was found. - */ -uint16_t EEPROM_erases(uint16_t *Erases) -{ - uint32_t pageBase; - if (Status != EEPROM_OK) - if (EEPROM_init() != EEPROM_OK) - return Status; - - // Get active Page for read operation - pageBase = EE_FindValidPage(); - if (pageBase == 0) - return EEPROM_NO_VALID_PAGE; - - *Erases = (*(__IO uint16_t*)pageBase+2); - return EEPROM_OK; -} - -/** - * @brief Returns the last stored variable data, if found, - * which correspond to the passed virtual address - * @param Address: Variable virtual address - * @retval Data for variable or EEPROM_DEFAULT_DATA, if any errors - */ -/* -uint16_t EEPROM_read (uint16_t Address) -{ - uint16_t data; - EEPROM_read(Address, &data); - return data; -}*/ - -/** - * @brief Returns the last stored variable data, if found, - * which correspond to the passed virtual address - * @param Address: Variable virtual address - * @param Data: Pointer to data variable - * @retval Success or error status: - * - EEPROM_OK: if variable was found - * - EEPROM_BAD_ADDRESS: if the variable was not found - * - EEPROM_NO_VALID_PAGE: if no valid page was found. - */ -uint16_t EEPROM_read(uint16_t Address, uint16_t *Data) -{ - uint32_t pageBase, pageEnd; - - // Set default data (empty EEPROM) - *Data = EEPROM_DEFAULT_DATA; - - if (Status == EEPROM_NOT_INIT) - if (EEPROM_init() != EEPROM_OK) - return Status; - - // Get active Page for read operation - pageBase = EE_FindValidPage(); - if (pageBase == 0) - return EEPROM_NO_VALID_PAGE; - - // Get the valid Page end Address - pageEnd = pageBase + ((uint32_t)(PageSize - 2)); - - // Check each active page address starting from end - for (pageBase += 6; pageEnd >= pageBase; pageEnd -= 4) - if ((*(__IO uint16_t*)pageEnd) == Address) // Compare the read address with the virtual address - { - *Data = (*(__IO uint16_t*)(pageEnd - 2)); // Get content of Address-2 which is variable value - return EEPROM_OK; - } - - // Return ReadStatus value: (0: variable exist, 1: variable doesn't exist) - return EEPROM_BAD_ADDRESS; -} - -/** - * @brief Writes/upadtes variable data in EEPROM. - * @param VirtAddress: Variable virtual address - * @param Data: 16 bit data to be written - * @retval Success or error status: - * - FLASH_COMPLETE: on success - * - EEPROM_BAD_ADDRESS: if address = 0xFFFF - * - EEPROM_PAGE_FULL: if valid page is full - * - EEPROM_NO_VALID_PAGE: if no valid page was found - * - EEPROM_OUT_SIZE: if no empty EEPROM variables - * - Flash error code: on write Flash error - */ -uint16_t EEPROM_write(uint16_t Address, uint16_t Data) -{ - if (Status == EEPROM_NOT_INIT) - if (EEPROM_init() != EEPROM_OK) - return Status; - - if (Address == 0xFFFF) - return EEPROM_BAD_ADDRESS; - - // Write the variable virtual address and value in the EEPROM - uint16_t status = EE_VerifyPageFullWriteVariable(Address, Data); - return status; -} - -/** - * @brief Writes/upadtes variable data in EEPROM. - The value is written only if differs from the one already saved at the same address. - * @param VirtAddress: Variable virtual address - * @param Data: 16 bit data to be written - * @retval Success or error status: - * - EEPROM_SAME_VALUE: If new Data matches existing EEPROM Data - * - FLASH_COMPLETE: on success - * - EEPROM_BAD_ADDRESS: if address = 0xFFFF - * - EEPROM_PAGE_FULL: if valid page is full - * - EEPROM_NO_VALID_PAGE: if no valid page was found - * - EEPROM_OUT_SIZE: if no empty EEPROM variables - * - Flash error code: on write Flash error - */ -uint16_t EEPROM_update(uint16_t Address, uint16_t Data) -{ - uint16_t temp; - EEPROM_read(Address, &temp); - if (temp == Data) - return EEPROM_SAME_VALUE; - else - return EEPROM_write(Address, Data); + return FlashStatus; } +/***************************************************************************** +* Read once data byte from a specified address. +*******************************************************************************/ +uint8_t EEPROM_ReadDataByte (uint16_t Address) { -/** - * @brief Return number of variable - * @retval Number of variables - */ -uint16_t EEPROM_count(uint16_t *Count) -{ - if (Status == EEPROM_NOT_INIT) - if (EEPROM_init() != EEPROM_OK) - return Status; - - // Get valid Page for write operation - uint32_t pageBase = EE_FindValidPage(); - if (pageBase == 0) - return EEPROM_NO_VALID_PAGE; // No valid page, return max. numbers + uint8_t DataByte = 0xFF; - *Count = EE_GetVariablesCount(pageBase, 0xFFFF); - return EEPROM_OK; -} + // Get Byte from specified address + DataByte = (*(__IO uint8_t*)(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address))); -uint16_t EEPROM_maxcount(void) -{ - return ((PageSize / 4)-1); + return DataByte; } - +/***************************************************************************** +* Wrap library in AVR style functions. +*******************************************************************************/ uint8_t eeprom_read_byte (const uint8_t *Address) { const uint16_t p = (const uint32_t) Address; - uint16_t temp; - EEPROM_read(p, &temp); - return (uint8_t) temp; + return EEPROM_ReadDataByte(p); } void eeprom_write_byte (uint8_t *Address, uint8_t Value) { uint16_t p = (uint32_t) Address; - EEPROM_write(p, (uint16_t) Value); + EEPROM_WriteDataByte(p, Value); } void eeprom_update_byte (uint8_t *Address, uint8_t Value) { uint16_t p = (uint32_t) Address; - EEPROM_update(p, (uint16_t) Value); + EEPROM_WriteDataByte(p, Value); } uint16_t eeprom_read_word (const uint16_t *Address) { const uint16_t p = (const uint32_t) Address; - uint16_t temp; - EEPROM_read(p, &temp); - return temp; + return EEPROM_ReadDataByte(p) | (EEPROM_ReadDataByte(p+1) << 8); } void eeprom_write_word (uint16_t *Address, uint16_t Value) { uint16_t p = (uint32_t) Address; - EEPROM_write(p, Value); + EEPROM_WriteDataByte(p, (uint8_t) Value); + EEPROM_WriteDataByte(p + 1, (uint8_t) (Value >> 8)); } void eeprom_update_word (uint16_t *Address, uint16_t Value) { uint16_t p = (uint32_t) Address; - EEPROM_update(p, Value); + EEPROM_WriteDataByte(p, (uint8_t) Value); + EEPROM_WriteDataByte(p + 1, (uint8_t) (Value >> 8)); } uint32_t eeprom_read_dword (const uint32_t *Address) { const uint16_t p = (const uint32_t) Address; - uint16_t temp1, temp2; - EEPROM_read(p, &temp1); - EEPROM_read(p + 1, &temp2); - return temp1 | (temp2 << 16); + return EEPROM_ReadDataByte(p) | (EEPROM_ReadDataByte(p+1) << 8) + | (EEPROM_ReadDataByte(p+2) << 16) | (EEPROM_ReadDataByte(p+3) << 24); } void eeprom_write_dword (uint32_t *Address, uint32_t Value) { - uint16_t temp = (uint16_t) Value; - uint16_t p = (uint32_t) Address; - EEPROM_write(p, temp); - temp = (uint16_t) (Value >> 16); - EEPROM_write(p + 1, temp); + uint16_t p = (const uint32_t) Address; + EEPROM_WriteDataByte(p, (uint8_t) Value); + EEPROM_WriteDataByte(p+1, (uint8_t) (Value >> 8)); + EEPROM_WriteDataByte(p+2, (uint8_t) (Value >> 16)); + EEPROM_WriteDataByte(p+3, (uint8_t) (Value >> 24)); } void eeprom_update_dword (uint32_t *Address, uint32_t Value) { - uint16_t temp = (uint16_t) Value; - uint16_t p = (uint32_t) Address; - EEPROM_update(p, temp); - temp = (uint16_t) (Value >> 16); - EEPROM_update(p + 1, temp); + uint16_t p = (const uint32_t) Address; + EEPROM_WriteDataByte(p, (uint8_t) Value); + EEPROM_WriteDataByte(p+1, (uint8_t) (Value >> 8)); + EEPROM_WriteDataByte(p+2, (uint8_t) (Value >> 16)); + EEPROM_WriteDataByte(p+3, (uint8_t) (Value >> 24)); +} + +void eeprom_read_block(void *buf, const void *addr, uint32_t len) { + const uint8_t *p = (const uint8_t *)addr; + uint8_t *dest = (uint8_t *)buf; + while (len--) { + *dest++ = eeprom_read_byte(p++); + } +} + +void eeprom_write_block(const void *buf, void *addr, uint32_t len) { + uint8_t *p = (uint8_t *)addr; + const uint8_t *src = (const uint8_t *)buf; + while (len--) { + eeprom_write_byte(p++, *src++); + } +} + +void eeprom_update_block(const void *buf, void *addr, uint32_t len) { + uint8_t *p = (uint8_t *)addr; + const uint8_t *src = (const uint8_t *)buf; + while (len--) { + eeprom_write_byte(p++, *src++); + } } diff --git a/tmk_core/common/chibios/eeprom_stm32.h b/tmk_core/common/chibios/eeprom_stm32.h index 09229530ca..892e417b7e 100755 --- a/tmk_core/common/chibios/eeprom_stm32.h +++ b/tmk_core/common/chibios/eeprom_stm32.h @@ -10,15 +10,17 @@ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * - * This files are free to use from https://github.com/rogerclarkmelbourne/Arduino_STM32 and - * https://github.com/leaflabs/libmaple + * This files are free to use from http://engsta.com/stm32-flash-memory-eeprom-emulator/ by + * Artur F. * * Modifications for QMK and STM32F303 by Yiancar + * + * This library assumes 8-bit data locations. To add a new MCU, please provide the flash + * page size and the total flash size in Kb. The number of available pages must be a multiple + * of 2. Only half of the pages account for the total EEPROM size. + * This library also assumes that the pages are not used by the firmware. */ -// This file must be modified if the MCU is not defined below. -// This library also assumes that the pages are not used by the firmware. - #ifndef __EEPROM_H #define __EEPROM_H @@ -38,9 +40,11 @@ #ifndef EEPROM_PAGE_SIZE #if defined (MCU_STM32F103RB) - #define EEPROM_PAGE_SIZE (uint16_t)0x400 /* Page size = 1KByte */ + #define FEE_PAGE_SIZE (uint16_t)0x400 // Page size = 1KByte + #define FEE_DENSITY_PAGES 2 // How many pages are used #elif defined (MCU_STM32F103ZE) || defined (MCU_STM32F103RE) || defined (MCU_STM32F103RD) || defined (MCU_STM32F303CC) - #define EEPROM_PAGE_SIZE (uint16_t)0x800 /* Page size = 2KByte */ + #define FEE_PAGE_SIZE (uint16_t)0x800 // Page size = 2KByte + #define FEE_DENSITY_PAGES 4 // How many pages are used #else #error "No MCU type specified. Add something like -DMCU_STM32F103RB to your compiler arguments (probably in a Makefile)." #endif @@ -48,48 +52,30 @@ #ifndef EEPROM_START_ADDRESS #if defined (MCU_STM32F103RB) - #define EEPROM_START_ADDRESS ((uint32_t)(0x8000000 + 128 * 1024 - 2 * EEPROM_PAGE_SIZE)) + #define FEE_MCU_FLASH_SIZE 128 // Size in Kb #elif defined (MCU_STM32F103ZE) || defined (MCU_STM32F103RE) - #define EEPROM_START_ADDRESS ((uint32_t)(0x8000000 + 512 * 1024 - 2 * EEPROM_PAGE_SIZE)) + #define FEE_MCU_FLASH_SIZE 512 // Size in Kb #elif defined (MCU_STM32F103RD) - #define EEPROM_START_ADDRESS ((uint32_t)(0x8000000 + 384 * 1024 - 2 * EEPROM_PAGE_SIZE)) + #define FEE_MCU_FLASH_SIZE 384 // Size in Kb #elif defined (MCU_STM32F303CC) - #define EEPROM_START_ADDRESS ((uint32_t)(0x8000000 + 256 * 1024 - 2 * EEPROM_PAGE_SIZE)) + #define FEE_MCU_FLASH_SIZE 256 // Size in Kb #else #error "No MCU type specified. Add something like -DMCU_STM32F103RB to your compiler arguments (probably in a Makefile)." #endif #endif -/* Pages 0 and 1 base and end addresses */ -#define EEPROM_PAGE0_BASE ((uint32_t)(EEPROM_START_ADDRESS + 0x000)) -#define EEPROM_PAGE1_BASE ((uint32_t)(EEPROM_START_ADDRESS + EEPROM_PAGE_SIZE)) - -/* Page status definitions */ -#define EEPROM_ERASED ((uint16_t)0xFFFF) /* PAGE is empty */ -#define EEPROM_RECEIVE_DATA ((uint16_t)0xEEEE) /* PAGE is marked to receive data */ -#define EEPROM_VALID_PAGE ((uint16_t)0x0000) /* PAGE containing valid data */ - -/* Page full define */ -enum uint16_t - { - EEPROM_OK = ((uint16_t)0x0000), - EEPROM_OUT_SIZE = ((uint16_t)0x0081), - EEPROM_BAD_ADDRESS = ((uint16_t)0x0082), - EEPROM_BAD_FLASH = ((uint16_t)0x0083), - EEPROM_NOT_INIT = ((uint16_t)0x0084), - EEPROM_SAME_VALUE = ((uint16_t)0x0085), - EEPROM_NO_VALID_PAGE = ((uint16_t)0x00AB) - }; - -#define EEPROM_DEFAULT_DATA 0xFFFF +// DONT CHANGE +// Choose location for the first EEPROM Page address on the top of flash +#define FEE_PAGE_BASE_ADDRESS ((uint32_t)(0x8000000 + FEE_MCU_FLASH_SIZE * 1024 - FEE_DENSITY_PAGES * FEE_PAGE_SIZE)) +#define FEE_DENSITY_BYTES ((FEE_PAGE_SIZE / 2) * FEE_DENSITY_PAGES - 1) +#define FEE_LAST_PAGE_ADDRESS (FEE_PAGE_BASE_ADDRESS + (FEE_PAGE_SIZE * FEE_DENSITY_PAGES)) +#define FEE_EMPTY_WORD ((uint16_t)0xFFFF) +#define FEE_ADDR_OFFSET(Address)(Address * 2) // 1Byte per Word will be saved to preserve Flash - uint16_t EEPROM_init(void); - uint16_t EEPROM_format(void); - uint16_t EEPROM_erases(uint16_t *); - uint16_t EEPROM_read (uint16_t address, uint16_t *data); - uint16_t EEPROM_write(uint16_t address, uint16_t data); - uint16_t EEPROM_update(uint16_t address, uint16_t data); - uint16_t EEPROM_count(uint16_t *); - uint16_t EEPROM_maxcount(void); +// Use this function to initialize the functionality +uint16_t EEPROM_Init(void); +void EEPROM_Erase (void); +uint16_t EEPROM_WriteDataByte (uint16_t Address, uint8_t DataByte); +uint8_t EEPROM_ReadDataByte (uint16_t Address); #endif /* __EEPROM_H */ diff --git a/tmk_core/common/chibios/flash_stm32.c b/tmk_core/common/chibios/flash_stm32.c index 2735934844..164654a15e 100755 --- a/tmk_core/common/chibios/flash_stm32.c +++ b/tmk_core/common/chibios/flash_stm32.c @@ -186,3 +186,18 @@ void FLASH_Lock(void) /* Set the Lock Bit to lock the FPEC and the FCR */ FLASH->CR |= FLASH_CR_LOCK; } + +/** + * @brief Clears the FLASH's pending flags. + * @param FLASH_FLAG: specifies the FLASH flags to clear. + * This parameter can be any combination of the following values: + * @arg FLASH_FLAG_PGERR: FLASH Programming error flag flag + * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag + * @arg FLASH_FLAG_EOP: FLASH End of Programming flag + * @retval None + */ +void FLASH_ClearFlag(uint32_t FLASH_FLAG) +{ + /* Clear the flags */ + FLASH->SR = FLASH_FLAG; +} diff --git a/tmk_core/common/chibios/flash_stm32.h b/tmk_core/common/chibios/flash_stm32.h index cc065cbca2..3c99cc566a 100755 --- a/tmk_core/common/chibios/flash_stm32.h +++ b/tmk_core/common/chibios/flash_stm32.h @@ -45,6 +45,7 @@ FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data); void FLASH_Unlock(void); void FLASH_Lock(void); +void FLASH_ClearFlag(uint32_t FLASH_FLAG); #ifdef __cplusplus } diff --git a/tmk_core/common/eeconfig.c b/tmk_core/common/eeconfig.c index d8bab7d2e5..59b2bffbc7 100644 --- a/tmk_core/common/eeconfig.c +++ b/tmk_core/common/eeconfig.c @@ -33,7 +33,7 @@ void eeconfig_init_kb(void) { */ void eeconfig_init_quantum(void) { #ifdef STM32_EEPROM_ENABLE - EEPROM_format(); + EEPROM_Erase(); #endif eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER); eeprom_update_byte(EECONFIG_DEBUG, 0); @@ -74,7 +74,7 @@ void eeconfig_enable(void) void eeconfig_disable(void) { #ifdef STM32_EEPROM_ENABLE - EEPROM_format(); + EEPROM_Erase(); #endif eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER_OFF); } diff --git a/tmk_core/common/eeconfig.h b/tmk_core/common/eeconfig.h index 8d4e1d4d00..eedd67602c 100644 --- a/tmk_core/common/eeconfig.h +++ b/tmk_core/common/eeconfig.h @@ -25,8 +25,7 @@ along with this program. If not, see . #define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEED #define EECONFIG_MAGIC_NUMBER_OFF (uint16_t)0xFFFF -/* eeprom parameteter address */ -#if !defined(STM32_EEPROM_ENABLE) +/* EEPROM parameter address */ #define EECONFIG_MAGIC (uint16_t *)0 #define EECONFIG_DEBUG (uint8_t *)2 #define EECONFIG_DEFAULT_LAYER (uint8_t *)3 @@ -42,24 +41,6 @@ along with this program. If not, see . #define EECONFIG_KEYBOARD (uint32_t *)15 #define EECONFIG_USER (uint32_t *)19 -#else -/* STM32F3 uses 16byte block. Reconfigure memory map */ -#define EECONFIG_MAGIC (uint16_t *)0 -#define EECONFIG_DEBUG (uint8_t *)1 -#define EECONFIG_DEFAULT_LAYER (uint8_t *)2 -#define EECONFIG_KEYMAP (uint8_t *)3 -#define EECONFIG_MOUSEKEY_ACCEL (uint8_t *)4 -#define EECONFIG_BACKLIGHT (uint8_t *)5 -#define EECONFIG_AUDIO (uint8_t *)6 -#define EECONFIG_RGBLIGHT (uint32_t *)7 -#define EECONFIG_UNICODEMODE (uint8_t *)9 -#define EECONFIG_STENOMODE (uint8_t *)10 -// EEHANDS for two handed boards -#define EECONFIG_HANDEDNESS (uint8_t *)11 -#define EECONFIG_KEYBOARD (uint32_t *)12 -#define EECONFIG_USER (uint32_t *)14 -#endif - /* debug bit */ #define EECONFIG_DEBUG_ENABLE (1<<0) #define EECONFIG_DEBUG_MATRIX (1<<1) diff --git a/tmk_core/common/eeprom.h b/tmk_core/common/eeprom.h index 3696d0df3f..5ae0f6eebd 100644 --- a/tmk_core/common/eeprom.h +++ b/tmk_core/common/eeprom.h @@ -20,5 +20,4 @@ void eeprom_update_dword (uint32_t *__p, uint32_t __value); void eeprom_update_block (const void *__src, void *__dst, uint32_t __n); #endif - #endif /* TMK_CORE_COMMON_EEPROM_H_ */ diff --git a/tmk_core/protocol/chibios/main.c b/tmk_core/protocol/chibios/main.c index ee9571c950..5436d49090 100644 --- a/tmk_core/protocol/chibios/main.c +++ b/tmk_core/protocol/chibios/main.c @@ -113,7 +113,7 @@ int main(void) { chSysInit(); #ifdef STM32_EEPROM_ENABLE - EEPROM_init(); + EEPROM_Init(); #endif // TESTING -- cgit v1.2.3 From 6e984a8b5e34ba181b0893a929af569a1faef2b6 Mon Sep 17 00:00:00 2001 From: patrickmt <40182064+patrickmt@users.noreply.github.com> Date: Tue, 18 Dec 2018 15:21:25 -0500 Subject: Update to arm_atsam wait and timer routines Microsecond (us) delays are now handled by a busy wait loop according to MCU frequency. This replaces the system counter method which had an overhead of around 12us. TC5 device and supporting routines removed as it was the old us delay counter. wait_ms is now properly a macro to CLK_delay_ms. wait_us is now properly a macro to CLK_delay_us. Removed CLK_get_us as it has no use. All calls to CLK_get_ms() have been replaced by timer_read64() with corrected typing. All calls to CLK_delay_ms() have been replaced by wait_ms(). All calls to CLK_delay_us() have been replaced by wait_us() and timings verified or updated as needed after review on scope. Corrected typing of variables using 64bit ms timer readings if needed. --- keyboards/massdrop/alt/matrix.c | 12 +--- keyboards/massdrop/ctrl/matrix.c | 12 +--- tmk_core/common/arm_atsam/timer.c | 20 +----- tmk_core/common/wait.h | 4 ++ tmk_core/protocol/arm_atsam/arm_atsam_protocol.h | 2 + tmk_core/protocol/arm_atsam/clks.c | 90 ++++++------------------ tmk_core/protocol/arm_atsam/clks.h | 5 +- tmk_core/protocol/arm_atsam/i2c_master.c | 4 +- tmk_core/protocol/arm_atsam/led_matrix.c | 4 +- tmk_core/protocol/arm_atsam/main_arm_atsam.c | 18 ++--- tmk_core/protocol/arm_atsam/usb/udi_cdc.c | 8 +-- tmk_core/protocol/arm_atsam/usb/usb2422.c | 15 ++-- 12 files changed, 61 insertions(+), 133 deletions(-) (limited to 'tmk_core/common') diff --git a/keyboards/massdrop/alt/matrix.c b/keyboards/massdrop/alt/matrix.c index 892d38791c..472479d303 100644 --- a/keyboards/massdrop/alt/matrix.c +++ b/keyboards/massdrop/alt/matrix.c @@ -79,8 +79,6 @@ void matrix_init(void) matrix_init_quantum(); } -#define MATRIX_SCAN_DELAY 10 //Delay after setting a col to output (in us) - uint64_t mdebouncing = 0; uint8_t matrix_scan(void) { @@ -89,9 +87,7 @@ uint8_t matrix_scan(void) uint8_t col; uint32_t scans[2]; //PA PB - if (CLK_get_ms() < mdebouncing) return 1; //mdebouncing == 0 when no debouncing active - - //DBG_1_OFF; //Profiling scans + if (timer_read64() < mdebouncing) return 1; //mdebouncing == 0 when no debouncing active memset(mlatest, 0, MATRIX_ROWS * sizeof(matrix_row_t)); //Zero the result buffer @@ -99,7 +95,7 @@ uint8_t matrix_scan(void) { PORT->Group[col_ports[col]].OUTSET.reg = 1 << col_pins[col]; //Set col output - CLK_delay_us(MATRIX_SCAN_DELAY); //Delay for output + wait_us(1); //Delay for output scans[PA] = PORT->Group[PA].IN.reg & row_masks[PA]; //Read PA row pins data scans[PB] = PORT->Group[PB].IN.reg & row_masks[PB]; //Read PB row pins data @@ -132,11 +128,9 @@ uint8_t matrix_scan(void) else { //Begin or extend debounce on change - mdebouncing = CLK_get_ms() + DEBOUNCING_DELAY; + mdebouncing = timer_read64() + DEBOUNCING_DELAY; } - //DBG_1_ON; //Profiling scans - matrix_scan_quantum(); return 1; diff --git a/keyboards/massdrop/ctrl/matrix.c b/keyboards/massdrop/ctrl/matrix.c index 3580577dc1..5f1741e58a 100644 --- a/keyboards/massdrop/ctrl/matrix.c +++ b/keyboards/massdrop/ctrl/matrix.c @@ -79,8 +79,6 @@ void matrix_init(void) matrix_init_quantum(); } -#define MATRIX_SCAN_DELAY 10 //Delay after setting a col to output (in us) - uint64_t mdebouncing = 0; uint8_t matrix_scan(void) { @@ -89,9 +87,7 @@ uint8_t matrix_scan(void) uint8_t col; uint32_t scans[2]; //PA PB - if (CLK_get_ms() < mdebouncing) return 1; //mdebouncing == 0 when no debouncing active - - //DBG_1_OFF; //Profiling scans + if (timer_read64() < mdebouncing) return 1; //mdebouncing == 0 when no debouncing active memset(mlatest, 0, MATRIX_ROWS * sizeof(matrix_row_t)); //Zero the result buffer @@ -99,7 +95,7 @@ uint8_t matrix_scan(void) { PORT->Group[col_ports[col]].OUTSET.reg = 1 << col_pins[col]; //Set col output - CLK_delay_us(MATRIX_SCAN_DELAY); //Delay for output + wait_us(1); //Delay for output scans[PA] = PORT->Group[PA].IN.reg & row_masks[PA]; //Read PA row pins data scans[PB] = PORT->Group[PB].IN.reg & row_masks[PB]; //Read PB row pins data @@ -132,11 +128,9 @@ uint8_t matrix_scan(void) else { //Begin or extend debounce on change - mdebouncing = CLK_get_ms() + DEBOUNCING_DELAY; + mdebouncing = timer_read64() + DEBOUNCING_DELAY; } - //DBG_1_ON; //Profiling scans - matrix_scan_quantum(); return 1; diff --git a/tmk_core/common/arm_atsam/timer.c b/tmk_core/common/arm_atsam/timer.c index bcfe5002c3..6c3905e308 100644 --- a/tmk_core/common/arm_atsam/timer.c +++ b/tmk_core/common/arm_atsam/timer.c @@ -9,7 +9,7 @@ void set_time(uint64_t tset) void timer_init(void) { - ms_clk = 0; + timer_clear(); } uint16_t timer_read(void) @@ -37,23 +37,7 @@ uint32_t timer_elapsed32(uint32_t tlast) return TIMER_DIFF_32(timer_read32(), tlast); } -uint32_t timer_elapsed64(uint32_t tlast) -{ - uint64_t tnow = timer_read64(); - return (tnow >= tlast ? tnow - tlast : UINT64_MAX - tlast + tnow); -} - void timer_clear(void) { - ms_clk = 0; -} - -void wait_ms(uint64_t msec) -{ - CLK_delay_ms(msec); -} - -void wait_us(uint16_t usec) -{ - CLK_delay_us(usec); + set_time(0); } diff --git a/tmk_core/common/wait.h b/tmk_core/common/wait.h index a7cded9420..a77840bcef 100644 --- a/tmk_core/common/wait.h +++ b/tmk_core/common/wait.h @@ -15,6 +15,10 @@ extern "C" { # include "ch.h" # define wait_ms(ms) chThdSleepMilliseconds(ms) # define wait_us(us) chThdSleepMicroseconds(us) +#elif defined PROTOCOL_ARM_ATSAM +# include "clks.h" +# define wait_ms(ms) CLK_delay_ms(ms) +# define wait_us(us) CLK_delay_us(us) #elif defined(__arm__) # include "wait_api.h" #else // Unit tests diff --git a/tmk_core/protocol/arm_atsam/arm_atsam_protocol.h b/tmk_core/protocol/arm_atsam/arm_atsam_protocol.h index 2ba0991749..928af8c7e1 100644 --- a/tmk_core/protocol/arm_atsam/arm_atsam_protocol.h +++ b/tmk_core/protocol/arm_atsam/arm_atsam_protocol.h @@ -21,8 +21,10 @@ along with this program. If not, see . #include "samd51j18a.h" #include "md_bootloader.h" +#include "timer.h" #include "d51_util.h" #include "clks.h" +#include "wait.h" #include "adc.h" #include "i2c_master.h" #include "spi.h" diff --git a/tmk_core/protocol/arm_atsam/clks.c b/tmk_core/protocol/arm_atsam/clks.c index 8768d0a99e..1ff318e59b 100644 --- a/tmk_core/protocol/arm_atsam/clks.c +++ b/tmk_core/protocol/arm_atsam/clks.c @@ -21,8 +21,8 @@ along with this program. If not, see . volatile clk_t system_clks; volatile uint64_t ms_clk; - -volatile uint8_t us_delay_done; +uint32_t usec_delay_mult; +#define USEC_DELAY_LOOP_CYCLES 3 //Sum of instruction cycles in us delay loop const uint32_t sercom_apbbase[] = {(uint32_t)SERCOM0,(uint32_t)SERCOM1,(uint32_t)SERCOM2,(uint32_t)SERCOM3,(uint32_t)SERCOM4,(uint32_t)SERCOM5}; const uint8_t sercom_pchan[] = {7, 8, 23, 24, 34, 35}; @@ -73,6 +73,9 @@ void CLK_oscctrl_init(void) system_clks.freq_gclk[0] = system_clks.freq_dpll[0]; + usec_delay_mult = system_clks.freq_gclk[0] / (USEC_DELAY_LOOP_CYCLES * 1000000); + if (usec_delay_mult < 1) usec_delay_mult = 1; //Never allow a multiplier of zero + DBGC(DC_CLK_OSC_INIT_COMPLETE); } @@ -158,23 +161,11 @@ void TC4_Handler() } } -void TC5_Handler() -{ - if (TC5->COUNT16.INTFLAG.bit.MC0) - { - TC5->COUNT16.INTFLAG.reg = TC_INTENCLR_MC0; - us_delay_done = 1; - TC5->COUNT16.CTRLA.bit.ENABLE = 0; - while (TC5->COUNT16.SYNCBUSY.bit.ENABLE) {} - } -} - uint32_t CLK_enable_timebase(void) { Gclk *pgclk = GCLK; Mclk *pmclk = MCLK; Tc *ptc4 = TC4; - Tc *ptc5 = TC5; Tc *ptc0 = TC0; Evsys *pevsys = EVSYS; @@ -189,11 +180,6 @@ uint32_t CLK_enable_timebase(void) pgclk->PCHCTRL[TC4_GCLK_ID].bit.GEN = GEN_TC45; pgclk->PCHCTRL[TC4_GCLK_ID].bit.CHEN = 1; - //unmask TC5 sourcegclk2 to TC5 - pmclk->APBCMASK.bit.TC5_ = 1; - pgclk->PCHCTRL[TC5_GCLK_ID].bit.GEN = GEN_TC45; - pgclk->PCHCTRL[TC5_GCLK_ID].bit.CHEN = 1; - //configure TC4 DBGC(DC_CLK_ENABLE_TIMEBASE_TC4_BEGIN); ptc4->COUNT16.CTRLA.bit.ENABLE = 0; @@ -220,30 +206,6 @@ uint32_t CLK_enable_timebase(void) DBGC(DC_CLK_ENABLE_TIMEBASE_TC4_COMPLETE); - //configure TC5 - DBGC(DC_CLK_ENABLE_TIMEBASE_TC5_BEGIN); - ptc5->COUNT16.CTRLA.bit.ENABLE = 0; - while (ptc5->COUNT16.SYNCBUSY.bit.ENABLE) { DBGC(DC_CLK_ENABLE_TIMEBASE_TC5_SYNC_DISABLE); } - ptc5->COUNT16.CTRLA.bit.SWRST = 1; - while (ptc5->COUNT16.SYNCBUSY.bit.SWRST) { DBGC(DC_CLK_ENABLE_TIMEBASE_TC5_SYNC_SWRST_1); } - while (ptc5->COUNT16.CTRLA.bit.SWRST) { DBGC(DC_CLK_ENABLE_TIMEBASE_TC5_SYNC_SWRST_2); } - - //CTRLA defaults - //CTRLB as default, counting up - ptc5->COUNT16.CTRLBCLR.reg = 5; - while (ptc5->COUNT16.SYNCBUSY.bit.CTRLB) { DBGC(DC_CLK_ENABLE_TIMEBASE_TC5_SYNC_CLTRB); } - //ptc5->COUNT16.DBGCTRL.bit.DBGRUN = 1; - - //wave mode - ptc5->COUNT16.WAVE.bit.WAVEGEN = 1; //MFRQ match frequency mode, toggle each CC match - //generate event for next stage - ptc5->COUNT16.EVCTRL.bit.MCEO0 = 1; - - NVIC_EnableIRQ(TC5_IRQn); - ptc5->COUNT16.INTENSET.bit.MC0 = 1; - - DBGC(DC_CLK_ENABLE_TIMEBASE_TC5_COMPLETE); - //unmask TC0,1, sourcegclk2 to TC0,1 pmclk->APBAMASK.bit.TC0_ = 1; pgclk->PCHCTRL[TC0_GCLK_ID].bit.GEN = GEN_TC45; @@ -289,37 +251,27 @@ uint32_t CLK_enable_timebase(void) return 0; } -uint32_t CLK_get_ms(void) +void CLK_delay_us(uint32_t usec) { - return ms_clk; -} - -void CLK_delay_us(uint16_t usec) -{ - us_delay_done = 0; - - if (TC5->COUNT16.CTRLA.bit.ENABLE) - { - TC5->COUNT16.CTRLA.bit.ENABLE = 0; - while (TC5->COUNT16.SYNCBUSY.bit.ENABLE) {} - } - - if (usec < 10) usec = 0; - else usec -= 10; - - TC5->COUNT16.CC[0].reg = usec; - while (TC5->COUNT16.SYNCBUSY.bit.CC0) {} - - TC5->COUNT16.CTRLA.bit.ENABLE = 1; - while (TC5->COUNT16.SYNCBUSY.bit.ENABLE) {} - - while (!us_delay_done) {} + asm ( + "CBZ R0, return\n\t" //If usec == 0, branch to return label + ); + asm ( + "MULS R0, %0\n\t" //Multiply R0(usec) by usec_delay_mult and store in R0 + ".balign 16\n\t" //Ensure loop is aligned for fastest performance + "loop: SUBS R0, #1\n\t" //Subtract 1 from R0 and update flags (1 cycle) + "BNE loop\n\t" //Branch if non-zero to loop label (2 cycles) NOTE: USEC_DELAY_LOOP_CYCLES is the sum of loop cycles + "return:\n\t" //Return label + : //No output registers + : "r" (usec_delay_mult) //For %0 + ); + //Note: BX LR generated } void CLK_delay_ms(uint64_t msec) { - msec += CLK_get_ms(); - while (msec > CLK_get_ms()) {} + msec += timer_read64(); + while (msec > timer_read64()) {} } void clk_enable_sercom_apbmask(int sercomn) diff --git a/tmk_core/protocol/arm_atsam/clks.h b/tmk_core/protocol/arm_atsam/clks.h index 96819bfdd0..1b01a1764e 100644 --- a/tmk_core/protocol/arm_atsam/clks.h +++ b/tmk_core/protocol/arm_atsam/clks.h @@ -77,9 +77,8 @@ void CLK_oscctrl_init(void); void CLK_reset_time(void); uint32_t CLK_set_gclk_freq(uint8_t gclkn, uint32_t freq); uint32_t CLK_enable_timebase(void); -uint32_t CLK_get_ms(void); -uint64_t CLK_get_us(void); -void CLK_delay_us(uint16_t usec); +uint64_t timer_read64(void); +void CLK_delay_us(uint32_t usec); void CLK_delay_ms(uint64_t msec); uint32_t CLK_set_spi_freq(uint8_t sercomn, uint32_t freq); diff --git a/tmk_core/protocol/arm_atsam/i2c_master.c b/tmk_core/protocol/arm_atsam/i2c_master.c index f608a79cc9..d91a851f37 100644 --- a/tmk_core/protocol/arm_atsam/i2c_master.c +++ b/tmk_core/protocol/arm_atsam/i2c_master.c @@ -265,12 +265,12 @@ uint8_t I2C3733_Init_Control(void) //USB state machine will enable driver when communication is ready I2C3733_Control_Set(0); - CLK_delay_ms(1); + wait_ms(1); sr_exp_data.bit.IRST = 0; SR_EXP_WriteData(); - CLK_delay_ms(1); + wait_ms(1); DBGC(DC_I2C3733_INIT_CONTROL_COMPLETE); diff --git a/tmk_core/protocol/arm_atsam/led_matrix.c b/tmk_core/protocol/arm_atsam/led_matrix.c index e914fc80ea..9ef7393a25 100644 --- a/tmk_core/protocol/arm_atsam/led_matrix.c +++ b/tmk_core/protocol/arm_atsam/led_matrix.c @@ -494,11 +494,11 @@ void led_matrix_task(void) if (led_enabled) { //If an update may run and frame processing has completed - if (CLK_get_ms() >= led_next_run && led_cur == lede) + if (timer_read64() >= led_next_run && led_cur == lede) { uint8_t drvid; - led_next_run = CLK_get_ms() + LED_UPDATE_RATE; //Set next frame update time + led_next_run = timer_read64() + LED_UPDATE_RATE; //Set next frame update time //NOTE: GCR does not need to be timed with LED processing, but there is really no harm if (gcr_actual != gcr_actual_last) diff --git a/tmk_core/protocol/arm_atsam/main_arm_atsam.c b/tmk_core/protocol/arm_atsam/main_arm_atsam.c index 2bda7d7c7b..eaad66e9fc 100644 --- a/tmk_core/protocol/arm_atsam/main_arm_atsam.c +++ b/tmk_core/protocol/arm_atsam/main_arm_atsam.c @@ -159,7 +159,7 @@ void send_consumer(uint16_t data) void main_subtask_usb_state(void) { - static uint32_t fsmstate_on_delay = 0; //Delay timer to be sure USB is actually operating before bringing up hardware + static uint64_t fsmstate_on_delay = 0; //Delay timer to be sure USB is actually operating before bringing up hardware uint8_t fsmstate_now = USB->DEVICE.FSMSTATUS.reg; //Current state from hardware register if (fsmstate_now == USB_FSMSTATUS_FSMSTATE_SUSPEND_Val) //If USB SUSPENDED @@ -188,9 +188,9 @@ void main_subtask_usb_state(void) { if (fsmstate_on_delay == 0) //If ON delay timer is cleared { - fsmstate_on_delay = CLK_get_ms() + 250; //Set ON delay timer + fsmstate_on_delay = timer_read64() + 250; //Set ON delay timer } - else if (CLK_get_ms() > fsmstate_on_delay) //Else if ON delay timer is active and timed out + else if (timer_read64() > fsmstate_on_delay) //Else if ON delay timer is active and timed out { suspend_wakeup_init(); //Run wakeup routine g_usb_state = fsmstate_now; //Save current USB state @@ -214,9 +214,9 @@ void main_subtask_power_check(void) { static uint64_t next_5v_checkup = 0; - if (CLK_get_ms() > next_5v_checkup) + if (timer_read64() > next_5v_checkup) { - next_5v_checkup = CLK_get_ms() + 5; + next_5v_checkup = timer_read64() + 5; v_5v = adc_get(ADC_5V); v_5v_avg = 0.9 * v_5v_avg + 0.1 * v_5v; @@ -229,9 +229,9 @@ void main_subtask_usb_extra_device(void) { static uint64_t next_usb_checkup = 0; - if (CLK_get_ms() > next_usb_checkup) + if (timer_read64() > next_usb_checkup) { - next_usb_checkup = CLK_get_ms() + 10; + next_usb_checkup = timer_read64() + 10; USB_HandleExtraDevice(); } @@ -325,9 +325,9 @@ int main(void) keyboard_task(); #ifdef CONSOLE_ENABLE - if (CLK_get_ms() > next_print) + if (timer_read64() > next_print) { - next_print = CLK_get_ms() + 250; + next_print = timer_read64() + 250; //Add any debug information here that you want to see very often //dprintf("5v=%u 5vu=%u dlow=%u dhi=%u gca=%u gcd=%u\r\n", v_5v, v_5v_avg, v_5v_avg - V5_LOW, v_5v_avg - V5_HIGH, gcr_actual, gcr_desired); } diff --git a/tmk_core/protocol/arm_atsam/usb/udi_cdc.c b/tmk_core/protocol/arm_atsam/usb/udi_cdc.c index 5f3c289e81..ffe3526db5 100644 --- a/tmk_core/protocol/arm_atsam/usb/udi_cdc.c +++ b/tmk_core/protocol/arm_atsam/usb/udi_cdc.c @@ -1227,9 +1227,9 @@ uint32_t cdc_tx_send_time_next; void CDC_send(void) { - while (CLK_get_ms() < cdc_tx_send_time_next); + while (timer_read64() < cdc_tx_send_time_next); udi_cdc_tx_send(0); - cdc_tx_send_time_next = CLK_get_ms() + CDC_SEND_INTERVAL; + cdc_tx_send_time_next = timer_read64() + CDC_SEND_INTERVAL; } uint32_t CDC_print(char *printbuf) @@ -1238,7 +1238,7 @@ uint32_t CDC_print(char *printbuf) char *buf = printbuf; char c; - if (CLK_get_ms() < 5000) return 0; + if (timer_read64() < 5000) return 0; while ((c = *buf++) != 0 && !(count >= MAX_PRINT)) { @@ -1339,7 +1339,7 @@ void CDC_init(void) inbuf.count = 0; inbuf.lastcount = 0; printbuf[0] = 0; - cdc_tx_send_time_next = CLK_get_ms() + CDC_SEND_INTERVAL; + cdc_tx_send_time_next = timer_read64() + CDC_SEND_INTERVAL; } #else //CDC line 62 diff --git a/tmk_core/protocol/arm_atsam/usb/usb2422.c b/tmk_core/protocol/arm_atsam/usb/usb2422.c index ac19bf4ea0..d6e1922429 100644 --- a/tmk_core/protocol/arm_atsam/usb/usb2422.c +++ b/tmk_core/protocol/arm_atsam/usb/usb2422.c @@ -64,7 +64,7 @@ void USB_write2422_block(void) i2c0_transmit(USB2422_ADDR, dest, 34, 50000); SERCOM0->I2CM.CTRLB.bit.CMD = 0x03; while (SERCOM0->I2CM.SYNCBUSY.bit.SYSOP) { DBGC(DC_USB_WRITE2422_BLOCK_SYNC_SYSOP); } - CLK_delay_us(100); + wait_us(100); } DBGC(DC_USB_WRITE2422_BLOCK_COMPLETE); @@ -135,7 +135,7 @@ void USB2422_init(void) sr_exp_data.bit.HUB_RESET_N = 1; //reset high SR_EXP_WriteData(); - CLK_delay_us(100); + wait_us(100); #ifndef MD_BOOTLOADER @@ -154,10 +154,9 @@ void USB_reset(void) //pulse reset for at least 1 usec sr_exp_data.bit.HUB_RESET_N = 0; //reset low SR_EXP_WriteData(); - CLK_delay_us(1); + wait_us(2); sr_exp_data.bit.HUB_RESET_N = 1; //reset high to run SR_EXP_WriteData(); - CLK_delay_us(1); DBGC(DC_USB_RESET_COMPLETE); } @@ -247,7 +246,7 @@ void USB_set_host_by_voltage(void) SR_EXP_WriteData(); - CLK_delay_ms(250); + wait_ms(250); while ((v_5v = adc_get(ADC_5V)) < ADC_5V_START_LEVEL) { DBGC(DC_USB_SET_HOST_5V_LOW_WAITING); } @@ -313,11 +312,11 @@ uint8_t USB2422_Port_Detect_Init(void) USB_set_host_by_voltage(); - port_detect_retry_ms = CLK_get_ms() + PORT_DETECT_RETRY_INTERVAL; + port_detect_retry_ms = timer_read64() + PORT_DETECT_RETRY_INTERVAL; while (!USB_active()) { - tmod = CLK_get_ms() % PORT_DETECT_RETRY_INTERVAL; + tmod = timer_read64() % PORT_DETECT_RETRY_INTERVAL; if (v_con_1 > v_con_2) //Values updated from USB_set_host_by_voltage(); { @@ -333,7 +332,7 @@ uint8_t USB2422_Port_Detect_Init(void) else { DBG_LED_OFF; } } - if (CLK_get_ms() > port_detect_retry_ms) + if (timer_read64() > port_detect_retry_ms) { DBGC(DC_PORT_DETECT_INIT_FAILED); return 0; -- cgit v1.2.3 From 64c957d907fc7476eca3c26c977ca55cf8a56b38 Mon Sep 17 00:00:00 2001 From: Konstantin Đorđević Date: Wed, 9 Jan 2019 00:08:17 +0100 Subject: Add missing parentheses to some important macros (#4775) * Add missing parentheses to quantum_keycodes macros * Add missing parentheses to progmem macros --- quantum/quantum_keycodes.h | 21 ++++++++++----------- tmk_core/common/progmem.h | 6 +++--- 2 files changed, 13 insertions(+), 14 deletions(-) (limited to 'tmk_core/common') diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index ccf5371f0e..583ba82646 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -489,9 +489,8 @@ enum quantum_keycodes { #define SWIN(kc) SGUI(kc) #define LCA(kc) (QK_LCTL | QK_LALT | (kc)) -#define MOD_HYPR 0xf -#define MOD_MEH 0x7 - +#define MOD_HYPR 0xF +#define MOD_MEH 0x7 // Aliases for shifted symbols // Each key has a 4-letter code, and some have longer aliases too. @@ -601,7 +600,7 @@ enum quantum_keycodes { #define RGB_M_T RGB_MODE_RGBTEST // L-ayer, T-ap - 256 keycode max, 16 layer max -#define LT(layer, kc) (QK_LAYER_TAP | ((layer & 0xF) << 8) | ((kc) & 0xFF)) +#define LT(layer, kc) (QK_LAYER_TAP | (((layer) & 0xF) << 8) | ((kc) & 0xFF)) #define AG_SWAP MAGIC_SWAP_ALT_GUI #define AG_NORM MAGIC_UNSWAP_ALT_GUI @@ -615,28 +614,28 @@ enum quantum_keycodes { // In fact, we changed it to assume ON_PRESS for sanity/simplicity. If needed, you can add your own // keycode modeled after the old version, kept below for this. /* #define TO(layer, when) (QK_TO | (when << 0x4) | (layer & 0xFF)) */ -#define TO(layer) (QK_TO | (ON_PRESS << 0x4) | (layer & 0xFF)) +#define TO(layer) (QK_TO | (ON_PRESS << 0x4) | ((layer) & 0xFF)) // Momentary switch layer - 256 layer max -#define MO(layer) (QK_MOMENTARY | (layer & 0xFF)) +#define MO(layer) (QK_MOMENTARY | ((layer) & 0xFF)) // Set default layer - 256 layer max -#define DF(layer) (QK_DEF_LAYER | (layer & 0xFF)) +#define DF(layer) (QK_DEF_LAYER | ((layer) & 0xFF)) // Toggle to layer - 256 layer max -#define TG(layer) (QK_TOGGLE_LAYER | (layer & 0xFF)) +#define TG(layer) (QK_TOGGLE_LAYER | ((layer) & 0xFF)) // One-shot layer - 256 layer max -#define OSL(layer) (QK_ONE_SHOT_LAYER | (layer & 0xFF)) +#define OSL(layer) (QK_ONE_SHOT_LAYER | ((layer) & 0xFF)) // L-ayer M-od: Momentary switch layer with modifiers active - 16 layer max, left mods only -#define LM(layer, mod) (QK_LAYER_MOD | ((layer & 0xF) << 4) | ((mod) & 0xF)) +#define LM(layer, mod) (QK_LAYER_MOD | (((layer) & 0xF) << 4) | ((mod) & 0xF)) // One-shot mod #define OSM(mod) (QK_ONE_SHOT_MOD | ((mod) & 0xFF)) // Layer tap-toggle -#define TT(layer) (QK_LAYER_TAP_TOGGLE | (layer & 0xFF)) +#define TT(layer) (QK_LAYER_TAP_TOGGLE | ((layer) & 0xFF)) // M-od, T-ap - 256 keycode max #define MT(mod, kc) (QK_MOD_TAP | (((mod) & 0x1F) << 8) | ((kc) & 0xFF)) diff --git a/tmk_core/common/progmem.h b/tmk_core/common/progmem.h index dcc9efb3ce..de93138397 100644 --- a/tmk_core/common/progmem.h +++ b/tmk_core/common/progmem.h @@ -5,9 +5,9 @@ # include #else # define PROGMEM -# define pgm_read_byte(p) *((unsigned char*)p) -# define pgm_read_word(p) *((uint16_t*)p) -# define pgm_read_dword(p) *((uint32_t*)p) +# define pgm_read_byte(p) *((unsigned char*)(p)) +# define pgm_read_word(p) *((uint16_t*)(p)) +# define pgm_read_dword(p) *((uint32_t*)(p)) #endif #endif -- cgit v1.2.3 From 2fd86f4252de4d04c34e1f2ea2ba1da4b842cdd5 Mon Sep 17 00:00:00 2001 From: Nikolaus Wittenstein Date: Wed, 16 Jan 2019 13:57:48 -0500 Subject: Add some function comments in action_layer.c (#4858) --- tmk_core/common/action_layer.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tmk_core/common') diff --git a/tmk_core/common/action_layer.c b/tmk_core/common/action_layer.c index 120ce3f51b..3147d61b36 100644 --- a/tmk_core/common/action_layer.c +++ b/tmk_core/common/action_layer.c @@ -140,7 +140,7 @@ void layer_state_set(uint32_t state) /** \brief Layer clear * - * FIXME: Needs docs + * Turn off all layers. */ void layer_clear(void) { @@ -149,7 +149,7 @@ void layer_clear(void) /** \brief Layer state is * - * FIXME: Needs docs + * Return whether the given state is on (it might still be shadowed by a higher state, though). */ bool layer_state_is(uint8_t layer) { @@ -167,7 +167,7 @@ bool layer_state_cmp(uint32_t cmp_layer_state, uint8_t layer) { /** \brief Layer move * - * FIXME: Needs docs + * Turn on the given layer and turn off all other layers. */ void layer_move(uint8_t layer) { @@ -176,7 +176,7 @@ void layer_move(uint8_t layer) /** \brief Layer on * - * FIXME: Needs docs + * Turn on the given layer. */ void layer_on(uint8_t layer) { @@ -194,7 +194,7 @@ void layer_off(uint8_t layer) /** \brief Layer invert * - * FIXME: Needs docs + * Toggle the given layer (set it if it's unset, or unset it if it's set). */ void layer_invert(uint8_t layer) { @@ -228,7 +228,7 @@ void layer_xor(uint32_t state) /** \brief Layer debug printing * - * FIXME: Needs docs + * Print out the hex value of the 32-bit layer state, as well as the value of the highest bit. */ void layer_debug(void) { -- cgit v1.2.3 From 5fcca9a226b2ab0b1335396e25c37e4b2a261a06 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Thu, 17 Jan 2019 09:04:35 -0800 Subject: Add documentation and fix formating (#4860) --- tmk_core/common/action_layer.c | 301 ++++++++++++++++++++--------------------- 1 file changed, 145 insertions(+), 156 deletions(-) (limited to 'tmk_core/common') diff --git a/tmk_core/common/action_layer.c b/tmk_core/common/action_layer.c index 3147d61b36..6ff8c5549b 100644 --- a/tmk_core/common/action_layer.c +++ b/tmk_core/common/action_layer.c @@ -17,82 +17,76 @@ uint32_t default_layer_state = 0; /** \brief Default Layer State Set At user Level * - * FIXME: Needs docs + * Run user code on default layer state change */ __attribute__((weak)) uint32_t default_layer_state_set_user(uint32_t state) { - return state; + return state; } /** \brief Default Layer State Set At Keyboard Level * - * FIXME: Needs docs + * Run keyboard code on default layer state change */ __attribute__((weak)) uint32_t default_layer_state_set_kb(uint32_t state) { - return default_layer_state_set_user(state); + return default_layer_state_set_user(state); } /** \brief Default Layer State Set * - * FIXME: Needs docs + * Static function to set the default layer state, prints debug info and clears keys */ -static void default_layer_state_set(uint32_t state) -{ - state = default_layer_state_set_kb(state); - debug("default_layer_state: "); - default_layer_debug(); debug(" to "); - default_layer_state = state; - default_layer_debug(); debug("\n"); +static void default_layer_state_set(uint32_t state) { + state = default_layer_state_set_kb(state); + debug("default_layer_state: "); + default_layer_debug(); debug(" to "); + default_layer_state = state; + default_layer_debug(); debug("\n"); #ifdef STRICT_LAYER_RELEASE - clear_keyboard_but_mods(); // To avoid stuck keys + clear_keyboard_but_mods(); // To avoid stuck keys #else - clear_keyboard_but_mods_and_keys(); // Don't reset held keys + clear_keyboard_but_mods_and_keys(); // Don't reset held keys #endif } /** \brief Default Layer Print * - * FIXME: Needs docs + * Print out the hex value of the 32-bit default layer state, as well as the value of the highest bit. */ -void default_layer_debug(void) -{ - dprintf("%08lX(%u)", default_layer_state, biton32(default_layer_state)); +void default_layer_debug(void) { + dprintf("%08lX(%u)", default_layer_state, biton32(default_layer_state)); } /** \brief Default Layer Set * - * FIXME: Needs docs + * Sets the default layer state. */ -void default_layer_set(uint32_t state) -{ - default_layer_state_set(state); +void default_layer_set(uint32_t state) { + default_layer_state_set(state); } #ifndef NO_ACTION_LAYER /** \brief Default Layer Or * - * FIXME: Needs docs + * Turns on the default layer based on matching bits between specifed layer and existing layer state */ -void default_layer_or(uint32_t state) -{ - default_layer_state_set(default_layer_state | state); +void default_layer_or(uint32_t state) { + default_layer_state_set(default_layer_state | state); } /** \brief Default Layer And * - * FIXME: Needs docs + * Turns on default layer based on matching enabled bits between specifed layer and existing layer state */ -void default_layer_and(uint32_t state) -{ - default_layer_state_set(default_layer_state & state); +void default_layer_and(uint32_t state) { + default_layer_state_set(default_layer_state & state); } /** \brief Default Layer Xor * - * FIXME: Needs docs + * Turns on default layer based on non-matching bits between specifed layer and existing layer state */ -void default_layer_xor(uint32_t state) -{ - default_layer_state_set(default_layer_state ^ state); +void default_layer_xor(uint32_t state) { + default_layer_state_set(default_layer_state ^ state); } #endif @@ -104,170 +98,168 @@ uint32_t layer_state = 0; /** \brief Layer state set user * - * FIXME: Needs docs + * Runs user code on layer state change */ __attribute__((weak)) uint32_t layer_state_set_user(uint32_t state) { - return state; + return state; } /** \brief Layer state set keyboard * - * FIXME: Needs docs + * Runs keyboard code on layer state change */ __attribute__((weak)) uint32_t layer_state_set_kb(uint32_t state) { - return layer_state_set_user(state); + return layer_state_set_user(state); } /** \brief Layer state set * - * FIXME: Needs docs + * Sets the layer to match the specifed state (a bitmask) */ -void layer_state_set(uint32_t state) -{ - state = layer_state_set_kb(state); - dprint("layer_state: "); - layer_debug(); dprint(" to "); - layer_state = state; - layer_debug(); dprintln(); +void layer_state_set(uint32_t state) { + state = layer_state_set_kb(state); + dprint("layer_state: "); + layer_debug(); dprint(" to "); + layer_state = state; + layer_debug(); dprintln(); #ifdef STRICT_LAYER_RELEASE - clear_keyboard_but_mods(); // To avoid stuck keys + clear_keyboard_but_mods(); // To avoid stuck keys #else - clear_keyboard_but_mods_and_keys(); // Don't reset held keys + clear_keyboard_but_mods_and_keys(); // Don't reset held keys #endif } /** \brief Layer clear * - * Turn off all layers. + * Turn off all layers */ -void layer_clear(void) -{ - layer_state_set(0); +void layer_clear(void) { + layer_state_set(0); } /** \brief Layer state is * - * Return whether the given state is on (it might still be shadowed by a higher state, though). + * Return whether the given state is on (it might still be shadowed by a higher state, though) */ -bool layer_state_is(uint8_t layer) -{ - return layer_state_cmp(layer_state, layer); +bool layer_state_is(uint8_t layer) { + return layer_state_cmp(layer_state, layer); } /** \brief Layer state compare * - * FIXME: Needs docs + * Used for comparing layers {mostly used for unit testing} */ bool layer_state_cmp(uint32_t cmp_layer_state, uint8_t layer) { - if (!cmp_layer_state) { return layer == 0; } - return (cmp_layer_state & (1UL<= 0; i--) { - if (layers & (1UL<= 0; i--) { + if (layers & (1UL< Date: Fri, 18 Jan 2019 04:08:14 +1000 Subject: Simplify split_common Code significantly (#4772) * Eliminate separate slave loop Both master and slave run the standard keyboard_task main loop now. * Refactor i2c/serial specific code Simplify some of the preprocessor mess by using common function names. * Fix missing #endif * Move direct pin mapping support from miniaxe to split_common For boards with more pins than sense--sorry, switches. * Reordering and reformatting only * Don't run matrix_scan_quantum on slave side * Clean up the offset/slaveOffset calculations * Cut undebounced matrix size in half * Refactor debouncing * Minor fixups * Split split_common transport and debounce code into their own files Can now be replaced with custom versions per keyboard using CUSTOM_TRANSPORT = yes and CUSTOM_DEBOUNCE = yes * Refactor debounce for non-split keyboards too * Update handwired/xealous to build using new split_common * Fix debounce breaking basic test * Dodgy method to allow a split kb to only include one of i2c/serial SPLIT_TRANSPORT = serial or SPLIT_TRANSPORT = i2c will include only that driver code in the binary. SPLIT_TRANSPORT = custom (or anything else) will include neither, the keyboard must supply it's own code if SPLIT_TRANSPORT is not defined then the original behaviour (include both avr i2c and serial code) is maintained. This could be better but it would require explicitly updating all the existing split keyboards. * Enable LTO to get lets_split/sockets under the line * Add docs for SPLIT_TRANSPORT, CUSTOM_MATRIX, CUSTOM_DEBOUNCE * Remove avr-specific sei() from split matrix_setup Not needed now that slave doesn't have a separate main loop. Both sides (on avr) call sei() in lufa's main() after exiting keyboard_setup(). * Fix QUANTUM_LIB_SRC references and simplify SPLIT_TRANSPORT. * Add comments and fix formatting. --- common_features.mk | 38 +- docs/config_options.md | 11 +- docs/getting_started_make_guide.md | 14 +- keyboards/handwired/xealous/debounce.c | 63 ++++ keyboards/handwired/xealous/rules.mk | 10 +- keyboards/lets_split/sockets/config.h | 9 + keyboards/lets_split/sockets/rules.mk | 2 + keyboards/miniaxe/config.h | 5 +- keyboards/miniaxe/matrix.c | 641 --------------------------------- keyboards/miniaxe/rules.mk | 3 +- quantum/config_common.h | 3 + quantum/debounce.c | 52 +++ quantum/debounce.h | 11 + quantum/matrix.c | 79 +--- quantum/split_common/i2c.h | 5 +- quantum/split_common/matrix.c | 639 +++++++++++--------------------- quantum/split_common/matrix.h | 30 +- quantum/split_common/serial.h | 5 +- quantum/split_common/split_flags.h | 9 +- quantum/split_common/split_util.c | 152 +++----- quantum/split_common/split_util.h | 15 +- quantum/split_common/transport.c | 224 ++++++++++++ quantum/split_common/transport.h | 10 + tmk_core/common/keyboard.h | 2 + 24 files changed, 711 insertions(+), 1321 deletions(-) create mode 100644 keyboards/handwired/xealous/debounce.c delete mode 100644 keyboards/miniaxe/matrix.c create mode 100644 quantum/debounce.c create mode 100644 quantum/debounce.h create mode 100644 quantum/split_common/transport.c create mode 100644 quantum/split_common/transport.h (limited to 'tmk_core/common') diff --git a/common_features.mk b/common_features.mk index 572a6db548..8c3361732c 100644 --- a/common_features.mk +++ b/common_features.mk @@ -254,20 +254,34 @@ QUANTUM_SRC:= \ $(QUANTUM_DIR)/keymap_common.c \ $(QUANTUM_DIR)/keycode_config.c -ifeq ($(strip $(SPLIT_KEYBOARD)), yes) - ifneq ($(strip $(CUSTOM_MATRIX)), yes) - QUANTUM_SRC += $(QUANTUM_DIR)/split_common/matrix.c - # Do not use $(QUANTUM_DIR)/matrix.c. - CUSTOM_MATRIX=yes +# Include the standard or split matrix code if needed +ifneq ($(strip $(CUSTOM_MATRIX)), yes) + ifeq ($(strip $(SPLIT_KEYBOARD)), yes) + QUANTUM_SRC += $(QUANTUM_DIR)/split_common/matrix.c + else + QUANTUM_SRC += $(QUANTUM_DIR)/matrix.c endif +endif + +# Include the standard debounce code if needed +ifneq ($(strip $(CUSTOM_DEBOUNCE)), yes) + QUANTUM_SRC += $(QUANTUM_DIR)/debounce.c +endif + +ifeq ($(strip $(SPLIT_KEYBOARD)), yes) OPT_DEFS += -DSPLIT_KEYBOARD + + # Include files used by all split keyboards QUANTUM_SRC += $(QUANTUM_DIR)/split_common/split_flags.c \ - $(QUANTUM_DIR)/split_common/split_util.c - QUANTUM_LIB_SRC += $(QUANTUM_DIR)/split_common/i2c.c - QUANTUM_LIB_SRC += $(QUANTUM_DIR)/split_common/serial.c + $(QUANTUM_DIR)/split_common/split_util.c + + # Determine which (if any) transport files are required + ifneq ($(strip $(SPLIT_TRANSPORT)), custom) + QUANTUM_SRC += $(QUANTUM_DIR)/split_common/transport.c + # Functions added via QUANTUM_LIB_SRC are only included in the final binary if they're called. + # Unused functions are pruned away, which is why we can add both drivers here without bloat. + QUANTUM_LIB_SRC += $(QUANTUM_DIR)/split_common/i2c.c \ + $(QUANTUM_DIR)/split_common/serial.c + endif COMMON_VPATH += $(QUANTUM_PATH)/split_common endif - -ifneq ($(strip $(CUSTOM_MATRIX)), yes) - QUANTUM_SRC += $(QUANTUM_DIR)/matrix.c -endif diff --git a/docs/config_options.md b/docs/config_options.md index 63bcc41d0a..f5c2e76e7e 100644 --- a/docs/config_options.md +++ b/docs/config_options.md @@ -143,7 +143,7 @@ If you define these options you will enable the associated feature, which may in * Breaks any Tap Toggle functionality (`TT` or the One Shot Tap Toggle) * `#define LEADER_TIMEOUT 300` * how long before the leader key times out - * If you're having issues finishing the sequence before it times out, you may need to increase the timeout setting. Or you may want to enable the `LEADER_PER_KEY_TIMING` option, which resets the timeout after each key is tapped. + * If you're having issues finishing the sequence before it times out, you may need to increase the timeout setting. Or you may want to enable the `LEADER_PER_KEY_TIMING` option, which resets the timeout after each key is tapped. * `#define LEADER_PER_KEY_TIMING` * sets the timer for leader key chords to run on each key press rather than overall * `#define LEADER_KEY_STRICT_KEY_PROCESSING` @@ -197,6 +197,9 @@ If you define these options you will enable the associated feature, which may in Split Keyboard specific options, make sure you have 'SPLIT_KEYBOARD = yes' in your rules.mk +* `SPLIT_TRANSPORT = custom` + * Allows replacing the standard split communication routines with a custom one. ARM based split keyboards must use this at present. + ### Setting Handedness One thing to remember, the side that the USB port is plugged into is always the master half. The side not plugged into USB is the slave. @@ -208,7 +211,7 @@ There are a few different ways to set handedness for split keyboards (listed in 3. Set `MASTER_RIGHT`: Half that is plugged into the USB port is determined to be the master and right half (inverse of the default) 4. Default: The side that is plugged into the USB port is the master half and is assumed to be the left half. The slave side is the right half -* `#define SPLIT_HAND_PIN B7` +* `#define SPLIT_HAND_PIN B7` * For using high/low pin to determine handedness, low = right hand, high = left hand. Replace `B7` with the pin you are using. This is optional, and if you leave `SPLIT_HAND_PIN` undefined, then you can still use the EE_HANDS method or MASTER_LEFT / MASTER_RIGHT defines like the stock Let's Split uses. * `#define EE_HANDS` (only works if `SPLIT_HAND_PIN` is not defined) @@ -302,6 +305,10 @@ Use these to enable or disable building certain features. The more you have enab * Current options are AdafruitEzKey, AdafruitBLE, RN42 * `SPLIT_KEYBOARD` * Enables split keyboard support (dual MCU like the let's split and bakingpy's boards) and includes all necessary files located at quantum/split_common +* `CUSTOM_MATRIX` + * Allows replacing the standard matrix scanning routine with a custom one. +* `CUSTOM_DEBOUNCE` + * Allows replacing the standard key debouncing routine with a custom one. * `WAIT_FOR_USB` * Forces the keyboard to wait for a USB connection to be established before it starts up * `NO_USB_STARTUP_CHECK` diff --git a/docs/getting_started_make_guide.md b/docs/getting_started_make_guide.md index adc1aed751..bb7e1e7e3b 100644 --- a/docs/getting_started_make_guide.md +++ b/docs/getting_started_make_guide.md @@ -97,7 +97,7 @@ This allows you to send Unicode characters using `UC()` in your keym `UNICODEMAP_ENABLE` -This allows you to send Unicode characters using `X()` in your keymap. You will need to maintain a mapping table in your keymap file. All possible code points (up to `0x10FFFF`) are supported. +This allows you to send Unicode characters using `X()` in your keymap. You will need to maintain a mapping table in your keymap file. All possible code points (up to `0x10FFFF`) are supported. `UCIS_ENABLE` @@ -135,6 +135,18 @@ This enables [key lock](feature_key_lock.md). This consumes an additional 260 by This enables split keyboard support (dual MCU like the let's split and bakingpy's boards) and includes all necessary files located at quantum/split_common +`SPLIT_TRANSPORT` + +As there is no standard split communication driver for ARM-based split keyboards yet, `SPLIT_TRANSPORT = custom` must be used for these. It will prevent the standard split keyboard communication code (which is AVR-specific) from being included, allowing a custom implementation to be used. + +`CUSTOM_MATRIX` + +Lets you replace the default matrix scanning routine with your own code. You will need to provide your own implementations of matrix_init() and matrix_scan(). + +`CUSTOM_DEBOUNCE` + +Lets you replace the default key debouncing routine with your own code. You will need to provide your own implementation of debounce(). + ## Customizing Makefile Options on a Per-Keymap Basis If your keymap directory has a file called `rules.mk` any options you set in that file will take precedence over other `rules.mk` options for your particular keyboard. diff --git a/keyboards/handwired/xealous/debounce.c b/keyboards/handwired/xealous/debounce.c new file mode 100644 index 0000000000..65a99f27f2 --- /dev/null +++ b/keyboards/handwired/xealous/debounce.c @@ -0,0 +1,63 @@ +#include +#include "config.h" +#include "matrix.h" +#include "timer.h" +#include "quantum.h" + +#ifndef DEBOUNCING_DELAY +# define DEBOUNCING_DELAY 5 +#endif + +//Debouncing counters +typedef uint8_t debounce_counter_t; +#define DEBOUNCE_COUNTER_MODULO 250 +#define DEBOUNCE_COUNTER_INACTIVE 251 + +static debounce_counter_t *debounce_counters; + +void debounce_init(uint8_t num_rows) +{ + debounce_counters = malloc(num_rows*MATRIX_COLS); + memset(debounce_counters, DEBOUNCE_COUNTER_INACTIVE, num_rows*MATRIX_COLS); +} + +void update_debounce_counters(uint8_t num_rows, uint8_t current_time) +{ + for (uint8_t row = 0; row < num_rows; row++) + { + for (uint8_t col = 0; col < MATRIX_COLS; col++) + { + if (debounce_counters[row*MATRIX_COLS + col] != DEBOUNCE_COUNTER_INACTIVE) + { + if (TIMER_DIFF(current_time, debounce_counters[row*MATRIX_COLS + col], DEBOUNCE_COUNTER_MODULO) >= DEBOUNCING_DELAY) { + debounce_counters[row*MATRIX_COLS + col] = DEBOUNCE_COUNTER_INACTIVE; + } + } + } + } +} + +void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t current_time) +{ + for (uint8_t row = 0; row < num_rows; row++) + { + matrix_row_t delta = raw[row] ^ cooked[row]; + + for (uint8_t col = 0; col < MATRIX_COLS; col++) + { + if (debounce_counters[row*MATRIX_COLS + col] == DEBOUNCE_COUNTER_INACTIVE && (delta & (1<. //#define NO_ACTION_ONESHOT //#define NO_ACTION_MACRO //#define NO_ACTION_FUNCTION + +#ifdef USE_Link_Time_Optimization + // LTO has issues with macros (action_get_macro) and "functions" (fn_actions), + // so just disable them + #define NO_ACTION_MACRO + #define NO_ACTION_FUNCTION + + #define DISABLE_LEADER +#endif // USE_Link_Time_Optimization \ No newline at end of file diff --git a/keyboards/lets_split/sockets/rules.mk b/keyboards/lets_split/sockets/rules.mk index e14d18d8de..da04decf40 100644 --- a/keyboards/lets_split/sockets/rules.mk +++ b/keyboards/lets_split/sockets/rules.mk @@ -1,3 +1,5 @@ BACKLIGHT_ENABLE = no AUDIO_ENABLE = yes RGBLIGHT_ENABLE = yes #Don't enable this along with I2C + +EXTRAFLAGS += -flto -DUSE_Link_Time_Optimization diff --git a/keyboards/miniaxe/config.h b/keyboards/miniaxe/config.h index 2b732ca16f..7a68476a54 100644 --- a/keyboards/miniaxe/config.h +++ b/keyboards/miniaxe/config.h @@ -44,8 +44,7 @@ along with this program. If not, see . */ // #define MATRIX_ROW_PINS { D0, D5 } // #define MATRIX_COL_PINS { F1, F0, B0 } -#define NO_PIN 0xFF -#define MATRIX_ROW_COL_PINS { \ +#define DIRECT_PINS { \ { F1, E6, B0, B2, B3 }, \ { F5, F0, B1, B7, D2 }, \ { F6, F7, C7, D5, D3 }, \ @@ -54,7 +53,7 @@ along with this program. If not, see . #define UNUSED_PINS /* COL2ROW, ROW2COL, or CUSTOM_MATRIX */ -#define DIODE_DIRECTION CUSTOM_MATRIX +//#define DIODE_DIRECTION CUSTOM_MATRIX // #define BACKLIGHT_PIN B7 // #define BACKLIGHT_BREATHING diff --git a/keyboards/miniaxe/matrix.c b/keyboards/miniaxe/matrix.c deleted file mode 100644 index 5fec1281df..0000000000 --- a/keyboards/miniaxe/matrix.c +++ /dev/null @@ -1,641 +0,0 @@ -/* -Copyright 2012 Jun Wako - -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 . -*/ - -/* - * scan matrix - */ -#include -#include -#include -#include "wait.h" -#include "print.h" -#include "debug.h" -#include "util.h" -#include "matrix.h" -#include "split_util.h" -#include "pro_micro.h" -#include "config.h" -#include "timer.h" -#include "split_flags.h" - -#ifdef BACKLIGHT_ENABLE -# include "backlight.h" - extern backlight_config_t backlight_config; -#endif - -#if defined(USE_I2C) || defined(EH) -# include "i2c.h" -#else // USE_SERIAL -# include "serial.h" -#endif - -#ifndef DEBOUNCING_DELAY -# define DEBOUNCING_DELAY 5 -#endif - -#if (DEBOUNCING_DELAY > 0) - static uint16_t debouncing_time; - static bool debouncing = false; -#endif - -#if defined(USE_I2C) || defined(EH) - -#if (MATRIX_COLS <= 8) -# define print_matrix_header() print("\nr/c 01234567\n") -# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row)) -# define matrix_bitpop(i) bitpop(matrix[i]) -# define ROW_SHIFTER ((uint8_t)1) -#else -# error "Currently only supports 8 COLS" -#endif - -#else // USE_SERIAL - -#if (MATRIX_COLS <= 8) -# define print_matrix_header() print("\nr/c 01234567\n") -# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row)) -# define matrix_bitpop(i) bitpop(matrix[i]) -# define ROW_SHIFTER ((uint8_t)1) -#elif (MATRIX_COLS <= 16) -# define print_matrix_header() print("\nr/c 0123456789ABCDEF\n") -# define print_matrix_row(row) print_bin_reverse16(matrix_get_row(row)) -# define matrix_bitpop(i) bitpop16(matrix[i]) -# define ROW_SHIFTER ((uint16_t)1) -#elif (MATRIX_COLS <= 32) -# define print_matrix_header() print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n") -# define print_matrix_row(row) print_bin_reverse32(matrix_get_row(row)) -# define matrix_bitpop(i) bitpop32(matrix[i]) -# define ROW_SHIFTER ((uint32_t)1) -#endif - -#endif -static matrix_row_t matrix_debouncing[MATRIX_ROWS]; - -#define ERROR_DISCONNECT_COUNT 5 - -#define ROWS_PER_HAND (MATRIX_ROWS/2) - -static uint8_t error_count = 0; - -#if ((DIODE_DIRECTION == COL2ROW) || (DIODE_DIRECTION == ROW2COL)) -static uint8_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; -static uint8_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; -#elif (DIODE_DIRECTION == CUSTOM_MATRIX) -static uint8_t row_col_pins[MATRIX_ROWS][MATRIX_COLS] = MATRIX_ROW_COL_PINS; -#endif - -/* matrix state(1:on, 0:off) */ -static matrix_row_t matrix[MATRIX_ROWS]; -static matrix_row_t matrix_debouncing[MATRIX_ROWS]; - -#if (DIODE_DIRECTION == COL2ROW) - static void init_cols(void); - static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row); - static void unselect_rows(void); - static void select_row(uint8_t row); - static void unselect_row(uint8_t row); -#elif (DIODE_DIRECTION == ROW2COL) - static void init_rows(void); - static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col); - static void unselect_cols(void); - static void unselect_col(uint8_t col); - static void select_col(uint8_t col); -#elif (DIODE_DIRECTION == CUSTOM_MATRIX) - static void init_cols_rows(void); - static bool read_cols(matrix_row_t current_matrix[], uint8_t current_row); -#endif - -__attribute__ ((weak)) -void matrix_init_kb(void) { - matrix_init_user(); -} - -__attribute__ ((weak)) -void matrix_scan_kb(void) { - matrix_scan_user(); -} - -__attribute__ ((weak)) -void matrix_init_user(void) { -} - -__attribute__ ((weak)) -void matrix_scan_user(void) { -} - -__attribute__ ((weak)) -void matrix_slave_scan_user(void) { -} - -inline -uint8_t matrix_rows(void) -{ - return MATRIX_ROWS; -} - -inline -uint8_t matrix_cols(void) -{ - return MATRIX_COLS; -} - -void matrix_init(void) -{ -#ifdef DISABLE_JTAG - // JTAG disable for PORT F. write JTD bit twice within four cycles. - MCUCR |= (1< 0) - bool matrix_changed = read_cols_on_row(matrix_debouncing+offset, current_row); - - if (matrix_changed) { - debouncing = true; - debouncing_time = timer_read(); - } - -# else - read_cols_on_row(matrix+offset, current_row); -# endif - - } - -#elif (DIODE_DIRECTION == ROW2COL) - // Set col, read rows - for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { -# if (DEBOUNCING_DELAY > 0) - bool matrix_changed = read_rows_on_col(matrix_debouncing+offset, current_col); - if (matrix_changed) { - debouncing = true; - debouncing_time = timer_read(); - } -# else - read_rows_on_col(matrix+offset, current_col); -# endif - - } - -#elif (DIODE_DIRECTION == CUSTOM_MATRIX) - // Set row, read cols - for (uint8_t current_row = 0; current_row < ROWS_PER_HAND; current_row++) { -# if (DEBOUNCING_DELAY > 0) - bool matrix_changed = read_cols(matrix_debouncing+offset, current_row); - if (matrix_changed) { - debouncing = true; - debouncing_time = timer_read(); - } -# else - read_cols(matrix+offset, current_row); -# endif - } -#endif - -# if (DEBOUNCING_DELAY > 0) - if (debouncing && (timer_elapsed(debouncing_time) > DEBOUNCING_DELAY)) { - for (uint8_t i = 0; i < ROWS_PER_HAND; i++) { - matrix[i+offset] = matrix_debouncing[i+offset]; - } - debouncing = false; - } -# endif - - return 1; -} - -#if defined(USE_I2C) || defined(EH) - -// Get rows from other half over i2c -int i2c_transaction(void) { - int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; - int err = 0; - - // write backlight info - #ifdef BACKLIGHT_ENABLE - if (BACKLIT_DIRTY) { - err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_WRITE); - if (err) goto i2c_error; - - // Backlight location - err = i2c_master_write(I2C_BACKLIT_START); - if (err) goto i2c_error; - - // Write backlight - i2c_master_write(get_backlight_level()); - - BACKLIT_DIRTY = false; - } - #endif - - err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_WRITE); - if (err) goto i2c_error; - - // start of matrix stored at I2C_KEYMAP_START - err = i2c_master_write(I2C_KEYMAP_START); - if (err) goto i2c_error; - - // Start read - err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_READ); - if (err) goto i2c_error; - - if (!err) { - int i; - for (i = 0; i < ROWS_PER_HAND-1; ++i) { - matrix[slaveOffset+i] = i2c_master_read(I2C_ACK); - } - matrix[slaveOffset+i] = i2c_master_read(I2C_NACK); - i2c_master_stop(); - } else { -i2c_error: // the cable is disconnceted, or something else went wrong - i2c_reset_state(); - return err; - } - - #ifdef RGBLIGHT_ENABLE - if (RGB_DIRTY) { - err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_WRITE); - if (err) goto i2c_error; - - // RGB Location - err = i2c_master_write(I2C_RGB_START); - if (err) goto i2c_error; - - uint32_t dword = eeconfig_read_rgblight(); - - // Write RGB - err = i2c_master_write_data(&dword, 4); - if (err) goto i2c_error; - - RGB_DIRTY = false; - i2c_master_stop(); - } - #endif - - return 0; -} - -#else // USE_SERIAL - - -typedef struct _Serial_s2m_buffer_t { - // TODO: if MATRIX_COLS > 8 change to uint8_t packed_matrix[] for pack/unpack - matrix_row_t smatrix[ROWS_PER_HAND]; -} Serial_s2m_buffer_t; - -volatile Serial_s2m_buffer_t serial_s2m_buffer = {}; -volatile Serial_m2s_buffer_t serial_m2s_buffer = {}; -uint8_t volatile status0 = 0; - -SSTD_t transactions[] = { - { (uint8_t *)&status0, - sizeof(serial_m2s_buffer), (uint8_t *)&serial_m2s_buffer, - sizeof(serial_s2m_buffer), (uint8_t *)&serial_s2m_buffer - } -}; - -void serial_master_init(void) -{ soft_serial_initiator_init(transactions, TID_LIMIT(transactions)); } - -void serial_slave_init(void) -{ soft_serial_target_init(transactions, TID_LIMIT(transactions)); } - -int serial_transaction(void) { - int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; - - if (soft_serial_transaction()) { - return 1; - } - - // TODO: if MATRIX_COLS > 8 change to unpack() - for (int i = 0; i < ROWS_PER_HAND; ++i) { - matrix[slaveOffset+i] = serial_s2m_buffer.smatrix[i]; - } - - #ifdef RGBLIGHT_ENABLE - // Code to send RGB over serial goes here (not implemented yet) - #endif - - #ifdef BACKLIGHT_ENABLE - // Write backlight level for slave to read - serial_m2s_buffer.backlight_level = backlight_config.enable ? backlight_config.level : 0; - #endif - - return 0; -} -#endif - -uint8_t matrix_scan(void) -{ - uint8_t ret = _matrix_scan(); - -#if defined(USE_I2C) || defined(EH) - if( i2c_transaction() ) { -#else // USE_SERIAL - if( serial_transaction() ) { -#endif - - error_count++; - - if (error_count > ERROR_DISCONNECT_COUNT) { - // reset other half if disconnected - int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; - for (int i = 0; i < ROWS_PER_HAND; ++i) { - matrix[slaveOffset+i] = 0; - } - } - } else { - error_count = 0; - } - matrix_scan_quantum(); - return ret; -} - -void matrix_slave_scan(void) { - _matrix_scan(); - - int offset = (isLeftHand) ? 0 : ROWS_PER_HAND; - -#if defined(USE_I2C) || defined(EH) - for (int i = 0; i < ROWS_PER_HAND; ++i) { - i2c_slave_buffer[I2C_KEYMAP_START+i] = matrix[offset+i]; - } -#else // USE_SERIAL - // TODO: if MATRIX_COLS > 8 change to pack() - for (int i = 0; i < ROWS_PER_HAND; ++i) { - serial_s2m_buffer.smatrix[i] = matrix[offset+i]; - } -#endif - matrix_slave_scan_user(); -} - -bool matrix_is_modified(void) -{ - if (debouncing) return false; - return true; -} - -inline -bool matrix_is_on(uint8_t row, uint8_t col) -{ - return (matrix[row] & ((matrix_row_t)1<> 4) + 1) &= ~_BV(pin & 0xF); // IN - _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI - } -} - -static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) -{ - // Store last value of row prior to reading - matrix_row_t last_row_value = current_matrix[current_row]; - - // Clear data in matrix row - current_matrix[current_row] = 0; - - // Select row and wait for row selecton to stabilize - select_row(current_row); - wait_us(30); - - // For each col... - for(uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { - - // Select the col pin to read (active low) - uint8_t pin = col_pins[col_index]; - uint8_t pin_state = (_SFR_IO8(pin >> 4) & _BV(pin & 0xF)); - - // Populate the matrix row with the state of the col pin - current_matrix[current_row] |= pin_state ? 0 : (ROW_SHIFTER << col_index); - } - - // Unselect row - unselect_row(current_row); - - return (last_row_value != current_matrix[current_row]); -} - -static void select_row(uint8_t row) -{ - uint8_t pin = row_pins[row]; - _SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); // OUT - _SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); // LOW -} - -static void unselect_row(uint8_t row) -{ - uint8_t pin = row_pins[row]; - _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN - _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI -} - -static void unselect_rows(void) -{ - for(uint8_t x = 0; x < ROWS_PER_HAND; x++) { - uint8_t pin = row_pins[x]; - _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN - _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI - } -} - -#elif (DIODE_DIRECTION == ROW2COL) - -static void init_rows(void) -{ - for(uint8_t x = 0; x < ROWS_PER_HAND; x++) { - uint8_t pin = row_pins[x]; - _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN - _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI - } -} - -static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) -{ - bool matrix_changed = false; - - // Select col and wait for col selecton to stabilize - select_col(current_col); - wait_us(30); - - // For each row... - for(uint8_t row_index = 0; row_index < ROWS_PER_HAND; row_index++) - { - - // Store last value of row prior to reading - matrix_row_t last_row_value = current_matrix[row_index]; - - // Check row pin state - if ((_SFR_IO8(row_pins[row_index] >> 4) & _BV(row_pins[row_index] & 0xF)) == 0) - { - // Pin LO, set col bit - current_matrix[row_index] |= (ROW_SHIFTER << current_col); - } - else - { - // Pin HI, clear col bit - current_matrix[row_index] &= ~(ROW_SHIFTER << current_col); - } - - // Determine if the matrix changed state - if ((last_row_value != current_matrix[row_index]) && !(matrix_changed)) - { - matrix_changed = true; - } - } - - // Unselect col - unselect_col(current_col); - - return matrix_changed; -} - -static void select_col(uint8_t col) -{ - uint8_t pin = col_pins[col]; - _SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); // OUT - _SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); // LOW -} - -static void unselect_col(uint8_t col) -{ - uint8_t pin = col_pins[col]; - _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN - _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI -} - -static void unselect_cols(void) -{ - for(uint8_t x = 0; x < MATRIX_COLS; x++) { - uint8_t pin = col_pins[x]; - _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN - _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI - } -} - -#elif (DIODE_DIRECTION == CUSTOM_MATRIX) - -static void init_cols_rows(void) -{ - for(int row = 0; row < MATRIX_ROWS; row++) { - for(int col = 0; col < MATRIX_COLS; col++) { - uint8_t pin = row_col_pins[row][col]; - if(pin == NO_PIN) { - continue; - } - // DDxn set 0 for input - _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); - // PORTxn set 1 for input/pullup - _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); - } - } -} - -static bool read_cols(matrix_row_t current_matrix[], uint8_t current_row) -{ - matrix_row_t last_row_value = current_matrix[current_row]; - current_matrix[current_row] = 0; - - for(uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { - uint8_t pin = row_col_pins[current_row][col_index]; - if(pin == NO_PIN) { - current_matrix[current_row] |= 0; - } - else { - uint8_t pin_state = (_SFR_IO8(pin >> 4) & _BV(pin & 0xF)); - current_matrix[current_row] |= pin_state ? 0 : (ROW_SHIFTER << col_index); - } - } - - return (last_row_value != current_matrix[current_row]); -} - -#endif diff --git a/keyboards/miniaxe/rules.mk b/keyboards/miniaxe/rules.mk index 96e27686b8..2f56a907ba 100644 --- a/keyboards/miniaxe/rules.mk +++ b/keyboards/miniaxe/rules.mk @@ -1,4 +1,3 @@ -SRC += matrix.c # MCU name #MCU = at90usb1286 @@ -83,6 +82,6 @@ FAUXCLICKY_ENABLE = no # Use buzzer to emulate clicky switches HD44780_ENABLE = no # Enable support for HD44780 based LCDs (+400) DEBUG_ENABLE = no -CUSTOM_MATRIX = yes # Use custom matrix code +CUSTOM_MATRIX = no # Use custom matrix code SPLIT_KEYBOARD = yes # Use shared split_common code diff --git a/quantum/config_common.h b/quantum/config_common.h index 606cd9381a..0b2e408a43 100644 --- a/quantum/config_common.h +++ b/quantum/config_common.h @@ -21,6 +21,9 @@ #define ROW2COL 1 #define CUSTOM_MATRIX 2 /* Disables built-in matrix scanning code */ +// useful for direct pin mapping +#define NO_PIN (~0) + #ifdef __AVR__ #ifndef __ASSEMBLER__ #include diff --git a/quantum/debounce.c b/quantum/debounce.c new file mode 100644 index 0000000000..929023ab2d --- /dev/null +++ b/quantum/debounce.c @@ -0,0 +1,52 @@ + +#include "matrix.h" +#include "timer.h" +#include "quantum.h" + +#ifndef DEBOUNCING_DELAY +# define DEBOUNCING_DELAY 5 +#endif + +void debounce_init(uint8_t num_rows) { +} + +#if DEBOUNCING_DELAY > 0 + +static bool debouncing = false; + +void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) { + static uint16_t debouncing_time; + + if (changed) { + debouncing = true; + debouncing_time = timer_read(); + } + + if (debouncing && (timer_elapsed(debouncing_time) > DEBOUNCING_DELAY)) { + for (uint8_t i = 0; i < num_rows; i++) { + cooked[i] = raw[i]; + } + debouncing = false; + } +} + +bool debounce_active(void) { + return debouncing; +} + +#else + +// no debounce +void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) { + if (changed) + { + for (uint8_t i = 0; i < num_rows; i++) { + cooked[i] = raw[i]; + } + } +} + +bool debounce_active(void) { + return false; +} +#endif diff --git a/quantum/debounce.h b/quantum/debounce.h new file mode 100644 index 0000000000..360af77e78 --- /dev/null +++ b/quantum/debounce.h @@ -0,0 +1,11 @@ +#pragma once + +// raw is the current key state +// on entry cooked is the previous debounced state +// on exit cooked is the current debounced state +// changed is true if raw has changed since the last call +void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed); + +bool debounce_active(void); + +void debounce_init(uint8_t num_rows); \ No newline at end of file diff --git a/quantum/matrix.c b/quantum/matrix.c index 9b5ce33d23..49a1845696 100644 --- a/quantum/matrix.c +++ b/quantum/matrix.c @@ -21,21 +21,9 @@ along with this program. If not, see . #include "debug.h" #include "util.h" #include "matrix.h" -#include "timer.h" +#include "debounce.h" #include "quantum.h" - -/* Set 0 if debouncing isn't needed */ - -#ifndef DEBOUNCING_DELAY -# define DEBOUNCING_DELAY 5 -#endif - -#if (DEBOUNCING_DELAY > 0) - static uint16_t debouncing_time; - static bool debouncing = false; -#endif - #if (MATRIX_COLS <= 8) # define print_matrix_header() print("\nr/c 01234567\n") # define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row)) @@ -63,9 +51,9 @@ static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; #endif /* matrix state(1:on, 0:off) */ -static matrix_row_t matrix[MATRIX_ROWS]; +static matrix_row_t raw_matrix[MATRIX_ROWS]; -static matrix_row_t matrix_debouncing[MATRIX_ROWS]; +static matrix_row_t matrix[MATRIX_ROWS]; #if (DIODE_DIRECTION == COL2ROW) @@ -157,70 +145,39 @@ void matrix_init(void) { // initialize matrix state: all keys off for (uint8_t i=0; i < MATRIX_ROWS; i++) { + raw_matrix[i] = 0; matrix[i] = 0; - matrix_debouncing[i] = 0; } + debounce_init(MATRIX_ROWS); matrix_init_quantum(); } uint8_t matrix_scan(void) { + bool changed = false; #if (DIODE_DIRECTION == COL2ROW) - - // Set row, read cols - for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { -# if (DEBOUNCING_DELAY > 0) - bool matrix_changed = read_cols_on_row(matrix_debouncing, current_row); - - if (matrix_changed) { - debouncing = true; - debouncing_time = timer_read(); - } - -# else - read_cols_on_row(matrix, current_row); -# endif - - } - + // Set row, read cols + for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { + changed |= read_cols_on_row(raw_matrix, current_row); + } #elif (DIODE_DIRECTION == ROW2COL) - - // Set col, read rows - for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { -# if (DEBOUNCING_DELAY > 0) - bool matrix_changed = read_rows_on_col(matrix_debouncing, current_col); - if (matrix_changed) { - debouncing = true; - debouncing_time = timer_read(); - } -# else - read_rows_on_col(matrix, current_col); -# endif - - } - + // Set col, read rows + for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { + changed |= read_rows_on_col(raw_matrix, current_col); + } #endif -# if (DEBOUNCING_DELAY > 0) - if (debouncing && (timer_elapsed(debouncing_time) > DEBOUNCING_DELAY)) { - for (uint8_t i = 0; i < MATRIX_ROWS; i++) { - matrix[i] = matrix_debouncing[i]; - } - debouncing = false; - } -# endif + debounce(raw_matrix, matrix, MATRIX_ROWS, changed); - matrix_scan_quantum(); - return 1; + matrix_scan_quantum(); + return 1; } bool matrix_is_modified(void) { -#if (DEBOUNCING_DELAY > 0) - if (debouncing) return false; -#endif + if (debounce_active()) return false; return true; } diff --git a/quantum/split_common/i2c.h b/quantum/split_common/i2c.h index b3cbe8c826..91e8e96f47 100644 --- a/quantum/split_common/i2c.h +++ b/quantum/split_common/i2c.h @@ -1,5 +1,4 @@ -#ifndef I2C_H -#define I2C_H +#pragma once #include @@ -58,5 +57,3 @@ extern unsigned char i2c_readNak(void); extern unsigned char i2c_read(unsigned char ack); #define i2c_read(ack) (ack) ? i2c_readAck() : i2c_readNak(); - -#endif diff --git a/quantum/split_common/matrix.c b/quantum/split_common/matrix.c index 2c37053f88..c3d2857ed5 100644 --- a/quantum/split_common/matrix.c +++ b/quantum/split_common/matrix.c @@ -25,529 +25,304 @@ along with this program. If not, see . #include "matrix.h" #include "split_util.h" #include "config.h" -#include "timer.h" #include "split_flags.h" #include "quantum.h" - -#ifdef BACKLIGHT_ENABLE -# include "backlight.h" - extern backlight_config_t backlight_config; -#endif - -#if defined(USE_I2C) || defined(EH) -# include "i2c.h" -#else // USE_SERIAL -# include "serial.h" -#endif - -#ifndef DEBOUNCING_DELAY -# define DEBOUNCING_DELAY 5 -#endif - -#if (DEBOUNCING_DELAY > 0) - static uint16_t debouncing_time; - static bool debouncing = false; -#endif - -#if defined(USE_I2C) || defined(EH) - -#if (MATRIX_COLS <= 8) -# define print_matrix_header() print("\nr/c 01234567\n") -# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row)) -# define matrix_bitpop(i) bitpop(matrix[i]) -# define ROW_SHIFTER ((uint8_t)1) -#else -# error "Currently only supports 8 COLS" -#endif - -#else // USE_SERIAL +#include "debounce.h" +#include "transport.h" #if (MATRIX_COLS <= 8) -# define print_matrix_header() print("\nr/c 01234567\n") -# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row)) -# define matrix_bitpop(i) bitpop(matrix[i]) -# define ROW_SHIFTER ((uint8_t)1) +# define print_matrix_header() print("\nr/c 01234567\n") +# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row)) +# define matrix_bitpop(i) bitpop(matrix[i]) +# define ROW_SHIFTER ((uint8_t)1) #elif (MATRIX_COLS <= 16) -# define print_matrix_header() print("\nr/c 0123456789ABCDEF\n") -# define print_matrix_row(row) print_bin_reverse16(matrix_get_row(row)) -# define matrix_bitpop(i) bitpop16(matrix[i]) -# define ROW_SHIFTER ((uint16_t)1) +# define print_matrix_header() print("\nr/c 0123456789ABCDEF\n") +# define print_matrix_row(row) print_bin_reverse16(matrix_get_row(row)) +# define matrix_bitpop(i) bitpop16(matrix[i]) +# define ROW_SHIFTER ((uint16_t)1) #elif (MATRIX_COLS <= 32) -# define print_matrix_header() print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n") -# define print_matrix_row(row) print_bin_reverse32(matrix_get_row(row)) -# define matrix_bitpop(i) bitpop32(matrix[i]) -# define ROW_SHIFTER ((uint32_t)1) -#endif - +# define print_matrix_header() print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n") +# define print_matrix_row(row) print_bin_reverse32(matrix_get_row(row)) +# define matrix_bitpop(i) bitpop32(matrix[i]) +# define ROW_SHIFTER ((uint32_t)1) #endif -static matrix_row_t matrix_debouncing[MATRIX_ROWS]; #define ERROR_DISCONNECT_COUNT 5 -#define ROWS_PER_HAND (MATRIX_ROWS/2) - -static uint8_t error_count = 0; +#define ROWS_PER_HAND (MATRIX_ROWS / 2) +#ifdef DIRECT_PINS +static pin_t direct_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; +#else static pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; static pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; +#endif /* matrix state(1:on, 0:off) */ static matrix_row_t matrix[MATRIX_ROWS]; -static matrix_row_t matrix_debouncing[MATRIX_ROWS]; - -#if (DIODE_DIRECTION == COL2ROW) - static void init_cols(void); - static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row); - static void unselect_rows(void); - static void select_row(uint8_t row); - static void unselect_row(uint8_t row); -#elif (DIODE_DIRECTION == ROW2COL) - static void init_rows(void); - static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col); - static void unselect_cols(void); - static void unselect_col(uint8_t col); - static void select_col(uint8_t col); -#endif +static matrix_row_t raw_matrix[ROWS_PER_HAND]; -__attribute__ ((weak)) -void matrix_init_kb(void) { - matrix_init_user(); -} +// row offsets for each hand +uint8_t thisHand, thatHand; -__attribute__ ((weak)) -void matrix_scan_kb(void) { - matrix_scan_user(); -} +// user-defined overridable functions -__attribute__ ((weak)) -void matrix_init_user(void) { -} +__attribute__((weak)) void matrix_init_kb(void) { matrix_init_user(); } -__attribute__ ((weak)) -void matrix_scan_user(void) { -} +__attribute__((weak)) void matrix_scan_kb(void) { matrix_scan_user(); } -__attribute__ ((weak)) -void matrix_slave_scan_user(void) { -} +__attribute__((weak)) void matrix_init_user(void) {} -inline -uint8_t matrix_rows(void) -{ - return MATRIX_ROWS; -} +__attribute__((weak)) void matrix_scan_user(void) {} -inline -uint8_t matrix_cols(void) -{ - return MATRIX_COLS; -} +__attribute__((weak)) void matrix_slave_scan_user(void) {} -void matrix_init(void) -{ - debug_enable = true; - debug_matrix = true; - debug_mouse = true; +// helper functions - // Set pinout for right half if pinout for that half is defined - if (!isLeftHand) { -#ifdef MATRIX_ROW_PINS_RIGHT - const uint8_t row_pins_right[MATRIX_ROWS] = MATRIX_ROW_PINS_RIGHT; - for (uint8_t i = 0; i < MATRIX_ROWS; i++) - row_pins[i] = row_pins_right[i]; -#endif -#ifdef MATRIX_COL_PINS_RIGHT - const uint8_t col_pins_right[MATRIX_COLS] = MATRIX_COL_PINS_RIGHT; - for (uint8_t i = 0; i < MATRIX_COLS; i++) - col_pins[i] = col_pins_right[i]; -#endif - } +inline uint8_t matrix_rows(void) { return MATRIX_ROWS; } - // initialize row and col -#if (DIODE_DIRECTION == COL2ROW) - unselect_rows(); - init_cols(); -#elif (DIODE_DIRECTION == ROW2COL) - unselect_cols(); - init_rows(); -#endif +inline uint8_t matrix_cols(void) { return MATRIX_COLS; } - // initialize matrix state: all keys off - for (uint8_t i=0; i < MATRIX_ROWS; i++) { - matrix[i] = 0; - matrix_debouncing[i] = 0; - } - - matrix_init_quantum(); - +bool matrix_is_modified(void) { + if (debounce_active()) return false; + return true; } -uint8_t _matrix_scan(void) -{ - int offset = isLeftHand ? 0 : (ROWS_PER_HAND); -#if (DIODE_DIRECTION == COL2ROW) - // Set row, read cols - for (uint8_t current_row = 0; current_row < ROWS_PER_HAND; current_row++) { -# if (DEBOUNCING_DELAY > 0) - bool matrix_changed = read_cols_on_row(matrix_debouncing+offset, current_row); - - if (matrix_changed) { - debouncing = true; - debouncing_time = timer_read(); - } - -# else - read_cols_on_row(matrix+offset, current_row); -# endif - - } +inline bool matrix_is_on(uint8_t row, uint8_t col) { return (matrix[row] & ((matrix_row_t)1 << col)); } -#elif (DIODE_DIRECTION == ROW2COL) - // Set col, read rows - for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { -# if (DEBOUNCING_DELAY > 0) - bool matrix_changed = read_rows_on_col(matrix_debouncing+offset, current_col); - if (matrix_changed) { - debouncing = true; - debouncing_time = timer_read(); - } -# else - read_rows_on_col(matrix+offset, current_col); -# endif +inline matrix_row_t matrix_get_row(uint8_t row) { return matrix[row]; } - } -#endif +void matrix_print(void) { + print_matrix_header(); -# if (DEBOUNCING_DELAY > 0) - if (debouncing && (timer_elapsed(debouncing_time) > DEBOUNCING_DELAY)) { - for (uint8_t i = 0; i < ROWS_PER_HAND; i++) { - matrix[i+offset] = matrix_debouncing[i+offset]; - } - debouncing = false; - } -# endif + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + phex(row); + print(": "); + print_matrix_row(row); + print("\n"); + } +} - return 1; +uint8_t matrix_key_count(void) { + uint8_t count = 0; + for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + count += matrix_bitpop(i); + } + return count; } -#if defined(USE_I2C) || defined(EH) - -// Get rows from other half over i2c -int i2c_transaction(void) { - int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; - int err = 0; - - // write backlight info - #ifdef BACKLIGHT_ENABLE - if (BACKLIT_DIRTY) { - err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_WRITE); - if (err) goto i2c_error; - - // Backlight location - err = i2c_master_write(I2C_BACKLIT_START); - if (err) goto i2c_error; - - // Write backlight - i2c_master_write(get_backlight_level()); - - BACKLIT_DIRTY = false; - } - #endif +// matrix code - err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_WRITE); - if (err) goto i2c_error; +#ifdef DIRECT_PINS - // start of matrix stored at I2C_KEYMAP_START - err = i2c_master_write(I2C_KEYMAP_START); - if (err) goto i2c_error; +static void init_pins(void) { + for (int row = 0; row < MATRIX_ROWS; row++) { + for (int col = 0; col < MATRIX_COLS; col++) { + pin_t pin = direct_pins[row][col]; + if (pin != NO_PIN) { + setPinInputHigh(pin); + } + } + } +} - // Start read - err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_READ); - if (err) goto i2c_error; +static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { + matrix_row_t last_row_value = current_matrix[current_row]; + current_matrix[current_row] = 0; - if (!err) { - int i; - for (i = 0; i < ROWS_PER_HAND-1; ++i) { - matrix[slaveOffset+i] = i2c_master_read(I2C_ACK); - } - matrix[slaveOffset+i] = i2c_master_read(I2C_NACK); - i2c_master_stop(); - } else { -i2c_error: // the cable is disconnceted, or something else went wrong - i2c_reset_state(); - return err; + for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { + pin_t pin = direct_pins[current_row][col_index]; + if (pin != NO_PIN) { + current_matrix[current_row] |= readPin(pin) ? 0 : (ROW_SHIFTER << col_index); } - - #ifdef RGBLIGHT_ENABLE - if (RGB_DIRTY) { - err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_WRITE); - if (err) goto i2c_error; - - // RGB Location - err = i2c_master_write(I2C_RGB_START); - if (err) goto i2c_error; - - uint32_t dword = eeconfig_read_rgblight(); - - // Write RGB - err = i2c_master_write_data(&dword, 4); - if (err) goto i2c_error; - - RGB_DIRTY = false; - i2c_master_stop(); - } - #endif + } - return 0; + return (last_row_value != current_matrix[current_row]); } -#else // USE_SERIAL - +#elif (DIODE_DIRECTION == COL2ROW) -typedef struct _Serial_s2m_buffer_t { - // TODO: if MATRIX_COLS > 8 change to uint8_t packed_matrix[] for pack/unpack - matrix_row_t smatrix[ROWS_PER_HAND]; -} Serial_s2m_buffer_t; +static void select_row(uint8_t row) { + writePinLow(row_pins[row]); + setPinOutput(row_pins[row]); +} -volatile Serial_s2m_buffer_t serial_s2m_buffer = {}; -volatile Serial_m2s_buffer_t serial_m2s_buffer = {}; -uint8_t volatile status0 = 0; +static void unselect_row(uint8_t row) { setPinInputHigh(row_pins[row]); } -SSTD_t transactions[] = { - { (uint8_t *)&status0, - sizeof(serial_m2s_buffer), (uint8_t *)&serial_m2s_buffer, - sizeof(serial_s2m_buffer), (uint8_t *)&serial_s2m_buffer +static void unselect_rows(void) { + for (uint8_t x = 0; x < ROWS_PER_HAND; x++) { + setPinInputHigh(row_pins[x]); } -}; +} -void serial_master_init(void) -{ soft_serial_initiator_init(transactions, TID_LIMIT(transactions)); } +static void init_pins(void) { + unselect_rows(); + for (uint8_t x = 0; x < MATRIX_COLS; x++) { + setPinInputHigh(col_pins[x]); + } +} -void serial_slave_init(void) -{ soft_serial_target_init(transactions, TID_LIMIT(transactions)); } +static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { + // Store last value of row prior to reading + matrix_row_t last_row_value = current_matrix[current_row]; -int serial_transaction(void) { - int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; + // Clear data in matrix row + current_matrix[current_row] = 0; - if (soft_serial_transaction()) { - return 1; - } + // Select row and wait for row selecton to stabilize + select_row(current_row); + wait_us(30); - // TODO: if MATRIX_COLS > 8 change to unpack() - for (int i = 0; i < ROWS_PER_HAND; ++i) { - matrix[slaveOffset+i] = serial_s2m_buffer.smatrix[i]; - } - - #if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) - // Code to send RGB over serial goes here (not implemented yet) - #endif - - #ifdef BACKLIGHT_ENABLE - // Write backlight level for slave to read - serial_m2s_buffer.backlight_level = backlight_config.enable ? backlight_config.level : 0; - #endif - - return 0; -} -#endif + // For each col... + for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { + // Populate the matrix row with the state of the col pin + current_matrix[current_row] |= readPin(col_pins[col_index]) ? 0 : (ROW_SHIFTER << col_index); + } -uint8_t matrix_scan(void) -{ - uint8_t ret = _matrix_scan(); + // Unselect row + unselect_row(current_row); -#if defined(USE_I2C) || defined(EH) - if( i2c_transaction() ) { -#else // USE_SERIAL - if( serial_transaction() ) { -#endif + return (last_row_value != current_matrix[current_row]); +} - error_count++; +#elif (DIODE_DIRECTION == ROW2COL) - if (error_count > ERROR_DISCONNECT_COUNT) { - // reset other half if disconnected - int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; - for (int i = 0; i < ROWS_PER_HAND; ++i) { - matrix[slaveOffset+i] = 0; - } - } - } else { - error_count = 0; - } - matrix_scan_quantum(); - return ret; +static void select_col(uint8_t col) { + writePinLow(col_pins[col]); + setPinOutput(col_pins[col]); } -void matrix_slave_scan(void) { - _matrix_scan(); - - int offset = (isLeftHand) ? 0 : ROWS_PER_HAND; +static void unselect_col(uint8_t col) { setPinInputHigh(col_pins[col]); } -#if defined(USE_I2C) || defined(EH) - for (int i = 0; i < ROWS_PER_HAND; ++i) { - i2c_slave_buffer[I2C_KEYMAP_START+i] = matrix[offset+i]; - } -#else // USE_SERIAL - // TODO: if MATRIX_COLS > 8 change to pack() - for (int i = 0; i < ROWS_PER_HAND; ++i) { - serial_s2m_buffer.smatrix[i] = matrix[offset+i]; - } -#endif - matrix_slave_scan_user(); +static void unselect_cols(void) { + for (uint8_t x = 0; x < MATRIX_COLS; x++) { + setPinInputHigh(col_pins[x]); + } } -bool matrix_is_modified(void) -{ - if (debouncing) return false; - return true; +static void init_pins(void) { + unselect_cols(); + for (uint8_t x = 0; x < ROWS_PER_HAND; x++) { + setPinInputHigh(row_pins[x]); + } } -inline -bool matrix_is_on(uint8_t row, uint8_t col) -{ - return (matrix[row] & ((matrix_row_t)1< ERROR_DISCONNECT_COUNT) { + // reset other half if disconnected + for (int i = 0; i < ROWS_PER_HAND; ++i) { + matrix[thatHand + i] = 0; } + } + } else { + error_count = 0; } - // Unselect col - unselect_col(current_col); - - return matrix_changed; -} - -static void select_col(uint8_t col) -{ - writePinLow(col_pins[col]); - setPinOutput(col_pins[col]); -} - -static void unselect_col(uint8_t col) -{ - setPinInputHigh(col_pins[col]); -} + matrix_scan_quantum(); + } else { + transport_slave(matrix + thisHand); + matrix_slave_scan_user(); + } -static void unselect_cols(void) -{ - for(uint8_t x = 0; x < MATRIX_COLS; x++) { - setPinInputHigh(col_pins[x]); - } + return ret; } - -#endif diff --git a/quantum/split_common/matrix.h b/quantum/split_common/matrix.h index b5cb45baed..c2bdd3098c 100644 --- a/quantum/split_common/matrix.h +++ b/quantum/split_common/matrix.h @@ -1,31 +1,3 @@ -#ifndef SPLIT_COMMON_MATRIX_H -#define SPLIT_COMMON_MATRIX_H +#pragma once #include - -#ifdef RGBLIGHT_ENABLE -# include "rgblight.h" -#endif - -typedef struct _Serial_m2s_buffer_t { -#ifdef BACKLIGHT_ENABLE - uint8_t backlight_level; -#endif -#if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) - rgblight_config_t rgblight_config; //not yet use - // - // When MCUs on both sides drive their respective RGB LED chains, - // it is necessary to synchronize, so it is necessary to communicate RGB information. - // In that case, define the RGBLIGHT_SPLIT macro. - // - // Otherwise, if the master side MCU drives both sides RGB LED chains, - // there is no need to communicate. -#endif -} Serial_m2s_buffer_t; - -extern volatile Serial_m2s_buffer_t serial_m2s_buffer; - -void serial_master_init(void); -void serial_slave_init(void); - -#endif diff --git a/quantum/split_common/serial.h b/quantum/split_common/serial.h index b6638b3bde..1c1e640069 100644 --- a/quantum/split_common/serial.h +++ b/quantum/split_common/serial.h @@ -1,5 +1,4 @@ -#ifndef SOFT_SERIAL_H -#define SOFT_SERIAL_H +#pragma once #include @@ -61,5 +60,3 @@ int soft_serial_transaction(int sstd_index); #ifdef SERIAL_USE_MULTI_TRANSACTION int soft_serial_get_and_clean_status(int sstd_index); #endif - -#endif /* SOFT_SERIAL_H */ diff --git a/quantum/split_common/split_flags.h b/quantum/split_common/split_flags.h index f101fff5b5..aaac474a7d 100644 --- a/quantum/split_common/split_flags.h +++ b/quantum/split_common/split_flags.h @@ -1,10 +1,9 @@ -#ifndef SPLIT_FLAGS_H -#define SPLIT_FLAGS_H +#pragma once #include #include -/** +/** * Global Flags **/ @@ -14,7 +13,3 @@ extern volatile bool RGB_DIRTY; //Backlight Stuff extern volatile bool BACKLIT_DIRTY; - - - -#endif \ No newline at end of file diff --git a/quantum/split_common/split_util.c b/quantum/split_common/split_util.c index e41b6f6386..5095cb8fdc 100644 --- a/quantum/split_common/split_util.c +++ b/quantum/split_common/split_util.c @@ -4,142 +4,84 @@ #include "config.h" #include "timer.h" #include "split_flags.h" +#include "transport.h" #include "quantum.h" #ifdef EE_HANDS # include "tmk_core/common/eeprom.h" -#endif - -#ifdef BACKLIGHT_ENABLE -# include "backlight.h" -#endif - -#if defined(USE_I2C) || defined(EH) -# include "i2c.h" +# include "eeconfig.h" #endif volatile bool isLeftHand = true; -volatile uint8_t setTries = 0; - -static void setup_handedness(void) { +__attribute__((weak)) +bool is_keyboard_left(void) { #ifdef SPLIT_HAND_PIN // Test pin SPLIT_HAND_PIN for High/Low, if low it's right hand setPinInput(SPLIT_HAND_PIN); - isLeftHand = readPin(SPLIT_HAND_PIN); + return readPin(SPLIT_HAND_PIN); #else #ifdef EE_HANDS - isLeftHand = eeprom_read_byte(EECONFIG_HANDEDNESS); + return eeprom_read_byte(EECONFIG_HANDEDNESS); #else #ifdef MASTER_RIGHT - isLeftHand = !has_usb(); + return !is_keyboard_master(); #else - isLeftHand = has_usb(); + return is_keyboard_master(); #endif #endif #endif } -static void keyboard_master_setup(void) { -#if defined(USE_I2C) || defined(EH) - i2c_master_init(); - #ifdef SSD1306OLED - matrix_master_OLED_init (); - #endif -#else - serial_master_init(); -#endif +bool is_keyboard_master(void) +{ +#ifdef __AVR__ + static enum { UNKNOWN, MASTER, SLAVE } usbstate = UNKNOWN; - // For master the Backlight info needs to be sent on startup - // Otherwise the salve won't start with the proper info until an update - BACKLIT_DIRTY = true; -} + // only check once, as this is called often + if (usbstate == UNKNOWN) + { + USBCON |= (1 << OTGPADE); // enables VBUS pad + wait_us(5); -static void keyboard_slave_setup(void) { - timer_init(); -#if defined(USE_I2C) || defined(EH) - i2c_slave_init(SLAVE_I2C_ADDRESS); + usbstate = (USBSTA & (1 << VBUS)) ? MASTER : SLAVE; // checks state of VBUS + } + + return (usbstate == MASTER); #else - serial_slave_init(); + return true; #endif } -bool has_usb(void) { - USBCON |= (1 << OTGPADE); //enables VBUS pad - _delay_us(5); - return (USBSTA & (1< #include #include #include -#include "eeconfig.h" - -#define SLAVE_I2C_ADDRESS 0x32 extern volatile bool isLeftHand; -// slave version of matix scan, defined in matrix.c -void matrix_slave_scan(void); - -void split_keyboard_setup(void); -bool has_usb(void); -void keyboard_slave_loop(void); - void matrix_master_OLED_init (void); - -#endif diff --git a/quantum/split_common/transport.c b/quantum/split_common/transport.c new file mode 100644 index 0000000000..95738530ec --- /dev/null +++ b/quantum/split_common/transport.c @@ -0,0 +1,224 @@ + +#include "config.h" +#include "matrix.h" +#include "quantum.h" + +#define ROWS_PER_HAND (MATRIX_ROWS/2) + +#ifdef RGBLIGHT_ENABLE +# include "rgblight.h" +#endif + +#ifdef BACKLIGHT_ENABLE +# include "backlight.h" + extern backlight_config_t backlight_config; +#endif + +#if defined(USE_I2C) || defined(EH) + +#include "i2c.h" + +#ifndef SLAVE_I2C_ADDRESS +# define SLAVE_I2C_ADDRESS 0x32 +#endif + +#if (MATRIX_COLS > 8) +# error "Currently only supports 8 COLS" +#endif + +// Get rows from other half over i2c +bool transport_master(matrix_row_t matrix[]) { + int err = 0; + + // write backlight info +#ifdef BACKLIGHT_ENABLE + if (BACKLIT_DIRTY) { + err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_WRITE); + if (err) { goto i2c_error; } + + // Backlight location + err = i2c_master_write(I2C_BACKLIT_START); + if (err) { goto i2c_error; } + + // Write backlight + i2c_master_write(get_backlight_level()); + + BACKLIT_DIRTY = false; + } +#endif + + err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_WRITE); + if (err) { goto i2c_error; } + + // start of matrix stored at I2C_KEYMAP_START + err = i2c_master_write(I2C_KEYMAP_START); + if (err) { goto i2c_error; } + + // Start read + err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_READ); + if (err) { goto i2c_error; } + + if (!err) { + int i; + for (i = 0; i < ROWS_PER_HAND-1; ++i) { + matrix[i] = i2c_master_read(I2C_ACK); + } + matrix[i] = i2c_master_read(I2C_NACK); + i2c_master_stop(); + } else { +i2c_error: // the cable is disconnceted, or something else went wrong + i2c_reset_state(); + return false; + } + +#ifdef RGBLIGHT_ENABLE + if (RGB_DIRTY) { + err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_WRITE); + if (err) { goto i2c_error; } + + // RGB Location + err = i2c_master_write(I2C_RGB_START); + if (err) { goto i2c_error; } + + uint32_t dword = eeconfig_read_rgblight(); + + // Write RGB + err = i2c_master_write_data(&dword, 4); + if (err) { goto i2c_error; } + + RGB_DIRTY = false; + i2c_master_stop(); + } +#endif + + return true; +} + +void transport_slave(matrix_row_t matrix[]) { + + for (int i = 0; i < ROWS_PER_HAND; ++i) + { + i2c_slave_buffer[I2C_KEYMAP_START + i] = matrix[i]; + } + // Read Backlight Info + #ifdef BACKLIGHT_ENABLE + if (BACKLIT_DIRTY) + { + backlight_set(i2c_slave_buffer[I2C_BACKLIT_START]); + BACKLIT_DIRTY = false; + } + #endif + #ifdef RGBLIGHT_ENABLE + if (RGB_DIRTY) + { + // Disable interupts (RGB data is big) + cli(); + // Create new DWORD for RGB data + uint32_t dword; + + // Fill the new DWORD with the data that was sent over + uint8_t * dword_dat = (uint8_t *)(&dword); + for (int i = 0; i < 4; i++) + { + dword_dat[i] = i2c_slave_buffer[I2C_RGB_START + i]; + } + + // Update the RGB now with the new data and set RGB_DIRTY to false + rgblight_update_dword(dword); + RGB_DIRTY = false; + // Re-enable interupts now that RGB is set + sei(); + } + #endif +} + +void transport_master_init(void) { + i2c_master_init(); +} + +void transport_slave_init(void) { + i2c_slave_init(SLAVE_I2C_ADDRESS); +} + +#else // USE_SERIAL + +#include "serial.h" + +typedef struct _Serial_s2m_buffer_t { + // TODO: if MATRIX_COLS > 8 change to uint8_t packed_matrix[] for pack/unpack + matrix_row_t smatrix[ROWS_PER_HAND]; +} Serial_s2m_buffer_t; + +typedef struct _Serial_m2s_buffer_t { +#ifdef BACKLIGHT_ENABLE + uint8_t backlight_level; +#endif +#if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) + rgblight_config_t rgblight_config; //not yet use + // + // When MCUs on both sides drive their respective RGB LED chains, + // it is necessary to synchronize, so it is necessary to communicate RGB information. + // In that case, define the RGBLIGHT_SPLIT macro. + // + // Otherwise, if the master side MCU drives both sides RGB LED chains, + // there is no need to communicate. +#endif +} Serial_m2s_buffer_t; + +volatile Serial_s2m_buffer_t serial_s2m_buffer = {}; +volatile Serial_m2s_buffer_t serial_m2s_buffer = {}; +uint8_t volatile status0 = 0; + +SSTD_t transactions[] = { + { (uint8_t *)&status0, + sizeof(serial_m2s_buffer), (uint8_t *)&serial_m2s_buffer, + sizeof(serial_s2m_buffer), (uint8_t *)&serial_s2m_buffer + } +}; + +void transport_master_init(void) +{ soft_serial_initiator_init(transactions, TID_LIMIT(transactions)); } + +void transport_slave_init(void) +{ soft_serial_target_init(transactions, TID_LIMIT(transactions)); } + +bool transport_master(matrix_row_t matrix[]) { + + if (soft_serial_transaction()) { + return false; + } + + // TODO: if MATRIX_COLS > 8 change to unpack() + for (int i = 0; i < ROWS_PER_HAND; ++i) { + matrix[i] = serial_s2m_buffer.smatrix[i]; + } + + #if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) + // Code to send RGB over serial goes here (not implemented yet) + #endif + + #ifdef BACKLIGHT_ENABLE + // Write backlight level for slave to read + serial_m2s_buffer.backlight_level = backlight_config.enable ? backlight_config.level : 0; + #endif + + return true; +} + +void transport_slave(matrix_row_t matrix[]) { + + // TODO: if MATRIX_COLS > 8 change to pack() + for (int i = 0; i < ROWS_PER_HAND; ++i) + { + serial_s2m_buffer.smatrix[i] = matrix[i]; + } + #ifdef BACKLIGHT_ENABLE + backlight_set(serial_m2s_buffer.backlight_level); + #endif + #if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) + // Add serial implementation for RGB here + #endif + +} + +#endif diff --git a/quantum/split_common/transport.h b/quantum/split_common/transport.h new file mode 100644 index 0000000000..ccce57e444 --- /dev/null +++ b/quantum/split_common/transport.h @@ -0,0 +1,10 @@ +#pragma once + +#include + +void transport_master_init(void); +void transport_slave_init(void); + +// returns false if valid data not received from slave +bool transport_master(matrix_row_t matrix[]); +void transport_slave(matrix_row_t matrix[]); diff --git a/tmk_core/common/keyboard.h b/tmk_core/common/keyboard.h index 71e594a890..ea2f336e9d 100644 --- a/tmk_core/common/keyboard.h +++ b/tmk_core/common/keyboard.h @@ -67,6 +67,8 @@ void keyboard_init(void); void keyboard_task(void); /* it runs when host LED status is updated */ void keyboard_set_leds(uint8_t leds); +/* it runs whenever code has to behave differently on a slave */ +bool is_keyboard_master(void); #ifdef __cplusplus } -- cgit v1.2.3 From 77399bfe515f4dde5cb6c08dbc466ac1aa77cda3 Mon Sep 17 00:00:00 2001 From: Jeremy Bernhardt Date: Thu, 17 Jan 2019 19:23:01 -0600 Subject: MacOS Brightness Alias (#4836) * Added aliases for OSX brightness * Updated docs for alises * Moved aliases, added docs to Brightness section * Update docs/keycodes.md Co-Authored-By: germ * Update docs/keycodes.md Co-Authored-By: germ * Update keycode.h * Update keycode.h * Update keycodes.md * Update docs/keycodes.md Co-Authored-By: germ --- docs/keycodes.md | 8 ++++---- tmk_core/common/keycode.h | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'tmk_core/common') diff --git a/docs/keycodes.md b/docs/keycodes.md index 6f28bbb97a..a98d1096be 100644 --- a/docs/keycodes.md +++ b/docs/keycodes.md @@ -77,8 +77,8 @@ This is a reference only. Each group of keys links to the page documenting their |`KC_F11` | |F11 | |`KC_F12` | |F12 | |`KC_PSCREEN` |`KC_PSCR` |Print Screen | -|`KC_SCROLLLOCK` |`KC_SLCK` |Scroll Lock | -|`KC_PAUSE` |`KC_PAUS`, `KC_BRK` |Pause | +|`KC_SCROLLLOCK` |`KC_SLCK`, `KC_BRMD`|Scroll Lock, Brightness Down (macOS) | +|`KC_PAUSE` |`KC_PAUS`, `KC_BRK`, `KC_BRMU`|Pause, Brightness Up (macOS) | |`KC_INSERT` |`KC_INS` |Insert | |`KC_HOME` | |Home | |`KC_PGUP` | |Page Up | @@ -203,8 +203,8 @@ This is a reference only. Each group of keys links to the page documenting their |`KC_WWW_FAVORITES` |`KC_WFAV` |Browser Favorites (Windows) | |`KC_MEDIA_FAST_FORWARD`|`KC_MFFD` |Next Track (macOS) | |`KC_MEDIA_REWIND` |`KC_MRWD` |Previous Track (macOS) | -|`KC_BRIGHTNESS_UP` |`KC_BRIU` |Brightness Up | -|`KC_BRIGHTNESS_DOWN` |`KC_BRID` |Brightness Down | +|`KC_BRIGHTNESS_UP` |`KC_BRIU` |Brightness Up (macOS: use `KC_BRMU`) | +|`KC_BRIGHTNESS_DOWN` |`KC_BRID` |Brightness Down (macOS: use `KC_BRMD`) | ## [Quantum Keycodes](quantum_keycodes.md#qmk-keycodes) diff --git a/tmk_core/common/keycode.h b/tmk_core/common/keycode.h index ac3edbd215..3e312b8292 100644 --- a/tmk_core/common/keycode.h +++ b/tmk_core/common/keycode.h @@ -174,6 +174,10 @@ along with this program. If not, see . #define KC_BRIU KC_BRIGHTNESS_UP #define KC_BRID KC_BRIGHTNESS_DOWN +/* System Specific */ +#define KC_BRMU KC_SCROLLLOCK +#define KC_BRMD KC_PAUSE + /* Mouse Keys */ #define KC_MS_U KC_MS_UP #define KC_MS_D KC_MS_DOWN -- cgit v1.2.3 From 94ba2e5a9f9c01b015b447554bfee99f5bcee032 Mon Sep 17 00:00:00 2001 From: DidierLoiseau Date: Fri, 18 Jan 2019 02:28:33 +0100 Subject: Defined IS_(HOST_)LED_ON/OFF() and improved LED documentation (#4853) * Defined IS_(HOST_)LED_ON/OFF() and improved LED documentation * Update docs/custom_quantum_functions.md Co-Authored-By: DidierLoiseau * Update docs/custom_quantum_functions.md Co-Authored-By: DidierLoiseau * Integrated @drashna and @fauxpark's PR comments - changed all plurals of "LED" to "LEDs" in the file - rewording of the note about host_keyboard_leds() vs. led_set_user() * Update docs/custom_quantum_functions.md Co-Authored-By: DidierLoiseau --- docs/custom_quantum_functions.md | 54 ++++++++++++++++++++++++++++++++++------ tmk_core/common/host.h | 6 +++++ 2 files changed, 52 insertions(+), 8 deletions(-) (limited to 'tmk_core/common') diff --git a/docs/custom_quantum_functions.md b/docs/custom_quantum_functions.md index 5b95450f26..3397bf2d4f 100644 --- a/docs/custom_quantum_functions.md +++ b/docs/custom_quantum_functions.md @@ -90,7 +90,7 @@ keyrecord_t record { # LED Control -This allows you to control the 5 LED's defined as part of the USB Keyboard spec. It will be called when the state of one of those 5 LEDs changes. +QMK provides methods to read the 5 LEDs defined as part of the HID spec: * `USB_LED_NUM_LOCK` * `USB_LED_CAPS_LOCK` @@ -98,31 +98,46 @@ This allows you to control the 5 LED's defined as part of the USB Keyboard spec. * `USB_LED_COMPOSE` * `USB_LED_KANA` +These five constants correspond to the positional bits of the host LED state. +There are two ways to get the host LED state: + +* by implementing `led_set_user()` +* by calling `host_keyboard_leds()` + +## `led_set_user()` + +This function will be called when the state of one of those 5 LEDs changes. +It receives the LED state as parameter. +Use the `IS_LED_ON(USB_LED, LED_NAME)` and `IS_LED_OFF(USB_LED, LED_NAME)` +macros to check the LED status. + +!> `host_keyboard_leds()` may already reflect a new value before `led_set_user()` is called. + ### Example `led_set_user()` Implementation ```c void led_set_user(uint8_t usb_led) { - if (usb_led & (1< Date: Fri, 18 Jan 2019 12:54:40 +0900 Subject: Flip definitions of macOS brightness alias Before: KC_BRMU - Brightness Down KC_BRMD - Brightness Up After: KC_BRMU - Brightness Up KC_BRMD - Brightness Down --- tmk_core/common/keycode.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tmk_core/common') diff --git a/tmk_core/common/keycode.h b/tmk_core/common/keycode.h index 3e312b8292..fd975dd6ad 100644 --- a/tmk_core/common/keycode.h +++ b/tmk_core/common/keycode.h @@ -175,8 +175,8 @@ along with this program. If not, see . #define KC_BRID KC_BRIGHTNESS_DOWN /* System Specific */ -#define KC_BRMU KC_SCROLLLOCK -#define KC_BRMD KC_PAUSE +#define KC_BRMU KC_PAUSE +#define KC_BRMD KC_SCROLLLOCK /* Mouse Keys */ #define KC_MS_U KC_MS_UP -- cgit v1.2.3 From 0f8431a57f4b1ce50528e4c1689e810ba9554e17 Mon Sep 17 00:00:00 2001 From: Konstantin Đorđević Date: Mon, 21 Jan 2019 05:16:36 +0100 Subject: Tidy up IS_{,HOST_}LED_{ON,OFF} macros (#4894) * Tidy up IS_{,HOST_}LED_{ON,OFF} macros * Tweak LED control docs --- docs/custom_quantum_functions.md | 27 +++++++++------------------ tmk_core/common/host.h | 17 ++++++----------- 2 files changed, 15 insertions(+), 29 deletions(-) (limited to 'tmk_core/common') diff --git a/docs/custom_quantum_functions.md b/docs/custom_quantum_functions.md index 3397bf2d4f..d44786e2d5 100644 --- a/docs/custom_quantum_functions.md +++ b/docs/custom_quantum_functions.md @@ -106,10 +106,8 @@ There are two ways to get the host LED state: ## `led_set_user()` -This function will be called when the state of one of those 5 LEDs changes. -It receives the LED state as parameter. -Use the `IS_LED_ON(USB_LED, LED_NAME)` and `IS_LED_OFF(USB_LED, LED_NAME)` -macros to check the LED status. +This function will be called when the state of one of those 5 LEDs changes. It receives the LED state as a parameter. +Use the `IS_LED_ON(usb_led, led_name)` and `IS_LED_OFF(usb_led, led_name)` macros to check the LED status. !> `host_keyboard_leds()` may already reflect a new value before `led_set_user()` is called. @@ -152,27 +150,20 @@ void led_set_user(uint8_t usb_led) { ## `host_keyboard_leds()` -Call this function to get the last received LED state. -This is useful for reading the LED state outside `led_set_*`, e.g. in [`matrix_scan_user()`](#matrix-scanning-code). +Call this function to get the last received LED state. This is useful for reading the LED state outside `led_set_*`, e.g. in [`matrix_scan_user()`](#matrix-scanning-code). +For convenience, you can use the `IS_HOST_LED_ON(led_name)` and `IS_HOST_LED_OFF(led_name)` macros instead of calling and checking `host_keyboard_leds()` directly. -For convenience, you can use the `IS_HOST_LED_ON(LED_NAME)` and `IS_HOST_LED_OFF(LED_NAME)` macros instead of calling `host_keyboard_leds()` directly. - -## Setting physical LED state +## Setting Physical LED State Some keyboard implementations provide convenience methods for setting the state of the physical LEDs. -### Ergodox and Ergodox EZ +### Ergodox Boards -The Ergodox EZ implementation provides `ergodox_right_led_``1`/`2`/`3_on`/`off()` -to turn individual LEDs on and off, as well as -`ergodox_right_led_on`/`off(uint8_t led)` -to turn them on and off by their number. +The Ergodox implementations provide `ergodox_right_led_1`/`2`/`3_on`/`off()` to turn individual LEDs on or off, as well as `ergodox_right_led_on`/`off(uint8_t led)` to turn them on or off by their index. -In addition, it is possible to specify the brightness level with `ergodox_led_all_set(uint8_t n)`, -for individual LEDs with `ergodox_right_led_1`/`2`/`3_set(uint8_t n)` -or by their number using `ergodox_right_led_set(uint8_t led, uint8_t n)`. +In addition, it is possible to specify the brightness level of all LEDs with `ergodox_led_all_set(uint8_t n)`; of individual LEDs with `ergodox_right_led_1`/`2`/`3_set(uint8_t n)`; or by index with `ergodox_right_led_set(uint8_t led, uint8_t n)`. -It defines `LED_BRIGHTNESS_LO` for the lowest brightness and `LED_BRIGHTNESS_HI` for the highest brightness, which is also the default. +Ergodox boards also define `LED_BRIGHTNESS_LO` for the lowest brightness and `LED_BRIGHTNESS_HI` for the highest brightness (which is the default). # Matrix Initialization Code diff --git a/tmk_core/common/host.h b/tmk_core/common/host.h index e70bb68533..3d172eed66 100644 --- a/tmk_core/common/host.h +++ b/tmk_core/common/host.h @@ -15,14 +15,18 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#ifndef HOST_H -#define HOST_H +#pragma once #include #include #include "report.h" #include "host_driver.h" +#define IS_LED_ON(leds, led_name) ( (leds) & (1 << (led_name))) +#define IS_LED_OFF(leds, led_name) (~(leds) & (1 << (led_name))) + +#define IS_HOST_LED_ON(led_name) IS_LED_ON(host_keyboard_leds(), led_name) +#define IS_HOST_LED_OFF(led_name) IS_LED_OFF(host_keyboard_leds(), led_name) #ifdef __cplusplus extern "C" { @@ -31,7 +35,6 @@ extern "C" { extern uint8_t keyboard_idle; extern uint8_t keyboard_protocol; - /* host driver */ void host_set_driver(host_driver_t *driver); host_driver_t *host_get_driver(void); @@ -46,14 +49,6 @@ void host_consumer_send(uint16_t data); uint16_t host_last_system_report(void); uint16_t host_last_consumer_report(void); -#define IS_LED_ON(USB_LED, LED_NAME) ((USB_LED) & (1 << (LED_NAME))) -#define IS_LED_OFF(USB_LED, LED_NAME) (~(USB_LED) & (1 << (LED_NAME))) - -#define IS_HOST_LED_ON(LED_NAME) IS_LED_ON(host_keyboard_leds(), (LED_NAME)) -#define IS_HOST_LED_OFF(LED_NAME) IS_LED_OFF(host_keyboard_leds(), (LED_NAME)) - #ifdef __cplusplus } #endif - -#endif -- cgit v1.2.3 From 8e47f64888b4b9edfcf6038d2dac0ec7d95623c1 Mon Sep 17 00:00:00 2001 From: lambda_sakura Date: Wed, 25 Apr 2018 19:14:27 +0900 Subject: Add support for RETRO_TAPPING to LT(layer, kc) --- tmk_core/common/action.c | 10 +++++++++- tmk_core/common/action.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'tmk_core/common') diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c index b99c2acaa7..ec8d6ed7b9 100644 --- a/tmk_core/common/action.c +++ b/tmk_core/common/action.c @@ -653,7 +653,7 @@ void process_action(keyrecord_t *record, action_t action) #ifndef NO_ACTION_TAPPING #ifdef RETRO_TAPPING - if (!is_tap_key(record->event.key)) { + if (!is_tap_action(action)) { retro_tapping_counter = 0; } else { if (event.pressed) { @@ -929,7 +929,15 @@ void clear_keyboard_but_mods_and_keys() bool is_tap_key(keypos_t key) { action_t action = layer_switch_get_action(key); + return is_tap_action(action); +} +/** \brief Utilities for actions. (FIXME: Needs better description) + * + * FIXME: Needs documentation. + */ +bool is_tap_action(action_t action) +{ switch (action.kind.id) { case ACT_LMODS_TAP: case ACT_RMODS_TAP: diff --git a/tmk_core/common/action.h b/tmk_core/common/action.h index 8e47e5339e..799e3bb0ef 100644 --- a/tmk_core/common/action.h +++ b/tmk_core/common/action.h @@ -97,6 +97,7 @@ void clear_keyboard_but_mods(void); void clear_keyboard_but_mods_and_keys(void); void layer_switch(uint8_t new_layer); bool is_tap_key(keypos_t key); +bool is_tap_action(action_t action); #ifndef NO_ACTION_TAPPING void process_record_tap_hint(keyrecord_t *record); -- cgit v1.2.3 From b4161136167556afd9a6073aa476846b90e3bfab Mon Sep 17 00:00:00 2001 From: Shihpin Tseng Date: Sat, 26 Jan 2019 04:09:53 +0800 Subject: Fix oneshot_time wrong type (#3696) * Fix oneshot_time wrong type * Fix oneshot_time_layer wrong type --- tmk_core/common/action_util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tmk_core/common') diff --git a/tmk_core/common/action_util.c b/tmk_core/common/action_util.c index afd4ae8b25..58401ace55 100644 --- a/tmk_core/common/action_util.c +++ b/tmk_core/common/action_util.c @@ -54,7 +54,7 @@ int8_t get_oneshot_locked_mods(void) { return oneshot_locked_mods; } void set_oneshot_locked_mods(int8_t mods) { oneshot_locked_mods = mods; } void clear_oneshot_locked_mods(void) { oneshot_locked_mods = 0; } #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) -static int16_t oneshot_time = 0; +static uint16_t oneshot_time = 0; bool has_oneshot_mods_timed_out(void) { return TIMER_DIFF_16(timer_read(), oneshot_time) >= ONESHOT_TIMEOUT; } @@ -79,7 +79,7 @@ inline uint8_t get_oneshot_layer(void) { return oneshot_layer_data >> 3; } inline uint8_t get_oneshot_layer_state(void) { return oneshot_layer_data & 0b111; } #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) -static int16_t oneshot_layer_time = 0; +static uint16_t oneshot_layer_time = 0; inline bool has_oneshot_layer_timed_out() { return TIMER_DIFF_16(timer_read(), oneshot_layer_time) >= ONESHOT_TIMEOUT && !(get_oneshot_layer_state() & ONESHOT_TOGGLED); -- cgit v1.2.3 From 2f009d7461a486cfa7307ef0cecd67d1abe570b3 Mon Sep 17 00:00:00 2001 From: Konstantin Đorđević Date: Fri, 25 Jan 2019 22:02:38 +0100 Subject: Add MOD_MASK_* macros to core code (#4337) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add MOD_MASK_* macros to core code * MOD_MASK_ALL → MOD_MASK_CSAG --- tmk_core/common/keycode.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tmk_core/common') diff --git a/tmk_core/common/keycode.h b/tmk_core/common/keycode.h index fd975dd6ad..d5904276ee 100644 --- a/tmk_core/common/keycode.h +++ b/tmk_core/common/keycode.h @@ -46,6 +46,22 @@ along with this program. If not, see . #define MOD_BIT(code) (1 << MOD_INDEX(code)) #define MOD_INDEX(code) ((code) & 0x07) +#define MOD_MASK_CTRL (MOD_BIT(KC_LCTRL) | MOD_BIT(KC_RCTRL)) +#define MOD_MASK_SHIFT (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) +#define MOD_MASK_ALT (MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT)) +#define MOD_MASK_GUI (MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI)) +#define MOD_MASK_CS (MOD_MASK_CTRL | MOD_MASK_SHIFT) +#define MOD_MASK_CA (MOD_MASK_CTRL | MOD_MASK_ALT) +#define MOD_MASK_CG (MOD_MASK_CTRL | MOD_MASK_GUI) +#define MOD_MASK_SA (MOD_MASK_SHIFT | MOD_MASK_ALT) +#define MOD_MASK_SG (MOD_MASK_SHIFT | MOD_MASK_GUI) +#define MOD_MASK_AG (MOD_MASK_ALT | MOD_MASK_GUI) +#define MOD_MASK_CSA (MOD_MASK_CTRL | MOD_MASK_SHIFT | MOD_MASK_ALT) +#define MOD_MASK_CSG (MOD_MASK_CTRL | MOD_MASK_SHIFT | MOD_MASK_GUI) +#define MOD_MASK_CAG (MOD_MASK_CTRL | MOD_MASK_ALT | MOD_MASK_GUI) +#define MOD_MASK_SAG (MOD_MASK_SHIFT | MOD_MASK_ALT | MOD_MASK_GUI) +#define MOD_MASK_CSAG (MOD_MASK_CTRL | MOD_MASK_SHIFT | MOD_MASK_ALT | MOD_MASK_GUI) + #define FN_BIT(code) (1 << FN_INDEX(code)) #define FN_INDEX(code) ((code) - KC_FN0) #define FN_MIN KC_FN0 -- cgit v1.2.3