Sample SPI drivers for a number of the Adesto Technologies flash devices.
spi_driver.h
Go to the documentation of this file.
1 /*
2  * The Clear BSD License
3  * Copyright (c) 2018 Adesto Technologies Corporation, Inc
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without modification,
7  * are permitted (subject to the limitations in the disclaimer below) provided
8  * that the following conditions are met:
9  *
10  * o Redistributions of source code must retain the above copyright notice, this list
11  * of conditions and the following disclaimer.
12  *
13  * o Redistributions in binary form must reproduce the above copyright notice, this
14  * list of conditions and the following disclaimer in the documentation and/or
15  * other materials provided with the distribution.
16  *
17  * o Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived from this
19  * software without specific prior written permission.
20  *
21  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24  * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
25  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
50 #ifndef SPI_DRIVER_H_
51 #define SPI_DRIVER_H_
52 
53 #include "user_config.h"
54 
61 #define SPI_CSB_PORT USER_CONFIG_CSB_PORT
62 
65 #define SPI_TRIGGER_PORT USER_CONFIG_TRIGGER_PORT
66 
69 #define SPI_SCK_PORT USER_CONFIG_SCK_PORT
70 
73 #define SPI_MOSI_PORT USER_CONFIG_MOSI_PORT
74 
77 #define SPI_MISO_PORT USER_CONFIG_MISO_PORT
78 
81 #define SPI_WPB_PORT USER_CONFIG_IO2_PORT
82 
85 #define SPI_HOLDB_PORT USER_CONFIG_IO3_PORT
86 
94 #define SPI_CSB_PIN USER_CONFIG_CSB_PIN
95 #define SPI_TRIGGER_PIN USER_CONFIG_TRIGGER_PIN
97 #define SPI_SCK_PIN USER_CONFIG_SCK_PIN
99 #define SPI_MOSI_PIN USER_CONFIG_MOSI_PIN
101 #define SPI_MISO_PIN USER_CONFIG_MISO_PIN
103 #define SPI_WPB_PIN USER_CONFIG_IO2_PIN
105 #define SPI_HOLDB_PIN USER_CONFIG_IO3_PIN
107 #define DELAY 5U
109 
110 #define SPI 0
111 #define QPI 1
112 
122 void SPI_PinInit(uint32_t port, uint32_t pin, enum directionIO direction);
123 
132 void SPI_PinClear(uint32_t port, uint32_t pin);
133 
142 void SPI_PinSet(uint32_t port, uint32_t pin);
143 
152 uint32_t SPI_PinRead(uint32_t port, uint32_t pin);
153 
168 void SPI_Exchange(uint8_t *txBuffer,
169  uint32_t txNumBytes,
170  uint8_t *rxBuffer,
171  uint32_t rxNumBytes,
172  uint32_t dummyNumBytes);
173 
192 void SPI_DualExchange(uint8_t standardSPINumBytes,
193  uint8_t *txBuffer,
194  uint32_t txNumBytes,
195  uint8_t *rxBuffer,
196  uint32_t rxNumBytes,
197  uint32_t dummyNumBytes);
198 
217 void SPI_QuadExchange(uint8_t standardSPINumBytes,
218  uint8_t *txBuffer,
219  uint32_t txNumBytes,
220  uint8_t *rxBuffer,
221  uint32_t rxNumBytes,
222  uint32_t dummyNumBytes);
223 
229 uint8_t SPI_ReceiveByte();
230 
236 uint8_t SPI_DualReceiveByte();
237 
244 void SPI_SendByte(uint8_t transmittedByte);
245 
252 void SPI_DualSendByte(uint8_t transmittedByte);
253 
259 void SPI_ClockTick();
260 
267 void SPI_SendBit(uint8_t transmittedBit);
268 
275 void SPI_Delay(uint32_t delayTime);
276 
291 
298 
310 
322 
334 
345 
352 void SPI_QuadSendByte(uint8_t transmittedByte);
353 
360 uint8_t SPI_QuadReceiveByte();
361 
367 void SPI_Trigger();
368 
376 void SPI_JEDECReset();
377 
378 #endif /* SPI_DRIVER_H_ */
void SPI_ConfigureQuadSPIIOsOutput()
Configures SPIO IOs for quad output. This changes the MISO pin to an output so that the master can dr...
Definition: spi_driver.c:128
Project declarations exist here.
uint8_t SPI_ReceiveByte()
Receives a byte along MISO and returns the value received.
Definition: spi_driver.c:251
void SPI_ConfigureQuadSPIIOsInput()
Configures SPIO IOs for quad input. This changes the MOSI, WPb, and HOLDb pins to inputs so that the ...
Definition: spi_driver.c:108
void SPI_DualExchange(uint8_t standardSPINumBytes, uint8_t *txBuffer, uint32_t txNumBytes, uint8_t *rxBuffer, uint32_t rxNumBytes, uint32_t dummyNumBytes)
Sends and receives bytes based on the function parameters. MOSI is used for the opcode and address...
Definition: spi_driver.c:355
void SPI_ClockTick()
Toggles the clock: current_state->high->low.
Definition: spi_driver.c:149
void SPI_JEDECReset()
Performs a JEDEC reset on the SPI device.
Definition: spi_driver.c:492
void SPI_Delay(uint32_t delayTime)
Performs a delayTime number of NOPs.
Definition: spi_driver.c:140
void SPI_PinInit(uint32_t port, uint32_t pin, enum directionIO direction)
Initializes a given pin as either an input or output.
Definition: spi_driver.c:43
uint32_t SPI_PinRead(uint32_t port, uint32_t pin)
Reads the voltage on a given pin.
Definition: spi_driver.c:56
void SPI_PinClear(uint32_t port, uint32_t pin)
Clears a given pin on a port to LOW.
Definition: spi_driver.c:47
void SPI_ConfigureDualSPIIOsOutput()
Configures SPIO IOs for dual output. This changes the MISO pin from an input to an output so that the...
Definition: spi_driver.c:121
uint8_t SPI_QuadReceiveByte()
Receives a byte along MOSI, MISO, HOLDb, and WPb and returns the value received.
Definition: spi_driver.c:292
directionIO
Enumeration used when initializing pins as inputs or outputs. OUTPUT = 0, INPUT = 1...
Definition: user_config.h:205
void SPI_SendBit(uint8_t transmittedBit)
Sends a single bit along MOSI while toggling the clock.
Definition: spi_driver.c:157
void SPI_DualSendByte(uint8_t transmittedByte)
Sends a byte along both MOSI and MISO.
Definition: spi_driver.c:180
void SPI_SendByte(uint8_t transmittedByte)
Sends a byte along MOSI.
Definition: spi_driver.c:170
void SPI_ReturnToSingleSPIIOs()
Returns MISO and MOSI pins to their standard SPI state as an input and output.
Definition: spi_driver.c:85
void SPI_QuadExchange(uint8_t standardSPINumBytes, uint8_t *txBuffer, uint32_t txNumBytes, uint8_t *rxBuffer, uint32_t rxNumBytes, uint32_t dummyNumBytes)
Sends and receives bytes based on the function parameters. MOSI can used for the opcode and address...
Definition: spi_driver.c:406
void SPI_ConfigureSingleSPIIOs()
Configure the IOs for SPI bit banging usage. 4 pins are needed: CSb, SCK, MOSI, MISO.
Definition: spi_driver.c:61
void SPI_Trigger()
Triggers a falling edge on the SPI_TRIGGER_PORT/PIN output.
Definition: spi_driver.c:485
uint8_t SPI_DualReceiveByte()
Receives a byte along both MOSI and MISO and returns the value received.
Definition: spi_driver.c:268
void SPI_Exchange(uint8_t *txBuffer, uint32_t txNumBytes, uint8_t *rxBuffer, uint32_t rxNumBytes, uint32_t dummyNumBytes)
Sends and receives bytes based on the function parameters. MISO and MOSI fill their standard SPI role...
Definition: spi_driver.c:325
void SPI_PinSet(uint32_t port, uint32_t pin)
Sets a given pin on a port to HIGH.
Definition: spi_driver.c:51
void SPI_ConfigureDualSPIIOsInput()
Configures SPIO IOs for dual input. This changes the MOSI pin from an output to an input so that the ...
Definition: spi_driver.c:101
void SPI_QuadSendByte(uint8_t transmittedByte)
Sends a byte along MISO, MOSI, WPb, and HOLDb.
Definition: spi_driver.c:211