libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
4l/adcife.h
Go to the documentation of this file.
1/*
2 * This file is part of the libopencm3 project.
3 *
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef LIBOPENCM3_SAM4L_ADCIFE_H
19#define LIBOPENCM3_SAM4L_ADCIFE_H
20
22
23
24/* Analog to Digital Converter Interface (ADCIFE) registers. */
25
26/* 0x0000 Control Register CR Write-Only 0x00000000 */
27#define ADCIFE_CR MMIO32(ADCIFE_BASE + 0x0000)
28
29/* 0x0004 Configuration Register CFG Read/Write 0x00000000 */
30#define ADCIFE_CFG MMIO32(ADCIFE_BASE + 0x0004)
31
32/* 0x0008 Status Register SR Read-Only 0x00000000 */
33#define ADCIFE_SR MMIO32(ADCIFE_BASE + 0x008)
34
35/* 0x000C Status Clear Register SCR Write-Only 0x00000000 */
36#define ADCIFE_SCR MMIO32(ADCIFE_BASE + 0x000C)
37
38/* 0x0014 Sequencer Configuration Register SEQCFG Read/Write 0x00000000 */
39#define ADCIFE_SEQCFG MMIO32(ADCIFE_BASE + 0x0014)
40
41/* 0x0018 Configuration Direct Memory Access Register CDMA Write-Only 0x00000000 */
42#define ADCIFE_CDMA MMIO32(ADCIFE_BASE + 0x0018)
43
44/* 0x001C Timing Configuration Register TIM Read/Write 0x00000000 */
45#define ADCIFE_TIM MMIO32(ADCIFE_BASE + 0x001C)
46
47/* 0x0020 Internal Timer Register ITIMER Read/Write 0x00000000 */
48#define ADCIFE_ITIMER MMIO32(ADCIFE_BASE + 0x0020)
49
50/* 0x0024 Window Monitor Configuration Register WCFG Read/Write 0x00000000 */
51#define ADCIFE_WCFG MMIO32(ADCIFE_BASE + 0x0024)
52
53/* 0x0028 Window Monitor Threshold Configuration Register WTH Read/Write 0x00000000 */
54#define ADCIFE_WTH MMIO32(ADCIFE_BASE + 0x0028)
55
56/* 0x002C Sequencer Last Converted Value Register LCV Read-Only 0x00000000 */
57#define ADCIFE_LCV MMIO32(ADCIFE_BASE + 0x002C)
58
59/* 0x0030 Interrupt Enable Register IER Write-Only 0x00000000 */
60#define ADCIFE_IER MMIO32(ADCIFE_BASE + 0x0030)
61
62/* 0x0034 Interrupt Disable Register IDR Write-Only 0x00000000 */
63#define ADCIFE_IDR MMIO32(ADCIFE_BASE + 0x0034)
64
65/* 0x0038 Interrupt Mask Register IMR Read-Only 0x00000000 */
66#define ADCIFE_IMR MMIO32(ADCIFE_BASE + 0x0038)
67
68/* 0x003C Calibration Register CALIB Read/Write 0x00000000 */
69#define ADCIFE_CALIB MMIO32(ADCIFE_BASE + 0x003C)
70
71/* 0x0040 Version Register VERSION Read-Only - */
72#define ADCIFE_VERSION MMIO32(ADCIFE_BASE + 0x0040)
73
74/* 0x0044 Parameter Register PARAMETER Read-Only - */
75#define ADCIFE_PARAMETER MMIO32(ADCIFE_BASE + 0x0044)
76
77
78/* --------- Register Contents --------------------------- */
79#define ADCIFE_CR_SWRST (1 << 0)
80#define ADCIFE_CR_TSTOP (1 << 1)
81#define ADCIFE_CR_TSTART (1 << 2)
82#define ADCIFE_CR_STRIG (1 << 3)
83#define ADCIFE_CR_REFBUFEN (1 << 4)
84#define ADCIFE_CR_REFBUFDIS (1 << 5)
85#define ADCIFE_CR_EN (1 << 8)
86#define ADCIFE_CR_DIS (1 << 9)
87#define ADCIFE_CR_BGREQEN (1 << 10)
88#define ADCIFE_CR_BGREQDIS (1 << 11)
89
90#define _MASKED_VALUE(V, S, M) (((V) << (S)) & (M))
91
92#define ADCIFE_CFG_REFSEL_SHIFT (1)
93#define ADCIFE_CFG_REFSEL_MASK (7 << ADCIFE_CFG_REFSEL_SHIFT)
94#define ADCIFE_CFG_REFSEL_MASKED(V) _MASKED_VALUE((V), ADCIFE_CFG_REFSEL_SHIFT, ADCIFE_CFG_REFSEL_MASK)
95#define ADCIFE_CFG_SPEED_SHIFT (4)
96#define ADCIFE_CFG_SPEED_MASK (3 << ADCIFE_CFG_SPEED_SHIFT)
97#define ADCIFE_CFG_SPEED_MASKED(V) _MASKED_VALUE((V), ADCIFE_CFG_SPEED_SHIFT, ADCIFE_CFG_SPEED_MASK)
98#define ADCIFE_CFG_CLKSEL (1 << 6)
99#define ADCIFE_CFG_PRESCAL_SHIFT (8)
100#define ADCIFE_CFG_PRESCAL_MASK (3 << ADCIFE_CFG_PRESCAL_SHIFT)
101#define ADCIFE_CFG_PRESCAL_MASKED(V) _MASKED_VALUE((V), ADCIFE_CFG_PRESCAL_SHIFT, ADCIFE_CFG_PRESCAL_MASK)
102
103#define ADCIFE_SR_SEOC (1 << 0)
104#define ADCIFE_SR_LOVR (1 << 1)
105#define ADCIFE_SR_WM (1 << 2)
106#define ADCIFE_SR_SMTRG (1 << 3)
107#define ADCIFE_SR_TTO (1 << 5)
108#define ADCIFE_SR_EN (1 << 24)
109#define ADCIFE_SR_TBUSY (1 << 25)
110#define ADCIFE_SR_SBUSY (1 << 26)
111#define ADCIFE_SR_CBUSY (1 << 27)
112#define ADCIFE_SR_REFBUF (1 << 28)
113#define ADCIFE_SR_BGREQ (1 << 30)
114
115#define ADCIFE_IR_SEOC (1 << 0)
116#define ADCIFE_IR_LOVR (1 << 1)
117#define ADCIFE_IR_WM (1 << 2)
118#define ADCIFE_IR_SMTRG (1 << 3)
119#define ADCIFE_IR_TTO (1 << 5)
120
121#define ADCIFE_SEQCFG_HWLA (1 << 0)
122#define ADCIFE_SEQCFG_BIPOLAR (1 << 2)
123#define ADCIFE_SEQCFG_GAIN_SHIFT (4)
124#define ADCIFE_SEQCFG_GAIN_MASK (7 << ADCIFE_SEQCFG_GAIN_SHIFT)
125#define ADCIFE_SEQCFG_GAIN_MASKED(V) _MASKED_VALUE((V), ADCIFE_SEQCFG_GAIN_SHIFT, ADCIFE_SEQCFG_GAIN_MASK)
126#define ADCIFE_SEQCFG_GCOMP (1 << 7)
127#define ADCIFE_SEQCFG_TRGSEL_SHIFT (8)
128#define ADCIFE_SEQCFG_TRGSEL_MASK (7 << ADCIFE_SEQCFG_TRGSEL_SHIFT)
129#define ADCIFE_SEQCFG_TRGSEL_MASKED(V) _MASKED_VALUE((V), ADCIFE_SEQCFG_TRGSEL_SHIFT, ADCIFE_SEQCFG_TRGSEL_MASK)
130#define ADCIFE_SEQCFG_RES (1 << 12)
131#define ADCIFE_SEQCFG_INTERNAL_SHIFT (14)
132#define ADCIFE_SEQCFG_INTERNAL_MASK (3 << ADCIFE_SEQCFG_INTERNAL_SHIFT)
133#define ADCIFE_SEQCFG_INTERNAL_MASKED(V) _MASKED_VALUE((V), ADCIFE_SEQCFG_INTERNAL_SHIFT, ADCIFE_SEQCFG_INTERNAL_MASK)
134#define ADCIFE_SEQCFG_MUXPOS_SHIFT (16)
135#define ADCIFE_SEQCFG_MUXPOS_MASK (0xf << ADCIFE_SEQCFG_MUXPOS_SHIFT)
136#define ADCIFE_SEQCFG_MUXPOS_MASKED(V) _MASKED_VALUE((V), ADCIFE_SEQCFG_MUXPOS_SHIFT, ADCIFE_SEQCFG_MUXPOS_MASK)
137#define ADCIFE_SEQCFG_MUXNEG_SHIFT (20)
138#define ADCIFE_SEQCFG_MUXNEG_MASK (7 << ADCIFE_SEQCFG_MUXNEG_SHIFT)
139#define ADCIFE_SEQCFG_MUXNEG_MASKED(V) _MASKED_VALUE((V), ADCIFE_SEQCFG_MUXNEG_SHIFT, ADCIFE_SEQCFG_MUXNEG_MASK)
140#define ADCIFE_SEQCFG_ZOOMRANGE_SHIFT (28)
141#define ADCIFE_SEQCFG_ZOOMRANGE_MASK (7 << ADCIFE_SEQCFG_ZOOMRANGE_SHIFT)
142#define ADCIFE_SEQCFG_ZOOMRANGE_MASKED(V) _MASKED_VALUE((V), ADCIFE_SEQCFG_ZOOMRANGE_SHIFT, ADCIFE_SEQCFG_ZOOMRANGE_MASK)
143
144/* If x is of type enum adcife_prescal, the prescale value is 2^(x + 2) */
154};
155
161};
162
169};
170
174};
175
192};
193
197};
198
207};
208
218};
219
221 union {
222 uint32_t lcv;
223 struct {
224 uint16_t value;
225 uint8_t channel;
226 uint8_t reserved;
229};
230
231#define lc_channel _lc_u._lc_s.channel
232#define lc_value _lc_u._lc_s.value
233
235
236void adcife_enable_sync(void);
238 enum adcife_refsel ref,
239 enum adcife_speed speed,
240 enum adcife_clk clk,
241 enum adcife_prescal prescal);
245void adcife_set_gain(enum adcife_gain gain);
246void adcife_set_bipolar(bool enable);
247void adcife_set_left_adjust(bool enable);
248void adcife_start_conversion(void);
249void adcife_wait_conversion(void);
250struct adcife_lcv adcife_get_lcv(void);
251void adcife_enable_interrupts(uint32_t imask);
252void adcife_disable_interrupts(uint32_t imask);
253void adcife_timer_start(void);
254void adcife_timer_stop(void);
255void adcife_timer_set_timeout(uint16_t timeout);
256
258
259#endif
void adcife_enable_sync(void)
Enable ADC interface.
Definition: adcife.c:18
adcife_resolution
Definition: 4l/adcife.h:194
@ ADCIFE_RESOLUTION_12BITS
Definition: 4l/adcife.h:195
@ ADCIFE_RESOLUTION_8BITS
Definition: 4l/adcife.h:196
void adcife_set_bipolar(bool enable)
Definition: adcife.c:62
void adcife_timer_stop(void)
Definition: adcife.c:113
void adcife_set_left_adjust(bool enable)
Definition: adcife.c:71
struct adcife_lcv adcife_get_lcv(void)
Definition: adcife.c:91
adcife_gain
Definition: 4l/adcife.h:209
@ ADCIFE_GAIN_4X
Definition: 4l/adcife.h:212
@ ADCIFE_GAIN_8X
Definition: 4l/adcife.h:213
@ ADCIFE_GAIN_32X
Definition: 4l/adcife.h:215
@ ADCIFE_GAIN_2X
Definition: 4l/adcife.h:211
@ ADCIFE_GAIN_1X
Definition: 4l/adcife.h:210
@ ADCIFE_GAIN_16X
Definition: 4l/adcife.h:214
@ ADCIFE_GAIN_0_5X
Definition: 4l/adcife.h:217
@ ADCIFE_GAIN_64X
Definition: 4l/adcife.h:216
void adcife_timer_start(void)
Definition: adcife.c:108
adcife_channel
Definition: 4l/adcife.h:176
@ ADCIFE_CHANNEL_AD2
Definition: 4l/adcife.h:179
@ ADCIFE_CHANNEL_AD3
Definition: 4l/adcife.h:180
@ ADCIFE_CHANNEL_AD0
Definition: 4l/adcife.h:177
@ ADCIFE_CHANNEL_AD9
Definition: 4l/adcife.h:186
@ ADCIFE_CHANNEL_AD14
Definition: 4l/adcife.h:191
@ ADCIFE_CHANNEL_AD5
Definition: 4l/adcife.h:182
@ ADCIFE_CHANNEL_AD8
Definition: 4l/adcife.h:185
@ ADCIFE_CHANNEL_AD10
Definition: 4l/adcife.h:187
@ ADCIFE_CHANNEL_AD12
Definition: 4l/adcife.h:189
@ ADCIFE_CHANNEL_AD6
Definition: 4l/adcife.h:183
@ ADCIFE_CHANNEL_AD13
Definition: 4l/adcife.h:190
@ ADCIFE_CHANNEL_AD1
Definition: 4l/adcife.h:178
@ ADCIFE_CHANNEL_AD4
Definition: 4l/adcife.h:181
@ ADCIFE_CHANNEL_AD11
Definition: 4l/adcife.h:188
@ ADCIFE_CHANNEL_AD7
Definition: 4l/adcife.h:184
void adcife_set_resolution(enum adcife_resolution res)
Definition: adcife.c:41
adcife_clk
Definition: 4l/adcife.h:171
@ ADCIFE_CLK_APB
Definition: 4l/adcife.h:173
@ ADCIFE_CLK_GENERIC
Definition: 4l/adcife.h:172
void adcife_start_conversion(void)
Definition: adcife.c:80
adcife_refsel
Definition: 4l/adcife.h:163
@ ADCIFE_REFSEL_HALF_VCC
Definition: 4l/adcife.h:168
@ ADCIFE_REFSEL_EXTERNAL1
Definition: 4l/adcife.h:166
@ ADCIFE_REFSEL_0_625xVCC
Definition: 4l/adcife.h:165
@ ADCIFE_REFSEL_EXTERNAL2
Definition: 4l/adcife.h:167
@ ADCIFE_REFSEL_INTERNAL1V
Definition: 4l/adcife.h:164
void adcife_select_trigger(enum adcife_trigger trig)
Definition: adcife.c:50
void adcife_disable_interrupts(uint32_t imask)
Definition: adcife.c:103
adcife_prescal
Definition: 4l/adcife.h:145
@ ADCIFE_PRESCAL_DIV16
Definition: 4l/adcife.h:148
@ ADCIFE_PRESCAL_DIV32
Definition: 4l/adcife.h:149
@ ADCIFE_PRESCAL_DIV128
Definition: 4l/adcife.h:151
@ ADCIFE_PRESCAL_DIV512
Definition: 4l/adcife.h:153
@ ADCIFE_PRESCAL_DIV256
Definition: 4l/adcife.h:152
@ ADCIFE_PRESCAL_DIV4
Definition: 4l/adcife.h:146
@ ADCIFE_PRESCAL_DIV64
Definition: 4l/adcife.h:150
@ ADCIFE_PRESCAL_DIV8
Definition: 4l/adcife.h:147
adcife_trigger
Definition: 4l/adcife.h:199
@ ADCIFE_TRIGGER_ITS
Definition: 4l/adcife.h:202
@ ADCIFE_TRIGGER_CONT
Definition: 4l/adcife.h:203
@ ADCIFE_TRIGGER_EXT_FALL
Definition: 4l/adcife.h:205
@ ADCIFE_TRIGGER_IADC_TMR
Definition: 4l/adcife.h:201
@ ADCIFE_TRIGGER_SW
Definition: 4l/adcife.h:200
@ ADCIFE_TRIGGER_EXT_BOTH
Definition: 4l/adcife.h:206
@ ADCIFE_TRIGGER_EXT_RIS
Definition: 4l/adcife.h:204
adcife_speed
Definition: 4l/adcife.h:156
@ ADCIFE_SPEED_150KSPS
Definition: 4l/adcife.h:159
@ ADCIFE_SPEED_300KSPS
Definition: 4l/adcife.h:157
@ ADCIFE_SPEED_225KSPS
Definition: 4l/adcife.h:158
@ ADCIFE_SPEED_75KSPS
Definition: 4l/adcife.h:160
#define ADCIFE_CFG_CLKSEL
Definition: 4l/adcife.h:98
void adcife_set_gain(enum adcife_gain gain)
Definition: adcife.c:56
void adcife_timer_set_timeout(uint16_t timeout)
Definition: adcife.c:118
void adcife_wait_conversion(void)
Definition: adcife.c:85
void adcife_select_channel(enum adcife_channel ad)
Definition: adcife.c:36
void adcife_enable_interrupts(uint32_t imask)
Definition: adcife.c:98
void adcife_configure(enum adcife_refsel ref, enum adcife_speed speed, enum adcife_clk clk, enum adcife_prescal prescal)
Definition: adcife.c:24
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33
union adcife_lcv::@0 _lc_u
uint16_t value
Definition: 4l/adcife.h:224
uint8_t channel
Definition: 4l/adcife.h:225
uint32_t lcv
Definition: 4l/adcife.h:222
uint8_t reserved
Definition: 4l/adcife.h:226
struct adcife_lcv::@0::@1 _lc_s