-
Notifications
You must be signed in to change notification settings - Fork 6
/
Port_ESPEasySerial_I2C_SC16IS752.cpp
138 lines (116 loc) · 2.92 KB
/
Port_ESPEasySerial_I2C_SC16IS752.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "Port_ESPEasySerial_I2C_SC16IS752.h"
#if USES_I2C_SC16IS752
Port_ESPEasySerial_I2C_SC16IS752_t::Port_ESPEasySerial_I2C_SC16IS752_t(const ESPEasySerialConfig& config)
{
if (config.port == ESPEasySerialPort::sc16is752) {
ESPEasySC16IS752_Serial::I2C_address addr;
ESPEasySC16IS752_Serial::SC16IS752_channel ch;
if (config.getI2C_SC16IS752_Parameters(addr, ch)) {
_config = config;
_config.rxBuffSize = 64; // Fixed size
_config.txBuffSize = 64; // Fixed size
_i2cserial = new (std::nothrow) ESPEasySC16IS752_Serial(addr, ch);
}
}
}
Port_ESPEasySerial_I2C_SC16IS752_t::~Port_ESPEasySerial_I2C_SC16IS752_t()
{
if (_i2cserial != nullptr) {
delete _i2cserial;
_i2cserial = nullptr;
}
}
void Port_ESPEasySerial_I2C_SC16IS752_t::begin(unsigned long baud)
{
if (_i2cserial != nullptr) {
_config.baud = baud;
_i2cserial->begin(baud);
}
}
void Port_ESPEasySerial_I2C_SC16IS752_t::end() {
if (_i2cserial != nullptr) {
_i2cserial->end();
}
}
int Port_ESPEasySerial_I2C_SC16IS752_t::available(void)
{
if (_i2cserial != nullptr) {
return _i2cserial->available();
}
return 0;
}
int Port_ESPEasySerial_I2C_SC16IS752_t::availableForWrite(void)
{
if (_i2cserial != nullptr) {
// FIXME TD-er: Implement availableForWrite
return 4; // _i2cserial->availableForWrite();
}
return 0;
}
int Port_ESPEasySerial_I2C_SC16IS752_t::peek(void)
{
if (_i2cserial != nullptr) {
return _i2cserial->peek();
}
return 0;
}
int Port_ESPEasySerial_I2C_SC16IS752_t::read(void)
{
if (_i2cserial != nullptr) {
return _i2cserial->read();
}
return 0;
}
size_t Port_ESPEasySerial_I2C_SC16IS752_t::read(uint8_t *buffer,
size_t size)
{
if (_i2cserial != nullptr) {
return _i2cserial->readBytes((char *)buffer, size);
}
return 0;
}
void Port_ESPEasySerial_I2C_SC16IS752_t::flush(void)
{
if (_i2cserial != nullptr) {
return _i2cserial->flush();
}
}
void Port_ESPEasySerial_I2C_SC16IS752_t::flush(bool txOnly)
{
flush();
}
size_t Port_ESPEasySerial_I2C_SC16IS752_t::write(uint8_t value)
{
if (_i2cserial != nullptr) {
return _i2cserial->write(value);
}
return 0;
}
size_t Port_ESPEasySerial_I2C_SC16IS752_t::write(const uint8_t *buffer,
size_t size)
{
if (_i2cserial != nullptr) {
return _i2cserial->write(buffer, size);
}
return 0;
}
Port_ESPEasySerial_I2C_SC16IS752_t::operator bool() const
{
return _i2cserial != nullptr;
}
void Port_ESPEasySerial_I2C_SC16IS752_t::setDebugOutput(bool) {}
size_t Port_ESPEasySerial_I2C_SC16IS752_t::setRxBufferSize(size_t new_size)
{
if (_i2cserial != nullptr) {
return 64;
}
return 0;
}
size_t Port_ESPEasySerial_I2C_SC16IS752_t::setTxBufferSize(size_t new_size)
{
if (_i2cserial != nullptr) {
return 64;
}
return 0;
}
#endif // ifndef DISABLE_SC16IS752_Serial