// ----------------------------------------------------------------------------- /// @file adc.h /// @brief File description // ----------------------------------------------------------------------------- // Micro-Key bv // Industrieweg 28, 9804 TG Noordhorn // Postbus 92, 9800 AB Zuidhorn // The Netherlands // Tel: +31 594 503020 // Fax: +31 594 505825 // Email: support@microkey.nl // Web: www.microkey.nl // ----------------------------------------------------------------------------- /// $Revision$ /// $Author$ /// $Date$ // (c) 2015 Micro-Key bv // ----------------------------------------------------------------------------- /** * InternalADC implementation * \defgroup InternalADC Package InternalADC * \ingroup Platform * @{ */ #ifndef INC_ADC_H_ #define INC_ADC_H_ // ----------------------------------------------------------------------------- // Include files // ----------------------------------------------------------------------------- #include #include "platform.h" #include "ADCDevice.h" #include "stm32f10x.h" #include "stm32f10x_adc.h" // ----------------------------------------------------------------------------- // Constant and macro definitions // ----------------------------------------------------------------------------- #define ADC_RESOLUTION_IN_BITS (12) #define ADC_AVERAGE_DEPTH (10) #define ADC_NUMBER_OF_CHANNELS (18) // 16 IOs + Temp + Vcc // ----------------------------------------------------------------------------- // Type definitions. // ----------------------------------------------------------------------------- struct Adc; // Prototype struct AdcChannelParameters { uint8_t channel; uint8_t Rank; uint8_t ADC_SampleTime; }; struct AdcChannel { struct ADCDevice adcDevice; struct Adc* parent; uint8_t channel; uint8_t Rank; uint8_t ADC_SampleTime; T_PL_GPIO input; bool initialized; }; struct AdcParameters { uint32_t ADC_Mode; FunctionalState ADC_ScanConvMode; FunctionalState ADC_ContinuousConvMode; uint32_t ADC_ExternalTrigConv; uint32_t ADC_DataAlign; uint8_t ADC_NbrOfChannel; }; struct Adc { ADC_TypeDef* ADCx; ADC_InitTypeDef ADC_InitStruct; bool useDMA; int numberOfUsedChannels; struct AdcChannel channel[ADC_NUMBER_OF_CHANNELS]; // Only necessary when the RANK parameter determines conversion order or RANK is used anyway // For single conversions the READ function simply returns the converted value // Note that the content of this array IS NOT SORTED BY CHANNEL NUMBER but sorted BY RANK NUMBER // When initialising an ADC channel to a regular group, the RANK parameter determines the // order of convertions. E.G. channel 5 can be put first while channel 1 can be put last. // The array index stands for the RANK uint16_t channelValue[ADC_NUMBER_OF_CHANNELS * ADC_AVERAGE_DEPTH]; bool initialized; }; // ----------------------------------------------------------------------------- // Function declarations // ----------------------------------------------------------------------------- /** ---------------------------------------------------------------------------- * ADC_construct * Constructor for ADC instance * * @param self The ADC instance to initialize * @param parameters Additional ADC parameters * * @return ErrorStatus SUCCESS if initialisation was successful * ERROR otherwise * * @todo * ----------------------------------------------------------------------------- */ extern ErrorStatus ADC_construct(struct Adc* self, struct AdcParameters* parameters); /** ---------------------------------------------------------------------------- * ADC_destruct * Destructor for an ADC instance * * @param self The ADC instance to destruct * * @return ErrorStatus SUCCESS if initialisation was successful * ERROR otherwise * * @todo * ----------------------------------------------------------------------------- */ extern void ADC_destruct(struct Adc* self); /** ---------------------------------------------------------------------------- * ADC_performInternalCalibration * Apply internal ADC calibration to ADC instance * ADC calibration is RESET and afterwards set. * * @param self The ADC instance to calibrate * * @return ErrorStatus SUCCESS if initialisation was successful * ERROR otherwise * * @todo * ----------------------------------------------------------------------------- */ extern ErrorStatus ADC_performInternalCalibration(const struct Adc* self); /** ---------------------------------------------------------------------------- * ADC_setStatus * Changes the status of the ADC instance * * @param self The ADC instance * @param command new command for the ADC instance * - ENABLE * - DISABLE * * @return ErrorStatus SUCCESS if initialisation was successful * ERROR otherwise * * @todo * ----------------------------------------------------------------------------- */ extern ErrorStatus ADC_setStatus (struct Adc* self, FunctionalState command); /** ---------------------------------------------------------------------------- * ADC_setDMAStatus * Changes the status of the ADC instance's DMA * * @param self The ADC instance * @param command new command for the ADC instance * - ENABLE * - DISABLE * * @return ErrorStatus SUCCESS if initialisation was successful * ERROR otherwise * * @todo * ----------------------------------------------------------------------------- */ extern ErrorStatus ADC_setDMAStatus (struct Adc* self, FunctionalState command); /** ---------------------------------------------------------------------------- * ADCChannel_construct * Constructor for ADC channel instance * * @param self The ADC channel instance to initialize * @param parent The parent ADC this channel belongs to * @param parameters Additional ADC parameters * * @return ErrorStatus SUCCESS if initialisation was successful * ERROR otherwise * * @todo * ----------------------------------------------------------------------------- */ extern ErrorStatus ADCChannel_construct(struct AdcChannel* self, struct Adc* parent, struct AdcChannelParameters* parameters); /** ---------------------------------------------------------------------------- * ADCChannel_destruct * Destructor for an ADC channel instance * * @param self The ADC channel instance to destruct * * @return ErrorStatus SUCCESS if initialisation was successful * ERROR otherwise * * @todo * ----------------------------------------------------------------------------- */ extern void ADCChannel_destruct(struct AdcChannel* self); /** ---------------------------------------------------------------------------- * ADCChannel_read * Read the current conversion value of the ADC channel in argument self * * @param self ADC channel object * @param value The read value * * @return ErrorStatus SUCCESS if initialisation was successful * ERROR otherwise * * @todo * ----------------------------------------------------------------------------- */ extern ErrorStatus ADCChannel_read(const struct AdcChannel* self, uint16_t* value); #endif /* INC_ADC_H_ */ /** @} */