]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_STM32L152_Discovery_IAR/ST_Code/Libraries/STMTouch_Driver/inc/tsl_acq_stm32l1xx_hw.h
Add STM32L Discovery board project as a starting point to adapt to an RTOS demo.
[freertos] / FreeRTOS / Demo / CORTEX_STM32L152_Discovery_IAR / ST_Code / Libraries / STMTouch_Driver / inc / tsl_acq_stm32l1xx_hw.h
1 /**\r
2   ******************************************************************************\r
3   * @file    tsl_acq_stm32l1xx_hw.h\r
4   * @author  MCD Application Team\r
5   * @version V1.3.2\r
6   * @date    22-January-2013\r
7   * @brief   This file contains external declarations of the tsl_acq_stm32l1xx_hw.c file.\r
8   ******************************************************************************\r
9   * @attention\r
10   *\r
11   * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>\r
12   *\r
13   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");\r
14   * You may not use this file except in compliance with the License.\r
15   * You may obtain a copy of the License at:\r
16   *\r
17   *        http://www.st.com/software_license_agreement_liberty_v2\r
18   *\r
19   * Unless required by applicable law or agreed to in writing, software\r
20   * distributed under the License is distributed on an "AS IS" BASIS,\r
21   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
22   * See the License for the specific language governing permissions and\r
23   * limitations under the License.\r
24   *\r
25   ******************************************************************************\r
26   */\r
27 \r
28 /* Define to prevent recursive inclusion -------------------------------------*/\r
29 #ifndef __TSL_ACQ_STM32L1XX_HW_H\r
30 #define __TSL_ACQ_STM32L1XX_HW_H\r
31 \r
32 /* Includes ------------------------------------------------------------------*/\r
33 #include "stm32l1xx.h"\r
34 #include "tsl_conf_stm32l1xx.h"\r
35 #include "tsl_types.h"\r
36 \r
37 /* Defines -------------------------------------------------------------------*/\r
38 \r
39 #ifndef CONST\r
40 #define CONST const\r
41 #endif\r
42 \r
43 // SysTick enable/disable interrupt macros\r
44 #define enableInterrupts()  {SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk;}\r
45 #define disableInterrupts() {SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;}\r
46 \r
47 /** Groups list\r
48   */\r
49 enum\r
50 {\r
51   GR1,\r
52   GR2,\r
53   GR3,\r
54   GR4,\r
55   GR5,\r
56   GR6,\r
57   GR7,\r
58   GR8,\r
59   GR9,\r
60   GR10,\r
61   GR11\r
62 };\r
63 \r
64 /** GPIOs list\r
65     High significant nibble for the IO port (GPIOA:0,...,GPIOG:6)\r
66     Low significant nibble for the IO number (pin0:0,...,pin15:F)\r
67   */\r
68 enum\r
69 {\r
70   PA0  = 0x00, /**< TSL_GROUP1_IO1 */\r
71   PA1  = 0x01,\r
72   PA2  = 0x02,\r
73   PA3  = 0x03,\r
74   PA6  = 0x06, /**< TSL_GROUP2_IO1 */\r
75   PA7  = 0x07,\r
76   PA8  = 0x08,\r
77   PA9  = 0x09,\r
78   PA10 = 0x0A,\r
79   PA13 = 0x0D, /**< TSL_GROUP5_IO1 */\r
80   PA14 = 0x0E,\r
81   PA15 = 0x0F,\r
82   PB0  = 0x10, /**< TSL_GROUP3_IO1 */\r
83   PB1  = 0x11,\r
84   PB2  = 0x12,\r
85   PB4  = 0x14, /**< TSL_GROUP6_IO1 */\r
86   PB5  = 0x15,\r
87   PB6  = 0x16,\r
88   PB7  = 0x17,\r
89   PB12 = 0x1C, /**< TSL_GROUP7_IO1 */\r
90   PB13 = 0x1D,\r
91   PB14 = 0x1E,\r
92   PB15 = 0x1F,\r
93   PC0  = 0x20, /**< TSL_GROUP8_IO1 */\r
94   PC1  = 0x21,\r
95   PC2  = 0x22,\r
96   PC3  = 0x23,\r
97   PC4  = 0x24,\r
98   PC5  = 0x25,\r
99   PC6  = 0x26,\r
100   PC7  = 0x27,\r
101   PC8  = 0x28,\r
102   PC9  = 0x29,\r
103   PF6  = 0x56, /**< TSL_GROUP11_IO1 */\r
104   PF7  = 0x57,\r
105   PF8  = 0x58,\r
106   PF9  = 0x59,\r
107   PF10 = 0x5A,\r
108   PF11 = 0x5B,\r
109   PF12 = 0x5C,\r
110   PF13 = 0x5D,\r
111   PF14 = 0x5E,\r
112   PF15 = 0x5F,\r
113   PG0  = 0x60, /**< TSL_GROUP2_IO4 */\r
114   PG1  = 0x61,\r
115   PG2  = 0x62,\r
116   PG3  = 0x63,\r
117   PG4  = 0x64\r
118 };\r
119 \r
120 /** GPIOs list:\r
121     High significant nibble for the IO port (GPIOA:0,...,GPIOG:6)\r
122     Low significant nibble for the IO number (pin0:0,...,pin15:F)\r
123   */\r
124 enum\r
125 {\r
126   TSL_GROUP1_IO1  = 0x00, /**< PA0 */\r
127   TSL_GROUP1_IO2  = 0x01,\r
128   TSL_GROUP1_IO3  = 0x02,\r
129   TSL_GROUP1_IO4  = 0x03,\r
130   TSL_GROUP2_IO1  = 0x06, /**< PA6 */\r
131   TSL_GROUP2_IO2  = 0x07,\r
132   TSL_GROUP4_IO1  = 0x08,\r
133   TSL_GROUP4_IO2  = 0x09,\r
134   TSL_GROUP4_IO3  = 0x0A,\r
135   TSL_GROUP5_IO1  = 0x0D, /**< PA13 */\r
136   TSL_GROUP5_IO2  = 0x0E,\r
137   TSL_GROUP5_IO3  = 0x0F,\r
138   TSL_GROUP3_IO1  = 0x10, /**< PB0 */\r
139   TSL_GROUP3_IO2  = 0x11,\r
140   TSL_GROUP3_IO3  = 0x12,\r
141   TSL_GROUP6_IO1  = 0x14, /**< PB4 */\r
142   TSL_GROUP6_IO2  = 0x15,\r
143   TSL_GROUP6_IO3  = 0x16,\r
144   TSL_GROUP6_IO4  = 0x17,\r
145   TSL_GROUP7_IO1  = 0x1C, /**< PB12 */\r
146   TSL_GROUP7_IO2  = 0x1D,\r
147   TSL_GROUP7_IO3  = 0x1E,\r
148   TSL_GROUP7_IO4  = 0x1F,\r
149   TSL_GROUP8_IO1  = 0x20, /**< PC0 */\r
150   TSL_GROUP8_IO2  = 0x21,\r
151   TSL_GROUP8_IO3  = 0x22,\r
152   TSL_GROUP8_IO4  = 0x23,\r
153   TSL_GROUP9_IO1  = 0x24,\r
154   TSL_GROUP9_IO2  = 0x25,\r
155   TSL_GROUP10_IO1 = 0x26,\r
156   TSL_GROUP10_IO2 = 0x27,\r
157   TSL_GROUP10_IO3 = 0x28,\r
158   TSL_GROUP10_IO4 = 0x29,\r
159   TSL_GROUP11_IO1 = 0x56, /**< PF6 */\r
160   TSL_GROUP11_IO2 = 0x57,\r
161   TSL_GROUP11_IO3 = 0x58,\r
162   TSL_GROUP11_IO4 = 0x59,\r
163   TSL_GROUP11_IO5 = 0x5A,\r
164   TSL_GROUP3_IO4  = 0x5B,\r
165   TSL_GROUP3_IO5  = 0x5C,\r
166   TSL_GROUP9_IO3  = 0x5D,\r
167   TSL_GROUP9_IO4  = 0x5E,\r
168   TSL_GROUP2_IO3  = 0x5F,\r
169   TSL_GROUP2_IO4  = 0x60, /**< PG0 */\r
170   TSL_GROUP2_IO5  = 0x61,\r
171   TSL_GROUP7_IO5  = 0x62,\r
172   TSL_GROUP7_IO6  = 0x63,\r
173   TSL_GROUP7_IO7  = 0x64\r
174 };\r
175 \r
176 /* Exported types ------------------------------------------------------------*/\r
177 \r
178 typedef struct\r
179 {\r
180   // RI\r
181   __IO uint32_t ICR;\r
182   __IO uint32_t ASCR1;\r
183   __IO uint32_t ASCR2;\r
184   __IO uint32_t HYSCR1;\r
185   __IO uint32_t HYSCR2;\r
186   __IO uint32_t HYSCR3;\r
187   __IO uint32_t HYSCR4;\r
188   // CP\r
189   __IO uint32_t ASMR1;\r
190   __IO uint32_t CMR1;\r
191   __IO uint32_t CICR1;\r
192   __IO uint32_t ASMR2;\r
193   __IO uint32_t CMR2;\r
194   __IO uint32_t CICR2;\r
195   __IO uint32_t ASMR3;\r
196   __IO uint32_t CMR3;\r
197   __IO uint32_t CICR3;\r
198   __IO uint32_t ASMR4;\r
199   __IO uint32_t CMR4;\r
200   __IO uint32_t CICR4;\r
201   __IO uint32_t ASMR5;\r
202   __IO uint32_t CMR5;\r
203   __IO uint32_t CICR5;\r
204 } CPRI_TypeDef;\r
205 \r
206 // For all devices/acquisitions\r
207 \r
208 typedef uint16_t  TSL_tMeas_T; /**< Measurement */\r
209 typedef uint16_t  TSL_tRef_T; /**< Reference */\r
210 typedef int16_t   TSL_tDelta_T; /**< Delta */\r
211 \r
212 typedef uint8_t   TSL_tIndexSrc_T; /**< Channel source index */\r
213 typedef uint16_t  TSL_tIndexDest_T; /**< Channel destination index */\r
214 \r
215 typedef uint8_t   TSL_tRefRest_T; /**< Reference Rest (ECS) */\r
216 typedef uint16_t  TSL_tKCoeff_T; /**< K coefficient (ECS) */\r
217 \r
218 typedef uint8_t   TSL_tIndex_T; /**< Generic index */\r
219 typedef uint16_t  TSL_tNb_T; /**< Generic number */\r
220 typedef uint8_t   TSL_tCounter_T; /**< Generic counter used for debounce */\r
221 \r
222 typedef uint8_t   TSL_tThreshold_T; /**< Delta threshold */\r
223 \r
224 typedef int16_t   TSL_tsignPosition_T; /**< Linear and Rotary sensors position */\r
225 typedef uint8_t   TSL_tPosition_T; /**< Linear and Rotary sensors position */\r
226 \r
227 typedef uint16_t  TSL_tTick_ms_T; /**< Time in ms */\r
228 typedef uint8_t   TSL_tTick_sec_T; /**< Time in sec */\r
229 \r
230 //------------------------------------------------------------------------------\r
231 // Channel\r
232 //------------------------------------------------------------------------------\r
233 \r
234 typedef uint8_t TSL_Conf_t;\r
235 \r
236 /** Channel destination index\r
237   */\r
238 typedef struct\r
239 {\r
240   TSL_tIndex_T IdxDest; /**< Index in the Channel data array */\r
241 } TSL_ChannelDest_T;\r
242 \r
243 /** Channel Source and Configuration\r
244   */\r
245 typedef struct\r
246 {\r
247   TSL_tIndex_T IdxSrc; /**< Index of source value */\r
248   // For stm32l1x acquisition only\r
249   TSL_Conf_t   t_sample;  /**< Indicates which GPIO.n is used for the sample */\r
250   TSL_Conf_t   t_channel; /**< Indicates which GPIO.n is used for the channel */\r
251 } TSL_ChannelSrc_T;\r
252 \r
253 /** Channel flags\r
254   */\r
255 typedef struct\r
256 {\r
257   unsigned int DataReady : 1; /**< To identify a new measurement (TSL_DataReady_enum_T) */\r
258   unsigned int AcqStatus : 2; /**< Acquisition status (TSL_AcqStatus_enum_T) */\r
259   unsigned int ObjStatus : 2; /**< Object status (TSL_ObjStatus_enum_T) */\r
260 } TSL_ChannelFlags_T;\r
261 \r
262 /** Channel Data\r
263   */\r
264 typedef struct\r
265 {\r
266   TSL_ChannelFlags_T   Flags;   /**< Flags */\r
267   TSL_tRef_T           Ref;     /**< Reference */\r
268   TSL_tRefRest_T       RefRest; /**< Reference rest for ECS */\r
269   TSL_tDelta_T         Delta;   /**< Delta */\r
270 #if TSLPRM_USE_MEAS > 0\r
271   TSL_tMeas_T          Meas;    /**< Hold the last acquisition measure */\r
272 #endif\r
273 } TSL_ChannelData_T;\r
274 \r
275 //------------------------------------------------------------------------------\r
276 // Bank\r
277 //------------------------------------------------------------------------------\r
278 \r
279 /** Bank\r
280   */\r
281 typedef struct\r
282 {\r
283   // Common to all acquisitions\r
284   CONST TSL_ChannelSrc_T  *p_chSrc;     /**< Pointer to the Channel Source and Configuration */\r
285   CONST TSL_ChannelDest_T *p_chDest;    /**< Pointer to the Channel Destination */\r
286   TSL_ChannelData_T       *p_chData;    /**< Pointer to the Channel Data */\r
287   TSL_tNb_T               NbChannels;   /**< Number of channels in the bank */\r
288   // For stm32l1x acquisition only\r
289   TSL_Conf_t              shield_sample;  /**< Indicates which GPIO.n is used for the shield sample */\r
290   TSL_Conf_t              shield_channel; /**< Indicates which GPIO.n is used for the shield channel */\r
291 } TSL_Bank_T;\r
292 \r
293 /* Exported variables --------------------------------------------------------*/\r
294 \r
295 /* Exported macros -----------------------------------------------------------*/\r
296 \r
297 #define CPRI_BASE  (APB1PERIPH_BASE + 0x7C04)\r
298 #define CPRI       ((CPRI_TypeDef *) CPRI_BASE)\r
299 \r
300 /* Exported functions ------------------------------------------------------- */\r
301 \r
302 TSL_Status_enum_T TSL_acq_Init(void);\r
303 TSL_Status_enum_T TSL_acq_BankConfig(TSL_tIndex_T idx_bk);\r
304 void TSL_acq_BankStartAcq(void);\r
305 TSL_Status_enum_T TSL_acq_BankWaitEOC(void);\r
306 void TSL_acq_ProcessIT(void);\r
307 TSL_tMeas_T TSL_acq_GetMeas(TSL_tIndex_T index);\r
308 TSL_AcqStatus_enum_T TSL_acq_CheckNoise(void);\r
309 TSL_Bool_enum_T TSL_acq_UseFilter(TSL_ChannelData_T *pCh);\r
310 TSL_tDelta_T TSL_acq_ComputeDelta(TSL_tRef_T ref, TSL_tMeas_T meas);\r
311 TSL_tMeas_T TSL_acq_ComputeMeas(TSL_tRef_T ref, TSL_tDelta_T delta);\r
312 TSL_Bool_enum_T TSL_acq_TestReferenceOutOfRange(TSL_ChannelData_T *pCh);\r
313 TSL_Bool_enum_T TSL_acq_TestFirstReferenceIsValid(TSL_ChannelData_T *pCh, TSL_tMeas_T new_meas);\r
314 \r
315 #endif // __TSL_ACQ_STM32L1XX_HW_H\r
316 \r
317 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/\r