diff --git a/drivers/SPI.cpp b/drivers/SPI.cpp index 465594dcdd..fc3764e241 100644 --- a/drivers/SPI.cpp +++ b/drivers/SPI.cpp @@ -32,7 +32,8 @@ SPI::SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel) : #endif _bits(8), _mode(0), - _hz(1000000) { + _hz(1000000), + _write_fill(SPI_FILL_CHAR) { // No lock needed in the constructor spi_init(&_spi, mosi, miso, sclk, ssel); @@ -102,7 +103,7 @@ int SPI::write(int value) { int SPI::write(const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { lock(); _acquire(); - int ret = spi_master_block_write(&_spi, tx_buffer, tx_length, rx_buffer, rx_length); + int ret = spi_master_block_write(&_spi, tx_buffer, tx_length, rx_buffer, rx_length, _write_fill); unlock(); return ret; } @@ -115,6 +116,12 @@ void SPI::unlock() { _mutex->unlock(); } +void SPI::set_default_write_value(char data) { + lock(); + _write_fill = data; + unlock(); +} + #if DEVICE_SPI_ASYNCH int SPI::transfer(const void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t& callback, int event) diff --git a/drivers/SPI.h b/drivers/SPI.h index 52df60f62c..645243070d 100644 --- a/drivers/SPI.h +++ b/drivers/SPI.h @@ -143,6 +143,15 @@ public: */ virtual void unlock(void); + /** Set default write data + * SPI requires the master to send some data during a read operation. + * Different devices may require different default byte values. + * For example: A SD Card requires default bytes to be 0xFF. + * + * @param data Default character to be transmitted while read operation + */ + void set_default_write_value(char data); + #if DEVICE_SPI_ASYNCH /** Start non-blocking SPI transfer using 8bit buffers. @@ -271,6 +280,7 @@ protected: int _bits; int _mode; int _hz; + char _write_fill; private: /* Private acquire function without locking/unlocking diff --git a/hal/spi_api.h b/hal/spi_api.h index 368e7b0e69..7fbcf223e4 100644 --- a/hal/spi_api.h +++ b/hal/spi_api.h @@ -33,6 +33,7 @@ #define SPI_EVENT_INTERNAL_TRANSFER_COMPLETE (1 << 30) // Internal flag to report that an event occurred #define SPI_FILL_WORD (0xFFFF) +#define SPI_FILL_CHAR (0xFF) #if DEVICE_SPI_ASYNCH /** Asynch SPI HAL structure @@ -122,16 +123,17 @@ int spi_master_write(spi_t *obj, int value); * 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 + * @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 + * @param[in] write_fill Default data transmitted while performing a read * @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); +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, char write_fill); /** Check if a value is available to read * diff --git a/targets/TARGET_ARM_SSG/TARGET_BEETLE/spi_api.c b/targets/TARGET_ARM_SSG/TARGET_BEETLE/spi_api.c index a54337f798..8385ecedae 100644 --- a/targets/TARGET_ARM_SSG/TARGET_BEETLE/spi_api.c +++ b/targets/TARGET_ARM_SSG/TARGET_BEETLE/spi_api.c @@ -262,11 +262,12 @@ int spi_master_write(spi_t *obj, int value) { return data; } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/spi_api.c b/targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/spi_api.c index b42079e3a8..cb2d6bfc0b 100644 --- a/targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/spi_api.c +++ b/targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/spi_api.c @@ -256,13 +256,13 @@ int spi_master_write(spi_t *obj, int value) } int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, - char *rx_buffer, int rx_length) + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; char out, in; for (int i = 0; i < total; i++) { - out = (i < tx_length) ? tx_buffer[i] : 0xff; + out = (i < tx_length) ? tx_buffer[i] : write_fill; in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_ARM_SSG/TARGET_IOTSS/spi_api.c b/targets/TARGET_ARM_SSG/TARGET_IOTSS/spi_api.c index f40445c90f..88b2e89be2 100644 --- a/targets/TARGET_ARM_SSG/TARGET_IOTSS/spi_api.c +++ b/targets/TARGET_ARM_SSG/TARGET_IOTSS/spi_api.c @@ -268,11 +268,12 @@ int spi_master_write(spi_t *obj, int value) { return (ssp_read(obj)); } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_ARM_SSG/TARGET_MPS2/spi_api.c b/targets/TARGET_ARM_SSG/TARGET_MPS2/spi_api.c index 3e2dcd9b13..affd5b2514 100644 --- a/targets/TARGET_ARM_SSG/TARGET_MPS2/spi_api.c +++ b/targets/TARGET_ARM_SSG/TARGET_MPS2/spi_api.c @@ -268,11 +268,12 @@ int spi_master_write(spi_t *obj, int value) { return (ssp_read(obj)); } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_Atmel/TARGET_SAM_CortexM0P/spi_api.c b/targets/TARGET_Atmel/TARGET_SAM_CortexM0P/spi_api.c index 09c4cbc3c4..9da9a458dd 100644 --- a/targets/TARGET_Atmel/TARGET_SAM_CortexM0P/spi_api.c +++ b/targets/TARGET_Atmel/TARGET_SAM_CortexM0P/spi_api.c @@ -555,11 +555,12 @@ int spi_master_write(spi_t *obj, int value) return rx_data; } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_Atmel/TARGET_SAM_CortexM4/spi_api.c b/targets/TARGET_Atmel/TARGET_SAM_CortexM4/spi_api.c index f2b2cf183d..13a326eab3 100644 --- a/targets/TARGET_Atmel/TARGET_SAM_CortexM4/spi_api.c +++ b/targets/TARGET_Atmel/TARGET_SAM_CortexM4/spi_api.c @@ -296,11 +296,12 @@ int spi_master_write(spi_t *obj, int value) return 0; } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char _write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : _write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_Freescale/TARGET_K20XX/spi_api.c b/targets/TARGET_Freescale/TARGET_K20XX/spi_api.c index 9dce8ddf46..391615e368 100644 --- a/targets/TARGET_Freescale/TARGET_K20XX/spi_api.c +++ b/targets/TARGET_Freescale/TARGET_K20XX/spi_api.c @@ -140,11 +140,12 @@ int spi_master_write(spi_t *obj, int value) { return obj->spi->POPR; } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_Freescale/TARGET_KLXX/TARGET_KL05Z/spi_api.c b/targets/TARGET_Freescale/TARGET_KLXX/TARGET_KL05Z/spi_api.c index a5ca202df3..1e9de30ce5 100644 --- a/targets/TARGET_Freescale/TARGET_KLXX/TARGET_KL05Z/spi_api.c +++ b/targets/TARGET_Freescale/TARGET_KLXX/TARGET_KL05Z/spi_api.c @@ -141,11 +141,12 @@ int spi_master_write(spi_t *obj, int value) { return obj->spi->D & 0xff; } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_Freescale/TARGET_KLXX/TARGET_KL25Z/spi_api.c b/targets/TARGET_Freescale/TARGET_KLXX/TARGET_KL25Z/spi_api.c index 4a5ddf7814..cfbc20384c 100644 --- a/targets/TARGET_Freescale/TARGET_KLXX/TARGET_KL25Z/spi_api.c +++ b/targets/TARGET_Freescale/TARGET_KLXX/TARGET_KL25Z/spi_api.c @@ -120,11 +120,12 @@ int spi_master_write(spi_t *obj, int value) { return obj->spi->D & 0xff; } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_Freescale/TARGET_KLXX/TARGET_KL26Z/spi_api.c b/targets/TARGET_Freescale/TARGET_KLXX/TARGET_KL26Z/spi_api.c index 0d75441a43..3d9b072b77 100644 --- a/targets/TARGET_Freescale/TARGET_KLXX/TARGET_KL26Z/spi_api.c +++ b/targets/TARGET_Freescale/TARGET_KLXX/TARGET_KL26Z/spi_api.c @@ -199,11 +199,12 @@ int spi_master_write(spi_t *obj, int value) { return ret; } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_Freescale/TARGET_KLXX/TARGET_KL46Z/spi_api.c b/targets/TARGET_Freescale/TARGET_KLXX/TARGET_KL46Z/spi_api.c index 0d75441a43..3d9b072b77 100644 --- a/targets/TARGET_Freescale/TARGET_KLXX/TARGET_KL46Z/spi_api.c +++ b/targets/TARGET_Freescale/TARGET_KLXX/TARGET_KL46Z/spi_api.c @@ -199,11 +199,12 @@ int spi_master_write(spi_t *obj, int value) { return ret; } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K66F/spi_api.c b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K66F/spi_api.c index 67d692f85e..8a65bd4f22 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K66F/spi_api.c +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K66F/spi_api.c @@ -118,11 +118,12 @@ int spi_master_write(spi_t *obj, int value) return rx_data & 0xffff; } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K82F/spi_api.c b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K82F/spi_api.c index 67d692f85e..8a65bd4f22 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K82F/spi_api.c +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K82F/spi_api.c @@ -118,11 +118,12 @@ int spi_master_write(spi_t *obj, int value) return rx_data & 0xffff; } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KL27Z/spi_api.c b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KL27Z/spi_api.c index 5e4b311d7a..084962073d 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KL27Z/spi_api.c +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KL27Z/spi_api.c @@ -115,11 +115,12 @@ int spi_master_write(spi_t *obj, int value) return rx_data & 0xffff; } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KL43Z/spi_api.c b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KL43Z/spi_api.c index 5e4b311d7a..084962073d 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KL43Z/spi_api.c +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KL43Z/spi_api.c @@ -115,11 +115,12 @@ int spi_master_write(spi_t *obj, int value) return rx_data & 0xffff; } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KL82Z/spi_api.c b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KL82Z/spi_api.c index 3d1a6af5a6..8bbf7ae247 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KL82Z/spi_api.c +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KL82Z/spi_api.c @@ -117,11 +117,12 @@ int spi_master_write(spi_t *obj, int value) return rx_data & 0xffff; } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KW24D/spi_api.c b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KW24D/spi_api.c index 3d1a6af5a6..8bbf7ae247 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KW24D/spi_api.c +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KW24D/spi_api.c @@ -117,11 +117,12 @@ int spi_master_write(spi_t *obj, int value) return rx_data & 0xffff; } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KW41Z/spi_api.c b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KW41Z/spi_api.c index 3d1a6af5a6..8bbf7ae247 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KW41Z/spi_api.c +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KW41Z/spi_api.c @@ -117,11 +117,12 @@ int spi_master_write(spi_t *obj, int value) return rx_data & 0xffff; } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K22F/spi_api.c b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K22F/spi_api.c index 3d1a6af5a6..8bbf7ae247 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K22F/spi_api.c +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K22F/spi_api.c @@ -117,11 +117,12 @@ int spi_master_write(spi_t *obj, int value) return rx_data & 0xffff; } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K24F/spi_api.c b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K24F/spi_api.c index cf301353a6..cc12421e4f 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K24F/spi_api.c +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K24F/spi_api.c @@ -127,11 +127,12 @@ int spi_master_write(spi_t *obj, int value) return rx_data & 0xffff; } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/spi_api.c b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/spi_api.c index 6751b85ea8..d07da22fa8 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/spi_api.c +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/spi_api.c @@ -127,17 +127,17 @@ int spi_master_write(spi_t *obj, int value) return rx_data & 0xffff; } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; - DSPI_MasterTransferBlocking(spi_address[obj->spi.instance], &(dspi_transfer_t){ - .txData = (uint8_t *)tx_buffer, - .rxData = (uint8_t *)rx_buffer, - .dataSize = total, - .configFlags = kDSPI_MasterCtar0 | kDSPI_MasterPcs0 | kDSPI_MasterPcsContinuous, - }); - - DSPI_ClearStatusFlags(spi_address[obj->spi.instance], kDSPI_RxFifoDrainRequestFlag | kDSPI_EndOfQueueFlag); + for (int i = 0; i < total; i++) { + char out = (i < tx_length) ? tx_buffer[i] : write_fill; + char in = spi_master_write(obj, out); + if (i < rx_length) { + rx_buffer[i] = in; + } + } return total; } diff --git a/targets/TARGET_Maxim/TARGET_MAX32600/spi_api.c b/targets/TARGET_Maxim/TARGET_MAX32600/spi_api.c index 2d1ec59712..edf5ab2f13 100644 --- a/targets/TARGET_Maxim/TARGET_MAX32600/spi_api.c +++ b/targets/TARGET_Maxim/TARGET_MAX32600/spi_api.c @@ -179,11 +179,12 @@ int spi_master_write(spi_t *obj, int value) return result; } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_Maxim/TARGET_MAX32610/spi_api.c b/targets/TARGET_Maxim/TARGET_MAX32610/spi_api.c index 2d1ec59712..edf5ab2f13 100644 --- a/targets/TARGET_Maxim/TARGET_MAX32610/spi_api.c +++ b/targets/TARGET_Maxim/TARGET_MAX32610/spi_api.c @@ -179,11 +179,12 @@ int spi_master_write(spi_t *obj, int value) return result; } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_Maxim/TARGET_MAX32620/spi_api.c b/targets/TARGET_Maxim/TARGET_MAX32620/spi_api.c index ed2d986e00..d2a194366d 100644 --- a/targets/TARGET_Maxim/TARGET_MAX32620/spi_api.c +++ b/targets/TARGET_Maxim/TARGET_MAX32620/spi_api.c @@ -231,11 +231,12 @@ int spi_master_write(spi_t *obj, int value) return spi_master_transaction(obj, value, MXC_S_SPI_FIFO_DIR_BOTH); } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_Maxim/TARGET_MAX32625/spi_api.c b/targets/TARGET_Maxim/TARGET_MAX32625/spi_api.c index 69e9e8eb80..a30e145502 100644 --- a/targets/TARGET_Maxim/TARGET_MAX32625/spi_api.c +++ b/targets/TARGET_Maxim/TARGET_MAX32625/spi_api.c @@ -167,11 +167,12 @@ int spi_master_write(spi_t *obj, int value) return *req.rx_data; } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_Maxim/TARGET_MAX32630/spi_api.c b/targets/TARGET_Maxim/TARGET_MAX32630/spi_api.c index 69e9e8eb80..a30e145502 100644 --- a/targets/TARGET_Maxim/TARGET_MAX32630/spi_api.c +++ b/targets/TARGET_Maxim/TARGET_MAX32630/spi_api.c @@ -167,11 +167,12 @@ int spi_master_write(spi_t *obj, int value) return *req.rx_data; } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_NORDIC/TARGET_MCU_NRF51822/spi_api.c b/targets/TARGET_NORDIC/TARGET_MCU_NRF51822/spi_api.c index d6cc309992..b1f354e77e 100755 --- a/targets/TARGET_NORDIC/TARGET_MCU_NRF51822/spi_api.c +++ b/targets/TARGET_NORDIC/TARGET_MCU_NRF51822/spi_api.c @@ -263,11 +263,12 @@ int spi_master_write(spi_t *obj, int value) return spi_read(obj); } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_NORDIC/TARGET_NRF5/spi_api.c b/targets/TARGET_NORDIC/TARGET_NRF5/spi_api.c index 1639279f7c..a44533ec54 100644 --- a/targets/TARGET_NORDIC/TARGET_NRF5/spi_api.c +++ b/targets/TARGET_NORDIC/TARGET_NRF5/spi_api.c @@ -487,11 +487,12 @@ int spi_master_write(spi_t *obj, int value) return p_spi_info->rx_buf; } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_NUVOTON/TARGET_M451/spi_api.c b/targets/TARGET_NUVOTON/TARGET_M451/spi_api.c index e67c1dbd76..dce7661584 100644 --- a/targets/TARGET_NUVOTON/TARGET_M451/spi_api.c +++ b/targets/TARGET_NUVOTON/TARGET_M451/spi_api.c @@ -241,11 +241,12 @@ int spi_master_write(spi_t *obj, int value) return value2; } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_NUVOTON/TARGET_NUC472/spi_api.c b/targets/TARGET_NUVOTON/TARGET_NUC472/spi_api.c index 74a728fd1e..7377915afc 100644 --- a/targets/TARGET_NUVOTON/TARGET_NUC472/spi_api.c +++ b/targets/TARGET_NUVOTON/TARGET_NUC472/spi_api.c @@ -244,11 +244,12 @@ int spi_master_write(spi_t *obj, int value) return value2; } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_NXP/TARGET_LPC11U6X/spi_api.c b/targets/TARGET_NXP/TARGET_LPC11U6X/spi_api.c index 2671cb29ba..95c647c74c 100644 --- a/targets/TARGET_NXP/TARGET_LPC11U6X/spi_api.c +++ b/targets/TARGET_NXP/TARGET_LPC11U6X/spi_api.c @@ -190,11 +190,12 @@ int spi_master_write(spi_t *obj, int value) { return ssp_read(obj); } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_NXP/TARGET_LPC11UXX/spi_api.c b/targets/TARGET_NXP/TARGET_LPC11UXX/spi_api.c index 2bce2490e9..024dff60d4 100644 --- a/targets/TARGET_NXP/TARGET_LPC11UXX/spi_api.c +++ b/targets/TARGET_NXP/TARGET_LPC11UXX/spi_api.c @@ -156,11 +156,12 @@ int spi_master_write(spi_t *obj, int value) { return ssp_read(obj); } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_NXP/TARGET_LPC11XX_11CXX/spi_api.c b/targets/TARGET_NXP/TARGET_LPC11XX_11CXX/spi_api.c index 80f2a72570..d8595cb22b 100644 --- a/targets/TARGET_NXP/TARGET_LPC11XX_11CXX/spi_api.c +++ b/targets/TARGET_NXP/TARGET_LPC11XX_11CXX/spi_api.c @@ -192,11 +192,12 @@ int spi_master_write(spi_t *obj, int value) { return ssp_read(obj); } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_NXP/TARGET_LPC13XX/spi_api.c b/targets/TARGET_NXP/TARGET_LPC13XX/spi_api.c index 2d8c2728ed..5c36ffece0 100644 --- a/targets/TARGET_NXP/TARGET_LPC13XX/spi_api.c +++ b/targets/TARGET_NXP/TARGET_LPC13XX/spi_api.c @@ -184,11 +184,12 @@ int spi_master_write(spi_t *obj, int value) { return ssp_read(obj); } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_NXP/TARGET_LPC15XX/spi_api.c b/targets/TARGET_NXP/TARGET_LPC15XX/spi_api.c index 3e2350375a..9d7d8f5f00 100644 --- a/targets/TARGET_NXP/TARGET_LPC15XX/spi_api.c +++ b/targets/TARGET_NXP/TARGET_LPC15XX/spi_api.c @@ -248,11 +248,12 @@ int spi_master_write(spi_t *obj, int value) return spi_read(obj); } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, + int tx_length, char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_NXP/TARGET_LPC176X/spi_api.c b/targets/TARGET_NXP/TARGET_LPC176X/spi_api.c index e01c937a44..ba2bde2989 100644 --- a/targets/TARGET_NXP/TARGET_LPC176X/spi_api.c +++ b/targets/TARGET_NXP/TARGET_LPC176X/spi_api.c @@ -190,11 +190,12 @@ int spi_master_write(spi_t *obj, int value) { return ssp_read(obj); } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_NXP/TARGET_LPC408X/TARGET_LPC4088/spi_api.c b/targets/TARGET_NXP/TARGET_LPC408X/TARGET_LPC4088/spi_api.c index efdbd1393c..2af13ff55b 100644 --- a/targets/TARGET_NXP/TARGET_LPC408X/TARGET_LPC4088/spi_api.c +++ b/targets/TARGET_NXP/TARGET_LPC408X/TARGET_LPC4088/spi_api.c @@ -197,11 +197,12 @@ int spi_master_write(spi_t *obj, int value) { return ssp_read(obj); } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_NXP/TARGET_LPC408X/TARGET_LPC4088_DM/spi_api.c b/targets/TARGET_NXP/TARGET_LPC408X/TARGET_LPC4088_DM/spi_api.c index b98ab158e4..5797a501cc 100644 --- a/targets/TARGET_NXP/TARGET_LPC408X/TARGET_LPC4088_DM/spi_api.c +++ b/targets/TARGET_NXP/TARGET_LPC408X/TARGET_LPC4088_DM/spi_api.c @@ -177,11 +177,12 @@ int spi_master_write(spi_t *obj, int value) { return ssp_read(obj); } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_NXP/TARGET_LPC43XX/spi_api.c b/targets/TARGET_NXP/TARGET_LPC43XX/spi_api.c index 035ca33bd9..03a8049864 100644 --- a/targets/TARGET_NXP/TARGET_LPC43XX/spi_api.c +++ b/targets/TARGET_NXP/TARGET_LPC43XX/spi_api.c @@ -196,11 +196,12 @@ int spi_master_write(spi_t *obj, int value) { return ssp_read(obj); } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_NXP/TARGET_LPC81X/spi_api.c b/targets/TARGET_NXP/TARGET_LPC81X/spi_api.c index aabe492697..88ba0a725f 100644 --- a/targets/TARGET_NXP/TARGET_LPC81X/spi_api.c +++ b/targets/TARGET_NXP/TARGET_LPC81X/spi_api.c @@ -178,11 +178,12 @@ int spi_master_write(spi_t *obj, int value) { return ssp_read(obj); } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_NXP/TARGET_LPC82X/spi_api.c b/targets/TARGET_NXP/TARGET_LPC82X/spi_api.c index 7e6cc51130..892a123ed1 100644 --- a/targets/TARGET_NXP/TARGET_LPC82X/spi_api.c +++ b/targets/TARGET_NXP/TARGET_LPC82X/spi_api.c @@ -174,11 +174,12 @@ int spi_master_write(spi_t *obj, int value) return spi_read(obj); } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_ONSEMI/TARGET_NCS36510/spi_api.c b/targets/TARGET_ONSEMI/TARGET_NCS36510/spi_api.c index db8a906319..646b953796 100644 --- a/targets/TARGET_ONSEMI/TARGET_NCS36510/spi_api.c +++ b/targets/TARGET_ONSEMI/TARGET_NCS36510/spi_api.c @@ -83,11 +83,12 @@ int spi_master_write(spi_t *obj, int value) return(fSpiWriteB(obj, value)); } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_RENESAS/TARGET_RZ_A1H/spi_api.c b/targets/TARGET_RENESAS/TARGET_RZ_A1H/spi_api.c index 7c58d0e0ad..a62d8b38db 100644 --- a/targets/TARGET_RENESAS/TARGET_RZ_A1H/spi_api.c +++ b/targets/TARGET_RENESAS/TARGET_RZ_A1H/spi_api.c @@ -260,11 +260,12 @@ int spi_master_write(spi_t *obj, int value) { return spi_read(obj); } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_RENESAS/TARGET_VK_RZ_A1H/spi_api.c b/targets/TARGET_RENESAS/TARGET_VK_RZ_A1H/spi_api.c index 3207a1be4d..1464aaacd3 100644 --- a/targets/TARGET_RENESAS/TARGET_VK_RZ_A1H/spi_api.c +++ b/targets/TARGET_RENESAS/TARGET_VK_RZ_A1H/spi_api.c @@ -311,11 +311,12 @@ int spi_master_write(spi_t *obj, int value) { return spi_read(obj); } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/spi_api.c b/targets/TARGET_Realtek/TARGET_AMEBA/spi_api.c index cec30a9b3b..90dd72ffd0 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/spi_api.c +++ b/targets/TARGET_Realtek/TARGET_AMEBA/spi_api.c @@ -241,12 +241,13 @@ int spi_master_write (spi_t *obj, int value) return ssi_read(obj); } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_STM/stm_spi_api.c b/targets/TARGET_STM/stm_spi_api.c index e64dafc8fa..f231e3dee9 100644 --- a/targets/TARGET_STM/stm_spi_api.c +++ b/targets/TARGET_STM/stm_spi_api.c @@ -387,12 +387,13 @@ int spi_master_write(spi_t *obj, int value) } } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_Silicon_Labs/TARGET_EFM32/spi_api.c b/targets/TARGET_Silicon_Labs/TARGET_EFM32/spi_api.c index a8d5f2842e..3dab2ecd63 100644 --- a/targets/TARGET_Silicon_Labs/TARGET_EFM32/spi_api.c +++ b/targets/TARGET_Silicon_Labs/TARGET_EFM32/spi_api.c @@ -391,11 +391,12 @@ int spi_master_write(spi_t *obj, int value) return spi_read(obj); } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; diff --git a/targets/TARGET_WIZNET/TARGET_W7500x/spi_api.c b/targets/TARGET_WIZNET/TARGET_W7500x/spi_api.c index 913789cbd4..33aa6798a9 100644 --- a/targets/TARGET_WIZNET/TARGET_W7500x/spi_api.c +++ b/targets/TARGET_WIZNET/TARGET_W7500x/spi_api.c @@ -183,11 +183,12 @@ int spi_master_write(spi_t *obj, int value) { return ssp_read(obj); } -int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length) { +int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, + char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : 0xff; + char out = (i < tx_length) ? tx_buffer[i] : write_fill; char in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in;