WPILibC++ 2025.2.1
Loading...
Searching...
No Matches
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 */
73
74/**
75 * Changes the frequency of the DO PWM generator.
76 *
77 * The valid range is from 0.6 Hz to 19 kHz.
78 *
79 * The frequency resolution is logarithmic.
80 *
81 * @param[in] rate the frequency to output all digital output PWM signals
82 * @param[out] status Error status variable. 0 on success.
83 */
84void HAL_SetDigitalPWMRate(double rate, int32_t* status);
85
86/**
87 * Configures the duty-cycle of the PWM generator.
88 *
89 * @param[in] pwmGenerator the digital PWM handle
90 * @param[in] dutyCycle the percent duty cycle to output [0..1]
91 * @param[out] status Error status variable. 0 on success.
92 */
94 double dutyCycle, int32_t* status);
95
96/**
97 * Configures the digital PWM to be a PPS signal with specified duty cycle.
98 *
99 * @param[in] pwmGenerator the digital PWM handle
100 * @param[in] dutyCycle the percent duty cycle to output [0..1]
101 * @param[out] status Error status variable. 0 on success.
102 */
103void HAL_SetDigitalPWMPPS(HAL_DigitalPWMHandle pwmGenerator, double dutyCycle,
104 int32_t* status);
105
106/**
107 * Configures which DO channel the PWM signal is output on.
108 *
109 * @param[in] pwmGenerator the digital PWM handle
110 * @param[in] channel the channel to output on
111 * @param[out] status Error status variable. 0 on success.
112 */
114 int32_t channel, int32_t* status);
115
116/**
117 * Writes a digital value to a DIO channel.
118 *
119 * @param[in] dioPortHandle the digital port handle
120 * @param[in] value the state to set the digital channel (if it is
121 * configured as an output)
122 * @param[out] status Error status variable. 0 on success.
123 */
124void HAL_SetDIO(HAL_DigitalHandle dioPortHandle, HAL_Bool value,
125 int32_t* status);
126
127/**
128 * Sets the direction of a DIO channel.
129 *
130 * @param[in] dioPortHandle the digital port handle
131 * @param[in] input true to set input, false for output
132 * @param[out] status Error status variable. 0 on success.
133 */
135 int32_t* status);
136
137/**
138 * Reads a digital value from a DIO channel.
139 *
140 * @param[in] dioPortHandle the digital port handle
141 * @param[out] status Error status variable. 0 on success.
142 * @return the state of the specified channel
143 */
144HAL_Bool HAL_GetDIO(HAL_DigitalHandle dioPortHandle, int32_t* status);
145
146/**
147 * Reads the direction of a DIO channel.
148 *
149 * @param[in] dioPortHandle the digital port handle
150 * @param[out] status Error status variable. 0 on success.
151 * @return true for input, false for output
152 */
153HAL_Bool HAL_GetDIODirection(HAL_DigitalHandle dioPortHandle, int32_t* status);
154
155/**
156 * Generates a single digital pulse.
157 *
158 * Write a pulse to the specified digital output channel. There can only be a
159 * single pulse going at any time.
160 *
161 * @param[in] dioPortHandle the digital port handle
162 * @param[in] pulseLengthSeconds the active length of the pulse (in seconds)
163 * @param[out] status Error status variable. 0 on success.
164 */
165void HAL_Pulse(HAL_DigitalHandle dioPortHandle, double pulseLengthSeconds,
166 int32_t* status);
167
168/**
169 * Generates a single digital pulse on multiple channels.
170 *
171 * Write a pulse to the channels enabled by the mask. There can only be a
172 * single pulse going at any time.
173 *
174 * @param[in] channelMask the channel mask
175 * @param[in] pulseLengthSeconds the active length of the pulse (in seconds)
176 * @param[out] status Error status variable. 0 on success.
177 */
178void HAL_PulseMultiple(uint32_t channelMask, double pulseLengthSeconds,
179 int32_t* status);
180
181/**
182 * Checks a DIO line to see if it is currently generating a pulse.
183 *
184 * @param[in] dioPortHandle the digital port handle
185 * @param[out] status Error status variable. 0 on success.
186 * @return true if a pulse is in progress, otherwise false
187 */
188HAL_Bool HAL_IsPulsing(HAL_DigitalHandle dioPortHandle, int32_t* status);
189
190/**
191 * Checks if any DIO line is currently generating a pulse.
192 *
193 * @param[out] status Error status variable. 0 on success.
194 * @return true if a pulse on some line is in progress
195 */
196HAL_Bool HAL_IsAnyPulsing(int32_t* status);
197
198/**
199 * Writes the filter index from the FPGA.
200 *
201 * Set the filter index used to filter out short pulses.
202 *
203 * @param[in] dioPortHandle the digital port handle
204 * @param[in] filterIndex the filter index (Must be in the range 0 - 3, where
205 * 0 means "none" and 1 - 3 means filter # filterIndex
206 * - 1)
207 * @param[out] status Error status variable. 0 on success.
208 */
209void HAL_SetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t filterIndex,
210 int32_t* status);
211
212/**
213 * Reads the filter index from the FPGA.
214 *
215 * Gets the filter index used to filter out short pulses.
216 *
217 * @param[in] dioPortHandle the digital port handle
218 * @param[out] status Error status variable. 0 on success.
219 * @return filterIndex the filter index (Must be in the range 0 - 3, where 0
220 * means "none" and 1 - 3 means filter # filterIndex - 1)
221 */
222int32_t HAL_GetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t* status);
223
224/**
225 * Sets the filter period for the specified filter index.
226 *
227 * Sets the filter period in FPGA cycles. Even though there are 2 different
228 * filter index domains (MXP vs HDR), ignore that distinction for now since it
229 * complicates the interface. That can be changed later.
230 *
231 * @param[in] filterIndex the filter index, 0 - 2
232 * @param[in] value the number of cycles that the signal must not
233 * transition to be counted as a transition.
234 * @param[out] status Error status variable. 0 on success.
235 */
236void HAL_SetFilterPeriod(int32_t filterIndex, int64_t value, int32_t* status);
237
238/**
239 * Gets the filter period for the specified filter index.
240 *
241 * Gets the filter period in FPGA cycles. Even though there are 2 different
242 * filter index domains (MXP vs HDR), ignore that distinction for now since it
243 * complicates the interface. Set status to NiFpga_Status_SoftwareFault if the
244 * filter values mismatch.
245 *
246 * @param[in] filterIndex the filter index, 0 - 2
247 * @param[out] status Error status variable. 0 on success.
248 * @return The number of FPGA cycles of the filter period.
249 */
250int64_t HAL_GetFilterPeriod(int32_t filterIndex, int32_t* status);
251#ifdef __cplusplus
252} // extern "C"
253#endif
254/** @} */
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.
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.
void HAL_FreeDigitalPWM(HAL_DigitalPWMHandle pwmGenerator)
Frees the resource associated with a DO PWM generator.
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