2022-08-29 09:17:44 -04:00
|
|
|
#pragma once
|
|
|
|
//
|
|
|
|
// FILE: I2C_SCANNER.h
|
|
|
|
// AUTHOR: Rob Tillaart
|
2023-01-30 08:32:38 -05:00
|
|
|
// VERSION: 0.1.4
|
2022-08-29 09:17:44 -04:00
|
|
|
// DATE: 2022-08-29
|
|
|
|
// PURPOSE: I2C scanner class
|
2023-01-30 08:32:38 -05:00
|
|
|
|
2022-08-29 09:17:44 -04:00
|
|
|
|
|
|
|
#include "Arduino.h"
|
|
|
|
#include "Wire.h"
|
|
|
|
|
2023-01-30 08:32:38 -05:00
|
|
|
#define I2C_SCANNER_LIB_VERSION (F("0.1.4"))
|
2022-08-29 09:17:44 -04:00
|
|
|
|
|
|
|
|
|
|
|
class I2C_SCANNER
|
|
|
|
{
|
2022-08-30 06:39:55 -04:00
|
|
|
public:
|
2022-08-29 09:17:44 -04:00
|
|
|
|
|
|
|
I2C_SCANNER(TwoWire *wire = &Wire);
|
2022-08-30 06:39:55 -04:00
|
|
|
|
|
|
|
// CONFIGURATION
|
|
|
|
bool begin();
|
2022-08-29 09:17:44 -04:00
|
|
|
#if defined (ESP8266) || defined(ESP32)
|
2022-08-30 06:39:55 -04:00
|
|
|
bool begin(int sda, int scl);
|
2022-08-29 09:17:44 -04:00
|
|
|
#endif
|
|
|
|
|
2022-08-30 06:39:55 -04:00
|
|
|
// I2C PORT
|
|
|
|
uint8_t getWirePortCount();
|
|
|
|
bool setWire(TwoWire *wire = &Wire);
|
|
|
|
// 0 == Wire, 1 = Wire1 etc. easy for iteration.
|
|
|
|
bool setWire(uint8_t n = 0);
|
|
|
|
TwoWire* getWire();
|
2022-08-29 09:17:44 -04:00
|
|
|
|
2022-08-31 05:08:07 -04:00
|
|
|
// valid methods 0 and 1.
|
|
|
|
int softwareReset(uint8_t method = 0);
|
2022-08-29 09:17:44 -04:00
|
|
|
|
2022-08-30 06:39:55 -04:00
|
|
|
// TIMING
|
|
|
|
bool setClock(uint32_t clockFrequency = 100000UL);
|
|
|
|
#if defined(ESP32)
|
|
|
|
uint32_t getClock();
|
|
|
|
#endif
|
2022-08-29 09:17:44 -04:00
|
|
|
|
2022-08-30 06:39:55 -04:00
|
|
|
// SCANNING FUNCTIONS
|
|
|
|
bool ping(uint8_t address);
|
|
|
|
int diag(uint8_t address);
|
|
|
|
int32_t pingTime(uint8_t address);
|
|
|
|
uint8_t count(uint8_t start = 0, uint8_t end = 127);
|
2022-08-29 09:17:44 -04:00
|
|
|
|
2023-01-30 08:32:38 -05:00
|
|
|
// experimental.
|
|
|
|
// not all platforms support this function.
|
|
|
|
// patch .cpp file to get this working for your platform.
|
|
|
|
bool setWireTimeout(uint32_t timeOut);
|
|
|
|
uint32_t getWireTimeout();
|
|
|
|
|
2022-08-30 06:39:55 -04:00
|
|
|
private:
|
|
|
|
int _init();
|
|
|
|
int _wirePortCount;
|
|
|
|
TwoWire* _wire;
|
2023-01-30 08:32:38 -05:00
|
|
|
|
|
|
|
uint32_t _timeout = 0;
|
2022-08-29 09:17:44 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// -- END OF FILE --
|
|
|
|
|