libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
adcife.c
Go to the documentation of this file.
1/** @addtogroup scif
2 *
3 * @brief <b>Access functions for the SAM4 Analog to Digital Converter Interface (ADCIFE)</b>
4 * @ingroup SAM4
5 * LGPL License Terms @ref lgpl_license
6 * @author @htmlonly &copy; @endhtmlonly 2016
7 * Maxim Sloyko <maxims@google.com>
8 *
9 */
10
12
13/** @brief Enable ADC interface. Must be done before any other configuration.
14 *
15 * This function does it synchronously and returns only when the interface is
16 * actually enabled.
17 */
19{
21 while (!(ADCIFE_SR & ADCIFE_SR_EN));
22}
23
25 enum adcife_refsel ref,
26 enum adcife_speed speed,
27 enum adcife_clk clk,
28 enum adcife_prescal prescal)
29{
33 | clk;
34}
35
37{
39}
40
42{
43 if (ADCIFE_RESOLUTION_12BITS == res) {
44 ADCIFE_SEQCFG &= ~ADCIFE_SEQCFG_RES;
45 } else {
47 }
48}
49
51{
52 ADCIFE_SEQCFG &= ~ADCIFE_SEQCFG_TRGSEL_MASK;
54}
55
57{
58 ADCIFE_SEQCFG &= ~ADCIFE_SEQCFG_GAIN_MASK;
60}
61
62void adcife_set_bipolar(bool enable)
63{
64 if (enable) {
66 } else {
67 ADCIFE_SEQCFG &= ~ADCIFE_SEQCFG_BIPOLAR;
68 }
69}
70
71void adcife_set_left_adjust(bool enable)
72{
73 if (enable) {
75 } else {
76 ADCIFE_SEQCFG &= ~ADCIFE_SEQCFG_HWLA;
77 }
78}
79
81{
83}
84
86{
87 while (!(ADCIFE_SR & ADCIFE_SR_SEOC));
89}
90
92{
93 struct adcife_lcv res;
94 res._lc_u.lcv = ADCIFE_LCV;
95 return res;
96}
97
98void adcife_enable_interrupts(uint32_t imask)
99{
100 ADCIFE_IER = imask;
101}
102
103void adcife_disable_interrupts(uint32_t imask)
104{
105 ADCIFE_IDR = imask;
106}
107
109{
111}
112
114{
116}
117
118void adcife_timer_set_timeout(uint16_t timeout)
119{
120 ADCIFE_TIM = timeout;
121}
#define ADCIFE_SEQCFG
Definition: 4l/adcife.h:39
adcife_resolution
Definition: 4l/adcife.h:194
@ ADCIFE_RESOLUTION_12BITS
Definition: 4l/adcife.h:195
#define ADCIFE_LCV
Definition: 4l/adcife.h:57
#define ADCIFE_SR_SEOC
Definition: 4l/adcife.h:103
#define ADCIFE_SEQCFG_TRGSEL_MASKED(V)
Definition: 4l/adcife.h:129
adcife_gain
Definition: 4l/adcife.h:209
#define ADCIFE_CR
Definition: 4l/adcife.h:27
#define ADCIFE_SR_EN
Definition: 4l/adcife.h:108
#define ADCIFE_IDR
Definition: 4l/adcife.h:63
#define ADCIFE_SEQCFG_RES
Definition: 4l/adcife.h:130
adcife_channel
Definition: 4l/adcife.h:176
#define ADCIFE_CFG_SPEED_MASKED(V)
Definition: 4l/adcife.h:97
adcife_clk
Definition: 4l/adcife.h:171
adcife_refsel
Definition: 4l/adcife.h:163
#define ADCIFE_CR_STRIG
Definition: 4l/adcife.h:82
#define ADCIFE_CFG_PRESCAL_MASKED(V)
Definition: 4l/adcife.h:101
#define ADCIFE_SR
Definition: 4l/adcife.h:33
#define ADCIFE_CR_TSTOP
Definition: 4l/adcife.h:80
adcife_prescal
Definition: 4l/adcife.h:145
#define ADCIFE_IER
Definition: 4l/adcife.h:60
adcife_trigger
Definition: 4l/adcife.h:199
#define ADCIFE_SEQCFG_MUXPOS_MASKED(V)
Definition: 4l/adcife.h:136
#define ADCIFE_CFG
Definition: 4l/adcife.h:30
#define ADCIFE_SEQCFG_BIPOLAR
Definition: 4l/adcife.h:122
adcife_speed
Definition: 4l/adcife.h:156
#define ADCIFE_TIM
Definition: 4l/adcife.h:45
#define ADCIFE_SEQCFG_GAIN_MASKED(V)
Definition: 4l/adcife.h:125
#define ADCIFE_CR_EN
Definition: 4l/adcife.h:85
#define ADCIFE_SCR
Definition: 4l/adcife.h:36
#define ADCIFE_CFG_REFSEL_MASKED(V)
Definition: 4l/adcife.h:94
#define ADCIFE_CR_TSTART
Definition: 4l/adcife.h:81
#define ADCIFE_SEQCFG_HWLA
Definition: 4l/adcife.h:121
void adcife_enable_sync(void)
Enable ADC interface.
Definition: adcife.c:18
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
void adcife_timer_start(void)
Definition: adcife.c:108
void adcife_set_resolution(enum adcife_resolution res)
Definition: adcife.c:41
void adcife_start_conversion(void)
Definition: adcife.c:80
void adcife_select_trigger(enum adcife_trigger trig)
Definition: adcife.c:50
void adcife_disable_interrupts(uint32_t imask)
Definition: adcife.c:103
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
union adcife_lcv::@0 _lc_u
uint32_t lcv
Definition: 4l/adcife.h:222