Skip to content

Commit

Permalink
Added RP2040 support
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed Sep 25, 2023
1 parent 5017111 commit f9278e1
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 6 deletions.
2 changes: 0 additions & 2 deletions examples/LTR553ALS_Sensor/LTR553ALS_Sensor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ void setup()

pinMode(SENSOR_IRQ, INPUT_PULLUP);

Wire.begin(SENSOR_SDA, SENSOR_SCL);

if (!als.begin(Wire, LTR553_SLAVE_ADDRESS, SENSOR_SDA, SENSOR_SCL)) {
Serial.println("Failed to find LTR553 - check your wiring!");
while (1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ void setup()

// Search for known CSTxxx device addresses
uint8_t address = 0xFF;

#ifdef ARDUINO_ARCH_RP2040
Wire.setSCL(SENSOR_SCL);
Wire.setSDA(SENSOR_SDA);
#else
Wire.begin(SENSOR_SDA, SENSOR_SCL);
#endif

// Scan I2C devices
scanDevices();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ void setup()
while (!Serial);
Serial.println("Start!");

#ifdef ARDUINO_ARCH_RP2040
Wire.setSCL(SENSOR_SCL);
Wire.setSDA(SENSOR_SDA);
#else
Wire.begin(SENSOR_SDA, SENSOR_SCL);
#endif

scanDevices();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ void setup()
Serial.begin(115200);
while (!Serial);

Wire.begin(I2C_SDA, I2C_SCL);

// Device address 0x20~0x27
if (!extIO.begin(Wire, XL9555_SLAVE_ADDRESS4, I2C_SDA, I2C_SCL)) {
Expand Down
1 change: 0 additions & 1 deletion examples/XL9555_ExtensionIORead/XL9555_ExtensionIORead.ino
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ void setup()
Serial.begin(115200);
while (!Serial);

Wire.begin(I2C_SDA, I2C_SCL);

// Device address 0x20~0x27
if (!extIO.begin(Wire, XL9555_SLAVE_ADDRESS4, I2C_SDA, I2C_SCL)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void setup()
while (!Serial);


Wire.begin(I2C_SDA, I2C_SCL);

// Device address 0x20~0x27
if (!extIO.begin(Wire, XL9555_SLAVE_ADDRESS4, I2C_SDA, I2C_SCL)) {
Serial.println("Failed to find XL9555 - check your wiring!");
Expand Down
25 changes: 24 additions & 1 deletion src/SensorCommon.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
#include <SPI.h>
#endif

#ifdef ARDUINO_ARCH_MBED
// Not supported at the moment
#error The Arduino RP2040 MBED board package is not supported when PIO is used. Use the community package by Earle Philhower.
#endif

#define SENSOR_PIN_NONE (-1)
#define DEV_WIRE_NONE (0)
#define DEV_WIRE_ERR (-1)
Expand All @@ -56,13 +61,31 @@
#define LOG_BIN(x)
#endif

#ifndef ESP32
#ifndef lowByte
#define lowByte(w) ((uint8_t) ((w) & 0xff))
#endif

#ifndef highByte
#define highByte(w) ((uint8_t) ((w) >> 8))
#endif

#ifndef bitRead
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
#endif

#ifndef bitSet
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
#endif

#ifndef bitClear
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
#endif

#ifndef bitToggle
#define bitToggle(value, bit) ((value) ^= (1UL << (bit)))
#endif

#ifndef bitWrite
#define bitWrite(value, bit, bitvalue) ((bitvalue) ? bitSet(value, bit) : bitClear(value, bit))
#endif

Expand Down

0 comments on commit f9278e1

Please sign in to comment.