24
24
* THE SOFTWARE.
25
25
*/
26
26
27
- #include "shared-bindings/i2cperipheral/I2CPeripheral .h"
27
+ #include "shared-bindings/i2ctarget/I2CTarget .h"
28
28
#include "shared-bindings/microcontroller/Pin.h"
29
29
#include "common-hal/busio/I2C.h"
30
30
36
36
#include "hal/include/hal_gpio.h"
37
37
#include "peripherals/samd/sercom.h"
38
38
39
- void common_hal_i2cperipheral_i2c_peripheral_construct ( i2cperipheral_i2c_peripheral_obj_t * self ,
39
+ void common_hal_i2ctarget_i2c_target_construct ( i2ctarget_i2c_target_obj_t * self ,
40
40
const mcu_pin_obj_t * scl , const mcu_pin_obj_t * sda ,
41
41
uint8_t * addresses , unsigned int num_addresses , bool smbus ) {
42
42
uint8_t sercom_index ;
@@ -100,12 +100,12 @@ void common_hal_i2cperipheral_i2c_peripheral_construct(i2cperipheral_i2c_periphe
100
100
sercom -> I2CS .CTRLA .bit .ENABLE = 1 ;
101
101
}
102
102
103
- bool common_hal_i2cperipheral_i2c_peripheral_deinited ( i2cperipheral_i2c_peripheral_obj_t * self ) {
103
+ bool common_hal_i2ctarget_i2c_target_deinited ( i2ctarget_i2c_target_obj_t * self ) {
104
104
return self -> sda_pin == NO_PIN ;
105
105
}
106
106
107
- void common_hal_i2cperipheral_i2c_peripheral_deinit ( i2cperipheral_i2c_peripheral_obj_t * self ) {
108
- if (common_hal_i2cperipheral_i2c_peripheral_deinited (self )) {
107
+ void common_hal_i2ctarget_i2c_target_deinit ( i2ctarget_i2c_target_obj_t * self ) {
108
+ if (common_hal_i2ctarget_i2c_target_deinited (self )) {
109
109
return ;
110
110
}
111
111
@@ -117,7 +117,7 @@ void common_hal_i2cperipheral_i2c_peripheral_deinit(i2cperipheral_i2c_peripheral
117
117
self -> scl_pin = NO_PIN ;
118
118
}
119
119
120
- static int i2c_peripheral_check_error ( i2cperipheral_i2c_peripheral_obj_t * self , bool raise ) {
120
+ static int i2c_target_check_error ( i2ctarget_i2c_target_obj_t * self , bool raise ) {
121
121
if (!self -> sercom -> I2CS .INTFLAG .bit .ERROR ) {
122
122
return 0 ;
123
123
}
@@ -136,8 +136,8 @@ static int i2c_peripheral_check_error(i2cperipheral_i2c_peripheral_obj_t *self,
136
136
return - err ;
137
137
}
138
138
139
- int common_hal_i2cperipheral_i2c_peripheral_is_addressed ( i2cperipheral_i2c_peripheral_obj_t * self , uint8_t * address , bool * is_read , bool * is_restart ) {
140
- int err = i2c_peripheral_check_error (self , false);
139
+ int common_hal_i2ctarget_i2c_target_is_addressed ( i2ctarget_i2c_target_obj_t * self , uint8_t * address , bool * is_read , bool * is_restart ) {
140
+ int err = i2c_target_check_error (self , false);
141
141
if (err ) {
142
142
return err ;
143
143
}
@@ -154,22 +154,22 @@ int common_hal_i2cperipheral_i2c_peripheral_is_addressed(i2cperipheral_i2c_perip
154
154
155
155
for (unsigned int i = 0 ; i < self -> num_addresses ; i ++ ) {
156
156
if (* address == self -> addresses [i ]) {
157
- common_hal_i2cperipheral_i2c_peripheral_ack (self , true);
157
+ common_hal_i2ctarget_i2c_target_ack (self , true);
158
158
return 1 ;
159
159
}
160
160
}
161
161
162
162
// This should clear AMATCH, but it doesn't...
163
- common_hal_i2cperipheral_i2c_peripheral_ack (self , false);
163
+ common_hal_i2ctarget_i2c_target_ack (self , false);
164
164
return 0 ;
165
165
}
166
166
167
- int common_hal_i2cperipheral_i2c_peripheral_read_byte ( i2cperipheral_i2c_peripheral_obj_t * self , uint8_t * data ) {
167
+ int common_hal_i2ctarget_i2c_target_read_byte ( i2ctarget_i2c_target_obj_t * self , uint8_t * data ) {
168
168
for (int t = 0 ; t < 100 && !self -> sercom -> I2CS .INTFLAG .reg ; t ++ ) {
169
169
mp_hal_delay_us (10 );
170
170
}
171
171
172
- i2c_peripheral_check_error (self , true);
172
+ i2c_target_check_error (self , true);
173
173
174
174
if (!self -> sercom -> I2CS .INTFLAG .bit .DRDY ||
175
175
self -> sercom -> I2CS .INTFLAG .bit .PREC ||
@@ -181,12 +181,12 @@ int common_hal_i2cperipheral_i2c_peripheral_read_byte(i2cperipheral_i2c_peripher
181
181
return 1 ;
182
182
}
183
183
184
- int common_hal_i2cperipheral_i2c_peripheral_write_byte ( i2cperipheral_i2c_peripheral_obj_t * self , uint8_t data ) {
184
+ int common_hal_i2ctarget_i2c_target_write_byte ( i2ctarget_i2c_target_obj_t * self , uint8_t data ) {
185
185
for (int t = 0 ; !self -> sercom -> I2CS .INTFLAG .reg && t < 100 ; t ++ ) {
186
186
mp_hal_delay_us (10 );
187
187
}
188
188
189
- i2c_peripheral_check_error (self , true);
189
+ i2c_target_check_error (self , true);
190
190
191
191
if (self -> sercom -> I2CS .INTFLAG .bit .PREC ) {
192
192
return 0 ;
@@ -208,12 +208,12 @@ int common_hal_i2cperipheral_i2c_peripheral_write_byte(i2cperipheral_i2c_periphe
208
208
return 1 ;
209
209
}
210
210
211
- void common_hal_i2cperipheral_i2c_peripheral_ack ( i2cperipheral_i2c_peripheral_obj_t * self , bool ack ) {
211
+ void common_hal_i2ctarget_i2c_target_ack ( i2ctarget_i2c_target_obj_t * self , bool ack ) {
212
212
self -> sercom -> I2CS .CTRLB .bit .ACKACT = !ack ;
213
213
self -> sercom -> I2CS .CTRLB .bit .CMD = 0x03 ;
214
214
}
215
215
216
- void common_hal_i2cperipheral_i2c_peripheral_close ( i2cperipheral_i2c_peripheral_obj_t * self ) {
216
+ void common_hal_i2ctarget_i2c_target_close ( i2ctarget_i2c_target_obj_t * self ) {
217
217
for (int t = 0 ; !self -> sercom -> I2CS .INTFLAG .reg && t < 100 ; t ++ ) {
218
218
mp_hal_delay_us (10 );
219
219
}
@@ -223,7 +223,7 @@ void common_hal_i2cperipheral_i2c_peripheral_close(i2cperipheral_i2c_peripheral_
223
223
}
224
224
225
225
if (!self -> sercom -> I2CS .STATUS .bit .DIR ) {
226
- common_hal_i2cperipheral_i2c_peripheral_ack (self , false);
226
+ common_hal_i2ctarget_i2c_target_ack (self , false);
227
227
} else {
228
228
int i = 0 ;
229
229
while (self -> sercom -> I2CS .INTFLAG .reg == SERCOM_I2CS_INTFLAG_DRDY ) {
0 commit comments