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

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

#include <unit_CardKB2.hpp>

Inheritance diagram for m5::unit::UnitCardKB2:
m5::unit::UnitKeyboard

Classes

struct  config_t
 Settings for begin. More...
 

Public Member Functions

 UnitCardKB2 (const uint8_t addr=DEFAULT_ADDRESS)
 
virtual bool begin () override
 
virtual void update (const bool force=false) override
 
virtual char getchar () const override
 Gets the character if input.
 
uint8_t available () const
 Number of available characters (0 or 1)
 
void discard ()
 Discard current character.
 
Settings for begin
config_t config ()
 Gets the configuration.
 
void config (const config_t &cfg)
 Set the configuration.
 
Firmware
uint8_t firmwareVersion () const
 Gets the firmware version.
 
bool readFirmwareVersion (uint8_t &ver)
 Read the firmware version.
 
- Public Member Functions inherited from m5::unit::UnitKeyboard
 UnitKeyboard (const uint8_t addr=DEFAULT_ADDRESS)
 
virtual uint8_t released () const
 Gets the released key character code if updated.
 

Protected Attributes

config_t _cfg {}
 
uint8_t _pressed_key {}
 
uint8_t _firmware_version {}
 

Detailed Description

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

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

  • Fn+Sym+1: I2C mode (factory default) — returns ASCII per keypress
  • Fn+Sym+2: UART mode (115200-8N1) — use UnitCardKB2UART for this mode

The selected mode is saved and persists across power cycles.

In I2C mode, the firmware returns ASCII on key press (not release) and auto-repeats after 300ms hold at 50ms intervals. Use getchar() after updated() to retrieve the pressed character.

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 are not available in I2C/UART mode.
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

◆ available()

uint8_t m5::unit::UnitCardKB2::available ( ) const
inline

Number of available characters (0 or 1)

Note
Provided for API compatibility with UnitKeyboardBitwise (UnitCardKB2UART)

◆ begin()

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

Reimplemented from m5::unit::UnitKeyboard.

◆ discard()

void m5::unit::UnitCardKB2::discard ( )
inline

Discard current character.

Note
Provided for API compatibility with UnitKeyboardBitwise (UnitCardKB2UART)

◆ firmwareVersion()

uint8_t m5::unit::UnitCardKB2::firmwareVersion ( ) const
inline

Gets the firmware version.

Return values
Firmwareversion read during begin()
Warning
Valid after begin

◆ getchar()

virtual char m5::unit::UnitCardKB2::getchar ( ) const
inlineoverridevirtual

Gets the character if input.

Return values
!=0 Pressed character
==0 Not input or invalid character
Note
CardKB2 I2C firmware sends ASCII on key press (not release)

Reimplemented from m5::unit::UnitKeyboard.

◆ readFirmwareVersion()

bool m5::unit::UnitCardKB2::readFirmwareVersion ( uint8_t & ver)

Read the firmware version.

Parameters
[out]verVersion
Returns
True if successful

◆ update()

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

Reimplemented from m5::unit::UnitKeyboard.