Platform drivers for Mbed.

Dependents:   EVAL-CN0535-FMCZ EVAL-CN0535-FMCZ EVAL-AD568x-AD569x EVAL-AD7606 ... more

Revision:
15:fd2c3c3038bf
Parent:
14:46aad38346a6
--- a/src/spi.cpp	Fri Oct 16 21:23:58 2020 +0530
+++ b/src/spi.cpp	Fri Feb 19 15:53:52 2021 +0530
@@ -25,15 +25,12 @@
 /********************** Macros and Constants Definitions **********************/
 /******************************************************************************/
 
-#define		SPI_16_BIT_FRAME		16		// SPI 16-bit frame size
 #define		SPI_8_BIT_FRAME			8		// SPI 8-bit frame size
 
 /******************************************************************************/
 /********************** Variables and User defined data types *****************/
 /******************************************************************************/
 
-static uint8_t spi_format_bytes = SPI_16_BIT_FRAME;   	// SPI format
-
 /******************************************************************************/
 /************************ Functions Declarations ******************************/
 /******************************************************************************/
@@ -100,8 +97,7 @@
 		    SPI frequency is required, consult your device documentation.
 		  **/
 		spi->frequency(param->max_speed_hz);
-		spi->format(SPI_16_BIT_FRAME, param->mode);  // data write/read format
-		spi_format_bytes = SPI_16_BIT_FRAME;
+		spi->format(SPI_8_BIT_FRAME, param->mode);   // data write/read format
 		spi->set_default_write_value(0x00);          // code to write when reading back
 		ss->write(GPIO_HIGH);                        // set SS high
 
@@ -158,61 +154,13 @@
 {
 	mbed::SPI *spi; 			// pointer to new spi instance
 	mbed::DigitalOut *ss;  		// pointer to new SS instance
-	uint16_t num_of_words;		// Number of words in SPI frame
-	uint16_t rw_data;			// SPI read data (16-bit)
-	uint16_t data_index = 0;	// Data index
-	size_t byte;				// Byte read/write index
 
 	if (desc) {
 		spi = (SPI *)(((mbed_spi_desc *)(desc->extra))->spi_port);
 		ss = (DigitalOut *)(((mbed_spi_desc *)(desc->extra))->slave_select);
 
-		/* Get the total number of words (16-bit) */
-		num_of_words = bytes_number / 2;
-
-		/* Determine the data transmit/receive format based on parity of data */
-		if (!(bytes_number % 2)) {
-			if (spi_format_bytes != SPI_16_BIT_FRAME) {
-				spi->format(SPI_16_BIT_FRAME, desc->mode);
-				spi_format_bytes = SPI_16_BIT_FRAME;
-			}
-		} else {
-			if (spi_format_bytes != SPI_8_BIT_FRAME) {
-				spi->format(SPI_8_BIT_FRAME, desc->mode);
-				spi_format_bytes = SPI_8_BIT_FRAME;
-			}
-		}
-
 		ss->write(GPIO_LOW);
-
-		/* **Note: It is not possible to change the format of data transfer when SPI
-		 * communication is in progress. If format is attempted to change (from 8-bit
-		 * to 16-bit or vice a versa), the SPI communication is reset and master generates
-		 * a single Clock signal during format change. This triggers false transfer on slave
-		 * which results into incorrect data transfer. For this reason, the bytes with even parity
-		 * are transferred in 16-bit format and odd parity bytes are transferred in 8-bit format.
-		 * Application layer doesn't have any control to stop SPI reset during format change. */
-
-		if (!(bytes_number % 2)) {
-			while (num_of_words) {
-				/* Form a 16-bit data to be written (LE format) */
-				rw_data = ((uint16_t)data[data_index + 1] | ((uint16_t)data[data_index] << 8));
-
-				/* Transmit a 16-bit data over SPI */
-				rw_data =  (uint16_t)spi->write(rw_data);
-
-				/* Extract the MSB and LSB from 16-bit read data (LE format) */
-				data[data_index++] = (uint8_t)(rw_data >> 8);
-				data[data_index++] = (uint8_t)rw_data;
-
-				num_of_words--;
-			}
-		} else {
-			for (byte = 0; byte < bytes_number; byte++) {
-				data[byte] =  spi->write(data[byte]);
-			}
-		}
-
+		spi->write((const char *)data, bytes_number, (char *)data, bytes_number);
 		ss->write(GPIO_HIGH);
 
 		return SUCCESS;