quantum.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /* Copyright 2016-2018 Erez Zukerman, Jack Humbert, Yiancar
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef QUANTUM_H
  17. #define QUANTUM_H
  18. #if defined(__AVR__)
  19. #include <avr/pgmspace.h>
  20. #include <avr/io.h>
  21. #include <avr/interrupt.h>
  22. #endif
  23. #if defined(PROTOCOL_CHIBIOS)
  24. #include "hal.h"
  25. #endif
  26. #include "wait.h"
  27. #include "matrix.h"
  28. #include "keymap.h"
  29. #ifdef BACKLIGHT_ENABLE
  30. #include "backlight.h"
  31. #endif
  32. #if !defined(RGBLIGHT_ENABLE) && !defined(RGB_MATRIX_ENABLE)
  33. #include "rgb.h"
  34. #endif
  35. #ifdef RGBLIGHT_ENABLE
  36. #include "rgblight.h"
  37. #else
  38. #ifdef RGB_MATRIX_ENABLE
  39. /* dummy define RGBLIGHT_MODE_xxxx */
  40. #define RGBLIGHT_H_DUMMY_DEFINE
  41. #include "rgblight.h"
  42. #endif
  43. #endif
  44. #ifdef SPLIT_KEYBOARD
  45. #include "split_flags.h"
  46. #endif
  47. #ifdef RGB_MATRIX_ENABLE
  48. #include "rgb_matrix.h"
  49. #endif
  50. #include "action_layer.h"
  51. #include "eeconfig.h"
  52. #include <stddef.h>
  53. #include "bootloader.h"
  54. #include "timer.h"
  55. #include "config_common.h"
  56. #include "led.h"
  57. #include "action_util.h"
  58. #include <stdlib.h>
  59. #include "print.h"
  60. #include "send_string_keycodes.h"
  61. #include "suspend.h"
  62. extern uint32_t default_layer_state;
  63. #ifndef NO_ACTION_LAYER
  64. extern uint32_t layer_state;
  65. #endif
  66. #ifdef MIDI_ENABLE
  67. #ifdef MIDI_ADVANCED
  68. #include "process_midi.h"
  69. #endif
  70. #endif // MIDI_ENABLE
  71. #ifdef AUDIO_ENABLE
  72. #include "audio.h"
  73. #include "process_audio.h"
  74. #ifdef AUDIO_CLICKY
  75. #include "process_clicky.h"
  76. #endif // AUDIO_CLICKY
  77. #endif
  78. #ifdef STENO_ENABLE
  79. #include "process_steno.h"
  80. #endif
  81. #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
  82. #include "process_music.h"
  83. #endif
  84. #ifdef LEADER_ENABLE
  85. #include "process_leader.h"
  86. #endif
  87. #ifdef UNICODE_ENABLE
  88. #include "process_unicode.h"
  89. #endif
  90. #ifdef UCIS_ENABLE
  91. #include "process_ucis.h"
  92. #endif
  93. #ifdef UNICODEMAP_ENABLE
  94. #include "process_unicodemap.h"
  95. #endif
  96. #ifdef TAP_DANCE_ENABLE
  97. #include "process_tap_dance.h"
  98. #endif
  99. #ifdef PRINTING_ENABLE
  100. #include "process_printer.h"
  101. #endif
  102. #ifdef AUTO_SHIFT_ENABLE
  103. #include "process_auto_shift.h"
  104. #endif
  105. #ifdef COMBO_ENABLE
  106. #include "process_combo.h"
  107. #endif
  108. #ifdef KEY_LOCK_ENABLE
  109. #include "process_key_lock.h"
  110. #endif
  111. #ifdef TERMINAL_ENABLE
  112. #include "process_terminal.h"
  113. #else
  114. #include "process_terminal_nop.h"
  115. #endif
  116. #ifdef HD44780_ENABLE
  117. #include "hd44780.h"
  118. #endif
  119. //Function substitutions to ease GPIO manipulation
  120. #ifdef __AVR__
  121. #define PIN_ADDRESS(p, offset) _SFR_IO8(ADDRESS_BASE + (p >> PORT_SHIFTER) + offset)
  122. #define pin_t uint8_t
  123. #define setPinInput(pin) PIN_ADDRESS(pin, 1) &= ~ _BV(pin & 0xF)
  124. #define setPinInputHigh(pin) ({\
  125. PIN_ADDRESS(pin, 1) &= ~ _BV(pin & 0xF);\
  126. PIN_ADDRESS(pin, 2) |= _BV(pin & 0xF);\
  127. })
  128. #define setPinInputLow(pin) _Static_assert(0, "AVR Processors cannot impliment an input as pull low")
  129. #define setPinOutput(pin) PIN_ADDRESS(pin, 1) |= _BV(pin & 0xF)
  130. #define writePinHigh(pin) PIN_ADDRESS(pin, 2) |= _BV(pin & 0xF)
  131. #define writePinLow(pin) PIN_ADDRESS(pin, 2) &= ~_BV(pin & 0xF)
  132. static inline void writePin(pin_t pin, uint8_t level){
  133. if (level){
  134. PIN_ADDRESS(pin, 2) |= _BV(pin & 0xF);
  135. } else {
  136. PIN_ADDRESS(pin, 2) &= ~_BV(pin & 0xF);
  137. }
  138. }
  139. #define readPin(pin) (PIN_ADDRESS(pin, 0) & _BV(pin & 0xF))
  140. #elif defined(PROTOCOL_CHIBIOS)
  141. #define pin_t ioline_t
  142. #define setPinInput(pin) palSetLineMode(pin, PAL_MODE_INPUT)
  143. #define setPinInputHigh(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLUP)
  144. #define setPinInputLow(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLDOWN)
  145. #define setPinOutput(pin) palSetLineMode(pin, PAL_MODE_OUTPUT_PUSHPULL)
  146. #define writePinHigh(pin) palSetLine(pin)
  147. #define writePinLow(pin) palClearLine(pin)
  148. static inline void writePin(pin_t pin, uint8_t level){
  149. if (level){
  150. palSetLine(pin);
  151. } else {
  152. palClearLine(pin);
  153. }
  154. }
  155. #define readPin(pin) palReadLine(pin)
  156. #endif
  157. #define STRINGIZE(z) #z
  158. #define ADD_SLASH_X(y) STRINGIZE(\x ## y)
  159. #define SYMBOL_STR(x) ADD_SLASH_X(x)
  160. #define SS_TAP(keycode) "\1" SYMBOL_STR(keycode)
  161. #define SS_DOWN(keycode) "\2" SYMBOL_STR(keycode)
  162. #define SS_UP(keycode) "\3" SYMBOL_STR(keycode)
  163. #define SS_LCTRL(string) SS_DOWN(X_LCTRL) string SS_UP(X_LCTRL)
  164. #define SS_LGUI(string) SS_DOWN(X_LGUI) string SS_UP(X_LGUI)
  165. #define SS_LCMD(string) SS_LGUI(string)
  166. #define SS_LWIN(string) SS_LGUI(string)
  167. #define SS_LALT(string) SS_DOWN(X_LALT) string SS_UP(X_LALT)
  168. #define SS_LSFT(string) SS_DOWN(X_LSHIFT) string SS_UP(X_LSHIFT)
  169. #define SS_RALT(string) SS_DOWN(X_RALT) string SS_UP(X_RALT)
  170. #define SEND_STRING(str) send_string_P(PSTR(str))
  171. extern const bool ascii_to_shift_lut[0x80];
  172. extern const uint8_t ascii_to_keycode_lut[0x80];
  173. void send_string(const char *str);
  174. void send_string_with_delay(const char *str, uint8_t interval);
  175. void send_string_P(const char *str);
  176. void send_string_with_delay_P(const char *str, uint8_t interval);
  177. void send_char(char ascii_code);
  178. // For tri-layer
  179. void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3);
  180. uint32_t update_tri_layer_state(uint32_t state, uint8_t layer1, uint8_t layer2, uint8_t layer3);
  181. void set_single_persistent_default_layer(uint8_t default_layer);
  182. void tap_random_base64(void);
  183. #define IS_LAYER_ON(layer) (layer_state & (1UL << (layer)))
  184. #define IS_LAYER_OFF(layer) (~layer_state & (1UL << (layer)))
  185. void matrix_init_kb(void);
  186. void matrix_scan_kb(void);
  187. void matrix_init_user(void);
  188. void matrix_scan_user(void);
  189. bool process_action_kb(keyrecord_t *record);
  190. bool process_record_kb(uint16_t keycode, keyrecord_t *record);
  191. bool process_record_user(uint16_t keycode, keyrecord_t *record);
  192. #ifndef BOOTMAGIC_LITE_COLUMN
  193. #define BOOTMAGIC_LITE_COLUMN 0
  194. #endif
  195. #ifndef BOOTMAGIC_LITE_ROW
  196. #define BOOTMAGIC_LITE_ROW 0
  197. #endif
  198. void bootmagic_lite(void);
  199. void reset_keyboard(void);
  200. void startup_user(void);
  201. void shutdown_user(void);
  202. void register_code16 (uint16_t code);
  203. void unregister_code16 (uint16_t code);
  204. #ifdef BACKLIGHT_ENABLE
  205. void backlight_init_ports(void);
  206. void backlight_task(void);
  207. #ifdef BACKLIGHT_BREATHING
  208. void breathing_enable(void);
  209. void breathing_pulse(void);
  210. void breathing_disable(void);
  211. void breathing_self_disable(void);
  212. void breathing_toggle(void);
  213. bool is_breathing(void);
  214. void breathing_intensity_default(void);
  215. void breathing_period_default(void);
  216. void breathing_period_set(uint8_t value);
  217. void breathing_period_inc(void);
  218. void breathing_period_dec(void);
  219. #endif
  220. #endif
  221. void send_dword(uint32_t number);
  222. void send_word(uint16_t number);
  223. void send_byte(uint8_t number);
  224. void send_nibble(uint8_t number);
  225. uint16_t hex_to_keycode(uint8_t hex);
  226. void led_set_user(uint8_t usb_led);
  227. void led_set_kb(uint8_t usb_led);
  228. void api_send_unicode(uint32_t unicode);
  229. #endif