Skip to content

Commit 2cec932

Browse files
committed
fix for samd
1 parent 667bf8f commit 2cec932

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

src/Wippersnapper.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
#define USE_STAGING
5959
#define IO_MQTT_SERVER "io.adafruit.us" ///< Adafruit IO MQTT Server
6060

61-
//#define IO_MQTT_SERVER "io.adafruit.com" ///< Adafruit IO MQTT Server (Production)
61+
//#define IO_MQTT_SERVER "io.adafruit.com" ///< Adafruit IO MQTT Server
62+
//(Production)
6263

6364
#ifdef USE_TINYUSB
6465
#include "provisioning/tinyusb/Wippersnapper_FS.h"
@@ -76,10 +77,10 @@
7677
#define TOPIC_IO_ERRORS "/errors" ///< Adafruit IO Error MQTT Topic
7778

7879
// Reserved Wippersnapper topics
79-
#define TOPIC_WS "/wprsnpr/" ///< WipperSnapper topic
80-
#define TOPIC_INFO "/info/" ///< Registration sub-topic
81-
#define TOPIC_SIGNALS "/signals/" ///< Signals sub-topic
82-
#define TOPIC_I2C "/i2c" ///< I2C sub-topic
80+
#define TOPIC_WS "/wprsnpr/" ///< WipperSnapper topic
81+
#define TOPIC_INFO "/info/" ///< Registration sub-topic
82+
#define TOPIC_SIGNALS "/signals/" ///< Signals sub-topic
83+
#define TOPIC_I2C "/i2c" ///< I2C sub-topic
8384

8485
#define WS_DEBUG ///< Define to enable debugging to serial terminal
8586
#define WS_PRINTER Serial ///< Where debug messages will be printed
@@ -302,7 +303,6 @@ class Wippersnapper {
302303
wippersnapper_signal_v1_CreateSignalRequest
303304
_incomingSignalMsg; /*!< Incoming signal message from broker */
304305

305-
306306
// i2c signal msg
307307
wippersnapper_signal_v1_I2CRequest msgSignalI2C =
308308
wippersnapper_signal_v1_I2CRequest_init_zero; ///< I2C request wrapper
@@ -315,7 +315,6 @@ class Wippersnapper {
315315
device. */
316316
bool pinCfgCompleted = false;
317317

318-
319318
private:
320319
void _init();
321320

src/components/i2c/WipperSnapper_I2C.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,26 @@ WipperSnapper_Component_I2C::WipperSnapper_Component_I2C(
3535
WS_DEBUG_PRINT("\tFrequency (Hz): ");
3636
WS_DEBUG_PRINTLN(msgInitRequest->i2c_frequency);
3737

38-
// initialize TwoWire w/ desired portNum if ESP32-S2
39-
#if defined(ARDUINO_ARCH_ESP32)
40-
_i2c = new TwoWire(msgInitRequest->i2c_port_number);
41-
#endif
4238
// validate if SDA & SCL has pullup
4339
if (digitalRead(msgInitRequest->i2c_pin_sda) == LOW) {
4440
pinMode(msgInitRequest->i2c_pin_sda, INPUT_PULLUP);
4541
}
4642
if (digitalRead(msgInitRequest->i2c_pin_scl) == LOW) {
4743
pinMode(msgInitRequest->i2c_pin_scl, INPUT_PULLUP);
4844
}
49-
// set up i2c port
45+
46+
// Initialize TwoWire interface
47+
#if defined(ARDUINO_ARCH_ESP32)
48+
// ESP32, ESP32-S2
49+
_i2c = new TwoWire(msgInitRequest->i2c_port_number);
5050
_i2c->begin(msgInitRequest->i2c_pin_sda, msgInitRequest->i2c_pin_scl);
51+
#else
52+
// SAMD
53+
_i2c = new TwoWire(&PERIPH_WIRE, msgInitRequest->i2c_pin_sda,
54+
msgInitRequest->i2c_pin_scl);
55+
_i2c->begin();
56+
#endif
57+
5158
_i2c->setClock(msgInitRequest->i2c_frequency);
5259
// set i2c obj. properties
5360
_portNum = msgInitRequest->i2c_port_number;
@@ -81,8 +88,8 @@ bool WipperSnapper_Component_I2C::isInitialized() { return _isInit; }
8188
/************************************************************************/
8289
wippersnapper_i2c_v1_I2CScanResponse
8390
WipperSnapper_Component_I2C::scanAddresses() {
84-
WS_DEBUG_PRINT("EXEC: I2C Scan on port # ");
85-
WS_DEBUG_PRINTLN(_portNum);
91+
WS_DEBUG_PRINT("EXEC: I2C Scan");
92+
8693
// Create response
8794
wippersnapper_i2c_v1_I2CScanResponse scanResp =
8895
wippersnapper_i2c_v1_I2CScanResponse_init_zero;

0 commit comments

Comments
 (0)