aboutsummaryrefslogtreecommitdiffstats
path: root/testhal/STM32/STM32L1xx/SPI/halconf.h
blob: 15abed3b1e9e307464316aa526fafb71144d40c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/*
    ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

/**
 * @file    templates/halconf.h
 * @brief   HAL configuration header.
 * @details HAL configuration file, this file allows to enable or disable the
 *          various device drivers from your application. You may also use
 *          this file in order to override the device drivers default settings.
 *
 * @addtogroup HAL_CONF
 * @{
 */

#ifndef _HALCONF_H_
#define _HALCONF_H_

#include "mcuconf.h"

/**
 * @brief   Enables the TM subsystem.
 */
#if !defined(HAL_USE_TM) || defined(__DOXYGEN__)
#define HAL_USE_TM                  TRUE
#endif

/**
 * @brief   Enables the PAL subsystem.
 */
#if !defined(HAL_USE_PAL) || defined(__DOXYGEN__)
#define HAL_USE_PAL                 TRUE
#endif

/**
 * @brief   Enables the ADC subsystem.
 */
#if !defined(HAL_USE_ADC) || defined(__DOXYGEN__)
#define HAL_USE_ADC                 FALSE
#endif

/**
 * @brief   Enables the CAN subsystem.
 */
#if !defined(HAL_USE_CAN) || defined(__DOXYGEN__)
#define HAL_USE_CAN                 FALSE
#endif

/**
 * @brief   Enables the EXT subsystem.
 */
#if !defined(HAL_USE_EXT) || defined(__DOXYGEN__)
#define HAL_USE_EXT                 FALSE
#endif

/**
 * @brief   Enables the GPT subsystem.
 */
#if !defined(HAL_USE_GPT) || defined(__DOXYGEN__)
#define HAL_USE_GPT                 FALSE
#endif

/**
 * @brief   Enables the I2C subsystem.
 */
#if !defined(HAL_USE_I2C) || defined(__DOXYGEN__)
#define HAL_USE_I2C                 FALSE
#endif

/**
 * @brief   Enables the I2S subsystem.
 */
#if !defined(HAL_USE_I2S) || defined(__DOXYGEN__)
#define HAL_USE_I2S                 FALSE
#endif

/**
 * @brief   Enables the ICU subsystem.
 */
#if !defined(HAL_USE_ICU) || defined(__DOXYGEN__)
#define HAL_USE_ICU                 FALSE
#endif

/**
 * @brief   Enables the MAC subsystem.
 */
#if !defined(HAL_USE_MAC) || defined(__DOXYGEN__)
#define HAL_USE_MAC                 FALSE
#endif

/**
 * @brief   Enables the MMC_SPI subsystem.
 */
#if !defined(HAL_USE_MMC_SPI) || defined(__DOXYGEN__)
#define HAL_USE_MMC_SPI             FALSE
#endif

/**
 * @brief   Enables the PWM subsystem.
 */
#if !defined(HAL_USE_PWM) || defined(__DOXYGEN__)
#define HAL_USE_PWM                 FALSE
#endif

/**
 * @brief   Enables the RTC subsystem.
 */
#if !defined(HAL_USE_RTC) || defined(__DOXYGEN__)
#define HAL_USE_RTC                 FALSE
#endif

/**
 * @brief   Enables the SDC subsystem.
 */
#if !defined(HAL_USE_SDC) || defined(__DOXYGEN__)
#define HAL_USE_SDC                 FALSE
#endif

/**
 * @brief   Enables the SERIAL subsystem.
 */
#if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__)
#define HAL_USE_SERIAL              FALSE
#endif

/**
 * @brief   Enables the SERIAL over USB subsystem.
 */
#if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__)
#define HAL_USE_SERIAL_USB          FALSE
#endif

/**
 * @brief   Enables the SPI subsystem.
 */
#if !defined(HAL_USE_SPI) || defined(__DOXYGEN__)
#define HAL_USE_SPI                 TRUE
#endif

/**
 * @brief   Enables the UART subsystem.
 */
#if !defined(HAL_USE_UART) || defined(__DOXYGEN__)
#define HAL_USE_UART                FALSE
#endif

/**
 * @brief   Enables the USB subsystem.
 */
#if !defined(HAL_USE_USB) || defined(__DOXYGEN__)
#define HAL_USE_USB                 FALSE
#endif

/*===========================================================================*/
/* ADC driver related settings.                                              */
/*===========================================================================*/

/**
 * @brief   Enables synchronous APIs.
 * @note    Disabling this option saves both code and data space.
 */
#if !defined(ADC_USE_WAIT) || defined(__DOXYGEN__)
#define ADC_USE_WAIT                TRUE
#endif

/**
 * @brief   Enables the @p adcAcquireBus() and @p adcReleaseBus() APIs.
 * @note    Disabling this option saves both code and data space.
 */
#if !defined(ADC_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
#define ADC_USE_MUTUAL_EXCLUSION    TRUE
#endif

/*===========================================================================*/
/* CAN driver related settings.                                              */
/*===========================================================================*/

/**
 * @brief   Sleep mode related APIs inclusion switch.
 */
#if !defined(CAN_USE_SLEEP_MODE) || defined(__DOXYGEN__)
#define CAN_USE_SLEEP_MODE          TRUE
#endif

/*===========================================================================*/
/* I2C driver related settings.                                              */
/*===========================================================================*/

/**
 * @brief   Enables the mutual exclusion APIs on the I2C bus.
 */
#if !defined(I2C_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
#define I2C_USE_MUTUAL_EXCLUSION    TRUE
#endif

/*===========================================================================*/
/* MAC driver related settings.                                              */
/*===========================================================================*/

/**
 * @brief   Enables an event sources for incoming packets.
 */
#if !defined(MAC_USE_ZERO_COPY) || defined(__DOXYGEN__)
#define MAC_USE_ZERO_COPY           FALSE
#endif

/**
 * @brief   Enables an event sources for incoming packets.
 */
#if !defined(MAC_USE_EVENTS) || defined(__DOXYGEN__)
#define MAC_USE_EVENTS              TRUE
#endif

/*===========================================================================*/
/* MMC_SPI driver related settings.                                          */
/*===========================================================================*/

/**
 * @brief   Delays insertions.
 * @details If enabled this options inserts delays into the MMC waiting
 *          routines releasing some extra CPU time for the threads with
 *          lower priority, this may slow down the driver a bit however.
 *          This option is recommended also if the SPI driver does not
 *          use a DMA channel and heavily loads the CPU.
 */
#if !defined(MMC_NICE_WAITING) || defined(__DOXYGEN__)
#define MMC_NICE_WAITING            TRUE
#endif

/*===========================================================================*/
/* SDC driver related settings.                                              */
/*===========================================================================*/

/**
 * @brief   Number of initialization attempts before rejecting the card.
 * @note    Attempts are performed at 10mS intervals.
 */
#if !defined(SDC_INIT_RETRY) || defined(__DOXYGEN__)
#define SDC_INIT_RETRY              100
#endif

/**
 * @brief   Include support for MMC cards.
 * @note    MMC support is not yet implemented so this option must be kept
 *          at @p FALSE.
 */
#if !defined(SDC_MMC_SUPPORT) || defined(__DOXYGEN__)
#define SDC_MMC_SUPPORT             FALSE
#endif

/**
 * @brief   Delays insertions.
 * @details If enabled this options inserts delays into the MMC waiting
 *          routines releasing some extra CPU time for the threads with
 *          lower priority, this may slow down the driver a bit however.
 */
#if !defined(SDC_NICE_WAITING) || defined(__DOXYGEN__)
#define SDC_NICE_WAITING            TRUE
#endif

/*===========================================================================*/
/* SERIAL driver related settings.                                           */
/*===========================================================================*/

/**
 * @brief   Default bit rate.
 * @details Configuration parameter, this is the baud rate selected for the
 *          default configuration.
 */
#if !defined(SERIAL_DEFAULT_BITRATE) || defined(__DOXYGEN__)
#define SERIAL_DEFAULT_BITRATE      38400
#endif

/**
 * @brief   Serial buffers size.
 * @details Configuration parameter, you can change the depth of the queue
 *          buffers depending on the requirements of your application.
 * @note    The default is 64 bytes for both the transmission and receive
 *          buffers.
 */
#if !defined(SERIAL_BUFFERS_SIZE) || defined(__DOXYGEN__)
#define SERIAL_BUFFERS_SIZE         16
#endif

/*===========================================================================*/
/* SERIAL_USB driver related setting.                                        */
/*===========================================================================*/

/**
 * @brief   Serial over USB buffers size.
 * @details Configuration parameter, the buffer size must be a multiple of
 *          the USB data endpoint maximum packet size.
 * @note    The default is 64 bytes for both the transmission and receive
 *          buffers.
 */
#if !defined(SERIAL_USB_BUFFERS_SIZE) || defined(__DOXYGEN__)
#define SERIAL_USB_BUFFERS_SIZE     256
#endif

/*===========================================================================*/
/* SPI driver related settings.                                              */
/*===========================================================================*/

/**
 * @brief   Enables synchronous APIs.
 * @note    Disabling this option saves both code and data space.
 */
#if !defined(SPI_USE_WAIT) || defined(__DOXYGEN__)
#define SPI_USE_WAIT                TRUE
#endif

/**
 * @brief   Enables the @p spiAcquireBus() and @p spiReleaseBus() APIs.
 * @note    Disabling this option saves both code and data space.
 */
#if !defined(SPI_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
#define SPI_USE_MUTUAL_EXCLUSION    TRUE
#endif

#endif /* _HALCONF_H_ */

/** @} */
="cpf">"print.h" #include "debug.h" #include "util.h" #include "timer.h" #include "keyboard.h" #include "bootloader.h" #include "action_layer.h" #include "action_util.h" #include "eeconfig.h" #include "sleep_led.h" #include "led.h" #include "command.h" #include "backlight.h" #include "quantum.h" #include "version.h" #ifdef MOUSEKEY_ENABLE #include "mousekey.h" #endif #ifdef PROTOCOL_PJRC #include "usb_keyboard.h" #ifdef EXTRAKEY_ENABLE #include "usb_extra.h" #endif #endif #ifdef PROTOCOL_VUSB #include "usbdrv.h" #endif #ifdef AUDIO_ENABLE #include "audio.h" #endif /* AUDIO_ENABLE */ static bool command_common(uint8_t code); static void command_common_help(void); static void print_version(void); static void print_status(void); static bool command_console(uint8_t code); static void command_console_help(void); #ifdef MOUSEKEY_ENABLE static bool mousekey_console(uint8_t code); static void mousekey_console_help(void); #endif static void switch_default_layer(uint8_t layer); command_state_t command_state = ONESHOT; bool command_proc(uint8_t code) { switch (command_state) { case ONESHOT: if (!IS_COMMAND()) return false; return (command_extra(code) || command_common(code)); break; case CONSOLE: if (IS_COMMAND()) return (command_extra(code) || command_common(code)); else return (command_console_extra(code) || command_console(code)); break; #ifdef MOUSEKEY_ENABLE case MOUSEKEY: mousekey_console(code); break; #endif default: command_state = ONESHOT; return false; } return true; } /* TODO: Refactoring is needed. */ /* This allows to define extra commands. return false when not processed. */ bool command_extra(uint8_t code) __attribute__ ((weak)); bool command_extra(uint8_t code) { (void)code; return false; } bool command_console_extra(uint8_t code) __attribute__ ((weak)); bool command_console_extra(uint8_t code) { (void)code; return false; } /*********************************************************** * Command common ***********************************************************/ static void command_common_help(void) { print( "\n\t- Magic -\n" STR(MAGIC_KEY_DEBUG ) ": Debug Message Toggle\n" STR(MAGIC_KEY_DEBUG_MATRIX) ": Matrix Debug Mode Toggle - Show keypresses in matrix grid\n" STR(MAGIC_KEY_DEBUG_KBD ) ": Keyboard Debug Toggle - Show keypress report\n" STR(MAGIC_KEY_DEBUG_MOUSE ) ": Debug Mouse Toggle\n" STR(MAGIC_KEY_VERSION ) ": Version\n" STR(MAGIC_KEY_STATUS ) ": Status\n" STR(MAGIC_KEY_CONSOLE ) ": Activate Console Mode\n" #if MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM STR(MAGIC_KEY_LAYER0 ) ": Switch to Layer 0\n" STR(MAGIC_KEY_LAYER1 ) ": Switch to Layer 1\n" STR(MAGIC_KEY_LAYER2 ) ": Switch to Layer 2\n" STR(MAGIC_KEY_LAYER3 ) ": Switch to Layer 3\n" STR(MAGIC_KEY_LAYER4 ) ": Switch to Layer 4\n" STR(MAGIC_KEY_LAYER5 ) ": Switch to Layer 5\n" STR(MAGIC_KEY_LAYER6 ) ": Switch to Layer 6\n" STR(MAGIC_KEY_LAYER7 ) ": Switch to Layer 7\n" STR(MAGIC_KEY_LAYER8 ) ": Switch to Layer 8\n" STR(MAGIC_KEY_LAYER9 ) ": Switch to Layer 9\n" #endif #if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS "F1-F10: Switch to Layer 0-9 (F10 = L0)\n" #endif #if MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS "0-9: Switch to Layer 0-9\n" #endif STR(MAGIC_KEY_LAYER0_ALT ) ": Switch to Layer 0 (alternate)\n" STR(MAGIC_KEY_BOOTLOADER ) ": Jump to Bootloader\n" STR(MAGIC_KEY_BOOTLOADER_ALT) ": Jump to Bootloader (alternate)\n" #ifdef KEYBOARD_LOCK_ENABLE STR(MAGIC_KEY_LOCK ) ": Lock Keyboard\n" #endif STR(MAGIC_KEY_EEPROM ) ": Print EEPROM Settings\n" STR(MAGIC_KEY_EEPROM_CLEAR) ": Clear EEPROM\n" #ifdef NKRO_ENABLE STR(MAGIC_KEY_NKRO ) ": NKRO Toggle\n" #endif #ifdef SLEEP_LED_ENABLE STR(MAGIC_KEY_SLEEP_LED ) ": Sleep LED Test\n" #endif ); } static void print_version(void) { // print version & information print("\n\t- Version -\n"); print("DESC: " STR(DESCRIPTION) "\n"); print("VID: " STR(VENDOR_ID) "(" STR(MANUFACTURER) ") " "PID: " STR(PRODUCT_ID) "(" STR(PRODUCT) ") " "VER: " STR(DEVICE_VER) "\n"); #ifdef SKIP_VERSION print("BUILD: (" __DATE__ ")\n"); #else print("BUILD: " STR(QMK_VERSION) " (" __TIME__ " " __DATE__ ")\n"); #endif /* build options */ print("OPTIONS:" #ifdef PROTOCOL_PJRC " PJRC" #endif #ifdef PROTOCOL_LUFA " LUFA" #endif #ifdef PROTOCOL_VUSB " VUSB" #endif #ifdef BOOTMAGIC_ENABLE " BOOTMAGIC" #endif #ifdef MOUSEKEY_ENABLE " MOUSEKEY" #endif #ifdef EXTRAKEY_ENABLE " EXTRAKEY" #endif #ifdef CONSOLE_ENABLE " CONSOLE" #endif #ifdef COMMAND_ENABLE " COMMAND" #endif #ifdef NKRO_ENABLE " NKRO" #endif #ifdef KEYMAP_SECTION_ENABLE " KEYMAP_SECTION" #endif " " STR(BOOTLOADER_SIZE) "\n"); print("GCC: " STR(__GNUC__) "." STR(__GNUC_MINOR__) "." STR(__GNUC_PATCHLEVEL__) #if defined(__AVR__) " AVR-LIBC: " __AVR_LIBC_VERSION_STRING__ " AVR_ARCH: avr" STR(__AVR_ARCH__) #endif "\n"); return; } static void print_status(void) { print("\n\t- Status -\n"); print_val_hex8(host_keyboard_leds()); #ifndef PROTOCOL_VUSB // these aren't set on the V-USB protocol, so we just ignore them for now print_val_hex8(keyboard_protocol); print_val_hex8(keyboard_idle); #endif #ifdef NKRO_ENABLE print_val_hex8(keymap_config.nkro); #endif print_val_hex32(timer_read32()); #ifdef PROTOCOL_PJRC print_val_hex8(UDCON); print_val_hex8(UDIEN); print_val_hex8(UDINT); print_val_hex8(usb_keyboard_leds); print_val_hex8(usb_keyboard_idle_count); #endif #ifdef PROTOCOL_PJRC # if USB_COUNT_SOF print_val_hex8(usbSofCount); # endif #endif return; } static void print_eeconfig(void) { // Print these variables if NO_PRINT or USER_PRINT are not defined. #if !defined(NO_PRINT) && !defined(USER_PRINT) print("default_layer: "); print_dec(eeconfig_read_default_layer()); print("\n"); debug_config_t dc; dc.raw = eeconfig_read_debug(); print("debug_config.raw: "); print_hex8(dc.raw); print("\n"); print(".enable: "); print_dec(dc.enable); print("\n"); print(".matrix: "); print_dec(dc.matrix); print("\n"); print(".keyboard: "); print_dec(dc.keyboard); print("\n"); print(".mouse: "); print_dec(dc.mouse); print("\n"); keymap_config_t kc; kc.raw = eeconfig_read_keymap(); print("keymap_config.raw: "); print_hex8(kc.raw); print("\n"); print(".swap_control_capslock: "); print_dec(kc.swap_control_capslock); print("\n"); print(".capslock_to_control: "); print_dec(kc.capslock_to_control); print("\n"); print(".swap_lalt_lgui: "); print_dec(kc.swap_lalt_lgui); print("\n"); print(".swap_ralt_rgui: "); print_dec(kc.swap_ralt_rgui); print("\n"); print(".no_gui: "); print_dec(kc.no_gui); print("\n"); print(".swap_grave_esc: "); print_dec(kc.swap_grave_esc); print("\n"); print(".swap_backslash_backspace: "); print_dec(kc.swap_backslash_backspace); print("\n"); print(".nkro: "); print_dec(kc.nkro); print("\n"); #ifdef BACKLIGHT_ENABLE backlight_config_t bc; bc.raw = eeconfig_read_backlight(); print("backlight_config.raw: "); print_hex8(bc.raw); print("\n"); print(".enable: "); print_dec(bc.enable); print("\n"); print(".level: "); print_dec(bc.level); print("\n"); #endif /* BACKLIGHT_ENABLE */ #endif /* !NO_PRINT */ } static bool command_common(uint8_t code) { #ifdef KEYBOARD_LOCK_ENABLE static host_driver_t *host_driver = 0; #endif switch (code) { #ifdef SLEEP_LED_ENABLE // test breathing sleep LED case MAGIC_KC(MAGIC_KEY_SLEEP_LED): print("Sleep LED Test\n"); sleep_led_toggle(); led_set(host_keyboard_leds()); break; #endif // print stored eeprom config case MAGIC_KC(MAGIC_KEY_EEPROM): print("eeconfig:\n"); print_eeconfig(); break; // clear eeprom case MAGIC_KC(MAGIC_KEY_EEPROM_CLEAR): print("Clearing EEPROM\n"); eeconfig_init(); break; #ifdef KEYBOARD_LOCK_ENABLE // lock/unlock keyboard case MAGIC_KC(MAGIC_KEY_LOCK): if (host_get_driver()) { host_driver = host_get_driver(); clear_keyboard(); host_set_driver(0); print("Locked.\n"); } else { host_set_driver(host_driver); print("Unlocked.\n"); } break; #endif // print help case MAGIC_KC(MAGIC_KEY_HELP): case MAGIC_KC(MAGIC_KEY_HELP_ALT): command_common_help(); break; // activate console case MAGIC_KC(MAGIC_KEY_CONSOLE): debug_matrix = false; debug_keyboard = false; debug_mouse = false; debug_enable = false; command_console_help(); print("C> "); command_state = CONSOLE; break; // jump to bootloader case MAGIC_KC(MAGIC_KEY_BOOTLOADER): case MAGIC_KC(MAGIC_KEY_BOOTLOADER_ALT): clear_keyboard(); // clear to prevent stuck keys print("\n\nJumping to bootloader... "); #ifdef AUDIO_ENABLE stop_all_notes(); shutdown_user(); #else wait_ms(1000); #endif bootloader_jump(); // not return break; // debug toggle case MAGIC_KC(MAGIC_KEY_DEBUG): debug_enable = !debug_enable; if (debug_enable) { print("\ndebug: on\n"); } else { print("\ndebug: off\n"); debug_matrix = false; debug_keyboard = false; debug_mouse = false; } break; // debug matrix toggle case MAGIC_KC(MAGIC_KEY_DEBUG_MATRIX): debug_matrix = !debug_matrix; if (debug_matrix) { print("\nmatrix: on\n"); debug_enable = true; } else { print("\nmatrix: off\n"); } break; // debug keyboard toggle case MAGIC_KC(MAGIC_KEY_DEBUG_KBD): debug_keyboard = !debug_keyboard; if (debug_keyboard) { print("\nkeyboard: on\n"); debug_enable = true; } else { print("\nkeyboard: off\n"); } break; // debug mouse toggle case MAGIC_KC(MAGIC_KEY_DEBUG_MOUSE): debug_mouse = !debug_mouse; if (debug_mouse) { print("\nmouse: on\n"); debug_enable = true; } else { print("\nmouse: off\n"); } break; // print version case MAGIC_KC(MAGIC_KEY_VERSION): print_version(); break; // print status case MAGIC_KC(MAGIC_KEY_STATUS): print_status(); break; #ifdef NKRO_ENABLE // NKRO toggle case MAGIC_KC(MAGIC_KEY_NKRO): clear_keyboard(); // clear to prevent stuck keys keymap_config.nkro = !keymap_config.nkro; if (keymap_config.nkro) { print("NKRO: on\n"); } else { print("NKRO: off\n"); } break; #endif // switch layers case MAGIC_KC(MAGIC_KEY_LAYER0_ALT): switch_default_layer(0); break; #if MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM case MAGIC_KC(MAGIC_KEY_LAYER0): switch_default_layer(0); break; case MAGIC_KC(MAGIC_KEY_LAYER1): switch_default_layer(1); break; case MAGIC_KC(MAGIC_KEY_LAYER2): switch_default_layer(2); break; case MAGIC_KC(MAGIC_KEY_LAYER3): switch_default_layer(3); break; case MAGIC_KC(MAGIC_KEY_LAYER4): switch_default_layer(4); break; case MAGIC_KC(MAGIC_KEY_LAYER5): switch_default_layer(5); break; case MAGIC_KC(MAGIC_KEY_LAYER6): switch_default_layer(6); break; case MAGIC_KC(MAGIC_KEY_LAYER7): switch_default_layer(7); break; case MAGIC_KC(MAGIC_KEY_LAYER8): switch_default_layer(8); break; case MAGIC_KC(MAGIC_KEY_LAYER9): switch_default_layer(9); break; #endif #if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS case KC_F1 ... KC_F9: switch_default_layer((code - KC_F1) + 1); break; case KC_F10: switch_default_layer(0); break; #endif #if MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS case KC_1 ... KC_9: switch_default_layer((code - KC_1) + 1); break; case KC_0: switch_default_layer(0); break; #endif default: print("?"); return false; } return true; } /*********************************************************** * Command console ***********************************************************/ static void command_console_help(void) { print("\n\t- Console -\n" "ESC/q: quit\n" #ifdef MOUSEKEY_ENABLE "m: mousekey\n" #endif ); } static bool command_console(uint8_t code) { switch (code) { case KC_H: case KC_SLASH: /* ? */ command_console_help(); break; case KC_Q: case KC_ESC: command_state = ONESHOT; return false; #ifdef MOUSEKEY_ENABLE case KC_M: mousekey_console_help(); print("M> "); command_state = MOUSEKEY; return true; #endif default: print("?"); return false; } print("C> "); return true; } #ifdef MOUSEKEY_ENABLE /*********************************************************** * Mousekey console ***********************************************************/ static uint8_t mousekey_param = 0; static void mousekey_param_print(void) { // Print these variables if NO_PRINT or USER_PRINT are not defined. #if !defined(NO_PRINT) && !defined(USER_PRINT) print("\n\t- Values -\n"); print("1: delay(*10ms): "); pdec(mk_delay); print("\n"); print("2: interval(ms): "); pdec(mk_interval); print("\n"); print("3: max_speed: "); pdec(mk_max_speed); print("\n"); print("4: time_to_max: "); pdec(mk_time_to_max); print("\n"); print("5: wheel_max_speed: "); pdec(mk_wheel_max_speed); print("\n"); print("6: wheel_time_to_max: "); pdec(mk_wheel_time_to_max); print("\n"); #endif /* !NO_PRINT */ } //#define PRINT_SET_VAL(v) print(#v " = "); print_dec(v); print("\n"); #define PRINT_SET_VAL(v) xprintf(#v " = %d\n", (v)) static void mousekey_param_inc(uint8_t param, uint8_t inc) { switch (param) { case 1: if (mk_delay + inc < UINT8_MAX) mk_delay += inc; else mk_delay = UINT8_MAX; PRINT_SET_VAL(mk_delay); break; case 2: if (mk_interval + inc < UINT8_MAX) mk_interval += inc; else mk_interval = UINT8_MAX; PRINT_SET_VAL(mk_interval); break; case 3: if (mk_max_speed + inc < UINT8_MAX) mk_max_speed += inc; else mk_max_speed = UINT8_MAX; PRINT_SET_VAL(mk_max_speed); break; case 4: if (mk_time_to_max + inc < UINT8_MAX) mk_time_to_max += inc; else mk_time_to_max = UINT8_MAX; PRINT_SET_VAL(mk_time_to_max); break; case 5: if (mk_wheel_max_speed + inc < UINT8_MAX) mk_wheel_max_speed += inc; else mk_wheel_max_speed = UINT8_MAX; PRINT_SET_VAL(mk_wheel_max_speed); break; case 6: if (mk_wheel_time_to_max + inc < UINT8_MAX) mk_wheel_time_to_max += inc; else mk_wheel_time_to_max = UINT8_MAX; PRINT_SET_VAL(mk_wheel_time_to_max); break; } } static void mousekey_param_dec(uint8_t param, uint8_t dec) { switch (param) { case 1: if (mk_delay > dec) mk_delay -= dec; else mk_delay = 0; PRINT_SET_VAL(mk_delay); break; case 2: if (mk_interval > dec) mk_interval -= dec; else mk_interval = 0; PRINT_SET_VAL(mk_interval); break; case 3: if (mk_max_speed > dec) mk_max_speed -= dec; else mk_max_speed = 0; PRINT_SET_VAL(mk_max_speed); break; case 4: if (mk_time_to_max > dec) mk_time_to_max -= dec; else mk_time_to_max = 0; PRINT_SET_VAL(mk_time_to_max); break; case 5: if (mk_wheel_max_speed > dec) mk_wheel_max_speed -= dec; else mk_wheel_max_speed = 0; PRINT_SET_VAL(mk_wheel_max_speed); break; case 6: if (mk_wheel_time_to_max > dec) mk_wheel_time_to_max -= dec; else mk_wheel_time_to_max = 0; PRINT_SET_VAL(mk_wheel_time_to_max); break; } } static void mousekey_console_help(void) { print("\n\t- Mousekey -\n" "ESC/q: quit\n" "1: delay(*10ms)\n" "2: interval(ms)\n" "3: max_speed\n" "4: time_to_max\n" "5: wheel_max_speed\n" "6: wheel_time_to_max\n" "\n" "p: print values\n" "d: set defaults\n" "up: +1\n" "down: -1\n" "pgup: +10\n" "pgdown: -10\n" "\n" "speed = delta * max_speed * (repeat / time_to_max)\n"); xprintf("where delta: cursor=%d, wheel=%d\n" "See http://en.wikipedia.org/wiki/Mouse_keys\n", MOUSEKEY_MOVE_DELTA, MOUSEKEY_WHEEL_DELTA); } static bool mousekey_console(uint8_t code) { switch (code) { case KC_H: case KC_SLASH: /* ? */ mousekey_console_help(); break; case KC_Q: case KC_ESC: if (mousekey_param) { mousekey_param = 0; } else { print("C> "); command_state = CONSOLE; return false; } break; case KC_P: mousekey_param_print(); break; case KC_1: case KC_2: case KC_3: case KC_4: case KC_5: case KC_6: mousekey_param = numkey2num(code); break; case KC_UP: mousekey_param_inc(mousekey_param, 1); break; case KC_DOWN: mousekey_param_dec(mousekey_param, 1); break; case KC_PGUP: mousekey_param_inc(mousekey_param, 10); break; case KC_PGDN: mousekey_param_dec(mousekey_param, 10); break; case KC_D: mk_delay = MOUSEKEY_DELAY/10; mk_interval = MOUSEKEY_INTERVAL; mk_max_speed = MOUSEKEY_MAX_SPEED; mk_time_to_max = MOUSEKEY_TIME_TO_MAX; mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED; mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX; print("set default\n"); break; default: print("?"); return false; } if (mousekey_param) { xprintf("M%d> ", mousekey_param); } else { print("M>" ); } return true; } #endif /*********************************************************** * Utilities ***********************************************************/ uint8_t numkey2num(uint8_t code) { switch (code) { case KC_1: return 1; case KC_2: return 2; case KC_3: return 3; case KC_4: return 4; case KC_5: return 5; case KC_6: return 6; case KC_7: return 7; case KC_8: return 8; case KC_9: return 9; case KC_0: return 0; } return 0; } static void switch_default_layer(uint8_t layer) { xprintf("L%d\n", layer); default_layer_set(1UL<<layer); clear_keyboard(); }