25
25
*****************************************************************************/
26
26
27
27
/* *
28
- * @file Wire .cpp
28
+ * @file SoftWire .cpp
29
29
* @author Trystan Jones <[email protected] >
30
30
* @brief Wire library, uses the WireBase to create the primary interface
31
31
* while keeping low level interactions invisible to the user.
54
54
* - always start with i2c_delay rather than end
55
55
*/
56
56
57
- void TwoWire ::set_scl (bool state) {
57
+ void SoftWire ::set_scl (bool state) {
58
58
I2C_DELAY (this ->i2c_delay );
59
59
60
60
gpio_write_bit (sclDevice,sclBit, state);
@@ -65,30 +65,30 @@ void TwoWire::set_scl(bool state) {
65
65
}
66
66
}
67
67
68
- void TwoWire ::set_sda (bool state) {
68
+ void SoftWire ::set_sda (bool state) {
69
69
I2C_DELAY (this ->i2c_delay );
70
70
gpio_write_bit (sdaDevice,sdaBit, state);
71
71
// digitalWrite(this->sda_pin, state);
72
72
}
73
73
74
- void TwoWire ::i2c_start () {
74
+ void SoftWire ::i2c_start () {
75
75
set_sda (LOW);
76
76
set_scl (LOW);
77
77
}
78
78
79
- void TwoWire ::i2c_stop () {
79
+ void SoftWire ::i2c_stop () {
80
80
set_sda (LOW);
81
81
set_scl (HIGH);
82
82
set_sda (HIGH);
83
83
}
84
84
85
- void TwoWire ::i2c_repeated_start () {
85
+ void SoftWire ::i2c_repeated_start () {
86
86
set_sda (HIGH);
87
87
set_scl (HIGH);
88
88
set_sda (LOW);
89
89
}
90
90
91
- bool TwoWire ::i2c_get_ack () {
91
+ bool SoftWire ::i2c_get_ack () {
92
92
set_scl (LOW);
93
93
set_sda (HIGH);
94
94
set_scl (HIGH);
@@ -98,19 +98,19 @@ bool TwoWire::i2c_get_ack() {
98
98
return ret;
99
99
}
100
100
101
- void TwoWire ::i2c_send_ack () {
101
+ void SoftWire ::i2c_send_ack () {
102
102
set_sda (LOW);
103
103
set_scl (HIGH);
104
104
set_scl (LOW);
105
105
}
106
106
107
- void TwoWire ::i2c_send_nack () {
107
+ void SoftWire ::i2c_send_nack () {
108
108
set_sda (HIGH);
109
109
set_scl (HIGH);
110
110
set_scl (LOW);
111
111
}
112
112
113
- uint8 TwoWire ::i2c_shift_in () {
113
+ uint8 SoftWire ::i2c_shift_in () {
114
114
uint8 data = 0 ;
115
115
set_sda (HIGH);
116
116
@@ -124,7 +124,7 @@ uint8 TwoWire::i2c_shift_in() {
124
124
return data;
125
125
}
126
126
127
- void TwoWire ::i2c_shift_out (uint8 val) {
127
+ void SoftWire ::i2c_shift_out (uint8 val) {
128
128
int i;
129
129
for (i = 0 ; i < 8 ; i++) {
130
130
set_sda (!!(val & (1 << (7 - i)) ) );
@@ -134,7 +134,7 @@ void TwoWire::i2c_shift_out(uint8 val) {
134
134
}
135
135
136
136
// process needs to be updated for repeated start.
137
- uint8 TwoWire ::process (uint8 stop) {
137
+ uint8 SoftWire ::process (uint8 stop) {
138
138
itc_msg.xferred = 0 ;
139
139
140
140
uint8 sla_addr = (itc_msg.addr << 1 );
@@ -183,18 +183,18 @@ uint8 TwoWire::process(uint8 stop) {
183
183
}
184
184
185
185
// For compatibility with legacy code
186
- uint8 TwoWire ::process (){
186
+ uint8 SoftWire ::process (){
187
187
return process (true );
188
188
}
189
189
190
190
// TODO: Add in Error Handling if pins is out of range for other Maples
191
191
// TODO: Make delays more capable
192
- TwoWire::TwoWire (uint8 scl, uint8 sda, uint8 delay) : i2c_delay(delay) {
192
+ SoftWire::SoftWire (uint8 scl, uint8 sda, uint8 delay) : i2c_delay(delay) {
193
193
this ->scl_pin =scl;
194
194
this ->sda_pin =sda;
195
195
}
196
196
197
- void TwoWire ::begin (uint8 self_addr) {
197
+ void SoftWire ::begin (uint8 self_addr) {
198
198
tx_buf_idx = 0 ;
199
199
tx_buf_overflow = false ;
200
200
rx_buf_idx = 0 ;
@@ -210,7 +210,7 @@ void TwoWire::begin(uint8 self_addr) {
210
210
set_sda (HIGH);
211
211
}
212
212
213
- void TwoWire ::end ()
213
+ void SoftWire ::end ()
214
214
{
215
215
if (this ->scl_pin )
216
216
{
@@ -222,7 +222,7 @@ void TwoWire::end()
222
222
}
223
223
}
224
224
225
- void TwoWire ::setClock (uint32_t frequencyHz)
225
+ void SoftWire ::setClock (uint32_t frequencyHz)
226
226
{
227
227
switch (frequencyHz)
228
228
{
@@ -236,11 +236,11 @@ void TwoWire::setClock(uint32_t frequencyHz)
236
236
}
237
237
}
238
238
239
- TwoWire ::~TwoWire () {
239
+ SoftWire ::~SoftWire () {
240
240
this ->scl_pin =0 ;
241
241
this ->sda_pin =0 ;
242
242
}
243
243
244
244
// Declare the instance that the users of the library can use
245
- // TwoWire Wire(SCL, SDA, SOFT_STANDARD);
246
- // TwoWire Wire(PB6, PB7, SOFT_FAST);
245
+ // SoftWire Wire(SCL, SDA, SOFT_STANDARD);
246
+ // SoftWire Wire(PB6, PB7, SOFT_FAST);
0 commit comments