Skip to content

Commit 79da775

Browse files
mcauserdpgeorge
authored andcommitted
rp2/machine_i2c: Allow boards to configure I2C pins using new macros.
1 parent 4f2a10b commit 79da775

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

ports/rp2/machine_i2c.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,16 @@
3333
#include "hardware/i2c.h"
3434

3535
#define DEFAULT_I2C_FREQ (400000)
36-
#define DEFAULT_I2C0_SCL (9)
37-
#define DEFAULT_I2C0_SDA (8)
38-
#define DEFAULT_I2C1_SCL (7)
39-
#define DEFAULT_I2C1_SDA (6)
36+
37+
#ifndef MICROPY_HW_I2C0_SCL
38+
#define MICROPY_HW_I2C0_SCL (9)
39+
#define MICROPY_HW_I2C0_SDA (8)
40+
#endif
41+
42+
#ifndef MICROPY_HW_I2C1_SCL
43+
#define MICROPY_HW_I2C1_SCL (7)
44+
#define MICROPY_HW_I2C1_SDA (6)
45+
#endif
4046

4147
// SDA/SCL on even/odd pins, I2C0/I2C1 on even/odd pairs of pins.
4248
#define IS_VALID_SCL(i2c, pin) (((pin) & 1) == 1 && (((pin) & 2) >> 1) == (i2c))
@@ -52,8 +58,8 @@ typedef struct _machine_i2c_obj_t {
5258
} machine_i2c_obj_t;
5359

5460
STATIC machine_i2c_obj_t machine_i2c_obj[] = {
55-
{{&machine_hw_i2c_type}, i2c0, 0, DEFAULT_I2C0_SCL, DEFAULT_I2C0_SDA, 0},
56-
{{&machine_hw_i2c_type}, i2c1, 1, DEFAULT_I2C1_SCL, DEFAULT_I2C1_SDA, 0},
61+
{{&machine_hw_i2c_type}, i2c0, 0, MICROPY_HW_I2C0_SCL, MICROPY_HW_I2C0_SDA, 0},
62+
{{&machine_hw_i2c_type}, i2c1, 1, MICROPY_HW_I2C1_SCL, MICROPY_HW_I2C1_SDA, 0},
5763
};
5864

5965
STATIC void machine_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {

0 commit comments

Comments
 (0)