Skip to content

Commit 6ea8d8a

Browse files
authored
Merge pull request #2498 from dhalbert/optional-i2c-pullup-checking
Make requiring I2C pullups be optional
2 parents 8708d3d + 360c876 commit 6ea8d8a

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
7676
mp_raise_ValueError(translate("Invalid pins"));
7777
}
7878

79+
#if CIRCUITPY_REQUIRE_I2C_PULLUPS
7980
// Test that the pins are in a high state. (Hopefully indicating they are pulled up.)
8081
gpio_set_pin_function(sda->number, GPIO_PIN_FUNCTION_OFF);
8182
gpio_set_pin_function(scl->number, GPIO_PIN_FUNCTION_OFF);
@@ -98,6 +99,8 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
9899
reset_pin_number(scl->number);
99100
mp_raise_RuntimeError(translate("SDA or SCL needs a pull up"));
100101
}
102+
#endif
103+
101104
gpio_set_pin_function(sda->number, sda_pinmux);
102105
gpio_set_pin_function(scl->number, scl_pinmux);
103106

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,13 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
9898

9999
LPI2C_MasterInit(self->i2c, &config, I2C_CLOCK_FREQ);
100100

101+
#if CIRCUITPY_REQUIRE_I2C_PULLUPS
101102
// if (!gpio_get_pin_level(sda->number) || !gpio_get_pin_level(scl->number)) {
102103
// reset_pin_number(sda->number);
103104
// reset_pin_number(scl->number);
104105
// mp_raise_RuntimeError(translate("SDA or SCL needs a pull up"));
105106
// }
107+
#endif
106108

107109
claim_pin(self->sda_pin->pin);
108110
claim_pin(self->scl_pin->pin);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t *
115115
mp_raise_ValueError(translate("All I2C peripherals are in use"));
116116
}
117117

118+
#if CIRCUITPY_REQUIRE_I2C_PULLUPS
118119
// Test that the pins are in a high state. (Hopefully indicating they are pulled up.)
119120
nrf_gpio_cfg_input(scl->number, NRF_GPIO_PIN_PULLDOWN);
120121
nrf_gpio_cfg_input(sda->number, NRF_GPIO_PIN_PULLDOWN);
@@ -132,6 +133,7 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t *
132133
reset_pin_number(scl->number);
133134
mp_raise_RuntimeError(translate("SDA or SCL needs a pull up"));
134135
}
136+
#endif
135137

136138
nrfx_twim_config_t config = NRFX_TWIM_DEFAULT_CONFIG(scl->number, sda->number);
137139

py/circuitpy_mpconfig.mk

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,13 @@ CIRCUITPY_BITBANG_APA102 = 0
310310
endif
311311
CFLAGS += -DCIRCUITPY_BITBANG_APA102=$(CIRCUITPY_BITBANG_APA102)
312312

313+
# Should busio.I2C() check for pullups?
314+
# Some boards in combination with certain peripherals may not want this.
315+
ifndef CIRCUITPY_REQUIRE_I2C_PULLUPS
316+
CIRCUITPY_REQUIRE_I2C_PULLUPS = 1
317+
endif
318+
CFLAGS += -DCIRCUITPY_REQUIRE_I2C_PULLUPS=$(CIRCUITPY_REQUIRE_I2C_PULLUPS)
319+
313320
# REPL over BLE
314321
ifndef CIRCUITPY_SERIAL_BLE
315322
CIRCUITPY_SERIAL_BLE = 0

0 commit comments

Comments
 (0)