WPILibC++  2018.4.1-20180924024742-1199-gb1965f7
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
SPI.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <stdint.h>
11 
12 #include "hal/AnalogTrigger.h"
13 #include "hal/Types.h"
14 
21 // clang-format off
22 HAL_ENUM(HAL_SPIPort) {
23  HAL_SPI_kInvalid = -1,
24  HAL_SPI_kOnboardCS0,
25  HAL_SPI_kOnboardCS1,
26  HAL_SPI_kOnboardCS2,
27  HAL_SPI_kOnboardCS3,
28  HAL_SPI_kMXP
29 };
30 // clang-format on
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
43 void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status);
44 
58 int32_t HAL_TransactionSPI(HAL_SPIPort port, const uint8_t* dataToSend,
59  uint8_t* dataReceived, int32_t size);
60 
72 int32_t HAL_WriteSPI(HAL_SPIPort port, const uint8_t* dataToSend,
73  int32_t sendSize);
74 
90 int32_t HAL_ReadSPI(HAL_SPIPort port, uint8_t* buffer, int32_t count);
91 
97 void HAL_CloseSPI(HAL_SPIPort port);
98 
106 void HAL_SetSPISpeed(HAL_SPIPort port, int32_t speed);
107 
119 void HAL_SetSPIOpts(HAL_SPIPort port, HAL_Bool msbFirst,
120  HAL_Bool sampleOnTrailing, HAL_Bool clkIdleHigh);
121 
127 void HAL_SetSPIChipSelectActiveHigh(HAL_SPIPort port, int32_t* status);
128 
134 void HAL_SetSPIChipSelectActiveLow(HAL_SPIPort port, int32_t* status);
135 
143 int32_t HAL_GetSPIHandle(HAL_SPIPort port);
144 
152 void HAL_SetSPIHandle(HAL_SPIPort port, int32_t handle);
153 
161 void HAL_InitSPIAuto(HAL_SPIPort port, int32_t bufferSize, int32_t* status);
162 
169 void HAL_FreeSPIAuto(HAL_SPIPort port, int32_t* status);
170 
178 void HAL_StartSPIAutoRate(HAL_SPIPort port, double period, int32_t* status);
179 
195 void HAL_StartSPIAutoTrigger(HAL_SPIPort port, HAL_Handle digitalSourceHandle,
196  HAL_AnalogTriggerType analogTriggerType,
197  HAL_Bool triggerRising, HAL_Bool triggerFalling,
198  int32_t* status);
199 
206 void HAL_StopSPIAuto(HAL_SPIPort port, int32_t* status);
207 
218 void HAL_SetSPIAutoTransmitData(HAL_SPIPort port, const uint8_t* dataToSend,
219  int32_t dataSize, int32_t zeroSize,
220  int32_t* status);
221 
228 void HAL_ForceSPIAutoRead(HAL_SPIPort port, int32_t* status);
229 
240 int32_t HAL_ReadSPIAutoReceivedData(HAL_SPIPort port, uint8_t* buffer,
241  int32_t numToRead, double timeout,
242  int32_t* status);
243 
251 int32_t HAL_GetSPIAutoDroppedCount(HAL_SPIPort port, int32_t* status);
252 
253 #ifdef __cplusplus
254 } // extern "C"
255 #endif
256 
void HAL_ForceSPIAutoRead(HAL_SPIPort port, int32_t *status)
Immediately forces an SPI read to happen.
void HAL_SetSPIOpts(HAL_SPIPort port, HAL_Bool msbFirst, HAL_Bool sampleOnTrailing, HAL_Bool clkIdleHigh)
Sets the SPI options.
void HAL_SetSPIAutoTransmitData(HAL_SPIPort port, const uint8_t *dataToSend, int32_t dataSize, int32_t zeroSize, int32_t *status)
Sets the data to be transmitted to the device to initiate a read.
void HAL_SetSPIChipSelectActiveLow(HAL_SPIPort port, int32_t *status)
Sets the CS Active low for a SPI port.
int32_t HAL_TransactionSPI(HAL_SPIPort port, const uint8_t *dataToSend, uint8_t *dataReceived, int32_t size)
Performs an SPI send/receive transaction.
void HAL_InitializeSPI(HAL_SPIPort port, int32_t *status)
Initializes the SPI port.
void HAL_FreeSPIAuto(HAL_SPIPort port, int32_t *status)
Frees an SPI automatic accumulator.
void HAL_SetSPIHandle(HAL_SPIPort port, int32_t handle)
Sets the stored handle for a SPI port.
int32_t HAL_ReadSPIAutoReceivedData(HAL_SPIPort port, uint8_t *buffer, int32_t numToRead, double timeout, int32_t *status)
Reads data received by the SPI accumulator.
void HAL_InitSPIAuto(HAL_SPIPort port, int32_t bufferSize, int32_t *status)
Initializes the SPI automatic accumulator.
int32_t HAL_GetSPIAutoDroppedCount(HAL_SPIPort port, int32_t *status)
Gets the count of how many SPI accumulations have been missed.
int32_t HAL_GetSPIHandle(HAL_SPIPort port)
Gets the stored handle for a SPI port.
void HAL_StopSPIAuto(HAL_SPIPort port, int32_t *status)
Stops an automatic SPI accumlation.
void HAL_CloseSPI(HAL_SPIPort port)
Closes the SPI port.
void HAL_StartSPIAutoRate(HAL_SPIPort port, double period, int32_t *status)
Sets the period for automatic SPI accumulation.
void HAL_SetSPISpeed(HAL_SPIPort port, int32_t speed)
Sets the clock speed for the SPI bus.
int32_t HAL_WriteSPI(HAL_SPIPort port, const uint8_t *dataToSend, int32_t sendSize)
Executes a write transaction with the device.
void HAL_StartSPIAutoTrigger(HAL_SPIPort port, HAL_Handle digitalSourceHandle, HAL_AnalogTriggerType analogTriggerType, HAL_Bool triggerRising, HAL_Bool triggerFalling, int32_t *status)
Starts the auto SPI accumulator on a specific trigger.
int32_t HAL_ReadSPI(HAL_SPIPort port, uint8_t *buffer, int32_t count)
Executes a read from the device.
void HAL_SetSPIChipSelectActiveHigh(HAL_SPIPort port, int32_t *status)
Sets the CS Active high for a SPI port.