stm32: adc: Add functions to get and clear flags

This includes adding documentation to the status flags.

Originally tracked at: https://github.com/libopencm3/libopencm3/pull/833

Modified to drop whitespace changes, and simply boolean return.
This commit is contained in:
Clara Casas 2017-10-01 02:05:33 +02:00 committed by Karl Palsson
parent 743513a4b1
commit 889b7de0d7
4 changed files with 63 additions and 0 deletions

View File

@ -185,12 +185,27 @@ specific memorymap.h header before including this header file.*/
/* --- ADC_SR values ------------------------------------------------------- */
/****************************************************************************/
/** @defgroup adc_sr_values ADC Status Register Flags
@ingroup STM32xx_adc_defines
@{*/
/* STRT:*//** Regular channel Start flag */
#define ADC_SR_STRT (1 << 4)
/* JSTRT:*//** Injected channel Start flag */
#define ADC_SR_JSTRT (1 << 3)
/* JEOC:*//** Injected channel end of conversion */
#define ADC_SR_JEOC (1 << 2)
/* EOC:*//** End of conversion */
#define ADC_SR_EOC (1 << 1)
/* AWD:*//** Analog watchdog flag */
#define ADC_SR_AWD (1 << 0)
/**@}*/
/* --- ADC_CR1 values ------------------------------------------------------ */
@ -396,6 +411,8 @@ void adc_start_conversion_regular(uint32_t adc);
void adc_start_conversion_injected(uint32_t adc);
void adc_enable_dma(uint32_t adc);
void adc_disable_dma(uint32_t adc);
bool adc_get_flag(uint32_t adc, uint32_t flag);
void adc_clear_flag(uint32_t adc, uint32_t flag);
/* common methods that have slight differences */
void adc_set_sample_time(uint32_t adc, uint8_t channel, uint8_t time);

View File

@ -96,7 +96,13 @@ LGPL License Terms @ref lgpl_license
/* --- ADC_SR values ------------------------------------------------------- */
/** @defgroup adc_sr_values ADC Status Register Flags
* @ingroup adc_defines
*@{*/
/* OVR:*//** Overrun */
#define ADC_SR_OVR (1 << 5)
/**@}*/
/* --- ADC_CR1 values specific to STM32F2,4--------------------------------- */

View File

@ -100,10 +100,24 @@ LGPL License Terms @ref lgpl_license
/**@}*/
/* --- ADC_SR values ------------------------------------------------------- */
/****************************************************************************/
/** @defgroup adc_sr_values ADC Status Register Flags
* @ingroup adc_defines
*
*@{*/
/* JCNR:*//** Injected channel not ready */
#define ADC_SR_JCNR (1 << 9)
/* RCNR:*//** Regular channel not ready */
#define ADC_SR_RCNR (1 << 8)
/* ADONS:*//** ADC ON status */
#define ADC_SR_ADONS (1 << 6)
/* OVR:*//** Overrun */
#define ADC_SR_OVR (1 << 5)
/**@}*/
/* --- ADC_CR1 values ------------------------------------------------------- */
#define ADC_CR1_OVRIE (1 << 28)

View File

@ -748,6 +748,32 @@ void adc_disable_dma(uint32_t adc)
ADC_CR2(adc) &= ~ADC_CR2_DMA;
}
/*---------------------------------------------------------------------------*/
/** @brief Read a Status Flag.
@param[in] adc Unsigned int32. ADC register address base @ref adc_reg_base
@param[in] flag Unsigned int32. Status register flag @ref adc_sr_values.
@returns boolean: flag set.
*/
bool adc_get_flag(uint32_t adc, uint32_t flag)
{
return ADC_SR(adc) & flag;
}
/*---------------------------------------------------------------------------*/
/** @brief Clear a Status Flag.
@param[in] adc Unsigned int32. ADC register address base @ref adc_reg_base
@param[in] flag Unsigned int32. Status register flag @ref adc_sr_values.
*/
void adc_clear_flag(uint32_t adc, uint32_t flag)
{
/* All defined bits are 'r' or 'rc_w0' */
ADC_SR(adc) = ~flag;
}
/*---------------------------------------------------------------------------*/
/**@}*/