Skip to content

Commit 300921a

Browse files
committed
i2c-support: Refactor to use variants pinmap
* Now the o2c_dev is defined in the XX_pinmap.h file in variants so we now have abstraction. This way there should not be a need for the user while adding new board support to modify or tweak the Wire library. * Replace double quotes (") with angel braces because we have a proper CMake structure that takes care of all the include locations for us. * Move a few includes from the Wire library into the arduino...pinmap.h file since we need to create the i2c_dev over there. * Delete unused variables inside Wire.h like rxRingBuffer and i2c_dev and bus. Signed-off-by: Dhruva Gole <[email protected]>
1 parent 5142275 commit 300921a

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

libraries/Wire/Wire.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <Wire.h>
22

33
void arduino::ZephyrI2C::begin() {
4-
i2c_dev = DEVICE_DT_GET(DT_NODELABEL(i2c0));
54
ring_buf_init(&rxRingBuffer.rb, sizeof(rxRingBuffer.buffer), rxRingBuffer.buffer);
65
}
76

@@ -75,7 +74,7 @@ int arduino::ZephyrI2C::read() {
7574
}
7675
return (int)buf[0];
7776
}
78-
return rxBuffer[0];
77+
return EXIT_FAILURE;
7978
}
8079

8180
int arduino::ZephyrI2C::available() { // TODO for ADS1115

libraries/Wire/Wire.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#pragma once
22

3-
#include "api/ArduinoAPI.h"
4-
#include "api/HardwareI2C.h"
5-
#include "api/Print.h"
6-
#include <zephyr/drivers/i2c.h>
7-
#include <zephyr/device.h>
3+
#include <Arduino.h>
4+
#include <api/HardwareI2C.h>
5+
#include <api/Print.h>
86
#include <zephyr/sys/ring_buffer.h>
97

108
typedef void (*voidFuncPtrParamInt)(int);
@@ -36,12 +34,10 @@ class ZephyrI2C : public HardwareI2C {
3634
virtual int peek();
3735
virtual void flush();
3836
virtual int available();
39-
const struct device *i2c_dev;
40-
static struct i2c_dt_spec bus;
4137

4238
private:
4339
int _address;
44-
uint8_t txBuffer[256], rxBuffer[256];
40+
uint8_t txBuffer[256];
4541
uint32_t usedTxBuffer;
4642
struct rx_ring_buf{
4743
struct ring_buf rb;

variants/arduino_nano_33_iot/arduino_nano_33_iot_pinmap.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#pragma once
99
#include <zephyr/drivers/gpio.h>
1010
#include <zephyr/zephyr.h>
11+
#include <zephyr/drivers/i2c.h>
12+
#include <zephyr/device.h>
1113

1214
#define LED_BUILTIN 13
1315

@@ -79,4 +81,6 @@ enum digitalPins {
7981
D19,
8082
D20,
8183
D21
82-
};
84+
};
85+
86+
const static struct device *i2c_dev = DEVICE_DT_GET(DT_NODELABEL(i2c0));

0 commit comments

Comments
 (0)