libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
f0/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 STM32F0xx Analog to Digital
4 * Converter</b>
5 *
6 * @ingroup STM32F0xx_defines
7 *
8 * @version 1.0.0
9 *
10 * @date 11 July 2013
11 *
12 * LGPL License Terms @ref lgpl_license
13 */
14/*
15 * This file is part of the libopencm3 project.
16 *
17 * Copyright (C) 2013 Frantisek Burian <BuFran@seznam.cz>
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
38
39/*****************************************************************************/
40/* Module definitions */
41/*****************************************************************************/
42
43/** @defgroup adc_reg_base ADC register base addresses
44 * @ingroup adc_defines
45 *
46 *@{*/
47#define ADC ADC_BASE
48#define ADC1 ADC_BASE/* for API compatibility */
49/**@}*/
50
51/*****************************************************************************/
52/* Register definitions */
53/*****************************************************************************/
54
55#define ADC1_ISR ADC_ISR(ADC)
56#define ADC1_IER ADC_IER(ADC)
57#define ADC1_CR ADC_CR(ADC)
58#define ADC1_CFGR1 ADC_CFGR1(ADC)
59#define ADC1_CFGR2 ADC_CFGR2(ADC)
60#define ADC1_SMPR1 ADC_SMPR1(ADC)
61#define ADC_SMPR(adc) ADC_SMPR1(adc) /* Compatibility */
62#define ADC1_SMPR ADC_SMPR1(ADC) /* Compatibility */
63#define ADC1_TR1 ADC_TR1(ADC)
64#define ADC_TR(adc) ADC_TR1(adc) /* Compatibility */
65#define ADC1_TR ADC1_TR(ADC) /* Compatibility */
66#define ADC1_CHSELR ADC_CHSELR(ADC)
67#define ADC1_DR ADC_DR(ADC)
68#define ADC1_CCR ADC_CCR(ADC)
69
70/*****************************************************************************/
71/* Register values */
72/*****************************************************************************/
73
74/* ADC_CFGR1 Values ---------------------------------------------------------*/
75
76/** ALIGN: Data alignment */
77#define ADC_CFGR1_ALIGN (1 << 5)
78
79/* EXTSEL[2:0]: External trigger selection for regular group */
80#define ADC_CFGR1_EXTSEL_SHIFT 6
81#define ADC_CFGR1_EXTSEL_MASK 0x7
82/** @defgroup adc_cfgr1_extsel ADC external trigger selection values
83 *@{*/
84#define ADC_CFGR1_EXTSEL_TIM1_TRGO 0x0
85#define ADC_CFGR1_EXTSEL_TIM1_CC4 0x1
86#define ADC_CFGR1_EXTSEL_TIM2_TRGO 0x2
87#define ADC_CFGR1_EXTSEL_TIM3_TRGO 0x3
88#define ADC_CFGR1_EXTSEL_TIM15_TRGO 0x4
89/**@}*/
90
91/* ADC_CFGR2 Values ---------------------------------------------------------*/
92
93#define ADC_CFGR2_CKMODE_SHIFT 30
94#define ADC_CFGR2_CKMODE (3 << ADC_CFGR2_CKMODE_SHIFT)
95#define ADC_CFGR2_CKMODE_CK_ADC (0 << ADC_CFGR2_CKMODE_SHIFT)
96#define ADC_CFGR2_CKMODE_PCLK_DIV2 (1 << ADC_CFGR2_CKMODE_SHIFT)
97#define ADC_CFGR2_CKMODE_PCLK_DIV4 (2 << ADC_CFGR2_CKMODE_SHIFT)
98
99/* ADC_SMPR Values ----------------------------------------------------------*/
100
101#define ADC_SMPR_SMP_SHIFT 0
102#define ADC_SMPR_SMP (7 << ADC_SMPR_SMP_SHIFT)
103#define ADC_SMPR_SMP_001DOT5 (0 << ADC_SMPR_SMP_SHIFT)
104#define ADC_SMPR_SMP_007DOT5 (1 << ADC_SMPR_SMP_SHIFT)
105#define ADC_SMPR_SMP_013DOT5 (2 << ADC_SMPR_SMP_SHIFT)
106#define ADC_SMPR_SMP_028DOT5 (3 << ADC_SMPR_SMP_SHIFT)
107#define ADC_SMPR_SMP_041DOT5 (4 << ADC_SMPR_SMP_SHIFT)
108#define ADC_SMPR_SMP_055DOT5 (5 << ADC_SMPR_SMP_SHIFT)
109#define ADC_SMPR_SMP_071DOT5 (6 << ADC_SMPR_SMP_SHIFT)
110#define ADC_SMPR_SMP_239DOT5 (7 << ADC_SMPR_SMP_SHIFT)
111
112
113/*****************************************************************************/
114/* API definitions */
115/*****************************************************************************/
116
117/** @defgroup adc_api_res ADC resolutions
118 * @ingroup adc_defines
119 *
120 *@{*/
121#define ADC_RESOLUTION_12BIT ADC_CFGR1_RES_12_BIT
122#define ADC_RESOLUTION_10BIT ADC_CFGR1_RES_10_BIT
123#define ADC_RESOLUTION_8BIT ADC_CFGR1_RES_8_BIT
124#define ADC_RESOLUTION_6BIT ADC_CFGR1_RES_6_BIT
125/**@}*/
126
127/** @defgroup adc_api_smptime ADC sampling time
128 * @ingroup adc_defines
129 *
130 *@{*/
131#define ADC_SMPTIME_001DOT5 ADC_SMPR_SMP_001DOT5
132#define ADC_SMPTIME_007DOT5 ADC_SMPR_SMP_007DOT5
133#define ADC_SMPTIME_013DOT5 ADC_SMPR_SMP_013DOT5
134#define ADC_SMPTIME_028DOT5 ADC_SMPR_SMP_028DOT5
135#define ADC_SMPTIME_041DOT5 ADC_SMPR_SMP_041DOT5
136#define ADC_SMPTIME_055DOT5 ADC_SMPR_SMP_055DOT5
137#define ADC_SMPTIME_071DOT5 ADC_SMPR_SMP_071DOT5
138#define ADC_SMPTIME_239DOT5 ADC_SMPR_SMP_239DOT5
139/**@}*/
140
141/** @defgroup adc_api_clksource ADC clock source
142 * @ingroup adc_defines
143 *
144 *@{*/
145#define ADC_CLKSOURCE_ADC ADC_CFGR2_CKMODE_CK_ADC
146#define ADC_CLKSOURCE_PCLK_DIV2 ADC_CFGR2_CKMODE_PCLK_DIV2
147#define ADC_CLKSOURCE_PCLK_DIV4 ADC_CFGR2_CKMODE_PCLK_DIV4
148/**@}*/
149
150/** @defgroup adc_channel ADC Channel Numbers
151 * @ingroup adc_defines
152 *
153 *@{*/
154#define ADC_CHANNEL_TEMP 16
155#define ADC_CHANNEL_VREF 17
156#define ADC_CHANNEL_VBAT 18
157/**@}*/
158
159/** @defgroup adc_api_opmode ADC Operation Modes
160 * @ingroup adc_defines
161 *
162 *@{*/
167};
168/**@}*/
169
170/*****************************************************************************/
171/* API Functions */
172/*****************************************************************************/
173
174
176
177/* Operation mode API */
178void adc_enable_discontinuous_mode(uint32_t adc);
179void adc_disable_discontinuous_mode(uint32_t adc);
180void adc_set_operation_mode(uint32_t adc, enum adc_opmode opmode);
181
182/* Trigger API */
183void adc_enable_external_trigger_regular(uint32_t adc, uint32_t trigger,
184 uint32_t polarity);
185void adc_disable_external_trigger_regular(uint32_t adc);
186
187/* Interrupt configuration */
188void adc_enable_watchdog_interrupt(uint32_t adc);
189void adc_disable_watchdog_interrupt(uint32_t adc);
190bool adc_get_watchdog_flag(uint32_t adc);
191void adc_clear_watchdog_flag(uint32_t adc);
192void adc_enable_eoc_sequence_interrupt(uint32_t adc);
193void adc_disable_eoc_sequence_interrupt(uint32_t adc);
194bool adc_get_eoc_sequence_flag(uint32_t adc);
195void adc_clear_eoc_sequence_flag(uint32_t adc);
196
197/* Basic configuration */
198void adc_set_clk_source(uint32_t adc, uint32_t source);
199void adc_enable_vbat_sensor(void);
200void adc_disable_vbat_sensor(void);
201void adc_calibrate_start(uint32_t adc)
202 LIBOPENCM3_DEPRECATED("see adc_calibrate/_async");
203void adc_calibrate_wait_finish(uint32_t adc)
204 LIBOPENCM3_DEPRECATED("see adc_is_calibrating");
205
206/* Analog Watchdog */
208void adc_enable_analog_watchdog_on_selected_channel(uint32_t adc, uint8_t chan);
209void adc_disable_analog_watchdog(uint32_t adc);
210void adc_set_watchdog_high_threshold(uint32_t adc, uint16_t threshold);
211void adc_set_watchdog_low_threshold(uint32_t adc, uint16_t threshold);
212
214
215#endif
#define END_DECLS
Definition: common.h:34
#define LIBOPENCM3_DEPRECATED(x)
Definition: common.h:46
#define BEGIN_DECLS
Definition: common.h:33
void adc_disable_vbat_sensor(void)
ADC Disable The VBat Sensor.
Definition: adc.c:398
void adc_calibrate_wait_finish(uint32_t adc) LIBOPENCM3_DEPRECATED("see adc_is_calibrating")
ADC Wait to finish the ADC calibration procedure.
Definition: adc.c:422
void adc_calibrate_start(uint32_t adc) LIBOPENCM3_DEPRECATED("see adc_calibrate/_async")
ADC Start the calibration procedure.
Definition: adc.c:410
void adc_enable_vbat_sensor(void)
ADC Enable The VBat Sensor.
Definition: adc.c:386
void adc_set_clk_source(uint32_t adc, uint32_t source)
ADC Set Clock Source.
Definition: adc.c:309
void adc_clear_watchdog_flag(uint32_t adc)
ADC Clear Analog Watchdog Flag.
Definition: adc.c:239
void adc_disable_eoc_sequence_interrupt(uint32_t adc)
ADC Disable Regular End-Of-Conversion Sequence Interrupt.
Definition: adc.c:261
void adc_disable_watchdog_interrupt(uint32_t adc)
ADC Disable Regular End-Of-Conversion Interrupt.
Definition: adc.c:213
void adc_clear_eoc_sequence_flag(uint32_t adc)
ADC Clear Regular End-Of-Conversion Sequence Flag.
Definition: adc.c:283
void adc_enable_watchdog_interrupt(uint32_t adc)
ADC Enable Analog Watchdog Interrupt.
Definition: adc.c:202
bool adc_get_eoc_sequence_flag(uint32_t adc)
ADC Read the Regular End-Of-Conversion Sequence Flag.
Definition: adc.c:272
bool adc_get_watchdog_flag(uint32_t adc)
ADC Read the Analog Watchdog Flag.
Definition: adc.c:228
void adc_enable_eoc_sequence_interrupt(uint32_t adc)
ADC Enable Regular End-Of-Conversion Sequence Interrupt.
Definition: adc.c:250
void adc_set_operation_mode(uint32_t adc, enum adc_opmode opmode)
ADC Set operation mode.
Definition: adc.c:120
void adc_disable_discontinuous_mode(uint32_t adc)
ADC Disable Discontinuous Mode for Regular Conversions.
Definition: adc.c:61
adc_opmode
Definition: f0/adc.h:163
void adc_enable_discontinuous_mode(uint32_t adc)
ADC Enable Discontinuous Mode for Regular Conversions.
Definition: adc.c:50
@ ADC_MODE_SCAN
Definition: f0/adc.h:165
@ ADC_MODE_SCAN_INFINITE
Definition: f0/adc.h:166
@ ADC_MODE_SEQUENTIAL
Definition: f0/adc.h:164
void adc_enable_external_trigger_regular(uint32_t adc, uint32_t trigger, uint32_t polarity)
ADC Enable an External Trigger for Regular Channels.
Definition: adc.c:162
void adc_disable_external_trigger_regular(uint32_t adc)
ADC Disable an External Trigger for Regular Channels.
Definition: adc.c:178
void adc_set_watchdog_high_threshold(uint32_t adc, uint16_t threshold)
ADC Set Analog Watchdog Upper Threshold.
Definition: adc.c:519
void adc_enable_analog_watchdog_on_all_channels(uint32_t adc)
ADC Enable Analog Watchdog for All Channels.
Definition: adc.c:481
void adc_enable_analog_watchdog_on_selected_channel(uint32_t adc, uint8_t chan)
ADC Enable Analog Watchdog for a Selected Channel.
Definition: adc.c:494
void adc_disable_analog_watchdog(uint32_t adc)
ADC Disable Analog Watchdog.
Definition: adc.c:507
void adc_set_watchdog_low_threshold(uint32_t adc, uint16_t threshold)
ADC Set Analog Watchdog Lower Threshold.
Definition: adc.c:531