MCPcopy Create free account
hub / github.com/SlimeVR/SlimeVR-Tracker-ESP / swapI2C

Function swapI2C

src/sensorinterface/I2CWireSensorInterface.cpp:37–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35
36namespace SlimeVR {
37void swapI2C(uint8_t sclPin, uint8_t sdaPin) {
38 if (sclPin != activeSCLPin || sdaPin != activeSDAPin || !isI2CActive) {
39 Wire.flush();
40#ifdef ESP32
41 if (!isI2CActive) {
42 // Reset HWI2C to avoid being affected by I2CBUS reset
43 Wire.end();
44 }
45
46 if (activeSCLPin && activeSCLPin) {
47 // Disconnect pins from HWI2C
48 gpio_set_direction((gpio_num_t)*activeSCLPin, GPIO_MODE_INPUT);
49 gpio_set_direction((gpio_num_t)*activeSDAPin, GPIO_MODE_INPUT);
50 }
51
52 if (isI2CActive) {
53 i2c_set_pin(I2C_NUM_0, sdaPin, sclPin, false, false, I2C_MODE_MASTER);
54 } else {
55 Wire.begin(static_cast<int>(sdaPin), static_cast<int>(sclPin), I2C_SPEED);
56 Wire.setTimeOut(150);
57 }
58#else
59 Wire.begin(static_cast<int>(sdaPin), static_cast<int>(sclPin));
60#endif
61
62 activeSCLPin = sclPin;
63 activeSDAPin = sdaPin;
64 isI2CActive = true;
65 }
66}
67
68void disconnectI2C() {
69 Wire.flush();

Callers 1

swapInMethod · 0.85

Calls 1

beginMethod · 0.45

Tested by

no test coverage detected