summaryrefslogtreecommitdiff
path: root/quantum/send_string/send_string.h
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2022-07-02 22:10:08 +1000
committerGitHub <noreply@github.com>2022-07-02 22:10:08 +1000
commit3ecb0a80af9e4ce4194a34032642933641730706 (patch)
tree3d4b0e24336762dc9b45a746334ebc09a5c59db1 /quantum/send_string/send_string.h
parent7e41eb02773207dd4a014575fe750f8d511bfb5b (diff)
Feature-ify Send String (#17275)
Diffstat (limited to 'quantum/send_string/send_string.h')
-rw-r--r--quantum/send_string/send_string.h152
1 files changed, 152 insertions, 0 deletions
diff --git a/quantum/send_string/send_string.h b/quantum/send_string/send_string.h
new file mode 100644
index 0000000000..4eb55b88dc
--- /dev/null
+++ b/quantum/send_string/send_string.h
@@ -0,0 +1,152 @@
1/* Copyright 2021
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
17/**
18 * \defgroup send_string
19 *
20 * Send String API. These functions allow you to create macros by typing out sequences of keystrokes.
21 * \{
22 */
23
24#include <stdint.h>
25
26#include "progmem.h"
27#include "send_string_keycodes.h"
28
29// Look-Up Tables (LUTs) to convert ASCII character to keycode sequence.
30extern const uint8_t ascii_to_shift_lut[16];
31extern const uint8_t ascii_to_altgr_lut[16];
32extern const uint8_t ascii_to_dead_lut[16];
33extern const uint8_t ascii_to_keycode_lut[128];
34
35// clang-format off
36#define KCLUT_ENTRY(a, b, c, d, e, f, g, h) \
37 ( ((a) ? 1 : 0) << 0 \
38 | ((b) ? 1 : 0) << 1 \
39 | ((c) ? 1 : 0) << 2 \
40 | ((d) ? 1 : 0) << 3 \
41 | ((e) ? 1 : 0) << 4 \
42 | ((f) ? 1 : 0) << 5 \
43 | ((g) ? 1 : 0) << 6 \
44 | ((h) ? 1 : 0) << 7 )
45// clang-format on
46
47/**
48 * \brief Type out a string of ASCII characters.
49 *
50 * This function simply calls `send_string_with_delay(string, 0)`.
51 *
52 * Most keycodes from the basic keycode range are also supported by way of a special sequence - see `send_string_keycodes.h`.
53 *
54 * \param string The string to type out.
55 */
56void send_string(const char *string);
57
58/**
59 * \brief Type out a string of ASCII characters, with a delay between each character.
60 *
61 * \param string The string to type out.
62 * \param interval The amount of time, in milliseconds, to wait before typing the next character.
63 */
64void send_string_with_delay(const char *string, uint8_t interval);
65
66/**
67 * \brief Type out an ASCII character.
68 *
69 * \param ascii_code The character to type.
70 */
71void send_char(char ascii_code);
72
73/**
74 * \brief Type out an eight digit (unsigned 32-bit) hexadecimal value.
75 *
76 * The format is `[0-9a-f]{8}`, eg. `00000000` through `ffffffff`.
77 *
78 * \param number The value to type, from 0 to 4,294,967,295.
79 */
80void send_dword(uint32_t number);
81
82/**
83 * \brief Type out a four digit (unsigned 16-bit) hexadecimal value.
84 *
85 * The format is `[0-9a-f]{4}`, eg. `0000` through `ffff`.
86 *
87 * \param number The value to type, from 0 to 65,535.
88 */
89void send_word(uint16_t number);
90
91/**
92 * \brief Type out a two digit (8-bit) hexadecimal value.
93 *
94 * The format is `[0-9a-f]{2}`, eg. `00` through `ff`.
95 *
96 * \param number The value to type, from 0 to 255.
97 */
98void send_byte(uint8_t number);
99
100/**
101 * \brief Type out a single hexadecimal digit.
102 *
103 * The format is `[0-9a-f]{1}`, eg. `0` through `f`.
104 *
105 * \param number The value to type, from 0 to 15.
106 */
107void send_nibble(uint8_t number);
108
109/**
110 * \brief Type a pseudorandom character from the set `A-Z`, `a-z`, `0-9`, `+` and `/`.
111 */
112void tap_random_base64(void);
113
114#if defined(__AVR__) || defined(__DOXYGEN__)
115/**
116 * \brief Type out a PROGMEM string of ASCII characters.
117 *
118 * On ARM devices, this function is simply an alias for send_string_with_delay(string, 0).
119 *
120 * \param string The string to type out.
121 */
122void send_string_P(const char *string);
123
124/**
125 * \brief Type out a PROGMEM string of ASCII characters, with a delay between each character.
126 *
127 * On ARM devices, this function is simply an alias for send_string_with_delay(string, interval).
128 *
129 * \param string The string to type out.
130 * \param interval The amount of time, in milliseconds, to wait before typing the next character.
131 */
132void send_string_with_delay_P(const char *string, uint8_t interval);
133#else
134# define send_string_P(string) send_string_with_delay(string, 0)
135# define send_string_with_delay_P(string, interval) send_string_with_delay(string, interval)
136#endif
137
138/**
139 * \brief Shortcut macro for send_string_with_delay_P(PSTR(string), 0).
140 *
141 * On ARM devices, this define evaluates to send_string_with_delay(string, 0).
142 */
143#define SEND_STRING(string) send_string_with_delay_P(PSTR(string), 0)
144
145/**
146 * \brief Shortcut macro for send_string_with_delay_P(PSTR(string), interval).
147 *
148 * On ARM devices, this define evaluates to send_string_with_delay(string, interval).
149 */
150#define SEND_STRING_DELAY(string, interval) send_string_with_delay_P(PSTR(string), interval)
151
152/** \} */