Skip to content

Commit

Permalink
Fix error handling in SPI master. (qmk#11122)
Browse files Browse the repository at this point in the history
Co-authored-by: Dimitris Papavasiliou <[email protected]>
  • Loading branch information
dpapavas and Dimitris Papavasiliou authored Dec 6, 2020
1 parent 54b932e commit 5cf70f3
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions drivers/avr/spi_master.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 5cf70f3

Please sign in to comment.