M5Unit-KEYBOARD 0.0.1 git rev:a483db1
Loading...
Searching...
No Matches
m5::unit::UnitCardKB2UART Class Reference

Card-size 42 key QWERTY keyboard — UART mode (SKU:U215) More...

#include <unit_CardKB2UART.hpp>

Inheritance diagram for m5::unit::UnitCardKB2UART:
m5::unit::UnitKeyboardBitwise m5::unit::UnitKeyboard

Classes

struct  config_t
 Settings for begin. More...
 

Public Types

using Packet = std::array<uint8_t, 5>
 

Public Member Functions

 UnitCardKB2UART (const uint8_t addr=DEFAULT_ADDRESS)
 
virtual bool begin () override
 
virtual void update (const bool force=false) override
 
virtual keyboard::key_index_t toKeyIndex (const char ch) const override
 Obtains the key index corresponding to the specified character.
 
Settings for begin
config_t config ()
 Gets the configuration.
 
void config (const config_t &cfg)
 Set the configuration.
 
Firmware
virtual bool readFirmwareVersion (uint8_t &ver) override
 Read the firmware version.
 
Mode
virtual bool readMode (keyboard::Mode &) override
 Not supported on CardKB2UART.
 
virtual bool writeMode (const keyboard::Mode) override
 Not supported on CardKB2UART.
 
- Public Member Functions inherited from m5::unit::UnitKeyboardBitwise
 UnitKeyboardBitwise (const uint8_t addr=DEFAULT_ADDRESS)
 
virtual char getchar () const override
 Gets the input character.
 
uint8_t pressed () const
 Get the oldest pressed key.
 
virtual uint8_t released () const override
 Get the oldest released key.
 
bool startPeriodicMeasurement (const uint32_t interval)
 Start periodic measurement.
 
bool startPeriodicMeasurement ()
 Start periodic measurement using current settings.
 
bool stopPeriodicMeasurement ()
 Stop periodic measurement.
 
keyboard::key_status_bits_t nowBits () const
 Get the bits of the key being pressed.
 
keyboard::key_status_bits_t previousBits () const
 Get the bits of the previous key pressed.
 
keyboard::key_status_bits_t pressedBits () const
 Get the key bits at the moment they are pressed.
 
keyboard::key_status_bits_t releasedBits () const
 Get the key bits at the moment they are released.
 
keyboard::key_status_bits_t holdingBits () const
 Get the bits of the held key.
 
keyboard::key_status_bits_t wasHoldBits () const
 Get the bits of the key at the moment of hold.
 
keyboard::key_status_bits_t repeatingBits () const
 Get the bits of the key that the software is repeatedly pressing.
 
keyboard::key_status_bits_t modifierBits () const
 Get the bits of the modifier key being pressed.
 
bool isModifier () const
 Is any modifier keys pressed?
 
bool isShift () const
 Is the shift key pressed?
 
bool isSymbol () const
 Is the symbol key pressed?
 
bool isFunction () const
 Is the function key pressed?
 
bool isAlt () const
 Is the alt key pressed?
 
bool isControl () const
 Is the control key pressed?
 
bool isOption () const
 Is the option key pressed?
 
bool isShiftEqual () const
 Is only shift pressed among the modifier keys?
 
bool isSymbolEqual () const
 Is only symbol pressed among the modifier keys?
 
bool isFunctionEqual () const
 Is only function pressed among the modifier keys?
 
bool isAltEqual () const
 Is only alt pressed among the modifier keys?
 
bool isControlEqual () const
 Is only control pressed among the modifier keys?
 
bool isOptionEqual () const
 Is only option pressed among the modifier keys?
 
bool isPressed () const
 Is any key press?
 
bool isReleased () const
 Is all key release?
 
bool wasPressed () const
 Was any key pressed?
 
bool wasReleased () const
 Was any key released?
 
bool isHolding () const
 Is any key holding?
 
bool wasHold () const
 Was any key hold?
 
bool isRepeating () const
 Is any key repeating?
 
bool isPressed (const keyboard::key_index_t kidx) const
 Is the specified key pressed?
 
bool isReleased (const keyboard::key_index_t kidx) const
 Is the specified key released?
 
bool wasPressed (const keyboard::key_index_t kidx) const
 Was the specified key pressed?
 
bool wasReleased (const keyboard::key_index_t kidx) const
 Was the specified key released?
 
bool isHolding (const keyboard::key_index_t kidx) const
 Is the specified key holding?
 
bool wasHold (const keyboard::key_index_t kidx) const
 Was the specified key hold?
 
bool isRepeating (const keyboard::key_index_t kidx) const
 Is the specified key repeating?
 
bool isPressed (const char ch) const
 Is the specified character pressed?
 
bool isReleased (const char ch) const
 Is the specified character released?
 
bool wasPressed (const char ch) const
 Was the specified character pressed?
 
bool wasReleased (const char ch) const
 Was the specified character released?
 
bool isHolding (const char ch) const
 Is the specified character holding?
 
bool wasHold (const char ch) const
 Was the specified character hold?
 
bool isRepeating (const char ch) const
 Is the specified character repeating?
 
uint8_t firmwareVersion () const
 Gets the firmware version.
 
uint32_t holdingThreshold () const
 Gets the holding threshold (ms)
 
uint32_t repeatingThreshold () const
 Gets the repeating threshold (ms)
 
void setHoldingThreshold (const uint32_t ms)
 Sets the holding threshold.
 
void setRepeatingThreshold (const uint32_t ms)
 Sets the repeating threshold.
 
- Public Member Functions inherited from m5::unit::UnitKeyboard
 UnitKeyboard (const uint8_t addr=DEFAULT_ADDRESS)
 

Protected Member Functions

void update_uart (const bool force)
 
uint8_t read_data (Packet &rbuf)
 
virtual uint8_t to_mode_bits (const char ch) const override
 
- Protected Member Functions inherited from m5::unit::UnitKeyboardBitwise
bool start_periodic_measurement ()
 
bool start_periodic_measurement (const uint32_t interval)
 
bool stop_periodic_measurement ()
 
bool update_new_firmware (const types::elapsed_time_t at)
 
void push_back (m5::container::CircularBuffer< uint8_t > *container, const uint8_t kidx, const uint8_t alt)
 
keyboard::key_status_bits_t modifier_bits () const
 
virtual uint8_t scan_reg_addr () const
 
virtual uint8_t mode_reg_addr () const
 
virtual uint8_t firmware_version_reg_addr () const
 
bool permitted_mode (const uint8_t mbits) const
 
 M5_UNIT_COMPONENT_PERIODIC_MEASUREMENT_ADAPTER_HPP_BUILDER (UnitKeyboardBitwise, uint8_t)
 

Protected Attributes

config_t _cfg {}
 
- Protected Attributes inherited from m5::unit::UnitKeyboardBitwise
std::unique_ptr< m5::container::CircularBuffer< uint8_t > > _data {}
 
keyboard::key_status_bits_t _now {}
 
keyboard::key_status_bits_t _prev {}
 
keyboard::key_status_bits_t _wasPressed {}
 
keyboard::key_status_bits_t _wasReleased {}
 
keyboard::key_status_bits_t _wasHold {}
 
keyboard::key_status_bits_t _holding {}
 
keyboard::key_status_bits_t _repeating {}
 
std::vector< types::elapsed_time_t > _repeat_start_at {}
 
std::vector< types::elapsed_time_t > _hold_start_at {}
 
uint32_t _repeating_threshold {400}
 
uint32_t _holding_threshold {800}
 
uint8_t _firmware_version {}
 
keyboard::Mode _mode {keyboard::Mode::Conventional}
 

Detailed Description

Card-size 42 key QWERTY keyboard — UART mode (SKU:U215)

CardKB2 supports I2C and UART communication via GROVE port, selectable on the device:

  • Fn+Sym+1: I2C mode (factory default) — use UnitCardKB2 for this mode
  • Fn+Sym+2: UART mode (115200-8N1) — sends KEY_ID + KEY_STATE packets

The selected mode is saved and persists across power cycles.

In UART mode, press/release key events are received as packets, enabling full bitwise key state tracking (isPressed, isHolding, isRepeating, etc.).

Note
Sym key operates as a toggle (press once to activate, press again to deactivate). Blue LED indicates Sym mode is active.
Fn+D/Z/X/C arrow keys work in UART mode (hold Fn, then press D/Z/X/C). Fn+1 (ESC) may require a long press due to a firmware issue.
Unlike CardKB/FacesQWERTY, CardKB2 does not support software mode switching via readMode()/writeMode().
Warning
After switching communication mode (Fn+Sym+1/2), press the RST button on CardKB2 to reset modifier state. This will be fixed in a future firmware update.

Member Function Documentation

◆ begin()

bool m5::unit::UnitCardKB2UART::begin ( )
overridevirtual

Reimplemented from m5::unit::UnitKeyboard.

◆ readFirmwareVersion()

bool m5::unit::UnitCardKB2UART::readFirmwareVersion ( uint8_t & ver)
overridevirtual

Read the firmware version.

Parameters
[out]verVersion
Returns
Always false (UART protocol has no version query command)

Reimplemented from m5::unit::UnitKeyboardBitwise.

◆ readMode()

virtual bool m5::unit::UnitCardKB2UART::readMode ( keyboard::Mode & )
inlineoverridevirtual

Not supported on CardKB2UART.

Returns
Always false

Reimplemented from m5::unit::UnitKeyboardBitwise.

◆ to_mode_bits()

virtual uint8_t m5::unit::UnitCardKB2UART::to_mode_bits ( const char ch) const
inlineoverrideprotectedvirtual

Reimplemented from m5::unit::UnitKeyboardBitwise.

◆ toKeyIndex()

virtual keyboard::key_index_t m5::unit::UnitCardKB2UART::toKeyIndex ( const char ch) const
inlineoverridevirtual

Obtains the key index corresponding to the specified character.

Return values
!=0xFF key index
==0xFF No corresponding key index

Reimplemented from m5::unit::UnitKeyboardBitwise.

◆ update()

void m5::unit::UnitCardKB2UART::update ( const bool force = false)
overridevirtual

Reimplemented from m5::unit::UnitKeyboardBitwise.

◆ writeMode()

virtual bool m5::unit::UnitCardKB2UART::writeMode ( const keyboard::Mode )
inlineoverridevirtual

Not supported on CardKB2UART.

Returns
Always false

Reimplemented from m5::unit::UnitKeyboardBitwise.