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) {

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t *scl,
1818
const mcu_pin_obj_t *sda, uint32_t frequency, uint32_t timeout) {
19+
20+
// Ensure the object starts in its deinit state.
21+
common_hal_busio_i2c_mark_deinit(self);
22+
1923
if (frequency != I2C_SPEED_STANDARD && frequency != I2C_SPEED_FAST) {
2024
mp_arg_error_invalid(MP_QSTR_frequency);
2125
}
@@ -44,12 +48,18 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) {
4448

4549
reset_pin_number(self->scl_pin->number);
4650
reset_pin_number(self->sda_pin->number);
51+
52+
common_hal_busio_i2c_mark_deinit(self);
4753
}
4854

4955
bool common_hal_busio_i2c_deinited(busio_i2c_obj_t *self) {
5056
return self->i2c_dev == NULL;
5157
}
5258

59+
void common_hal_busio_i2c_mark_deinit(busio_i2c_obj_t *self) {
60+
self->i2c_dev = NULL;
61+
}
62+
5363
bool common_hal_busio_i2c_try_lock(busio_i2c_obj_t *self) {
5464
if (common_hal_busio_i2c_deinited(self)) {
5565
return false;

ports/espressif/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.16)
55
set(ENV{IDF_PATH} ${CMAKE_SOURCE_DIR}/esp-idf)
66

77
# The component list here determines what options we get in menuconfig and what the ninja file can build.
8-
set(COMPONENTS bt driver esp_driver_dac esp_driver_gpio esp_driver_gptimer esp_driver_i2s esp_driver_ledc esp_driver_pcnt esp_driver_rmt esp_driver_spi esp_driver_tsens esp_driver_uart esp-tls esp_adc_cal esp_event esp_netif esp_psram esp_wifi esptool_py freertos log lwip main mbedtls mdns soc ulp usb wpa_supplicant esp-camera esp_lcd vfs esp_vfs_console sdmmc)
8+
set(COMPONENTS bt driver esp_driver_dac esp_driver_gpio esp_driver_gptimer esp_driver_i2c esp_driver_i2s esp_driver_ledc esp_driver_pcnt esp_driver_rmt esp_driver_spi esp_driver_tsens esp_driver_uart esp-tls esp_adc_cal esp_event esp_netif esp_psram esp_wifi esptool_py freertos log lwip main mbedtls mdns soc ulp usb wpa_supplicant esp-camera esp_lcd vfs esp_vfs_console sdmmc)
99
set(EXTRA_COMPONENT_DIRS "esp-protocols/components/mdns" "esp-camera")
1010

1111
include($ENV{IDF_PATH}/tools/cmake/project.cmake)

ports/espressif/Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ INC += \
6565
-isystem esp-idf/components/bt/host/nimble/nimble/porting/nimble/include \
6666
-isystem esp-idf/components/bt/host/nimble/nimble/porting/npl/freertos/include \
6767
-isystem esp-idf/components/bt/host/nimble/port/include \
68-
-isystem esp-idf/components/driver/i2c/include \
6968
-isystem esp-idf/components/driver/touch_sensor/include \
7069
-isystem esp-idf/components/driver/touch_sensor/$(IDF_TARGET)/include \
7170
-isystem esp-idf/components/driver/twai/include \
@@ -396,7 +395,6 @@ SRC_C += \
396395
boards/$(BOARD)/board.c \
397396
boards/$(BOARD)/pins.c \
398397
shared/netutils/netutils.c \
399-
peripherals/i2c.c \
400398
peripherals/$(IDF_TARGET)/pins.c
401399

402400
ifeq ($(CIRCUITPY_SSL),1)
@@ -618,7 +616,7 @@ ifeq ($(IDF_TARGET),esp32)
618616
BINARY_BLOBS += esp-idf/components/esp_phy/lib/$(IDF_TARGET)/librtc.a
619617
endif
620618

621-
ESP_IDF_COMPONENTS_LINK = $(IDF_TARGET_ARCH) $(CHIP_COMPONENTS) app_update bootloader_support driver esp_driver_gpio esp_driver_gptimer esp_driver_ledc esp_driver_spi esp_driver_uart efuse esp_adc esp_app_format esp_common esp_event esp_hw_support esp_mm esp_partition esp_pm esp_ringbuf esp_rom esp_system esp_timer freertos hal heap log newlib nvs_flash pthread soc spi_flash vfs esp_vfs_console
619+
ESP_IDF_COMPONENTS_LINK = $(IDF_TARGET_ARCH) $(CHIP_COMPONENTS) app_update bootloader_support driver esp_driver_gpio esp_driver_gptimer esp_driver_i2c esp_driver_ledc esp_driver_spi esp_driver_uart efuse esp_adc esp_app_format esp_common esp_event esp_hw_support esp_mm esp_partition esp_pm esp_ringbuf esp_rom esp_system esp_timer freertos hal heap log newlib nvs_flash pthread soc spi_flash vfs esp_vfs_console
622620
ifneq ($(CIRCUITPY_WIFI),0)
623621
ESP_IDF_COMPONENTS_LINK += esp_coex esp_netif esp-tls esp_wifi lwip mbedtls mdns wpa_supplicant esp_phy
624622
endif

ports/espressif/boards/adafruit_esp32s3_camera/board.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#include "esp_log.h"
1818
#include "esp_err.h"
19-
#include "driver/i2c.h"
2019

2120

2221
#define DELAY 0x80

ports/espressif/boards/seeed_xiao_esp32_s3_sense/board.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
//
55
// SPDX-License-Identifier: MIT
66

7-
#include "supervisor/board.h"
87
#include "mpconfigboard.h"
9-
#include "esp_log.h"
10-
#include "esp_err.h"
11-
#include "driver/i2c.h"
128

139
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.

0 commit comments

Comments
 (0)