Skip to content

Commit 5cf0305

Browse files
committed
Clean up MAX32 BUSIO drivers
- Fixed errors with peripheral bus hardware descriptions in MAX32690 "peripherals/" - Resolved all FIXME comments - Removed unused ringbuf API from common-hal/busio/UART.c Signed-off-by: Brandon Hurst <[email protected]>
1 parent 88099be commit 5cf0305

File tree

8 files changed

+16
-48
lines changed

8 files changed

+16
-48
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,6 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) {
155155
self->scl = NULL;
156156
}
157157

158-
void common_hal_busio_i2c_mark_deinit(busio_i2c_obj_t *self) {
159-
// FIXME: Implement
160-
}
161-
162158
// Probe device in I2C bus
163159
bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) {
164160
int nack = 0;

ports/analog/common-hal/busio/SPI.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@ void spi_isr(void) {
6060
}
6161
}
6262

63-
// Reset SPI when reload
64-
void spi_reset(void) {
65-
// FIXME: Implement
66-
return;
67-
}
68-
6963
// Construct SPI protocol, this function init SPI peripheral
7064
// todo: figure out Chip select behavior
7165
void common_hal_busio_spi_construct(busio_spi_obj_t *self,
@@ -102,11 +96,9 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
10296

10397
assert((self->spi_id >= 0) && (self->spi_id < NUM_SPI));
10498

105-
// Init I2C as main / controller node (0x00 is ignored)
106-
// FIXME: MUST map the SPI pins to a spi_pins_t struct
99+
// Init SPI controller
107100
if ((mosi != NULL) && (miso != NULL) && (sck != NULL)) {
108101
// spi, mastermode, quadModeUsed, numSubs, ssPolarity, frequency
109-
// err = MXC_SPI_Init((mxc_spi_reva_regs_t *)self->spi_regs, 1, 0, 1, 0x00, 1000000, &spi_pins);
110102
err = MXC_SPI_Init(self->spi_regs, MXC_SPI_TYPE_CONTROLLER, MXC_SPI_INTERFACE_STANDARD,
111103
1, 0x01, 1000000, spi_pins);
112104
MXC_GPIO_SetVSSEL(MXC_GPIO_GET_GPIO(sck->port), MXC_GPIO_VSSEL_VDDIOH, (sck->mask | miso->mask | mosi->mask | MXC_GPIO_PIN_0));
@@ -117,9 +109,6 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
117109
mp_raise_NotImplementedError(MP_ERROR_TEXT("SPI needs MOSI, MISO, and SCK"));
118110
}
119111

120-
// FIXME: Debugging
121-
122-
123112
// Attach SPI pins
124113
self->mosi = mosi;
125114
self->miso = miso;

ports/analog/common-hal/busio/UART.c

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static uint32_t timeout_ms = 0;
9696
static uint8_t uarts_active = 0;
9797
static uart_status_t uart_status[NUM_UARTS];
9898
static volatile int uart_err;
99-
// static uint8_t uart_never_reset_mask = 0;
99+
static uint8_t uart_never_reset_mask = 0;
100100

101101
static int isValidBaudrate(uint32_t baudrate) {
102102
switch (baudrate) {
@@ -167,8 +167,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
167167
const mcu_pin_obj_t *rts, const mcu_pin_obj_t *cts,
168168
const mcu_pin_obj_t *rs485_dir, bool rs485_invert,
169169
uint32_t baudrate, uint8_t bits, busio_uart_parity_t parity, uint8_t stop,
170-
mp_float_t timeout, uint16_t receiver_buffer_size, byte *receiver_buffer,
171-
bool sigint_enabled) {
170+
mp_float_t timeout, bool sigint_enabled) {
172171
int err, temp;
173172

174173
// Check for NULL Pointers && valid UART settings
@@ -236,21 +235,6 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
236235
self->baudrate = baudrate;
237236
self->error = E_NO_ERROR;
238237

239-
// Initialize ringbuffer for receiving data
240-
// FIXME: Either the use the ringbuf or get rid of it!
241-
if (self->rx_pin) {
242-
// if given a ringbuff, use that
243-
if (receiver_buffer) {
244-
ringbuf_init(&self->ringbuf, receiver_buffer, receiver_buffer_size);
245-
}
246-
// else create one and attach it
247-
else {
248-
if (!ringbuf_alloc(&self->ringbuf, receiver_buffer_size)) {
249-
m_malloc_fail(receiver_buffer_size);
250-
}
251-
}
252-
}
253-
254238
// Indicate to this module that the UART is active
255239
uarts_active |= (1 << self->uart_id);
256240

@@ -277,6 +261,7 @@ void common_hal_busio_uart_deinit(busio_uart_obj_t *self) {
277261
// First disable the ISR to avoid pre-emption
278262
NVIC_DisableIRQ(UART0_IRQn);
279263

264+
// Shutdown the UART Controller
280265
MXC_UART_Shutdown(self->uart_regs);
281266
self->error = E_UNINITIALIZED;
282267

@@ -307,7 +292,7 @@ bool common_hal_busio_uart_deinited(busio_uart_obj_t *self) {
307292
};
308293
}
309294

310-
// Read characters. len is in characters NOT bytes!
295+
// Read characters. len is in characters.
311296
size_t common_hal_busio_uart_read(busio_uart_obj_t *self,
312297
uint8_t *data, size_t len, int *errcode) {
313298
int err;
@@ -474,7 +459,7 @@ void common_hal_busio_uart_never_reset(busio_uart_obj_t *self) {
474459
common_hal_never_reset_pin(self->rx_pin);
475460
common_hal_never_reset_pin(self->cts_pin);
476461
common_hal_never_reset_pin(self->rts_pin);
477-
// uart_never_reset_mask |= ( 1 << (self->uart_id) );
462+
uart_never_reset_mask |= (1 << (self->uart_id));
478463
}
479464

480465
#endif // CIRCUITPY_BUSIO_UART

ports/analog/common-hal/busio/UART.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ typedef struct {
3333
int error;
3434
float timeout;
3535

36-
ringbuf_t ringbuf;
37-
3836
const mcu_pin_obj_t *rx_pin;
3937
const mcu_pin_obj_t *tx_pin;
4038
const mcu_pin_obj_t *rts_pin;

ports/analog/peripherals/max32690/max32_i2c.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*
2121
* See MAX32690 Rev A2 Errata #16:
2222
* https://www.analog.com/media/en/technical-documentation/data-sheets/max32690_a2_errata_rev2.pdf
23-
*
23+
*
2424
* Additionally, note that the TQFN package does not expose some of the duplicate pins. For this package,
2525
* enabling the un-routed GPIOs has been shown to cause initialization issues with the I2C block.
2626
* To work around this, "MAX32690GTK_PACKAGE_TQFN" can be defined by the build system. The recommend place
@@ -30,13 +30,13 @@
3030
const mxc_gpio_cfg_t i2c_maps[NUM_I2C] = {
3131
// I2C0
3232
{ MXC_GPIO2, (MXC_GPIO_PIN_7 | MXC_GPIO_PIN_8), MXC_GPIO_FUNC_ALT1,
33-
MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 };
33+
MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
3434
// I2C1
3535
{ MXC_GPIO0, (MXC_GPIO_PIN_11 | MXC_GPIO_PIN_12), MXC_GPIO_FUNC_ALT1,
36-
MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 };
36+
MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
3737
// I2C2
3838
{ MXC_GPIO1, (MXC_GPIO_PIN_7 | MXC_GPIO_PIN_8), MXC_GPIO_FUNC_ALT3,
39-
MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIOH, MXC_GPIO_DRVSTR_0 };,
39+
MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIOH, MXC_GPIO_DRVSTR_0 },
4040
};
4141
#ifndef MAX32690GTK_PACKAGE_TQFN
4242
const mxc_gpio_cfg_t i2c_maps_extra[NUM_I2C] = {
@@ -48,7 +48,7 @@ const mxc_gpio_cfg_t i2c_maps_extra[NUM_I2C] = {
4848
MXC_GPIO_PAD_PULL_UP, MXC_GPIO_VSSEL_VDDIOH, MXC_GPIO_DRVSTR_0 },
4949
// I2C2C
5050
{ MXC_GPIO0, (MXC_GPIO_PIN_13 | MXC_GPIO_PIN_14), MXC_GPIO_FUNC_ALT3,
51-
MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 };,
51+
MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
5252
};
5353
#endif
5454

ports/analog/peripherals/max32690/max32_i2c.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
#include "i2c.h"
1212
#include "peripherals/pins.h"
1313

14-
#define NUM_I2C 2
14+
#define NUM_I2C 3
1515

1616
int pinsToI2c(const mcu_pin_obj_t *sda, const mcu_pin_obj_t *scl);

ports/analog/peripherals/max32690/max32_spi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
const mxc_gpio_cfg_t spi_maps[NUM_SPI] = {
1717
// SPI0
1818
{ MXC_GPIO2, (MXC_GPIO_PIN_27 | MXC_GPIO_PIN_28 | MXC_GPIO_PIN_29),
19-
MXC_GPIO_FUNC_ALT2, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 };
19+
MXC_GPIO_FUNC_ALT2, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
2020
// SPI1
2121
{ MXC_GPIO1, (MXC_GPIO_PIN_26 | MXC_GPIO_PIN_28 | MXC_GPIO_PIN_29),
2222
MXC_GPIO_FUNC_ALT1, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },

ports/analog/peripherals/max32690/max32_uart.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ const mxc_gpio_cfg_t uart_maps[NUM_UARTS] = {
1818
MXC_GPIO_PAD_WEAK_PULL_UP, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
1919
{ MXC_GPIO2, (MXC_GPIO_PIN_14 | MXC_GPIO_PIN_16), MXC_GPIO_FUNC_ALT1,
2020
MXC_GPIO_PAD_WEAK_PULL_UP, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
21-
{ MXC_GPIO1, (MXC_GPIO_PIN_9 | MXC_GPIO_PIN_10), MXC_GPIO_FUNC_ALT1,
21+
{ MXC_GPIO1, (MXC_GPIO_PIN_9 | MXC_GPIO_PIN_10), MXC_GPIO_FUNC_ALT1,
2222
MXC_GPIO_PAD_WEAK_PULL_UP, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
23-
{ MXC_GPIO3, (MXC_GPIO_PIN_0 | MXC_GPIO_PIN_1), MXC_GPIO_FUNC_ALT2,
23+
{ MXC_GPIO3, (MXC_GPIO_PIN_0 | MXC_GPIO_PIN_1), MXC_GPIO_FUNC_ALT2,
2424
MXC_GPIO_PAD_WEAK_PULL_UP, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 }
2525
};
2626

2727
int pinsToUart(const mcu_pin_obj_t *rx, const mcu_pin_obj_t *tx) {
28-
for (int i = 0; i < uart_entries; i++) {
28+
for (int i = 0; i < NUM_UARTS; i++) {
2929
if ((uart_maps[i].port == (MXC_GPIO_GET_GPIO(tx->port)))
3030
&& (uart_maps[i].mask == ((tx->mask) | (rx->mask)))) {
3131
return i;

0 commit comments

Comments
 (0)