Files
hsb/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/adc.h
mmi 3990c23a79 Missing files for SWo
git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@236 05563f52-14a8-4384-a975-3d1654cca0fa
2017-10-05 08:33:15 +00:00

236 lines
8.0 KiB
C

// -----------------------------------------------------------------------------
/// @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
// -----------------------------------------------------------------------------
/// @defgroup {group_name} {group_description}
/// Description
/// @file adc.h
/// @ingroup {group_name}
#ifndef INC_ADC_H_
#define INC_ADC_H_
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include <stdbool.h>
#include "platform.h"
#include "IODevice.h"
#include "stm32f10x.h"
#include "stm32f10x_adc.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
#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 IODevice device;
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;
bool useRanks;
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];
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(struct AdcChannel* self, uint16_t* value);
#endif /* INC_ADC_H_ */