Skip to content

Commit d62a984

Browse files
committed
broadcom: restore reset_i2c() and special handling of two I2C ports
1 parent a023f92 commit d62a984

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,28 @@ static BSC0_Type *i2c[NUM_I2C] = {BSC0, BSC1, NULL, BSC3, BSC4, BSC5, BSC6, NULL
2323
static BSC0_Type *i2c[NUM_I2C] = {BSC0, BSC1, NULL};
2424
#endif
2525

26+
static bool never_reset_i2c[NUM_I2C];
2627
static bool i2c_in_use[NUM_I2C];
2728

29+
void reset_i2c(void) {
30+
// BSC2 is dedicated to the first HDMI output.
31+
never_reset_i2c[2] = true;
32+
i2c_in_use[2] = true;
33+
#if BCM_VERSION == 2711
34+
// BSC7 is dedicated to the second HDMI output.
35+
never_reset_i2c[7] = true;
36+
i2c_in_use[7] = true;
37+
#endif
38+
for (size_t i = 0; i < NUM_I2C; i++) {
39+
if (never_reset_i2c[i]) {
40+
continue;
41+
}
42+
i2c_in_use[i] = false;
43+
i2c[i]->C_b.I2CEN = false;
44+
COMPLETE_MEMORY_READS;
45+
}
46+
}
47+
2848
void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
2949
const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, uint32_t frequency, uint32_t timeout) {
3050

@@ -233,6 +253,8 @@ uint8_t common_hal_busio_i2c_write_read(busio_i2c_obj_t *self, uint16_t addr,
233253
}
234254

235255
void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) {
256+
never_reset_i2c[self->index] = true;
257+
236258
common_hal_never_reset_pin(self->scl_pin);
237259
common_hal_never_reset_pin(self->sda_pin);
238260
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ typedef struct {
2323
bool finish_write;
2424
uint8_t last_write_data;
2525
} busio_i2c_obj_t;
26+
27+
void reset_i2c(void);

ports/broadcom/supervisor/port.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "genhdr/mpversion.h"
1414

1515
#include "common-hal/rtc/RTC.h"
16+
#include "common-hal/busio/I2C.h"
1617
#include "common-hal/busio/SPI.h"
1718
#include "common-hal/busio/UART.h"
1819

@@ -65,6 +66,7 @@ safe_mode_t port_init(void) {
6566

6667
void reset_port(void) {
6768
#if CIRCUITPY_BUSIO
69+
reset_i2c();
6870
reset_spi();
6971
reset_uart();
7072
#endif

0 commit comments

Comments
 (0)