@@ -35,19 +35,26 @@ WipperSnapper_Component_I2C::WipperSnapper_Component_I2C(
35
35
WS_DEBUG_PRINT (" \t Frequency (Hz): " );
36
36
WS_DEBUG_PRINTLN (msgInitRequest->i2c_frequency );
37
37
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
42
38
// validate if SDA & SCL has pullup
43
39
if (digitalRead (msgInitRequest->i2c_pin_sda ) == LOW) {
44
40
pinMode (msgInitRequest->i2c_pin_sda , INPUT_PULLUP);
45
41
}
46
42
if (digitalRead (msgInitRequest->i2c_pin_scl ) == LOW) {
47
43
pinMode (msgInitRequest->i2c_pin_scl , INPUT_PULLUP);
48
44
}
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 );
50
50
_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
+
51
58
_i2c->setClock (msgInitRequest->i2c_frequency );
52
59
// set i2c obj. properties
53
60
_portNum = msgInitRequest->i2c_port_number ;
@@ -81,8 +88,8 @@ bool WipperSnapper_Component_I2C::isInitialized() { return _isInit; }
81
88
/* ***********************************************************************/
82
89
wippersnapper_i2c_v1_I2CScanResponse
83
90
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
+
86
93
// Create response
87
94
wippersnapper_i2c_v1_I2CScanResponse scanResp =
88
95
wippersnapper_i2c_v1_I2CScanResponse_init_zero;
0 commit comments