diff options
| author | Dimitris Papavasiliou <dpapavas@protonmail.ch> | 2020-12-06 03:50:02 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-06 12:50:02 +1100 |
| commit | 5cf70f3993ceecf24dc46c6791552f268d82ae91 (patch) | |
| tree | 2a8049ada0859d82f67edf97f4f6880be833060a | |
| parent | 54b932e84404725d3ac77d36faa2001c0aa8267b (diff) | |
| download | qmk_firmware-5cf70f3993ceecf24dc46c6791552f268d82ae91.tar.gz qmk_firmware-5cf70f3993ceecf24dc46c6791552f268d82ae91.zip | |
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 f91baf70b..cbec9f36e 100644 --- a/drivers/avr/spi_master.c +++ b/drivers/avr/spi_master.c | |||
| @@ -140,27 +140,33 @@ spi_status_t spi_read() { | |||
| 140 | } | 140 | } |
| 141 | 141 | ||
| 142 | spi_status_t spi_transmit(const uint8_t *data, uint16_t length) { | 142 | spi_status_t spi_transmit(const uint8_t *data, uint16_t length) { |
| 143 | spi_status_t status = SPI_STATUS_ERROR; | 143 | spi_status_t status; |
| 144 | 144 | ||
| 145 | for (uint16_t i = 0; i < length; i++) { | 145 | for (uint16_t i = 0; i < length; i++) { |
| 146 | status = spi_write(data[i]); | 146 | status = spi_write(data[i]); |
| 147 | |||
| 148 | if (status < 0) { | ||
| 149 | return status; | ||
| 150 | } | ||
| 147 | } | 151 | } |
| 148 | 152 | ||
| 149 | return status; | 153 | return SPI_STATUS_SUCCESS; |
| 150 | } | 154 | } |
| 151 | 155 | ||
| 152 | spi_status_t spi_receive(uint8_t *data, uint16_t length) { | 156 | spi_status_t spi_receive(uint8_t *data, uint16_t length) { |
| 153 | spi_status_t status = SPI_STATUS_ERROR; | 157 | spi_status_t status; |
| 154 | 158 | ||
| 155 | for (uint16_t i = 0; i < length; i++) { | 159 | for (uint16_t i = 0; i < length; i++) { |
| 156 | status = spi_read(); | 160 | status = spi_read(); |
| 157 | 161 | ||
| 158 | if (status > 0) { | 162 | if (status >= 0) { |
| 159 | data[i] = status; | 163 | data[i] = status; |
| 164 | } else { | ||
| 165 | return status; | ||
| 160 | } | 166 | } |
| 161 | } | 167 | } |
| 162 | 168 | ||
| 163 | return (status < 0) ? status : SPI_STATUS_SUCCESS; | 169 | return SPI_STATUS_SUCCESS; |
| 164 | } | 170 | } |
| 165 | 171 | ||
| 166 | void spi_stop(void) { | 172 | void spi_stop(void) { |
