diff options
author | Mike Causer <mcauser@gmail.com> | 2021-07-09 09:51:59 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2021-07-19 23:16:11 +1000 |
commit | 79da7757cc942f202b2f6a276ddcc1d42b484328 (patch) | |
tree | e4e2a560c1a7abb72e23a0872b865df35d30e5bc | |
parent | 4f2a10bfc91d5d49837de581eb09d21293f84e2c (diff) |
rp2/machine_i2c: Allow boards to configure I2C pins using new macros.
-rw-r--r-- | ports/rp2/machine_i2c.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/ports/rp2/machine_i2c.c b/ports/rp2/machine_i2c.c index 0852cc199..3b895ba4d 100644 --- a/ports/rp2/machine_i2c.c +++ b/ports/rp2/machine_i2c.c @@ -33,10 +33,16 @@ #include "hardware/i2c.h" #define DEFAULT_I2C_FREQ (400000) -#define DEFAULT_I2C0_SCL (9) -#define DEFAULT_I2C0_SDA (8) -#define DEFAULT_I2C1_SCL (7) -#define DEFAULT_I2C1_SDA (6) + +#ifndef MICROPY_HW_I2C0_SCL +#define MICROPY_HW_I2C0_SCL (9) +#define MICROPY_HW_I2C0_SDA (8) +#endif + +#ifndef MICROPY_HW_I2C1_SCL +#define MICROPY_HW_I2C1_SCL (7) +#define MICROPY_HW_I2C1_SDA (6) +#endif // SDA/SCL on even/odd pins, I2C0/I2C1 on even/odd pairs of pins. #define IS_VALID_SCL(i2c, pin) (((pin) & 1) == 1 && (((pin) & 2) >> 1) == (i2c)) @@ -52,8 +58,8 @@ typedef struct _machine_i2c_obj_t { } machine_i2c_obj_t; STATIC machine_i2c_obj_t machine_i2c_obj[] = { - {{&machine_hw_i2c_type}, i2c0, 0, DEFAULT_I2C0_SCL, DEFAULT_I2C0_SDA, 0}, - {{&machine_hw_i2c_type}, i2c1, 1, DEFAULT_I2C1_SCL, DEFAULT_I2C1_SDA, 0}, + {{&machine_hw_i2c_type}, i2c0, 0, MICROPY_HW_I2C0_SCL, MICROPY_HW_I2C0_SDA, 0}, + {{&machine_hw_i2c_type}, i2c1, 1, MICROPY_HW_I2C1_SCL, MICROPY_HW_I2C1_SDA, 0}, }; STATIC void machine_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { |