|
| 1 | +/** |
| 2 | + ******************************************************************************* |
| 3 | + * @file tmpm066_adc.h |
| 4 | + * @brief This file provides all the functions prototypes for ADC driver. |
| 5 | + * @version V2.0.2.1 |
| 6 | + * @date 2015/10/09 |
| 7 | + * |
| 8 | + * (C)Copyright TOSHIBA ELECTRONIC DEVICES & STORAGE CORPORATION 2017 All rights reserved |
| 9 | + ******************************************************************************* |
| 10 | + */ |
| 11 | + |
| 12 | +/* Define to prevent recursive inclusion -------------------------------------*/ |
| 13 | +#ifndef __TMPM066_ADC_H |
| 14 | +#define __TMPM066_ADC_H |
| 15 | + |
| 16 | +#ifdef __cplusplus |
| 17 | +extern "C" { |
| 18 | +#endif |
| 19 | + |
| 20 | +/* Includes ------------------------------------------------------------------*/ |
| 21 | +#include "TMPM066.h" |
| 22 | +#include "tx00_common.h" |
| 23 | + |
| 24 | +#if defined(__TMPM066_ADC_H) |
| 25 | + |
| 26 | +/** @addtogroup TX00_Periph_Driver |
| 27 | + * @{ |
| 28 | + */ |
| 29 | + |
| 30 | +/** @addtogroup ADC |
| 31 | + * @{ |
| 32 | + */ |
| 33 | + |
| 34 | +/** @defgroup ADC_Exported_Types |
| 35 | + * @{ |
| 36 | + */ |
| 37 | + |
| 38 | +#define ADC_CONVERSION_35_CLOCK ((uint32_t)0x00000000) /* 35.5 conversion clock */ |
| 39 | +#define ADC_CONVERSION_42_CLOCK ((uint32_t)0x00000040) /* 42 conversion clock */ |
| 40 | +#define ADC_CONVERSION_68_CLOCK ((uint32_t)0x00000080) /* 68 conversion clock */ |
| 41 | +#define ADC_CONVERSION_81_CLOCK ((uint32_t)0x000000C0) /* 81 conversion clock */ |
| 42 | +#define IS_ADC_CONVERSION_TIME(param) (((param) == ADC_CONVERSION_35_CLOCK) || \ |
| 43 | + ((param) == ADC_CONVERSION_42_CLOCK) || \ |
| 44 | + ((param) == ADC_CONVERSION_68_CLOCK) || \ |
| 45 | + ((param) == ADC_CONVERSION_81_CLOCK)) |
| 46 | + |
| 47 | +#define ADC_FC_DIVIDE_LEVEL_1 ((uint32_t)0x00000000) |
| 48 | +#define ADC_FC_DIVIDE_LEVEL_2 ((uint32_t)0x00000001) |
| 49 | +#define ADC_FC_DIVIDE_LEVEL_4 ((uint32_t)0x00000002) |
| 50 | +#define ADC_FC_DIVIDE_LEVEL_6 ((uint32_t)0x00000008) |
| 51 | +#define ADC_FC_DIVIDE_LEVEL_8 ((uint32_t)0x00000003) |
| 52 | +#define ADC_FC_DIVIDE_LEVEL_12 ((uint32_t)0x00000009) |
| 53 | +#define ADC_FC_DIVIDE_LEVEL_16 ((uint32_t)0x00000004) |
| 54 | +#define ADC_FC_DIVIDE_LEVEL_24 ((uint32_t)0x0000000A) |
| 55 | +#define ADC_FC_DIVIDE_LEVEL_48 ((uint32_t)0x0000000B) |
| 56 | +#define ADC_FC_DIVIDE_LEVEL_96 ((uint32_t)0x0000000C) |
| 57 | +#define IS_ADC_PRESCALER(param) (((param) == ADC_FC_DIVIDE_LEVEL_1) || \ |
| 58 | + ((param) == ADC_FC_DIVIDE_LEVEL_2) || \ |
| 59 | + ((param) == ADC_FC_DIVIDE_LEVEL_4) || \ |
| 60 | + ((param) == ADC_FC_DIVIDE_LEVEL_6) || \ |
| 61 | + ((param) == ADC_FC_DIVIDE_LEVEL_8) || \ |
| 62 | + ((param) == ADC_FC_DIVIDE_LEVEL_12) || \ |
| 63 | + ((param) == ADC_FC_DIVIDE_LEVEL_16) || \ |
| 64 | + ((param) == ADC_FC_DIVIDE_LEVEL_24) || \ |
| 65 | + ((param) == ADC_FC_DIVIDE_LEVEL_48) || \ |
| 66 | + ((param) == ADC_FC_DIVIDE_LEVEL_96)) |
| 67 | + |
| 68 | +#define ADC_INT_SINGLE ((uint32_t)0x00000000) |
| 69 | +#define ADC_INT_CONVERSION_4 ((uint32_t)0x00000008) |
| 70 | +#define ADC_INT_CONVERSION_8 ((uint32_t)0x00000010) |
| 71 | +#define IS_ADC_INT_MODE(param) (((param) == ADC_INT_SINGLE) || \ |
| 72 | + ((param) == ADC_INT_CONVERSION_4) || \ |
| 73 | + ((param) == ADC_INT_CONVERSION_8)) |
| 74 | + |
| 75 | +#define ADC_AN_0 ((uint32_t)0x00000000) |
| 76 | +#define ADC_AN_1 ((uint32_t)0x00000001) |
| 77 | +#define ADC_AN_2 ((uint32_t)0x00000002) |
| 78 | +#define ADC_AN_3 ((uint32_t)0x00000003) |
| 79 | +#define ADC_AN_4 ((uint32_t)0x00000004) |
| 80 | +#define ADC_AN_5 ((uint32_t)0x00000005) |
| 81 | +#define ADC_AN_6 ((uint32_t)0x00000006) |
| 82 | +#define ADC_AN_7 ((uint32_t)0x00000007) |
| 83 | + |
| 84 | +#define IS_ADC_INPUT_CH(param) (((param) == ADC_AN_0) || \ |
| 85 | + ((param) == ADC_AN_1) || \ |
| 86 | + ((param) == ADC_AN_2) || \ |
| 87 | + ((param) == ADC_AN_3) || \ |
| 88 | + ((param) == ADC_AN_4) || \ |
| 89 | + ((param) == ADC_AN_5) || \ |
| 90 | + ((param) == ADC_AN_6) || \ |
| 91 | + ((param) == ADC_AN_7)) |
| 92 | + |
| 93 | + |
| 94 | +#define ADC_CMP_0 ((uint8_t)0x00) |
| 95 | +#define ADC_CMP_1 ((uint8_t)0x01) |
| 96 | +#define IS_ADC_CMP(param) (((param) == ADC_CMP_0) || \ |
| 97 | + ((param) == ADC_CMP_1)) |
| 98 | + |
| 99 | +#define ADC_REG_0 ((uint32_t)0x00000000) |
| 100 | +#define ADC_REG_1 ((uint32_t)0x00000001) |
| 101 | +#define ADC_REG_2 ((uint32_t)0x00000002) |
| 102 | +#define ADC_REG_3 ((uint32_t)0x00000003) |
| 103 | +#define ADC_REG_4 ((uint32_t)0x00000004) |
| 104 | +#define ADC_REG_5 ((uint32_t)0x00000005) |
| 105 | +#define ADC_REG_6 ((uint32_t)0x00000006) |
| 106 | +#define ADC_REG_7 ((uint32_t)0x00000007) |
| 107 | +#define ADC_REG_SP ((uint32_t)0x00000008) |
| 108 | +#define IS_ADC_REG(param) ((param) <= ADC_REG_SP) |
| 109 | + |
| 110 | +#define IS_ADC_RESULT_CMP_REG(param) ((param) <= ADC_REG_SP) |
| 111 | + |
| 112 | +#define ADC_EXT_TRG ((uint32_t)0x00000000) |
| 113 | +#define ADC_MATCH_TB_0 ((uint32_t)0x00000020) |
| 114 | +#define IS_ADC_HW_TRG_NORMAL(param) (((param) == ADC_EXT_TRG) || \ |
| 115 | + ((param) == ADC_MATCH_TB_0)) |
| 116 | + |
| 117 | +#define ADC_MATCH_TB_1 ((uint32_t)0x00000080) |
| 118 | +#define IS_ADC_HW_TRG_TOP(param) (((param) == ADC_EXT_TRG) || \ |
| 119 | + ((param) == ADC_MATCH_TB_1)) |
| 120 | + |
| 121 | +#define IS_ADC_CMP_VALUE(param) ((param) <= (uint16_t)0x03ff) |
| 122 | + |
| 123 | + typedef enum { |
| 124 | + ADC_NO_OVERRUN = 0U, |
| 125 | + ADC_OVERRUN = 1U |
| 126 | + } ADC_OverrunState; |
| 127 | + |
| 128 | + typedef enum { |
| 129 | + ADC_SCAN_4CH = 0U, |
| 130 | + ADC_SCAN_8CH = 1U |
| 131 | + } ADC_ChannelScanMode; |
| 132 | +#define IS_ADC_CH_SCAN_MODE(param) (((param) == ADC_SCAN_4CH) || \ |
| 133 | + ((param) == ADC_SCAN_8CH)) |
| 134 | + |
| 135 | + typedef enum { |
| 136 | + ADC_COMPARISON_SMALLER = 0U, |
| 137 | + ADC_COMPARISON_LARGER = 1U |
| 138 | + } ADC_ComparisonState; |
| 139 | +#define IS_ADC_CMP_INT(param) (((param) == ADC_COMPARISON_SMALLER) || \ |
| 140 | + ((param) == ADC_COMPARISON_LARGER)) |
| 141 | + |
| 142 | + typedef struct { |
| 143 | + WorkState ADCResultStored; /*!< ADC result storage flag */ |
| 144 | + ADC_OverrunState ADCOverrunState; /*!< ADC overrun flag */ |
| 145 | + uint16_t ADCResultValue; /*!< ADC result value */ |
| 146 | + } ADC_ResultTypeDef; |
| 147 | + |
| 148 | +#define ADC_DMA_REQ_NORMAL ((uint8_t)0x00) |
| 149 | +#define ADC_DMA_REQ_TOP ((uint8_t)0x01) |
| 150 | +#define ADC_DMA_REQ_MONITOR1 ((uint8_t)0x02) |
| 151 | +#define ADC_DMA_REQ_MONITOR2 ((uint8_t)0x03) |
| 152 | +#define IS_ADC_DMA_REQ(param) ((param) <= ADC_DMA_REQ_MONITOR2) |
| 153 | + |
| 154 | + typedef union { |
| 155 | + uint32_t All; |
| 156 | + struct { |
| 157 | + uint32_t NormalBusy:1; /*!< bit0, Normal A/D conversion busy flag (MOD0<ADBFN>) */ |
| 158 | + uint32_t NormalComplete:1; /*!< bit1, Normal AD conversion complete flag (MOD0<EOCFN>) */ |
| 159 | + uint32_t TopBusy:1; /*!< bit2, Top-priority A/D conversion busy flag (MOD2<ADBFHP>) */ |
| 160 | + uint32_t TopComplete:1; /*!< bit3, Top-priority AD conversion complete flag (MOD2<EOCFHP>) */ |
| 161 | + uint32_t Reserved:28; /*!< bit4 to bit 31, reserved */ |
| 162 | + } Bit; |
| 163 | + } ADC_State; |
| 164 | + |
| 165 | +/** @} */ |
| 166 | +/* End of group ADC_Exported_Types */ |
| 167 | + |
| 168 | +/** @defgroup ADC_Exported_FunctionPrototypes |
| 169 | + * @{ |
| 170 | + */ |
| 171 | + void ADC_SWReset(void); |
| 172 | + void ADC_SetClk(uint32_t Conversion_Time, uint32_t Prescaler_Output); |
| 173 | + void ADC_Start(void); |
| 174 | + void ADC_SetScanMode(FunctionalState NewState); |
| 175 | + void ADC_SetRepeatMode(FunctionalState NewState); |
| 176 | + void ADC_SetINTMode(uint32_t INTMode); |
| 177 | + ADC_State ADC_GetConvertState(void); |
| 178 | + void ADC_SetInputChannel(uint32_t InputChannel); |
| 179 | + void ADC_SetChannelScanMode(ADC_ChannelScanMode ScanMode); |
| 180 | + void ADC_SetIdleMode(FunctionalState NewState); |
| 181 | + void ADC_SetVref(FunctionalState NewState); |
| 182 | + void ADC_SetInputChannelTop(uint32_t TopInputChannel); |
| 183 | + void ADC_StartTopConvert(void); |
| 184 | + void ADC_SetMonitor(uint8_t ADCMPx, FunctionalState NewState); |
| 185 | + void ADC_SetResultCmpReg(uint8_t ADCMPx, uint32_t ResultComparison); |
| 186 | + void ADC_SetMonitorINT(uint8_t ADCMPx, ADC_ComparisonState NewState); |
| 187 | + void ADC_SetHWTrg(uint32_t HwSource, FunctionalState NewState); |
| 188 | + void ADC_SetHWTrgTop(uint32_t HwSource, FunctionalState NewState); |
| 189 | + ADC_ResultTypeDef ADC_GetConvertResult(uint32_t ADREGx); |
| 190 | + void ADC_SetCmpValue(uint8_t ADCMPx, uint16_t value); |
| 191 | + void ADC_SetDMAReq(uint8_t DMAReq, FunctionalState NewState); |
| 192 | + |
| 193 | +/** @} */ |
| 194 | +/* End of group ADC_Exported_FunctionPrototypes */ |
| 195 | + |
| 196 | +/** @} */ |
| 197 | +/* End of group ADC */ |
| 198 | + |
| 199 | +/** @} */ |
| 200 | +/* End of group TX00_Periph_Driver */ |
| 201 | + |
| 202 | +#endif /* (__TMPM066_ADC_H) */ |
| 203 | + |
| 204 | +#ifdef __cplusplus |
| 205 | +} |
| 206 | +#endif |
| 207 | +#endif /* __TMPM066_ADC_H */ |
0 commit comments