WPILibC++  2018.4.1-20180920141831-1187-gd2a5aaa
 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_kOnboardCS0 = 0,
24  HAL_SPI_kOnboardCS1,
25  HAL_SPI_kOnboardCS2,
26  HAL_SPI_kOnboardCS3,
27  HAL_SPI_kMXP
28 };
29 // clang-format on
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
42 void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status);
43 
57 int32_t HAL_TransactionSPI(HAL_SPIPort port, const uint8_t* dataToSend,
58  uint8_t* dataReceived, int32_t size);
59 
71 int32_t HAL_WriteSPI(HAL_SPIPort port, const uint8_t* dataToSend,
72  int32_t sendSize);
73 
89 int32_t HAL_ReadSPI(HAL_SPIPort port, uint8_t* buffer, int32_t count);
90 
96 void HAL_CloseSPI(HAL_SPIPort port);
97 
105 void HAL_SetSPISpeed(HAL_SPIPort port, int32_t speed);
106 
118 void HAL_SetSPIOpts(HAL_SPIPort port, HAL_Bool msbFirst,
119  HAL_Bool sampleOnTrailing, HAL_Bool clkIdleHigh);
120 
126 void HAL_SetSPIChipSelectActiveHigh(HAL_SPIPort port, int32_t* status);
127 
133 void HAL_SetSPIChipSelectActiveLow(HAL_SPIPort port, int32_t* status);
134 
142 int32_t HAL_GetSPIHandle(HAL_SPIPort port);
143 
151 void HAL_SetSPIHandle(HAL_SPIPort port, int32_t handle);
152 
160 void HAL_InitSPIAuto(HAL_SPIPort port, int32_t bufferSize, int32_t* status);
161 
168 void HAL_FreeSPIAuto(HAL_SPIPort port, int32_t* status);
169 
177 void HAL_StartSPIAutoRate(HAL_SPIPort port, double period, int32_t* status);
178 
194 void HAL_StartSPIAutoTrigger(HAL_SPIPort port, HAL_Handle digitalSourceHandle,
195  HAL_AnalogTriggerType analogTriggerType,
196  HAL_Bool triggerRising, HAL_Bool triggerFalling,
197  int32_t* status);
198 
205 void HAL_StopSPIAuto(HAL_SPIPort port, int32_t* status);
206 
217 void HAL_SetSPIAutoTransmitData(HAL_SPIPort port, const uint8_t* dataToSend,
218  int32_t dataSize, int32_t zeroSize,
219  int32_t* status);
220 
227 void HAL_ForceSPIAutoRead(HAL_SPIPort port, int32_t* status);
228 
239 int32_t HAL_ReadSPIAutoReceivedData(HAL_SPIPort port, uint8_t* buffer,
240  int32_t numToRead, double timeout,
241  int32_t* status);
242 
250 int32_t HAL_GetSPIAutoDroppedCount(HAL_SPIPort port, int32_t* status);
251 
252 #ifdef __cplusplus
253 } // extern "C"
254 #endif
255 
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.