mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-08 22:22:05 +00:00
WIP
This commit is contained in:
parent
00162b4ccf
commit
b6066a78c1
@ -148,7 +148,7 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize)
|
|||||||
{
|
{
|
||||||
concurrency::LockGuard guard((concurrency::Lock *)&lock);
|
concurrency::LockGuard guard((concurrency::Lock *)&lock);
|
||||||
|
|
||||||
LOG_DEBUG("Scanning for i2c devices on port %d\n", port);
|
LOG_DEBUG("Scanning for I2C devices on port %d\n", port);
|
||||||
|
|
||||||
uint8_t err;
|
uint8_t err;
|
||||||
|
|
||||||
@ -172,10 +172,11 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (addr.address = 1; addr.address < 127; addr.address++) {
|
for (addr.address = 1; addr.address < 127; addr.address++) {
|
||||||
if (asize != 0)
|
if (asize != 0) {
|
||||||
if (in_array(address, asize, addr.address))
|
if (!in_array(address, asize, addr.address))
|
||||||
continue;
|
continue;
|
||||||
|
LOG_DEBUG("Scanning address 0x%x\n", addr.address);
|
||||||
|
}
|
||||||
i2cBus->beginTransmission(addr.address);
|
i2cBus->beginTransmission(addr.address);
|
||||||
#ifdef ARCH_PORTDUINO
|
#ifdef ARCH_PORTDUINO
|
||||||
if (i2cBus->read() != -1)
|
if (i2cBus->read() != -1)
|
||||||
@ -369,7 +370,7 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize)
|
|||||||
LOG_INFO("Device found at address 0x%x was not able to be enumerated\n", addr.address);
|
LOG_INFO("Device found at address 0x%x was not able to be enumerated\n", addr.address);
|
||||||
}
|
}
|
||||||
} else if (err == 4) {
|
} else if (err == 4) {
|
||||||
LOG_ERROR("Unknown error at address 0x%x\n", addr);
|
LOG_ERROR("Unknown error at address 0x%x\n", addr.address);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if a type was found for the enumerated device - save, if so
|
// Check if a type was found for the enumerated device - save, if so
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include "cardKbI2cImpl.h"
|
#include "cardKbI2cImpl.h"
|
||||||
#include "InputBroker.h"
|
#include "InputBroker.h"
|
||||||
|
#include "detect/ScanI2C.h"
|
||||||
|
#include "detect/ScanI2CTwoWire.h"
|
||||||
|
|
||||||
CardKbI2cImpl *cardKbI2cImpl;
|
CardKbI2cImpl *cardKbI2cImpl;
|
||||||
|
|
||||||
@ -8,8 +10,44 @@ CardKbI2cImpl::CardKbI2cImpl() : KbI2cBase("cardKB") {}
|
|||||||
void CardKbI2cImpl::init()
|
void CardKbI2cImpl::init()
|
||||||
{
|
{
|
||||||
if (cardkb_found.address == 0x00) {
|
if (cardkb_found.address == 0x00) {
|
||||||
disable();
|
LOG_DEBUG("Rescanning for I2C keyboard\n");
|
||||||
return;
|
uint8_t i2caddr_scan[] = {CARDKB_ADDR, TDECK_KB_ADDR, BBQ10_KB_ADDR};
|
||||||
|
uint8_t i2caddr_asize = 3;
|
||||||
|
auto i2cScanner = std::unique_ptr<ScanI2CTwoWire>(new ScanI2CTwoWire());
|
||||||
|
|
||||||
|
#if defined(I2C_SDA1)
|
||||||
|
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;
|
||||||
|
default:
|
||||||
|
// use this as default since it's also just zero
|
||||||
|
LOG_WARN("kb_info.type is unknown(0x%02x), setting kb_model=0x00\n", kb_info.type);
|
||||||
|
kb_model = 0x00;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (cardkb_found.address == 0x00) {
|
||||||
|
disable();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inputBroker->registerSource(this);
|
inputBroker->registerSource(this);
|
||||||
|
@ -30,44 +30,6 @@ uint8_t read_from_14004(TwoWire *i2cBus, uint8_t reg, uint8_t *data, uint8_t len
|
|||||||
|
|
||||||
int32_t KbI2cBase::runOnce()
|
int32_t KbI2cBase::runOnce()
|
||||||
{
|
{
|
||||||
if (cardkb_found.address == 0x00) {
|
|
||||||
// Input device is not detected. Rescan now.
|
|
||||||
auto i2cScanner = std::unique_ptr<ScanI2CTwoWire>(new ScanI2CTwoWire());
|
|
||||||
uint8_t i2caddr_scan[] = {CARDKB_ADDR, TDECK_KB_ADDR, BBQ10_KB_ADDR};
|
|
||||||
uint8_t i2caddr_asize = 3;
|
|
||||||
#if defined(I2C_SDA1)
|
|
||||||
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;
|
|
||||||
default:
|
|
||||||
// use this as default since it's also just zero
|
|
||||||
LOG_WARN("kb_info.type is unknown(0x%02x), setting kb_model=0x00\n", kb_info.type);
|
|
||||||
kb_model = 0x00;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (cardkb_found.address == 0x00)
|
|
||||||
return INT32_MAX;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!i2cBus) {
|
if (!i2cBus) {
|
||||||
switch (cardkb_found.port) {
|
switch (cardkb_found.port) {
|
||||||
case ScanI2C::WIRE1:
|
case ScanI2C::WIRE1:
|
||||||
|
Loading…
Reference in New Issue
Block a user