Implements an input driver utilising the MPR121 Touch IC and is compatible with common MPR121 keypad PCB's. - Implements a "candybar" phone style 12-key keypad - multiple taps to rotate through the character set - longpress for navigation keys - keymap to allow arbitrary routing of MPR121 pin to button configuration - extendable to other key functions - Integrates with the existing kbI2cBase implementation - Works with CannedMessageModule Freetext mode - Can be used with common MPR121 boards, such as https://www.amazon.com/MPR121-Capacitive-Keyboard-Buttons-Sensitive/dp/B083R89CHB/ref=sr_1_6 - Of use for PCB based radios, where some form of low surface area low component freetext input is required, but also without consuming too many IO pins. - Tested on a T3S3 connected to Wire1 (Second) interface. - Demonstration of functionality: https://youtu.be/UI6QP6nGvhY
65 lines
2.3 KiB
C++
65 lines
2.3 KiB
C++
#include "cardKbI2cImpl.h"
|
|
#include "InputBroker.h"
|
|
#include "detect/ScanI2CTwoWire.h"
|
|
#include "main.h"
|
|
|
|
CardKbI2cImpl *cardKbI2cImpl;
|
|
|
|
CardKbI2cImpl::CardKbI2cImpl() : KbI2cBase("cardKB") {}
|
|
|
|
void CardKbI2cImpl::init()
|
|
{
|
|
#if !MESHTASTIC_EXCLUDE_I2C && !defined(ARCH_PORTDUINO)
|
|
if (cardkb_found.address == 0x00) {
|
|
LOG_DEBUG("Rescanning for I2C keyboard");
|
|
uint8_t i2caddr_scan[] = {CARDKB_ADDR, TDECK_KB_ADDR, BBQ10_KB_ADDR, MPR121_KB_ADDR};
|
|
uint8_t i2caddr_asize = 4;
|
|
auto i2cScanner = std::unique_ptr<ScanI2CTwoWire>(new ScanI2CTwoWire());
|
|
|
|
#if WIRE_INTERFACES_COUNT == 2
|
|
i2cScanner->scanPort(ScanI2C::I2CPort::WIRE1, i2caddr_scan, i2caddr_asize);
|
|
#endif
|
|
i2cScanner->scanPort(ScanI2C::I2CPort::WIRE, i2caddr_scan, i2caddr_asize);
|
|
auto kb_info = i2cScanner->firstKeyboard();
|
|
|
|
if (kb_info.type != ScanI2C::DeviceType::NONE) {
|
|
cardkb_found = kb_info.address;
|
|
switch (kb_info.type) {
|
|
case ScanI2C::DeviceType::RAK14004:
|
|
kb_model = 0x02;
|
|
break;
|
|
case ScanI2C::DeviceType::CARDKB:
|
|
kb_model = 0x00;
|
|
break;
|
|
case ScanI2C::DeviceType::TDECKKB:
|
|
// assign an arbitrary value to distinguish from other models
|
|
kb_model = 0x10;
|
|
break;
|
|
case ScanI2C::DeviceType::BBQ10KB:
|
|
// assign an arbitrary value to distinguish from other models
|
|
kb_model = 0x11;
|
|
break;
|
|
case ScanI2C::DeviceType::MPR121KB:
|
|
// assign an arbitrary value to distinguish from other models
|
|
kb_model = 0x37;
|
|
break;
|
|
default:
|
|
// use this as default since it's also just zero
|
|
LOG_WARN("kb_info.type is unknown(0x%02x), setting kb_model=0x00", kb_info.type);
|
|
kb_model = 0x00;
|
|
}
|
|
}
|
|
LOG_DEBUG("Keyboard Type: 0x%02x Model: 0x%02x Address: 0x%02x\n", kb_info.type, kb_model, cardkb_found.address);
|
|
if (cardkb_found.address == 0x00) {
|
|
disable();
|
|
return;
|
|
}
|
|
}
|
|
#else
|
|
if (cardkb_found.address == 0x00) {
|
|
disable();
|
|
return;
|
|
}
|
|
#endif
|
|
inputBroker->registerSource(this);
|
|
} |