diff options
Diffstat (limited to 'keyboards/cannonkeys/stm32f072/keyboard.c')
| -rw-r--r-- | keyboards/cannonkeys/stm32f072/keyboard.c | 241 |
1 files changed, 0 insertions, 241 deletions
diff --git a/keyboards/cannonkeys/stm32f072/keyboard.c b/keyboards/cannonkeys/stm32f072/keyboard.c deleted file mode 100644 index 39f912506..000000000 --- a/keyboards/cannonkeys/stm32f072/keyboard.c +++ /dev/null | |||
| @@ -1,241 +0,0 @@ | |||
| 1 | #include "keyboard.h" | ||
| 2 | #include "ch.h" | ||
| 3 | #include "hal.h" | ||
| 4 | #include "led_custom.h" | ||
| 5 | #include "util.h" | ||
| 6 | #include "quantum.h" | ||
| 7 | |||
| 8 | #include "raw_hid.h" | ||
| 9 | #include "dynamic_keymap.h" | ||
| 10 | #include "tmk_core/common/eeprom.h" | ||
| 11 | #include "version.h" // for QMK_BUILDDATE used in EEPROM magic | ||
| 12 | |||
| 13 | #include "via.h" | ||
| 14 | #define EEPROM_CUSTOM_BACKLIGHT (VIA_EEPROM_CUSTOM_CONFIG_ADDR) | ||
| 15 | |||
| 16 | backlight_config_t kb_backlight_config = { | ||
| 17 | .enable = true, | ||
| 18 | .breathing = true, | ||
| 19 | .level = BACKLIGHT_LEVELS | ||
| 20 | }; | ||
| 21 | |||
| 22 | void backlight_config_save(){ | ||
| 23 | eeprom_update_byte((uint8_t*)EEPROM_CUSTOM_BACKLIGHT, kb_backlight_config.raw); | ||
| 24 | } | ||
| 25 | |||
| 26 | void backlight_config_load(){ | ||
| 27 | kb_backlight_config.raw = eeprom_read_byte((uint8_t*)EEPROM_CUSTOM_BACKLIGHT); | ||
| 28 | } | ||
| 29 | |||
| 30 | // Called from via_init() if VIA_ENABLE | ||
| 31 | // Called from matrix_init_kb() if not VIA_ENABLE | ||
| 32 | void via_init_kb(void) | ||
| 33 | { | ||
| 34 | // If the EEPROM has the magic, the data is good. | ||
| 35 | // OK to load from EEPROM. | ||
| 36 | if (via_eeprom_is_valid()) { | ||
| 37 | backlight_config_load(); | ||
| 38 | } else { | ||
| 39 | // If the EEPROM has not been saved before, or is out of date, | ||
| 40 | // save the default values to the EEPROM. Default values | ||
| 41 | // come from construction of the backlight_config instance. | ||
| 42 | backlight_config_save(); | ||
| 43 | |||
| 44 | // DO NOT set EEPROM valid here, let caller do this | ||
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 48 | __attribute__ ((weak)) | ||
| 49 | void matrix_init_board(void); | ||
| 50 | |||
| 51 | void matrix_init_kb(void){ | ||
| 52 | // If VIA is disabled, we still need to load backlight settings. | ||
| 53 | // Call via_init_kb() the same way as via_init(), with setting | ||
| 54 | // EEPROM valid afterwards. | ||
| 55 | #ifndef VIA_ENABLE | ||
| 56 | via_init_kb(); | ||
| 57 | via_eeprom_set_valid(true); | ||
| 58 | #endif // VIA_ENABLE | ||
| 59 | backlight_init_ports(); | ||
| 60 | |||
| 61 | matrix_init_board(); | ||
| 62 | } | ||
| 63 | |||
| 64 | bool process_record_kb(uint16_t keycode, keyrecord_t *record) { | ||
| 65 | switch (keycode) { | ||
| 66 | case BL_INC: | ||
| 67 | if (record->event.pressed) { | ||
| 68 | kb_backlight_config.level = kb_backlight_config.level + 1; | ||
| 69 | if(kb_backlight_config.level > BACKLIGHT_LEVELS){ | ||
| 70 | kb_backlight_config.level = BACKLIGHT_LEVELS; | ||
| 71 | } | ||
| 72 | backlight_set(kb_backlight_config.level); | ||
| 73 | backlight_config_save(); | ||
| 74 | } | ||
| 75 | return false; | ||
| 76 | case BL_TOGG: | ||
| 77 | if (record->event.pressed) { | ||
| 78 | kb_backlight_config.enable = !kb_backlight_config.enable; | ||
| 79 | if(kb_backlight_config.enable){ | ||
| 80 | backlight_set(kb_backlight_config.level); | ||
| 81 | } else { | ||
| 82 | backlight_set(0); | ||
| 83 | } | ||
| 84 | backlight_config_save(); | ||
| 85 | } | ||
| 86 | return false; | ||
| 87 | |||
| 88 | case BL_DEC: | ||
| 89 | if (record->event.pressed) { | ||
| 90 | if(kb_backlight_config.level <= 1){ | ||
| 91 | kb_backlight_config.level = 0; | ||
| 92 | } else { | ||
| 93 | kb_backlight_config.level = kb_backlight_config.level - 1; | ||
| 94 | } | ||
| 95 | backlight_set(kb_backlight_config.level); | ||
| 96 | backlight_config_save(); | ||
| 97 | } | ||
| 98 | return false; | ||
| 99 | case BL_BRTG: | ||
| 100 | if (record->event.pressed) { | ||
| 101 | kb_backlight_config.breathing = !kb_backlight_config.breathing; | ||
| 102 | breathing_toggle(); | ||
| 103 | backlight_config_save(); | ||
| 104 | } | ||
| 105 | return false; | ||
| 106 | default: | ||
| 107 | break; | ||
| 108 | } | ||
| 109 | |||
| 110 | return process_record_user(keycode, record);; | ||
| 111 | } | ||
| 112 | |||
| 113 | #ifdef VIA_ENABLE | ||
| 114 | |||
| 115 | void backlight_get_value( uint8_t *data ) | ||
| 116 | { | ||
| 117 | uint8_t *value_id = &(data[0]); | ||
| 118 | uint8_t *value_data = &(data[1]); | ||
| 119 | switch (*value_id) | ||
| 120 | { | ||
| 121 | case id_qmk_backlight_brightness: | ||
| 122 | { | ||
| 123 | // level / BACKLIGHT_LEVELS * 255 | ||
| 124 | value_data[0] = ((uint16_t)kb_backlight_config.level) * 255 / BACKLIGHT_LEVELS; | ||
| 125 | break; | ||
| 126 | } | ||
| 127 | case id_qmk_backlight_effect: | ||
| 128 | { | ||
| 129 | value_data[0] = kb_backlight_config.breathing ? 1 : 0; | ||
| 130 | break; | ||
| 131 | } | ||
| 132 | } | ||
| 133 | } | ||
| 134 | |||
| 135 | void backlight_set_value( uint8_t *data ) | ||
| 136 | { | ||
| 137 | uint8_t *value_id = &(data[0]); | ||
| 138 | uint8_t *value_data = &(data[1]); | ||
| 139 | switch (*value_id) | ||
| 140 | { | ||
| 141 | case id_qmk_backlight_brightness: | ||
| 142 | { | ||
| 143 | // level / 255 * BACKLIGHT_LEVELS | ||
| 144 | kb_backlight_config.level = ((uint16_t)value_data[0]) * BACKLIGHT_LEVELS / 255; | ||
| 145 | backlight_set(kb_backlight_config.level); | ||
| 146 | break; | ||
| 147 | } | ||
| 148 | case id_qmk_backlight_effect: | ||
| 149 | { | ||
| 150 | if ( value_data[0] == 0 ) { | ||
| 151 | kb_backlight_config.breathing = false; | ||
| 152 | breathing_disable(); | ||
| 153 | } else { | ||
| 154 | kb_backlight_config.breathing = true; | ||
| 155 | breathing_enable(); | ||
| 156 | } | ||
| 157 | break; | ||
| 158 | } | ||
| 159 | } | ||
| 160 | } | ||
| 161 | |||
| 162 | void raw_hid_receive_kb( uint8_t *data, uint8_t length ) | ||
| 163 | { | ||
| 164 | uint8_t *command_id = &(data[0]); | ||
| 165 | uint8_t *command_data = &(data[1]); | ||
| 166 | switch ( *command_id ) | ||
| 167 | { | ||
| 168 | case id_lighting_set_value: | ||
| 169 | { | ||
| 170 | backlight_set_value(command_data); | ||
| 171 | break; | ||
| 172 | } | ||
| 173 | case id_lighting_get_value: | ||
| 174 | { | ||
| 175 | backlight_get_value(command_data); | ||
| 176 | break; | ||
| 177 | } | ||
| 178 | case id_lighting_save: | ||
| 179 | { | ||
| 180 | backlight_config_save(); | ||
| 181 | break; | ||
| 182 | } | ||
| 183 | default: | ||
| 184 | { | ||
| 185 | // Unhandled message. | ||
| 186 | *command_id = id_unhandled; | ||
| 187 | break; | ||
| 188 | } | ||
| 189 | } | ||
| 190 | // DO NOT call raw_hid_send(data,length) here, let caller do this | ||
| 191 | } | ||
| 192 | #endif | ||
| 193 | |||
| 194 | // | ||
| 195 | // In the case of VIA being disabled, we still need to check if | ||
| 196 | // keyboard level EEPROM memory is valid before loading. | ||
| 197 | // Thus these are copies of the same functions in VIA, since | ||
| 198 | // the backlight settings reuse VIA's EEPROM magic/version, | ||
| 199 | // and the ones in via.c won't be compiled in. | ||
| 200 | // | ||
| 201 | // Yes, this is sub-optimal, and is only here for completeness | ||
| 202 | // (i.e. catering to the 1% of people that want wilba.tech LED bling | ||
| 203 | // AND want persistent settings BUT DON'T want to use dynamic keymaps/VIA). | ||
| 204 | // | ||
| 205 | #ifndef VIA_ENABLE | ||
| 206 | |||
| 207 | bool via_eeprom_is_valid(void) | ||
| 208 | { | ||
| 209 | char *p = QMK_BUILDDATE; // e.g. "2019-11-05-11:29:54" | ||
| 210 | uint8_t magic0 = ( ( p[2] & 0x0F ) << 4 ) | ( p[3] & 0x0F ); | ||
| 211 | uint8_t magic1 = ( ( p[5] & 0x0F ) << 4 ) | ( p[6] & 0x0F ); | ||
| 212 | uint8_t magic2 = ( ( p[8] & 0x0F ) << 4 ) | ( p[9] & 0x0F ); | ||
| 213 | |||
| 214 | return (eeprom_read_byte( (void*)VIA_EEPROM_MAGIC_ADDR+0 ) == magic0 && | ||
| 215 | eeprom_read_byte( (void*)VIA_EEPROM_MAGIC_ADDR+1 ) == magic1 && | ||
| 216 | eeprom_read_byte( (void*)VIA_EEPROM_MAGIC_ADDR+2 ) == magic2 ); | ||
| 217 | } | ||
| 218 | |||
| 219 | // Sets VIA/keyboard level usage of EEPROM to valid/invalid | ||
| 220 | // Keyboard level code (eg. via_init_kb()) should not call this | ||
| 221 | void via_eeprom_set_valid(bool valid) | ||
| 222 | { | ||
| 223 | char *p = QMK_BUILDDATE; // e.g. "2019-11-05-11:29:54" | ||
| 224 | uint8_t magic0 = ( ( p[2] & 0x0F ) << 4 ) | ( p[3] & 0x0F ); | ||
| 225 | uint8_t magic1 = ( ( p[5] & 0x0F ) << 4 ) | ( p[6] & 0x0F ); | ||
| 226 | uint8_t magic2 = ( ( p[8] & 0x0F ) << 4 ) | ( p[9] & 0x0F ); | ||
| 227 | |||
| 228 | eeprom_update_byte( (void*)VIA_EEPROM_MAGIC_ADDR+0, valid ? magic0 : 0xFF); | ||
| 229 | eeprom_update_byte( (void*)VIA_EEPROM_MAGIC_ADDR+1, valid ? magic1 : 0xFF); | ||
| 230 | eeprom_update_byte( (void*)VIA_EEPROM_MAGIC_ADDR+2, valid ? magic2 : 0xFF); | ||
| 231 | } | ||
| 232 | |||
| 233 | void via_eeprom_reset(void) | ||
| 234 | { | ||
| 235 | // Set the VIA specific EEPROM state as invalid. | ||
| 236 | via_eeprom_set_valid(false); | ||
| 237 | // Set the TMK/QMK EEPROM state as invalid. | ||
| 238 | eeconfig_disable(); | ||
| 239 | } | ||
| 240 | |||
| 241 | #endif // VIA_ENABLE | ||
