spi: Added block-level SPI writes at the HAL level

Poking the block-level SPI writes through the HAL level gives more
freedom to targets to improve SPI transaction speed.
pull/4207/head
Christopher Haster 2017-04-24 19:38:59 -05:00
parent 58491aa244
commit 31bf0d5099
2 changed files with 19 additions and 11 deletions

View File

@ -79,20 +79,11 @@ int SPI::write(int value) {
} }
int SPI::write(const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { int SPI::write(const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) {
int total = (tx_length > rx_length) ? tx_length : rx_length;
lock(); lock();
aquire(); aquire();
for (int i = 0; i < total; i++) { int ret = spi_master_block_write(&_spi, tx_buffer, tx_length, rx_buffer, rx_length);
char out = (i < tx_length) ? tx_buffer[i] : 0xff;
char in = spi_master_write(&_spi, out);
if (i < rx_length) {
rx_buffer[i] = in;
}
}
unlock(); unlock();
return ret;
return total;
} }
void SPI::lock() { void SPI::lock() {

View File

@ -116,6 +116,23 @@ void spi_frequency(spi_t *obj, int hz);
*/ */
int spi_master_write(spi_t *obj, int value); int spi_master_write(spi_t *obj, int value);
/** Write a block out in master mode and receive a value
*
* The total number of bytes sent and recieved will be the maximum of
* tx_length and rx_length. The bytes written will be padded with the
* value 0xff.
*
* @param[in] obj The SPI peripheral to use for sending
* @param[in] tx_buffer Pointer to the byte-array of data to write to the device
* @param[in] tx_length Number of bytes to write, may be zero
* @param[in] rx_buffer Pointer to the byte-array of data to read from the device
* @param[in] rx_length Number of bytes to read, may be zero
* @returns
* The number of bytes written and read from the device. This is
* maximum of tx_length and rx_length.
*/
int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length);
/** Check if a value is available to read /** Check if a value is available to read
* *
* @param[in] obj The SPI peripheral to check * @param[in] obj The SPI peripheral to check