arduino-emulator
Loading...
Searching...
No Matches
RemoteI2C.h
1#pragma once
2#include "Stream.h"
3#include "api/HardwareI2C.h"
4#include "HardwareService.h"
5
6namespace arduino {
7
30class RemoteI2C : public HardwareI2C {
31 public:
32 RemoteI2C() = default;
33 RemoteI2C(Stream* stream) { service.setStream(static_cast<Stream*>(stream)); }
34 void setStream(Stream* stream) {
35 service.setStream(static_cast<Stream*>(stream));
36 }
37
38 virtual void begin() {
39 service.send(I2cBegin0);
40 service.flush();
41 }
42
43 virtual void begin(uint8_t address) {
44 service.send(I2cBegin1);
45 service.send(address);
46 service.flush();
47 }
48 virtual void end() {
49 service.send(I2cEnd);
50 service.flush();
51 }
52
53 virtual void setClock(uint32_t freq) {
54 service.send(I2cSetClock);
55 service.send(freq);
56 service.flush();
57 }
58
59 virtual void beginTransmission(uint8_t address) {
60 service.send(I2cBeginTransmission);
61 service.send(address);
62 service.flush();
63 }
64
65 virtual uint8_t endTransmission(bool stopBit) {
66 service.send(I2cEndTransmission1);
67 service.send(stopBit);
68 return service.receive8();
69 }
70
71 virtual uint8_t endTransmission(void) {
72 service.send(I2cEndTransmission);
73 return service.receive8();
74 }
75
76 virtual size_t requestFrom(uint8_t address, size_t len, bool stopBit) {
77 service.send(I2cRequestFrom3);
78 service.send(address);
79 service.send((uint64_t)len);
80 service.send(stopBit);
81 return service.receive8();
82 }
83
84 virtual size_t requestFrom(uint8_t address, size_t len) {
85 service.send(I2cRequestFrom2);
86 service.send(address);
87 service.send((uint64_t)len);
88 return service.receive8();
89 }
90
91 virtual void onReceive(void (*)(int)) {}
92
93 virtual void onRequest(void (*)(void)) {}
94
95 size_t write(uint8_t c) {
96 service.send(I2cWrite);
97 service.send(c);
98 return service.receive16();
99 }
100
101 int available() {
102 service.send(I2cAvailable);
103 return service.receive16();
104 }
105
106 int read() {
107 service.send(I2cRead);
108 return service.receive16();
109 }
110
111 int peek() {
112 service.send(I2cPeek);
113 return service.receive16();
114 }
115
116 operator bool() { return service; }
117
118 protected:
119 HardwareService service;
120};
121
122} // namespace arduino
Definition DMAPool.h:103
Definition HardwareI2C.h:28
Provides a virtualized hardware communication service for SPI, I2C, I2S, and GPIO over a stream.
Definition HardwareService.h:115
Remote I2C implementation that operates over a communication stream.
Definition RemoteI2C.h:30
Definition Stream.h:51
We provide the WiFi class to simulate the Arduino WIFI. In in Linux we can expect that networking is ...
Definition CanMsg.cpp:31