Remove fixed pointers and check UART return

This commit is contained in:
Scott Shawcroft 2020-06-30 15:29:42 -07:00
parent 69b3d47564
commit 5028804878
No known key found for this signature in database
GPG Key ID: 9349BC7E64B1921E
4 changed files with 12 additions and 8 deletions

View File

@ -90,8 +90,10 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
#endif
self->semaphore_handle = xSemaphoreCreateBinaryStatic(&self->semaphore);
xSemaphoreGive(self->semaphore_handle);
if (xSemaphoreCreateBinaryStatic(&self->semaphore) != &self->semaphore) {
mp_raise_RuntimeError(translate("Unable to create lock"));
}
xSemaphoreGive(&self->semaphore);
self->sda_pin = sda;
self->scl_pin = scl;
self->i2c_num = I2C_NUM_MAX;
@ -161,7 +163,7 @@ bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) {
}
bool common_hal_busio_i2c_try_lock(busio_i2c_obj_t *self) {
self->has_lock = xSemaphoreTake(self->semaphore_handle, 0) == pdTRUE;
self->has_lock = xSemaphoreTake(&self->semaphore, 0) == pdTRUE;
return self->has_lock;
}
@ -170,7 +172,7 @@ bool common_hal_busio_i2c_has_lock(busio_i2c_obj_t *self) {
}
void common_hal_busio_i2c_unlock(busio_i2c_obj_t *self) {
xSemaphoreGive(self->semaphore_handle);
xSemaphoreGive(&self->semaphore);
self->has_lock = false;
}

View File

@ -40,7 +40,6 @@ typedef struct {
const mcu_pin_obj_t* sda_pin;
i2c_port_t i2c_num;
StaticSemaphore_t semaphore;
SemaphoreHandle_t semaphore_handle;
bool has_lock;
} busio_i2c_obj_t;

View File

@ -209,9 +209,6 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
hal->io_mode = SPI_LL_IO_MODE_NORMAL;
// This must be set after spi_hal_init.
hal->timing_conf = &self->timing_conf;
common_hal_busio_spi_configure(self, 250000, 0, 0, 8);
}
@ -261,6 +258,7 @@ bool common_hal_busio_spi_configure(busio_spi_obj_t *self,
self->phase = phase;
self->bits = bits;
self->target_frequency = baudrate;
self->hal_context.timing_conf = &self->timing_conf;
esp_err_t result = spi_hal_get_clock_conf(&self->hal_context,
self->target_frequency,
128 /* duty_cycle */,
@ -315,6 +313,8 @@ bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, const uint8_t *data_ou
spi_hal_context_t* hal = &self->hal_context;
hal->send_buffer = NULL;
hal->rcv_buffer = NULL;
// Reset timing_conf in case we've moved since the last time we used it.
hal->timing_conf = &self->timing_conf;
// This rounds up.
size_t dma_count = (len + LLDESC_MAX_NUM_PER_DESC - 1) / LLDESC_MAX_NUM_PER_DESC;
for (size_t i = 0; i < dma_count; i++) {

View File

@ -249,6 +249,9 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t
while (supervisor_ticks_ms64() - start_ticks <= self->timeout_ms) {
// Read as many chars as we can right now, up to len.
size_t num_read = uart_read_bytes(self->uart_num, data, len, 0);
if (num_read < 0) {
break;
}
// Advance pointer in data buffer, and decrease how many chars left to read.
data += num_read;