![]() |
ADI iSensor FX3 Firmware
v2.9.4-pub
Firmware for the Analog Devices EVAL-ADIS-FX3 IMU Evaluation Platform. This firmware can be compiled using the Cypress EZ USB Suite IDE
|
Header file for all SPI related functions. More...
#include "main.h"
Go to the source code of this file.
Data Structures | |
struct | BitBangSpiConf |
Macros | |
#define | BITBANG_HALFCLOCK_OFFSET 5 |
#define | STALL_COUNT_OFFSET 10 |
#define | GPIO_HIGH (1 << 31)|(1 << 5)|(1 << 4)|(1 << 0) |
#define | GPIO_LOW (1 << 31)|(1 << 5)|(1 << 4) |
Typedefs | |
typedef struct BitBangSpiConf | BitBangSpiConf |
Functions | |
CyU3PReturnStatus_t | AdiGetSpiSettings () |
This function handles vendor commands to get the current SPI configuration from the FX3. More... | |
CyBool_t | AdiSpiUpdate (uint16_t index, uint16_t value, uint16_t length) |
This function handles a vendor command request to update the SPI/DR Pin configuration. More... | |
CyU3PReturnStatus_t | AdiSpiResetFifo (CyBool_t isTx, CyBool_t isRx) |
This function resets the SPI FIFO and disables the SPI block after completion. More... | |
CyU3PSpiConfig_t | AdiGetSpiConfig () |
This function parses the SPI control registers into an easier to work with config struct. More... | |
void | AdiSetSpiWordLength (uint8_t wordLength) |
Sets the SPI controller word length (4 - 32 bits) More... | |
void | AdiPrintSpiConfig (CyU3PSpiConfig_t config) |
Prints a given SPI config over the UART debug port. More... | |
CyU3PReturnStatus_t | AdiRestartSpi () |
This function restarts the SPI controller. More... | |
void | AdiSpiPrepareForTransfer () |
Set up the SPI for a register based transfer. More... | |
void | AdiSpiTransferWord (uint8_t *txBuf, uint8_t *rxBuf) |
Bi-directional SPI transfer function, in register mode. Optimized for speed. More... | |
CyU3PReturnStatus_t | AdiTransferBytes (uint32_t writeData) |
This function performs a protocol agnostic SPI bi-directional SPI transfer of (1, 2, 4) bytes. More... | |
CyU3PReturnStatus_t | AdiWriteRegByte (uint16_t addr, uint8_t data) |
This function writes a single byte of data over the SPI bus. More... | |
CyU3PReturnStatus_t | AdiReadRegBytes (uint16_t addr) |
This function reads a single 16 bit SPI word from a slave device. More... | |
CyU3PReturnStatus_t | AdiBitBangSpiHandler () |
This function handles bit bang SPI requests from the control endpoint. More... | |
Header file for all SPI related functions.
Copyright (c) 2018-2020 Analog Devices, Inc. All Rights Reserved. This software is proprietary to Analog Devices, Inc. and its licensors.
THIS SOFTWARE UTILIZES LIBRARIES DEVELOPED AND MAINTAINED BY CYPRESS INC. THE LICENSE INCLUDED IN THIS REPOSITORY DOES NOT EXTEND TO CYPRESS PROPERTY.
Use of this file is governed by the license agreement included in this repository.
#define BITBANG_HALFCLOCK_OFFSET 5 |
Offset to make the short side of the bitbang SPI match long side. Approx. 62ns per tick
#define GPIO_HIGH (1 << 31)|(1 << 5)|(1 << 4)|(1 << 0) |
Register setting to drive GPIO high (enable (31), drive high (5), drive low (4), out enabled (0))
#define GPIO_LOW (1 << 31)|(1 << 5)|(1 << 4) |
Register setting to drive GPIO low (enable (31), drive high (5), drive low (4))
#define STALL_COUNT_OFFSET 10 |
Offset for bit bang stall time calc
typedef struct BitBangSpiConf BitBangSpiConf |
Structure to store configuration parameters for a bitbang SPI.
CyU3PReturnStatus_t AdiBitBangSpiHandler | ( | ) |
This function handles bit bang SPI requests from the control endpoint.
This function requires all data to have been retrieved from the control endpoint before being called. It parses all the parameters about the current bit bang SPI operation to perform from the transaction. The pins/timing/config is sent from the FX3 API to the firmware with each bitbang SPI transaction.
CyU3PSpiConfig_t AdiGetSpiConfig | ( | ) |
This function parses the SPI control registers into an easier to work with config struct.
This function can be used to ensure synchronization between the SPI controller and the SPI settings in firmware, without having to perform a SPI controller reset operation. Resetting the SPI controller can cause undesired effects on the SPI lines.
CyU3PReturnStatus_t AdiGetSpiSettings | ( | ) |
This function handles vendor commands to get the current SPI configuration from the FX3.
This function allows the FX3 API to verify that the FX3 board has the same SPI settings as the current FX3 connection instance. The current configuration is sent to the PC via EP0.
void AdiPrintSpiConfig | ( | CyU3PSpiConfig_t | config | ) |
Prints a given SPI config over the UART debug port.
config | The SPI config structure to print out. |
CyU3PReturnStatus_t AdiReadRegBytes | ( | uint16_t | addr | ) |
This function reads a single 16 bit SPI word from a slave device.
addr | The address to send to the DUT in the first SPI transaction. |
This function reads a single word over SPI. Note that reads are not "full duplex" and will require a discrete read to set the address to be read from (two 16 bit transactions per read).
CyU3PReturnStatus_t AdiRestartSpi | ( | ) |
This function restarts the SPI controller.
This function can be used to restore hardware SPI functionality after overriding the SPI pins to act as a bit-banged SPI port. This function can be called before or after the SPI controller has been initialized without causing problems. This function may cause erroneous toggles on the SPI lines during the initialization process - be careful to ensure that the connected DUT is not particularly sensitive to extra toggles.
void AdiSetSpiWordLength | ( | uint8_t | wordLength | ) |
Sets the SPI controller word length (4 - 32 bits)
wordLength | The number of bits to transfer in a single SPI transaction |
This function writes directly to the SPI control register. It does not cause the toggle on the chip select line seen using the cypress API for setting the SPI word length.
void AdiSpiPrepareForTransfer | ( | ) |
Set up the SPI for a register based transfer.
The process is as follows:
(1) Disable SPI (2) Disable interrupts (3) Ensure Rx and Tx clear is disabled (4) Clear FIFOs (5) Set the file scope SPI word length variable
CyU3PReturnStatus_t AdiSpiResetFifo | ( | CyBool_t | isTx, |
CyBool_t | isRx | ||
) |
This function resets the SPI FIFO and disables the SPI block after completion.
isTx | Boolean to indicate if you're clearing the TX FIFO |
isRx | Boolean to indicate if you're clearing the RX FIFO |
It is a copy of the private CyU3PSpiResetFifo() function which bypasses some input sanitization which the Cypress libraries perform. This is required due to our high-speed, register-initiated transfers.
void AdiSpiTransferWord | ( | uint8_t * | txBuf, |
uint8_t * | rxBuf | ||
) |
Bi-directional SPI transfer function, in register mode. Optimized for speed.
This function is used to allow for a reduced SPI stall time. Is fairly "unsafe" in that all hardware has to be configured for correct operation, and free, before this function can be called.
CyBool_t AdiSpiUpdate | ( | uint16_t | index, |
uint16_t | value, | ||
uint16_t | length | ||
) |
This function handles a vendor command request to update the SPI/DR Pin configuration.
index | The wIndex from the control endpoint transaction which indicates which parameter to update |
value | The wValue from the control endpoint transaction which holds the SPI value to set for the selected parameter. |
length | The length of the Data In phase of the control endpoint transaction |
This function provides an API for maintaining synchronicity in SPI and data ready triggering settings between the FX3 API and the firmware. Any time a setting is changed on the FX3 API, this function will be invoked to reflect that change.
CyU3PReturnStatus_t AdiTransferBytes | ( | uint32_t | writeData | ) |
This function performs a protocol agnostic SPI bi-directional SPI transfer of (1, 2, 4) bytes.
writeData | The data to transmit on the MOSI line. |
This function performs a bi-directional SPI transfer, on up to 4 bytes of data. The transfer length is determined by the current SPI config word length setting. The data received on the MISO line is placed in USBBuffer[4 - 7] following the transfer.
CyU3PReturnStatus_t AdiWriteRegByte | ( | uint16_t | addr, |
uint8_t | data | ||
) |
This function writes a single byte of data over the SPI bus.
addr | The DUT address to write data to (7 bits). |
data | The byte of data to write to the address |
This function uses the standard iSensor SPI protocol to issue a write command. For the standard iSensor SPI parts, a write is performed in a single 16 bit command, where the first bit clocked out is the write bit (high) followed by the address and data.