diff options
| author | Damien George | 2014-04-13 12:08:52 +0100 |
|---|---|---|
| committer | Damien George | 2014-04-13 12:08:52 +0100 |
| commit | 8a1cab952f08f46182f6f86caf8edf37e477be33 (patch) | |
| tree | 0d032ab1e5390a3d68414f2305a42a8172ee16bf /stmhal/i2c.c | |
| parent | 4b01de44ba110394cac66f83a44a037fc58ae4e8 (diff) | |
py: Fix mp_get_buffer, and use it in more places.
Must use mp_obj_get_type to get the type of an object. Can't assume
mp_obj_t is castable to mp_obj_base_t.
Diffstat (limited to 'stmhal/i2c.c')
| -rw-r--r-- | stmhal/i2c.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/stmhal/i2c.c b/stmhal/i2c.c index 9528a3c3c..65bc3600e 100644 --- a/stmhal/i2c.c +++ b/stmhal/i2c.c @@ -143,16 +143,13 @@ STATIC mp_obj_t pyb_i2c_mem_write(uint n_args, const mp_obj_t *args) { machine_uint_t i2c_addr = mp_obj_get_int(args[1]) << 1; machine_uint_t mem_addr = mp_obj_get_int(args[2]); HAL_StatusTypeDef status; - mp_obj_type_t *type = mp_obj_get_type(args[3]); - if (type->buffer_p.get_buffer != NULL) { - buffer_info_t bufinfo; - type->buffer_p.get_buffer(args[3], &bufinfo, BUFFER_READ); - status = HAL_I2C_Mem_Write(self->i2c_handle, i2c_addr, mem_addr, I2C_MEMADD_SIZE_8BIT, bufinfo.buf, bufinfo.len, 200); - } else if (MP_OBJ_IS_INT(args[3])) { + if (MP_OBJ_IS_INT(args[3])) { uint8_t data[1] = {mp_obj_get_int(args[3])}; status = HAL_I2C_Mem_Write(self->i2c_handle, i2c_addr, mem_addr, I2C_MEMADD_SIZE_8BIT, data, 1, 200); } else { - nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "data argument must be an integer or support the buffer protocol")); + buffer_info_t bufinfo; + mp_get_buffer_raise(args[3], &bufinfo); + status = HAL_I2C_Mem_Write(self->i2c_handle, i2c_addr, mem_addr, I2C_MEMADD_SIZE_8BIT, bufinfo.buf, bufinfo.len, 200); } //printf("Write got %d\n", status); |
