/** @file /hal/micro/adc.h * @brief Header for A/D converter. * * */ /** * @addtogroup stm32w-cpu * @{ */ /** @defgroup adc Sample A/D converter driver. * * See adc.h for source code. * * @note Stm32w108xx ADC driver support is preliminary and essentailly untested - * please do not attempt to use this ADC driver on this platform. * * @note Except for the Stm32w108xx, the StZNet stack does use these functions. * * To use the ADC system, include this file and ensure that * ::halInternalInitAdc() is called whenever the microcontroller is * started. * * A "user" is a separate thread of execution and usage. That is, * internal St code is one user and clients are a different user. * But a client that is calling the ADC in two different functions * constitutes only one user, as long as the ADC access is not * interleaved. * * @note This code does not allow access to the continuous reading mode of * the ADC, which some clients may require. * * Many functions in this file return an ::StStatus value. See * error-def.h for definitions of all ::StStatus return values. * *@{ */ #ifndef ADC_H_ #define ADC_H_ #ifdef CORTEXM3_STM32W108 // A type for the ADC User enumeration. typedef uint8_t ADCUser; enum { /** LQI User ID. */ ADC_USER_LQI = 0, /** Application User ID */ ADC_USER_APP = 1, /** Application User ID */ ADC_USER_APP2 = 2 }; /** @brief Be sure to update ::NUM_ADC_USERS if additional users are added * to the ::ADCUser list. */ #define NUM_ADC_USERS 3 // make sure to update if the above is adjusted // A type for the reference enumeration. typedef uint8_t ADCReferenceType; enum { /** AREF pin reference. */ ADC_REF_AREF = 0x00, /** AVCC pin reference. */ ADC_REF_AVCC = 0x40, /** Internal reference. */ ADC_REF_INT = 0xC0 }; // A type for the rate enumeration. typedef uint8_t ADCRateType; enum { /** Rate 32 us, 5 effective bits in ADC_DATA[15:11] */ ADC_CONVERSION_TIME_US_32 = 0x0, /** Rate 64 us, 6 effective bits in ADC_DATA[15:10] */ ADC_CONVERSION_TIME_US_64 = 0x1, /** Rate 128 us, 7 effective bits in ADC_DATA[15:9] */ ADC_CONVERSION_TIME_US_128 = 0x2, /** Rate 256 us, 8 effective bits in ADC_DATA[15:8] */ ADC_CONVERSION_TIME_US_256 = 0x3, /** Rate 512 us, 9 effective bits in ADC_DATA[15:7] */ ADC_CONVERSION_TIME_US_512 = 0x4, /** Rate 1024 us, 10 effective bits in ADC_DATA[15:6] */ ADC_CONVERSION_TIME_US_1024 = 0x5, /** Rate 2048 us, 11 effective bits in ADC_DATA[15:5] */ ADC_CONVERSION_TIME_US_2048 = 0x6, /** Rate 4096 us, 12 effective bits in ADC_DATA[15:4] */ ADC_CONVERSION_TIME_US_4096 = 0x7, }; #if defined (CORTEXM3) /** Channel 0 : ADC0 on PB5 */ #define ADC_MUX_ADC0 0x0 /** Channel 1 : ADC1 on PB6 */ #define ADC_MUX_ADC1 0x1 /** Channel 2 : ADC2 on PB7 */ #define ADC_MUX_ADC2 0x2 /** Channel 3 : ADC3 on PC1 */ #define ADC_MUX_ADC3 0x3 /** Channel 4 : ADC4 on PA4 */ #define ADC_MUX_ADC4 0x4 /** Channel 5 : ADC5 on PA5 */ #define ADC_MUX_ADC5 0x5 /** Channel 8 : VSS (0V) - not for high voltage range */ #define ADC_MUX_GND 0x8 /** Channel 9 : VREF/2 (0.6V) */ #define ADC_MUX_VREF2 0x9 /** Channel A : VREF (1.2V)*/ #define ADC_MUX_VREF 0xA /** Channel B : Regulator/2 (0.9V) - not for high voltage range */ #define ADC_MUX_VREG2 0xB // ADC_SOURCE__ selects as the positive input and as // the negative input. enum { ADC_SOURCE_ADC0_VREF2 = ((ADC_MUX_ADC0 <