WPILibC++ 2027.0.0-alpha-2
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] channel the smartio channel
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 const char* allocationLocation,
33 int32_t* status);
34
35/**
36 * Checks if a DIO channel is valid.
37 *
38 * @param channel the channel number to check
39 * @return true if the channel is valid, otherwise false
40 */
42
43/**
44 * Frees a DIO port.
45 *
46 * @param dioPortHandle the DIO channel handle
47 */
49
50/**
51 * Indicates the DIO channel is used by a simulated device.
52 *
53 * @param handle the DIO channel handle
54 * @param device simulated device handle
55 */
57
58/**
59 * Allocates a DO PWM Generator.
60 *
61 * @param[out] status Error status variable. 0 on success.
62 * @return the allocated digital PWM handle
63 */
65
66/**
67 * Frees the resource associated with a DO PWM generator.
68 *
69 * @param[in] pwmGenerator the digital PWM handle
70 */
72
73/**
74 * Changes the frequency of the DO PWM generator.
75 *
76 * The valid range is from 0.6 Hz to 19 kHz.
77 *
78 * The frequency resolution is logarithmic.
79 *
80 * @param[in] rate the frequency to output all digital output PWM signals
81 * @param[out] status Error status variable. 0 on success.
82 */
83void HAL_SetDigitalPWMRate(double rate, int32_t* status);
84
85/**
86 * Configures the duty-cycle of the PWM generator.
87 *
88 * @param[in] pwmGenerator the digital PWM handle
89 * @param[in] dutyCycle the percent duty cycle to output [0..1]
90 * @param[out] status Error status variable. 0 on success.
91 */
93 double dutyCycle, int32_t* status);
94
95/**
96 * Configures the digital PWM to be a PPS signal with specified duty cycle.
97 *
98 * @param[in] pwmGenerator the digital PWM handle
99 * @param[in] dutyCycle the percent duty cycle to output [0..1]
100 * @param[out] status Error status variable. 0 on success.
101 */
102void HAL_SetDigitalPWMPPS(HAL_DigitalPWMHandle pwmGenerator, double dutyCycle,
103 int32_t* status);
104
105/**
106 * Configures which DO channel the PWM signal is output on.
107 *
108 * @param[in] pwmGenerator the digital PWM handle
109 * @param[in] channel the channel to output on
110 * @param[out] status Error status variable. 0 on success.
111 */
113 int32_t channel, int32_t* status);
114
115/**
116 * Writes a digital value to a DIO channel.
117 *
118 * @param[in] dioPortHandle the digital port handle
119 * @param[in] value the state to set the digital channel (if it is
120 * configured as an output)
121 * @param[out] status Error status variable. 0 on success.
122 */
123void HAL_SetDIO(HAL_DigitalHandle dioPortHandle, HAL_Bool value,
124 int32_t* status);
125
126/**
127 * Sets the direction of a DIO channel.
128 *
129 * @param[in] dioPortHandle the digital port handle
130 * @param[in] input true to set input, false for output
131 * @param[out] status Error status variable. 0 on success.
132 */
134 int32_t* status);
135
136/**
137 * Reads a digital value from a DIO channel.
138 *
139 * @param[in] dioPortHandle the digital port handle
140 * @param[out] status Error status variable. 0 on success.
141 * @return the state of the specified channel
142 */
143HAL_Bool HAL_GetDIO(HAL_DigitalHandle dioPortHandle, int32_t* status);
144
145/**
146 * Reads the direction of a DIO channel.
147 *
148 * @param[in] dioPortHandle the digital port handle
149 * @param[out] status Error status variable. 0 on success.
150 * @return true for input, false for output
151 */
152HAL_Bool HAL_GetDIODirection(HAL_DigitalHandle dioPortHandle, int32_t* status);
153
154/**
155 * Generates a single digital pulse.
156 *
157 * Write a pulse to the specified digital output channel. There can only be a
158 * single pulse going at any time.
159 *
160 * @param[in] dioPortHandle the digital port handle
161 * @param[in] pulseLength the active length of the pulse in seconds
162 * @param[out] status Error status variable. 0 on success.
163 */
164void HAL_Pulse(HAL_DigitalHandle dioPortHandle, double pulseLength,
165 int32_t* status);
166
167/**
168 * Generates a single digital pulse on multiple channels.
169 *
170 * Write a pulse to the channels enabled by the mask. There can only be a
171 * single pulse going at any time.
172 *
173 * @param[in] channelMask the channel mask
174 * @param[in] pulseLength the active length of the pulse in seconds
175 * @param[out] status Error status variable. 0 on success.
176 */
177void HAL_PulseMultiple(uint32_t channelMask, double pulseLength,
178 int32_t* status);
179
180/**
181 * Checks a DIO line to see if it is currently generating a pulse.
182 *
183 * @param[in] dioPortHandle the digital port handle
184 * @param[out] status Error status variable. 0 on success.
185 * @return true if a pulse is in progress, otherwise false
186 */
187HAL_Bool HAL_IsPulsing(HAL_DigitalHandle dioPortHandle, int32_t* status);
188
189/**
190 * Checks if any DIO line is currently generating a pulse.
191 *
192 * @param[out] status Error status variable. 0 on success.
193 * @return true if a pulse on some line is in progress
194 */
195HAL_Bool HAL_IsAnyPulsing(int32_t* status);
196#ifdef __cplusplus
197} // extern "C"
198#endif
199/** @} */
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.
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(int32_t channel, 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.
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.
void HAL_Pulse(HAL_DigitalHandle dioPortHandle, double pulseLength, int32_t *status)
Generates a single digital pulse.
void HAL_PulseMultiple(uint32_t channelMask, double pulseLength, int32_t *status)
Generates a single digital pulse on multiple channels.
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_FreeDigitalPWM(HAL_DigitalPWMHandle pwmGenerator)
Frees the resource associated with a DO PWM generator.
int32_t HAL_Bool
Definition Types.h:73
HAL_Handle HAL_SimDeviceHandle
Definition Types.h:51
HAL_Handle HAL_DigitalPWMHandle
Definition Types.h:31
HAL_Handle HAL_DigitalHandle
Definition Types.h:29