Remove fixed pointers and check UART return
This commit is contained in:
parent
69b3d47564
commit
5028804878
@ -90,8 +90,10 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
self->semaphore_handle = xSemaphoreCreateBinaryStatic(&self->semaphore);
|
if (xSemaphoreCreateBinaryStatic(&self->semaphore) != &self->semaphore) {
|
||||||
xSemaphoreGive(self->semaphore_handle);
|
mp_raise_RuntimeError(translate("Unable to create lock"));
|
||||||
|
}
|
||||||
|
xSemaphoreGive(&self->semaphore);
|
||||||
self->sda_pin = sda;
|
self->sda_pin = sda;
|
||||||
self->scl_pin = scl;
|
self->scl_pin = scl;
|
||||||
self->i2c_num = I2C_NUM_MAX;
|
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) {
|
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;
|
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) {
|
void common_hal_busio_i2c_unlock(busio_i2c_obj_t *self) {
|
||||||
xSemaphoreGive(self->semaphore_handle);
|
xSemaphoreGive(&self->semaphore);
|
||||||
self->has_lock = false;
|
self->has_lock = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,6 @@ typedef struct {
|
|||||||
const mcu_pin_obj_t* sda_pin;
|
const mcu_pin_obj_t* sda_pin;
|
||||||
i2c_port_t i2c_num;
|
i2c_port_t i2c_num;
|
||||||
StaticSemaphore_t semaphore;
|
StaticSemaphore_t semaphore;
|
||||||
SemaphoreHandle_t semaphore_handle;
|
|
||||||
bool has_lock;
|
bool has_lock;
|
||||||
} busio_i2c_obj_t;
|
} busio_i2c_obj_t;
|
||||||
|
|
||||||
|
@ -209,9 +209,6 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
|
|||||||
|
|
||||||
hal->io_mode = SPI_LL_IO_MODE_NORMAL;
|
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);
|
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->phase = phase;
|
||||||
self->bits = bits;
|
self->bits = bits;
|
||||||
self->target_frequency = baudrate;
|
self->target_frequency = baudrate;
|
||||||
|
self->hal_context.timing_conf = &self->timing_conf;
|
||||||
esp_err_t result = spi_hal_get_clock_conf(&self->hal_context,
|
esp_err_t result = spi_hal_get_clock_conf(&self->hal_context,
|
||||||
self->target_frequency,
|
self->target_frequency,
|
||||||
128 /* duty_cycle */,
|
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;
|
spi_hal_context_t* hal = &self->hal_context;
|
||||||
hal->send_buffer = NULL;
|
hal->send_buffer = NULL;
|
||||||
hal->rcv_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.
|
// This rounds up.
|
||||||
size_t dma_count = (len + LLDESC_MAX_NUM_PER_DESC - 1) / LLDESC_MAX_NUM_PER_DESC;
|
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++) {
|
for (size_t i = 0; i < dma_count; i++) {
|
||||||
|
@ -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) {
|
while (supervisor_ticks_ms64() - start_ticks <= self->timeout_ms) {
|
||||||
// Read as many chars as we can right now, up to len.
|
// 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);
|
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.
|
// Advance pointer in data buffer, and decrease how many chars left to read.
|
||||||
data += num_read;
|
data += num_read;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user