Add adc defines.
[bertos.git] / bertos / cpu / cortex-m3 / io / stm32_adc.h
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
6  * Bertos is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  * As a special exception, you may use this file as part of a free software
21  * library without restriction.  Specifically, if other files instantiate
22  * templates or use macros or inline functions from this file, or you compile
23  * this file and link it with other files to produce an executable, this
24  * file does not by itself cause the resulting executable to be covered by
25  * the GNU General Public License.  This exception does not however
26  * invalidate any other reasons why the executable file might be covered by
27  * the GNU General Public License.
28  *
29  * Copyright 2010 Develer S.r.l. (http://www.develer.com/)
30  *
31  * -->
32  *
33  * \brief STM32F103xx adc definition.
34  */
35
36 #ifndef STM32_ADC_H
37 #define STM32_ADC_H
38
39 #include <cpu/types.h>
40
41 /* ADC dual mode */
42 #define ADC_MODE_INDEPENDENT                       ((uint32_t)0x00000000)
43 #define ADC_MODE_REGINJECSIMULT                    ((uint32_t)0x00010000)
44 #define ADC_MODE_REGSIMULT_ALTERTRIG               ((uint32_t)0x00020000)
45 #define ADC_MODE_INJECSIMULT_FASTINTERL            ((uint32_t)0x00030000)
46 #define ADC_MODE_INJECSIMULT_SLOWINTERL            ((uint32_t)0x00040000)
47 #define ADC_MODE_INJECSIMULT                       ((uint32_t)0x00050000)
48 #define ADC_MODE_REGSIMULT                         ((uint32_t)0x00060000)
49 #define ADC_MODE_FASTINTERL                        ((uint32_t)0x00070000)
50 #define ADC_MODE_SLOWINTERL                        ((uint32_t)0x00080000)
51 #define ADC_MODE_ALTERTRIG                         ((uint32_t)0x00090000)
52
53 /* ADC extrenal trigger sources for regular channels conversion */
54 #define ADC_EXTERNALTRIGCONV_T1_CC1                ((uint32_t)0x00000000)
55 #define ADC_EXTERNALTRIGCONV_T1_CC2                ((uint32_t)0x00020000)
56 #define ADC_EXTERNALTRIGCONV_T1_CC3                ((uint32_t)0x00040000)
57 #define ADC_EXTERNALTRIGCONV_T2_CC2                ((uint32_t)0x00060000)
58 #define ADC_EXTERNALTRIGCONV_T3_TRGO               ((uint32_t)0x00080000)
59 #define ADC_EXTERNALTRIGCONV_T4_CC4                ((uint32_t)0x000A0000)
60 #define ADC_EXTERNALTRIGCONV_EXT_IT11              ((uint32_t)0x000C0000)
61 #define ADC_EXTERNALTRIGCONV_NONE                  ((uint32_t)0x000E0000)
62
63 /* ADC data align */
64 #define ADC_DATAALIGN_RIGHT                        ((uint32_t)0x00000000)
65 #define ADC_DATAALIGN_LEFT                         ((uint32_t)0x00000800)
66
67 /* ADC channels */
68 #define ADC_CHANNEL_0                               ((uint8_t)0x00)
69 #define ADC_CHANNEL_1                               ((uint8_t)0x01)
70 #define ADC_CHANNEL_2                               ((uint8_t)0x02)
71 #define ADC_CHANNEL_3                               ((uint8_t)0x03)
72 #define ADC_CHANNEL_4                               ((uint8_t)0x04)
73 #define ADC_CHANNEL_5                               ((uint8_t)0x05)
74 #define ADC_CHANNEL_6                               ((uint8_t)0x06)
75 #define ADC_CHANNEL_7                               ((uint8_t)0x07)
76 #define ADC_CHANNEL_8                               ((uint8_t)0x08)
77 #define ADC_CHANNEL_9                               ((uint8_t)0x09)
78 #define ADC_CHANNEL_10                              ((uint8_t)0x0A)
79 #define ADC_CHANNEL_11                              ((uint8_t)0x0B)
80 #define ADC_CHANNEL_12                              ((uint8_t)0x0C)
81 #define ADC_CHANNEL_13                              ((uint8_t)0x0D)
82 #define ADC_CHANNEL_14                              ((uint8_t)0x0E)
83 #define ADC_CHANNEL_15                              ((uint8_t)0x0F)
84 #define ADC_CHANNEL_16                              ((uint8_t)0X10)
85 #define ADC_CHANNEL_17                              ((uint8_t)0X11)
86
87 /* ADC sampling times */
88 #define ADC_SAMPLETIME_1CYCLES5                    ((uint8_t)0x00)
89 #define ADC_SAMPLETIME_7CYCLES5                    ((uint8_t)0x01)
90 #define ADC_SAMPLETIME_13CYCLES5                   ((uint8_t)0x02)
91 #define ADC_SAMPLETIME_28CYCLES5                   ((uint8_t)0x03)
92 #define ADC_SAMPLETIME_41CYCLES5                   ((uint8_t)0x04)
93 #define ADC_SAMPLETIME_55CYCLES5                   ((uint8_t)0x05)
94 #define ADC_SAMPLETIME_71CYCLES5                   ((uint8_t)0x06)
95 #define ADC_SAMPLETIME_239CYCLES5                  ((uint8_t)0x07)
96
97 /* ADC extrenal trigger sources for injected channels conversion */
98 #define ADC_EXTERNALTRIGINJECCONV_T1_TRGO          ((uint32_t)0x00000000)
99 #define ADC_EXTERNALTRIGINJECCONV_T1_CC4           ((uint32_t)0x00001000)
100 #define ADC_EXTERNALTRIGINJECCONV_T2_TRGO          ((uint32_t)0x00002000)
101 #define ADC_EXTERNALTRIGINJECCONV_T2_CC1           ((uint32_t)0x00003000)
102 #define ADC_EXTERNALTRIGINJECCONV_T3_CC4           ((uint32_t)0x00004000)
103 #define ADC_EXTERNALTRIGINJECCONV_T4_TRGO          ((uint32_t)0x00005000)
104 #define ADC_EXTERNALTRIGINJECCONV_EXT_IT15         ((uint32_t)0x00006000)
105 #define ADC_EXTERNALTRIGINJECCONV_NONE             ((uint32_t)0x00007000)
106
107 /* ADC injected channel selection */
108 #define ADC_INJECTEDCHANNEL_1                       ((uint8_t)0x14)
109 #define ADC_INJECTEDCHANNEL_2                       ((uint8_t)0x18)
110 #define ADC_INJECTEDCHANNEL_3                       ((uint8_t)0x1C)
111 #define ADC_INJECTEDCHANNEL_4                       ((uint8_t)0x20)
112
113 /* ADC analog watchdog selection */
114 #define ADC_ANALOGWATCHDOG_SINGLEREGENABLE         ((uint32_t)0x00800200)
115 #define ADC_ANALOGWATCHDOG_SINGLEINJECENABLE       ((uint32_t)0x00400200)
116 #define ADC_ANALOGWATCHDOG_SINGLEREGORINJECENABLE  ((uint32_t)0x00C00200)
117 #define ADC_ANALOGWATCHDOG_ALLREGENABLE            ((uint32_t)0x00800000)
118 #define ADC_ANALOGWATCHDOG_ALLINJECENABLE          ((uint32_t)0x00400000)
119 #define ADC_ANALOGWATCHDOG_ALLREGALLINJECENABLE    ((uint32_t)0x00C00000)
120 #define ADC_ANALOGWATCHDOG_NONE                    ((uint32_t)0x00000000)
121
122 /* ADC interrupts definition */
123 #define ADC_IT_EOC                                 ((uint16_t)0x0220)
124 #define ADC_IT_AWD                                 ((uint16_t)0x0140)
125 #define ADC_IT_JEOC                                ((uint16_t)0x0480)
126
127 /* ADC flags definition */
128 #define ADC_FLAG_AWD                               ((uint8_t)0x01)
129 #define ADC_FLAG_EOC                               ((uint8_t)0x02)
130 #define ADC_FLAG_JEOC                              ((uint8_t)0x04)
131 #define ADC_FLAG_JSTRT                             ((uint8_t)0x08)
132 #define ADC_FLAG_STRT                              ((uint8_t)0X10)
133
134 #endif /* STM32_ADC_H */