Skip to content

Commit bebaf2d

Browse files
authored
Add smbus support and the writeQuick function (#43)
1 parent c36e44f commit bebaf2d

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

ArduinoCore-API/api/HardwareI2C.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class HardwareI2C : public Stream
4141

4242
virtual void onReceive(void(*)(int)) = 0;
4343
virtual void onRequest(void(*)(void)) = 0;
44+
45+
virtual int writeQuick(uint8_t toWrite) = 0;
4446
};
4547

4648
}

cores/portduino/linux/LinuxHardwareI2C.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
#include <iostream>
1010
#include <linux/i2c.h>
1111

12+
13+
extern "C"
14+
{
15+
#include<linux/i2c-dev.h>
16+
#include <i2c/smbus.h>
17+
}
18+
19+
1220
namespace arduino {
1321
char buf[100] = {0};
1422
int requestedBytes = 0;
@@ -46,6 +54,10 @@ namespace arduino {
4654

4755
}
4856

57+
int LinuxHardwareI2C::writeQuick(uint8_t toWrite) {
58+
int a = i2c_smbus_write_quick(i2c_file, toWrite);
59+
return a;
60+
}
4961

5062
size_t LinuxHardwareI2C::write(uint8_t toWrite) {
5163
buf[requestedBytes] = toWrite; // todo: alloc and copy

cores/portduino/linux/LinuxHardwareI2C.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class LinuxHardwareI2C : public HardwareI2C {
5353
// Methods from Print
5454

5555
virtual size_t write(uint8_t toWrite);
56+
57+
int writeQuick(uint8_t toWrite);
5658

5759
virtual size_t write(const uint8_t *buffer, size_t size);
5860

cores/portduino/simulated/SimHardwareI2C.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ enum ResultI2c {
2222
class SimHardwareI2C : public HardwareI2C {
2323
public:
2424
virtual void begin() NOT_IMPLEMENTED("i2cbegin");
25+
virtual int writeQuick(uint8_t toWrite) NOT_IMPLEMENTED("writeQuick");
2526

2627
virtual void begin(uint8_t address) NOT_IMPLEMENTED("i2cslave begin");
2728

0 commit comments

Comments
 (0)