summaryrefslogtreecommitdiff
path: root/Libraries/TouchSense/STMTouch_Driver/inc/tsl_acq_stm8l_hw.h
blob: b77d867ba1af460a2cdf87e08b9b936c2818276a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/**
  ******************************************************************************
  * @file    tsl_acq_stm8l_hw.h
  * @author  MCD Application Team
  * @version V1.4.4
  * @date    31-March-2014
  * @brief   This file contains external declarations of the tsl_acq_stm8l_hw.c file.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
  *
  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  * You may not use this file except in compliance with the License.
  * You may obtain a copy of the License at:
  *
  *        http://www.st.com/software_license_agreement_liberty_v2
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __TSL_ACQ_STM8L_HW_H
#define __TSL_ACQ_STM8L_HW_H

/* Includes ------------------------------------------------------------------*/
#include "stm8l15x.h"
#include "tsl_conf_stm8l.h"
#include "tsl_types.h"

/* Defines -------------------------------------------------------------------*/

#ifndef CONST
#define CONST const
#endif

enum
{
  GR1 = 0,
  GR2,
  GR3,
  GR4,
  GR5,
  GR6,
  GR7,
  GR8
};

enum
{
  TSL_BANK_GPIOA = 0,
  TSL_BANK_GPIOB,
  TSL_BANK_GPIOC,
  TSL_BANK_GPIOD,
  TSL_BANK_GPIOE
};

/** GPIOs list:
  - bits 7:3 GPIO number (0=GPIOA, 1=GPIOB, 2=GPIOC, 3=GPIOD, 4=GPIOE)
  - bits 2:0 IO number (0=pin0, ..., 7=pin7)
  */

// GROUP1
#define  PA4 (0x00|0x04) // CH1
#define  PA5 (0x00|0x05) // CH2
#define  PA6 (0x00|0x06) // CH3
#define  PA7 (0x00|0x07) // CH4
// GROUP2
#define  PC7 (0x10|0x07) // CH1
#define  PC4 (0x10|0x04) // CH2
#define  PC3 (0x10|0x03) // CH3
#define  PE7 (0x20|0x07) // CH4
// GROUP3
#define  PC2 (0x10|0x02) // CH1
#define  PD7 (0x18|0x07) // CH2
#define  PD6 (0x18|0x06) // CH3
// GROUP4
#define  PD5 (0x18|0x05) // CH1
#define  PD4 (0x18|0x04) // CH2
#define  PB7 (0x08|0x07) // CH3
// GROUP5
#define  PB6 (0x08|0x06) // CH1
#define  PB5 (0x08|0x05) // CH2
#define  PB4 (0x08|0x04) // CH3
// GROUP6
#define  PB3 (0x08|0x03) // CH1
#define  PB2 (0x08|0x02) // CH2
#define  PB1 (0x08|0x01) // CH3
// GROUP7
#define  PB0 (0x08|0x00) // CH1
#define  PD3 (0x18|0x03) // CH2
#define  PD2 (0x18|0x02) // CH3
#define  PE3 (0x20|0x03) // CH4
// GROUP8
#define  PD1 (0x18|0x01) // CH1
#define  PD0 (0x18|0x00) // CH2
#define  PE5 (0x20|0x05) // CH3
#define  PE4 (0x20|0x04) // CH4

// Acquisition pulses period
/** Master timer reload value for HW acquisition only (range=4..65534, even number)
    --> Period for Charge/Transfer cycle = ((TSLPRM_TIM_RELOAD*2)/FTimer)
*/
#define TIM_RELOAD ((TSLPRM_CT_PERIOD * TSLPRM_TIMER_FREQ) / 2)
#define TIM2_PWM_CH1_WIDTH  ((TIM_RELOAD / 2) - 1) // Configure channel 1 Pulse Width
#define TIM2_PWM_CH2_WIDTH  ((TIM_RELOAD / 2) + 1) // Configure channel 2 Pulse Width

/* Exported types ------------------------------------------------------------*/

// For all devices/acquisitions

typedef uint16_t  TSL_tMeas_T; /**< Measurement */
typedef uint16_t  TSL_tRef_T; /**< Reference */
typedef int16_t   TSL_tDelta_T; /**< Delta */

typedef uint8_t   TSL_tIndexSrc_T; /**< Channel source index */
typedef uint8_t   TSL_tIndexDest_T; /**< Channel destination index */

typedef uint8_t   TSL_tRefRest_T; /**< Reference Rest (ECS) */
typedef uint16_t  TSL_tKCoeff_T; /**< K coefficient (ECS) */

typedef uint16_t  TSL_tIndex_T; /**< Generic index */
typedef uint16_t  TSL_tNb_T; /**< Generic number */
typedef uint8_t   TSL_tCounter_T; /**< Generic counter used for debounce */

typedef uint8_t   TSL_tThreshold_T; /**< Delta threshold */

typedef int16_t   TSL_tsignPosition_T; /**< Linear and Rotary sensors position */
typedef uint8_t   TSL_tPosition_T; /**< Linear and Rotary sensors position */

typedef uint16_t  TSL_tTick_ms_T; /**< Time in ms */
typedef uint8_t   TSL_tTick_sec_T; /**< Time in sec */

//------------------------------------------------------------------------------
// Channel
//------------------------------------------------------------------------------

typedef uint8_t TSL_Conf_T;

/** Channel destination index
  */
typedef struct
{
  TSL_tIndexDest_T  IdxDest; /**< Index in the Channel data array */
} TSL_ChannelDest_T;

/** Channel Source and Configuration
  */
typedef struct
{
  TSL_tIndex_T IdxSrc; /**< Index of source value */
  // For stm8l acquisition only
  TSL_Conf_T   sampling; /**< Indicates which GPIO.n is used for the sample */
  TSL_Conf_T   channel;   /**< Indicates which GPIO.n is used for the channel */
} TSL_ChannelSrc_T;

/** Channel flags
  */
typedef struct
{
unsigned int DataReady : 1; /**< To identify a new measurement (TSL_DataReady_enum_T) */
unsigned int AcqStatus : 2; /**< Acquisition status (TSL_AcqStatus_enum_T) */
unsigned int ObjStatus : 2; /**< Object status (TSL_ObjStatus_enum_T) */
} TSL_ChannelFlags_T;

/** Channel Data
  */
typedef struct
{
  TSL_ChannelFlags_T   Flags;   /**< Flags */
  TSL_tRef_T           Ref;     /**< Reference */
  TSL_tRefRest_T       RefRest; /**< Reference rest for ECS */
  TSL_tDelta_T         Delta;   /**< Delta */
#if TSLPRM_USE_MEAS > 0
  TSL_tMeas_T          Meas;    /**< Hold the last acquisition measure */
#endif
} TSL_ChannelData_T;

//------------------------------------------------------------------------------
// Bank
//------------------------------------------------------------------------------

/** Bank
  */
typedef struct
{
  // Common to all acquisitions
  CONST TSL_ChannelSrc_T  *p_chSrc;     /**< Pointer to the Channel Source and Configuration */
  CONST TSL_ChannelDest_T *p_chDest;    /**< Pointer to the Channel Destination */
  TSL_ChannelData_T       *p_chData;    /**< Pointer to the Channel Data */
  TSL_tNb_T               NbChannels;   /**< Number of channels in the bank */
  // For stm8l acquisition only
  TSL_Conf_T              shield_sampling; /**< Indicates which GPIO.n is used for the shield sample */
  TSL_Conf_T              shield_channel;   /**< Indicates which GPIO.n is used for the shield channel */
} TSL_Bank_T;

/** Bank Config Mask
 */
typedef struct
{
  uint8_t  ch1;  /**< Contains the mask for all first channel of group */
  uint8_t  ch2;  /**< Contains the mask for all second channel of group */
  uint8_t  ch3;  /**< Contains the mask for all third channel of group */
  uint8_t  ch4;  /**< Contains the mask for all fourth channel of group (if LD device)*/
} TSL_Bank_Config_Mask_T;

/* Exported variables --------------------------------------------------------*/

/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
TSL_Status_enum_T TSL_acq_Init(void);
TSL_Status_enum_T TSL_acq_BankConfig(TSL_tIndex_T idx_bk);
void TSL_acq_BankStartAcq(void);
TSL_Status_enum_T TSL_acq_BankWaitEOC(void);
void TSL_CT_HWacq_TIM3(void);
void TSL_CT_HWacq_RI(void);
TSL_tMeas_T TSL_acq_GetMeas(TSL_tIndex_T index);
TSL_AcqStatus_enum_T TSL_acq_CheckNoise(void);

TSL_Bool_enum_T TSL_acq_UseFilter(TSL_ChannelData_T *pCh);
TSL_tDelta_T TSL_acq_ComputeDelta(TSL_tRef_T ref, TSL_tMeas_T meas);
TSL_tMeas_T TSL_acq_ComputeMeas(TSL_tRef_T ref, TSL_tDelta_T delta);
TSL_Bool_enum_T TSL_acq_TestReferenceOutOfRange(TSL_ChannelData_T *pCh);
TSL_Bool_enum_T TSL_acq_TestFirstReferenceIsValid(TSL_ChannelData_T *pCh, TSL_tMeas_T new_meas);

#endif /* __TSL_ACQ_STM8L_HW_H */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/