Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error handling in SPI master driver. #11122

Merged
merged 1 commit into from
Dec 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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