aboutsummaryrefslogtreecommitdiff
path: root/keyboards/cannonkeys/satisfaction75
diff options
context:
space:
mode:
authorAndrew Kannan <andrew.kannan@klaviyo.com>2019-09-18 20:41:46 -0400
committerDrashna Jaelre <drashna@live.com>2019-09-18 17:41:46 -0700
commite5aa28455ec6c377cc9117b07dfa7d3951e6d610 (patch)
tree0bf2ff0faf5864b1e062adb609dbaf63df1aa240 /keyboards/cannonkeys/satisfaction75
parent6f5f943bb91185e9dacc499fcc97550348223e90 (diff)
downloadqmk_firmware-e5aa28455ec6c377cc9117b07dfa7d3951e6d610.tar.gz
qmk_firmware-e5aa28455ec6c377cc9117b07dfa7d3951e6d610.zip
[Keyboard] 201909 s75 custom encoder (#6745)
* Handle custom encoder configuration * Whitespace changes * Undo broken stuff * more * Remove printfs * fix the dumb bug
Diffstat (limited to 'keyboards/cannonkeys/satisfaction75')
-rw-r--r--keyboards/cannonkeys/satisfaction75/config.h18
-rw-r--r--keyboards/cannonkeys/satisfaction75/satisfaction75.c112
-rw-r--r--keyboards/cannonkeys/satisfaction75/satisfaction75.h8
-rw-r--r--keyboards/cannonkeys/satisfaction75/satisfaction_encoder.c58
4 files changed, 129 insertions, 67 deletions
diff --git a/keyboards/cannonkeys/satisfaction75/config.h b/keyboards/cannonkeys/satisfaction75/config.h
index 1cbe43fad..8387289d8 100644
--- a/keyboards/cannonkeys/satisfaction75/config.h
+++ b/keyboards/cannonkeys/satisfaction75/config.h
@@ -71,15 +71,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
71 71
72// TODO: refactor with new user EEPROM code (coming soon) 72// TODO: refactor with new user EEPROM code (coming soon)
73#define EEPROM_MAGIC 0x451F 73#define EEPROM_MAGIC 0x451F
74#define EEPROM_MAGIC_ADDR 32 74#define EEPROM_MAGIC_ADDR 40
75// Bump this every time we change what we store 75// Bump this every time we change what we store
76// This will automatically reset the EEPROM with defaults 76// This will automatically reset the EEPROM with defaults
77// and avoid loading invalid data from the EEPROM 77// and avoid loading invalid data from the EEPROM
78#define EEPROM_VERSION 0x01 78#define EEPROM_VERSION 0x01
79#define EEPROM_VERSION_ADDR 34 79#define EEPROM_VERSION_ADDR 42
80 80
81// Dynamic keymap starts after EEPROM version 81// Dynamic keymap starts after EEPROM version
82#define DYNAMIC_KEYMAP_EEPROM_ADDR 35 82#define DYNAMIC_KEYMAP_EEPROM_ADDR 43
83 83
84// Dynamic macro starts after dynamic keymaps (35+(4*6*16*2)) = (35+768) = 803 84// Dynamic macro starts after dynamic keymaps (35+(4*6*16*2)) = (35+768) = 803
85 85
@@ -89,13 +89,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
89// 1 for OLED default mode 89// 1 for OLED default mode
90// 6 for 3x custom encoder settings, left, right, and press (18 total) 90// 6 for 3x custom encoder settings, left, right, and press (18 total)
91 91
92#define DYNAMIC_KEYMAP_ENABLED_ENCODER_MODES 803 92#define DYNAMIC_KEYMAP_ENABLED_ENCODER_MODES 811
93#define DYNAMIC_KEYMAP_CUSTOM_BACKLIGHT 804 93#define DYNAMIC_KEYMAP_CUSTOM_BACKLIGHT 812
94#define DYNAMIC_KEYMAP_DEFAULT_OLED 805 94#define DYNAMIC_KEYMAP_DEFAULT_OLED 813
95#define DYNAMIC_KEYMAP_CUSTOM_ENCODER 806 95#define DYNAMIC_KEYMAP_CUSTOM_ENCODER 814
96 96
97#define DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR 824 97#define DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR 832
98#define DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE 200 98#define DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE 192
99#define DYNAMIC_KEYMAP_MACRO_COUNT 16 99#define DYNAMIC_KEYMAP_MACRO_COUNT 16
100 100
101 101
diff --git a/keyboards/cannonkeys/satisfaction75/satisfaction75.c b/keyboards/cannonkeys/satisfaction75/satisfaction75.c
index 531bf0474..12d3660da 100644
--- a/keyboards/cannonkeys/satisfaction75/satisfaction75.c
+++ b/keyboards/cannonkeys/satisfaction75/satisfaction75.c
@@ -94,51 +94,53 @@ void raw_hid_receive( uint8_t *data, uint8_t length )
94 } 94 }
95 case id_get_keyboard_value: 95 case id_get_keyboard_value:
96 { 96 {
97 switch( command_data[0]) 97 switch( command_data[0])
98 { 98 {
99 case id_uptime: 99 case id_uptime:
100 { 100 {
101 uint32_t value = timer_read32(); 101 uint32_t value = timer_read32();
102 command_data[1] = (value >> 24 ) & 0xFF; 102 command_data[1] = (value >> 24 ) & 0xFF;
103 command_data[2] = (value >> 16 ) & 0xFF; 103 command_data[2] = (value >> 16 ) & 0xFF;
104 command_data[3] = (value >> 8 ) & 0xFF; 104 command_data[3] = (value >> 8 ) & 0xFF;
105 command_data[4] = value & 0xFF; 105 command_data[4] = value & 0xFF;
106 break; 106 break;
107 } 107 }
108 case id_oled_default_mode: 108 case id_oled_default_mode:
109 { 109 {
110 uint8_t default_oled = eeprom_read_byte((uint8_t*)DYNAMIC_KEYMAP_DEFAULT_OLED); 110 uint8_t default_oled = eeprom_read_byte((uint8_t*)DYNAMIC_KEYMAP_DEFAULT_OLED);
111 command_data[1] = default_oled; 111 command_data[1] = default_oled;
112 break; 112 break;
113 } 113 }
114 case id_oled_mode: 114 case id_oled_mode:
115 { 115 {
116 command_data[1] = oled_mode; 116 command_data[1] = oled_mode;
117 break; 117 break;
118 118 }
119 } 119 case id_encoder_modes:
120 case id_encoder_modes: 120 {
121 { 121 command_data[1] = enabled_encoder_modes;
122 command_data[1] = enabled_encoder_modes; 122 break;
123 break; 123 }
124 } 124 case id_encoder_custom:
125 case id_encoder_custom: 125 {
126 { 126 uint8_t custom_encoder_idx = command_data[1];
127 // uint8_t custom_encoder_idx = command_data[1]; 127 uint16_t keycode = retrieve_custom_encoder_config(custom_encoder_idx, ENC_CUSTOM_CW);
128 // command_data[2] = 0x00; 128 command_data[2] = keycode >> 8;
129 // command_data[3] = 0x00; 129 command_data[3] = keycode & 0xFF;
130 // command_data[4] = 0x00; 130 keycode = retrieve_custom_encoder_config(custom_encoder_idx, ENC_CUSTOM_CCW);
131 // command_data[5] = 0x00; 131 command_data[4] = keycode >> 8;
132 // command_data[6] = 0x00; 132 command_data[5] = keycode & 0xFF;
133 // command_data[7] = 0x00; 133 keycode = retrieve_custom_encoder_config(custom_encoder_idx, ENC_CUSTOM_PRESS);
134 break; 134 command_data[6] = keycode >> 8;
135 } 135 command_data[7] = keycode & 0xFF;
136 default: 136 break;
137 { 137 }
138 *command_id = id_unhandled; 138 default:
139 break; 139 {
140 } 140 *command_id = id_unhandled;
141 } 141 break;
142 }
143 }
142 break; 144 break;
143 } 145 }
144#ifdef DYNAMIC_KEYMAP_ENABLE 146#ifdef DYNAMIC_KEYMAP_ENABLE
@@ -164,7 +166,10 @@ void raw_hid_receive( uint8_t *data, uint8_t length )
164 } 166 }
165 case id_encoder_custom: 167 case id_encoder_custom:
166 { 168 {
167 // uint8_t custom_encoder_idx = command_data[1]; 169 uint8_t custom_encoder_idx = command_data[1];
170 uint8_t encoder_behavior = command_data[2];
171 uint16_t keycode = (command_data[3] << 8) | command_data[4];
172 set_custom_encoder_config(custom_encoder_idx, encoder_behavior, keycode);
168 break; 173 break;
169 } 174 }
170 default: 175 default:
@@ -208,13 +213,6 @@ void raw_hid_receive( uint8_t *data, uint8_t length )
208 { 213 {
209 uint16_t offset = ( command_data[0] << 8 ) | command_data[1]; 214 uint16_t offset = ( command_data[0] << 8 ) | command_data[1];
210 uint16_t size = command_data[2]; // size <= 28 215 uint16_t size = command_data[2]; // size <= 28
211 dynamic_keymap_macro_get_buffer( offset, size, &command_data[3] );
212 break;
213 }
214 case id_dynamic_keymap_macro_set_buffer:
215 {
216 uint16_t offset = ( command_data[0] << 8 ) | command_data[1];
217 uint16_t size = command_data[2]; // size <= 28
218 dynamic_keymap_macro_set_buffer( offset, size, &command_data[3] ); 216 dynamic_keymap_macro_set_buffer( offset, size, &command_data[3] );
219 break; 217 break;
220 } 218 }
@@ -339,9 +337,9 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
339 uint16_t mapped_code = handle_encoder_press(); 337 uint16_t mapped_code = handle_encoder_press();
340 uint16_t held_keycode_timer = timer_read(); 338 uint16_t held_keycode_timer = timer_read();
341 if(mapped_code != 0){ 339 if(mapped_code != 0){
342 register_code(mapped_code); 340 register_code16(mapped_code);
343 while (timer_elapsed(held_keycode_timer) < MEDIA_KEY_DELAY){ /* no-op */ } 341 while (timer_elapsed(held_keycode_timer) < MEDIA_KEY_DELAY){ /* no-op */ }
344 unregister_code(mapped_code); 342 unregister_code16(mapped_code);
345 } 343 }
346 } else { 344 } else {
347 // Do something else when release 345 // Do something else when release
@@ -380,9 +378,9 @@ void encoder_update_kb(uint8_t index, bool clockwise) {
380 } 378 }
381 uint16_t held_keycode_timer = timer_read(); 379 uint16_t held_keycode_timer = timer_read();
382 if(mapped_code != 0){ 380 if(mapped_code != 0){
383 register_code(mapped_code); 381 register_code16(mapped_code);
384 while (timer_elapsed(held_keycode_timer) < MEDIA_KEY_DELAY){ /* no-op */ } 382 while (timer_elapsed(held_keycode_timer) < MEDIA_KEY_DELAY){ /* no-op */ }
385 unregister_code(mapped_code); 383 unregister_code16(mapped_code);
386 } 384 }
387 } else { 385 } else {
388 if(clockwise){ 386 if(clockwise){
diff --git a/keyboards/cannonkeys/satisfaction75/satisfaction75.h b/keyboards/cannonkeys/satisfaction75/satisfaction75.h
index dfab68017..188a1d497 100644
--- a/keyboards/cannonkeys/satisfaction75/satisfaction75.h
+++ b/keyboards/cannonkeys/satisfaction75/satisfaction75.h
@@ -47,6 +47,12 @@ enum encoder_modes {
47 ENC_MODE_CLOCK_SET // This shouldn't be included in the default modes, so we put it after NUM_ENCODER_MODES 47 ENC_MODE_CLOCK_SET // This shouldn't be included in the default modes, so we put it after NUM_ENCODER_MODES
48}; 48};
49 49
50enum custom_encoder_behavior {
51 ENC_CUSTOM_CW = 0,
52 ENC_CUSTOM_CCW,
53 ENC_CUSTOM_PRESS
54};
55
50enum oled_modes { 56enum oled_modes {
51 OLED_DEFAULT, 57 OLED_DEFAULT,
52 OLED_TIME, 58 OLED_TIME,
@@ -96,6 +102,8 @@ void change_encoder_mode(bool negative);
96uint16_t handle_encoder_clockwise(void); 102uint16_t handle_encoder_clockwise(void);
97uint16_t handle_encoder_ccw(void); 103uint16_t handle_encoder_ccw(void);
98uint16_t handle_encoder_press(void); 104uint16_t handle_encoder_press(void);
105uint16_t retrieve_custom_encoder_config(uint8_t encoder_idx, uint8_t behavior);
106void set_custom_encoder_config(uint8_t encoder_idx, uint8_t behavior, uint16_t new_code);
99 107
100void update_time_config(int8_t increment); 108void update_time_config(int8_t increment);
101 109
diff --git a/keyboards/cannonkeys/satisfaction75/satisfaction_encoder.c b/keyboards/cannonkeys/satisfaction75/satisfaction_encoder.c
index 677681691..e866d897c 100644
--- a/keyboards/cannonkeys/satisfaction75/satisfaction_encoder.c
+++ b/keyboards/cannonkeys/satisfaction75/satisfaction_encoder.c
@@ -1,4 +1,5 @@
1#include "satisfaction75.h" 1#include "satisfaction75.h"
2#include "tmk_core/common/eeprom.h"
2 3
3void pre_encoder_mode_change(){ 4void pre_encoder_mode_change(){
4 if(encoder_mode == ENC_MODE_CLOCK_SET){ 5 if(encoder_mode == ENC_MODE_CLOCK_SET){
@@ -111,6 +112,17 @@ uint16_t handle_encoder_clockwise(){
111 case ENC_MODE_BRIGHTNESS: 112 case ENC_MODE_BRIGHTNESS:
112 mapped_code = KC_BRIGHTNESS_UP; 113 mapped_code = KC_BRIGHTNESS_UP;
113 break; 114 break;
115#ifdef DYNAMIC_KEYMAP_ENABLE
116 case ENC_MODE_CUSTOM0:
117 mapped_code = retrieve_custom_encoder_config(0, ENC_CUSTOM_CW);
118 break;
119 case ENC_MODE_CUSTOM1:
120 mapped_code = retrieve_custom_encoder_config(1, ENC_CUSTOM_CW);
121 break;
122 case ENC_MODE_CUSTOM2:
123 mapped_code = retrieve_custom_encoder_config(2, ENC_CUSTOM_CW);
124 break;
125#endif
114 case ENC_MODE_CLOCK_SET: 126 case ENC_MODE_CLOCK_SET:
115 update_time_config(1); 127 update_time_config(1);
116 queue_for_send = true; 128 queue_for_send = true;
@@ -145,6 +157,18 @@ uint16_t handle_encoder_ccw(){
145 case ENC_MODE_BRIGHTNESS: 157 case ENC_MODE_BRIGHTNESS:
146 mapped_code = KC_BRIGHTNESS_DOWN; 158 mapped_code = KC_BRIGHTNESS_DOWN;
147 break; 159 break;
160#ifdef DYNAMIC_KEYMAP_ENABLE
161 case ENC_MODE_CUSTOM0:
162 mapped_code = retrieve_custom_encoder_config(0, ENC_CUSTOM_CCW);
163 break;
164 case ENC_MODE_CUSTOM1:
165 mapped_code = retrieve_custom_encoder_config(1, ENC_CUSTOM_CCW);
166 break;
167 case ENC_MODE_CUSTOM2:
168 mapped_code = retrieve_custom_encoder_config(2, ENC_CUSTOM_CCW);
169 break;
170#endif
171
148 case ENC_MODE_CLOCK_SET: 172 case ENC_MODE_CLOCK_SET:
149 update_time_config(-1); 173 update_time_config(-1);
150 queue_for_send = true; 174 queue_for_send = true;
@@ -159,6 +183,7 @@ uint16_t handle_encoder_press(){
159 case ENC_MODE_VOLUME: 183 case ENC_MODE_VOLUME:
160 mapped_code = KC_MUTE; 184 mapped_code = KC_MUTE;
161 break; 185 break;
186 default:
162 case ENC_MODE_MEDIA: 187 case ENC_MODE_MEDIA:
163 mapped_code = KC_MEDIA_PLAY_PAUSE; 188 mapped_code = KC_MEDIA_PLAY_PAUSE;
164 break; 189 break;
@@ -174,11 +199,42 @@ uint16_t handle_encoder_press(){
174 breathing_enable(); 199 breathing_enable();
175 } 200 }
176 break; 201 break;
202#ifdef DYNAMIC_KEYMAP_ENABLE
203 case ENC_MODE_CUSTOM0:
204 mapped_code = retrieve_custom_encoder_config(0, ENC_CUSTOM_PRESS);
205 break;
206 case ENC_MODE_CUSTOM1:
207 mapped_code = retrieve_custom_encoder_config(1, ENC_CUSTOM_PRESS);
208 break;
209 case ENC_MODE_CUSTOM2:
210 mapped_code = retrieve_custom_encoder_config(2, ENC_CUSTOM_PRESS);
211 break;
212#endif
177 case ENC_MODE_CLOCK_SET: 213 case ENC_MODE_CLOCK_SET:
178 time_config_idx = (time_config_idx + 1) % 5; 214 time_config_idx = (time_config_idx + 1) % 5;
179 default:
180 case ENC_MODE_BRIGHTNESS: 215 case ENC_MODE_BRIGHTNESS:
181 break; 216 break;
182 } 217 }
183 return mapped_code; 218 return mapped_code;
184} 219}
220
221
222uint16_t retrieve_custom_encoder_config(uint8_t encoder_idx, uint8_t behavior){
223#ifdef DYNAMIC_KEYMAP_ENABLE
224 void* addr = (void*)(DYNAMIC_KEYMAP_CUSTOM_ENCODER + (encoder_idx * 6) + (behavior * 2));
225 //big endian
226 uint16_t keycode = eeprom_read_byte(addr) << 8;
227 keycode |= eeprom_read_byte(addr + 1);
228 return keycode;
229#else
230 return 0;
231#endif
232}
233
234void set_custom_encoder_config(uint8_t encoder_idx, uint8_t behavior, uint16_t new_code){
235#ifdef DYNAMIC_KEYMAP_ENABLE
236 void* addr = (void*)(DYNAMIC_KEYMAP_CUSTOM_ENCODER + (encoder_idx * 6) + (behavior * 2));
237 eeprom_update_byte(addr, (uint8_t)(new_code >> 8));
238 eeprom_update_byte(addr + 1, (uint8_t)(new_code & 0xFF));
239#endif
240}