mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-28 18:47:40 +00:00
Iterate through uint array
This commit is contained in:
parent
dca8615eaa
commit
c46c3427f0
@ -6,7 +6,7 @@ const ScanI2C::FoundDevice ScanI2C::DEVICE_NONE = ScanI2C::FoundDevice(ScanI2C::
|
|||||||
ScanI2C::ScanI2C() = default;
|
ScanI2C::ScanI2C() = default;
|
||||||
|
|
||||||
void ScanI2C::scanPort(ScanI2C::I2CPort port) {}
|
void ScanI2C::scanPort(ScanI2C::I2CPort port) {}
|
||||||
void ScanI2C::scanPort(ScanI2C::I2CPort port, uint8_t *address) {}
|
void ScanI2C::scanPort(ScanI2C::I2CPort port, uint8_t *address, uint8_t asize) {}
|
||||||
|
|
||||||
void ScanI2C::setSuppressScreen()
|
void ScanI2C::setSuppressScreen()
|
||||||
{
|
{
|
||||||
|
@ -81,7 +81,7 @@ class ScanI2C
|
|||||||
ScanI2C();
|
ScanI2C();
|
||||||
|
|
||||||
virtual void scanPort(ScanI2C::I2CPort);
|
virtual void scanPort(ScanI2C::I2CPort);
|
||||||
virtual void scanPort(ScanI2C::I2CPort, uint8_t *);
|
virtual void scanPort(ScanI2C::I2CPort, uint8_t *, uint8_t);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A bit of a hack, this tells the scanner not to tell later systems there is a screen to avoid enabling it.
|
* A bit of a hack, this tells the scanner not to tell later systems there is a screen to avoid enabling it.
|
||||||
|
@ -14,6 +14,15 @@
|
|||||||
#define XPOWERS_AXP192_AXP2101_ADDRESS 0x34
|
#define XPOWERS_AXP192_AXP2101_ADDRESS 0x34
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bool in_array(uint8_t *array, int size, uint8_t lookfor)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < size; i++)
|
||||||
|
if (lookfor == array[i])
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
ScanI2C::FoundDevice ScanI2CTwoWire::find(ScanI2C::DeviceType type) const
|
ScanI2C::FoundDevice ScanI2CTwoWire::find(ScanI2C::DeviceType type) const
|
||||||
{
|
{
|
||||||
concurrency::LockGuard guard((concurrency::Lock *)&lock);
|
concurrency::LockGuard guard((concurrency::Lock *)&lock);
|
||||||
@ -135,7 +144,7 @@ uint16_t ScanI2CTwoWire::getRegisterValue(const ScanI2CTwoWire::RegisterLocation
|
|||||||
type = T; \
|
type = T; \
|
||||||
break;
|
break;
|
||||||
|
|
||||||
void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address)
|
void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize)
|
||||||
{
|
{
|
||||||
concurrency::LockGuard guard((concurrency::Lock *)&lock);
|
concurrency::LockGuard guard((concurrency::Lock *)&lock);
|
||||||
|
|
||||||
@ -163,10 +172,10 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (addr.address = 1; addr.address < 127; addr.address++) {
|
for (addr.address = 1; addr.address < 127; addr.address++) {
|
||||||
// Skip the address if it is not requested on a partial scan
|
if (asize != 0)
|
||||||
if (address != nullptr && *address != addr.address) {
|
if (in_array(address, asize, addr.address))
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
i2cBus->beginTransmission(addr.address);
|
i2cBus->beginTransmission(addr.address);
|
||||||
#ifdef ARCH_PORTDUINO
|
#ifdef ARCH_PORTDUINO
|
||||||
if (i2cBus->read() != -1)
|
if (i2cBus->read() != -1)
|
||||||
@ -359,7 +368,7 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address)
|
|||||||
|
|
||||||
void ScanI2CTwoWire::scanPort(I2CPort port)
|
void ScanI2CTwoWire::scanPort(I2CPort port)
|
||||||
{
|
{
|
||||||
scanPort(port, nullptr);
|
scanPort(port, nullptr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TwoWire *ScanI2CTwoWire::fetchI2CBus(ScanI2C::DeviceAddress address) const
|
TwoWire *ScanI2CTwoWire::fetchI2CBus(ScanI2C::DeviceAddress address) const
|
||||||
|
@ -16,7 +16,7 @@ class ScanI2CTwoWire : public ScanI2C
|
|||||||
public:
|
public:
|
||||||
void scanPort(ScanI2C::I2CPort) override;
|
void scanPort(ScanI2C::I2CPort) override;
|
||||||
|
|
||||||
void scanPort(ScanI2C::I2CPort, uint8_t *) override;
|
void scanPort(ScanI2C::I2CPort, uint8_t *, uint8_t) override;
|
||||||
|
|
||||||
ScanI2C::FoundDevice find(ScanI2C::DeviceType) const override;
|
ScanI2C::FoundDevice find(ScanI2C::DeviceType) const override;
|
||||||
|
|
||||||
|
@ -34,10 +34,11 @@ int32_t KbI2cBase::runOnce()
|
|||||||
// Input device is not detected. Rescan now.
|
// Input device is not detected. Rescan now.
|
||||||
auto i2cScanner = std::unique_ptr<ScanI2CTwoWire>(new ScanI2CTwoWire());
|
auto i2cScanner = std::unique_ptr<ScanI2CTwoWire>(new ScanI2CTwoWire());
|
||||||
uint8_t i2caddr_scan[] = {CARDKB_ADDR, TDECK_KB_ADDR, BBQ10_KB_ADDR};
|
uint8_t i2caddr_scan[] = {CARDKB_ADDR, TDECK_KB_ADDR, BBQ10_KB_ADDR};
|
||||||
|
uint8_t i2caddr_asize = 3;
|
||||||
#if defined(I2C_SDA1)
|
#if defined(I2C_SDA1)
|
||||||
i2cScanner->scanPort(ScanI2C::I2CPort::WIRE1, i2caddr_scan);
|
i2cScanner->scanPort(ScanI2C::I2CPort::WIRE1, i2caddr_scan, i2caddr_asize);
|
||||||
#endif
|
#endif
|
||||||
i2cScanner->scanPort(ScanI2C::I2CPort::WIRE, i2caddr_scan);
|
i2cScanner->scanPort(ScanI2C::I2CPort::WIRE, i2caddr_scan, i2caddr_asize);
|
||||||
auto kb_info = i2cScanner->firstKeyboard();
|
auto kb_info = i2cScanner->firstKeyboard();
|
||||||
|
|
||||||
if (kb_info.type != ScanI2C::DeviceType::NONE) {
|
if (kb_info.type != ScanI2C::DeviceType::NONE) {
|
||||||
|
Loading…
Reference in New Issue
Block a user