M5Unit-KEYBOARD 0.0.1 git rev:a483db1
Loading...
Searching...
No Matches
unit_CardKB.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
3 *
4 * SPDX-License-Identifier: MIT
5 */
10#ifndef M5_UNIT_KEYBOARD_UNIT_CARD_KB_HPP
11#define M5_UNIT_KEYBOARD_UNIT_CARD_KB_HPP
12
13#include "unit_Keyboard.hpp"
14#include <m5_utility/container/circular_buffer.hpp>
15
16namespace m5 {
17namespace unit {
18
23namespace cardkb {
26constexpr uint8_t TYPE_CARDKB{0x01};
27constexpr uint8_t TYPE_CARDKB_V11{0x11};
29} // namespace cardkb
30
36class UnitCardKB : public UnitKeyboardBitwise {
37 M5_UNIT_COMPONENT_HPP_BUILDER(UnitCardKB, 0x5F);
38
39public:
40 static constexpr uint8_t NUMBER_OF_KEYS{48};
41
44 static constexpr keyboard::key_index_t KEY_ESC{0};
45 static constexpr keyboard::key_index_t KEY_1{1};
46 static constexpr keyboard::key_index_t KEY_2{2};
47 static constexpr keyboard::key_index_t KEY_3{3};
48 static constexpr keyboard::key_index_t KEY_4{4};
49 static constexpr keyboard::key_index_t KEY_5{5};
50 static constexpr keyboard::key_index_t KEY_6{6};
51 static constexpr keyboard::key_index_t KEY_7{7};
52 static constexpr keyboard::key_index_t KEY_8{8};
53 static constexpr keyboard::key_index_t KEY_9{9};
54 static constexpr keyboard::key_index_t KEY_0{10};
55 static constexpr keyboard::key_index_t KEY_BS{11};
56 static constexpr keyboard::key_index_t KEY_TAB{12};
57 static constexpr keyboard::key_index_t KEY_Q{13};
58 static constexpr keyboard::key_index_t KEY_W{14};
59 static constexpr keyboard::key_index_t KEY_E{15};
60 static constexpr keyboard::key_index_t KEY_R{16};
61 static constexpr keyboard::key_index_t KEY_T{17};
62 static constexpr keyboard::key_index_t KEY_Y{18};
63 static constexpr keyboard::key_index_t KEY_U{19};
64 static constexpr keyboard::key_index_t KEY_I{20};
65 static constexpr keyboard::key_index_t KEY_O{21};
66 static constexpr keyboard::key_index_t KEY_P{22};
67 static constexpr keyboard::key_index_t KEY_NO_KEY{23};
68 static constexpr keyboard::key_index_t KEY_LEFT{24};
69 static constexpr keyboard::key_index_t KEY_UP{25};
70 static constexpr keyboard::key_index_t KEY_A{26};
71 static constexpr keyboard::key_index_t KEY_S{27};
72 static constexpr keyboard::key_index_t KEY_D{28};
73 static constexpr keyboard::key_index_t KEY_F{29};
74 static constexpr keyboard::key_index_t KEY_G{30};
75 static constexpr keyboard::key_index_t KEY_H{31};
76 static constexpr keyboard::key_index_t KEY_J{32};
77 static constexpr keyboard::key_index_t KEY_K{33};
78 static constexpr keyboard::key_index_t KEY_L{34};
79 static constexpr keyboard::key_index_t KEY_ENTER{35};
80 static constexpr keyboard::key_index_t KEY_DOWN{36};
81 static constexpr keyboard::key_index_t KEY_RIGHT{37};
82 static constexpr keyboard::key_index_t KEY_Z{38};
83 static constexpr keyboard::key_index_t KEY_X{39};
84 static constexpr keyboard::key_index_t KEY_C{40};
85 static constexpr keyboard::key_index_t KEY_V{41};
86 static constexpr keyboard::key_index_t KEY_B{42};
87 static constexpr keyboard::key_index_t KEY_N{43};
88 static constexpr keyboard::key_index_t KEY_M{44};
89 static constexpr keyboard::key_index_t KEY_COMMA{45};
90 static constexpr keyboard::key_index_t KEY_PERIOD{46};
91 static constexpr keyboard::key_index_t KEY_SPACE{47};
93
96 static constexpr char SCHAR_LEFT{static_cast<char>(180)};
97 static constexpr char SCHAR_UP{static_cast<char>(181)};
98 static constexpr char SCHAR_DOWN{static_cast<char>(182)};
99 static constexpr char SCHAR_RIGHT{static_cast<char>(183)};
101
106 struct config_t {
108 bool start_periodic{true};
111
112 keyboard::Mode mode{keyboard::Mode::Conventional};
114 uint32_t interval{10};
116 uint32_t repeating_threshold{400};
118 uint32_t holding_threshold{800};
120 };
121
122 explicit UnitCardKB(const uint8_t addr = DEFAULT_ADDRESS) : UnitKeyboardBitwise(addr)
123 {
124 _repeat_start_at.resize(NUMBER_OF_KEYS);
125 _hold_start_at.resize(NUMBER_OF_KEYS);
126 }
128 virtual bool begin() override;
130 virtual void update(const bool force = false) override;
131
134
136 {
137 return _cfg;
138 }
140 inline void config(const config_t& cfg)
141 {
142 _cfg = cfg;
143 }
145
147 inline virtual keyboard::key_index_t toKeyIndex(const char ch) const override
148 {
149 return character_to_key_index(ch);
150 }
151
157 static keyboard::key_index_t character_to_key_index(const char ch);
164 static uint8_t character_to_mode_bits(const char ch);
165
169
173 uint8_t hardwareType() const
174 {
175 return _type;
176 }
182 bool readHardwareType(uint8_t& htype);
184
185protected:
186 bool update_new_firmware(const types::elapsed_time_t at);
187 void push_back(m5::container::CircularBuffer<uint8_t>* container, const uint8_t kidx, const uint8_t mod8);
188
189 inline virtual uint8_t to_mode_bits(const char ch) const override
190 {
191 return character_to_mode_bits(ch);
192 }
193
194protected:
195 uint8_t _type{};
196 config_t _cfg{};
197};
198
200namespace cardkb {
201namespace command {
202constexpr uint8_t CMD_HARDWARE_TYPE_REG{0xFD};
203} // namespace command
204} // namespace cardkb
206
207} // namespace unit
208} // namespace m5
209#endif
Card-size 50 key QWERTY keyboard.
void config(const config_t &cfg)
Set the configuration.
Definition unit_CardKB.hpp:140
virtual void update(const bool force=false) override
Definition unit_CardKB.cpp:296
static keyboard::key_index_t character_to_key_index(const char ch)
Character to key index.
Definition unit_CardKB.cpp:227
bool readHardwareType(uint8_t &htype)
Read the hardware type.
Definition unit_CardKB.cpp:376
static uint8_t character_to_mode_bits(const char ch)
Character to mode bits.
Definition unit_CardKB.cpp:243
virtual bool begin() override
Definition unit_CardKB.cpp:263
virtual keyboard::key_index_t toKeyIndex(const char ch) const override
Obtains the key index corresponding to the specified character.
Definition unit_CardKB.hpp:147
uint8_t hardwareType() const
Gets the hardware type.
Definition unit_CardKB.hpp:173
config_t config()
Gets the configuration.
Definition unit_CardKB.hpp:135
Class supporting keyboard state acquisition by key press bits.
For CardKB.
Top level namespace of M5stack.
Unit-related namespace.
Settings for begin.
Definition unit_CardKB.hpp:106
uint32_t repeating_threshold
Threshold for key repeating (ms)
Definition unit_CardKB.hpp:116
uint32_t interval
Periodic interval.
Definition unit_CardKB.hpp:114
uint32_t holding_threshold
Threshold for key holding (ms)
Definition unit_CardKB.hpp:118
bool start_periodic
Start periodic measurement on begin?
Definition unit_CardKB.hpp:108
keyboard::Mode mode
Definition unit_CardKB.hpp:112
constexpr uint8_t TYPE_CARDKB_V11
V11 SKU:U035-B.
Definition unit_CardKB.hpp:27
constexpr uint8_t TYPE_CARDKB
SKU:U035.
Definition unit_CardKB.hpp:26
Base class for units.
uint8_t key_index_t
Key index (Not character)
Definition unit_Keyboard.hpp:24
Mode
Operation mode for M5Unit-KEYBOARD firmware.
Definition unit_Keyboard.hpp:50