|
| 1 | +/** |
| 2 | + ******************************************************************************* |
| 3 | + * @file txzp_adc.h |
| 4 | + * @brief This file provides all the functions prototypes for ADC driver. |
| 5 | + * @version V1.0.0 |
| 6 | + * |
| 7 | + * DO NOT USE THIS SOFTWARE WITHOUT THE SOFTWARE LICENSE AGREEMENT. |
| 8 | + * |
| 9 | + * Copyright(C) Toshiba Electronic Device Solutions Corporation 2021 |
| 10 | + * SPDX-License-Identifier: Apache-2.0 |
| 11 | + * |
| 12 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 13 | + * you may not use this file except in compliance with the License. |
| 14 | + * You may obtain a copy of the License at |
| 15 | + * |
| 16 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 17 | + * |
| 18 | + * Unless required by applicable law or agreed to in writing, software |
| 19 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 20 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 21 | + * See the License for the specific language governing permissions and |
| 22 | + * limitations under the License. |
| 23 | + ******************************************************************************* |
| 24 | + */ |
| 25 | +/*------------------------------------------------------------------------------*/ |
| 26 | +/* Define to prevent recursive inclusion */ |
| 27 | +/*------------------------------------------------------------------------------*/ |
| 28 | +#ifndef __ADC_H |
| 29 | +#define __ADC_H |
| 30 | + |
| 31 | +#ifdef __cplusplus |
| 32 | +extern "C" { |
| 33 | +#endif |
| 34 | + |
| 35 | +/*------------------------------------------------------------------------------*/ |
| 36 | +/* Includes */ |
| 37 | +/*------------------------------------------------------------------------------*/ |
| 38 | +#include "txzp_driver_def.h" |
| 39 | +#include "txzp_adc_ch.h" |
| 40 | + |
| 41 | +/** |
| 42 | + * @addtogroup Periph_Driver Peripheral Driver |
| 43 | + * @{ |
| 44 | + */ |
| 45 | + |
| 46 | +/** |
| 47 | + * @defgroup ADC ADC |
| 48 | + * @brief ADC Driver. |
| 49 | + * @{ |
| 50 | + */ |
| 51 | +/*------------------------------------------------------------------------------*/ |
| 52 | +/* Macro Definition */ |
| 53 | +/*------------------------------------------------------------------------------*/ |
| 54 | +/** |
| 55 | + * @defgroup ADC_Exported_define ADC Exported Define |
| 56 | + * @{ |
| 57 | + */ |
| 58 | + |
| 59 | +/** |
| 60 | + * @defgroup ADC_ChannelMax Channel Num Max |
| 61 | + * @brief Max Num of channel. |
| 62 | + * @{ |
| 63 | + */ |
| 64 | +#define ADC_NUM_MAX ((uint32_t)24) /*!< Max Num of conversion. */ |
| 65 | +/** |
| 66 | + * @} |
| 67 | + */ /* End of group ADC_ChannelMax */ |
| 68 | + |
| 69 | +/** |
| 70 | + * @defgroup ADC_CONVERT_TIME AD Convert Time & AVDD. |
| 71 | + * @brief Select AD Convert Time & AVDD. |
| 72 | + * @{ |
| 73 | + */ |
| 74 | +#define ADC_CONVERT_TIME_0_96_AVDD_4_5 ((uint32_t)0x00000000) /*!< ADC CONVERT TIME 0.96u AVDD 4.5V */ |
| 75 | +#define ADC_CONVERT_TIME_0_91_AVDD_4_5 ((uint32_t)0x00000001) /*!< ADC CONVERT TIME 0.91u AVDD 4.5V */ |
| 76 | +#define ADC_CONVERT_TIME_1_09_AVDD_4_5 ((uint32_t)0x00000002) /*!< ADC CONVERT TIME 1.09u AVDD 4.5V */ |
| 77 | +/** |
| 78 | + * @} |
| 79 | + */ /* End of group ADC_CONVERT_TIME */ |
| 80 | + |
| 81 | +/** |
| 82 | + * @defgroup ADC_RCUT AD RCUT. |
| 83 | + * @brief Select AD RCUT. |
| 84 | + * @{ |
| 85 | + */ |
| 86 | +#define ADC_RCUT_NORMAL ((uint32_t)0x00000000) /*!< ADC RCUT NORMAL */ |
| 87 | +#define ADC_RCUT_LOW ((uint32_t)0x00000002) /*!< ADC RCUT LOW */ |
| 88 | +/** |
| 89 | + * @} |
| 90 | + */ /* End of group ADC_RCUT */ |
| 91 | + |
| 92 | +/** |
| 93 | + * @defgroup ADC_IntEnable Interrupt Enable. |
| 94 | + * @brief Interrupt Enable. |
| 95 | + * @{ |
| 96 | + */ |
| 97 | +#define ADC_INT_DISABLE ((uint32_t)0x00000000) /*!< Disable. */ |
| 98 | +#define ADC_INT_ENABLE ((uint32_t)0x00000080) /*!< Enable. */ |
| 99 | +/** |
| 100 | + * @} |
| 101 | + */ /* End of group ADC_IntEnable */ |
| 102 | + |
| 103 | +/** |
| 104 | + * @defgroup ADC_Conversion Conversion Method. |
| 105 | + * @brief Select conversion method. |
| 106 | + * @{ |
| 107 | + */ |
| 108 | +#define ADC_CONVERSION_DISABLE ((uint32_t)0x00000000) /*!< Disable. */ |
| 109 | +#define ADC_CONVERSION_CNT ((uint32_t)0x00000020) /*!< Continuation. */ |
| 110 | +#define ADC_CONVERSION_SGL ((uint32_t)0x00000040) /*!< Single. */ |
| 111 | +#define ADC_CONVERSION_TRG ((uint32_t)0x00000060) /*!< Universal Trigger. */ |
| 112 | +/** |
| 113 | + * @} |
| 114 | + */ /* End of group ADC_Conversion */ |
| 115 | + |
| 116 | +/** |
| 117 | + * @defgroup ADC_AINRange AIN Range. |
| 118 | + * @brief Range of AIN Macro Definisiton. |
| 119 | + * @brief Range of AIN be set "(ADC_AIN_RANGE_MIN <= Value <= ADC_AIN_RANGE_MAX)". |
| 120 | + * @{ |
| 121 | + */ |
| 122 | +#define ADC_AIN_RANGE_MIN ((uint32_t)0x00000000) /*!< Minimum Value :AINx00 */ |
| 123 | +#define ADC_AIN_RANGE_MAX ((uint32_t)0x00000017) /*!< Maximum Value :AINx23 */ |
| 124 | +/** |
| 125 | + * @} |
| 126 | + */ /* End of group ADC_AINRange */ |
| 127 | + |
| 128 | +/** |
| 129 | + * @defgroup ADC_Status AD Running Status. |
| 130 | + * @brief AD Running Status. |
| 131 | + * @{ |
| 132 | + */ |
| 133 | +#define ADC_STATUS_MASK ((uint32_t)0x00000080) /*!< for Mask. */ |
| 134 | +#define ADC_STATUS_SLEEP ((uint32_t)0x00000000) /*!< Sleep. */ |
| 135 | +#define ADC_STATUS_RUNNING ((uint32_t)0x00000080) /*!< Running. */ |
| 136 | +/** |
| 137 | + * @} |
| 138 | + */ /* End of group ADC_Status */ |
| 139 | + |
| 140 | +/** |
| 141 | + * @defgroup ADC_ContinuityStatus Continuity Conversion Running Status. |
| 142 | + * @brief Continuity Conversion Running Status. |
| 143 | + * @{ |
| 144 | + */ |
| 145 | +#define ADC_CNT_STATUS_MASK ((uint32_t)0x00000008) /*!< for Mask. */ |
| 146 | +#define ADC_CNT_STATUS_SLEEP ((uint32_t)0x00000000) /*!< Sleep. */ |
| 147 | +#define ADC_CNT_STATUS_RUNNING ((uint32_t)0x00000008) /*!< Running. */ |
| 148 | +/** |
| 149 | + * @} |
| 150 | + */ /* End of group ADC_ContinuityStatus */ |
| 151 | + |
| 152 | +/** |
| 153 | + * @defgroup ADC_SingleStatus Single Conversion Running Status. |
| 154 | + * @brief Single Conversion Running Status. |
| 155 | + * @{ |
| 156 | + */ |
| 157 | +#define ADC_SGL_STATUS_MASK ((uint32_t)0x00000004) /*!< for Mask. */ |
| 158 | +#define ADC_SGL_STATUS_SLEEP ((uint32_t)0x00000000) /*!< Sleep. */ |
| 159 | +#define ADC_SGL_STATUS_RUNNING ((uint32_t)0x00000004) /*!< Running. */ |
| 160 | +/** |
| 161 | + * @} |
| 162 | + */ /* End of group ADC_SingleStatus */ |
| 163 | + |
| 164 | +/** |
| 165 | + * @defgroup ADC_TriggerStatus Trigger Conversion Running Status. |
| 166 | + * @brief Trigger Conversion Running Status. |
| 167 | + * @{ |
| 168 | + */ |
| 169 | +#define ADC_TRG_STATUS_MASK ((uint32_t)0x00000002) /*!< for Mask. */ |
| 170 | +#define ADC_TRG_STATUS_SLEEP ((uint32_t)0x00000000) /*!< Sleep. */ |
| 171 | +#define ADC_TRG_STATUS_RUNNING ((uint32_t)0x00000002) /*!< Running. */ |
| 172 | +/** |
| 173 | + * @} |
| 174 | + */ /* End of group ADC_TriggerStatus */ |
| 175 | + |
| 176 | +/** |
| 177 | + * @defgroup ADC_SH_TriggerPattern TriggerPattern |
| 178 | + * @brief SH TriggerPattern. |
| 179 | + * @{ |
| 180 | + */ |
| 181 | +#define ADC_SH_TRGPAT_UPPER_0 ((uint32_t)0x00000000) /*!< Triger Combination Upper pattern 0 */ |
| 182 | +#define ADC_SH_TRGPAT_UPPER_1 ((uint32_t)0x00000004) /*!< Triger Combination Upper pattern 1 */ |
| 183 | +#define ADC_SH_TRGPAT_UPPER_2 ((uint32_t)0x00000008) /*!< Triger Combination Upper pattern 2 */ |
| 184 | +#define ADC_SH_TRGPAT_UPPER_3 ((uint32_t)0x0000000C) /*!< Triger Combination Upper pattern 3 */ |
| 185 | +#define ADC_SH_TRGPAT_LOWER_0 ((uint32_t)0x00000000) /*!< Triger Combination Lower pattern 0 */ |
| 186 | +#define ADC_SH_TRGPAT_LOWER_1 ((uint32_t)0x00000001) /*!< Triger Combination Lower pattern 1 */ |
| 187 | +#define ADC_SH_TRGPAT_LOWER_2 ((uint32_t)0x00000002) /*!< Triger Combination Lower pattern 2 */ |
| 188 | +#define ADC_SH_TRGPAT_LOWER_3 ((uint32_t)0x00000003) /*!< Triger Combination Lower pattern 3 */ |
| 189 | +/** |
| 190 | + * @} |
| 191 | + */ /* End of group ADC_SH_TriggerPattern */ |
| 192 | + |
| 193 | +/** |
| 194 | + * @} |
| 195 | + */ /* End of group ADC_Exported_define */ |
| 196 | + |
| 197 | +/*------------------------------------------------------------------------------*/ |
| 198 | +/* Enumerated Type Definition */ |
| 199 | +/*------------------------------------------------------------------------------*/ |
| 200 | +/** |
| 201 | + * @defgroup ADC_Exported_define ADC Exported Define |
| 202 | + * @{ |
| 203 | + */ |
| 204 | + |
| 205 | +/* no define */ |
| 206 | + |
| 207 | +/** |
| 208 | + * @} |
| 209 | + */ /* End of group ADC_Exported_define */ |
| 210 | + |
| 211 | +/*------------------------------------------------------------------------------*/ |
| 212 | +/* Structure Definition */ |
| 213 | +/*------------------------------------------------------------------------------*/ |
| 214 | +/** |
| 215 | + * @defgroup ADC_Exported_typedef ADC Exported Typedef |
| 216 | + * @{ |
| 217 | + */ |
| 218 | +/*----------------------------------*/ |
| 219 | +/** |
| 220 | + * @brief Initial setting structure definenition. |
| 221 | +*/ |
| 222 | +/*----------------------------------*/ |
| 223 | +typedef struct { |
| 224 | + uint32_t id; /*!< ID: User value. */ |
| 225 | + uint32_t convert_time; /*!< AD Convert time & AVDD. |
| 226 | + : Use @ref ADC_CONVERT_TIME. */ |
| 227 | + uint32_t refbsel; /*!< VREFHz/AINxn. |
| 228 | + : Use @ref ADC_REFBSEL. */ |
| 229 | + uint32_t rcut; /*!< RCUT. |
| 230 | + : Use @ref ADC_RCUT. */ |
| 231 | + |
| 232 | +} adc_initial_setting_t; |
| 233 | + |
| 234 | +/*----------------------------------*/ |
| 235 | +/** |
| 236 | + * @brief Channel Setting. \n |
| 237 | +*/ |
| 238 | +/*----------------------------------*/ |
| 239 | +typedef struct { |
| 240 | + uint32_t ain; /*!< AIN. |
| 241 | + : Range is @ref ADC_AINRange. */ |
| 242 | +} adc_channel_setting_t; |
| 243 | + |
| 244 | +/*----------------------------------*/ |
| 245 | +/** |
| 246 | + * @brief Driver internal information structure definenition. |
| 247 | +*/ |
| 248 | +/*----------------------------------*/ |
| 249 | +typedef struct { |
| 250 | + adc_ch_t ch[ADC_NUM_MAX]; /*!< Channel Instance. */ |
| 251 | +} adc_internal_info_t; |
| 252 | + |
| 253 | +/*----------------------------------*/ |
| 254 | +/** |
| 255 | + * @brief ADC handle structure definenition. |
| 256 | +*/ |
| 257 | +/*----------------------------------*/ |
| 258 | +typedef struct { |
| 259 | + TSB_AD_TypeDef *p_instance; /*!< Registers base address. */ |
| 260 | + adc_initial_setting_t init; /*!< Initial setting. */ |
| 261 | + void (*handler)(uint32_t id, TXZ_Result result); /*!< Notity Conversion Done. */ |
| 262 | + adc_internal_info_t info; /*!< Driver internal information. */ |
| 263 | +} adc_t; |
| 264 | + |
| 265 | +/** |
| 266 | + * @} |
| 267 | + */ /* End of group ADC_Exported_typedef */ |
| 268 | + |
| 269 | +/*------------------------------------------------------------------------------*/ |
| 270 | +/* Functions */ |
| 271 | +/*------------------------------------------------------------------------------*/ |
| 272 | +/** |
| 273 | + * @defgroup ADC_Exported_functions ADC Exported Functions |
| 274 | + * @{ |
| 275 | + */ |
| 276 | +TXZ_Result adc_init(adc_t *p_obj); |
| 277 | +TXZ_Result adc_deinit(adc_t *p_obj); |
| 278 | +TXZ_Result adc_channel_setting(adc_t *p_obj, uint32_t ch, adc_channel_setting_t *p_setting); |
| 279 | +TXZ_Result adc_channel_clear(adc_t *p_obj, uint32_t ch); |
| 280 | +TXZ_Result adc_channel_get_value(adc_t *p_obj, uint32_t ch, uint32_t *p_value); |
| 281 | +TXZ_Result adc_start(adc_t *p_obj); |
| 282 | +TXZ_Result adc_stop(adc_t *p_obj); |
| 283 | +TXZ_Result adc_startIt(adc_t *p_obj); |
| 284 | +TXZ_Result adc_stopIt(adc_t *p_obj); |
| 285 | +void adc_irq_handler(adc_t *p_obj); |
| 286 | +/** |
| 287 | + * @} |
| 288 | + */ /* End of group ADC_Exported_functions */ |
| 289 | + |
| 290 | +/** |
| 291 | + * @} |
| 292 | + */ /* End of group ADC */ |
| 293 | + |
| 294 | +/** |
| 295 | + * @} |
| 296 | + */ /* End of group Periph_Driver */ |
| 297 | + |
| 298 | +#ifdef __cplusplus |
| 299 | +} |
| 300 | +#endif /* __cplusplus */ |
| 301 | +#endif /* __ADC_H */ |
| 302 | + |
| 303 | + |
0 commit comments