mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-22 02:32:23 +00:00
Refactor i2cScan.h To Handle 2 Bus (#2337)
* Break i2cScan out into a set of classes for scanning i2c * refactor i2cscan addresses to be structs that allow addressing by port + address * build whoopsies * trunk fmt * trunk fmt * lost some build fixes from the merge * more cleaning for build safety, RTC behavior
This commit is contained in:
56
src/detect/ScanI2CTwoWire.h
Normal file
56
src/detect/ScanI2CTwoWire.h
Normal file
@@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <Wire.h>
|
||||
|
||||
#include "ScanI2C.h"
|
||||
|
||||
#include "../concurrency/Lock.h"
|
||||
|
||||
class ScanI2CTwoWire : public ScanI2C
|
||||
{
|
||||
public:
|
||||
void scanPort(ScanI2C::I2CPort) override;
|
||||
|
||||
ScanI2C::FoundDevice find(ScanI2C::DeviceType) const override;
|
||||
|
||||
bool exists(ScanI2C::DeviceType) const override;
|
||||
|
||||
size_t countDevices() const override;
|
||||
|
||||
protected:
|
||||
FoundDevice firstOfOrNONE(size_t, DeviceType[]) const override;
|
||||
|
||||
private:
|
||||
typedef struct RegisterLocation {
|
||||
DeviceAddress i2cAddress;
|
||||
RegisterAddress registerAddress;
|
||||
|
||||
RegisterLocation(DeviceAddress deviceAddress, RegisterAddress registerAddress)
|
||||
: i2cAddress(deviceAddress), registerAddress(registerAddress)
|
||||
{
|
||||
}
|
||||
|
||||
} RegisterLocation;
|
||||
|
||||
typedef uint8_t ResponseWidth;
|
||||
|
||||
std::map<ScanI2C::DeviceAddress, ScanI2C::DeviceType> foundDevices;
|
||||
|
||||
// note: prone to overwriting if multiple devices of a type are added at different addresses (rare?)
|
||||
std::map<ScanI2C::DeviceType, ScanI2C::DeviceAddress> deviceAddresses;
|
||||
|
||||
concurrency::Lock lock;
|
||||
|
||||
void printATECCInfo() const;
|
||||
|
||||
uint16_t getRegisterValue(const RegisterLocation &, ResponseWidth) const;
|
||||
|
||||
DeviceType probeOLED(ScanI2C::DeviceAddress) const;
|
||||
|
||||
TwoWire *fetchI2CBus(ScanI2C::DeviceAddress) const;
|
||||
};
|
||||
Reference in New Issue
Block a user