Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ports/atmel-samd/boards/feather_m4_express/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#define IGNORE_PIN_PA27 1
#define IGNORE_PIN_PB00 1
#define IGNORE_PIN_PB04 1
#define IGNORE_PIN_PB05 1
#define IGNORE_PIN_PB06 1
#define IGNORE_PIN_PB07 1
#define IGNORE_PIN_PB30 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ LONGINT_IMPL = MPZ

CIRCUITPY__EVE = 1
CIRCUITPY_FLOPPYIO = 0
CIRCUITPY_SYNTHIO = 0
CIRCUITPY_JPEGIO = 0
CIRCUITPY_SYNTHIO = 0

# We don't have room for the fonts for terminalio for certain languages,
# so turn off terminalio, and if it's off and displayio is on,
Expand Down
1 change: 1 addition & 0 deletions ports/atmel-samd/boards/metro_m0_express/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ SPI_FLASH_FILESYSTEM = 1
EXTERNAL_FLASH_DEVICES = "S25FL216K, GD25Q16C, W25Q16JVxQ"
LONGINT_IMPL = MPZ

CIRCUITPY_CODEOP = 0
CIRCUITPY_RAINBOWIO = 0
2 changes: 2 additions & 0 deletions ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@
#define IGNORE_PIN_PB04 1
#define IGNORE_PIN_PB05 1
#define IGNORE_PIN_PB23 1
#define IGNORE_PIN_PB30 1
#define IGNORE_PIN_PB31 1
1 change: 1 addition & 0 deletions ports/atmel-samd/boards/metro_m4_express/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ EXTERNAL_FLASH_DEVICES = "S25FL116K, S25FL216K, GD25Q16C, W25Q16JVxQ"
LONGINT_IMPL = MPZ

CIRCUITPY__EVE = 1
CIRCUITPY_CODEOP = 0
CIRCUITPY_FLOPPYIO = 0
CIRCUITPY_JPEGIO = 0
CIRCUITPY_SYNTHIO = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ SPI_FLASH_FILESYSTEM = 1
EXTERNAL_FLASH_DEVICES = "W25Q32FV"
LONGINT_IMPL = MPZ

CIRCUITPY_CODEOP = 0
CIRCUITPY_RAINBOWIO = 0
37 changes: 37 additions & 0 deletions ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,43 @@
#define DEFAULT_UART_BUS_RX (&pin_PA07)
#define DEFAULT_UART_BUS_TX (&pin_PA06)

#define IGNORE_PIN_PA03 1
#define IGNORE_PIN_PA04 1
#define IGNORE_PIN_PA12 1
#define IGNORE_PIN_PA13 1
#define IGNORE_PIN_PA14 1
#define IGNORE_PIN_PA15 1
#define IGNORE_PIN_PA18 1
#define IGNORE_PIN_PA20 1
#define IGNORE_PIN_PA21 1
#define IGNORE_PIN_PA22 1
#define IGNORE_PIN_PA23 1
// USB is always used internally so skip the pin objects for it.
#define IGNORE_PIN_PA24 1
#define IGNORE_PIN_PA25 1
#define IGNORE_PIN_PA27 1
#define IGNORE_PIN_PA28 1
#define IGNORE_PIN_PA30 1
#define IGNORE_PIN_PA31 1
#define IGNORE_PIN_PB01 1
#define IGNORE_PIN_PB02 1
#define IGNORE_PIN_PB03 1
#define IGNORE_PIN_PB04 1
#define IGNORE_PIN_PB05 1
#define IGNORE_PIN_PB06 1
#define IGNORE_PIN_PB07 1
#define IGNORE_PIN_PB08 1
#define IGNORE_PIN_PB09 1
#define IGNORE_PIN_PB10 1
#define IGNORE_PIN_PB11 1
#define IGNORE_PIN_PB12 1
#define IGNORE_PIN_PB13 1
#define IGNORE_PIN_PB14 1
#define IGNORE_PIN_PB15 1
#define IGNORE_PIN_PB16 1
#define IGNORE_PIN_PB17 1
#define IGNORE_PIN_PB22 1
#define IGNORE_PIN_PB23 1
#define IGNORE_PIN_PB30 1
#define IGNORE_PIN_PB31 1
#define IGNORE_PIN_PB00 1
2 changes: 2 additions & 0 deletions ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ CHIP_FAMILY = samd21
SPI_FLASH_FILESYSTEM = 1
EXTERNAL_FLASH_DEVICES = W25Q32BV
LONGINT_IMPL = MPZ

CIRCUITPY_CODEOP = 0
23 changes: 14 additions & 9 deletions ports/atmel-samd/common-hal/busio/I2C.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
uint32_t sda_pinmux, scl_pinmux;

// Ensure the object starts in its deinit state.
self->sda_pin = NO_PIN;
common_hal_busio_i2c_mark_deinit(self);

Sercom *sercom = samd_i2c_get_sercom(scl, sda, &sercom_index, &sda_pinmux, &scl_pinmux);
if (sercom == NULL) {
raise_ValueError_invalid_pins();
Expand Down Expand Up @@ -108,21 +109,28 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
mp_arg_error_invalid(MP_QSTR_frequency);
}

if (i2c_m_sync_enable(&self->i2c_desc) != ERR_NONE) {
common_hal_busio_i2c_deinit(self);
mp_raise_OSError(MP_EIO);
}

self->sda_pin = sda->number;
self->scl_pin = scl->number;
claim_pin(sda);
claim_pin(scl);

if (i2c_m_sync_enable(&self->i2c_desc) != ERR_NONE) {
common_hal_busio_i2c_deinit(self);
mp_raise_OSError(MP_EIO);
}
// Prevent bulk sercom reset from resetting us. The finalizer will instead.
never_reset_sercom(self->i2c_desc.device.hw);
}

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

void common_hal_busio_i2c_mark_deinit(busio_i2c_obj_t *self) {
self->sda_pin = NO_PIN;
}

void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) {
if (common_hal_busio_i2c_deinited(self)) {
return;
Expand All @@ -133,8 +141,7 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) {

reset_pin_number(self->sda_pin);
reset_pin_number(self->scl_pin);
self->sda_pin = NO_PIN;
self->scl_pin = NO_PIN;
common_hal_busio_i2c_mark_deinit(self);
}

bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) {
Expand Down Expand Up @@ -236,8 +243,6 @@ uint8_t common_hal_busio_i2c_write_read(busio_i2c_obj_t *self, uint16_t addr,
}

void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) {
never_reset_sercom(self->i2c_desc.device.hw);

never_reset_pin_number(self->scl_pin);
never_reset_pin_number(self->sda_pin);
}
35 changes: 10 additions & 25 deletions ports/broadcom/common-hal/busio/I2C.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,18 @@ static BSC0_Type *i2c[NUM_I2C] = {BSC0, BSC1, NULL, BSC3, BSC4, BSC5, BSC6, NULL
static BSC0_Type *i2c[NUM_I2C] = {BSC0, BSC1, NULL};
#endif

static bool never_reset_i2c[NUM_I2C];
static bool i2c_in_use[NUM_I2C];

void reset_i2c(void) {
// BSC2 is dedicated to the first HDMI output.
never_reset_i2c[2] = true;
i2c_in_use[2] = true;
#if BCM_VERSION == 2711
// BSC7 is dedicated to the second HDMI output.
never_reset_i2c[7] = true;
i2c_in_use[7] = true;
#endif
for (size_t i = 0; i < NUM_I2C; i++) {
if (never_reset_i2c[i]) {
continue;
}
i2c_in_use[i] = false;
i2c[i]->C_b.I2CEN = false;
COMPLETE_MEMORY_READS;
}
}

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

// Ensure the object starts in its deinit state.
common_hal_busio_i2c_mark_deinit(self);

size_t instance_index = NUM_I2C;
uint8_t scl_alt = 0;
uint8_t sda_alt = 0;

for (scl_alt = 0; scl_alt < 6; scl_alt++) {
if (scl->functions[scl_alt].type != PIN_FUNCTION_I2C ||
i2c_in_use[scl->functions[scl_alt].index] ||
Expand Down Expand Up @@ -90,17 +75,19 @@ bool common_hal_busio_i2c_deinited(busio_i2c_obj_t *self) {
return self->sda_pin == NULL;
}

void common_hal_busio_i2c_mark_deinit(busio_i2c_obj_t *self) {
self->sda_pin = NULL;
}

void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) {
if (common_hal_busio_i2c_deinited(self)) {
return;
}
never_reset_i2c[self->index] = false;
i2c_in_use[self->index] = false;

common_hal_reset_pin(self->sda_pin);
common_hal_reset_pin(self->scl_pin);
self->sda_pin = NULL;
self->scl_pin = NULL;
common_hal_busio_i2c_mark_deinit(self);
}

bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) {
Expand Down Expand Up @@ -246,8 +233,6 @@ uint8_t common_hal_busio_i2c_write_read(busio_i2c_obj_t *self, uint16_t addr,
}

void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) {
never_reset_i2c[self->index] = true;

common_hal_never_reset_pin(self->scl_pin);
common_hal_never_reset_pin(self->sda_pin);
}
2 changes: 0 additions & 2 deletions ports/broadcom/common-hal/busio/I2C.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,3 @@ typedef struct {
bool finish_write;
uint8_t last_write_data;
} busio_i2c_obj_t;

void reset_i2c(void);
2 changes: 0 additions & 2 deletions ports/broadcom/supervisor/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "genhdr/mpversion.h"

#include "common-hal/rtc/RTC.h"
#include "common-hal/busio/I2C.h"
#include "common-hal/busio/SPI.h"
#include "common-hal/busio/UART.h"

Expand Down Expand Up @@ -66,7 +65,6 @@ safe_mode_t port_init(void) {

void reset_port(void) {
#if CIRCUITPY_BUSIO
reset_i2c();
reset_spi();
reset_uart();
#endif
Expand Down
10 changes: 10 additions & 0 deletions ports/cxd56/common-hal/busio/I2C.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

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

// Ensure the object starts in its deinit state.
common_hal_busio_i2c_mark_deinit(self);

if (frequency != I2C_SPEED_STANDARD && frequency != I2C_SPEED_FAST) {
mp_arg_error_invalid(MP_QSTR_frequency);
}
Expand Down Expand Up @@ -44,12 +48,18 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) {

reset_pin_number(self->scl_pin->number);
reset_pin_number(self->sda_pin->number);

common_hal_busio_i2c_mark_deinit(self);
}

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

void common_hal_busio_i2c_mark_deinit(busio_i2c_obj_t *self) {
self->i2c_dev = NULL;
}

bool common_hal_busio_i2c_try_lock(busio_i2c_obj_t *self) {
if (common_hal_busio_i2c_deinited(self)) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion ports/espressif/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.16)
set(ENV{IDF_PATH} ${CMAKE_SOURCE_DIR}/esp-idf)

# The component list here determines what options we get in menuconfig and what the ninja file can build.
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)
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)
set(EXTRA_COMPONENT_DIRS "esp-protocols/components/mdns" "esp-camera")

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
Expand Down
4 changes: 1 addition & 3 deletions ports/espressif/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ INC += \
-isystem esp-idf/components/bt/host/nimble/nimble/porting/nimble/include \
-isystem esp-idf/components/bt/host/nimble/nimble/porting/npl/freertos/include \
-isystem esp-idf/components/bt/host/nimble/port/include \
-isystem esp-idf/components/driver/i2c/include \
-isystem esp-idf/components/driver/touch_sensor/include \
-isystem esp-idf/components/driver/touch_sensor/$(IDF_TARGET)/include \
-isystem esp-idf/components/driver/twai/include \
Expand Down Expand Up @@ -396,7 +395,6 @@ SRC_C += \
boards/$(BOARD)/board.c \
boards/$(BOARD)/pins.c \
shared/netutils/netutils.c \
peripherals/i2c.c \
peripherals/$(IDF_TARGET)/pins.c

ifeq ($(CIRCUITPY_SSL),1)
Expand Down Expand Up @@ -618,7 +616,7 @@ ifeq ($(IDF_TARGET),esp32)
BINARY_BLOBS += esp-idf/components/esp_phy/lib/$(IDF_TARGET)/librtc.a
endif

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
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
ifneq ($(CIRCUITPY_WIFI),0)
ESP_IDF_COMPONENTS_LINK += esp_coex esp_netif esp-tls esp_wifi lwip mbedtls mdns wpa_supplicant esp_phy
endif
Expand Down
1 change: 0 additions & 1 deletion ports/espressif/boards/adafruit_esp32s3_camera/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include "esp_log.h"
#include "esp_err.h"
#include "driver/i2c.h"


#define DELAY 0x80
Expand Down
4 changes: 0 additions & 4 deletions ports/espressif/boards/seeed_xiao_esp32_s3_sense/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
//
// SPDX-License-Identifier: MIT

#include "supervisor/board.h"
#include "mpconfigboard.h"
#include "esp_log.h"
#include "esp_err.h"
#include "driver/i2c.h"

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