Skip to content

Commit da65146

Browse files
committed
working on being able to share the SPI Bus
1 parent 22d82d6 commit da65146

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

builder/rp2.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ def compile(): # NOQA
150150

151151
os.remove(os.path.join('build', f))
152152

153-
import shutil
154-
155153
if board_variant:
156154
src = f'lib/micropython/ports/rp2/build-{board}_{board_variant}/firmware.uf2'
157155
dst = f'build/lvgl_micropy_{board}_{board_variant}.uf2'

builder/stm32.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ def compile(): # NOQA
121121

122122
os.remove(os.path.join('build', f))
123123

124-
import shutil
125-
126124
if board_variant:
127125
src = f'lib/micropython/ports/stm32/build-{board}_{board_variant}/firmware.dfu'
128126
dst = f'build/lvgl_micropy_{board}_{board_variant}.dfu'

micropy_updates/rp2/machine_spi.c

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,19 +127,23 @@ typedef struct _machine_hw_spi_obj_t {
127127

128128
machine_hw_spi_bus_obj_t rp2_machine_spi_bus_obj[] = {
129129
{
130-
0,
131-
mp_obj_new_int(MICROPY_HW_SPI0_SCK),
132-
mp_obj_new_int(MICROPY_HW_SPI0_MOSI),
133-
mp_obj_new_int(MICROPY_HW_SPI0_MISO),
134-
0, 0, (const void *)spi0
130+
.host = 0,
131+
.sck = MP_OBJ_NULL,
132+
.mosi = MP_OBJ_NULL,
133+
.miso = MP_OBJ_NULL,
134+
.active_devices = 0,
135+
.state = 0,
136+
.user_data = (const void *)spi0
135137
},
136138
{
137-
1,
138-
mp_obj_new_int(MICROPY_HW_SPI1_SCK),
139-
mp_obj_new_int(MICROPY_HW_SPI1_MOSI),
140-
mp_obj_new_int(MICROPY_HW_SPI1_MISO),
141-
0, 0, (const void *)spi1
142-
},
139+
.host = 1,
140+
.sck = MP_OBJ_NULL,
141+
.mosi = MP_OBJ_NULL,
142+
.miso = MP_OBJ_NULL,
143+
.active_devices = 0,
144+
.state = 0,
145+
.user_data = (const void *)spi1
146+
}
143147
};
144148

145149

@@ -171,8 +175,20 @@ mp_obj_t machine_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
171175
machine_hw_spi_obj_t *self = m_new_obj(machine_hw_spi_obj_t);
172176
self->base.type = &machine_spi_type;
173177

174-
self->spi_bus = (machine_hw_spi_bus_obj_t *)&rp2_machine_spi_bus_obj[spi_id];
178+
machine_hw_spi_bus_obj_t *spi_bus = &rp2_machine_spi_bus_obj[spi_id];
179+
if (spi_bus->sck == MP_OBJ_NULL) {
180+
if (spi_id == 0 && .sck = MP_OBJ_NULL)
181+
spi_bus->sck = mp_obj_new_int(MICROPY_HW_SPI0_SCK);
182+
spi_bus->mosi = mp_obj_new_int(MICROPY_HW_SPI0_MOSI);
183+
spi_bus->miso = mp_obj_new_int(MICROPY_HW_SPI0_MISO);
184+
} else {
185+
spi_bus->sck = mp_obj_new_int(MICROPY_HW_SPI1_SCK);
186+
spi_bus->mosi = mp_obj_new_int(MICROPY_HW_SPI1_MOSI);
187+
spi_bus->miso = mp_obj_new_int(MICROPY_HW_SPI1_MISO);
188+
}
189+
}
175190

191+
self->spi_bus = spi_bus;
176192
self->baudrate = (uint32_t)args[ARG_baudrate].u_int;
177193
self->bits = (uint8_t)args[ARG_bits].u_int;
178194
self->polarity = (uint8_t)args[ARG_polarity].u_int;

0 commit comments

Comments
 (0)