ad7124_rs/ffi/types.rs
1//! C-compatible type definitions for AD7124 FFI
2//!
3//! This module defines C-compatible enums and structures that match
4//! the definitions in the C header file.
5
6/// C-compatible error codes
7#[repr(i32)]
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum CAd7124Error {
10 /// Operation completed successfully
11 Ok = 0,
12 /// Null pointer was passed as argument
13 NullPointer = -1,
14 /// SPI write operation failed
15 SpiWrite = -2,
16 /// SPI read operation failed
17 SpiRead = -3,
18 /// SPI transfer operation failed
19 SpiTransfer = -4,
20 /// Invalid channel number specified
21 InvalidChannel = -5,
22 /// Invalid parameter value provided
23 InvalidParameter = -6,
24 /// Driver not initialized before use
25 NotInitialized = -7,
26 /// Device not responding to commands
27 DeviceNotResponding = -8,
28 /// Calibration procedure failed
29 CalibrationFailed = -9,
30 /// Conversion operation timed out
31 ConversionTimeout = -10,
32 /// Data length is invalid for operation
33 InvalidDataLength = -11,
34 /// Device ID does not match expected value
35 InvalidDeviceId = -12,
36 /// Operation timed out
37 Timeout = -13,
38 /// Invalid configuration specified
39 InvalidConfiguration = -14,
40}
41
42/// C-compatible device types
43#[repr(u8)]
44#[derive(Debug, Clone, Copy, PartialEq, Eq)]
45pub enum CAd7124DeviceType {
46 /// AD7124-4: 4-channel, 24-bit ADC
47 AD7124_4 = 0,
48 /// AD7124-8: 8-channel, 24-bit ADC
49 AD7124_8 = 1,
50 /// Unknown or unsupported device
51 Unknown = 255,
52}
53
54/// C-compatible gain values
55#[repr(u8)]
56#[derive(Debug, Clone, Copy, PartialEq, Eq)]
57pub enum CAd7124Gain {
58 /// Gain of 1x
59 Gain1 = 0,
60 /// Gain of 2x
61 Gain2 = 1,
62 /// Gain of 4x
63 Gain4 = 2,
64 /// Gain of 8x
65 Gain8 = 3,
66 /// Gain of 16x
67 Gain16 = 4,
68 /// Gain of 32x
69 Gain32 = 5,
70 /// Gain of 64x
71 Gain64 = 6,
72 /// Gain of 128x
73 Gain128 = 7,
74}
75
76/// C-compatible channel input values
77#[repr(u8)]
78#[derive(Debug, Clone, Copy, PartialEq, Eq)]
79pub enum CAd7124ChannelInput {
80 /// Analog input 0
81 Ain0 = 0,
82 /// Analog input 1
83 Ain1 = 1,
84 /// Analog input 2
85 Ain2 = 2,
86 /// Analog input 3
87 Ain3 = 3,
88 /// Analog input 4
89 Ain4 = 4,
90 /// Analog input 5
91 Ain5 = 5,
92 /// Analog input 6
93 Ain6 = 6,
94 /// Analog input 7
95 Ain7 = 7,
96 /// Internal temperature sensor
97 TempSensor = 16,
98 /// Internal reference
99 IntRef = 17,
100 /// Digital ground
101 Dgnd = 18,
102 /// (AVDD - AVSS) / 5
103 AvddAvssDiv5 = 19,
104}
105
106/// C-compatible operating modes
107#[repr(C)]
108#[derive(Debug, Clone, Copy, PartialEq, Eq)]
109pub enum CAd7124OperatingMode {
110 /// Continuous conversion mode
111 Continuous = 0,
112 /// Single conversion mode
113 SingleConv = 1,
114 /// Standby mode
115 Standby = 2,
116 /// Power down mode
117 PowerDown = 3,
118 /// Idle mode
119 Idle = 4,
120 /// Internal zero-scale calibration
121 InternalZeroScale = 5,
122 /// Internal full-scale calibration
123 InternalFullScale = 6,
124 /// System zero-scale calibration
125 SystemZeroScale = 7,
126 /// System full-scale calibration
127 SystemFullScale = 8,
128}
129
130/// C-compatible power modes
131#[repr(C)]
132#[derive(Debug, Clone, Copy, PartialEq, Eq)]
133pub enum CAd7124PowerMode {
134 /// Low power consumption mode
135 LowPower = 0,
136 /// Medium power consumption mode
137 MidPower = 1,
138 /// Full power mode (best performance)
139 FullPower = 2,
140}
141
142/// C-compatible reference sources
143#[repr(C)]
144#[derive(Debug, Clone, Copy, PartialEq, Eq)]
145pub enum CAd7124ReferenceSource {
146 /// External reference voltage
147 External = 0,
148 /// Internal reference voltage
149 Internal = 1,
150 /// AVDD - AVSS as reference
151 AvddAvss = 2,
152}
153
154/// C-compatible burnout current sources
155#[repr(u8)]
156#[derive(Debug, Clone, Copy, PartialEq, Eq)]
157pub enum CAd7124BurnoutCurrent {
158 /// No burnout current
159 Off = 0,
160 /// 0.5 µA burnout current
161 Current0_5uA = 1,
162 /// 2 µA burnout current
163 Current2uA = 2,
164 /// 4 µA burnout current
165 Current4uA = 3,
166}
167
168/// C-compatible filter types
169#[repr(u8)]
170#[derive(Debug, Clone, Copy, PartialEq, Eq)]
171pub enum CAd7124FilterType {
172 /// SINC4 filter
173 Sinc4 = 0,
174 /// SINC3 filter
175 Sinc3 = 5,
176 /// Fast settling filter
177 FastSettle = 4,
178}
179
180/// SPI write function pointer type
181pub type CSpiWriteFn = extern "C" fn(data: *const u8, len: usize) -> i32;
182/// SPI read function pointer type
183pub type CSpiReadFn = extern "C" fn(data: *mut u8, len: usize) -> i32;
184/// SPI transfer function pointer type
185pub type CSpiTransferFn =
186 extern "C" fn(read_data: *mut u8, write_data: *const u8, len: usize) -> i32;
187/// Delay function pointer type
188pub type CDelayMsFn = extern "C" fn(ms: u32) -> i32;
189
190/// C-compatible SPI interface structure
191#[repr(C)]
192#[derive(Debug, Clone, Copy)]
193pub struct CAd7124SpiInterface {
194 /// SPI write function pointer
195 pub write: CSpiWriteFn,
196 /// SPI read function pointer
197 pub read: CSpiReadFn,
198 /// SPI transfer function pointer
199 pub transfer: CSpiTransferFn,
200 /// Delay function pointer
201 pub delay_ms: CDelayMsFn,
202}
203
204/// C-compatible AD7124 configuration structure
205#[repr(C)]
206#[derive(Debug, Clone, Copy)]
207pub struct CAd7124Config {
208 /// ADC operating mode
209 pub operating_mode: CAd7124OperatingMode,
210 /// Device power consumption mode
211 pub power_mode: CAd7124PowerMode,
212 /// Reference voltage source
213 pub reference_source: CAd7124ReferenceSource,
214 /// Whether internal reference is enabled
215 pub internal_ref_enabled: bool,
216 /// Whether data ready output is enabled
217 pub data_ready_output_enabled: bool,
218}
219
220/// C-compatible channel configuration structure
221#[repr(C)]
222#[derive(Debug, Clone, Copy)]
223pub struct CAd7124ChannelConfig {
224 /// Whether this channel is enabled
225 pub enabled: bool,
226 /// Positive input selection
227 pub positive_input: CAd7124ChannelInput,
228 /// Negative input selection
229 pub negative_input: CAd7124ChannelInput,
230 /// Setup configuration index to use
231 pub setup_index: u8,
232}
233
234/// C-compatible setup configuration structure
235#[repr(C)]
236#[derive(Debug, Clone, Copy)]
237pub struct CAd7124SetupConfig {
238 /// Programmable gain amplifier setting
239 pub pga_gain: CAd7124Gain,
240 /// Reference voltage source
241 pub reference_source: CAd7124ReferenceSource,
242 /// Whether to use bipolar mode
243 pub bipolar: bool,
244 /// Whether reference buffers are enabled
245 pub reference_buffers_enabled: bool,
246 /// Whether input buffers are enabled
247 pub input_buffers_enabled: bool,
248 /// Burnout current source for sensor diagnostics
249 pub burnout_current: CAd7124BurnoutCurrent,
250}
251
252/// C-compatible filter configuration structure
253#[repr(C)]
254#[derive(Debug, Clone, Copy)]
255pub struct CAd7124FilterConfig {
256 /// Digital filter type
257 pub filter_type: CAd7124FilterType,
258 /// Output data rate (0-2047)
259 pub output_data_rate: u16,
260 /// Single cycle conversion mode
261 pub single_cycle: bool,
262 /// Enable 60Hz rejection
263 pub reject_60hz: bool,
264}
265
266/// Opaque driver handle type
267#[repr(C)]
268#[derive(Debug)]
269pub struct Ad7124Driver {
270 /// Private data (zero-sized for opaque handle)
271 _private: [u8; 0],
272}