|
| 1 | +/** |
| 2 | + ******************************************************************************* |
| 3 | + * @file tmpm46b_adc.h |
| 4 | + * @brief This file provides all the functions prototypes for ADC driver. |
| 5 | + * @version V2.0.2.1 |
| 6 | + * @date 2015/02/11 |
| 7 | + * |
| 8 | + * DO NOT USE THIS SOFTWARE WITHOUT THE SOFTWARE LISENCE AGREEMENT. |
| 9 | + * |
| 10 | + * (C)Copyright TOSHIBA CORPORATION 2015 All rights reserved |
| 11 | + ******************************************************************************* |
| 12 | + */ |
| 13 | + |
| 14 | +/* Define to prevent recursive inclusion -------------------------------------*/ |
| 15 | +#ifndef __TMPM46B_ADC_H |
| 16 | +#define __TMPM46B_ADC_H |
| 17 | + |
| 18 | +#ifdef __cplusplus |
| 19 | +extern "C" { |
| 20 | +#endif |
| 21 | + |
| 22 | +/* Includes ------------------------------------------------------------------*/ |
| 23 | +#include "TMPM46B.h" |
| 24 | +#include "tx04_common.h" |
| 25 | + |
| 26 | +/** @addtogroup TX04_Periph_Driver |
| 27 | + * @{ |
| 28 | + */ |
| 29 | + |
| 30 | +/** @addtogroup ADC |
| 31 | + * @{ |
| 32 | + */ |
| 33 | + |
| 34 | +/** @defgroup ADC_Exported_Types |
| 35 | + * @{ |
| 36 | + */ |
| 37 | +#define IS_ADC_UNIT(param) (((param) == TSB_AD)) |
| 38 | + |
| 39 | +#define ADC_CONVERSION_CLK_10 ((uint32_t)0x00000000) |
| 40 | +#define ADC_CONVERSION_CLK_20 ((uint32_t)0x00000010) |
| 41 | +#define ADC_CONVERSION_CLK_30 ((uint32_t)0x00000020) |
| 42 | +#define ADC_CONVERSION_CLK_40 ((uint32_t)0x00000030) |
| 43 | +#define ADC_CONVERSION_CLK_80 ((uint32_t)0x00000040) |
| 44 | +#define ADC_CONVERSION_CLK_160 ((uint32_t)0x00000050) |
| 45 | +#define ADC_CONVERSION_CLK_320 ((uint32_t)0x00000060) |
| 46 | +#define IS_ADC_HOLD_TIME(param) (((param) == ADC_CONVERSION_CLK_10) || \ |
| 47 | + ((param) == ADC_CONVERSION_CLK_20) || \ |
| 48 | + ((param) == ADC_CONVERSION_CLK_30) || \ |
| 49 | + ((param) == ADC_CONVERSION_CLK_40) || \ |
| 50 | + ((param) == ADC_CONVERSION_CLK_80) || \ |
| 51 | + ((param) == ADC_CONVERSION_CLK_160)|| \ |
| 52 | + ((param) == ADC_CONVERSION_CLK_320)) |
| 53 | + |
| 54 | +#define ADC_FC_DIVIDE_LEVEL_1 ((uint32_t)0x00000000) |
| 55 | +#define ADC_FC_DIVIDE_LEVEL_2 ((uint32_t)0x00000001) |
| 56 | +#define ADC_FC_DIVIDE_LEVEL_4 ((uint32_t)0x00000002) |
| 57 | +#define ADC_FC_DIVIDE_LEVEL_8 ((uint32_t)0x00000003) |
| 58 | +#define ADC_FC_DIVIDE_LEVEL_16 ((uint32_t)0x00000004) |
| 59 | +#define IS_ADC_PRESCALER(param) ((param) <= ADC_FC_DIVIDE_LEVEL_16) |
| 60 | + |
| 61 | +/* Interrupt generation timing in fixed channel mode */ |
| 62 | +#define ADC_INT_SINGLE ((uint32_t)0x00000000) |
| 63 | +#define ADC_INT_CONVERSION_2 ((uint32_t)0x00000010) |
| 64 | +#define ADC_INT_CONVERSION_3 ((uint32_t)0x00000020) |
| 65 | +#define ADC_INT_CONVERSION_4 ((uint32_t)0x00000030) |
| 66 | +#define ADC_INT_CONVERSION_5 ((uint32_t)0x00000040) |
| 67 | +#define ADC_INT_CONVERSION_6 ((uint32_t)0x00000050) |
| 68 | +#define ADC_INT_CONVERSION_7 ((uint32_t)0x00000060) |
| 69 | +#define ADC_INT_CONVERSION_8 ((uint32_t)0x00000070) |
| 70 | +#define IS_ADC_INT_MODE(param) (((param) == ADC_INT_SINGLE) || \ |
| 71 | + ((param) == ADC_INT_CONVERSION_2) || \ |
| 72 | + ((param) == ADC_INT_CONVERSION_3) || \ |
| 73 | + ((param) == ADC_INT_CONVERSION_4) || \ |
| 74 | + ((param) == ADC_INT_CONVERSION_5) || \ |
| 75 | + ((param) == ADC_INT_CONVERSION_6) || \ |
| 76 | + ((param) == ADC_INT_CONVERSION_7) || \ |
| 77 | + ((param) == ADC_INT_CONVERSION_8)) |
| 78 | + |
| 79 | + typedef enum { |
| 80 | + ADC_AN_00 = 0U, /*!< define for Analog Input channel */ |
| 81 | + ADC_AN_01 = 1U, |
| 82 | + ADC_AN_02 = 2U, |
| 83 | + ADC_AN_03 = 3U, |
| 84 | + ADC_AN_04 = 4U, |
| 85 | + ADC_AN_05 = 5U, |
| 86 | + ADC_AN_06 = 6U, |
| 87 | + ADC_AN_07 = 7U, |
| 88 | + } ADC_AINx; |
| 89 | +#define IS_ADC_INPUT_CHANNEL(param) ((param) <= ADC_AN_07) |
| 90 | +#define IS_ADC_SCAN_CHANNEL(start, range) (((start) <= ADC_AN_07) && \ |
| 91 | + ((range) >= 1U) && \ |
| 92 | + (((start) + (range)) <= 8U)) |
| 93 | + |
| 94 | + |
| 95 | + typedef enum { |
| 96 | + ADC_REG_00 = 0U, |
| 97 | + ADC_REG_01 = 1U, |
| 98 | + ADC_REG_02 = 2U, |
| 99 | + ADC_REG_03 = 3U, |
| 100 | + ADC_REG_04 = 4U, |
| 101 | + ADC_REG_05 = 5U, |
| 102 | + ADC_REG_06 = 6U, |
| 103 | + ADC_REG_07 = 7U, |
| 104 | + ADC_REG_SP = 8U |
| 105 | + } ADC_REGx; |
| 106 | +#define IS_ADC_REG(param) ((param) <= ADC_REG_SP) |
| 107 | + |
| 108 | +#define ADC_APPLY_VREF_IN_CONVERSION ((uint32_t)0x00000000) |
| 109 | +#define ADC_APPLY_VREF_AT_ANY_TIME ((uint32_t)0x00000001) |
| 110 | +#define IS_ADC_VREF_CTRL(param) (((param) == ADC_APPLY_VREF_IN_CONVERSION) || \ |
| 111 | + ((param) == ADC_APPLY_VREF_AT_ANY_TIME)) |
| 112 | + |
| 113 | + typedef enum { |
| 114 | + ADC_CMPCR_0 = 0U, |
| 115 | + ADC_CMPCR_1 = 1U |
| 116 | + } ADC_CMPCRx; |
| 117 | +#define IS_ADC_CMPCRx(param) ((param) <= ADC_CMPCR_1) |
| 118 | + |
| 119 | +#define ADC_EXTERADTRG ((uint32_t)0x00000000) |
| 120 | +#define ADC_INTERTRIGGER ((uint32_t)0x00000001) |
| 121 | +#define IS_ADC_EXTERADTRG(param) (((param) == ADC_EXTERADTRG)|| \ |
| 122 | + ((param) == ADC_INTERTRIGGER)) |
| 123 | + |
| 124 | +#define IS_ADC_EXTERADTRG_TOP(param) (((param) == ADC_EXTERADTRG)|| \ |
| 125 | + ((param) == ADC_INTERTRIGGER)) |
| 126 | + |
| 127 | + |
| 128 | + typedef enum { |
| 129 | + ADC_LARGER_THAN_CMP_REG = 0U, |
| 130 | + ADC_SMALLER_THAN_CMP_REG = 1U |
| 131 | + } ADC_CmpCondition; |
| 132 | +#define IS_ADC_CMPCONDITION(param) ((param) <= ADC_SMALLER_THAN_CMP_REG) |
| 133 | + |
| 134 | + typedef enum { |
| 135 | + ADC_SEQUENCE_CMP_MODE = 0U, |
| 136 | + ADC_CUMULATION_CMP_MODE = 1U |
| 137 | + } ADC_CmpCntMode; |
| 138 | +#define IS_ADC_CMPMODE(param) ((param) <= ADC_CUMULATION_CMP_MODE) |
| 139 | + |
| 140 | + typedef enum { |
| 141 | + ADC_TRG_00 = 0U, |
| 142 | + ADC_TRG_01 = 1U, |
| 143 | + ADC_TRG_02 = 2U, |
| 144 | + ADC_TRG_03 = 3U, |
| 145 | + ADC_TRG_04 = 4U, |
| 146 | + ADC_TRG_05 = 5U, |
| 147 | + ADC_TRG_06 = 6U, |
| 148 | + ADC_TRG_07 = 7U, |
| 149 | + ADC_TRG_08 = 8U, |
| 150 | + ADC_TRG_09 = 9U |
| 151 | + } ADC_TRGx; |
| 152 | +#define IS_ADC_TRG(param) ((param) <= ADC_TRG_09) |
| 153 | + |
| 154 | +/** |
| 155 | + * @brief ADC Monitor Configuration Structure definition |
| 156 | + */ |
| 157 | + typedef struct { |
| 158 | + ADC_AINx CmpChannel; /*!< Select which ADC channel will be used */ |
| 159 | + uint32_t CmpCnt; /*!< How many times will valid comparisons be counted, range from 1 to 16 */ |
| 160 | + ADC_CmpCondition Condition; /*!< Condition to compare ADC channel with Compare Register */ |
| 161 | + ADC_CmpCntMode CntMode; /*!< Mode to compare ADC channel with Compare Register */ |
| 162 | + uint32_t CmpValue; /*!< Comparison value to be set in Compare Register, max value is 4095 */ |
| 163 | + } ADC_MonitorTypeDef; |
| 164 | + |
| 165 | +#define IS_ADC_CMPCNT(param) (((param) >= 1U) && ((param) <= 16U)) |
| 166 | +#define IS_ADC_CMPVALUE_12BIT(param) ((param) <= 4095U) |
| 167 | + |
| 168 | +/** |
| 169 | + * @brief Union to store ADC state |
| 170 | + */ |
| 171 | + typedef union { |
| 172 | + uint32_t All; |
| 173 | + struct { |
| 174 | + uint32_t NormalBusy:1; /*!< bit0, Normal A/D conversion busy flag (ADBF) */ |
| 175 | + uint32_t NormalComplete:1; /*!< bit1, Normal AD conversion complete flag (EOCF) */ |
| 176 | + uint32_t TopBusy:1; /*!< bit2, Top-priority A/D conversion busy flag (HPADBF) */ |
| 177 | + uint32_t TopComplete:1; /*!< bit3, Top-priority AD conversion complete flag (HPEOCF) */ |
| 178 | + uint32_t Reserved:28; /*!< bit4 to bit 31, reserved */ |
| 179 | + } Bit; |
| 180 | + } ADC_State; |
| 181 | + |
| 182 | +/** |
| 183 | + * @brief Union to store ADC result |
| 184 | + */ |
| 185 | + typedef union { |
| 186 | + uint32_t All; |
| 187 | + struct { |
| 188 | + uint32_t ADResult:12; /*!< bit0 to bit11, store AD result */ |
| 189 | + uint32_t Stored:1; /*!< bit12, AD result has been stored */ |
| 190 | + uint32_t OverRun:1; /*!< bit13, new AD result is stored before the old one is read */ |
| 191 | + uint32_t Reserved:18; /*!< bit14 to bit31, reserved */ |
| 192 | + } Bit; |
| 193 | + } ADC_Result; |
| 194 | + |
| 195 | + |
| 196 | +/** @} */ |
| 197 | +/* End of group ADC_Exported_Types */ |
| 198 | + |
| 199 | +/** @defgroup ADC_Exported_FunctionPrototypes |
| 200 | + * @{ |
| 201 | + */ |
| 202 | + |
| 203 | + void ADC_SWReset(TSB_AD_TypeDef * ADx); |
| 204 | + void ADC_SetClk(TSB_AD_TypeDef * ADx, uint32_t Sample_HoldTime, uint32_t Prescaler_Output); |
| 205 | + void ADC_Start(TSB_AD_TypeDef * ADx); |
| 206 | + void ADC_SetScanMode(TSB_AD_TypeDef * ADx, FunctionalState NewState); |
| 207 | + void ADC_SetRepeatMode(TSB_AD_TypeDef * ADx, FunctionalState NewState); |
| 208 | + void ADC_SetINTMode(TSB_AD_TypeDef * ADx, uint32_t INTMode); |
| 209 | + void ADC_SetInputChannel(TSB_AD_TypeDef * ADx, ADC_AINx InputChannel); |
| 210 | + void ADC_SetScanChannel(TSB_AD_TypeDef * ADx, ADC_AINx StartChannel, uint32_t Range); |
| 211 | + void ADC_SetVrefCut(TSB_AD_TypeDef * ADx, uint32_t VrefCtrl); |
| 212 | + void ADC_SetIdleMode(TSB_AD_TypeDef * ADx, FunctionalState NewState); |
| 213 | + void ADC_SetVref(TSB_AD_TypeDef * ADx, FunctionalState NewState); |
| 214 | + void ADC_SetInputChannelTop(TSB_AD_TypeDef * ADx, ADC_AINx TopInputChannel); |
| 215 | + void ADC_StartTopConvert(TSB_AD_TypeDef * ADx); |
| 216 | + void ADC_SetMonitor(TSB_AD_TypeDef * ADx, ADC_CMPCRx ADCMPx, FunctionalState NewState); |
| 217 | + void ADC_ConfigMonitor(TSB_AD_TypeDef * ADx, ADC_CMPCRx ADCMPx, ADC_MonitorTypeDef * Monitor); |
| 218 | + void ADC_SetHWTrg(TSB_AD_TypeDef * ADx, uint32_t HWSrc, FunctionalState NewState); |
| 219 | + void ADC_SetHWTrgTop(TSB_AD_TypeDef * ADx, uint32_t HWSrc, FunctionalState NewState); |
| 220 | + ADC_State ADC_GetConvertState(TSB_AD_TypeDef * ADx); |
| 221 | + ADC_Result ADC_GetConvertResult(TSB_AD_TypeDef * ADx, ADC_REGx ADREGx); |
| 222 | + void ADC_EnableTrigger(void); |
| 223 | + void ADC_DisableTrigger(void); |
| 224 | + void ADC_SetTriggerStartup(ADC_TRGx TriggerStartup); |
| 225 | + void ADC_SetTriggerStartupTop(ADC_TRGx TopTriggerStartup); |
| 226 | + |
| 227 | +/** @} */ |
| 228 | +/* End of group ADC_Exported_FunctionPrototypes */ |
| 229 | +/** @} */ |
| 230 | +/* End of group ADC */ |
| 231 | +/** @} */ |
| 232 | +/* End of group TX04_Periph_Driver */ |
| 233 | +#ifdef __cplusplus |
| 234 | +} |
| 235 | +#endif /* __cplusplus */ |
| 236 | +#endif /* __TMPM46B_ADC_H */ |
0 commit comments