HF-ADS7952 Driver 0.1.0-dev
HF-ADS7952 C++ Driver
Loading...
Searching...
No Matches
ads7952_registers.hpp
Go to the documentation of this file.
1
13#pragma once
14#include <cstdint>
15
16namespace ads7952 {
17namespace reg {
18
25// =============================================================================
26// Command Frame Mode Select — bits [15:12]
27// Datasheet Tables 1-7
28// =============================================================================
30namespace Mode {
31 inline constexpr uint16_t CONTINUE = 0x0000; // 0000: Continue previous
32 inline constexpr uint16_t MANUAL = 0x1000; // 0001: Manual channel select
33 inline constexpr uint16_t AUTO_1 = 0x2000; // 0010: Auto-1 sequencing
34 inline constexpr uint16_t AUTO_2 = 0x3000; // 0011: Auto-2 sequencing
35 inline constexpr uint16_t GPIO_PROG = 0x4000; // 0100: GPIO programming
36 inline constexpr uint16_t AUTO_1_PROG = 0x8000; // 1000: Auto-1 programming
37 inline constexpr uint16_t AUTO_2_PROG = 0x9000; // 1001: Auto-2 programming
38 inline constexpr uint16_t ALARM_GROUP_0 = 0xC000; // 1100: Alarm group 0 (CH0-3)
39 inline constexpr uint16_t ALARM_GROUP_1 = 0xD000; // 1101: Alarm group 1 (CH4-7)
40 inline constexpr uint16_t ALARM_GROUP_2 = 0xE000; // 1110: Alarm group 2 (CH8-11)
41 inline constexpr uint16_t ALARM_GROUP_3 = 0xF000; // 1111: Alarm group 3 (CH12-15)
42 inline constexpr uint16_t MASK = 0xF000;
43} // namespace Mode
44
45// =============================================================================
46// Bit 11: Programming enable
47// =============================================================================
48inline constexpr uint16_t PROGRAM_ENABLE = 0x0800;
49inline constexpr uint16_t PROGRAM_RETAIN = 0x0000;
50
51// =============================================================================
52// Bit 10: Channel counter reset (Auto modes only)
53// =============================================================================
54inline constexpr uint16_t RESET_COUNTER = 0x0400;
55inline constexpr uint16_t NO_RESET_COUNTER = 0x0000;
56
57// =============================================================================
58// Bits [10:7]: Manual mode channel select
59// =============================================================================
66inline constexpr uint16_t ChannelSelect(uint8_t ch) noexcept {
67 return static_cast<uint16_t>((ch & 0xF) << 7);
68}
69
70// =============================================================================
71// Bit 6: Input voltage range
72// =============================================================================
73inline constexpr uint16_t RANGE_VREF = 0x0000; // 0 to Vref
74inline constexpr uint16_t RANGE_2VREF = 0x0040; // 0 to 2*Vref
75
76// =============================================================================
77// Bit 5: Power-down control
78// =============================================================================
79inline constexpr uint16_t POWER_NORMAL = 0x0000;
80inline constexpr uint16_t POWER_DOWN = 0x0020;
81
82// =============================================================================
83// Bit 4: Data descriptor output selection
84// =============================================================================
85inline constexpr uint16_t OUTPUT_CHAN_ADDR = 0x0000; // DO[15:12] = channel addr
86inline constexpr uint16_t OUTPUT_GPIO_DATA = 0x0010; // DO[15:12] = GPIO data
87
88// =============================================================================
89// Bits [3:0]: GPIO output state
90// =============================================================================
92namespace GPIO {
93 inline constexpr uint16_t PIN0_HIGH = 0x0001;
94 inline constexpr uint16_t PIN1_HIGH = 0x0002;
95 inline constexpr uint16_t PIN2_HIGH = 0x0004;
96 inline constexpr uint16_t PIN3_HIGH = 0x0008;
97 inline constexpr uint16_t ALL_LOW = 0x0000;
98} // namespace GPIO
99
100// =============================================================================
101// Auto-1 Programming — Channel enable mask (Frame 2, bits [11:0])
102// Datasheet Table 3
103// =============================================================================
110inline constexpr uint16_t Auto1ChannelBit(uint8_t ch) noexcept {
111 return static_cast<uint16_t>(1U << (ch & 0xF));
112}
113
114// =============================================================================
115// Auto-2 Programming — Last channel (bits [9:6])
116// Datasheet Table 5
117// =============================================================================
124inline constexpr uint16_t Auto2LastChannel(uint8_t ch) noexcept {
125 return static_cast<uint16_t>((ch & 0xF) << 6);
126}
127
128// =============================================================================
129// GPIO Programming Register Layout (single frame, mode=0100)
130// Datasheet Table 11
131// =============================================================================
133namespace GPIOProg {
134 // Bit 9: Reset all registers
135 inline constexpr uint16_t RESET_ALL_REGS = 0x0200;
136 inline constexpr uint16_t NORMAL_OPERATION = 0x0000;
137 // Bit 8: GPIO3 function
138 inline constexpr uint16_t GPIO3_PWRDOWN_IN = 0x0100;
139 inline constexpr uint16_t GPIO3_AS_GPIO = 0x0000;
140 // Bit 7: GPIO2 function
141 inline constexpr uint16_t GPIO2_RANGE_IN = 0x0080;
142 inline constexpr uint16_t GPIO2_AS_GPIO = 0x0000;
143 // Bits [6:4]: GPIO0 & GPIO1 alarm assignment
144 inline constexpr uint16_t GPIO01_GPIO = 0x0000;
145 inline constexpr uint16_t GPIO0_HI_LO_ALARM = 0x0010;
146 inline constexpr uint16_t GPIO0_HI_ALARM = 0x0020;
147 inline constexpr uint16_t GPIO1_HI_ALARM = 0x0040;
148 inline constexpr uint16_t GPIO1_LO_GPIO0_HI_ALARM = 0x0060;
149 // Bits [3:0]: GPIO direction (1=output)
150 inline constexpr uint16_t DIR_GPIO0_OUT = 0x0001;
151 inline constexpr uint16_t DIR_GPIO1_OUT = 0x0002;
152 inline constexpr uint16_t DIR_GPIO2_OUT = 0x0004;
153 inline constexpr uint16_t DIR_GPIO3_OUT = 0x0008;
154} // namespace GPIOProg
155
156// =============================================================================
157// Alarm Programming Register Layout (Frame 2 of alarm sequence)
158// Datasheet Table 13
159// =============================================================================
161namespace Alarm {
162 // Bits [15:14]: Channel within group (0-3)
168 inline constexpr uint16_t ChannelInGroup(uint8_t ch_in_group) noexcept {
169 return static_cast<uint16_t>((ch_in_group & 0x3) << 14);
170 }
171 // Bit 13: Alarm register select
172 inline constexpr uint16_t HIGH_REGISTER = 0x2000;
173 inline constexpr uint16_t LOW_REGISTER = 0x0000;
174 // Bit 12: Continue/exit alarm programming
175 inline constexpr uint16_t EXIT_NEXT_FRAME = 0x1000;
176 inline constexpr uint16_t CONTINUE_PROG = 0x0000;
177 // Bits [9:0]: 10-bit threshold (top 10 of 12-bit ADC value)
183 inline constexpr uint16_t Threshold12To10(uint16_t adc_12bit) noexcept {
184 return (adc_12bit >> 2) & 0x03FF;
185 }
186
187 // Alarm group mode for a given global channel number (0-11)
193 inline constexpr uint16_t GroupMode(uint8_t channel) noexcept {
194 uint8_t group = channel / 4;
195 constexpr uint16_t modes[] = {
198 };
199 return (group < 4) ? modes[group] : Mode::ALARM_GROUP_0;
200 }
201} // namespace Alarm
202
203// =============================================================================
204// Response Frame Parsing — DO[15:12] channel, DO[11:0] data
205// =============================================================================
207namespace Response {
213 inline constexpr uint8_t GetChannel(uint16_t frame) noexcept {
214 return static_cast<uint8_t>((frame >> 12) & 0x0F);
215 }
221 inline constexpr uint16_t GetData(uint16_t frame) noexcept {
222 return frame & 0x0FFF;
223 }
224} // namespace Response
225
226// =============================================================================
227// Device Constants (ADS7952 specific)
228// =============================================================================
229inline constexpr uint8_t NUM_CHANNELS = 12;
230inline constexpr uint8_t RESOLUTION_BITS = 12;
231inline constexpr uint16_t MAX_COUNT = 4095;
232inline constexpr uint8_t NUM_GPIO_PINS = 4;
233inline constexpr uint8_t CHANNELS_PER_ALARM_GROUP = 4;
234inline constexpr uint8_t NUM_ALARM_GROUPS = 3;
235inline constexpr uint8_t INVALID_CONVERSIONS_AFTER_POWERUP = 1;
236
237} // namespace reg
238} // namespace ads7952
constexpr uint16_t ChannelSelect(uint8_t ch) noexcept
Encode manual-mode channel selection bits DI[10:7].
constexpr uint16_t Auto1ChannelBit(uint8_t ch) noexcept
Build the Auto-1 enable bit for a channel.
constexpr uint16_t Auto2LastChannel(uint8_t ch) noexcept
Encode Auto-2 last-channel field DI[9:6].
@ GPIO
Both as general-purpose I/O.
constexpr uint16_t LOW_REGISTER
constexpr uint16_t EXIT_NEXT_FRAME
constexpr uint16_t Threshold12To10(uint16_t adc_12bit) noexcept
Convert 12-bit ADC threshold to 10-bit alarm register format.
constexpr uint16_t HIGH_REGISTER
constexpr uint16_t CONTINUE_PROG
constexpr uint16_t ChannelInGroup(uint8_t ch_in_group) noexcept
Encode alarm channel index within a 4-channel group.
constexpr uint16_t GroupMode(uint8_t channel) noexcept
Resolve alarm programming mode code for a global channel.
constexpr uint16_t GPIO0_HI_ALARM
constexpr uint16_t RESET_ALL_REGS
constexpr uint16_t GPIO01_GPIO
constexpr uint16_t NORMAL_OPERATION
constexpr uint16_t DIR_GPIO1_OUT
constexpr uint16_t GPIO3_AS_GPIO
constexpr uint16_t DIR_GPIO2_OUT
constexpr uint16_t GPIO1_LO_GPIO0_HI_ALARM
constexpr uint16_t GPIO2_AS_GPIO
constexpr uint16_t GPIO3_PWRDOWN_IN
constexpr uint16_t DIR_GPIO0_OUT
constexpr uint16_t DIR_GPIO3_OUT
constexpr uint16_t GPIO0_HI_LO_ALARM
constexpr uint16_t GPIO1_HI_ALARM
constexpr uint16_t GPIO2_RANGE_IN
constexpr uint16_t PIN2_HIGH
constexpr uint16_t ALL_LOW
constexpr uint16_t PIN3_HIGH
constexpr uint16_t PIN1_HIGH
constexpr uint16_t PIN0_HIGH
constexpr uint16_t AUTO_1
constexpr uint16_t AUTO_1_PROG
constexpr uint16_t ALARM_GROUP_0
constexpr uint16_t ALARM_GROUP_1
constexpr uint16_t CONTINUE
constexpr uint16_t MASK
constexpr uint16_t GPIO_PROG
constexpr uint16_t AUTO_2_PROG
constexpr uint16_t ALARM_GROUP_2
constexpr uint16_t ALARM_GROUP_3
constexpr uint16_t MANUAL
constexpr uint16_t AUTO_2
constexpr uint8_t GetChannel(uint16_t frame) noexcept
Extract channel descriptor from response frame DO[15:12].
constexpr uint16_t GetData(uint16_t frame) noexcept
Extract conversion data from response frame DO[11:0].
constexpr uint16_t POWER_NORMAL
constexpr uint16_t PROGRAM_RETAIN
constexpr uint16_t RANGE_2VREF
constexpr uint16_t NO_RESET_COUNTER
constexpr uint16_t PROGRAM_ENABLE
constexpr uint16_t RANGE_VREF
constexpr uint8_t NUM_CHANNELS
Number of ADC input channels.
constexpr uint16_t POWER_DOWN
constexpr uint16_t OUTPUT_GPIO_DATA
constexpr uint16_t OUTPUT_CHAN_ADDR
constexpr uint16_t MAX_COUNT
Maximum 12-bit conversion value.
constexpr uint8_t NUM_GPIO_PINS
Number of GPIO pins on ADS7952.
constexpr uint8_t INVALID_CONVERSIONS_AFTER_POWERUP
Frames to discard after power-up.
constexpr uint8_t NUM_ALARM_GROUPS
Valid alarm groups for CH0..CH11.
constexpr uint16_t RESET_COUNTER
constexpr uint8_t RESOLUTION_BITS
ADC resolution in bits.
constexpr uint8_t CHANNELS_PER_ALARM_GROUP
Channels per alarm group.