diff options
| author | Naoki Katahira <kata0510.com@gmail.com> | 2019-01-06 02:30:48 +0900 |
|---|---|---|
| committer | Drashna Jaelre <drashna@live.com> | 2019-01-05 09:30:48 -0800 |
| commit | ea47be936b41a31e2644ad3403d91010916683ce (patch) | |
| tree | c8db4d32373542cd1236a4d537fa45a00ed7b6fb | |
| parent | 5b5f452bf9feae121ec5c2f3e9d5d993fcb73f92 (diff) | |
| download | qmk_firmware-ea47be936b41a31e2644ad3403d91010916683ce.tar.gz qmk_firmware-ea47be936b41a31e2644ad3403d91010916683ce.zip | |
Keyboard: Lily58 update serial.c and add OLED (#4715)
* update serial.c and add OLED
* update readme
* keymap fix
* keymap fix2
36 files changed, 1972 insertions, 215 deletions
diff --git a/keyboards/lily58/config.h b/keyboards/lily58/config.h index db4844c91..b88ec06bf 100644 --- a/keyboards/lily58/config.h +++ b/keyboards/lily58/config.h | |||
| @@ -18,4 +18,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 18 | 18 | ||
| 19 | #pragma once | 19 | #pragma once |
| 20 | 20 | ||
| 21 | #include "serial_config.h" \ No newline at end of file | 21 | #include "config_common.h" |
| 22 | #include <serial_config.h> | ||
| 23 | |||
| 24 | #define USE_I2C | ||
| 25 | #define USE_SERIAL | ||
| 26 | |||
| 27 | #ifdef USE_Link_Time_Optimization | ||
| 28 | // LTO has issues with macros (action_get_macro) and "functions" (fn_actions), | ||
| 29 | // so just disable them | ||
| 30 | #define NO_ACTION_MACRO | ||
| 31 | #define NO_ACTION_FUNCTION | ||
| 32 | |||
| 33 | #define DISABLE_LEADER | ||
| 34 | #endif // USE_Link_Time_Optimization \ No newline at end of file | ||
diff --git a/keyboards/lily58/i2c.c b/keyboards/lily58/i2c.c index 084c890c4..4bee5c639 100644..100755 --- a/keyboards/lily58/i2c.c +++ b/keyboards/lily58/i2c.c | |||
| @@ -34,7 +34,7 @@ void i2c_delay(void) { | |||
| 34 | // _delay_us(100); | 34 | // _delay_us(100); |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | // Setup twi to run at 100kHz | 37 | // Setup twi to run at 100kHz or 400kHz (see ./i2c.h SCL_CLOCK) |
| 38 | void i2c_master_init(void) { | 38 | void i2c_master_init(void) { |
| 39 | // no prescaler | 39 | // no prescaler |
| 40 | TWSR = 0; | 40 | TWSR = 0; |
diff --git a/keyboards/lily58/i2c.h b/keyboards/lily58/i2c.h index c15b6bc50..710662c7a 100644..100755 --- a/keyboards/lily58/i2c.h +++ b/keyboards/lily58/i2c.h | |||
| @@ -1,5 +1,4 @@ | |||
| 1 | #ifndef I2C_H | 1 | #pragma once |
| 2 | #define I2C_H | ||
| 3 | 2 | ||
| 4 | #include <stdint.h> | 3 | #include <stdint.h> |
| 5 | 4 | ||
| @@ -15,7 +14,7 @@ | |||
| 15 | 14 | ||
| 16 | #define SLAVE_BUFFER_SIZE 0x10 | 15 | #define SLAVE_BUFFER_SIZE 0x10 |
| 17 | 16 | ||
| 18 | // i2c SCL clock frequency | 17 | // i2c SCL clock frequency 400kHz |
| 19 | #define SCL_CLOCK 400000L | 18 | #define SCL_CLOCK 400000L |
| 20 | 19 | ||
| 21 | extern volatile uint8_t i2c_slave_buffer[SLAVE_BUFFER_SIZE]; | 20 | extern volatile uint8_t i2c_slave_buffer[SLAVE_BUFFER_SIZE]; |
| @@ -45,5 +44,3 @@ extern unsigned char i2c_readNak(void); | |||
| 45 | extern unsigned char i2c_read(unsigned char ack); | 44 | extern unsigned char i2c_read(unsigned char ack); |
| 46 | 45 | ||
| 47 | #define i2c_read(ack) (ack) ? i2c_readAck() : i2c_readNak(); | 46 | #define i2c_read(ack) (ack) ? i2c_readAck() : i2c_readNak(); |
| 48 | |||
| 49 | #endif | ||
diff --git a/keyboards/lily58/keymaps/default/config.h b/keyboards/lily58/keymaps/default/config.h index fd0978559..58bbdc5e9 100644 --- a/keyboards/lily58/keymaps/default/config.h +++ b/keyboards/lily58/keymaps/default/config.h | |||
| @@ -17,12 +17,10 @@ GNU General Public License for more details. | |||
| 17 | You should have received a copy of the GNU General Public License | 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ | 19 | */ |
| 20 | #pragma once | ||
| 21 | 20 | ||
| 22 | /* Use I2C or Serial, not both */ | 21 | #pragma once |
| 23 | 22 | ||
| 24 | #define USE_SERIAL | 23 | //#define USE_MATRIX_I2C |
| 25 | // #define USE_I2C | ||
| 26 | 24 | ||
| 27 | /* Select hand configuration */ | 25 | /* Select hand configuration */ |
| 28 | 26 | ||
| @@ -30,6 +28,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 30 | // #define MASTER_RIGHT | 28 | // #define MASTER_RIGHT |
| 31 | // #define EE_HANDS | 29 | // #define EE_HANDS |
| 32 | 30 | ||
| 31 | #define SSD1306OLED | ||
| 32 | |||
| 33 | #define USE_SERIAL_PD2 | ||
| 34 | |||
| 35 | #define TAPPING_FORCE_HOLD | ||
| 36 | #define TAPPING_TERM 100 | ||
| 37 | |||
| 38 | #undef RGBLED_NUM | ||
| 39 | #define RGBLIGHT_ANIMATIONS | ||
| 40 | #define RGBLED_NUM 27 | ||
| 41 | #define RGBLIGHT_LIMIT_VAL 120 | ||
| 42 | #define RGBLIGHT_HUE_STEP 10 | ||
| 43 | #define RGBLIGHT_SAT_STEP 17 | ||
| 44 | #define RGBLIGHT_VAL_STEP 17 | ||
| 45 | |||
| 33 | // Underglow | 46 | // Underglow |
| 34 | /* | 47 | /* |
| 35 | #undef RGBLED_NUM | 48 | #undef RGBLED_NUM |
diff --git a/keyboards/lily58/keymaps/default/keymap.c b/keyboards/lily58/keymaps/default/keymap.c index 8d7705812..5ff5dc318 100644 --- a/keyboards/lily58/keymaps/default/keymap.c +++ b/keyboards/lily58/keymaps/default/keymap.c | |||
| @@ -1,7 +1,23 @@ | |||
| 1 | #include QMK_KEYBOARD_H | 1 | #include QMK_KEYBOARD_H |
| 2 | 2 | ||
| 3 | #ifdef PROTOCOL_LUFA | ||
| 4 | #include "lufa.h" | ||
| 5 | #include "split_util.h" | ||
| 6 | #endif | ||
| 7 | #ifdef SSD1306OLED | ||
| 8 | #include "ssd1306.h" | ||
| 9 | #endif | ||
| 10 | |||
| 11 | |||
| 3 | extern keymap_config_t keymap_config; | 12 | extern keymap_config_t keymap_config; |
| 4 | 13 | ||
| 14 | #ifdef RGBLIGHT_ENABLE | ||
| 15 | //Following line allows macro to read current RGB settings | ||
| 16 | extern rgblight_config_t rgblight_config; | ||
| 17 | #endif | ||
| 18 | |||
| 19 | extern uint8_t is_master; | ||
| 20 | |||
| 5 | #define _QWERTY 0 | 21 | #define _QWERTY 0 |
| 6 | #define _LOWER 1 | 22 | #define _LOWER 1 |
| 7 | #define _RAISE 2 | 23 | #define _RAISE 2 |
| @@ -88,9 +104,9 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |||
| 88 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | 104 | * |------+------+------+------+------+------| |------+------+------+------+------+------| |
| 89 | * | | | | | | | | | | | | | | | 105 | * | | | | | | | | | | | | | | |
| 90 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | 106 | * |------+------+------+------+------+------| |------+------+------+------+------+------| |
| 91 | * | | | | | | |-------. ,-------| | | | | | | | 107 | * | | | | | | |-------. ,-------| | |RGB ON| HUE+ | SAT+ | VAL+ | |
| 92 | * |------+------+------+------+------+------| | | |------+------+------+------+------+------| | 108 | * |------+------+------+------+------+------| | | |------+------+------+------+------+------| |
| 93 | * | | | | | | |-------| |-------| | | | | | | | 109 | * | | | | | | |-------| |-------| | | MODE | HUE- | SAT- | VAL- | |
| 94 | * `-----------------------------------------/ / \ \-----------------------------------------' | 110 | * `-----------------------------------------/ / \ \-----------------------------------------' |
| 95 | * | LAlt | LGUI |LOWER | /Space / \Enter \ |RAISE |BackSP| RGUI | | 111 | * | LAlt | LGUI |LOWER | /Space / \Enter \ |RAISE |BackSP| RGUI | |
| 96 | * | | | |/ / \ \ | | | | | 112 | * | | | |/ / \ \ | | | | |
| @@ -99,17 +115,92 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |||
| 99 | [_ADJUST] = LAYOUT( \ | 115 | [_ADJUST] = LAYOUT( \ |
| 100 | XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \ | 116 | XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \ |
| 101 | XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \ | 117 | XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \ |
| 102 | XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \ | 118 | XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, RGB_TOG, RGB_HUI, RGB_SAI, RGB_VAI, \ |
| 103 | XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,\ | 119 | XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, RGB_MOD, RGB_HUD, RGB_SAD, RGB_VAD,\ |
| 104 | _______, _______, _______, _______, _______, _______, _______, _______ \ | 120 | _______, _______, _______, _______, _______, _______, _______, _______ \ |
| 105 | ) | 121 | ) |
| 106 | }; | 122 | }; |
| 107 | 123 | ||
| 124 | int RGB_current_mode; | ||
| 125 | |||
| 126 | // Setting ADJUST layer RGB back to default | ||
| 127 | void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) { | ||
| 128 | if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) { | ||
| 129 | layer_on(layer3); | ||
| 130 | } else { | ||
| 131 | layer_off(layer3); | ||
| 132 | } | ||
| 133 | } | ||
| 134 | |||
| 135 | void matrix_init_user(void) { | ||
| 136 | #ifdef RGBLIGHT_ENABLE | ||
| 137 | RGB_current_mode = rgblight_config.mode; | ||
| 138 | #endif | ||
| 139 | //SSD1306 OLED init, make sure to add #define SSD1306OLED in config.h | ||
| 140 | #ifdef SSD1306OLED | ||
| 141 | iota_gfx_init(!has_usb()); // turns on the display | ||
| 142 | #endif | ||
| 143 | } | ||
| 144 | |||
| 145 | //SSD1306 OLED update loop, make sure to add #define SSD1306OLED in config.h | ||
| 146 | #ifdef SSD1306OLED | ||
| 147 | |||
| 148 | // When add source files to SRC in rules.mk, you can use functions. | ||
| 149 | const char *read_layer_state(void); | ||
| 150 | const char *read_logo(void); | ||
| 151 | void set_keylog(uint16_t keycode, keyrecord_t *record); | ||
| 152 | const char *read_keylog(void); | ||
| 153 | const char *read_keylogs(void); | ||
| 154 | |||
| 155 | // const char *read_mode_icon(bool swap); | ||
| 156 | // const char *read_host_led_state(void); | ||
| 157 | // void set_timelog(void); | ||
| 158 | // const char *read_timelog(void); | ||
| 159 | |||
| 160 | void matrix_scan_user(void) { | ||
| 161 | iota_gfx_task(); | ||
| 162 | } | ||
| 163 | |||
| 164 | void matrix_render_user(struct CharacterMatrix *matrix) { | ||
| 165 | if (is_master) { | ||
| 166 | // If you want to change the display of OLED, you need to change here | ||
| 167 | matrix_write_ln(matrix, read_layer_state()); | ||
| 168 | matrix_write_ln(matrix, read_keylog()); | ||
| 169 | matrix_write_ln(matrix, read_keylogs()); | ||
| 170 | //matrix_write_ln(matrix, read_mode_icon(keymap_config.swap_lalt_lgui)); | ||
| 171 | //matrix_write_ln(matrix, read_host_led_state()); | ||
| 172 | //matrix_write_ln(matrix, read_timelog()); | ||
| 173 | } else { | ||
| 174 | matrix_write(matrix, read_logo()); | ||
| 175 | } | ||
| 176 | } | ||
| 177 | |||
| 178 | void matrix_update(struct CharacterMatrix *dest, const struct CharacterMatrix *source) { | ||
| 179 | if (memcmp(dest->display, source->display, sizeof(dest->display))) { | ||
| 180 | memcpy(dest->display, source->display, sizeof(dest->display)); | ||
| 181 | dest->dirty = true; | ||
| 182 | } | ||
| 183 | } | ||
| 184 | |||
| 185 | void iota_gfx_task_user(void) { | ||
| 186 | struct CharacterMatrix matrix; | ||
| 187 | matrix_clear(&matrix); | ||
| 188 | matrix_render_user(&matrix); | ||
| 189 | matrix_update(&display, &matrix); | ||
| 190 | } | ||
| 191 | #endif//SSD1306OLED | ||
| 108 | 192 | ||
| 109 | bool process_record_user(uint16_t keycode, keyrecord_t *record) { | 193 | bool process_record_user(uint16_t keycode, keyrecord_t *record) { |
| 194 | if (record->event.pressed) { | ||
| 195 | #ifdef SSD1306OLED | ||
| 196 | set_keylog(keycode, record); | ||
| 197 | #endif | ||
| 198 | // set_timelog(); | ||
| 199 | } | ||
| 200 | |||
| 110 | switch (keycode) { | 201 | switch (keycode) { |
| 111 | case QWERTY: | 202 | case QWERTY: |
| 112 | if (record->event.pressed) { | 203 | if (record->event.pressed) { |
| 113 | set_single_persistent_default_layer(_QWERTY); | 204 | set_single_persistent_default_layer(_QWERTY); |
| 114 | } | 205 | } |
| 115 | return false; | 206 | return false; |
| @@ -117,31 +208,31 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { | |||
| 117 | case LOWER: | 208 | case LOWER: |
| 118 | if (record->event.pressed) { | 209 | if (record->event.pressed) { |
| 119 | layer_on(_LOWER); | 210 | layer_on(_LOWER); |
| 120 | update_tri_layer(_LOWER, _RAISE, _ADJUST); | 211 | update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST); |
| 121 | } else { | 212 | } else { |
| 122 | layer_off(_LOWER); | 213 | layer_off(_LOWER); |
| 123 | update_tri_layer(_LOWER, _RAISE, _ADJUST); | 214 | update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST); |
| 124 | } | 215 | } |
| 125 | return false; | 216 | return false; |
| 126 | break; | 217 | break; |
| 127 | case RAISE: | 218 | case RAISE: |
| 128 | if (record->event.pressed) { | 219 | if (record->event.pressed) { |
| 129 | layer_on(_RAISE); | 220 | layer_on(_RAISE); |
| 130 | update_tri_layer(_LOWER, _RAISE, _ADJUST); | 221 | update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST); |
| 131 | } else { | 222 | } else { |
| 132 | layer_off(_RAISE); | 223 | layer_off(_RAISE); |
| 133 | update_tri_layer(_LOWER, _RAISE, _ADJUST); | 224 | update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST); |
| 134 | } | 225 | } |
| 135 | return false; | 226 | return false; |
| 136 | break; | 227 | break; |
| 137 | case ADJUST: | 228 | case ADJUST: |
| 138 | if (record->event.pressed) { | 229 | if (record->event.pressed) { |
| 139 | layer_on(_ADJUST); | 230 | layer_on(_ADJUST); |
| 140 | } else { | 231 | } else { |
| 141 | layer_off(_ADJUST); | 232 | layer_off(_ADJUST); |
| 142 | } | 233 | } |
| 143 | return false; | 234 | return false; |
| 144 | break; | 235 | break; |
| 145 | } | 236 | } |
| 146 | return true; | 237 | return true; |
| 147 | } \ No newline at end of file | 238 | } \ No newline at end of file |
diff --git a/keyboards/lily58/keymaps/default/rules.mk b/keyboards/lily58/keymaps/default/rules.mk index 3d2d3c9e0..922fac6b6 100644 --- a/keyboards/lily58/keymaps/default/rules.mk +++ b/keyboards/lily58/keymaps/default/rules.mk | |||
| @@ -1,21 +1,30 @@ | |||
| 1 | |||
| 2 | # Build Options | 1 | # Build Options |
| 3 | # change to "no" to disable the options, or define them in the Makefile in | 2 | # change to "no" to disable the options, or define them in the Makefile in |
| 4 | # the appropriate keymap folder that will get included automatically | 3 | # the appropriate keymap folder that will get included automatically |
| 5 | # | 4 | # |
| 6 | |||
| 7 | RGBLIGHT_ENABLE = no | ||
| 8 | |||
| 9 | BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000) | 5 | BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000) |
| 10 | MOUSEKEY_ENABLE = no # Mouse keys(+4700) | 6 | MOUSEKEY_ENABLE = no # Mouse keys(+4700) |
| 11 | EXTRAKEY_ENABLE = no # Audio control and System control(+450) | 7 | EXTRAKEY_ENABLE = no # Audio control and System control(+450) |
| 12 | CONSOLE_ENABLE = no # Console for debug(+400) | 8 | CONSOLE_ENABLE = no # Console for debug(+400) |
| 13 | COMMAND_ENABLE = no # Commands for debug and configuration | 9 | COMMAND_ENABLE = no # Commands for debug and configuration |
| 14 | NKRO_ENABLE = no # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work | 10 | NKRO_ENABLE = no # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work |
| 11 | BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality | ||
| 15 | MIDI_ENABLE = no # MIDI controls | 12 | MIDI_ENABLE = no # MIDI controls |
| 16 | AUDIO_ENABLE = no # Audio output on port C6 | 13 | AUDIO_ENABLE = no # Audio output on port C6 |
| 17 | UNICODE_ENABLE = no # Unicode | 14 | UNICODE_ENABLE = no # Unicode |
| 18 | BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID | 15 | BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID |
| 19 | ONEHAND_ENABLE = no # Enable one-hand typing | 16 | RGBLIGHT_ENABLE = yes # Enable WS2812 RGB underlight. |
| 17 | SWAP_HANDS_ENABLE = no # Enable one-hand typing | ||
| 18 | |||
| 20 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE | 19 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE |
| 21 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend \ No newline at end of file | 20 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend |
| 21 | |||
| 22 | # If you want to change the display of OLED, you need to change here | ||
| 23 | SRC += ./lib/glcdfont.c \ | ||
| 24 | ./lib/rgb_state_reader.c \ | ||
| 25 | ./lib/layer_state_reader.c \ | ||
| 26 | ./lib/logo_reader.c \ | ||
| 27 | ./lib/keylogger.c \ | ||
| 28 | # ./lib/mode_icon_reader.c \ | ||
| 29 | # ./lib/host_led_state_reader.c \ | ||
| 30 | # ./lib/timelogger.c \ | ||
diff --git a/keyboards/lily58/keymaps/yuchi/config.h b/keyboards/lily58/keymaps/yuchi/config.h index fd0978559..58bbdc5e9 100644 --- a/keyboards/lily58/keymaps/yuchi/config.h +++ b/keyboards/lily58/keymaps/yuchi/config.h | |||
| @@ -17,12 +17,10 @@ GNU General Public License for more details. | |||
| 17 | You should have received a copy of the GNU General Public License | 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ | 19 | */ |
| 20 | #pragma once | ||
| 21 | 20 | ||
| 22 | /* Use I2C or Serial, not both */ | 21 | #pragma once |
| 23 | 22 | ||
| 24 | #define USE_SERIAL | 23 | //#define USE_MATRIX_I2C |
| 25 | // #define USE_I2C | ||
| 26 | 24 | ||
| 27 | /* Select hand configuration */ | 25 | /* Select hand configuration */ |
| 28 | 26 | ||
| @@ -30,6 +28,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 30 | // #define MASTER_RIGHT | 28 | // #define MASTER_RIGHT |
| 31 | // #define EE_HANDS | 29 | // #define EE_HANDS |
| 32 | 30 | ||
| 31 | #define SSD1306OLED | ||
| 32 | |||
| 33 | #define USE_SERIAL_PD2 | ||
| 34 | |||
| 35 | #define TAPPING_FORCE_HOLD | ||
| 36 | #define TAPPING_TERM 100 | ||
| 37 | |||
| 38 | #undef RGBLED_NUM | ||
| 39 | #define RGBLIGHT_ANIMATIONS | ||
| 40 | #define RGBLED_NUM 27 | ||
| 41 | #define RGBLIGHT_LIMIT_VAL 120 | ||
| 42 | #define RGBLIGHT_HUE_STEP 10 | ||
| 43 | #define RGBLIGHT_SAT_STEP 17 | ||
| 44 | #define RGBLIGHT_VAL_STEP 17 | ||
| 45 | |||
| 33 | // Underglow | 46 | // Underglow |
| 34 | /* | 47 | /* |
| 35 | #undef RGBLED_NUM | 48 | #undef RGBLED_NUM |
diff --git a/keyboards/lily58/keymaps/yuchi/keymap.c b/keyboards/lily58/keymaps/yuchi/keymap.c index d708dbec7..13b6cb168 100644 --- a/keyboards/lily58/keymaps/yuchi/keymap.c +++ b/keyboards/lily58/keymaps/yuchi/keymap.c | |||
| @@ -1,7 +1,23 @@ | |||
| 1 | #include QMK_KEYBOARD_H | 1 | #include QMK_KEYBOARD_H |
| 2 | 2 | ||
| 3 | #ifdef PROTOCOL_LUFA | ||
| 4 | #include "lufa.h" | ||
| 5 | #include "split_util.h" | ||
| 6 | #endif | ||
| 7 | #ifdef SSD1306OLED | ||
| 8 | #include "ssd1306.h" | ||
| 9 | #endif | ||
| 10 | |||
| 11 | |||
| 3 | extern keymap_config_t keymap_config; | 12 | extern keymap_config_t keymap_config; |
| 4 | 13 | ||
| 14 | #ifdef RGBLIGHT_ENABLE | ||
| 15 | //Following line allows macro to read current RGB settings | ||
| 16 | extern rgblight_config_t rgblight_config; | ||
| 17 | #endif | ||
| 18 | |||
| 19 | extern uint8_t is_master; | ||
| 20 | |||
| 5 | #define _QWERTY 0 | 21 | #define _QWERTY 0 |
| 6 | #define _LOWER 1 | 22 | #define _LOWER 1 |
| 7 | #define _RAISE 2 | 23 | #define _RAISE 2 |
| @@ -89,28 +105,103 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |||
| 89 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | 105 | * |------+------+------+------+------+------| |------+------+------+------+------+------| |
| 90 | * | | | | | | | | | | | | | | | 106 | * | | | | | | | | | | | | | | |
| 91 | * |------+------+------+------+------+------| |------+------+------+------+------+------| | 107 | * |------+------+------+------+------+------| |------+------+------+------+------+------| |
| 92 | * | | | | | | |-------. ,-------| | | | | | | | 108 | * | | | | | | |-------. ,-------| | |RGB ON| HUE+ | SAT+ | VAL+ | |
| 93 | * |------+------+------+------+------+------| | | |------+------+------+------+------+------| | 109 | * |------+------+------+------+------+------| | | |------+------+------+------+------+------| |
| 94 | * | | | | | | |-------| |-------| | | | | | | | 110 | * | | | | | | |-------| |-------| | | MODE | HUE- | SAT- | VAL- | |
| 95 | * `-----------------------------------------/ / \ \-----------------------------------------' | 111 | * `-----------------------------------------/ / \ \-----------------------------------------' |
| 96 | * |LOWER | LGUI | Alt | /Space / \Enter \ |BackSP| RGUI |RAISE | | 112 | * |LOWER | LGUI | Alt | /Space / \Enter \ |BackSP| RGUI |RAISE | |
| 97 | * | | | |/ / \ \ | | | | | 113 | * | | | |/ / \ \ | | | | |
| 98 | * `-------------------''-------' '------''--------------------' | 114 | * `----------------------------' '------''--------------------' |
| 99 | */ | 115 | */ |
| 100 | [_ADJUST] = LAYOUT( \ | 116 | [_ADJUST] = LAYOUT( \ |
| 101 | XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \ | 117 | XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \ |
| 102 | XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \ | 118 | XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \ |
| 103 | XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \ | 119 | XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, RGB_TOG, RGB_HUI, RGB_SAI, RGB_VAI, \ |
| 104 | XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,\ | 120 | XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, RGB_MOD, RGB_HUD, RGB_SAD, RGB_VAD,\ |
| 105 | _______, _______, _______, _______, _______, _______, _______, _______ \ | 121 | _______, _______, _______, _______, _______, _______, _______, _______ \ |
| 106 | ) | 122 | ) |
| 107 | }; | 123 | }; |
| 108 | 124 | ||
| 125 | int RGB_current_mode; | ||
| 126 | |||
| 127 | // Setting ADJUST layer RGB back to default | ||
| 128 | void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) { | ||
| 129 | if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) { | ||
| 130 | layer_on(layer3); | ||
| 131 | } else { | ||
| 132 | layer_off(layer3); | ||
| 133 | } | ||
| 134 | } | ||
| 135 | |||
| 136 | void matrix_init_user(void) { | ||
| 137 | #ifdef RGBLIGHT_ENABLE | ||
| 138 | RGB_current_mode = rgblight_config.mode; | ||
| 139 | #endif | ||
| 140 | //SSD1306 OLED init, make sure to add #define SSD1306OLED in config.h | ||
| 141 | #ifdef SSD1306OLED | ||
| 142 | iota_gfx_init(!has_usb()); // turns on the display | ||
| 143 | #endif | ||
| 144 | } | ||
| 145 | |||
| 146 | //SSD1306 OLED update loop, make sure to add #define SSD1306OLED in config.h | ||
| 147 | #ifdef SSD1306OLED | ||
| 148 | |||
| 149 | // When add source files to SRC in rules.mk, you can use functions. | ||
| 150 | const char *read_layer_state(void); | ||
| 151 | const char *read_logo(void); | ||
| 152 | void set_keylog(uint16_t keycode, keyrecord_t *record); | ||
| 153 | const char *read_keylog(void); | ||
| 154 | const char *read_keylogs(void); | ||
| 155 | |||
| 156 | // const char *read_mode_icon(bool swap); | ||
| 157 | // const char *read_host_led_state(void); | ||
| 158 | // void set_timelog(void); | ||
| 159 | // const char *read_timelog(void); | ||
| 160 | |||
| 161 | void matrix_scan_user(void) { | ||
| 162 | iota_gfx_task(); | ||
| 163 | } | ||
| 164 | |||
| 165 | void matrix_render_user(struct CharacterMatrix *matrix) { | ||
| 166 | if (is_master) { | ||
| 167 | // If you want to change the display of OLED, you need to change here | ||
| 168 | matrix_write_ln(matrix, read_layer_state()); | ||
| 169 | matrix_write_ln(matrix, read_keylog()); | ||
| 170 | matrix_write_ln(matrix, read_keylogs()); | ||
| 171 | //matrix_write_ln(matrix, read_mode_icon(keymap_config.swap_lalt_lgui)); | ||
| 172 | //matrix_write_ln(matrix, read_host_led_state()); | ||
| 173 | //matrix_write_ln(matrix, read_timelog()); | ||
| 174 | } else { | ||
| 175 | matrix_write(matrix, read_logo()); | ||
| 176 | } | ||
| 177 | } | ||
| 178 | |||
| 179 | void matrix_update(struct CharacterMatrix *dest, const struct CharacterMatrix *source) { | ||
| 180 | if (memcmp(dest->display, source->display, sizeof(dest->display))) { | ||
| 181 | memcpy(dest->display, source->display, sizeof(dest->display)); | ||
| 182 | dest->dirty = true; | ||
| 183 | } | ||
| 184 | } | ||
| 185 | |||
| 186 | void iota_gfx_task_user(void) { | ||
| 187 | struct CharacterMatrix matrix; | ||
| 188 | matrix_clear(&matrix); | ||
| 189 | matrix_render_user(&matrix); | ||
| 190 | matrix_update(&display, &matrix); | ||
| 191 | } | ||
| 192 | #endif//SSD1306OLED | ||
| 109 | 193 | ||
| 110 | bool process_record_user(uint16_t keycode, keyrecord_t *record) { | 194 | bool process_record_user(uint16_t keycode, keyrecord_t *record) { |
| 195 | if (record->event.pressed) { | ||
| 196 | #ifdef SSD1306OLED | ||
| 197 | set_keylog(keycode, record); | ||
| 198 | #endif | ||
| 199 | // set_timelog(); | ||
| 200 | } | ||
| 201 | |||
| 111 | switch (keycode) { | 202 | switch (keycode) { |
| 112 | case QWERTY: | 203 | case QWERTY: |
| 113 | if (record->event.pressed) { | 204 | if (record->event.pressed) { |
| 114 | set_single_persistent_default_layer(_QWERTY); | 205 | set_single_persistent_default_layer(_QWERTY); |
| 115 | } | 206 | } |
| 116 | return false; | 207 | return false; |
| @@ -118,31 +209,31 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { | |||
| 118 | case LOWER: | 209 | case LOWER: |
| 119 | if (record->event.pressed) { | 210 | if (record->event.pressed) { |
| 120 | layer_on(_LOWER); | 211 | layer_on(_LOWER); |
| 121 | update_tri_layer(_LOWER, _RAISE, _ADJUST); | 212 | update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST); |
| 122 | } else { | 213 | } else { |
| 123 | layer_off(_LOWER); | 214 | layer_off(_LOWER); |
| 124 | update_tri_layer(_LOWER, _RAISE, _ADJUST); | 215 | update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST); |
| 125 | } | 216 | } |
| 126 | return false; | 217 | return false; |
| 127 | break; | 218 | break; |
| 128 | case RAISE: | 219 | case RAISE: |
| 129 | if (record->event.pressed) { | 220 | if (record->event.pressed) { |
| 130 | layer_on(_RAISE); | 221 | layer_on(_RAISE); |
| 131 | update_tri_layer(_LOWER, _RAISE, _ADJUST); | 222 | update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST); |
| 132 | } else { | 223 | } else { |
| 133 | layer_off(_RAISE); | 224 | layer_off(_RAISE); |
| 134 | update_tri_layer(_LOWER, _RAISE, _ADJUST); | 225 | update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST); |
| 135 | } | 226 | } |
| 136 | return false; | 227 | return false; |
| 137 | break; | 228 | break; |
| 138 | case ADJUST: | 229 | case ADJUST: |
| 139 | if (record->event.pressed) { | 230 | if (record->event.pressed) { |
| 140 | layer_on(_ADJUST); | 231 | layer_on(_ADJUST); |
| 141 | } else { | 232 | } else { |
| 142 | layer_off(_ADJUST); | 233 | layer_off(_ADJUST); |
| 143 | } | 234 | } |
| 144 | return false; | 235 | return false; |
| 145 | break; | 236 | break; |
| 146 | } | 237 | } |
| 147 | return true; | 238 | return true; |
| 148 | } \ No newline at end of file | 239 | } \ No newline at end of file |
diff --git a/keyboards/lily58/keymaps/yuchi/rules.mk b/keyboards/lily58/keymaps/yuchi/rules.mk index 73777a1b7..922fac6b6 100644 --- a/keyboards/lily58/keymaps/yuchi/rules.mk +++ b/keyboards/lily58/keymaps/yuchi/rules.mk | |||
| @@ -1,22 +1,30 @@ | |||
| 1 | |||
| 2 | # Build Options | 1 | # Build Options |
| 3 | # change to "no" to disable the options, or define them in the Makefile in | 2 | # change to "no" to disable the options, or define them in the Makefile in |
| 4 | # the appropriate keymap folder that will get included automatically | 3 | # the appropriate keymap folder that will get included automatically |
| 5 | # | 4 | # |
| 6 | |||
| 7 | OLED_ENABLE = no | ||
| 8 | RGBLIGHT_ENABLE = no | ||
| 9 | |||
| 10 | BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000) | 5 | BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000) |
| 11 | MOUSEKEY_ENABLE = no # Mouse keys(+4700) | 6 | MOUSEKEY_ENABLE = no # Mouse keys(+4700) |
| 12 | EXTRAKEY_ENABLE = no # Audio control and System control(+450) | 7 | EXTRAKEY_ENABLE = no # Audio control and System control(+450) |
| 13 | CONSOLE_ENABLE = no # Console for debug(+400) | 8 | CONSOLE_ENABLE = no # Console for debug(+400) |
| 14 | COMMAND_ENABLE = no # Commands for debug and configuration | 9 | COMMAND_ENABLE = no # Commands for debug and configuration |
| 15 | NKRO_ENABLE = no # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work | 10 | NKRO_ENABLE = no # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work |
| 11 | BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality | ||
| 16 | MIDI_ENABLE = no # MIDI controls | 12 | MIDI_ENABLE = no # MIDI controls |
| 17 | AUDIO_ENABLE = no # Audio output on port C6 | 13 | AUDIO_ENABLE = no # Audio output on port C6 |
| 18 | UNICODE_ENABLE = no # Unicode | 14 | UNICODE_ENABLE = no # Unicode |
| 19 | BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID | 15 | BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID |
| 20 | ONEHAND_ENABLE = no # Enable one-hand typing | 16 | RGBLIGHT_ENABLE = yes # Enable WS2812 RGB underlight. |
| 17 | SWAP_HANDS_ENABLE = no # Enable one-hand typing | ||
| 18 | |||
| 21 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE | 19 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE |
| 22 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend \ No newline at end of file | 20 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend |
| 21 | |||
| 22 | # If you want to change the display of OLED, you need to change here | ||
| 23 | SRC += ./lib/glcdfont.c \ | ||
| 24 | ./lib/rgb_state_reader.c \ | ||
| 25 | ./lib/layer_state_reader.c \ | ||
| 26 | ./lib/logo_reader.c \ | ||
| 27 | ./lib/keylogger.c \ | ||
| 28 | # ./lib/mode_icon_reader.c \ | ||
| 29 | # ./lib/host_led_state_reader.c \ | ||
| 30 | # ./lib/timelogger.c \ | ||
diff --git a/keyboards/lily58/lib/glcdfont.c b/keyboards/lily58/lib/glcdfont.c new file mode 100644 index 000000000..c691ea9d0 --- /dev/null +++ b/keyboards/lily58/lib/glcdfont.c | |||
| @@ -0,0 +1,243 @@ | |||
| 1 | // This is the 'classic' fixed-space bitmap font for Adafruit_GFX since 1.0. | ||
| 2 | // See gfxfont.h for newer custom bitmap font info. | ||
| 3 | |||
| 4 | #ifndef FONT5X7_H | ||
| 5 | #define FONT5X7_H | ||
| 6 | |||
| 7 | #ifdef __AVR__ | ||
| 8 | #include <avr/io.h> | ||
| 9 | #include <avr/pgmspace.h> | ||
| 10 | #elif defined(ESP8266) | ||
| 11 | #include <pgmspace.h> | ||
| 12 | #else | ||
| 13 | #define PROGMEM | ||
| 14 | #endif | ||
| 15 | |||
| 16 | // Standard ASCII 5x7 font | ||
| 17 | const unsigned char font[] PROGMEM = { | ||
| 18 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 19 | 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, 0x00, | ||
| 20 | 0x3E, 0x6B, 0x4F, 0x6B, 0x3E, 0x00, | ||
| 21 | 0x1C, 0x3E, 0x7C, 0x3E, 0x1C, 0x00, | ||
| 22 | 0x18, 0x3C, 0x7E, 0x3C, 0x18, 0x00, | ||
| 23 | 0x1C, 0x57, 0x7D, 0x57, 0x1C, 0x00, | ||
| 24 | 0x1C, 0x5E, 0x7F, 0x5E, 0x1C, 0x00, | ||
| 25 | 0x00, 0x18, 0x3C, 0x18, 0x00, 0x00, | ||
| 26 | 0xFF, 0xE7, 0xC3, 0xE7, 0xFF, 0x00, | ||
| 27 | 0x00, 0x18, 0x24, 0x18, 0x00, 0x00, | ||
| 28 | 0xFF, 0xE7, 0xDB, 0xE7, 0xFF, 0x00, | ||
| 29 | 0x30, 0x48, 0x3A, 0x06, 0x0E, 0x00, | ||
| 30 | 0x26, 0x29, 0x79, 0x29, 0x26, 0x00, | ||
| 31 | 0x40, 0x7F, 0x05, 0x05, 0x07, 0x00, | ||
| 32 | 0x40, 0x7F, 0x05, 0x25, 0x3F, 0x00, | ||
| 33 | 0x5A, 0x3C, 0xE7, 0x3C, 0x5A, 0x00, | ||
| 34 | 0x7F, 0x3E, 0x1C, 0x1C, 0x08, 0x00, | ||
| 35 | 0x08, 0x1C, 0x1C, 0x3E, 0x7F, 0x00, | ||
| 36 | 0x14, 0x22, 0x7F, 0x22, 0x14, 0x00, | ||
| 37 | 0x5F, 0x5F, 0x00, 0x5F, 0x5F, 0x00, | ||
| 38 | 0x06, 0x09, 0x7F, 0x01, 0x7F, 0x00, | ||
| 39 | 0x00, 0x66, 0x89, 0x95, 0x6A, 0x00, | ||
| 40 | 0x60, 0x60, 0x60, 0x60, 0x60, 0x00, | ||
| 41 | 0x94, 0xA2, 0xFF, 0xA2, 0x94, 0x00, | ||
| 42 | 0x08, 0x04, 0x7E, 0x04, 0x08, 0x00, | ||
| 43 | 0x10, 0x20, 0x7E, 0x20, 0x10, 0x00, | ||
| 44 | 0x08, 0x08, 0x2A, 0x1C, 0x08, 0x00, | ||
| 45 | 0x08, 0x1C, 0x2A, 0x08, 0x08, 0x00, | ||
| 46 | 0x1E, 0x10, 0x10, 0x10, 0x10, 0x00, | ||
| 47 | 0x0C, 0x1E, 0x0C, 0x1E, 0x0C, 0x00, | ||
| 48 | 0x30, 0x38, 0x3E, 0x38, 0x30, 0x00, | ||
| 49 | 0x06, 0x0E, 0x3E, 0x0E, 0x06, 0x00, | ||
| 50 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 51 | 0x00, 0x00, 0x5F, 0x00, 0x00, 0x00, | ||
| 52 | 0x00, 0x07, 0x00, 0x07, 0x00, 0x00, | ||
| 53 | 0x14, 0x7F, 0x14, 0x7F, 0x14, 0x00, | ||
| 54 | 0x24, 0x2A, 0x7F, 0x2A, 0x12, 0x00, | ||
| 55 | 0x23, 0x13, 0x08, 0x64, 0x62, 0x00, | ||
| 56 | 0x36, 0x49, 0x56, 0x20, 0x50, 0x00, | ||
| 57 | 0x00, 0x08, 0x07, 0x03, 0x00, 0x00, | ||
| 58 | 0x00, 0x1C, 0x22, 0x41, 0x00, 0x00, | ||
| 59 | 0x00, 0x41, 0x22, 0x1C, 0x00, 0x00, | ||
| 60 | 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, 0x00, | ||
| 61 | 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00, | ||
| 62 | 0x00, 0x80, 0x70, 0x30, 0x00, 0x00, | ||
| 63 | 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, | ||
| 64 | 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, | ||
| 65 | 0x20, 0x10, 0x08, 0x04, 0x02, 0x00, | ||
| 66 | 0x3E, 0x51, 0x49, 0x45, 0x3E, 0x00, | ||
| 67 | 0x00, 0x42, 0x7F, 0x40, 0x00, 0x00, | ||
| 68 | 0x72, 0x49, 0x49, 0x49, 0x46, 0x00, | ||
| 69 | 0x21, 0x41, 0x49, 0x4D, 0x33, 0x00, | ||
| 70 | 0x18, 0x14, 0x12, 0x7F, 0x10, 0x00, | ||
| 71 | 0x27, 0x45, 0x45, 0x45, 0x39, 0x00, | ||
| 72 | 0x3C, 0x4A, 0x49, 0x49, 0x31, 0x00, | ||
| 73 | 0x41, 0x21, 0x11, 0x09, 0x07, 0x00, | ||
| 74 | 0x36, 0x49, 0x49, 0x49, 0x36, 0x00, | ||
| 75 | 0x46, 0x49, 0x49, 0x29, 0x1E, 0x00, | ||
| 76 | 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, | ||
| 77 | 0x00, 0x40, 0x34, 0x00, 0x00, 0x00, | ||
| 78 | 0x00, 0x08, 0x14, 0x22, 0x41, 0x00, | ||
| 79 | 0x14, 0x14, 0x14, 0x14, 0x14, 0x00, | ||
| 80 | 0x00, 0x41, 0x22, 0x14, 0x08, 0x00, | ||
| 81 | 0x02, 0x01, 0x59, 0x09, 0x06, 0x00, | ||
| 82 | 0x3E, 0x41, 0x5D, 0x59, 0x4E, 0x00, | ||
| 83 | 0x7C, 0x12, 0x11, 0x12, 0x7C, 0x00, | ||
| 84 | 0x7F, 0x49, 0x49, 0x49, 0x36, 0x00, | ||
| 85 | 0x3E, 0x41, 0x41, 0x41, 0x22, 0x00, | ||
| 86 | 0x7F, 0x41, 0x41, 0x41, 0x3E, 0x00, | ||
| 87 | 0x7F, 0x49, 0x49, 0x49, 0x41, 0x00, | ||
| 88 | 0x7F, 0x09, 0x09, 0x09, 0x01, 0x00, | ||
| 89 | 0x3E, 0x41, 0x41, 0x51, 0x73, 0x00, | ||
| 90 | 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00, | ||
| 91 | 0x00, 0x41, 0x7F, 0x41, 0x00, 0x00, | ||
| 92 | 0x20, 0x40, 0x41, 0x3F, 0x01, 0x00, | ||
| 93 | 0x7F, 0x08, 0x14, 0x22, 0x41, 0x00, | ||
| 94 | 0x7F, 0x40, 0x40, 0x40, 0x40, 0x00, | ||
| 95 | 0x7F, 0x02, 0x1C, 0x02, 0x7F, 0x00, | ||
| 96 | 0x7F, 0x04, 0x08, 0x10, 0x7F, 0x00, | ||
| 97 | 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00, | ||
| 98 | 0x7F, 0x09, 0x09, 0x09, 0x06, 0x00, | ||
| 99 | 0x3E, 0x41, 0x51, 0x21, 0x5E, 0x00, | ||
| 100 | 0x7F, 0x09, 0x19, 0x29, 0x46, 0x00, | ||
| 101 | 0x26, 0x49, 0x49, 0x49, 0x32, 0x00, | ||
| 102 | 0x03, 0x01, 0x7F, 0x01, 0x03, 0x00, | ||
| 103 | 0x3F, 0x40, 0x40, 0x40, 0x3F, 0x00, | ||
| 104 | 0x1F, 0x20, 0x40, 0x20, 0x1F, 0x00, | ||
| 105 | 0x3F, 0x40, 0x38, 0x40, 0x3F, 0x00, | ||
| 106 | 0x63, 0x14, 0x08, 0x14, 0x63, 0x00, | ||
| 107 | 0x03, 0x04, 0x78, 0x04, 0x03, 0x00, | ||
| 108 | 0x61, 0x59, 0x49, 0x4D, 0x43, 0x00, | ||
| 109 | 0x00, 0x7F, 0x41, 0x41, 0x41, 0x00, | ||
| 110 | 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, | ||
| 111 | 0x00, 0x41, 0x41, 0x41, 0x7F, 0x00, | ||
| 112 | 0x04, 0x02, 0x01, 0x02, 0x04, 0x00, | ||
| 113 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, | ||
| 114 | 0x00, 0x03, 0x07, 0x08, 0x00, 0x00, | ||
| 115 | 0x20, 0x54, 0x54, 0x78, 0x40, 0x00, | ||
| 116 | 0x7F, 0x28, 0x44, 0x44, 0x38, 0x00, | ||
| 117 | 0x38, 0x44, 0x44, 0x44, 0x28, 0x00, | ||
| 118 | 0x38, 0x44, 0x44, 0x28, 0x7F, 0x00, | ||
| 119 | 0x38, 0x54, 0x54, 0x54, 0x18, 0x00, | ||
| 120 | 0x00, 0x08, 0x7E, 0x09, 0x02, 0x00, | ||
| 121 | 0x18, 0x24, 0x24, 0x1C, 0x78, 0x00, | ||
| 122 | 0x7F, 0x08, 0x04, 0x04, 0x78, 0x00, | ||
| 123 | 0x00, 0x44, 0x7D, 0x40, 0x00, 0x00, | ||
| 124 | 0x20, 0x40, 0x40, 0x3D, 0x00, 0x00, | ||
| 125 | 0x7F, 0x10, 0x28, 0x44, 0x00, 0x00, | ||
| 126 | 0x00, 0x41, 0x7F, 0x40, 0x00, 0x00, | ||
| 127 | 0x7C, 0x04, 0x78, 0x04, 0x78, 0x00, | ||
| 128 | 0x7C, 0x08, 0x04, 0x04, 0x78, 0x00, | ||
| 129 | 0x38, 0x44, 0x44, 0x44, 0x38, 0x00, | ||
| 130 | 0x7C, 0x18, 0x24, 0x24, 0x18, 0x00, | ||
| 131 | 0x18, 0x24, 0x24, 0x18, 0x7C, 0x00, | ||
| 132 | 0x7C, 0x08, 0x04, 0x04, 0x08, 0x00, | ||
| 133 | 0x48, 0x54, 0x54, 0x54, 0x24, 0x00, | ||
| 134 | 0x04, 0x04, 0x3F, 0x44, 0x24, 0x00, | ||
| 135 | 0x3C, 0x40, 0x40, 0x20, 0x7C, 0x00, | ||
| 136 | 0x1C, 0x20, 0x40, 0x20, 0x1C, 0x00, | ||
| 137 | 0x3C, 0x40, 0x30, 0x40, 0x3C, 0x00, | ||
| 138 | 0x44, 0x28, 0x10, 0x28, 0x44, 0x00, | ||
| 139 | 0x4C, 0x90, 0x90, 0x90, 0x7C, 0x00, | ||
| 140 | 0x44, 0x64, 0x54, 0x4C, 0x44, 0x00, | ||
| 141 | 0x00, 0x08, 0x36, 0x41, 0x00, 0x00, | ||
| 142 | 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, | ||
| 143 | 0x00, 0x41, 0x36, 0x08, 0x00, 0x00, | ||
| 144 | 0x02, 0x01, 0x02, 0x04, 0x02, 0x00, | ||
| 145 | 0x3C, 0x26, 0x23, 0x26, 0x3C, 0x00, | ||
| 146 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, | ||
| 147 | 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, | ||
| 148 | 0x00, 0x00, 0x80, 0xE0, 0x70, 0x18, | ||
| 149 | 0x0C, 0x18, 0x30, 0xE0, 0x80, 0x00, | ||
| 150 | 0x00, 0x10, 0xF8, 0x90, 0x10, 0x30, | ||
| 151 | 0x78, 0x30, 0x10, 0xB8, 0xFC, 0x38, | ||
| 152 | 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 153 | 0x00, 0xF8, 0xFC, 0xF8, 0x00, 0x00, | ||
| 154 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 155 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, | ||
| 156 | 0x9C, 0x1C, 0x00, 0x00, 0x00, 0x00, | ||
| 157 | 0xF8, 0xFC, 0xF8, 0x00, 0x00, 0x00, | ||
| 158 | 0x00, 0x00, 0x00, 0x1C, 0xFC, 0xF8, | ||
| 159 | 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 160 | 0x00, 0x80, 0xE0, 0xF8, 0x7C, 0x1C, | ||
| 161 | 0x00, 0x00, 0x00, 0xF0, 0xFC, 0xFC, | ||
| 162 | 0xFC, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, | ||
| 163 | 0x1C, 0x1C, 0x1C, 0x00, 0x00, 0x00, | ||
| 164 | 0x00, 0x00, 0x00, 0xC0, 0xF0, 0xF8, | ||
| 165 | 0x38, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, | ||
| 166 | 0x1C, 0x3C, 0xF8, 0xF0, 0xE0, 0x00, | ||
| 167 | 0xE0, 0xF0, 0xF0, 0xF0, 0xE0, 0xEC, | ||
| 168 | 0xEE, 0xF7, 0xF3, 0x70, 0x20, 0x00, | ||
| 169 | 0x7C, 0x7C, 0x7C, 0x7E, 0x00, 0x7E, | ||
| 170 | 0x7E, 0x7E, 0x7F, 0x7F, 0x7F, 0x00, | ||
| 171 | 0x00, 0x80, 0xC0, 0xE0, 0x7E, 0x5B, | ||
| 172 | 0x4F, 0x5B, 0xFE, 0xC0, 0x00, 0x00, | ||
| 173 | 0xC0, 0x00, 0xDC, 0xD7, 0xDE, 0xDE, | ||
| 174 | 0xDE, 0xD7, 0xDC, 0x00, 0xC0, 0x00, | ||
| 175 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 176 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 177 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 178 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, | ||
| 179 | 0xBC, 0xE0, 0x81, 0x81, 0x81, 0x83, | ||
| 180 | 0x83, 0x82, 0x87, 0x0C, 0x18, 0x30, | ||
| 181 | 0x60, 0xC0, 0x00, 0x00, 0x1F, 0xFE, | ||
| 182 | 0x90, 0xB9, 0xFF, 0xBB, 0x91, 0x98, | ||
| 183 | 0x3C, 0x18, 0x11, 0x13, 0x3F, 0x11, | ||
| 184 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 185 | 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, | ||
| 186 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 187 | 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, | ||
| 188 | 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, | ||
| 189 | 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, | ||
| 190 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, | ||
| 191 | 0x0F, 0x7F, 0xF8, 0xE0, 0x80, 0xF0, | ||
| 192 | 0xFC, 0x3F, 0x0F, 0x01, 0x00, 0x00, | ||
| 193 | 0x00, 0x00, 0x00, 0x3F, 0x3F, 0x3F, | ||
| 194 | 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x3C, | ||
| 195 | 0x78, 0xF8, 0xF0, 0xE0, 0x80, 0x00, | ||
| 196 | 0x00, 0x00, 0x00, 0xC3, 0xE7, 0xFF, | ||
| 197 | 0x7E, 0x3C, 0x38, 0x78, 0x78, 0x70, | ||
| 198 | 0x70, 0xF8, 0xFF, 0xDF, 0x87, 0x00, | ||
| 199 | 0x0F, 0x1F, 0x3F, 0x7F, 0x7F, 0x7F, | ||
| 200 | 0x7F, 0x7F, 0x3F, 0x1E, 0x0C, 0x00, | ||
| 201 | 0x1F, 0x1F, 0x1F, 0x3F, 0x00, 0x3F, | ||
| 202 | 0x3F, 0x3F, 0x7F, 0x7F, 0x7F, 0x00, | ||
| 203 | 0x30, 0x7B, 0x7F, 0x78, 0x30, 0x20, | ||
| 204 | 0x20, 0x30, 0x78, 0x7F, 0x3B, 0x00, | ||
| 205 | 0x03, 0x00, 0x0F, 0x7F, 0x0F, 0x0F, | ||
| 206 | 0x0F, 0x7F, 0x0F, 0x00, 0x03, 0x00, | ||
| 207 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 208 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 209 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 210 | 0x18, 0x3C, 0x24, 0x66, 0x63, 0x41, | ||
| 211 | 0xC1, 0x81, 0x80, 0x80, 0x80, 0x80, | ||
| 212 | 0x80, 0x80, 0x81, 0xC1, 0x41, 0x62, | ||
| 213 | 0x38, 0x6C, 0x4C, 0xC6, 0x81, 0x81, | ||
| 214 | 0x80, 0x80, 0x80, 0x80, 0x80, 0x81, | ||
| 215 | 0xC1, 0x43, 0x62, 0x36, 0x1C, 0x18, | ||
| 216 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 217 | 0x00, 0xFF, 0xFF, 0xFF, 0xC0, 0xC0, | ||
| 218 | 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, | ||
| 219 | 0xC0, 0x80, 0x00, 0x00, 0x00, 0x7F, | ||
| 220 | 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, | ||
| 221 | 0x7F, 0xFF, 0xFF, 0xC0, 0x80, 0x00, | ||
| 222 | 0x00, 0x00, 0xE0, 0xE0, 0xC0, 0xC0, | ||
| 223 | 0xC0, 0xE0, 0xF9, 0x7F, 0x1F, 0x07, | ||
| 224 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 225 | 0x00, 0x00, 0x00, 0x70, 0xF0, 0xE0, | ||
| 226 | 0xE0, 0xC0, 0xC0, 0xC0, 0xC0, 0xE0, | ||
| 227 | 0xF0, 0xF8, 0x7F, 0x3F, 0x0F, 0x00, | ||
| 228 | 0x00, 0x00, 0x0F, 0x3F, 0x7F, 0xF9, | ||
| 229 | 0xE0, 0xE0, 0xC0, 0xC0, 0xC0, 0xC0, | ||
| 230 | 0xC0, 0xE0, 0xF9, 0x7F, 0x3F, 0x1F, | ||
| 231 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 232 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 233 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 234 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 235 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 236 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 237 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 238 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 239 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 240 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 241 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 242 | }; | ||
| 243 | #endif // FONT5X7_H | ||
diff --git a/keyboards/lily58/lib/host_led_state_reader.c b/keyboards/lily58/lib/host_led_state_reader.c new file mode 100644 index 000000000..0e22173b1 --- /dev/null +++ b/keyboards/lily58/lib/host_led_state_reader.c | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | #include "lily58.h" | ||
| 3 | |||
| 4 | char host_led_state_str[24]; | ||
| 5 | |||
| 6 | const char *read_host_led_state(void) | ||
| 7 | { | ||
| 8 | uint8_t leds = host_keyboard_leds(); | ||
| 9 | snprintf(host_led_state_str, sizeof(host_led_state_str), "NL:%s CL:%s SL:%s", | ||
| 10 | (leds & (1 << USB_LED_NUM_LOCK)) ? "on" : "- ", | ||
| 11 | (leds & (1 << USB_LED_CAPS_LOCK)) ? "on" : "- ", | ||
| 12 | (leds & (1 << USB_LED_SCROLL_LOCK)) ? "on" : "- "); | ||
| 13 | |||
| 14 | return host_led_state_str; | ||
| 15 | } | ||
diff --git a/keyboards/lily58/lib/keylogger.c b/keyboards/lily58/lib/keylogger.c new file mode 100644 index 000000000..a1bd476d2 --- /dev/null +++ b/keyboards/lily58/lib/keylogger.c | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | #include "lily58.h" | ||
| 3 | |||
| 4 | char keylog_str[24] = {}; | ||
| 5 | char keylogs_str[21] = {}; | ||
| 6 | int keylogs_str_idx = 0; | ||
| 7 | |||
| 8 | const char code_to_name[60] = { | ||
| 9 | ' ', ' ', ' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f', | ||
| 10 | 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', | ||
| 11 | 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', | ||
| 12 | '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', | ||
| 13 | 'R', 'E', 'B', 'T', ' ', ' ', ' ', ' ', ' ', ' ', | ||
| 14 | ' ', ';', '\'', ' ', ',', '.', '/', ' ', ' ', ' '}; | ||
| 15 | |||
| 16 | void set_keylog(uint16_t keycode, keyrecord_t *record) { | ||
| 17 | char name = ' '; | ||
| 18 | if (keycode < 60) { | ||
| 19 | name = code_to_name[keycode]; | ||
| 20 | } | ||
| 21 | |||
| 22 | // update keylog | ||
| 23 | snprintf(keylog_str, sizeof(keylog_str), "%dx%d, k%2d : %c", | ||
| 24 | record->event.key.row, record->event.key.col, | ||
| 25 | keycode, name); | ||
| 26 | |||
| 27 | // update keylogs | ||
| 28 | if (keylogs_str_idx == sizeof(keylogs_str) - 1) { | ||
| 29 | keylogs_str_idx = 0; | ||
| 30 | for (int i = 0; i < sizeof(keylogs_str) - 1; i++) { | ||
| 31 | keylogs_str[i] = ' '; | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | keylogs_str[keylogs_str_idx] = name; | ||
| 36 | keylogs_str_idx++; | ||
| 37 | } | ||
| 38 | |||
| 39 | const char *read_keylog(void) { | ||
| 40 | return keylog_str; | ||
| 41 | } | ||
| 42 | |||
| 43 | const char *read_keylogs(void) { | ||
| 44 | return keylogs_str; | ||
| 45 | } | ||
diff --git a/keyboards/lily58/lib/layer_state_reader.c b/keyboards/lily58/lib/layer_state_reader.c new file mode 100644 index 000000000..58f406bbc --- /dev/null +++ b/keyboards/lily58/lib/layer_state_reader.c | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | |||
| 2 | #include QMK_KEYBOARD_H | ||
| 3 | #include <stdio.h> | ||
| 4 | #include "lily58.h" | ||
| 5 | |||
| 6 | #define L_BASE 0 | ||
| 7 | #define L_LOWER 2 | ||
| 8 | #define L_RAISE 4 | ||
| 9 | #define L_ADJUST 65536 | ||
| 10 | #define L_ADJUST_TRI 65542 | ||
| 11 | |||
| 12 | char layer_state_str[24]; | ||
| 13 | |||
| 14 | const char *read_layer_state(void) { | ||
| 15 | switch (layer_state) | ||
| 16 | { | ||
| 17 | case L_BASE: | ||
| 18 | snprintf(layer_state_str, sizeof(layer_state_str), "Layer: Default"); | ||
| 19 | break; | ||
| 20 | case L_RAISE: | ||
| 21 | snprintf(layer_state_str, sizeof(layer_state_str), "Layer: Raise"); | ||
| 22 | break; | ||
| 23 | case L_LOWER: | ||
| 24 | snprintf(layer_state_str, sizeof(layer_state_str), "Layer: Lower"); | ||
| 25 | break; | ||
| 26 | case L_ADJUST: | ||
| 27 | case L_ADJUST_TRI: | ||
| 28 | snprintf(layer_state_str, sizeof(layer_state_str), "Layer: Adjust"); | ||
| 29 | break; | ||
| 30 | default: | ||
| 31 | snprintf(layer_state_str, sizeof(layer_state_str), "Layer: Undef-%ld", layer_state); | ||
| 32 | } | ||
| 33 | |||
| 34 | return layer_state_str; | ||
| 35 | } | ||
diff --git a/keyboards/lily58/lib/logo_reader.c b/keyboards/lily58/lib/logo_reader.c new file mode 100644 index 000000000..9f8adb846 --- /dev/null +++ b/keyboards/lily58/lib/logo_reader.c | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | #include "lily58.h" | ||
| 2 | |||
| 3 | const char *read_logo(void) { | ||
| 4 | static char logo[] = { | ||
| 5 | 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, | ||
| 6 | 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, | ||
| 7 | 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, | ||
| 8 | 0}; | ||
| 9 | |||
| 10 | return logo; | ||
| 11 | } | ||
diff --git a/keyboards/lily58/lib/mode_icon_reader.c b/keyboards/lily58/lib/mode_icon_reader.c new file mode 100644 index 000000000..2bce4a71b --- /dev/null +++ b/keyboards/lily58/lib/mode_icon_reader.c | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | #include "lily58.h" | ||
| 3 | |||
| 4 | char mode_icon[24]; | ||
| 5 | |||
| 6 | const char *read_mode_icon(bool swap) { | ||
| 7 | static char logo[][2][3] = {{{0x95, 0x96, 0}, {0xb5, 0xb6, 0}}, {{0x97, 0x98, 0}, {0xb7, 0xb8, 0}}}; | ||
| 8 | if (swap == false) { | ||
| 9 | snprintf(mode_icon, sizeof(mode_icon), "%s\n%s", logo[0][0], logo[0][1]); | ||
| 10 | } else { | ||
| 11 | snprintf(mode_icon, sizeof(mode_icon), "%s\n%s", logo[1][0], logo[1][1]); | ||
| 12 | } | ||
| 13 | |||
| 14 | return mode_icon; | ||
| 15 | } | ||
diff --git a/keyboards/lily58/lib/rgb_state_reader.c b/keyboards/lily58/lib/rgb_state_reader.c new file mode 100644 index 000000000..e0efe2e52 --- /dev/null +++ b/keyboards/lily58/lib/rgb_state_reader.c | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | #ifdef RGBLIGHT_ENABLE | ||
| 2 | |||
| 3 | #include QMK_KEYBOARD_H | ||
| 4 | #include <stdio.h> | ||
| 5 | |||
| 6 | extern rgblight_config_t rgblight_config; | ||
| 7 | char rbf_info_str[24]; | ||
| 8 | const char *read_rgb_info(void) { | ||
| 9 | |||
| 10 | snprintf(rbf_info_str, sizeof(rbf_info_str), "%s %2d h%3d s%3d v%3d", | ||
| 11 | rgblight_config.enable ? "on" : "- ", rgblight_config.mode, | ||
| 12 | rgblight_config.hue, rgblight_config.sat, rgblight_config.val); | ||
| 13 | return rbf_info_str; | ||
| 14 | } | ||
| 15 | #endif | ||
diff --git a/keyboards/lily58/lib/timelogger.c b/keyboards/lily58/lib/timelogger.c new file mode 100644 index 000000000..bfbfbe8a2 --- /dev/null +++ b/keyboards/lily58/lib/timelogger.c | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | #include "lily58.h" | ||
| 3 | |||
| 4 | char timelog_str[24] = {}; | ||
| 5 | int last_time = 0; | ||
| 6 | int elapsed_time = 0; | ||
| 7 | |||
| 8 | void set_timelog(void) { | ||
| 9 | elapsed_time = timer_elapsed(last_time); | ||
| 10 | last_time = timer_read(); | ||
| 11 | snprintf(timelog_str, sizeof(timelog_str), "lt:%5d, et:%5d", last_time, elapsed_time); | ||
| 12 | } | ||
| 13 | |||
| 14 | const char *read_timelog(void) { | ||
| 15 | return timelog_str; | ||
| 16 | } | ||
diff --git a/keyboards/lily58/lily58.c b/keyboards/lily58/lily58.c index 697e3820c..eacd90a82 100644 --- a/keyboards/lily58/lily58.c +++ b/keyboards/lily58/lily58.c | |||
| @@ -1 +1,10 @@ | |||
| 1 | #include "lily58.h" | 1 | #include "lily58.h" |
| 2 | #include "ssd1306.h" | ||
| 3 | |||
| 4 | bool process_record_kb(uint16_t keycode, keyrecord_t *record) { | ||
| 5 | #ifdef SSD1306OLED | ||
| 6 | return process_record_gfx(keycode,record) && process_record_user(keycode, record); | ||
| 7 | #else | ||
| 8 | return process_record_user(keycode, record); | ||
| 9 | #endif | ||
| 10 | } \ No newline at end of file | ||
diff --git a/keyboards/lily58/lily58.h b/keyboards/lily58/lily58.h index 1d64dd7b2..064f847dd 100644 --- a/keyboards/lily58/lily58.h +++ b/keyboards/lily58/lily58.h | |||
| @@ -1,28 +1,5 @@ | |||
| 1 | #ifndef LILY58_H | 1 | #pragma once |
| 2 | #define LILY58_H | ||
| 3 | |||
| 4 | #include "quantum.h" | ||
| 5 | 2 | ||
| 6 | #ifdef KEYBOARD_lily58_rev1 | 3 | #ifdef KEYBOARD_lily58_rev1 |
| 7 | #include "rev1.h" | 4 | #include "rev1.h" |
| 8 | #endif | 5 | #endif |
| 9 | |||
| 10 | |||
| 11 | |||
| 12 | // Used to create a keymap using only KC_ prefixed keys | ||
| 13 | #define LAYOUT_kc( \ | ||
| 14 | L00, L01, L02, L03, L04, L05, R00, R01, R02, R03, R04, R05, \ | ||
| 15 | L10, L11, L12, L13, L14, L15, R10, R11, R12, R13, R14, R15, \ | ||
| 16 | L20, L21, L22, L23, L24, L25, R20, R21, R22, R23, R24, R25, \ | ||
| 17 | L30, L31, L32, L33, L34, L35, L45, R40, R30, R31, R32, R33, R34, R35, \ | ||
| 18 | L41, L42, L43, L44, R41, R42, R43, R44 \ | ||
| 19 | ) \ | ||
| 20 | LAYOUT( \ | ||
| 21 | KC_##L00, KC_##L01, KC_##L02, KC_##L03, KC_##L04, KC_##L05, KC_##R00, KC_##R01, KC_##R02, KC_##R03, KC_##R04, KC_##R05, \ | ||
| 22 | KC_##L10, KC_##L11, KC_##L12, KC_##L13, KC_##L14, KC_##L15, KC_##R10, KC_##R11, KC_##R12, KC_##R13, KC_##R14, KC_##R15, \ | ||
| 23 | KC_##L20, KC_##L21, KC_##L22, KC_##L23, KC_##L24, KC_##L25, KC_##R20, KC_##R21, KC_##R22, KC_##R23, KC_##R24, KC_##R25, \ | ||
| 24 | KC_##L30, KC_##L31, KC_##L32, KC_##L33, KC_##L34, KC_##L35, KC_##L45, KC_##R40, KC_##R30, KC_##R31, KC_##R32, KC_##R33, KC_##R34, KC_##R35, \ | ||
| 25 | KC_##L41, KC_##L42, KC_##L43, KC_##L44, KC_##R41, KC_##R42, KC_##R43, KC_##R44 \ | ||
| 26 | ) | ||
| 27 | |||
| 28 | #endif | ||
diff --git a/keyboards/lily58/readme.md b/keyboards/lily58/readme.md index c71365e46..cbf0c1eeb 100644 --- a/keyboards/lily58/readme.md +++ b/keyboards/lily58/readme.md | |||
| @@ -2,16 +2,14 @@ | |||
| 2 | 2 | ||
| 3 | Lily58 is 6×4+5keys column-staggered split keyboard. | 3 | Lily58 is 6×4+5keys column-staggered split keyboard. |
| 4 | 4 | ||
| 5 |  | 5 |  |
| 6 | 6 |  | |
| 7 |  | ||
| 8 | |||
| 9 | Keyboard Maintainer: [Naoki Katahira](https://github.com/kata0510/) [Twitter:@F_YUUCHI](https://twitter.com/F_YUUCHI) | 7 | Keyboard Maintainer: [Naoki Katahira](https://github.com/kata0510/) [Twitter:@F_YUUCHI](https://twitter.com/F_YUUCHI) |
| 10 | Hardware Supported: Lily58 PCB, ProMicro | 8 | Hardware Supported: Lily58 PCB, ProMicro |
| 11 | Hardware Availability: [PCB & Case Data](https://github.com/kata0510/Lily58) | 9 | Hardware Availability: [PCB & Case Data](https://github.com/kata0510/Lily58) |
| 12 | 10 | ||
| 13 | Make example for this keyboard (after setting up your build environment): | 11 | Make example for this keyboard (after setting up your build environment): |
| 14 | 12 | ||
| 15 | make lily58:default | 13 | sudo make lily58:default |
| 16 | 14 | ||
| 17 | See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) and the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. Brand new to QMK? Start with our [Complete Newbs Guide](https://docs.qmk.fm/#/newbs). \ No newline at end of file | 15 | See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) and the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. Brand new to QMK? Start with our [Complete Newbs Guide](https://docs.qmk.fm/#/newbs). \ No newline at end of file |
diff --git a/keyboards/lily58/rev1/config.h b/keyboards/lily58/rev1/config.h index a991e8832..0dee6a694 100644 --- a/keyboards/lily58/rev1/config.h +++ b/keyboards/lily58/rev1/config.h | |||
| @@ -19,12 +19,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 19 | 19 | ||
| 20 | #pragma once | 20 | #pragma once |
| 21 | 21 | ||
| 22 | //#include QMK_KEYBOARD_CONFIG_H | ||
| 23 | #include "config_common.h" | ||
| 24 | |||
| 25 | /* USB Device descriptor parameter */ | 22 | /* USB Device descriptor parameter */ |
| 26 | #define VENDOR_ID 0xFC51 | 23 | #define VENDOR_ID 0xFC51 |
| 27 | #define PRODUCT_ID 0x0058 | 24 | #define PRODUCT_ID 0x0058 |
| 28 | #define DEVICE_VER 0x0100 | 25 | #define DEVICE_VER 0x0100 |
| 29 | #define MANUFACTURER F_YUUCHI | 26 | #define MANUFACTURER F_YUUCHI |
| 30 | #define PRODUCT Lily58 | 27 | #define PRODUCT Lily58 |
| @@ -51,9 +48,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 51 | #define DEBOUNCING_DELAY 5 | 48 | #define DEBOUNCING_DELAY 5 |
| 52 | 49 | ||
| 53 | /* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */ | 50 | /* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */ |
| 54 | #define LOCKING_SUPPORT_ENABLE | 51 | //#define LOCKING_SUPPORT_ENABLE |
| 55 | /* Locking resynchronize hack */ | 52 | /* Locking resynchronize hack */ |
| 56 | #define LOCKING_RESYNC_ENABLE | 53 | //#define LOCKING_RESYNC_ENABLE |
| 57 | 54 | ||
| 58 | /* key combination for command */ | 55 | /* key combination for command */ |
| 59 | #define IS_COMMAND() ( \ | 56 | #define IS_COMMAND() ( \ |
| @@ -62,8 +59,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 62 | 59 | ||
| 63 | /* ws2812 RGB LED */ | 60 | /* ws2812 RGB LED */ |
| 64 | #define RGB_DI_PIN D3 | 61 | #define RGB_DI_PIN D3 |
| 65 | 62 | #define RGBLED_NUM 12 // Number of LEDs | |
| 66 | #define RGBLED_NUM 14 // Number of LEDs | ||
| 67 | 63 | ||
| 68 | /* | 64 | /* |
| 69 | * Feature disable options | 65 | * Feature disable options |
| @@ -81,4 +77,4 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 81 | //#define NO_ACTION_TAPPING | 77 | //#define NO_ACTION_TAPPING |
| 82 | //#define NO_ACTION_ONESHOT | 78 | //#define NO_ACTION_ONESHOT |
| 83 | //#define NO_ACTION_MACRO | 79 | //#define NO_ACTION_MACRO |
| 84 | //#define NO_ACTION_FUNCTION | 80 | //#define NO_ACTION_FUNCTION \ No newline at end of file |
diff --git a/keyboards/lily58/rev1/matrix.c b/keyboards/lily58/rev1/matrix.c new file mode 100755 index 000000000..718cc5744 --- /dev/null +++ b/keyboards/lily58/rev1/matrix.c | |||
| @@ -0,0 +1,357 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2012 Jun Wako <wakojun@gmail.com> | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | /* | ||
| 19 | * scan matrix | ||
| 20 | */ | ||
| 21 | #include <stdint.h> | ||
| 22 | #include <stdbool.h> | ||
| 23 | #include <string.h> | ||
| 24 | #include <avr/io.h> | ||
| 25 | #include <avr/wdt.h> | ||
| 26 | #include <avr/interrupt.h> | ||
| 27 | #include <util/delay.h> | ||
| 28 | #include "print.h" | ||
| 29 | #include "debug.h" | ||
| 30 | #include "util.h" | ||
| 31 | #include "matrix.h" | ||
| 32 | #include "split_util.h" | ||
| 33 | #include "pro_micro.h" | ||
| 34 | |||
| 35 | #ifdef USE_MATRIX_I2C | ||
| 36 | # include "i2c.h" | ||
| 37 | #else // USE_SERIAL | ||
| 38 | # include "split_scomm.h" | ||
| 39 | #endif | ||
| 40 | |||
| 41 | #ifndef DEBOUNCE | ||
| 42 | # define DEBOUNCE 5 | ||
| 43 | #endif | ||
| 44 | |||
| 45 | #define ERROR_DISCONNECT_COUNT 5 | ||
| 46 | |||
| 47 | static uint8_t debouncing = DEBOUNCE; | ||
| 48 | static const int ROWS_PER_HAND = MATRIX_ROWS/2; | ||
| 49 | static uint8_t error_count = 0; | ||
| 50 | uint8_t is_master = 0 ; | ||
| 51 | |||
| 52 | static const uint8_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; | ||
| 53 | static const uint8_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; | ||
| 54 | |||
| 55 | /* matrix state(1:on, 0:off) */ | ||
| 56 | static matrix_row_t matrix[MATRIX_ROWS]; | ||
| 57 | static matrix_row_t matrix_debouncing[MATRIX_ROWS]; | ||
| 58 | |||
| 59 | static matrix_row_t read_cols(void); | ||
| 60 | static void init_cols(void); | ||
| 61 | static void unselect_rows(void); | ||
| 62 | static void select_row(uint8_t row); | ||
| 63 | static uint8_t matrix_master_scan(void); | ||
| 64 | |||
| 65 | |||
| 66 | __attribute__ ((weak)) | ||
| 67 | void matrix_init_kb(void) { | ||
| 68 | matrix_init_user(); | ||
| 69 | } | ||
| 70 | |||
| 71 | __attribute__ ((weak)) | ||
| 72 | void matrix_scan_kb(void) { | ||
| 73 | matrix_scan_user(); | ||
| 74 | } | ||
| 75 | |||
| 76 | __attribute__ ((weak)) | ||
| 77 | void matrix_init_user(void) { | ||
| 78 | } | ||
| 79 | |||
| 80 | __attribute__ ((weak)) | ||
| 81 | void matrix_scan_user(void) { | ||
| 82 | } | ||
| 83 | |||
| 84 | inline | ||
| 85 | uint8_t matrix_rows(void) | ||
| 86 | { | ||
| 87 | return MATRIX_ROWS; | ||
| 88 | } | ||
| 89 | |||
| 90 | inline | ||
| 91 | uint8_t matrix_cols(void) | ||
| 92 | { | ||
| 93 | return MATRIX_COLS; | ||
| 94 | } | ||
| 95 | |||
| 96 | void matrix_init(void) | ||
| 97 | { | ||
| 98 | debug_enable = true; | ||
| 99 | debug_matrix = true; | ||
| 100 | debug_mouse = true; | ||
| 101 | // initialize row and col | ||
| 102 | unselect_rows(); | ||
| 103 | init_cols(); | ||
| 104 | |||
| 105 | TX_RX_LED_INIT; | ||
| 106 | TXLED0; | ||
| 107 | RXLED0; | ||
| 108 | |||
| 109 | // initialize matrix state: all keys off | ||
| 110 | for (uint8_t i=0; i < MATRIX_ROWS; i++) { | ||
| 111 | matrix[i] = 0; | ||
| 112 | matrix_debouncing[i] = 0; | ||
| 113 | } | ||
| 114 | |||
| 115 | is_master = has_usb(); | ||
| 116 | |||
| 117 | matrix_init_quantum(); | ||
| 118 | } | ||
| 119 | |||
| 120 | uint8_t _matrix_scan(void) | ||
| 121 | { | ||
| 122 | // Right hand is stored after the left in the matirx so, we need to offset it | ||
| 123 | int offset = isLeftHand ? 0 : (ROWS_PER_HAND); | ||
| 124 | |||
| 125 | for (uint8_t i = 0; i < ROWS_PER_HAND; i++) { | ||
| 126 | select_row(i); | ||
| 127 | _delay_us(30); // without this wait read unstable value. | ||
| 128 | matrix_row_t cols = read_cols(); | ||
| 129 | if (matrix_debouncing[i+offset] != cols) { | ||
| 130 | matrix_debouncing[i+offset] = cols; | ||
| 131 | debouncing = DEBOUNCE; | ||
| 132 | } | ||
| 133 | unselect_rows(); | ||
| 134 | } | ||
| 135 | |||
| 136 | if (debouncing) { | ||
| 137 | if (--debouncing) { | ||
| 138 | _delay_ms(1); | ||
| 139 | } else { | ||
| 140 | for (uint8_t i = 0; i < ROWS_PER_HAND; i++) { | ||
| 141 | matrix[i+offset] = matrix_debouncing[i+offset]; | ||
| 142 | } | ||
| 143 | } | ||
| 144 | } | ||
| 145 | |||
| 146 | return 1; | ||
| 147 | } | ||
| 148 | |||
| 149 | #ifdef USE_MATRIX_I2C | ||
| 150 | |||
| 151 | // Get rows from other half over i2c | ||
| 152 | int i2c_transaction(void) { | ||
| 153 | int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; | ||
| 154 | |||
| 155 | int err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_WRITE); | ||
| 156 | if (err) goto i2c_error; | ||
| 157 | |||
| 158 | // start of matrix stored at 0x00 | ||
| 159 | err = i2c_master_write(0x00); | ||
| 160 | if (err) goto i2c_error; | ||
| 161 | |||
| 162 | // Start read | ||
| 163 | err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_READ); | ||
| 164 | if (err) goto i2c_error; | ||
| 165 | |||
| 166 | if (!err) { | ||
| 167 | int i; | ||
| 168 | for (i = 0; i < ROWS_PER_HAND-1; ++i) { | ||
| 169 | matrix[slaveOffset+i] = i2c_master_read(I2C_ACK); | ||
| 170 | } | ||
| 171 | matrix[slaveOffset+i] = i2c_master_read(I2C_NACK); | ||
| 172 | i2c_master_stop(); | ||
| 173 | } else { | ||
| 174 | i2c_error: // the cable is disconnceted, or something else went wrong | ||
| 175 | i2c_reset_state(); | ||
| 176 | return err; | ||
| 177 | } | ||
| 178 | |||
| 179 | return 0; | ||
| 180 | } | ||
| 181 | |||
| 182 | #else // USE_SERIAL | ||
| 183 | |||
| 184 | int serial_transaction(int master_changed) { | ||
| 185 | int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; | ||
| 186 | #ifdef SERIAL_USE_MULTI_TRANSACTION | ||
| 187 | int ret=serial_update_buffers(master_changed); | ||
| 188 | #else | ||
| 189 | int ret=serial_update_buffers(); | ||
| 190 | #endif | ||
| 191 | if (ret ) { | ||
| 192 | if(ret==2) RXLED1; | ||
| 193 | return 1; | ||
| 194 | } | ||
| 195 | RXLED0; | ||
| 196 | memcpy(&matrix[slaveOffset], | ||
| 197 | (void *)serial_slave_buffer, SERIAL_SLAVE_BUFFER_LENGTH); | ||
| 198 | return 0; | ||
| 199 | } | ||
| 200 | #endif | ||
| 201 | |||
| 202 | uint8_t matrix_scan(void) | ||
| 203 | { | ||
| 204 | if (is_master) { | ||
| 205 | matrix_master_scan(); | ||
| 206 | }else{ | ||
| 207 | matrix_slave_scan(); | ||
| 208 | int offset = (isLeftHand) ? ROWS_PER_HAND : 0; | ||
| 209 | memcpy(&matrix[offset], | ||
| 210 | (void *)serial_master_buffer, SERIAL_MASTER_BUFFER_LENGTH); | ||
| 211 | matrix_scan_quantum(); | ||
| 212 | } | ||
| 213 | return 1; | ||
| 214 | } | ||
| 215 | |||
| 216 | |||
| 217 | uint8_t matrix_master_scan(void) { | ||
| 218 | |||
| 219 | int ret = _matrix_scan(); | ||
| 220 | int mchanged = 1; | ||
| 221 | |||
| 222 | int offset = (isLeftHand) ? 0 : ROWS_PER_HAND; | ||
| 223 | |||
| 224 | #ifdef USE_MATRIX_I2C | ||
| 225 | // for (int i = 0; i < ROWS_PER_HAND; ++i) { | ||
| 226 | /* i2c_slave_buffer[i] = matrix[offset+i]; */ | ||
| 227 | // i2c_slave_buffer[i] = matrix[offset+i]; | ||
| 228 | // } | ||
| 229 | #else // USE_SERIAL | ||
| 230 | #ifdef SERIAL_USE_MULTI_TRANSACTION | ||
| 231 | mchanged = memcmp((void *)serial_master_buffer, | ||
| 232 | &matrix[offset], SERIAL_MASTER_BUFFER_LENGTH); | ||
| 233 | #endif | ||
| 234 | memcpy((void *)serial_master_buffer, | ||
| 235 | &matrix[offset], SERIAL_MASTER_BUFFER_LENGTH); | ||
| 236 | #endif | ||
| 237 | |||
| 238 | #ifdef USE_MATRIX_I2C | ||
| 239 | if( i2c_transaction() ) { | ||
| 240 | #else // USE_SERIAL | ||
| 241 | if( serial_transaction(mchanged) ) { | ||
| 242 | #endif | ||
| 243 | // turn on the indicator led when halves are disconnected | ||
| 244 | TXLED1; | ||
| 245 | |||
| 246 | error_count++; | ||
| 247 | |||
| 248 | if (error_count > ERROR_DISCONNECT_COUNT) { | ||
| 249 | // reset other half if disconnected | ||
| 250 | int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; | ||
| 251 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | ||
| 252 | matrix[slaveOffset+i] = 0; | ||
| 253 | } | ||
| 254 | } | ||
| 255 | } else { | ||
| 256 | // turn off the indicator led on no error | ||
| 257 | TXLED0; | ||
| 258 | error_count = 0; | ||
| 259 | } | ||
| 260 | matrix_scan_quantum(); | ||
| 261 | return ret; | ||
| 262 | } | ||
| 263 | |||
| 264 | void matrix_slave_scan(void) { | ||
| 265 | _matrix_scan(); | ||
| 266 | |||
| 267 | int offset = (isLeftHand) ? 0 : ROWS_PER_HAND; | ||
| 268 | |||
| 269 | #ifdef USE_MATRIX_I2C | ||
| 270 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | ||
| 271 | /* i2c_slave_buffer[i] = matrix[offset+i]; */ | ||
| 272 | i2c_slave_buffer[i] = matrix[offset+i]; | ||
| 273 | } | ||
| 274 | #else // USE_SERIAL | ||
| 275 | #ifdef SERIAL_USE_MULTI_TRANSACTION | ||
| 276 | int change = 0; | ||
| 277 | #endif | ||
| 278 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | ||
| 279 | #ifdef SERIAL_USE_MULTI_TRANSACTION | ||
| 280 | if( serial_slave_buffer[i] != matrix[offset+i] ) | ||
| 281 | change = 1; | ||
| 282 | #endif | ||
| 283 | serial_slave_buffer[i] = matrix[offset+i]; | ||
| 284 | } | ||
| 285 | #ifdef SERIAL_USE_MULTI_TRANSACTION | ||
| 286 | slave_buffer_change_count += change; | ||
| 287 | #endif | ||
| 288 | #endif | ||
| 289 | } | ||
| 290 | |||
| 291 | bool matrix_is_modified(void) | ||
| 292 | { | ||
| 293 | if (debouncing) return false; | ||
| 294 | return true; | ||
| 295 | } | ||
| 296 | |||
| 297 | inline | ||
| 298 | bool matrix_is_on(uint8_t row, uint8_t col) | ||
| 299 | { | ||
| 300 | return (matrix[row] & ((matrix_row_t)1<<col)); | ||
| 301 | } | ||
| 302 | |||
| 303 | inline | ||
| 304 | matrix_row_t matrix_get_row(uint8_t row) | ||
| 305 | { | ||
| 306 | return matrix[row]; | ||
| 307 | } | ||
| 308 | |||
| 309 | void matrix_print(void) | ||
| 310 | { | ||
| 311 | print("\nr/c 0123456789ABCDEF\n"); | ||
| 312 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
| 313 | phex(row); print(": "); | ||
| 314 | pbin_reverse16(matrix_get_row(row)); | ||
| 315 | print("\n"); | ||
| 316 | } | ||
| 317 | } | ||
| 318 | |||
| 319 | uint8_t matrix_key_count(void) | ||
| 320 | { | ||
| 321 | uint8_t count = 0; | ||
| 322 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | ||
| 323 | count += bitpop16(matrix[i]); | ||
| 324 | } | ||
| 325 | return count; | ||
| 326 | } | ||
| 327 | |||
| 328 | static void init_cols(void) | ||
| 329 | { | ||
| 330 | for(int x = 0; x < MATRIX_COLS; x++) { | ||
| 331 | _SFR_IO8((col_pins[x] >> 4) + 1) &= ~_BV(col_pins[x] & 0xF); | ||
| 332 | _SFR_IO8((col_pins[x] >> 4) + 2) |= _BV(col_pins[x] & 0xF); | ||
| 333 | } | ||
| 334 | } | ||
| 335 | |||
| 336 | static matrix_row_t read_cols(void) | ||
| 337 | { | ||
| 338 | matrix_row_t result = 0; | ||
| 339 | for(int x = 0; x < MATRIX_COLS; x++) { | ||
| 340 | result |= (_SFR_IO8(col_pins[x] >> 4) & _BV(col_pins[x] & 0xF)) ? 0 : (1 << x); | ||
| 341 | } | ||
| 342 | return result; | ||
| 343 | } | ||
| 344 | |||
| 345 | static void unselect_rows(void) | ||
| 346 | { | ||
| 347 | for(int x = 0; x < ROWS_PER_HAND; x++) { | ||
| 348 | _SFR_IO8((row_pins[x] >> 4) + 1) &= ~_BV(row_pins[x] & 0xF); | ||
| 349 | _SFR_IO8((row_pins[x] >> 4) + 2) |= _BV(row_pins[x] & 0xF); | ||
| 350 | } | ||
| 351 | } | ||
| 352 | |||
| 353 | static void select_row(uint8_t row) | ||
| 354 | { | ||
| 355 | _SFR_IO8((row_pins[row] >> 4) + 1) |= _BV(row_pins[row] & 0xF); | ||
| 356 | _SFR_IO8((row_pins[row] >> 4) + 2) &= ~_BV(row_pins[row] & 0xF); | ||
| 357 | } | ||
diff --git a/keyboards/lily58/rev1/rev1.c b/keyboards/lily58/rev1/rev1.c index 4c54d7717..e78f2ccfa 100644 --- a/keyboards/lily58/rev1/rev1.c +++ b/keyboards/lily58/rev1/rev1.c | |||
| @@ -1,14 +1,8 @@ | |||
| 1 | #include "lily58.h" | 1 | #include "lily58.h" |
| 2 | 2 | ||
| 3 | void matrix_init_kb(void) { | 3 | #ifdef SSD1306OLED |
| 4 | 4 | void led_set_kb(uint8_t usb_led) { | |
| 5 | // // green led on | 5 | // put your keyboard LED indicator (ex: Caps Lock LED) toggling code here |
| 6 | // DDRD |= (1<<5); | 6 | //led_set_user(usb_led); |
| 7 | // PORTD &= ~(1<<5); | 7 | } |
| 8 | 8 | #endif \ No newline at end of file | |
| 9 | // // orange led on | ||
| 10 | // DDRB |= (1<<0); | ||
| 11 | // PORTB &= ~(1<<0); | ||
| 12 | |||
| 13 | matrix_init_user(); | ||
| 14 | }; \ No newline at end of file | ||
diff --git a/keyboards/lily58/rev1/rev1.h b/keyboards/lily58/rev1/rev1.h index a83046358..4949bf537 100644 --- a/keyboards/lily58/rev1/rev1.h +++ b/keyboards/lily58/rev1/rev1.h | |||
| @@ -5,6 +5,10 @@ | |||
| 5 | //void promicro_bootloader_jmp(bool program); | 5 | //void promicro_bootloader_jmp(bool program); |
| 6 | #include "quantum.h" | 6 | #include "quantum.h" |
| 7 | 7 | ||
| 8 | #ifdef RGBLIGHT_ENABLE | ||
| 9 | //rgb led driver | ||
| 10 | #include "ws2812.h" | ||
| 11 | #endif | ||
| 8 | 12 | ||
| 9 | #ifdef USE_I2C | 13 | #ifdef USE_I2C |
| 10 | #include <stddef.h> | 14 | #include <stddef.h> |
diff --git a/keyboards/lily58/rev1/rules.mk b/keyboards/lily58/rev1/rules.mk index f84561674..7fc101bf2 100644 --- a/keyboards/lily58/rev1/rules.mk +++ b/keyboards/lily58/rev1/rules.mk | |||
| @@ -1 +1,3 @@ | |||
| 1 | BACKLIGHT_ENABLE = no \ No newline at end of file | 1 | SRC += rev1/matrix.c |
| 2 | SRC += rev1/split_util.c | ||
| 3 | SRC += rev1/split_scomm.c \ No newline at end of file | ||
diff --git a/keyboards/lily58/rev1/serial_config.h b/keyboards/lily58/rev1/serial_config.h new file mode 100755 index 000000000..4fab8e8dd --- /dev/null +++ b/keyboards/lily58/rev1/serial_config.h | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | #ifndef SOFT_SERIAL_PIN | ||
| 2 | #define SOFT_SERIAL_PIN D2 | ||
| 3 | #define SERIAL_USE_MULTI_TRANSACTION | ||
| 4 | #endif | ||
diff --git a/keyboards/lily58/rev1/split_scomm.c b/keyboards/lily58/rev1/split_scomm.c new file mode 100755 index 000000000..a1fe6ba5b --- /dev/null +++ b/keyboards/lily58/rev1/split_scomm.c | |||
| @@ -0,0 +1,91 @@ | |||
| 1 | #ifdef USE_SERIAL | ||
| 2 | #ifdef SERIAL_USE_MULTI_TRANSACTION | ||
| 3 | /* --- USE flexible API (using multi-type transaction function) --- */ | ||
| 4 | |||
| 5 | #include <stdbool.h> | ||
| 6 | #include <stdint.h> | ||
| 7 | #include <stddef.h> | ||
| 8 | #include <split_scomm.h> | ||
| 9 | #include "serial.h" | ||
| 10 | #ifdef CONSOLE_ENABLE | ||
| 11 | #include <print.h> | ||
| 12 | #endif | ||
| 13 | |||
| 14 | uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0}; | ||
| 15 | uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0}; | ||
| 16 | uint8_t volatile status_com = 0; | ||
| 17 | uint8_t volatile status1 = 0; | ||
| 18 | uint8_t slave_buffer_change_count = 0; | ||
| 19 | uint8_t s_change_old = 0xff; | ||
| 20 | uint8_t s_change_new = 0xff; | ||
| 21 | |||
| 22 | SSTD_t transactions[] = { | ||
| 23 | #define GET_SLAVE_STATUS 0 | ||
| 24 | /* master buffer not changed, only recive slave_buffer_change_count */ | ||
| 25 | { (uint8_t *)&status_com, | ||
| 26 | 0, NULL, | ||
| 27 | sizeof(slave_buffer_change_count), &slave_buffer_change_count, | ||
| 28 | }, | ||
| 29 | #define PUT_MASTER_GET_SLAVE_STATUS 1 | ||
| 30 | /* master buffer changed need send, and recive slave_buffer_change_count */ | ||
| 31 | { (uint8_t *)&status_com, | ||
| 32 | sizeof(serial_master_buffer), (uint8_t *)serial_master_buffer, | ||
| 33 | sizeof(slave_buffer_change_count), &slave_buffer_change_count, | ||
| 34 | }, | ||
| 35 | #define GET_SLAVE_BUFFER 2 | ||
| 36 | /* recive serial_slave_buffer */ | ||
| 37 | { (uint8_t *)&status1, | ||
| 38 | 0, NULL, | ||
| 39 | sizeof(serial_slave_buffer), (uint8_t *)serial_slave_buffer | ||
| 40 | } | ||
| 41 | }; | ||
| 42 | |||
| 43 | void serial_master_init(void) | ||
| 44 | { | ||
| 45 | soft_serial_initiator_init(transactions, TID_LIMIT(transactions)); | ||
| 46 | } | ||
| 47 | |||
| 48 | void serial_slave_init(void) | ||
| 49 | { | ||
| 50 | soft_serial_target_init(transactions, TID_LIMIT(transactions)); | ||
| 51 | } | ||
| 52 | |||
| 53 | // 0 => no error | ||
| 54 | // 1 => slave did not respond | ||
| 55 | // 2 => checksum error | ||
| 56 | int serial_update_buffers(int master_update) | ||
| 57 | { | ||
| 58 | int status, smatstatus; | ||
| 59 | static int need_retry = 0; | ||
| 60 | |||
| 61 | if( s_change_old != s_change_new ) { | ||
| 62 | smatstatus = soft_serial_transaction(GET_SLAVE_BUFFER); | ||
| 63 | if( smatstatus == TRANSACTION_END ) { | ||
| 64 | s_change_old = s_change_new; | ||
| 65 | #ifdef CONSOLE_ENABLE | ||
| 66 | uprintf("slave matrix = %b %b %b %b\n", | ||
| 67 | serial_slave_buffer[0], serial_slave_buffer[1], | ||
| 68 | serial_slave_buffer[2], serial_slave_buffer[3]); | ||
| 69 | #endif | ||
| 70 | } | ||
| 71 | } else { | ||
| 72 | // serial_slave_buffer dosen't change | ||
| 73 | smatstatus = TRANSACTION_END; // dummy status | ||
| 74 | } | ||
| 75 | |||
| 76 | if( !master_update && !need_retry) { | ||
| 77 | status = soft_serial_transaction(GET_SLAVE_STATUS); | ||
| 78 | } else { | ||
| 79 | status = soft_serial_transaction(PUT_MASTER_GET_SLAVE_STATUS); | ||
| 80 | } | ||
| 81 | if( status == TRANSACTION_END ) { | ||
| 82 | s_change_new = slave_buffer_change_count; | ||
| 83 | need_retry = 0; | ||
| 84 | } else { | ||
| 85 | need_retry = 1; | ||
| 86 | } | ||
| 87 | return smatstatus; | ||
| 88 | } | ||
| 89 | |||
| 90 | #endif // SERIAL_USE_MULTI_TRANSACTION | ||
| 91 | #endif /* USE_SERIAL */ | ||
diff --git a/keyboards/lily58/rev1/split_scomm.h b/keyboards/lily58/rev1/split_scomm.h new file mode 100755 index 000000000..873d8939d --- /dev/null +++ b/keyboards/lily58/rev1/split_scomm.h | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | #ifndef SPLIT_COMM_H | ||
| 2 | #define SPLIT_COMM_H | ||
| 3 | |||
| 4 | #ifndef SERIAL_USE_MULTI_TRANSACTION | ||
| 5 | /* --- USE Simple API (OLD API, compatible with let's split serial.c) --- */ | ||
| 6 | #include "serial.h" | ||
| 7 | |||
| 8 | #else | ||
| 9 | /* --- USE flexible API (using multi-type transaction function) --- */ | ||
| 10 | // Buffers for master - slave communication | ||
| 11 | #define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2 | ||
| 12 | #define SERIAL_MASTER_BUFFER_LENGTH MATRIX_ROWS/2 | ||
| 13 | |||
| 14 | extern volatile uint8_t serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH]; | ||
| 15 | extern volatile uint8_t serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH]; | ||
| 16 | extern uint8_t slave_buffer_change_count; | ||
| 17 | |||
| 18 | void serial_master_init(void); | ||
| 19 | void serial_slave_init(void); | ||
| 20 | int serial_update_buffers(int master_changed); | ||
| 21 | |||
| 22 | #endif | ||
| 23 | |||
| 24 | #endif /* SPLIT_COMM_H */ | ||
diff --git a/keyboards/lily58/rev1/split_util.c b/keyboards/lily58/rev1/split_util.c new file mode 100755 index 000000000..e1ff8b437 --- /dev/null +++ b/keyboards/lily58/rev1/split_util.c | |||
| @@ -0,0 +1,70 @@ | |||
| 1 | #include <avr/io.h> | ||
| 2 | #include <avr/wdt.h> | ||
| 3 | #include <avr/power.h> | ||
| 4 | #include <avr/interrupt.h> | ||
| 5 | #include <util/delay.h> | ||
| 6 | #include <avr/eeprom.h> | ||
| 7 | #include "split_util.h" | ||
| 8 | #include "matrix.h" | ||
| 9 | #include "keyboard.h" | ||
| 10 | |||
| 11 | #ifdef USE_MATRIX_I2C | ||
| 12 | # include "i2c.h" | ||
| 13 | #else | ||
| 14 | # include "split_scomm.h" | ||
| 15 | #endif | ||
| 16 | |||
| 17 | volatile bool isLeftHand = true; | ||
| 18 | |||
| 19 | static void setup_handedness(void) { | ||
| 20 | #ifdef EE_HANDS | ||
| 21 | isLeftHand = eeprom_read_byte(EECONFIG_HANDEDNESS); | ||
| 22 | #else | ||
| 23 | // I2C_MASTER_RIGHT is deprecated, use MASTER_RIGHT instead, since this works for both serial and i2c | ||
| 24 | #if defined(I2C_MASTER_RIGHT) || defined(MASTER_RIGHT) | ||
| 25 | isLeftHand = !has_usb(); | ||
| 26 | #else | ||
| 27 | isLeftHand = has_usb(); | ||
| 28 | #endif | ||
| 29 | #endif | ||
| 30 | } | ||
| 31 | |||
| 32 | static void keyboard_master_setup(void) { | ||
| 33 | |||
| 34 | #ifdef USE_MATRIX_I2C | ||
| 35 | i2c_master_init(); | ||
| 36 | #else | ||
| 37 | serial_master_init(); | ||
| 38 | #endif | ||
| 39 | } | ||
| 40 | |||
| 41 | static void keyboard_slave_setup(void) { | ||
| 42 | |||
| 43 | #ifdef USE_MATRIX_I2C | ||
| 44 | i2c_slave_init(SLAVE_I2C_ADDRESS); | ||
| 45 | #else | ||
| 46 | serial_slave_init(); | ||
| 47 | #endif | ||
| 48 | } | ||
| 49 | |||
| 50 | bool has_usb(void) { | ||
| 51 | USBCON |= (1 << OTGPADE); //enables VBUS pad | ||
| 52 | _delay_us(5); | ||
| 53 | return (USBSTA & (1<<VBUS)); //checks state of VBUS | ||
| 54 | } | ||
| 55 | |||
| 56 | void split_keyboard_setup(void) { | ||
| 57 | setup_handedness(); | ||
| 58 | |||
| 59 | if (has_usb()) { | ||
| 60 | keyboard_master_setup(); | ||
| 61 | } else { | ||
| 62 | keyboard_slave_setup(); | ||
| 63 | } | ||
| 64 | sei(); | ||
| 65 | } | ||
| 66 | |||
| 67 | // this code runs before the usb and keyboard is initialized | ||
| 68 | void matrix_setup(void) { | ||
| 69 | split_keyboard_setup(); | ||
| 70 | } | ||
diff --git a/keyboards/lily58/rev1/split_util.h b/keyboards/lily58/rev1/split_util.h new file mode 100755 index 000000000..687ca19bd --- /dev/null +++ b/keyboards/lily58/rev1/split_util.h | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | #ifndef SPLIT_KEYBOARD_UTIL_H | ||
| 2 | #define SPLIT_KEYBOARD_UTIL_H | ||
| 3 | |||
| 4 | #include <stdbool.h> | ||
| 5 | #include "eeconfig.h" | ||
| 6 | |||
| 7 | #define SLAVE_I2C_ADDRESS 0x32 | ||
| 8 | |||
| 9 | extern volatile bool isLeftHand; | ||
| 10 | |||
| 11 | // slave version of matix scan, defined in matrix.c | ||
| 12 | void matrix_slave_scan(void); | ||
| 13 | |||
| 14 | void split_keyboard_setup(void); | ||
| 15 | bool has_usb(void); | ||
| 16 | |||
| 17 | void matrix_master_OLED_init (void); | ||
| 18 | |||
| 19 | #endif | ||
diff --git a/keyboards/lily58/rules.mk b/keyboards/lily58/rules.mk index ad8ad585e..f6b922eea 100644 --- a/keyboards/lily58/rules.mk +++ b/keyboards/lily58/rules.mk | |||
| @@ -1,7 +1,10 @@ | |||
| 1 | SRC += matrix.c \ | 1 | SRC += i2c.c |
| 2 | i2c.c \ | 2 | SRC += serial.c |
| 3 | split_util.c \ | 3 | SRC += ssd1306.c |
| 4 | serial.c | 4 | |
| 5 | # if firmware size over limit, try this option | ||
| 6 | # CFLAGS += -flto | ||
| 7 | |||
| 5 | # MCU name | 8 | # MCU name |
| 6 | #MCU = at90usb1287 | 9 | #MCU = at90usb1287 |
| 7 | MCU = atmega32u4 | 10 | MCU = atmega32u4 |
| @@ -38,16 +41,15 @@ ARCH = AVR8 | |||
| 38 | # CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU. | 41 | # CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU. |
| 39 | F_USB = $(F_CPU) | 42 | F_USB = $(F_CPU) |
| 40 | 43 | ||
| 41 | # Interrupt driven control endpoint task(+60) | ||
| 42 | OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT | ||
| 43 | |||
| 44 | |||
| 45 | # Bootloader | 44 | # Bootloader |
| 46 | # This definition is optional, and if your keyboard supports multiple bootloaders of | 45 | # This definition is optional, and if your keyboard supports multiple bootloaders of |
| 47 | # different sizes, comment this out, and the correct address will be loaded | 46 | # different sizes, comment this out, and the correct address will be loaded |
| 48 | # automatically (+60). See bootloader.mk for all options. | 47 | # automatically (+60). See bootloader.mk for all options. |
| 49 | BOOTLOADER = caterina | 48 | BOOTLOADER = caterina |
| 50 | 49 | ||
| 50 | # Interrupt driven control endpoint task(+60) | ||
| 51 | OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT | ||
| 52 | |||
| 51 | # Build Options | 53 | # Build Options |
| 52 | # change to "no" to disable the options, or define them in the Makefile in | 54 | # change to "no" to disable the options, or define them in the Makefile in |
| 53 | # the appropriate keymap folder that will get included automatically | 55 | # the appropriate keymap folder that will get included automatically |
| @@ -65,7 +67,7 @@ UNICODE_ENABLE = no # Unicode | |||
| 65 | BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID | 67 | BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID |
| 66 | RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight. | 68 | RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight. |
| 67 | SUBPROJECT_rev1 = no | 69 | SUBPROJECT_rev1 = no |
| 68 | USE_I2C = no | 70 | USE_I2C = yes |
| 69 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE | 71 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE |
| 70 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend | 72 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend |
| 71 | 73 | ||
diff --git a/keyboards/lily58/serial.c b/keyboards/lily58/serial.c index f85dc28dc..325c29a3f 100644..100755 --- a/keyboards/lily58/serial.c +++ b/keyboards/lily58/serial.c | |||
| @@ -1,5 +1,10 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * WARNING: be careful changing this code, it is very timing dependent | 2 | * WARNING: be careful changing this code, it is very timing dependent |
| 3 | * | ||
| 4 | * 2018-10-28 checked | ||
| 5 | * avr-gcc 4.9.2 | ||
| 6 | * avr-gcc 5.4.0 | ||
| 7 | * avr-gcc 7.3.0 | ||
| 3 | */ | 8 | */ |
| 4 | 9 | ||
| 5 | #ifndef F_CPU | 10 | #ifndef F_CPU |
| @@ -14,9 +19,58 @@ | |||
| 14 | #include "serial.h" | 19 | #include "serial.h" |
| 15 | //#include <pro_micro.h> | 20 | //#include <pro_micro.h> |
| 16 | 21 | ||
| 17 | #ifdef USE_SERIAL | 22 | #ifdef SOFT_SERIAL_PIN |
| 18 | //#ifndef USE_SERIAL_PD2 | ||
| 19 | 23 | ||
| 24 | #ifdef __AVR_ATmega32U4__ | ||
| 25 | // if using ATmega32U4 I2C, can not use PD0 and PD1 in soft serial. | ||
| 26 | #ifdef USE_I2C | ||
| 27 | #if SOFT_SERIAL_PIN == D0 || SOFT_SERIAL_PIN == D1 | ||
| 28 | #error Using ATmega32U4 I2C, so can not use PD0, PD1 | ||
| 29 | #endif | ||
| 30 | #endif | ||
| 31 | |||
| 32 | #if SOFT_SERIAL_PIN >= D0 && SOFT_SERIAL_PIN <= D3 | ||
| 33 | #define SERIAL_PIN_DDR DDRD | ||
| 34 | #define SERIAL_PIN_PORT PORTD | ||
| 35 | #define SERIAL_PIN_INPUT PIND | ||
| 36 | #if SOFT_SERIAL_PIN == D0 | ||
| 37 | #define SERIAL_PIN_MASK _BV(PD0) | ||
| 38 | #define EIMSK_BIT _BV(INT0) | ||
| 39 | #define EICRx_BIT (~(_BV(ISC00) | _BV(ISC01))) | ||
| 40 | #define SERIAL_PIN_INTERRUPT INT0_vect | ||
| 41 | #elif SOFT_SERIAL_PIN == D1 | ||
| 42 | #define SERIAL_PIN_MASK _BV(PD1) | ||
| 43 | #define EIMSK_BIT _BV(INT1) | ||
| 44 | #define EICRx_BIT (~(_BV(ISC10) | _BV(ISC11))) | ||
| 45 | #define SERIAL_PIN_INTERRUPT INT1_vect | ||
| 46 | #elif SOFT_SERIAL_PIN == D2 | ||
| 47 | #define SERIAL_PIN_MASK _BV(PD2) | ||
| 48 | #define EIMSK_BIT _BV(INT2) | ||
| 49 | #define EICRx_BIT (~(_BV(ISC20) | _BV(ISC21))) | ||
| 50 | #define SERIAL_PIN_INTERRUPT INT2_vect | ||
| 51 | #elif SOFT_SERIAL_PIN == D3 | ||
| 52 | #define SERIAL_PIN_MASK _BV(PD3) | ||
| 53 | #define EIMSK_BIT _BV(INT3) | ||
| 54 | #define EICRx_BIT (~(_BV(ISC30) | _BV(ISC31))) | ||
| 55 | #define SERIAL_PIN_INTERRUPT INT3_vect | ||
| 56 | #endif | ||
| 57 | #elif SOFT_SERIAL_PIN == E6 | ||
| 58 | #define SERIAL_PIN_DDR DDRE | ||
| 59 | #define SERIAL_PIN_PORT PORTE | ||
| 60 | #define SERIAL_PIN_INPUT PINE | ||
| 61 | #define SERIAL_PIN_MASK _BV(PE6) | ||
| 62 | #define EIMSK_BIT _BV(INT6) | ||
| 63 | #define EICRx_BIT (~(_BV(ISC60) | _BV(ISC61))) | ||
| 64 | #define SERIAL_PIN_INTERRUPT INT6_vect | ||
| 65 | #else | ||
| 66 | #error invalid SOFT_SERIAL_PIN value | ||
| 67 | #endif | ||
| 68 | |||
| 69 | #else | ||
| 70 | #error serial.c now support ATmega32U4 only | ||
| 71 | #endif | ||
| 72 | |||
| 73 | //////////////// for backward compatibility //////////////////////////////// | ||
| 20 | #ifndef SERIAL_USE_MULTI_TRANSACTION | 74 | #ifndef SERIAL_USE_MULTI_TRANSACTION |
| 21 | /* --- USE Simple API (OLD API, compatible with let's split serial.c) */ | 75 | /* --- USE Simple API (OLD API, compatible with let's split serial.c) */ |
| 22 | #if SERIAL_SLAVE_BUFFER_LENGTH > 0 | 76 | #if SERIAL_SLAVE_BUFFER_LENGTH > 0 |
| @@ -43,56 +97,118 @@ SSTD_t transactions[] = { | |||
| 43 | }; | 97 | }; |
| 44 | 98 | ||
| 45 | void serial_master_init(void) | 99 | void serial_master_init(void) |
| 46 | { soft_serial_initiator_init(transactions); } | 100 | { soft_serial_initiator_init(transactions, TID_LIMIT(transactions)); } |
| 47 | 101 | ||
| 48 | void serial_slave_init(void) | 102 | void serial_slave_init(void) |
| 49 | { soft_serial_target_init(transactions); } | 103 | { soft_serial_target_init(transactions, TID_LIMIT(transactions)); } |
| 50 | 104 | ||
| 51 | // 0 => no error | 105 | // 0 => no error |
| 52 | // 1 => slave did not respond | 106 | // 1 => slave did not respond |
| 53 | // 2 => checksum error | 107 | // 2 => checksum error |
| 54 | int serial_update_buffers() | 108 | int serial_update_buffers() |
| 55 | { return soft_serial_transaction(); } | 109 | { |
| 110 | int result; | ||
| 111 | result = soft_serial_transaction(); | ||
| 112 | return result; | ||
| 113 | } | ||
| 56 | 114 | ||
| 57 | #endif // Simple API (OLD API, compatible with let's split serial.c) | 115 | #endif // end of Simple API (OLD API, compatible with let's split serial.c) |
| 116 | //////////////////////////////////////////////////////////////////////////// | ||
| 58 | 117 | ||
| 59 | #define ALWAYS_INLINE __attribute__((always_inline)) | 118 | #define ALWAYS_INLINE __attribute__((always_inline)) |
| 60 | #define NO_INLINE __attribute__((noinline)) | 119 | #define NO_INLINE __attribute__((noinline)) |
| 61 | #define _delay_sub_us(x) __builtin_avr_delay_cycles(x) | 120 | #define _delay_sub_us(x) __builtin_avr_delay_cycles(x) |
| 62 | 121 | ||
| 63 | // Serial pulse period in microseconds. | 122 | // parity check |
| 64 | #define TID_SEND_ADJUST 14 | 123 | #define ODD_PARITY 1 |
| 124 | #define EVEN_PARITY 0 | ||
| 125 | #define PARITY EVEN_PARITY | ||
| 126 | |||
| 127 | #ifdef SERIAL_DELAY | ||
| 128 | // custom setup in config.h | ||
| 129 | // #define TID_SEND_ADJUST 2 | ||
| 130 | // #define SERIAL_DELAY 6 // micro sec | ||
| 131 | // #define READ_WRITE_START_ADJUST 30 // cycles | ||
| 132 | // #define READ_WRITE_WIDTH_ADJUST 8 // cycles | ||
| 133 | #else | ||
| 134 | // ============ Standard setups ============ | ||
| 135 | |||
| 136 | #ifndef SELECT_SOFT_SERIAL_SPEED | ||
| 137 | #define SELECT_SOFT_SERIAL_SPEED 1 | ||
| 138 | // 0: about 189kbps | ||
| 139 | // 1: about 137kbps (default) | ||
| 140 | // 2: about 75kbps | ||
| 141 | // 3: about 39kbps | ||
| 142 | // 4: about 26kbps | ||
| 143 | // 5: about 20kbps | ||
| 144 | #endif | ||
| 65 | 145 | ||
| 66 | #define SELECT_SERIAL_SPEED 1 | 146 | #if __GNUC__ < 6 |
| 67 | #if SELECT_SERIAL_SPEED == 0 | 147 | #define TID_SEND_ADJUST 14 |
| 148 | #else | ||
| 149 | #define TID_SEND_ADJUST 2 | ||
| 150 | #endif | ||
| 151 | |||
| 152 | #if SELECT_SOFT_SERIAL_SPEED == 0 | ||
| 68 | // Very High speed | 153 | // Very High speed |
| 69 | #define SERIAL_DELAY 4 // micro sec | 154 | #define SERIAL_DELAY 4 // micro sec |
| 70 | #define READ_WRITE_START_ADJUST 33 // cycles | 155 | #if __GNUC__ < 6 |
| 71 | #define READ_WRITE_WIDTH_ADJUST 3 // cycles | 156 | #define READ_WRITE_START_ADJUST 33 // cycles |
| 72 | #elif SELECT_SERIAL_SPEED == 1 | 157 | #define READ_WRITE_WIDTH_ADJUST 3 // cycles |
| 158 | #else | ||
| 159 | #define READ_WRITE_START_ADJUST 34 // cycles | ||
| 160 | #define READ_WRITE_WIDTH_ADJUST 7 // cycles | ||
| 161 | #endif | ||
| 162 | #elif SELECT_SOFT_SERIAL_SPEED == 1 | ||
| 73 | // High speed | 163 | // High speed |
| 74 | #define SERIAL_DELAY 6 // micro sec | 164 | #define SERIAL_DELAY 6 // micro sec |
| 75 | #define READ_WRITE_START_ADJUST 30 // cycles | 165 | #if __GNUC__ < 6 |
| 76 | #define READ_WRITE_WIDTH_ADJUST 3 // cycles | 166 | #define READ_WRITE_START_ADJUST 30 // cycles |
| 77 | #elif SELECT_SERIAL_SPEED == 2 | 167 | #define READ_WRITE_WIDTH_ADJUST 3 // cycles |
| 168 | #else | ||
| 169 | #define READ_WRITE_START_ADJUST 33 // cycles | ||
| 170 | #define READ_WRITE_WIDTH_ADJUST 7 // cycles | ||
| 171 | #endif | ||
| 172 | #elif SELECT_SOFT_SERIAL_SPEED == 2 | ||
| 78 | // Middle speed | 173 | // Middle speed |
| 79 | #define SERIAL_DELAY 12 // micro sec | 174 | #define SERIAL_DELAY 12 // micro sec |
| 80 | #define READ_WRITE_START_ADJUST 30 // cycles | 175 | #define READ_WRITE_START_ADJUST 30 // cycles |
| 81 | #define READ_WRITE_WIDTH_ADJUST 3 // cycles | 176 | #if __GNUC__ < 6 |
| 82 | #elif SELECT_SERIAL_SPEED == 3 | 177 | #define READ_WRITE_WIDTH_ADJUST 3 // cycles |
| 178 | #else | ||
| 179 | #define READ_WRITE_WIDTH_ADJUST 7 // cycles | ||
| 180 | #endif | ||
| 181 | #elif SELECT_SOFT_SERIAL_SPEED == 3 | ||
| 83 | // Low speed | 182 | // Low speed |
| 84 | #define SERIAL_DELAY 24 // micro sec | 183 | #define SERIAL_DELAY 24 // micro sec |
| 85 | #define READ_WRITE_START_ADJUST 30 // cycles | 184 | #define READ_WRITE_START_ADJUST 30 // cycles |
| 86 | #define READ_WRITE_WIDTH_ADJUST 3 // cycles | 185 | #if __GNUC__ < 6 |
| 87 | #elif SELECT_SERIAL_SPEED == 4 | 186 | #define READ_WRITE_WIDTH_ADJUST 3 // cycles |
| 187 | #else | ||
| 188 | #define READ_WRITE_WIDTH_ADJUST 7 // cycles | ||
| 189 | #endif | ||
| 190 | #elif SELECT_SOFT_SERIAL_SPEED == 4 | ||
| 88 | // Very Low speed | 191 | // Very Low speed |
| 89 | #define SERIAL_DELAY 50 // micro sec | 192 | #define SERIAL_DELAY 36 // micro sec |
| 193 | #define READ_WRITE_START_ADJUST 30 // cycles | ||
| 194 | #if __GNUC__ < 6 | ||
| 195 | #define READ_WRITE_WIDTH_ADJUST 3 // cycles | ||
| 196 | #else | ||
| 197 | #define READ_WRITE_WIDTH_ADJUST 7 // cycles | ||
| 198 | #endif | ||
| 199 | #elif SELECT_SOFT_SERIAL_SPEED == 5 | ||
| 200 | // Ultra Low speed | ||
| 201 | #define SERIAL_DELAY 48 // micro sec | ||
| 90 | #define READ_WRITE_START_ADJUST 30 // cycles | 202 | #define READ_WRITE_START_ADJUST 30 // cycles |
| 91 | #define READ_WRITE_WIDTH_ADJUST 3 // cycles | 203 | #if __GNUC__ < 6 |
| 204 | #define READ_WRITE_WIDTH_ADJUST 3 // cycles | ||
| 205 | #else | ||
| 206 | #define READ_WRITE_WIDTH_ADJUST 7 // cycles | ||
| 207 | #endif | ||
| 92 | #else | 208 | #else |
| 93 | #error Illegal Serial Speed | 209 | #error invalid SELECT_SOFT_SERIAL_SPEED value |
| 94 | #endif | 210 | #endif /* SELECT_SOFT_SERIAL_SPEED */ |
| 95 | 211 | #endif /* SERIAL_DELAY */ | |
| 96 | 212 | ||
| 97 | #define SERIAL_DELAY_HALF1 (SERIAL_DELAY/2) | 213 | #define SERIAL_DELAY_HALF1 (SERIAL_DELAY/2) |
| 98 | #define SERIAL_DELAY_HALF2 (SERIAL_DELAY - SERIAL_DELAY/2) | 214 | #define SERIAL_DELAY_HALF2 (SERIAL_DELAY - SERIAL_DELAY/2) |
| @@ -106,17 +222,21 @@ int serial_update_buffers() | |||
| 106 | #endif | 222 | #endif |
| 107 | 223 | ||
| 108 | static SSTD_t *Transaction_table = NULL; | 224 | static SSTD_t *Transaction_table = NULL; |
| 225 | static uint8_t Transaction_table_size = 0; | ||
| 109 | 226 | ||
| 227 | inline static void serial_delay(void) ALWAYS_INLINE; | ||
| 110 | inline static | 228 | inline static |
| 111 | void serial_delay(void) { | 229 | void serial_delay(void) { |
| 112 | _delay_us(SERIAL_DELAY); | 230 | _delay_us(SERIAL_DELAY); |
| 113 | } | 231 | } |
| 114 | 232 | ||
| 233 | inline static void serial_delay_half1(void) ALWAYS_INLINE; | ||
| 115 | inline static | 234 | inline static |
| 116 | void serial_delay_half1(void) { | 235 | void serial_delay_half1(void) { |
| 117 | _delay_us(SERIAL_DELAY_HALF1); | 236 | _delay_us(SERIAL_DELAY_HALF1); |
| 118 | } | 237 | } |
| 119 | 238 | ||
| 239 | inline static void serial_delay_half2(void) ALWAYS_INLINE; | ||
| 120 | inline static | 240 | inline static |
| 121 | void serial_delay_half2(void) { | 241 | void serial_delay_half2(void) { |
| 122 | _delay_us(SERIAL_DELAY_HALF2); | 242 | _delay_us(SERIAL_DELAY_HALF2); |
| @@ -136,6 +256,7 @@ void serial_input_with_pullup(void) { | |||
| 136 | SERIAL_PIN_PORT |= SERIAL_PIN_MASK; | 256 | SERIAL_PIN_PORT |= SERIAL_PIN_MASK; |
| 137 | } | 257 | } |
| 138 | 258 | ||
| 259 | inline static uint8_t serial_read_pin(void) ALWAYS_INLINE; | ||
| 139 | inline static | 260 | inline static |
| 140 | uint8_t serial_read_pin(void) { | 261 | uint8_t serial_read_pin(void) { |
| 141 | return !!(SERIAL_PIN_INPUT & SERIAL_PIN_MASK); | 262 | return !!(SERIAL_PIN_INPUT & SERIAL_PIN_MASK); |
| @@ -153,30 +274,28 @@ void serial_high(void) { | |||
| 153 | SERIAL_PIN_PORT |= SERIAL_PIN_MASK; | 274 | SERIAL_PIN_PORT |= SERIAL_PIN_MASK; |
| 154 | } | 275 | } |
| 155 | 276 | ||
| 156 | void soft_serial_initiator_init(SSTD_t *sstd_table) | 277 | void soft_serial_initiator_init(SSTD_t *sstd_table, int sstd_table_size) |
| 157 | { | 278 | { |
| 158 | Transaction_table = sstd_table; | 279 | Transaction_table = sstd_table; |
| 280 | Transaction_table_size = (uint8_t)sstd_table_size; | ||
| 159 | serial_output(); | 281 | serial_output(); |
| 160 | serial_high(); | 282 | serial_high(); |
| 161 | } | 283 | } |
| 162 | 284 | ||
| 163 | void soft_serial_target_init(SSTD_t *sstd_table) | 285 | void soft_serial_target_init(SSTD_t *sstd_table, int sstd_table_size) |
| 164 | { | 286 | { |
| 165 | Transaction_table = sstd_table; | 287 | Transaction_table = sstd_table; |
| 288 | Transaction_table_size = (uint8_t)sstd_table_size; | ||
| 166 | serial_input_with_pullup(); | 289 | serial_input_with_pullup(); |
| 167 | 290 | ||
| 168 | #if SERIAL_PIN_MASK == _BV(PD0) | 291 | // Enable INT0-INT3,INT6 |
| 169 | // Enable INT0 | 292 | EIMSK |= EIMSK_BIT; |
| 170 | EIMSK |= _BV(INT0); | 293 | #if SERIAL_PIN_MASK == _BV(PE6) |
| 171 | // Trigger on falling edge of INT0 | 294 | // Trigger on falling edge of INT6 |
| 172 | EICRA &= ~(_BV(ISC00) | _BV(ISC01)); | 295 | EICRB &= EICRx_BIT; |
| 173 | #elif SERIAL_PIN_MASK == _BV(PD2) | ||
| 174 | // Enable INT2 | ||
| 175 | EIMSK |= _BV(INT2); | ||
| 176 | // Trigger on falling edge of INT2 | ||
| 177 | EICRA &= ~(_BV(ISC20) | _BV(ISC21)); | ||
| 178 | #else | 296 | #else |
| 179 | #error unknown SERIAL_PIN_MASK value | 297 | // Trigger on falling edge of INT0-INT3 |
| 298 | EICRA &= EICRx_BIT; | ||
| 180 | #endif | 299 | #endif |
| 181 | } | 300 | } |
| 182 | 301 | ||
| @@ -192,7 +311,7 @@ void sync_recv(void) { | |||
| 192 | } | 311 | } |
| 193 | 312 | ||
| 194 | // Used by the reciver to send a synchronization signal to the sender. | 313 | // Used by the reciver to send a synchronization signal to the sender. |
| 195 | static void sync_send(void)NO_INLINE; | 314 | static void sync_send(void) NO_INLINE; |
| 196 | static | 315 | static |
| 197 | void sync_send(void) { | 316 | void sync_send(void) { |
| 198 | serial_low(); | 317 | serial_low(); |
| @@ -206,12 +325,12 @@ static uint8_t serial_read_chunk(uint8_t *pterrcount, uint8_t bit) { | |||
| 206 | uint8_t byte, i, p, pb; | 325 | uint8_t byte, i, p, pb; |
| 207 | 326 | ||
| 208 | _delay_sub_us(READ_WRITE_START_ADJUST); | 327 | _delay_sub_us(READ_WRITE_START_ADJUST); |
| 209 | for( i = 0, byte = 0, p = 0; i < bit; i++ ) { | 328 | for( i = 0, byte = 0, p = PARITY; i < bit; i++ ) { |
| 210 | serial_delay_half1(); // read the middle of pulses | 329 | serial_delay_half1(); // read the middle of pulses |
| 211 | if( serial_read_pin() ) { | 330 | if( serial_read_pin() ) { |
| 212 | byte = (byte << 1) | 1; p ^= 1; | 331 | byte = (byte << 1) | 1; p ^= 1; |
| 213 | } else { | 332 | } else { |
| 214 | byte = (byte << 1) | 0; p ^= 0; | 333 | byte = (byte << 1) | 0; p ^= 0; |
| 215 | } | 334 | } |
| 216 | _delay_sub_us(READ_WRITE_WIDTH_ADJUST); | 335 | _delay_sub_us(READ_WRITE_WIDTH_ADJUST); |
| 217 | serial_delay_half2(); | 336 | serial_delay_half2(); |
| @@ -231,13 +350,13 @@ static uint8_t serial_read_chunk(uint8_t *pterrcount, uint8_t bit) { | |||
| 231 | void serial_write_chunk(uint8_t data, uint8_t bit) NO_INLINE; | 350 | void serial_write_chunk(uint8_t data, uint8_t bit) NO_INLINE; |
| 232 | void serial_write_chunk(uint8_t data, uint8_t bit) { | 351 | void serial_write_chunk(uint8_t data, uint8_t bit) { |
| 233 | uint8_t b, p; | 352 | uint8_t b, p; |
| 234 | for( p = 0, b = 1<<(bit-1); b ; b >>= 1) { | 353 | for( p = PARITY, b = 1<<(bit-1); b ; b >>= 1) { |
| 235 | if(data & b) { | 354 | if(data & b) { |
| 236 | serial_high(); p ^= 1; | 355 | serial_high(); p ^= 1; |
| 237 | } else { | 356 | } else { |
| 238 | serial_low(); p ^= 0; | 357 | serial_low(); p ^= 0; |
| 239 | } | 358 | } |
| 240 | serial_delay(); | 359 | serial_delay(); |
| 241 | } | 360 | } |
| 242 | /* send parity bit */ | 361 | /* send parity bit */ |
| 243 | if(p & 1) { serial_high(); } | 362 | if(p & 1) { serial_high(); } |
| @@ -289,6 +408,13 @@ void change_reciver2sender(void) { | |||
| 289 | serial_delay_half1(); //4 | 408 | serial_delay_half1(); //4 |
| 290 | } | 409 | } |
| 291 | 410 | ||
| 411 | static inline uint8_t nibble_bits_count(uint8_t bits) | ||
| 412 | { | ||
| 413 | bits = (bits & 0x5) + (bits >> 1 & 0x5); | ||
| 414 | bits = (bits & 0x3) + (bits >> 2 & 0x3); | ||
| 415 | return bits; | ||
| 416 | } | ||
| 417 | |||
| 292 | // interrupt handle to be used by the target device | 418 | // interrupt handle to be used by the target device |
| 293 | ISR(SERIAL_PIN_INTERRUPT) { | 419 | ISR(SERIAL_PIN_INTERRUPT) { |
| 294 | 420 | ||
| @@ -298,12 +424,15 @@ ISR(SERIAL_PIN_INTERRUPT) { | |||
| 298 | SSTD_t *trans = Transaction_table; | 424 | SSTD_t *trans = Transaction_table; |
| 299 | #else | 425 | #else |
| 300 | // recive transaction table index | 426 | // recive transaction table index |
| 301 | uint8_t tid; | 427 | uint8_t tid, bits; |
| 302 | uint8_t pecount = 0; | 428 | uint8_t pecount = 0; |
| 303 | sync_recv(); | 429 | sync_recv(); |
| 304 | tid = serial_read_chunk(&pecount,4); | 430 | bits = serial_read_chunk(&pecount,7); |
| 305 | if(pecount> 0) | 431 | tid = bits>>3; |
| 432 | bits = (bits&7) != nibble_bits_count(tid); | ||
| 433 | if( bits || pecount> 0 || tid > Transaction_table_size ) { | ||
| 306 | return; | 434 | return; |
| 435 | } | ||
| 307 | serial_delay_half1(); | 436 | serial_delay_half1(); |
| 308 | 437 | ||
| 309 | serial_high(); // response step1 low->high | 438 | serial_high(); // response step1 low->high |
| @@ -316,17 +445,17 @@ ISR(SERIAL_PIN_INTERRUPT) { | |||
| 316 | // target send phase | 445 | // target send phase |
| 317 | if( trans->target2initiator_buffer_size > 0 ) | 446 | if( trans->target2initiator_buffer_size > 0 ) |
| 318 | serial_send_packet((uint8_t *)trans->target2initiator_buffer, | 447 | serial_send_packet((uint8_t *)trans->target2initiator_buffer, |
| 319 | trans->target2initiator_buffer_size); | 448 | trans->target2initiator_buffer_size); |
| 320 | // target switch to input | 449 | // target switch to input |
| 321 | change_sender2reciver(); | 450 | change_sender2reciver(); |
| 322 | 451 | ||
| 323 | // target recive phase | 452 | // target recive phase |
| 324 | if( trans->initiator2target_buffer_size > 0 ) { | 453 | if( trans->initiator2target_buffer_size > 0 ) { |
| 325 | if (serial_recive_packet((uint8_t *)trans->initiator2target_buffer, | 454 | if (serial_recive_packet((uint8_t *)trans->initiator2target_buffer, |
| 326 | trans->initiator2target_buffer_size) ) { | 455 | trans->initiator2target_buffer_size) ) { |
| 327 | *trans->status = TRANSACTION_ACCEPTED; | 456 | *trans->status = TRANSACTION_ACCEPTED; |
| 328 | } else { | 457 | } else { |
| 329 | *trans->status = TRANSACTION_DATA_ERROR; | 458 | *trans->status = TRANSACTION_DATA_ERROR; |
| 330 | } | 459 | } |
| 331 | } else { | 460 | } else { |
| 332 | *trans->status = TRANSACTION_ACCEPTED; | 461 | *trans->status = TRANSACTION_ACCEPTED; |
| @@ -350,6 +479,8 @@ int soft_serial_transaction(void) { | |||
| 350 | SSTD_t *trans = Transaction_table; | 479 | SSTD_t *trans = Transaction_table; |
| 351 | #else | 480 | #else |
| 352 | int soft_serial_transaction(int sstd_index) { | 481 | int soft_serial_transaction(int sstd_index) { |
| 482 | if( sstd_index > Transaction_table_size ) | ||
| 483 | return TRANSACTION_TYPE_ERROR; | ||
| 353 | SSTD_t *trans = &Transaction_table[sstd_index]; | 484 | SSTD_t *trans = &Transaction_table[sstd_index]; |
| 354 | #endif | 485 | #endif |
| 355 | cli(); | 486 | cli(); |
| @@ -376,9 +507,10 @@ int soft_serial_transaction(int sstd_index) { | |||
| 376 | 507 | ||
| 377 | #else | 508 | #else |
| 378 | // send transaction table index | 509 | // send transaction table index |
| 510 | int tid = (sstd_index<<3) | (7 & nibble_bits_count(sstd_index)); | ||
| 379 | sync_send(); | 511 | sync_send(); |
| 380 | _delay_sub_us(TID_SEND_ADJUST); | 512 | _delay_sub_us(TID_SEND_ADJUST); |
| 381 | serial_write_chunk(sstd_index, 4); | 513 | serial_write_chunk(tid, 7); |
| 382 | serial_delay_half1(); | 514 | serial_delay_half1(); |
| 383 | 515 | ||
| 384 | // wait for the target response (step1 low->high) | 516 | // wait for the target response (step1 low->high) |
| @@ -390,12 +522,12 @@ int soft_serial_transaction(int sstd_index) { | |||
| 390 | // check if the target is present (step2 high->low) | 522 | // check if the target is present (step2 high->low) |
| 391 | for( int i = 0; serial_read_pin(); i++ ) { | 523 | for( int i = 0; serial_read_pin(); i++ ) { |
| 392 | if (i > SLAVE_INT_ACK_WIDTH + 1) { | 524 | if (i > SLAVE_INT_ACK_WIDTH + 1) { |
| 393 | // slave failed to pull the line low, assume not present | 525 | // slave failed to pull the line low, assume not present |
| 394 | serial_output(); | 526 | serial_output(); |
| 395 | serial_high(); | 527 | serial_high(); |
| 396 | *trans->status = TRANSACTION_NO_RESPONSE; | 528 | *trans->status = TRANSACTION_NO_RESPONSE; |
| 397 | sei(); | 529 | sei(); |
| 398 | return TRANSACTION_NO_RESPONSE; | 530 | return TRANSACTION_NO_RESPONSE; |
| 399 | } | 531 | } |
| 400 | _delay_sub_us(SLAVE_INT_ACK_WIDTH_UNIT); | 532 | _delay_sub_us(SLAVE_INT_ACK_WIDTH_UNIT); |
| 401 | } | 533 | } |
| @@ -405,12 +537,12 @@ int soft_serial_transaction(int sstd_index) { | |||
| 405 | // if the target is present syncronize with it | 537 | // if the target is present syncronize with it |
| 406 | if( trans->target2initiator_buffer_size > 0 ) { | 538 | if( trans->target2initiator_buffer_size > 0 ) { |
| 407 | if (!serial_recive_packet((uint8_t *)trans->target2initiator_buffer, | 539 | if (!serial_recive_packet((uint8_t *)trans->target2initiator_buffer, |
| 408 | trans->target2initiator_buffer_size) ) { | 540 | trans->target2initiator_buffer_size) ) { |
| 409 | serial_output(); | 541 | serial_output(); |
| 410 | serial_high(); | 542 | serial_high(); |
| 411 | *trans->status = TRANSACTION_DATA_ERROR; | 543 | *trans->status = TRANSACTION_DATA_ERROR; |
| 412 | sei(); | 544 | sei(); |
| 413 | return TRANSACTION_DATA_ERROR; | 545 | return TRANSACTION_DATA_ERROR; |
| 414 | } | 546 | } |
| 415 | } | 547 | } |
| 416 | 548 | ||
| @@ -420,7 +552,7 @@ int soft_serial_transaction(int sstd_index) { | |||
| 420 | // initiator send phase | 552 | // initiator send phase |
| 421 | if( trans->initiator2target_buffer_size > 0 ) { | 553 | if( trans->initiator2target_buffer_size > 0 ) { |
| 422 | serial_send_packet((uint8_t *)trans->initiator2target_buffer, | 554 | serial_send_packet((uint8_t *)trans->initiator2target_buffer, |
| 423 | trans->initiator2target_buffer_size); | 555 | trans->initiator2target_buffer_size); |
| 424 | } | 556 | } |
| 425 | 557 | ||
| 426 | // always, release the line when not in use | 558 | // always, release the line when not in use |
| @@ -443,3 +575,16 @@ int soft_serial_get_and_clean_status(int sstd_index) { | |||
| 443 | #endif | 575 | #endif |
| 444 | 576 | ||
| 445 | #endif | 577 | #endif |
| 578 | |||
| 579 | // Helix serial.c history | ||
| 580 | // 2018-1-29 fork from let's split and add PD2, modify sync_recv() (#2308, bceffdefc) | ||
| 581 | // 2018-6-28 bug fix master to slave comm and speed up (#3255, 1038bbef4) | ||
| 582 | // (adjusted with avr-gcc 4.9.2) | ||
| 583 | // 2018-7-13 remove USE_SERIAL_PD2 macro (#3374, f30d6dd78) | ||
| 584 | // (adjusted with avr-gcc 4.9.2) | ||
| 585 | // 2018-8-11 add support multi-type transaction (#3608, feb5e4aae) | ||
| 586 | // (adjusted with avr-gcc 4.9.2) | ||
| 587 | // 2018-10-21 fix serial and RGB animation conflict (#4191, 4665e4fff) | ||
| 588 | // (adjusted with avr-gcc 7.3.0) | ||
| 589 | // 2018-10-28 re-adjust compiler depend value of delay (#4269, 8517f8a66) | ||
| 590 | // (adjusted with avr-gcc 5.4.0, 7.3.0) | ||
diff --git a/keyboards/lily58/serial.h b/keyboards/lily58/serial.h index d2b7fd8e6..7e0c0847a 100644..100755 --- a/keyboards/lily58/serial.h +++ b/keyboards/lily58/serial.h | |||
| @@ -4,14 +4,16 @@ | |||
| 4 | #include <stdbool.h> | 4 | #include <stdbool.h> |
| 5 | 5 | ||
| 6 | // ///////////////////////////////////////////////////////////////// | 6 | // ///////////////////////////////////////////////////////////////// |
| 7 | // Need Soft Serial defines in serial_config.h | 7 | // Need Soft Serial defines in config.h |
| 8 | // ///////////////////////////////////////////////////////////////// | 8 | // ///////////////////////////////////////////////////////////////// |
| 9 | // ex. | 9 | // ex. |
| 10 | // #define SERIAL_PIN_DDR DDRD | 10 | // #define SOFT_SERIAL_PIN ?? // ?? = D0,D1,D2,D3,E6 |
| 11 | // #define SERIAL_PIN_PORT PORTD | 11 | // OPTIONAL: #define SELECT_SOFT_SERIAL_SPEED ? // ? = 1,2,3,4,5 |
| 12 | // #define SERIAL_PIN_INPUT PIND | 12 | // // 1: about 137kbps (default) |
| 13 | // #define SERIAL_PIN_MASK _BV(PD?) ?=0,2 | 13 | // // 2: about 75kbps |
| 14 | // #define SERIAL_PIN_INTERRUPT INT?_vect ?=0,2 | 14 | // // 3: about 39kbps |
| 15 | // // 4: about 26kbps | ||
| 16 | // // 5: about 20kbps | ||
| 15 | // | 17 | // |
| 16 | // //// USE Simple API (OLD API, compatible with let's split serial.c) | 18 | // //// USE Simple API (OLD API, compatible with let's split serial.c) |
| 17 | // ex. | 19 | // ex. |
| @@ -47,16 +49,18 @@ typedef struct _SSTD_t { | |||
| 47 | uint8_t target2initiator_buffer_size; | 49 | uint8_t target2initiator_buffer_size; |
| 48 | uint8_t *target2initiator_buffer; | 50 | uint8_t *target2initiator_buffer; |
| 49 | } SSTD_t; | 51 | } SSTD_t; |
| 52 | #define TID_LIMIT( table ) (sizeof(table) / sizeof(SSTD_t)) | ||
| 50 | 53 | ||
| 51 | // initiator is transaction start side | 54 | // initiator is transaction start side |
| 52 | void soft_serial_initiator_init(SSTD_t *sstd_table); | 55 | void soft_serial_initiator_init(SSTD_t *sstd_table, int sstd_table_size); |
| 53 | // target is interrupt accept side | 56 | // target is interrupt accept side |
| 54 | void soft_serial_target_init(SSTD_t *sstd_table); | 57 | void soft_serial_target_init(SSTD_t *sstd_table, int sstd_table_size); |
| 55 | 58 | ||
| 56 | // initiator resullt | 59 | // initiator resullt |
| 57 | #define TRANSACTION_END 0 | 60 | #define TRANSACTION_END 0 |
| 58 | #define TRANSACTION_NO_RESPONSE 0x1 | 61 | #define TRANSACTION_NO_RESPONSE 0x1 |
| 59 | #define TRANSACTION_DATA_ERROR 0x2 | 62 | #define TRANSACTION_DATA_ERROR 0x2 |
| 63 | #define TRANSACTION_TYPE_ERROR 0x4 | ||
| 60 | #ifndef SERIAL_USE_MULTI_TRANSACTION | 64 | #ifndef SERIAL_USE_MULTI_TRANSACTION |
| 61 | int soft_serial_transaction(void); | 65 | int soft_serial_transaction(void); |
| 62 | #else | 66 | #else |
| @@ -72,7 +76,7 @@ int soft_serial_transaction(int sstd_index); | |||
| 72 | // target: | 76 | // target: |
| 73 | // TRANSACTION_DATA_ERROR | 77 | // TRANSACTION_DATA_ERROR |
| 74 | // or TRANSACTION_ACCEPTED | 78 | // or TRANSACTION_ACCEPTED |
| 75 | #define TRANSACTION_ACCEPTED 0x4 | 79 | #define TRANSACTION_ACCEPTED 0x8 |
| 76 | #ifdef SERIAL_USE_MULTI_TRANSACTION | 80 | #ifdef SERIAL_USE_MULTI_TRANSACTION |
| 77 | int soft_serial_get_and_clean_status(int sstd_index); | 81 | int soft_serial_get_and_clean_status(int sstd_index); |
| 78 | #endif | 82 | #endif |
diff --git a/keyboards/lily58/serial_config.h b/keyboards/lily58/serial_config.h index fef689038..4fab8e8dd 100644 --- a/keyboards/lily58/serial_config.h +++ b/keyboards/lily58/serial_config.h | |||
| @@ -1,8 +1,4 @@ | |||
| 1 | #define SERIAL_PIN_DDR DDRD | 1 | #ifndef SOFT_SERIAL_PIN |
| 2 | #define SERIAL_PIN_PORT PORTD | 2 | #define SOFT_SERIAL_PIN D2 |
| 3 | #define SERIAL_PIN_INPUT PIND | 3 | #define SERIAL_USE_MULTI_TRANSACTION |
| 4 | #define SERIAL_PIN_MASK _BV(PD2) | 4 | #endif |
| 5 | #define SERIAL_PIN_INTERRUPT INT2_vect | ||
| 6 | |||
| 7 | #define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2 | ||
| 8 | #define SERIAL_MASTER_BUFFER_LENGTH 1 \ No newline at end of file | ||
diff --git a/keyboards/lily58/ssd1306.c b/keyboards/lily58/ssd1306.c new file mode 100755 index 000000000..4330c8497 --- /dev/null +++ b/keyboards/lily58/ssd1306.c | |||
| @@ -0,0 +1,344 @@ | |||
| 1 | #ifdef SSD1306OLED | ||
| 2 | |||
| 3 | #include "ssd1306.h" | ||
| 4 | #include "i2c.h" | ||
| 5 | #include <string.h> | ||
| 6 | #include "print.h" | ||
| 7 | #ifdef ADAFRUIT_BLE_ENABLE | ||
| 8 | #include "adafruit_ble.h" | ||
| 9 | #endif | ||
| 10 | #ifdef PROTOCOL_LUFA | ||
| 11 | #include "lufa.h" | ||
| 12 | #endif | ||
| 13 | #include "sendchar.h" | ||
| 14 | #include "timer.h" | ||
| 15 | |||
| 16 | static const unsigned char font[] PROGMEM; | ||
| 17 | |||
| 18 | // Set this to 1 to help diagnose early startup problems | ||
| 19 | // when testing power-on with ble. Turn it off otherwise, | ||
| 20 | // as the latency of printing most of the debug info messes | ||
| 21 | // with the matrix scan, causing keys to drop. | ||
| 22 | #define DEBUG_TO_SCREEN 0 | ||
| 23 | |||
| 24 | //static uint16_t last_battery_update; | ||
| 25 | //static uint32_t vbat; | ||
| 26 | //#define BatteryUpdateInterval 10000 /* milliseconds */ | ||
| 27 | |||
| 28 | // 'last_flush' is declared as uint16_t, | ||
| 29 | // so this must be less than 65535 | ||
| 30 | #define ScreenOffInterval 60000 /* milliseconds */ | ||
| 31 | #if DEBUG_TO_SCREEN | ||
| 32 | static uint8_t displaying; | ||
| 33 | #endif | ||
| 34 | static uint16_t last_flush; | ||
| 35 | |||
| 36 | static bool force_dirty = true; | ||
| 37 | |||
| 38 | // Write command sequence. | ||
| 39 | // Returns true on success. | ||
| 40 | static inline bool _send_cmd1(uint8_t cmd) { | ||
| 41 | bool res = false; | ||
| 42 | |||
| 43 | if (i2c_start_write(SSD1306_ADDRESS)) { | ||
| 44 | xprintf("failed to start write to %d\n", SSD1306_ADDRESS); | ||
| 45 | goto done; | ||
| 46 | } | ||
| 47 | |||
| 48 | if (i2c_master_write(0x0 /* command byte follows */)) { | ||
| 49 | print("failed to write control byte\n"); | ||
| 50 | |||
| 51 | goto done; | ||
| 52 | } | ||
| 53 | |||
| 54 | if (i2c_master_write(cmd)) { | ||
| 55 | xprintf("failed to write command %d\n", cmd); | ||
| 56 | goto done; | ||
| 57 | } | ||
| 58 | res = true; | ||
| 59 | done: | ||
| 60 | i2c_master_stop(); | ||
| 61 | return res; | ||
| 62 | } | ||
| 63 | |||
| 64 | // Write 2-byte command sequence. | ||
| 65 | // Returns true on success | ||
| 66 | static inline bool _send_cmd2(uint8_t cmd, uint8_t opr) { | ||
| 67 | if (!_send_cmd1(cmd)) { | ||
| 68 | return false; | ||
| 69 | } | ||
| 70 | return _send_cmd1(opr); | ||
| 71 | } | ||
| 72 | |||
| 73 | // Write 3-byte command sequence. | ||
| 74 | // Returns true on success | ||
| 75 | static inline bool _send_cmd3(uint8_t cmd, uint8_t opr1, uint8_t opr2) { | ||
| 76 | if (!_send_cmd1(cmd)) { | ||
| 77 | return false; | ||
| 78 | } | ||
| 79 | if (!_send_cmd1(opr1)) { | ||
| 80 | return false; | ||
| 81 | } | ||
| 82 | return _send_cmd1(opr2); | ||
| 83 | } | ||
| 84 | |||
| 85 | #define send_cmd1(c) if (!_send_cmd1(c)) {goto done;} | ||
| 86 | #define send_cmd2(c,o) if (!_send_cmd2(c,o)) {goto done;} | ||
| 87 | #define send_cmd3(c,o1,o2) if (!_send_cmd3(c,o1,o2)) {goto done;} | ||
| 88 | |||
| 89 | static void clear_display(void) { | ||
| 90 | matrix_clear(&display); | ||
| 91 | |||
| 92 | // Clear all of the display bits (there can be random noise | ||
| 93 | // in the RAM on startup) | ||
| 94 | send_cmd3(PageAddr, 0, (DisplayHeight / 8) - 1); | ||
| 95 | send_cmd3(ColumnAddr, 0, DisplayWidth - 1); | ||
| 96 | |||
| 97 | if (i2c_start_write(SSD1306_ADDRESS)) { | ||
| 98 | goto done; | ||
| 99 | } | ||
| 100 | if (i2c_master_write(0x40)) { | ||
| 101 | // Data mode | ||
| 102 | goto done; | ||
| 103 | } | ||
| 104 | for (uint8_t row = 0; row < MatrixRows; ++row) { | ||
| 105 | for (uint8_t col = 0; col < DisplayWidth; ++col) { | ||
| 106 | i2c_master_write(0); | ||
| 107 | } | ||
| 108 | } | ||
| 109 | |||
| 110 | display.dirty = false; | ||
| 111 | |||
| 112 | done: | ||
| 113 | i2c_master_stop(); | ||
| 114 | } | ||
| 115 | |||
| 116 | #if DEBUG_TO_SCREEN | ||
| 117 | #undef sendchar | ||
| 118 | static int8_t capture_sendchar(uint8_t c) { | ||
| 119 | sendchar(c); | ||
| 120 | iota_gfx_write_char(c); | ||
| 121 | |||
| 122 | if (!displaying) { | ||
| 123 | iota_gfx_flush(); | ||
| 124 | } | ||
| 125 | return 0; | ||
| 126 | } | ||
| 127 | #endif | ||
| 128 | |||
| 129 | bool iota_gfx_init(bool rotate) { | ||
| 130 | bool success = false; | ||
| 131 | |||
| 132 | i2c_master_init(); | ||
| 133 | send_cmd1(DisplayOff); | ||
| 134 | send_cmd2(SetDisplayClockDiv, 0x80); | ||
| 135 | send_cmd2(SetMultiPlex, DisplayHeight - 1); | ||
| 136 | |||
| 137 | send_cmd2(SetDisplayOffset, 0); | ||
| 138 | |||
| 139 | |||
| 140 | send_cmd1(SetStartLine | 0x0); | ||
| 141 | send_cmd2(SetChargePump, 0x14 /* Enable */); | ||
| 142 | send_cmd2(SetMemoryMode, 0 /* horizontal addressing */); | ||
| 143 | |||
| 144 | if(rotate){ | ||
| 145 | // the following Flip the display orientation 180 degrees | ||
| 146 | send_cmd1(SegRemap); | ||
| 147 | send_cmd1(ComScanInc); | ||
| 148 | }else{ | ||
| 149 | // Flips the display orientation 0 degrees | ||
| 150 | send_cmd1(SegRemap | 0x1); | ||
| 151 | send_cmd1(ComScanDec); | ||
| 152 | } | ||
| 153 | |||
| 154 | send_cmd2(SetComPins, 0x2); | ||
| 155 | send_cmd2(SetContrast, 0x8f); | ||
| 156 | send_cmd2(SetPreCharge, 0xf1); | ||
| 157 | send_cmd2(SetVComDetect, 0x40); | ||
| 158 | send_cmd1(DisplayAllOnResume); | ||
| 159 | send_cmd1(NormalDisplay); | ||
| 160 | send_cmd1(DeActivateScroll); | ||
| 161 | send_cmd1(DisplayOn); | ||
| 162 | |||
| 163 | send_cmd2(SetContrast, 0); // Dim | ||
| 164 | |||
| 165 | clear_display(); | ||
| 166 | |||
| 167 | success = true; | ||
| 168 | |||
| 169 | iota_gfx_flush(); | ||
| 170 | |||
| 171 | #if DEBUG_TO_SCREEN | ||
| 172 | print_set_sendchar(capture_sendchar); | ||
| 173 | #endif | ||
| 174 | |||
| 175 | done: | ||
| 176 | return success; | ||
| 177 | } | ||
| 178 | |||
| 179 | bool iota_gfx_off(void) { | ||
| 180 | bool success = false; | ||
| 181 | |||
| 182 | send_cmd1(DisplayOff); | ||
| 183 | success = true; | ||
| 184 | |||
| 185 | done: | ||
| 186 | return success; | ||
| 187 | } | ||
| 188 | |||
| 189 | bool iota_gfx_on(void) { | ||
| 190 | bool success = false; | ||
| 191 | |||
| 192 | send_cmd1(DisplayOn); | ||
| 193 | success = true; | ||
| 194 | |||
| 195 | done: | ||
| 196 | return success; | ||
| 197 | } | ||
| 198 | |||
| 199 | void matrix_write_char_inner(struct CharacterMatrix *matrix, uint8_t c) { | ||
| 200 | *matrix->cursor = c; | ||
| 201 | ++matrix->cursor; | ||
| 202 | |||
| 203 | if (matrix->cursor - &matrix->display[0][0] == sizeof(matrix->display)) { | ||
| 204 | // We went off the end; scroll the display upwards by one line | ||
| 205 | memmove(&matrix->display[0], &matrix->display[1], | ||
| 206 | MatrixCols * (MatrixRows - 1)); | ||
| 207 | matrix->cursor = &matrix->display[MatrixRows - 1][0]; | ||
| 208 | memset(matrix->cursor, ' ', MatrixCols); | ||
| 209 | } | ||
| 210 | } | ||
| 211 | |||
| 212 | void matrix_write_char(struct CharacterMatrix *matrix, uint8_t c) { | ||
| 213 | matrix->dirty = true; | ||
| 214 | |||
| 215 | if (c == '\n') { | ||
| 216 | // Clear to end of line from the cursor and then move to the | ||
| 217 | // start of the next line | ||
| 218 | uint8_t cursor_col = (matrix->cursor - &matrix->display[0][0]) % MatrixCols; | ||
| 219 | |||
| 220 | while (cursor_col++ < MatrixCols) { | ||
| 221 | matrix_write_char_inner(matrix, ' '); | ||
| 222 | } | ||
| 223 | return; | ||
| 224 | } | ||
| 225 | |||
| 226 | matrix_write_char_inner(matrix, c); | ||
| 227 | } | ||
| 228 | |||
| 229 | void iota_gfx_write_char(uint8_t c) { | ||
| 230 | matrix_write_char(&display, c); | ||
| 231 | } | ||
| 232 | |||
| 233 | void matrix_write(struct CharacterMatrix *matrix, const char *data) { | ||
| 234 | const char *end = data + strlen(data); | ||
| 235 | while (data < end) { | ||
| 236 | matrix_write_char(matrix, *data); | ||
| 237 | ++data; | ||
| 238 | } | ||
| 239 | } | ||
| 240 | |||
| 241 | void matrix_write_ln(struct CharacterMatrix *matrix, const char *data) { | ||
| 242 | char data_ln[strlen(data)+2]; | ||
| 243 | snprintf(data_ln, sizeof(data_ln), "%s\n", data); | ||
| 244 | matrix_write(matrix, data_ln); | ||
| 245 | } | ||
| 246 | |||
| 247 | void iota_gfx_write(const char *data) { | ||
| 248 | matrix_write(&display, data); | ||
| 249 | } | ||
| 250 | |||
| 251 | void matrix_write_P(struct CharacterMatrix *matrix, const char *data) { | ||
| 252 | while (true) { | ||
| 253 | uint8_t c = pgm_read_byte(data); | ||
| 254 | if (c == 0) { | ||
| 255 | return; | ||
| 256 | } | ||
| 257 | matrix_write_char(matrix, c); | ||
| 258 | ++data; | ||
| 259 | } | ||
| 260 | } | ||
| 261 | |||
| 262 | void iota_gfx_write_P(const char *data) { | ||
| 263 | matrix_write_P(&display, data); | ||
| 264 | } | ||
| 265 | |||
| 266 | void matrix_clear(struct CharacterMatrix *matrix) { | ||
| 267 | memset(matrix->display, ' ', sizeof(matrix->display)); | ||
| 268 | matrix->cursor = &matrix->display[0][0]; | ||
| 269 | matrix->dirty = true; | ||
| 270 | } | ||
| 271 | |||
| 272 | void iota_gfx_clear_screen(void) { | ||
| 273 | matrix_clear(&display); | ||
| 274 | } | ||
| 275 | |||
| 276 | void matrix_render(struct CharacterMatrix *matrix) { | ||
| 277 | last_flush = timer_read(); | ||
| 278 | iota_gfx_on(); | ||
| 279 | #if DEBUG_TO_SCREEN | ||
| 280 | ++displaying; | ||
| 281 | #endif | ||
| 282 | |||
| 283 | // Move to the home position | ||
| 284 | send_cmd3(PageAddr, 0, MatrixRows - 1); | ||
| 285 | send_cmd3(ColumnAddr, 0, (MatrixCols * FontWidth) - 1); | ||
| 286 | |||
| 287 | if (i2c_start_write(SSD1306_ADDRESS)) { | ||
| 288 | goto done; | ||
| 289 | } | ||
| 290 | if (i2c_master_write(0x40)) { | ||
| 291 | // Data mode | ||
| 292 | goto done; | ||
| 293 | } | ||
| 294 | |||
| 295 | for (uint8_t row = 0; row < MatrixRows; ++row) { | ||
| 296 | for (uint8_t col = 0; col < MatrixCols; ++col) { | ||
| 297 | const uint8_t *glyph = font + (matrix->display[row][col] * FontWidth); | ||
| 298 | |||
| 299 | for (uint8_t glyphCol = 0; glyphCol < FontWidth; ++glyphCol) { | ||
| 300 | uint8_t colBits = pgm_read_byte(glyph + glyphCol); | ||
| 301 | i2c_master_write(colBits); | ||
| 302 | } | ||
| 303 | |||
| 304 | // 1 column of space between chars (it's not included in the glyph) | ||
| 305 | //i2c_master_write(0); | ||
| 306 | } | ||
| 307 | } | ||
| 308 | |||
| 309 | matrix->dirty = false; | ||
| 310 | |||
| 311 | done: | ||
| 312 | i2c_master_stop(); | ||
| 313 | #if DEBUG_TO_SCREEN | ||
| 314 | --displaying; | ||
| 315 | #endif | ||
| 316 | } | ||
| 317 | |||
| 318 | void iota_gfx_flush(void) { | ||
| 319 | matrix_render(&display); | ||
| 320 | } | ||
| 321 | |||
| 322 | __attribute__ ((weak)) | ||
| 323 | void iota_gfx_task_user(void) { | ||
| 324 | } | ||
| 325 | |||
| 326 | void iota_gfx_task(void) { | ||
| 327 | iota_gfx_task_user(); | ||
| 328 | |||
| 329 | if (display.dirty|| force_dirty) { | ||
| 330 | iota_gfx_flush(); | ||
| 331 | force_dirty = false; | ||
| 332 | } | ||
| 333 | |||
| 334 | if (timer_elapsed(last_flush) > ScreenOffInterval) { | ||
| 335 | iota_gfx_off(); | ||
| 336 | } | ||
| 337 | } | ||
| 338 | |||
| 339 | bool process_record_gfx(uint16_t keycode, keyrecord_t *record) { | ||
| 340 | force_dirty = true; | ||
| 341 | return true; | ||
| 342 | } | ||
| 343 | |||
| 344 | #endif | ||
diff --git a/keyboards/lily58/ssd1306.h b/keyboards/lily58/ssd1306.h new file mode 100755 index 000000000..ea8c92328 --- /dev/null +++ b/keyboards/lily58/ssd1306.h | |||
| @@ -0,0 +1,91 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <stdbool.h> | ||
| 4 | #include <stdio.h> | ||
| 5 | #include "pincontrol.h" | ||
| 6 | #include "action.h" | ||
| 7 | |||
| 8 | enum ssd1306_cmds { | ||
| 9 | DisplayOff = 0xAE, | ||
| 10 | DisplayOn = 0xAF, | ||
| 11 | |||
| 12 | SetContrast = 0x81, | ||
| 13 | DisplayAllOnResume = 0xA4, | ||
| 14 | |||
| 15 | DisplayAllOn = 0xA5, | ||
| 16 | NormalDisplay = 0xA6, | ||
| 17 | InvertDisplay = 0xA7, | ||
| 18 | SetDisplayOffset = 0xD3, | ||
| 19 | SetComPins = 0xda, | ||
| 20 | SetVComDetect = 0xdb, | ||
| 21 | SetDisplayClockDiv = 0xD5, | ||
| 22 | SetPreCharge = 0xd9, | ||
| 23 | SetMultiPlex = 0xa8, | ||
| 24 | SetLowColumn = 0x00, | ||
| 25 | SetHighColumn = 0x10, | ||
| 26 | SetStartLine = 0x40, | ||
| 27 | |||
| 28 | SetMemoryMode = 0x20, | ||
| 29 | ColumnAddr = 0x21, | ||
| 30 | PageAddr = 0x22, | ||
| 31 | |||
| 32 | ComScanInc = 0xc0, | ||
| 33 | ComScanDec = 0xc8, | ||
| 34 | SegRemap = 0xa0, | ||
| 35 | SetChargePump = 0x8d, | ||
| 36 | ExternalVcc = 0x01, | ||
| 37 | SwitchCapVcc = 0x02, | ||
| 38 | |||
| 39 | ActivateScroll = 0x2f, | ||
| 40 | DeActivateScroll = 0x2e, | ||
| 41 | SetVerticalScrollArea = 0xa3, | ||
| 42 | RightHorizontalScroll = 0x26, | ||
| 43 | LeftHorizontalScroll = 0x27, | ||
| 44 | VerticalAndRightHorizontalScroll = 0x29, | ||
| 45 | VerticalAndLeftHorizontalScroll = 0x2a, | ||
| 46 | }; | ||
| 47 | |||
| 48 | // Controls the SSD1306 128x32 OLED display via i2c | ||
| 49 | |||
| 50 | #ifndef SSD1306_ADDRESS | ||
| 51 | #define SSD1306_ADDRESS 0x3C | ||
| 52 | #endif | ||
| 53 | |||
| 54 | #define DisplayHeight 32 | ||
| 55 | #define DisplayWidth 128 | ||
| 56 | |||
| 57 | #define FontHeight 8 | ||
| 58 | #define FontWidth 6 | ||
| 59 | |||
| 60 | #define MatrixRows (DisplayHeight / FontHeight) | ||
| 61 | #define MatrixCols (DisplayWidth / FontWidth) | ||
| 62 | |||
| 63 | struct CharacterMatrix { | ||
| 64 | uint8_t display[MatrixRows][MatrixCols]; | ||
| 65 | uint8_t *cursor; | ||
| 66 | bool dirty; | ||
| 67 | }; | ||
| 68 | |||
| 69 | struct CharacterMatrix display; | ||
| 70 | |||
| 71 | bool iota_gfx_init(bool rotate); | ||
| 72 | void iota_gfx_task(void); | ||
| 73 | bool iota_gfx_off(void); | ||
| 74 | bool iota_gfx_on(void); | ||
| 75 | void iota_gfx_flush(void); | ||
| 76 | void iota_gfx_write_char(uint8_t c); | ||
| 77 | void iota_gfx_write(const char *data); | ||
| 78 | void iota_gfx_write_P(const char *data); | ||
| 79 | void iota_gfx_clear_screen(void); | ||
| 80 | |||
| 81 | void iota_gfx_task_user(void); | ||
| 82 | |||
| 83 | void matrix_clear(struct CharacterMatrix *matrix); | ||
| 84 | void matrix_write_char_inner(struct CharacterMatrix *matrix, uint8_t c); | ||
| 85 | void matrix_write_char(struct CharacterMatrix *matrix, uint8_t c); | ||
| 86 | void matrix_write(struct CharacterMatrix *matrix, const char *data); | ||
| 87 | void matrix_write_ln(struct CharacterMatrix *matrix, const char *data); | ||
| 88 | void matrix_write_P(struct CharacterMatrix *matrix, const char *data); | ||
| 89 | void matrix_render(struct CharacterMatrix *matrix); | ||
| 90 | |||
| 91 | bool process_record_gfx(uint16_t keycode, keyrecord_t *record); \ No newline at end of file | ||
