Merge pull request #2498 from dhalbert/optional-i2c-pullup-checking
Make requiring I2C pullups be optional
This commit is contained in:
commit
6ea8d8a6c2
@ -76,6 +76,7 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
|
|||||||
mp_raise_ValueError(translate("Invalid pins"));
|
mp_raise_ValueError(translate("Invalid pins"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if CIRCUITPY_REQUIRE_I2C_PULLUPS
|
||||||
// Test that the pins are in a high state. (Hopefully indicating they are pulled up.)
|
// Test that the pins are in a high state. (Hopefully indicating they are pulled up.)
|
||||||
gpio_set_pin_function(sda->number, GPIO_PIN_FUNCTION_OFF);
|
gpio_set_pin_function(sda->number, GPIO_PIN_FUNCTION_OFF);
|
||||||
gpio_set_pin_function(scl->number, GPIO_PIN_FUNCTION_OFF);
|
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,
|
|||||||
reset_pin_number(scl->number);
|
reset_pin_number(scl->number);
|
||||||
mp_raise_RuntimeError(translate("SDA or SCL needs a pull up"));
|
mp_raise_RuntimeError(translate("SDA or SCL needs a pull up"));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
gpio_set_pin_function(sda->number, sda_pinmux);
|
gpio_set_pin_function(sda->number, sda_pinmux);
|
||||||
gpio_set_pin_function(scl->number, scl_pinmux);
|
gpio_set_pin_function(scl->number, scl_pinmux);
|
||||||
|
|
||||||
|
@ -98,11 +98,13 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
|
|||||||
|
|
||||||
LPI2C_MasterInit(self->i2c, &config, I2C_CLOCK_FREQ);
|
LPI2C_MasterInit(self->i2c, &config, I2C_CLOCK_FREQ);
|
||||||
|
|
||||||
|
#if CIRCUITPY_REQUIRE_I2C_PULLUPS
|
||||||
// if (!gpio_get_pin_level(sda->number) || !gpio_get_pin_level(scl->number)) {
|
// if (!gpio_get_pin_level(sda->number) || !gpio_get_pin_level(scl->number)) {
|
||||||
// reset_pin_number(sda->number);
|
// reset_pin_number(sda->number);
|
||||||
// reset_pin_number(scl->number);
|
// reset_pin_number(scl->number);
|
||||||
// mp_raise_RuntimeError(translate("SDA or SCL needs a pull up"));
|
// mp_raise_RuntimeError(translate("SDA or SCL needs a pull up"));
|
||||||
// }
|
// }
|
||||||
|
#endif
|
||||||
|
|
||||||
claim_pin(self->sda_pin->pin);
|
claim_pin(self->sda_pin->pin);
|
||||||
claim_pin(self->scl_pin->pin);
|
claim_pin(self->scl_pin->pin);
|
||||||
|
@ -115,6 +115,7 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t *
|
|||||||
mp_raise_ValueError(translate("All I2C peripherals are in use"));
|
mp_raise_ValueError(translate("All I2C peripherals are in use"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if CIRCUITPY_REQUIRE_I2C_PULLUPS
|
||||||
// Test that the pins are in a high state. (Hopefully indicating they are pulled up.)
|
// Test that the pins are in a high state. (Hopefully indicating they are pulled up.)
|
||||||
nrf_gpio_cfg_input(scl->number, NRF_GPIO_PIN_PULLDOWN);
|
nrf_gpio_cfg_input(scl->number, NRF_GPIO_PIN_PULLDOWN);
|
||||||
nrf_gpio_cfg_input(sda->number, NRF_GPIO_PIN_PULLDOWN);
|
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 *
|
|||||||
reset_pin_number(scl->number);
|
reset_pin_number(scl->number);
|
||||||
mp_raise_RuntimeError(translate("SDA or SCL needs a pull up"));
|
mp_raise_RuntimeError(translate("SDA or SCL needs a pull up"));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
nrfx_twim_config_t config = NRFX_TWIM_DEFAULT_CONFIG(scl->number, sda->number);
|
nrfx_twim_config_t config = NRFX_TWIM_DEFAULT_CONFIG(scl->number, sda->number);
|
||||||
|
|
||||||
|
@ -310,6 +310,13 @@ CIRCUITPY_BITBANG_APA102 = 0
|
|||||||
endif
|
endif
|
||||||
CFLAGS += -DCIRCUITPY_BITBANG_APA102=$(CIRCUITPY_BITBANG_APA102)
|
CFLAGS += -DCIRCUITPY_BITBANG_APA102=$(CIRCUITPY_BITBANG_APA102)
|
||||||
|
|
||||||
|
# Should busio.I2C() check for pullups?
|
||||||
|
# Some boards in combination with certain peripherals may not want this.
|
||||||
|
ifndef CIRCUITPY_REQUIRE_I2C_PULLUPS
|
||||||
|
CIRCUITPY_REQUIRE_I2C_PULLUPS = 1
|
||||||
|
endif
|
||||||
|
CFLAGS += -DCIRCUITPY_REQUIRE_I2C_PULLUPS=$(CIRCUITPY_REQUIRE_I2C_PULLUPS)
|
||||||
|
|
||||||
# REPL over BLE
|
# REPL over BLE
|
||||||
ifndef CIRCUITPY_SERIAL_BLE
|
ifndef CIRCUITPY_SERIAL_BLE
|
||||||
CIRCUITPY_SERIAL_BLE = 0
|
CIRCUITPY_SERIAL_BLE = 0
|
||||||
|
Loading…
Reference in New Issue
Block a user