Optimize SPI functions, lowering ROM usage by 70 bytes.

- Have only one transfer function, to minimize duplicate code.
- Remove address assignments that does not make a difference.
This commit is contained in:
Daniel Jobson 2024-09-30 11:29:08 +02:00
parent 9fabff90cb
commit 6ac874584d
No known key found for this signature in database
GPG key ID: 3707A9DBF4BB8F1A
3 changed files with 29 additions and 41 deletions

View file

@ -64,7 +64,10 @@ static void _spi_read(uint8_t *buf, size_t size)
}
}
int spi_write(uint8_t *cmd, size_t cmd_size, uint8_t *data, size_t data_size)
// Function to both read and write data to the connected SPI flash.
int spi_transfer(uint8_t *cmd, size_t cmd_size, uint8_t *tx_buf, size_t tx_size,
uint8_t *rx_buf, size_t rx_size)
{
if (cmd == NULL || cmd_size == 0) {
return -1;
@ -74,26 +77,10 @@ int spi_write(uint8_t *cmd, size_t cmd_size, uint8_t *data, size_t data_size)
_spi_write(cmd, cmd_size);
if (data != NULL && data_size != 0) {
_spi_write(data, data_size);
if (tx_buf != NULL || tx_size != 0) {
_spi_write(tx_buf, tx_size);
}
spi_disable();
return 0;
}
int spi_transfer(uint8_t *tx_buf, size_t tx_size, uint8_t *rx_buf,
size_t rx_size)
{
if (tx_buf == NULL || tx_size == 0) {
return -1;
}
spi_enable();
_spi_write(tx_buf, tx_size);
if (rx_buf != NULL && rx_size != 0) {
_spi_read(rx_buf, rx_size);
}