Skip to content

Commit 1f6ec28

Browse files
committed
Add config options to enable onboard i2c pull-ups
Adds CIRCUITPY_BUSIO_I2C_INTERNAL_PULLUPS config option to enable/use internal i2c pull-ups. Adds CIRCUITPY_BUSIO_I2C_INTERNAL_PULLUPS_AVAILABLE to indicate availability of internal pull-up resistors.
1 parent b8d4f96 commit 1f6ec28

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

ports/raspberrypi/boards/pimoroni_keybow2040/mpconfigboard.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,7 @@
3939
#define IGNORE_PIN_GPIO27 1
4040
#define IGNORE_PIN_GPIO28 1
4141
#define IGNORE_PIN_GPIO29 1
42+
43+
#undef CIRCUITPY_REQUIRE_I2C_PULLUPS
44+
#define CIRCUITPY_REQUIRE_I2C_PULLUPS (0)
45+
#define CIRCUITPY_BUSIO_I2C_INTERNAL_PULLUPS (1)

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,10 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
108108
// set up as GPIO by the bitbangio.I2C object.
109109
//
110110
// Sets pins to open drain, high, and input.
111+
#ifndef CIRCUITPY_BUSIO_I2C_INTERNAL_PULLUPS
111112
shared_module_bitbangio_i2c_construct(&self->bitbangio_i2c, scl, sda,
112-
frequency, timeout);
113+
frequency, timeout);
114+
#endif
113115

114116
self->baudrate = i2c_init(self->peripheral, frequency);
115117

@@ -120,6 +122,11 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
120122

121123
gpio_set_function(self->scl_pin, GPIO_FUNC_I2C);
122124
gpio_set_function(self->sda_pin, GPIO_FUNC_I2C);
125+
126+
#if CIRCUITPY_BUSIO_I2C_INTERNAL_PULLUPS
127+
gpio_set_pulls(self->scl_pin, true, false);
128+
gpio_set_pulls(self->sda_pin, true, false);
129+
#endif
123130
}
124131

125132
bool common_hal_busio_i2c_deinited(busio_i2c_obj_t *self) {
@@ -163,6 +170,8 @@ void common_hal_busio_i2c_unlock(busio_i2c_obj_t *self) {
163170

164171
uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr,
165172
const uint8_t *data, size_t len, bool transmit_stop_bit) {
173+
174+
#ifndef CIRCUITPY_BUSIO_I2C_INTERNAL_PULLUPS
166175
if (len == 0) {
167176
// The RP2040 I2C peripheral will not perform 0 byte writes.
168177
// So use bitbangio.I2C to do the write.
@@ -184,6 +193,7 @@ uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr,
184193

185194
return status;
186195
}
196+
#endif
187197

188198
int result = i2c_write_timeout_us(self->peripheral, addr, data, len, !transmit_stop_bit, BUS_TIMEOUT_US);
189199
if (result == len) {

ports/raspberrypi/mpconfigport.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
#define CIRCUITPY_DEFAULT_STACK_SIZE (24 * 1024)
3838

39+
#define CIRCUITPY_BUSIO_I2C_INTERNAL_PULLUPS_AVAILABLE (1)
40+
3941
#define MICROPY_USE_INTERNAL_PRINTF (1)
4042

4143
#define CIRCUITPY_PROCESSOR_COUNT (2)

0 commit comments

Comments
 (0)