summaryrefslogtreecommitdiff
path: root/shared-bindings
diff options
context:
space:
mode:
authorJerry Needell <jerryneedell@gmail.com>2018-05-13 21:54:44 -0400
committerJerry Needell <jerryneedell@gmail.com>2018-05-13 21:54:44 -0400
commitd6c26942a5fadeb95305c86a604233257a7858db (patch)
tree662f54774c30ea60b8b8dd928f55df02ee25cec6 /shared-bindings
parentce5eae1c76b82132453cc9734fb808cf413ffb17 (diff)
add timeout keyword to I2C - for bitbangio - ignored for busio
Diffstat (limited to 'shared-bindings')
-rw-r--r--shared-bindings/bitbangio/I2C.c7
-rw-r--r--shared-bindings/bitbangio/I2C.h3
-rw-r--r--shared-bindings/busio/I2C.c6
-rw-r--r--shared-bindings/busio/I2C.h3
4 files changed, 13 insertions, 6 deletions
diff --git a/shared-bindings/bitbangio/I2C.c b/shared-bindings/bitbangio/I2C.c
index f8f60210e..a5c000ae5 100644
--- a/shared-bindings/bitbangio/I2C.c
+++ b/shared-bindings/bitbangio/I2C.c
@@ -35,6 +35,7 @@
#include "lib/utils/context_manager_helpers.h"
#include "py/mperrno.h"
#include "py/runtime.h"
+
//| .. currentmodule:: bitbangio
//|
//| :class:`I2C` --- Two wire serial protocol
@@ -49,6 +50,7 @@
//| :param ~microcontroller.Pin scl: The clock pin
//| :param ~microcontroller.Pin sda: The data pin
//| :param int frequency: The clock frequency of the bus
+//| :param int timeout: The maximum clock stretching timeout in microseconds
//|
STATIC mp_obj_t bitbangio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
mp_arg_check_num(n_args, n_kw, 0, MP_OBJ_FUN_ARGS_MAX, true);
@@ -57,11 +59,12 @@ STATIC mp_obj_t bitbangio_i2c_make_new(const mp_obj_type_t *type, size_t n_args,
self->base.type = &bitbangio_i2c_type;
mp_map_t kw_args;
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
- enum { ARG_scl, ARG_sda, ARG_frequency };
+ enum { ARG_scl, ARG_sda, ARG_frequency, ARG_timeout };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_scl, MP_ARG_REQUIRED | MP_ARG_OBJ },
{ MP_QSTR_sda, MP_ARG_REQUIRED | MP_ARG_OBJ },
{ MP_QSTR_frequency, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 400000} },
+ { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 255} },
};
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
@@ -69,7 +72,7 @@ STATIC mp_obj_t bitbangio_i2c_make_new(const mp_obj_type_t *type, size_t n_args,
assert_pin(args[ARG_sda].u_obj, false);
const mcu_pin_obj_t* scl = MP_OBJ_TO_PTR(args[ARG_scl].u_obj);
const mcu_pin_obj_t* sda = MP_OBJ_TO_PTR(args[ARG_sda].u_obj);
- shared_module_bitbangio_i2c_construct(self, scl, sda, args[ARG_frequency].u_int);
+ shared_module_bitbangio_i2c_construct(self, scl, sda, args[ARG_frequency].u_int, args[ARG_timeout].u_int);
return (mp_obj_t)self;
}
diff --git a/shared-bindings/bitbangio/I2C.h b/shared-bindings/bitbangio/I2C.h
index 9d393ee12..1ce4d21e9 100644
--- a/shared-bindings/bitbangio/I2C.h
+++ b/shared-bindings/bitbangio/I2C.h
@@ -39,7 +39,8 @@ extern const mp_obj_type_t bitbangio_i2c_type;
extern void shared_module_bitbangio_i2c_construct(bitbangio_i2c_obj_t *self,
const mcu_pin_obj_t * scl,
const mcu_pin_obj_t * sda,
- uint32_t frequency);
+ uint32_t frequency,
+ uint32_t us_timeout);
extern void shared_module_bitbangio_i2c_deinit(bitbangio_i2c_obj_t *self);
extern bool shared_module_bitbangio_i2c_deinited(bitbangio_i2c_obj_t *self);
diff --git a/shared-bindings/busio/I2C.c b/shared-bindings/busio/I2C.c
index b0954d6c8..0d21d30f0 100644
--- a/shared-bindings/busio/I2C.c
+++ b/shared-bindings/busio/I2C.c
@@ -56,6 +56,7 @@
//| :param ~microcontroller.Pin scl: The clock pin
//| :param ~microcontroller.Pin sda: The data pin
//| :param int frequency: The clock frequency in Hertz
+//| :param int timeout: The maximum clock stretching timeut - only for bitbang
//|
STATIC mp_obj_t busio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
mp_arg_check_num(n_args, n_kw, 0, MP_OBJ_FUN_ARGS_MAX, true);
@@ -63,11 +64,12 @@ STATIC mp_obj_t busio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, siz
self->base.type = &busio_i2c_type;
mp_map_t kw_args;
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
- enum { ARG_scl, ARG_sda, ARG_frequency };
+ enum { ARG_scl, ARG_sda, ARG_frequency, ARG_timeout };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_scl, MP_ARG_REQUIRED | MP_ARG_OBJ },
{ MP_QSTR_sda, MP_ARG_REQUIRED | MP_ARG_OBJ },
{ MP_QSTR_frequency, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 400000} },
+ { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 255} },
};
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
@@ -77,7 +79,7 @@ STATIC mp_obj_t busio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, siz
assert_pin_free(scl);
const mcu_pin_obj_t* sda = MP_OBJ_TO_PTR(args[ARG_sda].u_obj);
assert_pin_free(sda);
- common_hal_busio_i2c_construct(self, scl, sda, args[ARG_frequency].u_int);
+ common_hal_busio_i2c_construct(self, scl, sda, args[ARG_frequency].u_int, args[ARG_timeout].u_int);
return (mp_obj_t)self;
}
diff --git a/shared-bindings/busio/I2C.h b/shared-bindings/busio/I2C.h
index 7185d6075..739732e97 100644
--- a/shared-bindings/busio/I2C.h
+++ b/shared-bindings/busio/I2C.h
@@ -46,7 +46,8 @@ extern const mp_obj_type_t busio_i2c_type;
extern void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
const mcu_pin_obj_t * scl,
const mcu_pin_obj_t * sda,
- uint32_t frequency);
+ uint32_t frequency,
+ uint32_t timeout);
extern void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self);
extern bool common_hal_busio_i2c_deinited(busio_i2c_obj_t *self);