|
38 | 38 | #include "py/obj.h"
|
39 | 39 | #include "py/objproperty.h"
|
40 | 40 | #include "py/runtime.h"
|
| 41 | +#include "py/stream.h" |
41 | 42 |
|
42 | 43 | STATIC mp_obj_t mp_obj_new_i2cslave_i2c_slave_request(i2cslave_i2c_slave_obj_t *slave, uint8_t address, bool is_read, bool is_restart) {
|
43 | 44 | i2cslave_i2c_slave_request_obj_t *self = m_new_obj(i2cslave_i2c_slave_request_obj_t);
|
@@ -226,10 +227,28 @@ STATIC const mp_rom_map_elem_t i2cslave_i2c_slave_locals_dict_table[] = {
|
226 | 227 |
|
227 | 228 | STATIC MP_DEFINE_CONST_DICT(i2cslave_i2c_slave_locals_dict, i2cslave_i2c_slave_locals_dict_table);
|
228 | 229 |
|
| 230 | +STATIC mp_uint_t i2cslave_ioctl(mp_obj_t obj, mp_uint_t request, uintptr_t arg, int *errcode) { |
| 231 | + i2cslave_i2c_slave_obj_t *self = MP_OBJ_TO_PTR(obj); |
| 232 | + int status = -MP_EINVAL; |
| 233 | + if (request == MP_STREAM_POLL) { |
| 234 | + status = common_hal_i2cslave_i2c_slave_is_addressed(self, NULL, NULL, NULL); |
| 235 | + } |
| 236 | + if (status < 0) { |
| 237 | + *errcode = -status; |
| 238 | + return MP_STREAM_ERROR; |
| 239 | + } |
| 240 | + return status; |
| 241 | +} |
| 242 | + |
| 243 | +STATIC const mp_stream_p_t i2cslave_p = { |
| 244 | + .ioctl = i2cslave_ioctl, |
| 245 | +}; |
| 246 | + |
229 | 247 | const mp_obj_type_t i2cslave_i2c_slave_type = {
|
230 | 248 | { &mp_type_type },
|
231 | 249 | .name = MP_QSTR_I2CSlave,
|
232 | 250 | .make_new = i2cslave_i2c_slave_make_new,
|
| 251 | + .protocol = &i2cslave_p, |
233 | 252 | .locals_dict = (mp_obj_dict_t*)&i2cslave_i2c_slave_locals_dict,
|
234 | 253 | };
|
235 | 254 |
|
|
0 commit comments