Skip to content

Commit 23663a7

Browse files
committed
Add registers file.
Adds registers and enums for states in the registers.
1 parent b42b05b commit 23663a7

File tree

1 file changed

+251
-0
lines changed

1 file changed

+251
-0
lines changed

src/sfe_as7331_registers.h

Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
2+
#pragma once
3+
#include <stdint.h>
4+
5+
/// I2C addresses
6+
// 7-bit address defined as [1, 1, 1, 0, 1, A1, A0] where A1/A0 are the address pins tied high or low
7+
#define AS7331_ADDR_DEFAULT 0x74
8+
#define AS7331_ADDR_SEC 0x75
9+
#define AS7331_ADDR_TER 0x76
10+
#define AS7331_ADDR_QUA 0x77
11+
12+
#define AS7331_DEFAULT_DEV_ID 0x21
13+
#define AS7331_DEV_ID_HIGH 0x2
14+
15+
16+
/// Enum Settings
17+
18+
typedef enum {
19+
// 0x00X invalid
20+
DEVICE_MODE_CFG = 0x010,
21+
DEVICE_MODE_MEAS
22+
// 0x1XX invalid
23+
} as7331_device_op_state_t;
24+
25+
typedef enum {
26+
POWER_DOWN_DISABLE = 0x0,
27+
POWER_DOWN_ENABLE
28+
} as7331_power_state_t;
29+
30+
typedef enum {
31+
START_STATE_DISABLED = 0x0,
32+
START_STATE_ENABLED
33+
} as7331_startstate_t;
34+
35+
typedef enum {
36+
GAIN_2048 = 0x0000,
37+
GAIN_1024,
38+
GAIN_512,
39+
GAIN_256,
40+
GAIN_128,
41+
GAIN_64,
42+
GAIN_32,
43+
GAIN_16,
44+
GAIN_8,
45+
GAIN_4,
46+
GAIN_2,
47+
GAIN_1
48+
} as7331_gain_t;
49+
50+
typedef enum {
51+
PRESCALE_1,
52+
PRESCALE_2,
53+
PRESCALE_3,
54+
PRESCALE_4,
55+
PRESCALE_5,
56+
PRESCALE_6,
57+
PRESCALE_7,
58+
PRESCALE_8
59+
} as7331_prescale_range_t;
60+
61+
typedef enum {
62+
PRESCALE_DISABLED = 0x0,
63+
PRESCALE_ENABLED
64+
} as7331_prescale_enable_t;
65+
66+
typedef enum {
67+
SYN_TEMP_DISABLED = 0x0,
68+
SYN_TEMP_ENABLED
69+
} as7331_ext_syn_temp_meas_t;
70+
71+
typedef enum {
72+
CCLK_1_024_MHZ = 0x00,
73+
CCLK_2_048_MHZ,
74+
CCLK_4_096_MHZ,
75+
CCLK_8_192_MHZ
76+
} as7331_conv_clk_freq_t;
77+
78+
typedef enum {
79+
READYPIN_PUSHPULL = 0x0,
80+
READYPIN_OPENDRAIN
81+
} as7331_ready_pin_mode_t;
82+
83+
typedef enum {
84+
STANDBY_DISABLED = 0x0,
85+
STANDBY_ENABLED
86+
} as7331_standby_mode_t;
87+
88+
typedef enum {
89+
MEAS_MODE_CONT = 0x0,
90+
MEAS_MODE_CMD,
91+
MEAS_MODE_SYNS,
92+
MEAS_MODE_SYND
93+
} as7331_meas_mode_t;
94+
95+
typedef enum {
96+
INDEX_NO_REPEAT_START = 0x0,
97+
INDEX_REPEAT_START
98+
} as7331_simple_reg_read_mode_t;
99+
100+
/// Configuration Registers
101+
// These registers can only be accessed in the configuration state, and they
102+
// are all 8 bits long.
103+
104+
#define SFE_AS7331_REGISTER_CFG_OSR 0x00
105+
typedef union {
106+
struct {
107+
uint8_t dos : 3;
108+
uint8_t sw_res : 1;
109+
uint8_t reserved : 2;
110+
uint8_t pd : 1;
111+
uint8_t ss : 1;
112+
};
113+
uint8_t byte;
114+
} sfe_as7331_reg_cfg_osr_t;
115+
116+
#define SFE_AS7331_REGISTER_CFG_AGEN 0x02
117+
typedef union {
118+
struct {
119+
uint8_t mut : 4;
120+
uint8_t devid : 4;
121+
};
122+
uint8_t byte;
123+
} sfe_as7331_reg_cfg_agen_t;
124+
125+
#define SFE_AS7331_REGISTER_CFG_CREG1 0x06
126+
typedef union {
127+
struct {
128+
uint8_t time : 4;
129+
uint8_t gain : 4;
130+
};
131+
uint8_t byte;
132+
} sfe_as7331_reg_cfg_creg1_t;
133+
134+
#define SFE_AS7331_REGISTER_CFG_CREG2 0x07
135+
typedef union {
136+
struct {
137+
uint8_t div : 3;
138+
uint8_t en_div : 1;
139+
uint8_t reserved : 2;
140+
uint8_t en_tm : 1;
141+
uint8_t reserved1 : 1;
142+
};
143+
uint8_t byte;
144+
} sfe_as7331_reg_cfg_creg2_t;
145+
146+
#define SFE_AS7331_REGISTER_CFG_CREG3 0x08
147+
typedef union {
148+
struct {
149+
uint8_t cclk : 2;
150+
uint8_t reserved : 1;
151+
uint8_t rdyod : 1;
152+
uint8_t sb : 1;
153+
uint8_t reserved1 : 1;
154+
uint8_t mmode : 2;
155+
};
156+
uint8_t byte;
157+
} sfe_as7331_reg_cfg_creg3_t;
158+
159+
#define SFE_AS7331_REGISTER_CFG_BREAK 0x09
160+
typedef uint8_t sfe_as7331_reg_cfg_break_t;
161+
162+
#define SFE_AS7331_REGISTER_CFG_EDGES 0x0A
163+
typedef uint8_t sfe_as7331_reg_cfg_edges_t;
164+
165+
#define SFE_AS7331_REGISTER_CFG_OPTREG 0x0B
166+
typedef union {
167+
struct {
168+
uint8_t init_idx : 1;
169+
uint8_t reserved : 7;
170+
};
171+
uint8_t byte;
172+
} sfe_as7331_reg_cfg_optreg_t;
173+
174+
175+
/// Measurement Registers
176+
// These registers can only be accessed in the measurement state. They are
177+
// read-only and 16 bits long, except OUTCONV, which is 24 bits long.
178+
179+
#define SFE_AS7331_REGISTER_MEAS_OSR_STATUS 0x00
180+
typedef union {
181+
struct {
182+
sfe_as7331_reg_cfg_osr_t osr;
183+
uint8_t powerstate : 1;
184+
uint8_t standbystate : 1;
185+
uint8_t notready : 1;
186+
uint8_t ndata : 1;
187+
uint8_t ldata : 1;
188+
uint8_t adcof : 1;
189+
uint8_t mresof : 1;
190+
uint8_t outconvof : 1;
191+
};
192+
uint16_t word;
193+
} sfe_as7331_reg_meas_osr_status_t;
194+
195+
#define SFE_AS7331_REGISTER_MEAS_TEMP 0x01
196+
typedef union {
197+
struct {
198+
uint16_t temp : 12;
199+
uint8_t zeros : 4;
200+
};
201+
uint16_t word;
202+
} sfe_as7331_reg_meas_temp_t;
203+
204+
#define SFE_AS7331_REGISTER_MEAS_MRES1 0x02
205+
typedef union {
206+
struct {
207+
uint8_t res_l;
208+
uint8_t res_h;
209+
};
210+
uint16_t word;
211+
} sfe_as7331_reg_meas_mres1_t;
212+
213+
#define SFE_AS7331_REGISTER_MEAS_MRES2 0x03
214+
typedef union {
215+
struct {
216+
uint8_t res_l;
217+
uint8_t res_h;
218+
};
219+
uint16_t word;
220+
} sfe_as7331_reg_meas_mres2_t;
221+
222+
223+
#define SFE_AS7331_REGISTER_MEAS_MRES3 0x04
224+
typedef union {
225+
struct {
226+
uint8_t res_l;
227+
uint8_t res_h;
228+
};
229+
uint16_t word;
230+
} sfe_as7331_reg_meas_mres3_t;
231+
232+
233+
#define SFE_AS7331_REGISTER_MEAS_OUTCONV_L 0x05
234+
typedef union {
235+
struct {
236+
uint8_t outconv_l;
237+
uint8_t outconv_m;
238+
};
239+
uint16_t word;
240+
} sfe_as7331_reg_meas_outconv_l_t;
241+
242+
243+
#define SFE_AS7331_REGISTER_MEAS_OUTCONV_H 0x06
244+
typedef union {
245+
struct {
246+
uint8_t outconv_h;
247+
uint8_t zeros;
248+
};
249+
uint16_t word;
250+
} sfe_as7331_reg_meas_outconv_h_t;
251+

0 commit comments

Comments
 (0)