From fd43405ffe5d4da0a51ec6436fa4837c47c01dc9 Mon Sep 17 00:00:00 2001 From: Deepika Date: Tue, 11 Jul 2017 15:46:32 -0500 Subject: [PATCH 1/2] Allow user to set dummy tranfer byte for block read --- drivers/SPI.cpp | 11 +++++++++-- drivers/SPI.h | 9 +++++++++ hal/spi_api.h | 3 ++- .../TARGET_MCU_K64F/drivers/fsl_dspi.c | 4 ++-- .../TARGET_MCU_K64F/drivers/fsl_dspi.h | 2 +- .../TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/spi_api.c | 4 ++-- 6 files changed, 25 insertions(+), 8 deletions(-) diff --git a/drivers/SPI.cpp b/drivers/SPI.cpp index 465594dcdd..e432e635a2 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), + _dummy(0x00) { // 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, _dummy); unlock(); return ret; } @@ -115,6 +116,12 @@ void SPI::unlock() { _mutex->unlock(); } +void SPI::dummy(char data) { + lock(); + _dummy = 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..4d502b7a2d 100644 --- a/drivers/SPI.h +++ b/drivers/SPI.h @@ -143,6 +143,14 @@ public: */ virtual void unlock(void); + /** SPI block read dummy data + * SPI requires master to send dummy data, in order to perform read operation. + * Dummy bytes can be different for devices. Example SD Card require 0xFF. + * + * @param dummy Dummy character to be transmitted while read operation + */ + void dummy(char data); + #if DEVICE_SPI_ASYNCH /** Start non-blocking SPI transfer using 8bit buffers. @@ -271,6 +279,7 @@ protected: int _bits; int _mode; int _hz; + char _dummy; private: /* Private acquire function without locking/unlocking diff --git a/hal/spi_api.h b/hal/spi_api.h index 368e7b0e69..065e516a99 100644 --- a/hal/spi_api.h +++ b/hal/spi_api.h @@ -127,11 +127,12 @@ int spi_master_write(spi_t *obj, int value); * @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] dummy Dummy data transmitted while performing 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 dummy); /** Check if a value is available to read * diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/drivers/fsl_dspi.c b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/drivers/fsl_dspi.c index 4bc67d7ad3..ac8b7828bf 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/drivers/fsl_dspi.c +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/drivers/fsl_dspi.c @@ -576,13 +576,13 @@ void DSPI_MasterTransferCreateHandle(SPI_Type *base, handle->userData = userData; } -status_t DSPI_MasterTransferBlocking(SPI_Type *base, dspi_transfer_t *transfer) +status_t DSPI_MasterTransferBlocking(SPI_Type *base, dspi_transfer_t *transfer, char dummy) { assert(transfer); uint16_t wordToSend = 0; uint16_t wordReceived = 0; - uint8_t dummyData = DSPI_DUMMY_DATA; + uint8_t dummyData = dummy; uint8_t bitsPerFrame; uint32_t command; diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/drivers/fsl_dspi.h b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/drivers/fsl_dspi.h index eb730bd13a..e7dd2f35ea 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/drivers/fsl_dspi.h +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/drivers/fsl_dspi.h @@ -1058,7 +1058,7 @@ void DSPI_MasterTransferCreateHandle(SPI_Type *base, * @param transfer Pointer to the dspi_transfer_t structure. * @return status of status_t. */ -status_t DSPI_MasterTransferBlocking(SPI_Type *base, dspi_transfer_t *transfer); +status_t DSPI_MasterTransferBlocking(SPI_Type *base, dspi_transfer_t *transfer, char dummy); /*! * @brief DSPI master transfer data using interrupts. 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..746ebf5f19 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,7 +127,7 @@ 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 dummy) { int total = (tx_length > rx_length) ? tx_length : rx_length; DSPI_MasterTransferBlocking(spi_address[obj->spi.instance], &(dspi_transfer_t){ @@ -135,7 +135,7 @@ int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, cha .rxData = (uint8_t *)rx_buffer, .dataSize = total, .configFlags = kDSPI_MasterCtar0 | kDSPI_MasterPcs0 | kDSPI_MasterPcsContinuous, - }); + }, dummy); DSPI_ClearStatusFlags(spi_address[obj->spi.instance], kDSPI_RxFifoDrainRequestFlag | kDSPI_EndOfQueueFlag); From 1b797e9081472f2d4f743b9b9c644f88d17d8951 Mon Sep 17 00:00:00 2001 From: Deepika Date: Tue, 11 Jul 2017 16:10:14 -0500 Subject: [PATCH 2/2] Closed review comments 1. Doxygen and Grammar related 2. Change dummy to spi_fill 3. Remove NXP driver and add default loop in spi block read (same as all other drivers) --- drivers/SPI.cpp | 8 ++++---- drivers/SPI.h | 13 +++++++------ hal/spi_api.h | 15 ++++++++------- targets/TARGET_ARM_SSG/TARGET_BEETLE/spi_api.c | 5 +++-- .../TARGET_ARM_SSG/TARGET_CM3DS_MPS2/spi_api.c | 4 ++-- targets/TARGET_ARM_SSG/TARGET_IOTSS/spi_api.c | 5 +++-- targets/TARGET_ARM_SSG/TARGET_MPS2/spi_api.c | 5 +++-- .../TARGET_SAM_CortexM0P/spi_api.c | 5 +++-- .../TARGET_Atmel/TARGET_SAM_CortexM4/spi_api.c | 5 +++-- .../TARGET_Freescale/TARGET_K20XX/spi_api.c | 5 +++-- .../TARGET_KLXX/TARGET_KL05Z/spi_api.c | 5 +++-- .../TARGET_KLXX/TARGET_KL25Z/spi_api.c | 5 +++-- .../TARGET_KLXX/TARGET_KL26Z/spi_api.c | 5 +++-- .../TARGET_KLXX/TARGET_KL46Z/spi_api.c | 5 +++-- .../TARGET_K66F/spi_api.c | 5 +++-- .../TARGET_K82F/spi_api.c | 5 +++-- .../TARGET_KL27Z/spi_api.c | 5 +++-- .../TARGET_KL43Z/spi_api.c | 5 +++-- .../TARGET_KL82Z/spi_api.c | 5 +++-- .../TARGET_KW24D/spi_api.c | 5 +++-- .../TARGET_KW41Z/spi_api.c | 5 +++-- .../TARGET_MCU_K22F/spi_api.c | 5 +++-- .../TARGET_MCU_K24F/spi_api.c | 5 +++-- .../TARGET_MCU_K64F/drivers/fsl_dspi.c | 4 ++-- .../TARGET_MCU_K64F/drivers/fsl_dspi.h | 2 +- .../TARGET_MCU_K64F/spi_api.c | 18 +++++++++--------- targets/TARGET_Maxim/TARGET_MAX32600/spi_api.c | 5 +++-- targets/TARGET_Maxim/TARGET_MAX32610/spi_api.c | 5 +++-- targets/TARGET_Maxim/TARGET_MAX32620/spi_api.c | 5 +++-- targets/TARGET_Maxim/TARGET_MAX32625/spi_api.c | 5 +++-- targets/TARGET_Maxim/TARGET_MAX32630/spi_api.c | 5 +++-- .../TARGET_MCU_NRF51822/spi_api.c | 5 +++-- targets/TARGET_NORDIC/TARGET_NRF5/spi_api.c | 5 +++-- targets/TARGET_NUVOTON/TARGET_M451/spi_api.c | 5 +++-- targets/TARGET_NUVOTON/TARGET_NUC472/spi_api.c | 5 +++-- targets/TARGET_NXP/TARGET_LPC11U6X/spi_api.c | 5 +++-- targets/TARGET_NXP/TARGET_LPC11UXX/spi_api.c | 5 +++-- .../TARGET_NXP/TARGET_LPC11XX_11CXX/spi_api.c | 5 +++-- targets/TARGET_NXP/TARGET_LPC13XX/spi_api.c | 5 +++-- targets/TARGET_NXP/TARGET_LPC15XX/spi_api.c | 5 +++-- targets/TARGET_NXP/TARGET_LPC176X/spi_api.c | 5 +++-- .../TARGET_LPC408X/TARGET_LPC4088/spi_api.c | 5 +++-- .../TARGET_LPC408X/TARGET_LPC4088_DM/spi_api.c | 5 +++-- targets/TARGET_NXP/TARGET_LPC43XX/spi_api.c | 5 +++-- targets/TARGET_NXP/TARGET_LPC81X/spi_api.c | 5 +++-- targets/TARGET_NXP/TARGET_LPC82X/spi_api.c | 5 +++-- .../TARGET_ONSEMI/TARGET_NCS36510/spi_api.c | 5 +++-- targets/TARGET_RENESAS/TARGET_RZ_A1H/spi_api.c | 5 +++-- .../TARGET_RENESAS/TARGET_VK_RZ_A1H/spi_api.c | 5 +++-- targets/TARGET_Realtek/TARGET_AMEBA/spi_api.c | 5 +++-- targets/TARGET_STM/stm_spi_api.c | 5 +++-- .../TARGET_Silicon_Labs/TARGET_EFM32/spi_api.c | 5 +++-- targets/TARGET_WIZNET/TARGET_W7500x/spi_api.c | 5 +++-- 53 files changed, 171 insertions(+), 123 deletions(-) diff --git a/drivers/SPI.cpp b/drivers/SPI.cpp index e432e635a2..fc3764e241 100644 --- a/drivers/SPI.cpp +++ b/drivers/SPI.cpp @@ -33,7 +33,7 @@ SPI::SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel) : _bits(8), _mode(0), _hz(1000000), - _dummy(0x00) { + _write_fill(SPI_FILL_CHAR) { // No lock needed in the constructor spi_init(&_spi, mosi, miso, sclk, ssel); @@ -103,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, _dummy); + int ret = spi_master_block_write(&_spi, tx_buffer, tx_length, rx_buffer, rx_length, _write_fill); unlock(); return ret; } @@ -116,9 +116,9 @@ void SPI::unlock() { _mutex->unlock(); } -void SPI::dummy(char data) { +void SPI::set_default_write_value(char data) { lock(); - _dummy = data; + _write_fill = data; unlock(); } diff --git a/drivers/SPI.h b/drivers/SPI.h index 4d502b7a2d..645243070d 100644 --- a/drivers/SPI.h +++ b/drivers/SPI.h @@ -143,13 +143,14 @@ public: */ virtual void unlock(void); - /** SPI block read dummy data - * SPI requires master to send dummy data, in order to perform read operation. - * Dummy bytes can be different for devices. Example SD Card require 0xFF. + /** 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 dummy Dummy character to be transmitted while read operation + * @param data Default character to be transmitted while read operation */ - void dummy(char data); + void set_default_write_value(char data); #if DEVICE_SPI_ASYNCH @@ -279,7 +280,7 @@ protected: int _bits; int _mode; int _hz; - char _dummy; + char _write_fill; private: /* Private acquire function without locking/unlocking diff --git a/hal/spi_api.h b/hal/spi_api.h index 065e516a99..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,17 +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] dummy Dummy data transmitted while performing read + * @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, char dummy); +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/drivers/fsl_dspi.c b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/drivers/fsl_dspi.c index ac8b7828bf..4bc67d7ad3 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/drivers/fsl_dspi.c +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/drivers/fsl_dspi.c @@ -576,13 +576,13 @@ void DSPI_MasterTransferCreateHandle(SPI_Type *base, handle->userData = userData; } -status_t DSPI_MasterTransferBlocking(SPI_Type *base, dspi_transfer_t *transfer, char dummy) +status_t DSPI_MasterTransferBlocking(SPI_Type *base, dspi_transfer_t *transfer) { assert(transfer); uint16_t wordToSend = 0; uint16_t wordReceived = 0; - uint8_t dummyData = dummy; + uint8_t dummyData = DSPI_DUMMY_DATA; uint8_t bitsPerFrame; uint32_t command; diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/drivers/fsl_dspi.h b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/drivers/fsl_dspi.h index e7dd2f35ea..eb730bd13a 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/drivers/fsl_dspi.h +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/drivers/fsl_dspi.h @@ -1058,7 +1058,7 @@ void DSPI_MasterTransferCreateHandle(SPI_Type *base, * @param transfer Pointer to the dspi_transfer_t structure. * @return status of status_t. */ -status_t DSPI_MasterTransferBlocking(SPI_Type *base, dspi_transfer_t *transfer, char dummy); +status_t DSPI_MasterTransferBlocking(SPI_Type *base, dspi_transfer_t *transfer); /*! * @brief DSPI master transfer data using interrupts. 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 746ebf5f19..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, char dummy) { +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, - }, dummy); - - 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 ba8c7d27cb..7899992eb2 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;