diff options
author | Dimitris Papavasiliou <dpapavas@protonmail.ch> | 2020-12-06 03:50:02 +0200 |
---|---|---|
committer | Drashna Jael're <drashna@live.com> | 2021-01-12 22:46:06 -0800 |
commit | 3a5434f5f4b1e4f370bcdb260bdf949e03ba2ffa (patch) | |
tree | 3c0df9ed96c52c7b89f5137daa34b9d895c14498 | |
parent | 3272f6ee6abd3dcfdff4de3bb11369f7e9365c54 (diff) |
Fix error handling in SPI master. (#11122)
Co-authored-by: Dimitris Papavasiliou <dpapavas@gmail.com>
-rw-r--r-- | drivers/avr/spi_master.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/drivers/avr/spi_master.c b/drivers/avr/spi_master.c index f91baf70ba..cbec9f36e1 100644 --- a/drivers/avr/spi_master.c +++ b/drivers/avr/spi_master.c @@ -140,27 +140,33 @@ spi_status_t spi_read() { } spi_status_t spi_transmit(const uint8_t *data, uint16_t length) { - spi_status_t status = SPI_STATUS_ERROR; + spi_status_t status; for (uint16_t i = 0; i < length; i++) { status = spi_write(data[i]); + + if (status < 0) { + return status; + } } - return status; + return SPI_STATUS_SUCCESS; } spi_status_t spi_receive(uint8_t *data, uint16_t length) { - spi_status_t status = SPI_STATUS_ERROR; + spi_status_t status; for (uint16_t i = 0; i < length; i++) { status = spi_read(); - if (status > 0) { + if (status >= 0) { data[i] = status; + } else { + return status; } } - return (status < 0) ? status : SPI_STATUS_SUCCESS; + return SPI_STATUS_SUCCESS; } void spi_stop(void) { |