libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
l1/adc.h
Go to the documentation of this file.
1/** @defgroup adc_defines ADC Defines
2
3@brief <b>Defined Constants and Types for the STM32L1xx Analog to
4Digital Converters</b>
5
6@ingroup STM32L1xx_defines
7
8@version 1.0.0
9
10@author @htmlonly &copy; @endhtmlonly 2013 Karl Palsson <karlp@remake.is>
11
12LGPL License Terms @ref lgpl_license
13 */
14/*
15 * This file is part of the libopencm3 project.
16 *
17 * Copyright (C) 2013 Karl Palsson <karlp@remake.is>
18 *
19 * This library is free software: you can redistribute it and/or modify
20 * it under the terms of the GNU Lesser General Public License as published by
21 * the Free Software Foundation, either version 3 of the License, or
22 * (at your option) any later version.
23 *
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU Lesser General Public License for more details.
28 *
29 * You should have received a copy of the GNU Lesser General Public License
30 * along with this library. If not, see <http://www.gnu.org/licenses/>.
31 */
32
33#ifndef LIBOPENCM3_ADC_H
34#define LIBOPENCM3_ADC_H
35
37
38#define ADC_MAX_REGULAR_SEQUENCE 28
39/* 26 in L/M, but 32 in two banks for M+/H density */
40#define ADC_MAX_CHANNELS 32
41
42/* ADC sample time register 3 (ADC_SMPR3) */
43#define ADC_SMPR3(block) MMIO32((block) + 0x14)
44#define ADC1_SMPR3 ADC_SMPR3(ADC1)
45
46/* ADC injected channel data offset register x (ADC_JOFRx) (x=1..4) */
47#define ADC_JOFR1(block) MMIO32((block) + 0x18)
48#define ADC_JOFR2(block) MMIO32((block) + 0x1c)
49#define ADC_JOFR3(block) MMIO32((block) + 0x20)
50#define ADC_JOFR4(block) MMIO32((block) + 0x24)
51
52/* ADC watchdog high threshold register (ADC_HTR) */
53#define ADC_HTR(block) MMIO32((block) + 0x28)
54
55/* ADC watchdog low threshold register (ADC_LTR) */
56#define ADC_LTR(block) MMIO32((block) + 0x2c)
57
58/* ADC regular sequence register 1 (ADC_SQR1) */
59#define ADC_SQR1(block) MMIO32((block) + 0x30)
60
61/* ADC regular sequence register 2 (ADC_SQR2) */
62#define ADC_SQR2(block) MMIO32((block) + 0x34)
63
64/* ADC regular sequence register 3 (ADC_SQR3) */
65#define ADC_SQR3(block) MMIO32((block) + 0x38)
66
67/* ADC regular sequence register 4 (ADC_SQR4) */
68#define ADC_SQR4(block) MMIO32((block) + 0x3c)
69#define ADC1_SQR4 ADC_SQR4(ADC1)
70
71/* ADC regular sequence register 5 (ADC_SQR5) */
72#define ADC_SQR5(block) MMIO32((block) + 0x40)
73#define ADC1_SQR5 ADC_SQR5(ADC1)
74
75/* ADC injected sequence register (ADC_JSQR) */
76#define ADC_JSQR(block) MMIO32((block) + 0x44)
77
78/* ADC injected data register x (ADC_JDRx) (x=1..4) */
79#define ADC_JDR1(block) MMIO32((block) + 0x48)
80#define ADC_JDR2(block) MMIO32((block) + 0x4c)
81#define ADC_JDR3(block) MMIO32((block) + 0x50)
82#define ADC_JDR4(block) MMIO32((block) + 0x54)
83
84/* ADC regular data register (ADC_DR) */
85#define ADC_DR(block) MMIO32((block) + 0x58)
86
87/* ADC sample time register 0 (ADC_SMPR0) (high/med+ only) */
88#define ADC_SMPR0(block) MMIO32((block) + 0x5c)
89#define ADC1_SMPR0 ADC_SMPR0(ADC1)
90
91/** @defgroup adc_channel ADC Channel Numbers
92 * @ingroup adc_defines
93 *
94 *@{*/
95#define ADC_CHANNEL_TEMP ADC_CHANNEL16
96#define ADC_CHANNEL_VREF ADC_CHANNEL17
97/**@}*/
98
99/* --- ADC_SR values ------------------------------------------------------- */
100/****************************************************************************/
101/** @defgroup adc_sr_values ADC Status Register Flags
102 * @ingroup adc_defines
103 *
104 *@{*/
105
106/* JCNR:*//** Injected channel not ready */
107#define ADC_SR_JCNR (1 << 9)
108
109/* RCNR:*//** Regular channel not ready */
110#define ADC_SR_RCNR (1 << 8)
111
112/* ADONS:*//** ADC ON status */
113#define ADC_SR_ADONS (1 << 6)
114
115/**@}*/
116
117/* --- ADC_CR1 values ------------------------------------------------------- */
118#define ADC_CR1_PDI (1 << 17)
119#define ADC_CR1_PDD (1 << 16)
120
121#define ADC_CR1_AWDCH_MAX 26
122
123/* EXTSEL[3:0]: External event selection for regular group. */
124/****************************************************************************/
125/** @defgroup adc_trigger_regular ADC Trigger Identifier for Regular group
126@ingroup adc_defines
127
128@{*/
129#define ADC_CR2_EXTSEL_TIM9_CC2 (0 << ADC_CR2_EXTSEL_SHIFT)
130#define ADC_CR2_EXTSEL_TIM9_TRGO (1 << ADC_CR2_EXTSEL_SHIFT)
131#define ADC_CR2_EXTSEL_TIM2_CC3 (2 << ADC_CR2_EXTSEL_SHIFT)
132#define ADC_CR2_EXTSEL_TIM2_CC2 (3 << ADC_CR2_EXTSEL_SHIFT)
133#define ADC_CR2_EXTSEL_TIM3_TRGO (4 << ADC_CR2_EXTSEL_SHIFT)
134#define ADC_CR2_EXTSEL_TIM4_CC4 (5 << ADC_CR2_EXTSEL_SHIFT)
135#define ADC_CR2_EXTSEL_TIM2_TRGO (6 << ADC_CR2_EXTSEL_SHIFT)
136#define ADC_CR2_EXTSEL_TIM3_CC1 (7 << ADC_CR2_EXTSEL_SHIFT)
137#define ADC_CR2_EXTSEL_TIM3_CC3 (8 << ADC_CR2_EXTSEL_SHIFT)
138#define ADC_CR2_EXTSEL_TIM4_TRGO (9 << ADC_CR2_EXTSEL_SHIFT)
139#define ADC_CR2_EXTSEL_TIM6_TRGO (10 << ADC_CR2_EXTSEL_SHIFT)
140/* reserved.... */
141#define ADC_CR2_EXTSEL_EXTI11 (15 << ADC_CR2_EXTSEL_SHIFT)
142/**@}*/
143
144
145/* FIXME - JEXTSEL values here */
146
147/* FIXME- add the values here */
148#define ADC_CR2_DELS_SHIFT 4
149#define ADC_CR2_DELS_MASK 0x7
150
151#define ADC_CR2_ADC_CFG (1 << 2)
152
153
154
155
156/* --- ADC_SMPRx generic values -------------------------------------------- */
157/****************************************************************************/
158/* ADC_SMPRG ADC Sample Time Selection for Channels */
159/** @defgroup adc_sample_rg ADC Sample Time Selection for All Channels
160@ingroup adc_defines
161
162@{*/
163#define ADC_SMPR_SMP_4CYC 0x0
164#define ADC_SMPR_SMP_9CYC 0x1
165#define ADC_SMPR_SMP_16CYC 0x2
166#define ADC_SMPR_SMP_24CYC 0x3
167#define ADC_SMPR_SMP_48CYC 0x4
168#define ADC_SMPR_SMP_96CYC 0x5
169#define ADC_SMPR_SMP_192CYC 0x6
170#define ADC_SMPR_SMP_384CYC 0x7
171/**@}*/
172
173#define ADC_SQR_MASK 0x1f
174#define ADC_SQR_MAX_CHANNELS_REGULAR 28 /* m+/h only, otherwise 27 */
175
176/** @defgroup adc_ccr_adcpre ADC Prescale
177@ingroup adc_defines
178@{*/
179#define ADC_CCR_ADCPRE_BY1 (0x0 << 16)
180#define ADC_CCR_ADCPRE_BY2 (0x1 << 16)
181#define ADC_CCR_ADCPRE_BY4 (0x2 << 16)
182/**@}*/
183#define ADC_CCR_ADCPRE_MASK (0x3 << 16)
184#define ADC_CCR_ADCPRE_SHIFT 16
185
187
189
190#endif
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33