Skip to content

Commit 7e9e8b1

Browse files
authored
Merge pull request #9671 from dhalbert/esp-idf-new-i2c
Use new ESP-IDF I2C driver
2 parents e445047 + d62a984 commit 7e9e8b1

File tree

42 files changed

+283
-312
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+283
-312
lines changed

ports/atmel-samd/boards/feather_m4_express/mpconfigboard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#define IGNORE_PIN_PA27 1
4242
#define IGNORE_PIN_PB00 1
4343
#define IGNORE_PIN_PB04 1
44+
#define IGNORE_PIN_PB05 1
4445
#define IGNORE_PIN_PB06 1
4546
#define IGNORE_PIN_PB07 1
4647
#define IGNORE_PIN_PB30 1

ports/atmel-samd/boards/feather_m4_express/mpconfigboard.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ LONGINT_IMPL = MPZ
1212

1313
CIRCUITPY__EVE = 1
1414
CIRCUITPY_FLOPPYIO = 0
15-
CIRCUITPY_SYNTHIO = 0
1615
CIRCUITPY_JPEGIO = 0
16+
CIRCUITPY_SYNTHIO = 0
1717

1818
# We don't have room for the fonts for terminalio for certain languages,
1919
# so turn off terminalio, and if it's off and displayio is on,

ports/atmel-samd/boards/metro_m0_express/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ SPI_FLASH_FILESYSTEM = 1
1010
EXTERNAL_FLASH_DEVICES = "S25FL216K, GD25Q16C, W25Q16JVxQ"
1111
LONGINT_IMPL = MPZ
1212

13+
CIRCUITPY_CODEOP = 0
1314
CIRCUITPY_RAINBOWIO = 0

ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,5 @@
4848
#define IGNORE_PIN_PB04 1
4949
#define IGNORE_PIN_PB05 1
5050
#define IGNORE_PIN_PB23 1
51+
#define IGNORE_PIN_PB30 1
52+
#define IGNORE_PIN_PB31 1

ports/atmel-samd/boards/metro_m4_express/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ EXTERNAL_FLASH_DEVICES = "S25FL116K, S25FL216K, GD25Q16C, W25Q16JVxQ"
1111
LONGINT_IMPL = MPZ
1212

1313
CIRCUITPY__EVE = 1
14+
CIRCUITPY_CODEOP = 0
1415
CIRCUITPY_FLOPPYIO = 0
1516
CIRCUITPY_JPEGIO = 0
1617
CIRCUITPY_SYNTHIO = 0

ports/atmel-samd/boards/sparkfun_redboard_turbo/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ SPI_FLASH_FILESYSTEM = 1
1010
EXTERNAL_FLASH_DEVICES = "W25Q32FV"
1111
LONGINT_IMPL = MPZ
1212

13+
CIRCUITPY_CODEOP = 0
1314
CIRCUITPY_RAINBOWIO = 0

ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,43 @@
3131
#define DEFAULT_UART_BUS_RX (&pin_PA07)
3232
#define DEFAULT_UART_BUS_TX (&pin_PA06)
3333

34+
#define IGNORE_PIN_PA03 1
35+
#define IGNORE_PIN_PA04 1
36+
#define IGNORE_PIN_PA12 1
37+
#define IGNORE_PIN_PA13 1
38+
#define IGNORE_PIN_PA14 1
39+
#define IGNORE_PIN_PA15 1
40+
#define IGNORE_PIN_PA18 1
41+
#define IGNORE_PIN_PA20 1
42+
#define IGNORE_PIN_PA21 1
43+
#define IGNORE_PIN_PA22 1
44+
#define IGNORE_PIN_PA23 1
3445
// USB is always used internally so skip the pin objects for it.
3546
#define IGNORE_PIN_PA24 1
3647
#define IGNORE_PIN_PA25 1
48+
#define IGNORE_PIN_PA27 1
49+
#define IGNORE_PIN_PA28 1
50+
#define IGNORE_PIN_PA30 1
51+
#define IGNORE_PIN_PA31 1
52+
#define IGNORE_PIN_PB01 1
53+
#define IGNORE_PIN_PB02 1
54+
#define IGNORE_PIN_PB03 1
55+
#define IGNORE_PIN_PB04 1
56+
#define IGNORE_PIN_PB05 1
57+
#define IGNORE_PIN_PB06 1
58+
#define IGNORE_PIN_PB07 1
59+
#define IGNORE_PIN_PB08 1
60+
#define IGNORE_PIN_PB09 1
61+
#define IGNORE_PIN_PB10 1
62+
#define IGNORE_PIN_PB11 1
63+
#define IGNORE_PIN_PB12 1
64+
#define IGNORE_PIN_PB13 1
65+
#define IGNORE_PIN_PB14 1
66+
#define IGNORE_PIN_PB15 1
67+
#define IGNORE_PIN_PB16 1
68+
#define IGNORE_PIN_PB17 1
69+
#define IGNORE_PIN_PB22 1
70+
#define IGNORE_PIN_PB23 1
71+
#define IGNORE_PIN_PB30 1
72+
#define IGNORE_PIN_PB31 1
73+
#define IGNORE_PIN_PB00 1

ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ CHIP_FAMILY = samd21
99
SPI_FLASH_FILESYSTEM = 1
1010
EXTERNAL_FLASH_DEVICES = W25Q32BV
1111
LONGINT_IMPL = MPZ
12+
13+
CIRCUITPY_CODEOP = 0

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
5353
uint32_t sda_pinmux, scl_pinmux;
5454

5555
// Ensure the object starts in its deinit state.
56-
self->sda_pin = NO_PIN;
56+
common_hal_busio_i2c_mark_deinit(self);
57+
5758
Sercom *sercom = samd_i2c_get_sercom(scl, sda, &sercom_index, &sda_pinmux, &scl_pinmux);
5859
if (sercom == NULL) {
5960
raise_ValueError_invalid_pins();
@@ -108,21 +109,28 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
108109
mp_arg_error_invalid(MP_QSTR_frequency);
109110
}
110111

112+
if (i2c_m_sync_enable(&self->i2c_desc) != ERR_NONE) {
113+
common_hal_busio_i2c_deinit(self);
114+
mp_raise_OSError(MP_EIO);
115+
}
116+
111117
self->sda_pin = sda->number;
112118
self->scl_pin = scl->number;
113119
claim_pin(sda);
114120
claim_pin(scl);
115121

116-
if (i2c_m_sync_enable(&self->i2c_desc) != ERR_NONE) {
117-
common_hal_busio_i2c_deinit(self);
118-
mp_raise_OSError(MP_EIO);
119-
}
122+
// Prevent bulk sercom reset from resetting us. The finalizer will instead.
123+
never_reset_sercom(self->i2c_desc.device.hw);
120124
}
121125

122126
bool common_hal_busio_i2c_deinited(busio_i2c_obj_t *self) {
123127
return self->sda_pin == NO_PIN;
124128
}
125129

130+
void common_hal_busio_i2c_mark_deinit(busio_i2c_obj_t *self) {
131+
self->sda_pin = NO_PIN;
132+
}
133+
126134
void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) {
127135
if (common_hal_busio_i2c_deinited(self)) {
128136
return;
@@ -133,8 +141,7 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) {
133141

134142
reset_pin_number(self->sda_pin);
135143
reset_pin_number(self->scl_pin);
136-
self->sda_pin = NO_PIN;
137-
self->scl_pin = NO_PIN;
144+
common_hal_busio_i2c_mark_deinit(self);
138145
}
139146

140147
bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) {
@@ -236,8 +243,6 @@ uint8_t common_hal_busio_i2c_write_read(busio_i2c_obj_t *self, uint16_t addr,
236243
}
237244

238245
void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) {
239-
never_reset_sercom(self->i2c_desc.device.hw);
240-
241246
never_reset_pin_number(self->scl_pin);
242247
never_reset_pin_number(self->sda_pin);
243248
}

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,14 @@ void reset_i2c(void) {
4747

4848
void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
4949
const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, uint32_t frequency, uint32_t timeout) {
50+
51+
// Ensure the object starts in its deinit state.
52+
common_hal_busio_i2c_mark_deinit(self);
53+
5054
size_t instance_index = NUM_I2C;
5155
uint8_t scl_alt = 0;
5256
uint8_t sda_alt = 0;
57+
5358
for (scl_alt = 0; scl_alt < 6; scl_alt++) {
5459
if (scl->functions[scl_alt].type != PIN_FUNCTION_I2C ||
5560
i2c_in_use[scl->functions[scl_alt].index] ||
@@ -90,17 +95,19 @@ bool common_hal_busio_i2c_deinited(busio_i2c_obj_t *self) {
9095
return self->sda_pin == NULL;
9196
}
9297

98+
void common_hal_busio_i2c_mark_deinit(busio_i2c_obj_t *self) {
99+
self->sda_pin = NULL;
100+
}
101+
93102
void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) {
94103
if (common_hal_busio_i2c_deinited(self)) {
95104
return;
96105
}
97-
never_reset_i2c[self->index] = false;
98106
i2c_in_use[self->index] = false;
99107

100108
common_hal_reset_pin(self->sda_pin);
101109
common_hal_reset_pin(self->scl_pin);
102-
self->sda_pin = NULL;
103-
self->scl_pin = NULL;
110+
common_hal_busio_i2c_mark_deinit(self);
104111
}
105112

106113
bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) {

0 commit comments

Comments
 (0)