33#include " DriverCommon.h"
44#include " Platforms/API_I2C.h"
55#include " Platforms/API_SPI.h"
6+ #include " Platforms/Logger.h"
67#include " Platforms/Optional.h"
78#include " Platforms/Vector.h"
8- #include " Platforms/Logger.h"
99
1010#ifdef ARDUINO
1111#include " Wire.h"
12+ #define DEFAULT_WIRE &Wire
13+ #else
14+ #define DEFAULT_WIRE nullptr
1215#endif
1316
1417#ifndef TOUCH_LIMIT
@@ -135,7 +138,7 @@ struct PinsSPI : public SPIConfig {
135138 operator bool () { return pinsAvailable (); }
136139 bool begin () {
137140 if (set_active) {
138- AD_LOGD (" PinsSPI::begin for %d" , (int ) function);
141+ AD_LOGD (" PinsSPI::begin for %d" , (int )function);
139142 spi_bus_create (this );
140143 } else {
141144 AD_LOGI (" SPI, not active, MOSI, MISO, SCLK, SSEL not modified" );
@@ -168,16 +171,11 @@ struct PinsI2C : public I2CConfig {
168171 sda = -1 ;
169172 frequency = 100000 ;
170173 set_active = true ;
171- #ifdef ARDUINO
172- p_wire = &Wire;
173- #else
174- p_wire = nullptr ;
175- #endif
174+ p_wire = DEFAULT_WIRE;
176175 };
177176
178- #ifdef ARDUINO
179177 PinsI2C (PinFunction function, GpioPin scl, GpioPin sda, int address = -1 ,
180- uint32_t frequency = 100000 , TwoWire & wire = Wire ,
178+ uint32_t frequency = 100000 , i2c_bus_handle_t wire = DEFAULT_WIRE ,
181179 bool active = true ) {
182180 this ->function = function;
183181 this ->scl = scl;
@@ -188,19 +186,6 @@ struct PinsI2C : public I2CConfig {
188186 this ->set_active = active;
189187 this ->address = address;
190188 }
191- #else
192- PinsI2C (PinFunction function, GpioPin scl, GpioPin sda, int address = -1 ,
193- uint32_t frequency = 100000 , bool active = true ) {
194- this ->function = function;
195- this ->scl = scl;
196- this ->sda = sda;
197- this ->port = 0 ;
198- this ->frequency = frequency;
199- this ->p_wire = nullptr ;
200- this ->set_active = active;
201- this ->address = address;
202- }
203- #endif
204189
205190 PinFunction function;
206191 bool set_active = true ;
@@ -275,12 +260,12 @@ class DriverPins {
275260
276261#ifdef ARDUINO
277262 bool addSPI (PinFunction function, GpioPin clk, GpioPin miso, GpioPin mosi,
278- GpioPin cs, SPIClass &spi = SPI ) {
263+ GpioPin cs, SPIClass &spi) {
279264 PinsSPI pin (function, clk, miso, mosi, cs, spi);
280265 return addSPI (pin);
281266 }
282-
283267#endif
268+
284269 // / Updates the SPI pin information using the function as key
285270 bool setSPI (PinsSPI pin) { return set<PinsSPI>(pin, spi); }
286271
@@ -291,25 +276,26 @@ class DriverPins {
291276 }
292277
293278#ifdef ARDUINO
294- bool addI2C (PinFunction function, GpioPin scl, GpioPin sda, int port = -1 ,
295- uint32_t frequency = 100000 , TwoWire &wire = Wire,
296- bool active = true ) {
297- PinsI2C pin (function, scl, sda, port, frequency, wire, active);
298- return addI2C (pin);
299- }
300279 // / Just define your initialzed wire object
301280 bool addI2C (PinFunction function, TwoWire &wire, bool setActive = false ) {
302- PinsI2C pin (function, -1 , -1 , -1 , -1 , wire, setActive);
281+ PinsI2C pin (function, -1 , -1 , -1 , -1 , & wire, setActive);
303282 return addI2C (pin);
304283 }
305- #else
306- bool addI2C (PinFunction function, GpioPin scl, GpioPin sda, int port = -1 ,
307- uint32_t frequency = 100000 , bool active = true ) {
308- PinsI2C pin (function, scl, sda, port, frequency, active);
284+
285+ bool addI2C (PinFunction function, GpioPin scl, GpioPin sda, int port,
286+ uint32_t frequency, TwoWire &wire,
287+ bool active = true ) {
288+ PinsI2C pin (function, scl, sda, port, frequency, &wire, active);
309289 return addI2C (pin);
310290 }
311291#endif
312292
293+ bool addI2C (PinFunction function, GpioPin scl, GpioPin sda, int port = -1 ,
294+ uint32_t frequency = 100000 , i2c_bus_handle_t wire=DEFAULT_WIRE, bool active = true ) {
295+ PinsI2C pin (function, scl, sda, port, frequency, wire, active);
296+ return addI2C (pin);
297+ }
298+
313299 // / Updates the I2C pin information using the function as key
314300 bool setI2C (PinsI2C pin) { return set<PinsI2C>(pin, i2c); }
315301
0 commit comments