ctre_sys/
canifier.rs

1//! Enums and functions related to the CANifier.
2#![allow(non_camel_case_types)]
3
4use std::os::raw::{c_char, c_int};
5use ErrorCode;
6
7pub enum _Handle {}
8pub type Handle = *mut _Handle;
9
10/* automatically generated by rust-bindgen */
11
12#[repr(i32)]
13/// Enumerated type for status frame types.
14#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
15pub enum CANifierControlFrame {
16    Control_1_General = 50593792,
17    Control_2_PwmOutput = 50593856,
18}
19#[repr(i32)]
20/// Enumerated type for status frame types.
21#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
22pub enum CANifierStatusFrame {
23    Status_1_General = 267264,
24    Status_2_General = 267328,
25    Status_3_PwmInputs0 = 267392,
26    Status_4_PwmInputs1 = 267456,
27    Status_5_PwmInputs2 = 267520,
28    Status_6_PwmInputs3 = 267584,
29    Status_8_Misc = 267712,
30}
31
32#[repr(i32)]
33#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
34pub enum CANifierVelocityMeasPeriod {
35    Period_1Ms = 1,
36    Period_2Ms = 2,
37    Period_5Ms = 5,
38    Period_10Ms = 10,
39    Period_20Ms = 20,
40    Period_25Ms = 25,
41    Period_50Ms = 50,
42    Period_100Ms = 100,
43}
44
45#[repr(u32)]
46/// General IO Pins on the CANifier
47#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
48pub enum GeneralPin {
49    QUAD_IDX = 0,
50    QUAD_B = 1,
51    QUAD_A = 2,
52    LIMR = 3,
53    LIMF = 4,
54    SDA = 5,
55    SCL = 6,
56    SPI_CS = 7,
57    SPI_MISO_PWM2P = 8,
58    SPI_MOSI_PWM1P = 9,
59    SPI_CLK_PWM0P = 10,
60}
61
62extern "C" {
63    pub fn c_CANifier_Create1(deviceNumber: c_int) -> Handle;
64
65    pub fn c_CANifier_GetDescription(
66        handle: Handle,
67        toFill: *mut c_char,
68        toFillByteSz: c_int,
69        numBytesFilled: *mut c_int,
70    ) -> ErrorCode;
71
72    pub fn c_CANifier_SetLEDOutput(handle: Handle, dutyCycle: u32, ledChannel: u32) -> ErrorCode;
73
74    pub fn c_CANifier_SetGeneralOutputs(
75        handle: Handle,
76        outputsBits: u32,
77        isOutputBits: u32,
78    ) -> ErrorCode;
79
80    pub fn c_CANifier_SetGeneralOutput(
81        handle: Handle,
82        outputPin: u32,
83        outputValue: bool,
84        outputEnable: bool,
85    ) -> ErrorCode;
86
87    pub fn c_CANifier_SetPWMOutput(handle: Handle, pwmChannel: u32, dutyCycle: u32) -> ErrorCode;
88
89    pub fn c_CANifier_EnablePWMOutput(handle: Handle, pwmChannel: u32, bEnable: bool) -> ErrorCode;
90
91    pub fn c_CANifier_GetGeneralInputs(
92        handle: Handle,
93        allPins: *mut bool,
94        capacity: u32,
95    ) -> ErrorCode;
96
97    pub fn c_CANifier_GetGeneralInput(
98        handle: Handle,
99        inputPin: u32,
100        measuredInput: *mut bool,
101    ) -> ErrorCode;
102
103    /// dutyCycleAndPeriod takes an array of length 2
104    pub fn c_CANifier_GetPWMInput(
105        handle: Handle,
106        pwmChannel: u32,
107        dutyCycleAndPeriod: *mut f64,
108    ) -> ErrorCode;
109
110    pub fn c_CANifier_GetLastError(handle: Handle) -> ErrorCode;
111
112    pub fn c_CANifier_GetBusVoltage(handle: Handle, batteryVoltage: *mut f64) -> ErrorCode;
113
114    pub fn c_CANifier_GetQuadraturePosition(handle: Handle, pos: *mut c_int) -> ErrorCode;
115
116    pub fn c_CANifier_SetQuadraturePosition(
117        handle: Handle,
118        pos: c_int,
119        timeoutMs: c_int,
120    ) -> ErrorCode;
121
122    pub fn c_CANifier_GetQuadratureVelocity(handle: Handle, vel: *mut c_int) -> ErrorCode;
123
124    pub fn c_CANifier_GetQuadratureSensor(
125        handle: Handle,
126        pos: *mut c_int,
127        vel: *mut c_int,
128    ) -> ErrorCode;
129
130    pub fn c_CANifier_ConfigVelocityMeasurementPeriod(
131        handle: Handle,
132        period: c_int,
133        timeoutMs: c_int,
134    ) -> ErrorCode;
135
136    pub fn c_CANifier_ConfigVelocityMeasurementWindow(
137        handle: Handle,
138        window: c_int,
139        timeoutMs: c_int,
140    ) -> ErrorCode;
141
142    pub fn c_CANifier_SetLastError(handle: Handle, error: c_int);
143
144    pub fn c_CANifier_ConfigSetParameter(
145        handle: Handle,
146        param: c_int,
147        value: f64,
148        subValue: c_int,
149        ordinal: c_int,
150        timeoutMs: c_int,
151    ) -> ErrorCode;
152
153    pub fn c_CANifier_ConfigGetParameter(
154        handle: Handle,
155        param: c_int,
156        value: *mut f64,
157        ordinal: c_int,
158        timeoutMs: c_int,
159    ) -> ErrorCode;
160
161    pub fn c_CANifier_ConfigSetCustomParam(
162        handle: Handle,
163        newValue: c_int,
164        paramIndex: c_int,
165        timeoutMs: c_int,
166    ) -> ErrorCode;
167
168    pub fn c_CANifier_ConfigGetCustomParam(
169        handle: Handle,
170        readValue: *mut c_int,
171        paramIndex: c_int,
172        timoutMs: c_int,
173    ) -> ErrorCode;
174
175    pub fn c_CANifier_GetFaults(handle: Handle, param: *mut c_int) -> ErrorCode;
176
177    pub fn c_CANifier_GetStickyFaults(handle: Handle, param: *mut c_int) -> ErrorCode;
178
179    pub fn c_CANifier_ClearStickyFaults(handle: Handle, timeoutMs: c_int) -> ErrorCode;
180
181    pub fn c_CANifier_GetFirmwareVersion(handle: Handle, firmwareVers: *mut c_int) -> ErrorCode;
182
183    pub fn c_CANifier_HasResetOccurred(handle: Handle, hasReset: *mut bool) -> ErrorCode;
184
185    pub fn c_CANifier_SetStatusFramePeriod(
186        handle: Handle,
187        frame: c_int,
188        periodMs: c_int,
189        timeoutMs: c_int,
190    ) -> ErrorCode;
191
192    pub fn c_CANifier_GetStatusFramePeriod(
193        handle: Handle,
194        frame: c_int,
195        periodMs: *mut c_int,
196        timeoutMs: c_int,
197    ) -> ErrorCode;
198
199    pub fn c_CANifier_SetControlFramePeriod(
200        handle: Handle,
201        frame: c_int,
202        periodMs: c_int,
203    ) -> ErrorCode;
204}