Skip to content

Commit cc52f8e

Browse files
author
Matt Land
committed
Merge branch 'feature-i2c-gemma' into feature-default-spi-circuit-playground
2 parents de885e8 + 0a185c4 commit cc52f8e

File tree

14 files changed

+36
-19
lines changed

14 files changed

+36
-19
lines changed

ports/atmel-samd/board_busses.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
assert_pin_free(DEFAULT_I2C_BUS_SDA);
5454
assert_pin_free(DEFAULT_I2C_BUS_SCL);
55-
common_hal_busio_i2c_construct(self, DEFAULT_I2C_BUS_SCL, DEFAULT_I2C_BUS_SDA, 400000);
55+
common_hal_busio_i2c_construct(self, DEFAULT_I2C_BUS_SCL, DEFAULT_I2C_BUS_SDA, 400000, 0);
5656
i2c_singleton = (mp_obj_t)self;
5757
}
5858
return i2c_singleton;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#include "samd21_pins.h"
2+
#include "board_busses.h"
23

34
STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
45
{ MP_ROM_QSTR(MP_QSTR_REMOTEIN), MP_ROM_PTR(&pin_PA28) },
56

67
{ MP_ROM_QSTR(MP_QSTR_APA102_MOSI), MP_ROM_PTR(&pin_PA00) },
78
{ MP_ROM_QSTR(MP_QSTR_APA102_SCK), MP_ROM_PTR(&pin_PA01) },
9+
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
810
};
911
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);

ports/atmel-samd/boards/ugame10/pins.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "samd21_pins.h"
2+
#include "board_busses.h"
23

34
STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
45
{ MP_ROM_QSTR(MP_QSTR_X), MP_ROM_PTR(&pin_PA00) },
@@ -23,5 +24,6 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
2324
{ MP_ROM_QSTR(MP_QSTR_B), MP_ROM_PTR(&pin_PA14) },
2425
{ MP_ROM_QSTR(MP_QSTR_C), MP_ROM_PTR(&pin_PA15) },
2526
{ MP_ROM_QSTR(MP_QSTR_D), MP_ROM_PTR(&pin_PA28) },
27+
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
2628
};
2729
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);

ports/atmel-samd/common-hal/busio/I2C.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#define ATTEMPTS 2
4242

4343
void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
44-
const mcu_pin_obj_t* scl, const mcu_pin_obj_t* sda, uint32_t frequency) {
44+
const mcu_pin_obj_t* scl, const mcu_pin_obj_t* sda, uint32_t frequency, uint32_t timeout) {
4545
Sercom* sercom = NULL;
4646
uint8_t sercom_index;
4747
uint32_t sda_pinmux = 0;

ports/esp8266/mpconfigport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#define MICROPY_ENABLE_SOURCE_LINE (1)
2929
#define MICROPY_MODULE_WEAK_LINKS (1)
3030
#define MICROPY_CAN_OVERRIDE_BUILTINS (1)
31-
#define MICROPY_USE_INTERNAL_ERRNO (1)
31+
#define MICROPY_USE_INTERNAL_ERRNO (0)
3232
#define MICROPY_ENABLE_SCHEDULER (1)
3333
#define MICROPY_PY_ALL_SPECIAL_METHODS (1)
3434
#define MICROPY_PY_BUILTINS_COMPLEX (0)

ports/nrf/common-hal/busio/I2C.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include "pins.h"
3333
#include "nrf.h"
3434

35-
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) {
35+
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 timeout ) {
3636
if (scl->pin == sda->pin) {
3737
mp_raise_ValueError("Invalid pins");
3838
}

py/objexcept.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,7 @@ MP_DEFINE_EXCEPTION(Exception, BaseException)
275275
MP_DEFINE_EXCEPTION(UnboundLocalError, NameError)
276276
*/
277277
MP_DEFINE_EXCEPTION(OSError, Exception)
278-
#if MICROPY_PY_BUILTINS_TIMEOUTERROR
279-
MP_DEFINE_EXCEPTION(TimeoutError, OSError)
280-
#endif
278+
MP_DEFINE_EXCEPTION(TimeoutError, OSError)
281279
/*
282280
MP_DEFINE_EXCEPTION(BlockingIOError, OSError)
283281
MP_DEFINE_EXCEPTION(ChildProcessError, OSError)

shared-bindings/bitbangio/I2C.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "lib/utils/context_manager_helpers.h"
3636
#include "py/mperrno.h"
3737
#include "py/runtime.h"
38+
3839
//| .. currentmodule:: bitbangio
3940
//|
4041
//| :class:`I2C` --- Two wire serial protocol
@@ -49,6 +50,7 @@
4950
//| :param ~microcontroller.Pin scl: The clock pin
5051
//| :param ~microcontroller.Pin sda: The data pin
5152
//| :param int frequency: The clock frequency of the bus
53+
//| :param int timeout: The maximum clock stretching timeout in microseconds
5254
//|
5355
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) {
5456
mp_arg_check_num(n_args, n_kw, 0, MP_OBJ_FUN_ARGS_MAX, true);
@@ -57,19 +59,20 @@ STATIC mp_obj_t bitbangio_i2c_make_new(const mp_obj_type_t *type, size_t n_args,
5759
self->base.type = &bitbangio_i2c_type;
5860
mp_map_t kw_args;
5961
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
60-
enum { ARG_scl, ARG_sda, ARG_frequency };
62+
enum { ARG_scl, ARG_sda, ARG_frequency, ARG_timeout };
6163
static const mp_arg_t allowed_args[] = {
6264
{ MP_QSTR_scl, MP_ARG_REQUIRED | MP_ARG_OBJ },
6365
{ MP_QSTR_sda, MP_ARG_REQUIRED | MP_ARG_OBJ },
6466
{ MP_QSTR_frequency, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 400000} },
67+
{ MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 255} },
6568
};
6669
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
6770
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
6871
assert_pin(args[ARG_scl].u_obj, false);
6972
assert_pin(args[ARG_sda].u_obj, false);
7073
const mcu_pin_obj_t* scl = MP_OBJ_TO_PTR(args[ARG_scl].u_obj);
7174
const mcu_pin_obj_t* sda = MP_OBJ_TO_PTR(args[ARG_sda].u_obj);
72-
shared_module_bitbangio_i2c_construct(self, scl, sda, args[ARG_frequency].u_int);
75+
shared_module_bitbangio_i2c_construct(self, scl, sda, args[ARG_frequency].u_int, args[ARG_timeout].u_int);
7376
return (mp_obj_t)self;
7477
}
7578

shared-bindings/bitbangio/I2C.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ extern const mp_obj_type_t bitbangio_i2c_type;
3939
extern void shared_module_bitbangio_i2c_construct(bitbangio_i2c_obj_t *self,
4040
const mcu_pin_obj_t * scl,
4141
const mcu_pin_obj_t * sda,
42-
uint32_t frequency);
42+
uint32_t frequency,
43+
uint32_t us_timeout);
4344

4445
extern void shared_module_bitbangio_i2c_deinit(bitbangio_i2c_obj_t *self);
4546
extern bool shared_module_bitbangio_i2c_deinited(bitbangio_i2c_obj_t *self);

shared-bindings/busio/I2C.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,20 @@
5656
//| :param ~microcontroller.Pin scl: The clock pin
5757
//| :param ~microcontroller.Pin sda: The data pin
5858
//| :param int frequency: The clock frequency in Hertz
59+
//| :param int timeout: The maximum clock stretching timeut - only for bitbang
5960
//|
6061
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) {
6162
mp_arg_check_num(n_args, n_kw, 0, MP_OBJ_FUN_ARGS_MAX, true);
6263
busio_i2c_obj_t *self = m_new_obj(busio_i2c_obj_t);
6364
self->base.type = &busio_i2c_type;
6465
mp_map_t kw_args;
6566
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
66-
enum { ARG_scl, ARG_sda, ARG_frequency };
67+
enum { ARG_scl, ARG_sda, ARG_frequency, ARG_timeout };
6768
static const mp_arg_t allowed_args[] = {
6869
{ MP_QSTR_scl, MP_ARG_REQUIRED | MP_ARG_OBJ },
6970
{ MP_QSTR_sda, MP_ARG_REQUIRED | MP_ARG_OBJ },
7071
{ MP_QSTR_frequency, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 400000} },
72+
{ MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 255} },
7173
};
7274
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
7375
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
7779
assert_pin_free(scl);
7880
const mcu_pin_obj_t* sda = MP_OBJ_TO_PTR(args[ARG_sda].u_obj);
7981
assert_pin_free(sda);
80-
common_hal_busio_i2c_construct(self, scl, sda, args[ARG_frequency].u_int);
82+
common_hal_busio_i2c_construct(self, scl, sda, args[ARG_frequency].u_int, args[ARG_timeout].u_int);
8183
return (mp_obj_t)self;
8284
}
8385

0 commit comments

Comments
 (0)