WPILibC++ 2024.3.2
DIO.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <stdint.h>
8
9#include "hal/Types.h"
10
11/**
12 * @defgroup hal_dio DIO Functions
13 * @ingroup hal_capi
14 * @{
15 */
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21/**
22 * Creates a new instance of a digital port.
23 *
24 * @param[in] portHandle the port handle to create from
25 * @param[in] input true for input, false for output
26 * @param[in] allocationLocation the location where the allocation is occurring
27 * (can be null)
28 * @param[out] status Error status variable. 0 on success.
29 * @return the created digital handle
30 */
32 HAL_Bool input,
33 const char* allocationLocation,
34 int32_t* status);
35
36/**
37 * Checks if a DIO channel is valid.
38 *
39 * @param channel the channel number to check
40 * @return true if the channel is valid, otherwise false
41 */
43
44/**
45 * Frees a DIO port.
46 *
47 * @param dioPortHandle the DIO channel handle
48 */
50
51/**
52 * Indicates the DIO channel is used by a simulated device.
53 *
54 * @param handle the DIO channel handle
55 * @param device simulated device handle
56 */
58
59/**
60 * Allocates a DO PWM Generator.
61 *
62 * @param[out] status Error status variable. 0 on success.
63 * @return the allocated digital PWM handle
64 */
66
67/**
68 * Frees the resource associated with a DO PWM generator.
69 *
70 * @param[in] pwmGenerator the digital PWM handle
71 * @param[out] status Error status variable. 0 on success.
72 */
73void HAL_FreeDigitalPWM(HAL_DigitalPWMHandle pwmGenerator, int32_t* status);
74
75/**
76 * Changes the frequency of the DO PWM generator.
77 *
78 * The valid range is from 0.6 Hz to 19 kHz.
79 *
80 * The frequency resolution is logarithmic.
81 *
82 * @param[in] rate the frequency to output all digital output PWM signals
83 * @param[out] status Error status variable. 0 on success.
84 */
85void HAL_SetDigitalPWMRate(double rate, int32_t* status);
86
87/**
88 * Configures the duty-cycle of the PWM generator.
89 *
90 * @param[in] pwmGenerator the digital PWM handle
91 * @param[in] dutyCycle the percent duty cycle to output [0..1]
92 * @param[out] status Error status variable. 0 on success.
93 */
95 double dutyCycle, int32_t* status);
96
97/**
98 * Configures the digital PWM to be a PPS signal with specified duty cycle.
99 *
100 * @param[in] pwmGenerator the digital PWM handle
101 * @param[in] dutyCycle the percent duty cycle to output [0..1]
102 * @param[out] status Error status variable. 0 on success.
103 */
104void HAL_SetDigitalPWMPPS(HAL_DigitalPWMHandle pwmGenerator, double dutyCycle,
105 int32_t* status);
106
107/**
108 * Configures which DO channel the PWM signal is output on.
109 *
110 * @param[in] pwmGenerator the digital PWM handle
111 * @param[in] channel the channel to output on
112 * @param[out] status Error status variable. 0 on success.
113 */
115 int32_t channel, int32_t* status);
116
117/**
118 * Writes a digital value to a DIO channel.
119 *
120 * @param[in] dioPortHandle the digital port handle
121 * @param[in] value the state to set the digital channel (if it is
122 * configured as an output)
123 * @param[out] status Error status variable. 0 on success.
124 */
125void HAL_SetDIO(HAL_DigitalHandle dioPortHandle, HAL_Bool value,
126 int32_t* status);
127
128/**
129 * Sets the direction of a DIO channel.
130 *
131 * @param[in] dioPortHandle the digital port handle
132 * @param[in] input true to set input, false for output
133 * @param[out] status Error status variable. 0 on success.
134 */
136 int32_t* status);
137
138/**
139 * Reads a digital value from a DIO channel.
140 *
141 * @param[in] dioPortHandle the digital port handle
142 * @param[out] status Error status variable. 0 on success.
143 * @return the state of the specified channel
144 */
145HAL_Bool HAL_GetDIO(HAL_DigitalHandle dioPortHandle, int32_t* status);
146
147/**
148 * Reads the direction of a DIO channel.
149 *
150 * @param[in] dioPortHandle the digital port handle
151 * @param[out] status Error status variable. 0 on success.
152 * @return true for input, false for output
153 */
154HAL_Bool HAL_GetDIODirection(HAL_DigitalHandle dioPortHandle, int32_t* status);
155
156/**
157 * Generates a single digital pulse.
158 *
159 * Write a pulse to the specified digital output channel. There can only be a
160 * single pulse going at any time.
161 *
162 * @param[in] dioPortHandle the digital port handle
163 * @param[in] pulseLengthSeconds the active length of the pulse (in seconds)
164 * @param[out] status Error status variable. 0 on success.
165 */
166void HAL_Pulse(HAL_DigitalHandle dioPortHandle, double pulseLengthSeconds,
167 int32_t* status);
168
169/**
170 * Generates a single digital pulse on multiple channels.
171 *
172 * Write a pulse to the channels enabled by the mask. There can only be a
173 * single pulse going at any time.
174 *
175 * @param[in] channelMask the channel mask
176 * @param[in] pulseLengthSeconds the active length of the pulse (in seconds)
177 * @param[out] status Error status variable. 0 on success.
178 */
179void HAL_PulseMultiple(uint32_t channelMask, double pulseLengthSeconds,
180 int32_t* status);
181
182/**
183 * Checks a DIO line to see if it is currently generating a pulse.
184 *
185 * @param[in] dioPortHandle the digital port handle
186 * @param[out] status Error status variable. 0 on success.
187 * @return true if a pulse is in progress, otherwise false
188 */
189HAL_Bool HAL_IsPulsing(HAL_DigitalHandle dioPortHandle, int32_t* status);
190
191/**
192 * Checks if any DIO line is currently generating a pulse.
193 *
194 * @param[out] status Error status variable. 0 on success.
195 * @return true if a pulse on some line is in progress
196 */
197HAL_Bool HAL_IsAnyPulsing(int32_t* status);
198
199/**
200 * Writes the filter index from the FPGA.
201 *
202 * Set the filter index used to filter out short pulses.
203 *
204 * @param[in] dioPortHandle the digital port handle
205 * @param[in] filterIndex the filter index (Must be in the range 0 - 3, where
206 * 0 means "none" and 1 - 3 means filter # filterIndex
207 * - 1)
208 * @param[out] status Error status variable. 0 on success.
209 */
210void HAL_SetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t filterIndex,
211 int32_t* status);
212
213/**
214 * Reads the filter index from the FPGA.
215 *
216 * Gets the filter index used to filter out short pulses.
217 *
218 * @param[in] dioPortHandle the digital port handle
219 * @param[out] status Error status variable. 0 on success.
220 * @return filterIndex the filter index (Must be in the range 0 - 3, where 0
221 * means "none" and 1 - 3 means filter # filterIndex - 1)
222 */
223int32_t HAL_GetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t* status);
224
225/**
226 * Sets the filter period for the specified filter index.
227 *
228 * Sets the filter period in FPGA cycles. Even though there are 2 different
229 * filter index domains (MXP vs HDR), ignore that distinction for now since it
230 * complicates the interface. That can be changed later.
231 *
232 * @param[in] filterIndex the filter index, 0 - 2
233 * @param[in] value the number of cycles that the signal must not
234 * transition to be counted as a transition.
235 * @param[out] status Error status variable. 0 on success.
236 */
237void HAL_SetFilterPeriod(int32_t filterIndex, int64_t value, int32_t* status);
238
239/**
240 * Gets the filter period for the specified filter index.
241 *
242 * Gets the filter period in FPGA cycles. Even though there are 2 different
243 * filter index domains (MXP vs HDR), ignore that distinction for now since it
244 * complicates the interface. Set status to NiFpga_Status_SoftwareFault if the
245 * filter values mismatch.
246 *
247 * @param[in] filterIndex the filter index, 0 - 2
248 * @param[out] status Error status variable. 0 on success.
249 * @return The number of FPGA cycles of the filter period.
250 */
251int64_t HAL_GetFilterPeriod(int32_t filterIndex, int32_t* status);
252#ifdef __cplusplus
253} // extern "C"
254#endif
255/** @} */
void HAL_SetDIOSimDevice(HAL_DigitalHandle handle, HAL_SimDeviceHandle device)
Indicates the DIO channel is used by a simulated device.
void HAL_SetDIO(HAL_DigitalHandle dioPortHandle, HAL_Bool value, int32_t *status)
Writes a digital value to a DIO channel.
HAL_Bool HAL_GetDIODirection(HAL_DigitalHandle dioPortHandle, int32_t *status)
Reads the direction of a DIO channel.
void HAL_PulseMultiple(uint32_t channelMask, double pulseLengthSeconds, int32_t *status)
Generates a single digital pulse on multiple channels.
HAL_Bool HAL_GetDIO(HAL_DigitalHandle dioPortHandle, int32_t *status)
Reads a digital value from a DIO channel.
HAL_Bool HAL_IsAnyPulsing(int32_t *status)
Checks if any DIO line is currently generating a pulse.
void HAL_SetDigitalPWMPPS(HAL_DigitalPWMHandle pwmGenerator, double dutyCycle, int32_t *status)
Configures the digital PWM to be a PPS signal with specified duty cycle.
void HAL_SetDigitalPWMDutyCycle(HAL_DigitalPWMHandle pwmGenerator, double dutyCycle, int32_t *status)
Configures the duty-cycle of the PWM generator.
HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle, HAL_Bool input, const char *allocationLocation, int32_t *status)
Creates a new instance of a digital port.
void HAL_SetDigitalPWMRate(double rate, int32_t *status)
Changes the frequency of the DO PWM generator.
int64_t HAL_GetFilterPeriod(int32_t filterIndex, int32_t *status)
Gets the filter period for the specified filter index.
void HAL_Pulse(HAL_DigitalHandle dioPortHandle, double pulseLengthSeconds, int32_t *status)
Generates a single digital pulse.
void HAL_FreeDIOPort(HAL_DigitalHandle dioPortHandle)
Frees a DIO port.
HAL_Bool HAL_IsPulsing(HAL_DigitalHandle dioPortHandle, int32_t *status)
Checks a DIO line to see if it is currently generating a pulse.
void HAL_FreeDigitalPWM(HAL_DigitalPWMHandle pwmGenerator, int32_t *status)
Frees the resource associated with a DO PWM generator.
HAL_DigitalPWMHandle HAL_AllocateDigitalPWM(int32_t *status)
Allocates a DO PWM Generator.
HAL_Bool HAL_CheckDIOChannel(int32_t channel)
Checks if a DIO channel is valid.
int32_t HAL_GetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t *status)
Reads the filter index from the FPGA.
void HAL_SetFilterPeriod(int32_t filterIndex, int64_t value, int32_t *status)
Sets the filter period for the specified filter index.
void HAL_SetDIODirection(HAL_DigitalHandle dioPortHandle, HAL_Bool input, int32_t *status)
Sets the direction of a DIO channel.
void HAL_SetDigitalPWMOutputChannel(HAL_DigitalPWMHandle pwmGenerator, int32_t channel, int32_t *status)
Configures which DO channel the PWM signal is output on.
void HAL_SetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t filterIndex, int32_t *status)
Writes the filter index from the FPGA.
int32_t HAL_Bool
Definition: Types.h:73
HAL_Handle HAL_PortHandle
Definition: Types.h:19
HAL_Handle HAL_SimDeviceHandle
Definition: Types.h:53
HAL_Handle HAL_DigitalPWMHandle
Definition: Types.h:33
HAL_Handle HAL_DigitalHandle
Definition: Types.h:31