Skip to content

Commit bd6f5dd

Browse files
committed
Reuse more existing error messages in ports/analog BUSIO
- Reuse more messages in locales/circuitpython.pot in BUSIO - Remove UART write timeout - Refine some error handling for SPI initialization Signed-off-by: Brandon-Hurst <brandon.hurst97@gmail.com>
1 parent fed3081 commit bd6f5dd

File tree

4 files changed

+19
-62
lines changed

4 files changed

+19
-62
lines changed

locale/circuitpython.pot

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,6 @@ msgstr ""
163163
msgid "%q must be %d"
164164
msgstr ""
165165

166-
#: py/runtime.c
167-
msgid "%q moved from %q to %q"
168-
msgstr ""
169-
170166
#: py/argcheck.c shared-bindings/busdisplay/BusDisplay.c
171167
#: shared-bindings/displayio/Bitmap.c
172168
#: shared-bindings/framebufferio/FramebufferDisplay.c
@@ -242,6 +238,7 @@ msgstr ""
242238
msgid "%q out of bounds"
243239
msgstr ""
244240

241+
#: ports/analog/common-hal/busio/SPI.c
245242
#: ports/atmel-samd/common-hal/pulseio/PulseIn.c
246243
#: ports/cxd56/common-hal/pulseio/PulseIn.c
247244
#: ports/nordic/common-hal/pulseio/PulseIn.c
@@ -946,14 +943,6 @@ msgstr ""
946943
msgid "ECB only operates on 16 bytes at a time"
947944
msgstr ""
948945

949-
#: ports/analog/common-hal/busio/UART.c
950-
msgid "ERR: Could not init ringbuffer\n"
951-
msgstr ""
952-
953-
#: ports/analog/common-hal/busio/I2C.c
954-
msgid "ERROR during I2C Transaction\n"
955-
msgstr ""
956-
957946
#: ports/espressif/common-hal/busio/SPI.c
958947
#: ports/espressif/common-hal/canio/CAN.c
959948
msgid "ESP-IDF memory allocation failed"
@@ -1002,7 +991,7 @@ msgid ""
1002991
"Failed to add service TXT record; non-string or bytes found in txt_records"
1003992
msgstr ""
1004993

1005-
#: shared-module/rgbmatrix/RGBMatrix.c
994+
#: ports/analog/common-hal/busio/UART.c shared-module/rgbmatrix/RGBMatrix.c
1006995
msgid "Failed to allocate %q buffer"
1007996
msgstr ""
1008997

@@ -1061,15 +1050,7 @@ msgid "Failed to release mutex, err 0x%04x"
10611050
msgstr ""
10621051

10631052
#: ports/analog/common-hal/busio/SPI.c
1064-
msgid "Failed to set SPI Clock Mode\n"
1065-
msgstr ""
1066-
1067-
#: ports/analog/common-hal/busio/SPI.c
1068-
msgid "Failed to set SPI Frame Size\n"
1069-
msgstr ""
1070-
1071-
#: ports/analog/common-hal/busio/SPI.c
1072-
msgid "Failed to set SPI Frequency\n"
1053+
msgid "Failed to set SPI Clock Mode"
10731054
msgstr ""
10741055

10751056
#: ports/zephyr-cp/common-hal/wifi/Radio.c
@@ -1370,6 +1351,7 @@ msgstr ""
13701351
msgid "Invalid socket for TLS"
13711352
msgstr ""
13721353

1354+
#: ports/analog/common-hal/busio/SPI.c
13731355
#: ports/espressif/common-hal/espidf/__init__.c
13741356
#: ports/nordic/common-hal/_bleio/__init__.c
13751357
msgid "Invalid state"
@@ -2256,10 +2238,6 @@ msgstr ""
22562238
msgid "UUID value is not str, int or byte buffer"
22572239
msgstr ""
22582240

2259-
#: ports/analog/common-hal/busio/UART.c
2260-
msgid "Uart transaction timed out."
2261-
msgstr ""
2262-
22632241
#: ports/raspberrypi/common-hal/memorymap/AddressRange.c
22642242
msgid "Unable to access unaligned IO register"
22652243
msgstr ""

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr,
191191
};
192192
ret = MXC_I2C_MasterTransaction(&wr_req);
193193
if (ret) {
194-
mp_raise_RuntimeError(MP_ERROR_TEXT("ERROR during I2C Transaction\n"));
194+
return MP_EIO;
195195
}
196196

197197
return 0;

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,19 @@ bool common_hal_busio_spi_configure(busio_spi_obj_t *self,
177177

178178
ret = MXC_SPI_SetFrequency(self->spi_regs, baudrate);
179179
if (ret) {
180-
mp_raise_ValueError(MP_ERROR_TEXT("Failed to set SPI Frequency\n"));
180+
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q out of range"), MP_QSTR_baudrate);
181181
return false;
182182
}
183183
ret = MXC_SPI_SetDataSize(self->spi_regs, bits);
184-
if (ret) {
185-
mp_raise_ValueError(MP_ERROR_TEXT("Failed to set SPI Frame Size\n"));
184+
if (ret == E_BAD_PARAM) {
185+
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q out of range"), MP_QSTR_bits);
186186
return false;
187+
} else if (ret == E_BAD_STATE) {
188+
mp_raise_RuntimeError(MP_ERROR_TEXT("Invalid state"));
187189
}
188190
ret = MXC_SPI_SetMode(self->spi_regs, clk_mode);
189191
if (ret) {
190-
mp_raise_ValueError(MP_ERROR_TEXT("Failed to set SPI Clock Mode\n"));
192+
mp_raise_ValueError(MP_ERROR_TEXT("Failed to set SPI Clock Mode"));
191193
return false;
192194
}
193195
return true;
@@ -246,11 +248,6 @@ bool common_hal_busio_spi_read(busio_spi_obj_t *self,
246248
uint8_t write_value) {
247249

248250
int ret = 0;
249-
// uint8_t tx_buffer[len] = {0x0};
250-
251-
// for (int i = 0; i < len; i++) {
252-
// tx_buffer[i] = write_value;
253-
// }
254251

255252
mxc_spi_req_t rd_req = {
256253
.spi = self->spi_regs,

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

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
/** TODO:
28-
* - Fix readline issue
29-
*
30-
*/
31-
3227
#if CIRCUITPY_BUSIO_UART
3328

3429
#include "mpconfigport.h"
@@ -242,19 +237,19 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
242237
self->ringbuf = m_malloc_without_collect(receiver_buffer_size);
243238
if (!ringbuf_alloc(self->ringbuf, receiver_buffer_size)) {
244239
m_malloc_fail(receiver_buffer_size);
245-
mp_raise_RuntimeError(MP_ERROR_TEXT("ERR: Could not init ringbuffer\n"));
240+
mp_raise_RuntimeError_varg(MP_ERROR_TEXT("Failed to allocate %q buffer"),
241+
MP_QSTR_UART);
246242
}
247243
} else {
248244
if (!(ringbuf_init(self->ringbuf, receiver_buffer, receiver_buffer_size))) {
249-
mp_raise_RuntimeError(MP_ERROR_TEXT("ERR: Could not init ringbuffer\n"));
245+
mp_raise_RuntimeError_varg(MP_ERROR_TEXT("Failed to allocate %q buffer"),
246+
MP_QSTR_UART);
250247
}
251-
;
252248
}
253249

254250
context = self;
255251

256252
// Setup UART interrupt
257-
258253
NVIC_ClearPendingIRQ(MXC_UART_GET_IRQ(self->uart_id));
259254
NVIC_DisableIRQ(MXC_UART_GET_IRQ(self->uart_id));
260255
NVIC_SetPriority(MXC_UART_GET_IRQ(self->uart_id), UART_PRIORITY);
@@ -351,7 +346,7 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self,
351346
}
352347
// Check for errors from the callback
353348
else if (uart_err != E_NO_ERROR) {
354-
// todo: indicate error?
349+
mp_raise_RuntimeError(MP_ERROR_TEXT("UART read error"));
355350
MXC_UART_AbortAsync(self->uart_regs);
356351
}
357352

@@ -368,7 +363,6 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self,
368363
size_t common_hal_busio_uart_write(busio_uart_obj_t *self,
369364
const uint8_t *data, size_t len, int *errcode) {
370365
int err;
371-
uint32_t start_time = 0;
372366
static size_t bytes_remaining;
373367

374368
// Setup globals & status tracking
@@ -390,7 +384,6 @@ size_t common_hal_busio_uart_write(busio_uart_obj_t *self,
390384
uart_wr_req.callback = (void *)uartCallback;
391385

392386
// Start the transaction
393-
start_time = supervisor_ticks_ms64();
394387
err = MXC_UART_TransactionAsync(&uart_wr_req);
395388
if (err != E_NO_ERROR) {
396389
*errcode = err;
@@ -399,27 +392,16 @@ size_t common_hal_busio_uart_write(busio_uart_obj_t *self,
399392
mp_raise_ValueError(MP_ERROR_TEXT("All UART peripherals are in use"));
400393
}
401394

402-
// Wait for transaction completion or timeout
403-
while ((uart_status[self->uart_id] != UART_FREE) &&
404-
(supervisor_ticks_ms64() - start_time < (self->timeout * 1000))) {
405-
395+
// Wait for transaction completion
396+
while (uart_status[self->uart_id] != UART_FREE) {
406397
// Call the handler and abort if errors
407398
uart_err = MXC_UART_AsyncHandler(self->uart_regs);
408399
if (uart_err != E_NO_ERROR) {
409-
// todo: indicate error?
410400
MXC_UART_AbortAsync(self->uart_regs);
411401
}
412402
}
413-
414-
// If the timeout gets hit, abort and error out
415-
if (uart_status[self->uart_id] != UART_FREE) {
416-
MXC_UART_AbortAsync(self->uart_regs);
417-
NVIC_DisableIRQ(MXC_UART_GET_IRQ(self->uart_id));
418-
mp_raise_RuntimeError(MP_ERROR_TEXT("Uart transaction timed out."));
419-
}
420403
// Check for errors from the callback
421-
else if (uart_err != E_NO_ERROR) {
422-
// todo: indicate error?
404+
if (uart_err != E_NO_ERROR) {
423405
MXC_UART_AbortAsync(self->uart_regs);
424406
}
425407

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy