summaryrefslogtreecommitdiff
path: root/quantum/quantum.h
diff options
context:
space:
mode:
authorDrashna Jael're <drashna@live.com>2021-06-29 12:23:03 -0700
committerDrashna Jael're <drashna@live.com>2021-06-29 12:24:07 -0700
commitacf2c323e2927f6007b17ded577cf49fd86fec6c (patch)
tree8334dc5c71e6ab9bf33c76143eac7bb0e60159b0 /quantum/quantum.h
parentec7a7beeed3046e9144d4c4ce0ef3b2c4f9e4341 (diff)
parentf55e39e8a2246f6f96fd5d4a84a866e2615cde7b (diff)
Merge upstream QMK Firmware at '0.12.52~1'
Diffstat (limited to 'quantum/quantum.h')
-rw-r--r--quantum/quantum.h143
1 files changed, 31 insertions, 112 deletions
diff --git a/quantum/quantum.h b/quantum/quantum.h
index b105c66664..a5ed1b66bd 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -53,12 +53,15 @@
#include "eeconfig.h"
#include "bootloader.h"
#include "timer.h"
+#include "sync_timer.h"
#include "config_common.h"
+#include "gpio.h"
+#include "atomic_util.h"
#include "led.h"
#include "action_util.h"
#include "action_tapping.h"
#include "print.h"
-#include "send_string_keycodes.h"
+#include "send_string.h"
#include "suspend.h"
#include <stddef.h>
#include <stdlib.h>
@@ -201,128 +204,50 @@ extern layer_state_t layer_state;
# include "wpm.h"
#endif
-// Function substitutions to ease GPIO manipulation
-#if defined(__AVR__)
-typedef uint8_t pin_t;
-
-# define setPinInput(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF))
-# define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF))
-# define setPinInputLow(pin) _Static_assert(0, "AVR processors cannot implement an input as pull low")
-# define setPinOutput(pin) (DDRx_ADDRESS(pin) |= _BV((pin)&0xF))
-
-# define writePinHigh(pin) (PORTx_ADDRESS(pin) |= _BV((pin)&0xF))
-# define writePinLow(pin) (PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF))
-# define writePin(pin, level) ((level) ? writePinHigh(pin) : writePinLow(pin))
-
-# define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF)))
-
-# define togglePin(pin) (PORTx_ADDRESS(pin) ^= _BV((pin)&0xF))
-
-#elif defined(PROTOCOL_CHIBIOS)
-typedef ioline_t pin_t;
-
-# define setPinInput(pin) palSetLineMode(pin, PAL_MODE_INPUT)
-# define setPinInputHigh(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLUP)
-# define setPinInputLow(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLDOWN)
-# define setPinOutput(pin) palSetLineMode(pin, PAL_MODE_OUTPUT_PUSHPULL)
-# define writePinHigh(pin) palSetLine(pin)
-# define writePinLow(pin) palClearLine(pin)
-# define writePin(pin, level) ((level) ? (writePinHigh(pin)) : (writePinLow(pin)))
-
-# define readPin(pin) palReadLine(pin)
-
-# define togglePin(pin) palToggleLine(pin)
+#ifdef USBPD_ENABLE
+# include "usbpd.h"
#endif
-// Atomic macro to help make GPIO and other controls atomic.
-#ifdef IGNORE_ATOMIC_BLOCK
-/* do nothing atomic macro */
-# define ATOMIC_BLOCK for (uint8_t __ToDo = 1; __ToDo; __ToDo = 0)
-# define ATOMIC_BLOCK_RESTORESTATE ATOMIC_BLOCK
-# define ATOMIC_BLOCK_FORCEON ATOMIC_BLOCK
-
-#elif defined(__AVR__)
-/* atomic macro for AVR */
-# include <util/atomic.h>
-
-# define ATOMIC_BLOCK_RESTORESTATE ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
-# define ATOMIC_BLOCK_FORCEON ATOMIC_BLOCK(ATOMIC_FORCEON)
+// Function substitutions to ease GPIO manipulation
+#if defined(__AVR__)
-#elif defined(PROTOCOL_CHIBIOS) || defined(PROTOCOL_ARM_ATSAM)
-/* atomic macro for ChibiOS / ARM ATSAM */
-# if defined(PROTOCOL_ARM_ATSAM)
-# include "arm_atsam_protocol.h"
+/* The AVR series GPIOs have a one clock read delay for changes in the digital input signal.
+ * But here's more margin to make it two clocks. */
+# if !defined(GPIO_INPUT_PIN_DELAY)
+# define GPIO_INPUT_PIN_DELAY 2
# endif
+# define waitInputPinDelay() wait_cpuclock(GPIO_INPUT_PIN_DELAY)
-static __inline__ uint8_t __interrupt_disable__(void) {
-# if defined(PROTOCOL_CHIBIOS)
- chSysLock();
-# endif
-# if defined(PROTOCOL_ARM_ATSAM)
- __disable_irq();
-# endif
- return 1;
-}
+#elif defined(__ARMEL__) || defined(__ARMEB__)
-static __inline__ void __interrupt_enable__(const uint8_t *__s) {
-# if defined(PROTOCOL_CHIBIOS)
- chSysUnlock();
-# endif
-# if defined(PROTOCOL_ARM_ATSAM)
- __enable_irq();
+/* For GPIOs on ARM-based MCUs, the input pins are sampled by the clock of the bus
+ * to which the GPIO is connected.
+ * The connected buses differ depending on the various series of MCUs.
+ * And since the instruction execution clock of the CPU and the bus clock of GPIO are different,
+ * there is a delay of several clocks to read the change of the input signal.
+ *
+ * Define this delay with the GPIO_INPUT_PIN_DELAY macro.
+ * If the GPIO_INPUT_PIN_DELAY macro is not defined, the following default values will be used.
+ * (A fairly large value of 0.25 microseconds is set.)
+ */
+# if !defined(GPIO_INPUT_PIN_DELAY)
+# if defined(STM32_SYSCLK)
+# define GPIO_INPUT_PIN_DELAY (STM32_SYSCLK / 1000000L / 4)
+# elif defined(KINETIS_SYSCLK_FREQUENCY)
+# define GPIO_INPUT_PIN_DELAY (KINETIS_SYSCLK_FREQUENCY / 1000000L / 4)
+# endif
# endif
- __asm__ volatile("" ::: "memory");
- (void)__s;
-}
-
-# define ATOMIC_BLOCK(type) for (type, __ToDo = __interrupt_disable__(); __ToDo; __ToDo = 0)
-# define ATOMIC_FORCEON uint8_t sreg_save __attribute__((__cleanup__(__interrupt_enable__))) = 0
-
-# define ATOMIC_BLOCK_RESTORESTATE _Static_assert(0, "ATOMIC_BLOCK_RESTORESTATE dose not implement")
-# define ATOMIC_BLOCK_FORCEON ATOMIC_BLOCK(ATOMIC_FORCEON)
-
-/* Other platform */
-#else
-
-# define ATOMIC_BLOCK_RESTORESTATE _Static_assert(0, "ATOMIC_BLOCK_RESTORESTATE dose not implement")
-# define ATOMIC_BLOCK_FORCEON _Static_assert(0, "ATOMIC_BLOCK_FORCEON dose not implement")
+# define waitInputPinDelay() wait_cpuclock(GPIO_INPUT_PIN_DELAY)
#endif
-#define SEND_STRING(string) send_string_P(PSTR(string))
-#define SEND_STRING_DELAY(string, interval) send_string_with_delay_P(PSTR(string), interval)
-
-// Look-Up Tables (LUTs) to convert ASCII character to keycode sequence.
-extern const uint8_t ascii_to_keycode_lut[128];
-extern const uint8_t ascii_to_shift_lut[16];
-extern const uint8_t ascii_to_altgr_lut[16];
-// clang-format off
-#define KCLUT_ENTRY(a, b, c, d, e, f, g, h) \
- ( ((a) ? 1 : 0) << 0 \
- | ((b) ? 1 : 0) << 1 \
- | ((c) ? 1 : 0) << 2 \
- | ((d) ? 1 : 0) << 3 \
- | ((e) ? 1 : 0) << 4 \
- | ((f) ? 1 : 0) << 5 \
- | ((g) ? 1 : 0) << 6 \
- | ((h) ? 1 : 0) << 7 )
-// clang-format on
-
-void send_string(const char *str);
-void send_string_with_delay(const char *str, uint8_t interval);
-void send_string_P(const char *str);
-void send_string_with_delay_P(const char *str, uint8_t interval);
-void send_char(char ascii_code);
-
// For tri-layer
void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3);
layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_t layer2, uint8_t layer3);
void set_single_persistent_default_layer(uint8_t default_layer);
-void tap_random_base64(void);
-
#define IS_LAYER_ON(layer) layer_state_is(layer)
#define IS_LAYER_OFF(layer) !layer_state_is(layer)
@@ -359,12 +284,6 @@ void register_code16(uint16_t code);
void unregister_code16(uint16_t code);
void tap_code16(uint16_t code);
-void send_dword(uint32_t number);
-void send_word(uint16_t number);
-void send_byte(uint8_t number);
-void send_nibble(uint8_t number);
-uint16_t hex_to_keycode(uint8_t hex);
-
void led_set_user(uint8_t usb_led);
void led_set_kb(uint8_t usb_led);
bool led_update_user(led_t led_state);