bf0_hal_adc.h
Defines
-
HAL_ADC_STATE_RESET
HAL ADC state machine: ADC states definition (bitfields)
Note
ADC state machine is managed by bitfields, state must be compared with bit by bit. For example: “ if (HAL_IS_BIT_SET(HAL_ADC_GetState(hadc1), HAL_ADC_STATE_REG_BUSY)) “ “ if (HAL_IS_BIT_SET(HAL_ADC_GetState(hadc1), HAL_ADC_STATE_AWD1) ) “ ADC not yet initialized or disabled
-
HAL_ADC_STATE_READY
ADC peripheral ready for use
-
HAL_ADC_STATE_BUSY_INTERNAL
ADC is busy to internal process (initialization, calibration)
-
HAL_ADC_STATE_TIMEOUT
TimeOut occurrence
-
HAL_ADC_STATE_ERROR_INTERNAL
Internal error occurrence
-
HAL_ADC_STATE_ERROR_CONFIG
Configuration error occurrence
-
HAL_ADC_STATE_ERROR_DMA
DMA error occurrence
-
HAL_ADC_STATE_REG_BUSY
A conversion on group regular is ongoing or can occur (either by continuous mode, external trigger, low power auto power-on, multimode ADC master control)
-
HAL_ADC_STATE_REG_EOC
Conversion data available on group regular
-
HAL_ADC_STATE_REG_OVR
Overrun occurrence
-
HAL_ADC_START_IRQ_DONE
-
HAL_ADC_ERROR_NONE
No error
-
HAL_ADC_ERROR_INTERNAL
ADC IP internal error: if problem of clocking, enable/disable, erroneous state
-
HAL_ADC_ERROR_OVR
Overrun error
-
HAL_ADC_ERROR_DMA
DMA transfer error
-
ADC_RESOLUTION_10B
ADC 10-bit resolution
-
ADC_DATAALIGN_RIGHT
-
ADC_SCAN_DIRECTION_FORWARD
Scan direction forward: from channel 0 to channel 7
-
ADC_SCAN_DIRECTION_BACKWARD
Scan direction backward: from channel 7 to channel 0
-
ADC_SCAN_ENABLE
-
ADC_EXTERNALTRIGCONVEDGE_NONE
-
__HAL_ADC_GET_FLAG(__HANDLE__, __FLAG__)
Get the selected ADC’s flag status.
- Parameters:
__HANDLE__ – ADC handle
__FLAG__ – ADC flag
- Return values:
None –
-
__HAL_ADC_CLEAR_FLAG(__HANDLE__, __FLAG__)
Clear the ADC’s pending flags.
- Parameters:
__HANDLE__ – ADC handle
__FLAG__ – ADC flag
- Return values:
None –
-
__HAL_ADC_ENABLE_IRQ(__HANDLE__, __FLAG__)
Enable ADC irq.
- Parameters:
__HANDLE__ – ADC handle
__FLAG__ – ADC irq flag
- Return values:
None –
-
__HAL_ADC_DISABLE_IRQ(__HANDLE__, __FLAG__)
Disable ADC irq.
- Parameters:
__HANDLE__ – ADC handle
__FLAG__ – ADC irq flag
- Return values:
None –
-
__HAL_ADC_ENABLE_LDO_REF(__HANDLE__)
Enable ADC LdoRef.
- Parameters:
__HANDLE__ – ADC handle
- Return values:
None –
-
__HAL_ADC_DISABLE_LDO_REF(__HANDLE__)
Disable ADC LdoRef.
- Parameters:
__HANDLE__ – ADC handle
- Return values:
None –
-
__HAL_ADC_SET_LDO_REF_SEL(__HANDLE__, value)
Set ADC LdoRef Sel.
- Parameters:
__HANDLE__ – ADC handle
LdoRef – Sel Value.
- Return values:
None –
-
__HAL_ADC_RESET_HANDLE_STATE(__HANDLE__)
Reset ADC handle state.
- Parameters:
__HANDLE__ – ADC handle
- Return values:
None –
-
__HAL_ADC_SET_SAMPLE_WIDTH(__HANDLE__, width)
Set ADC Sample width.
- Parameters:
__HANDLE__ – ADC handle
width – Sample width in unit of PCLK cycles.
- Return values:
None –
-
__HAL_ADC_SET_CONV_WIDTH(__HANDLE__, width)
Set ADC Conversion width.
- Parameters:
__HANDLE__ – ADC handle
width – Conversion width in unit of PCLK cycles.
- Return values:
None –
-
__HAL_ADC_SET_DATA_DELAY(__HANDLE__, delay)
Set ADC Data sample delay.
- Parameters:
__HANDLE__ – ADC handle
delay – Delay for data in unit of PCLK cycles.
- Return values:
None –
-
__HAL_ADC_START_CONV(__HANDLE__)
Start ADC convert.
- Parameters:
__HANDLE__ – ADC handle
- Return values:
None –
-
__HAL_ADC_STOP_CONV(__HANDLE__)
Stop ADC convert, only work for infinite mode.
- Parameters:
__HANDLE__ – ADC handle
- Return values:
None –
-
__HAL_ADC_SINGLE_END(__HANDLE__)
Set ADC to single end mode.
- Parameters:
__HANDLE__ – ADC handle
- Return values:
None –
-
__HAL_ADC_DIFF_MODE(__HANDLE__)
Set ADC to differential mode.
- Parameters:
__HANDLE__ – ADC handle
- Return values:
None –
-
ADC_IS_ENABLE(__HANDLE__)
Verification of ADC state: enabled or disabled.
- Parameters:
__HANDLE__ – ADC handle
- Return values:
SET – (ADC enabled) or RESET (ADC disabled)
-
ADC_STATE_CLR_SET
Simultaneously clears and sets specific bits of the handle State.
Note
: ADC_STATE_CLR_SET() macro is merely aliased to generic macro MODIFY_REG(), the first parameter is the ADC handle State, the second parameter is the bit field to clear, the third and last parameter is the bit field to set.
- Return values:
None –
-
ADC_CLEAR_ERRORCODE(__HANDLE__)
Clear ADC error code (set it to error code: “no error”)
- Parameters:
__HANDLE__ – ADC handle
- Return values:
None –
-
ADC_CHSELR_CHANNEL(_CHANNEL_)
Configure the channel number into channel selection register.
- Parameters:
_CHANNEL_ – ADC Channel
- Return values:
None –
-
ADC_CFGR_CONTINUOUS(__HANDLE__, _CONTINUOUS_MODE_)
Enable ADC continuous conversion mode.
- Parameters:
__HANDLE__ – ADC handle.
_CONTINUOUS_MODE_ – Continuous mode.
- Return values:
None –
-
ADC_CFGR_DMACONTREQ(_DMACONTREQ_MODE_)
Enable the ADC DMA continuous request.
- Parameters:
_DMACONTREQ_MODE_ – DMA continuous request mode.
- Return values:
None –
-
ADC_DMA_ENABLE(__HANDLE__)
Enable ADC DMA mode.
- Parameters:
__HANDLE__ – ADC handle.
- Return values:
None –
-
ADC_DMA_RAW_DATA(__HANDLE__)
ADC DMA output raw data.
- Parameters:
__HANDLE__ – ADC handle.
- Return values:
None –
-
ADC_DMA_COMB_DATA(__HANDLE__)
ADC DMA output combined data.
- Parameters:
__HANDLE__ – ADC handle.
- Return values:
None –
-
ADC_DMA_DISABLE(__HANDLE__)
Disable ADC DMA mode.
- Parameters:
__HANDLE__ – ADC handle.
- Return values:
None –
-
IS_ADC_SRC_TIMER(__HANDLE__)
Check if timer triger enable.
- Parameters:
__HANDLE__ – ADC handle.
- Return values:
Not – 0 if timer triger enable
-
ADC_ENABLE_TIMER_TRIGER(__HANDLE__)
Enable timer triger.
- Parameters:
__HANDLE__ – ADC handle.
- Return values:
None –
-
ADC_DISABLE_TIMER_TRIGER(__HANDLE__)
Enable timer triger.
- Parameters:
__HANDLE__ – ADC handle.
- Return values:
None –
-
ADC_ENABLE_GPIO_TRIGER(__HANDLE__)
Enable GPIO triger.
- Parameters:
__HANDLE__ – ADC handle.
- Return values:
None –
-
ADC_DISABLE_GPIO_TRIGER(__HANDLE__)
Enable GPIO triger.
- Parameters:
__HANDLE__ – ADC handle.
- Return values:
None –
-
ADC_TIMER_TRIGER_LEVEL(__HANDLE__)
ADC TIMER triger with level mode, need edge detect.
- Parameters:
__HANDLE__ – ADC handle.
- Return values:
None –
-
ADC_TIMER_TRIGER_PULSE(__HANDLE__)
ADC TIMER triger with pulse mode, no edge detect.
- Parameters:
__HANDLE__ – ADC handle.
- Return values:
None –
-
ADC_FRC_EN(__HANDLE__)
Manual open ADC power.
- Parameters:
__HANDLE__ – ADC handle.
- Return values:
None –
-
ADC_CLR_FRC_EN(__HANDLE__)
AUTO open ADC power.
- Parameters:
__HANDLE__ – ADC handle.
- Return values:
None –
-
ADC_CHNL_SEL_FRC_EN(__HANDLE__)
Use auto chnel selet in configure register.
- Parameters:
__HANDLE__ – ADC handle.
- Return values:
None –
-
ADC_CHNL_CLR_FRC_EN(__HANDLE__)
Disable channel auto select.
- Parameters:
__HANDLE__ – ADC handle.
- Return values:
None –
-
ADC_SET_MUTE(__HANDLE__)
Set ADC mute.
- Parameters:
__HANDLE__ – ADC handle.
- Return values:
None –
-
ADC_SET_UNMUTE(__HANDLE__)
Set ADC unmute.
- Parameters:
__HANDLE__ – ADC handle.
- Return values:
None –
-
IS_ADC_RANGE(RESOLUTION, ADC_VALUE)
-
IS_ADC_REGULAR_RANK(RANK)
Enums
-
enum HAL_ADC_SRC_TIME_T
ENUM definition of Timer source for timer triger.
Note
All timer is hardware timer id.
Values:
-
enumerator HAL_ADC_SRC_GPTIM1
-
enumerator HAL_ADC_SRC_GPTIM2
-
enumerator HAL_ADC_SRC_GPTIM3
-
enumerator HAL_ADC_SRC_BTIM1
-
enumerator HAL_ADC_SRC_BTIM2
-
enumerator HAL_ADC_SRC_TIMER_CNT
-
enumerator HAL_ADC_SRC_GPTIM1
Functions
-
HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef *hadc)
Initializes the ADC peripheral and regular group according to parameters specified in structure “ADC_InitTypeDef”.
Note
As prerequisite, ADC clock must be configured at RCC top level depending on both possible clock sources: APB clock of HSI clock.
Note
Possibility to update parameters on the fly: The setting of these parameters is conditioned to ADC state. For parameters constraints, see comments of structure “ADC_InitTypeDef”.
Note
This function configures the ADC within 2 scopes: scope of entire ADC and scope of regular group. For parameters details, see comments of structure “ADC_InitTypeDef”.
- Parameters:
hadc – ADC handle
- Return values:
HAL – status
-
HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef *hadc)
Deinitial ADC hardware.
- Parameters:
hadc – ADC handle.
- Return values:
HAL_StatusTypeDef –
-
void HAL_ADC_HwInit(bool cold_boot)
Init all ADC hardware to expected state @reture void.
-
HAL_StatusTypeDef HAL_ADC_Prepare(ADC_HandleTypeDef *hadc)
Prepare ADC setting before start triger.
- Parameters:
hadc – ADC handle
- Return values:
HAL – status
-
HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef *hadc)
Enables ADC, starts conversion of regular group. Interruptions enabled in this function: None.
- Parameters:
hadc – ADC handle
- Return values:
HAL – status
-
HAL_StatusTypeDef HAL_ADC_Stop(ADC_HandleTypeDef *hadc)
Stop ADC conversion of regular group, disable ADC peripheral.
- Parameters:
hadc – ADC handle
- Return values:
HAL – status.
-
HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef *hadc, uint32_t Timeout)
Wait for regular group conversion to be completed.
- Parameters:
hadc – ADC handle
Timeout – Timeout value in millisecond.
- Return values:
HAL – status
-
HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef *hadc)
Start ADC with IRQ mode.
- Parameters:
hadc – ADC handle.
- Return values:
HAL_StatusTypeDef –
-
HAL_StatusTypeDef HAL_ADC_Stop_IT(ADC_HandleTypeDef *hadc)
Stop ADC irq mode.
- Parameters:
hadc – ADC handle.
- Return values:
HAL_StatusTypeDef –
-
void HAL_ADC_IRQHandler(ADC_HandleTypeDef *hadc)
Handle ADC interrupt request.
- Parameters:
hadc – ADC handle.
- Return values:
None –
-
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc)
Conversion complete callback in non blocking mode.
- Parameters:
hadc – ADC handle
- Return values:
None –
-
HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef *hadc, uint32_t *pData, uint32_t Length)
start ADC convert with dma mode.
- Parameters:
hadc – ADC handle.
pData – data buffer.
Length – data lenght.
- Return values:
HAL_StatusTypeDef –
-
HAL_StatusTypeDef HAL_ADC_Stop_DMA(ADC_HandleTypeDef *hadc)
Stop ADC DMA transmit.
- Parameters:
hadc – ADC handle.
- Return values:
HAL_StatusTypeDef –
-
HAL_StatusTypeDef HAL_ADC_DMA_PREPARE(ADC_HandleTypeDef *hadc)
Configure adc power before start dma.
- Parameters:
hadc – ADC handle.
- Return values:
HAL_StatusTypeDef –
-
HAL_StatusTypeDef HAL_ADC_DMA_WAIT_DONE(ADC_HandleTypeDef *hadc, uint32_t timeout)
Wait ADC DMA done by polling mode.
- Parameters:
hadc – ADC handle.
timeout – wait time out in ms
- Return values:
HAL_StatusTypeDef –
-
uint32_t HAL_ADC_GetValue(ADC_HandleTypeDef *hadc, uint32_t slot)
Get ADC convert result.
- Parameters:
hadc – ADC handle.
slot – ADC slot number.
- Return values:
ADC – convert result.
-
HAL_StatusTypeDef HAL_ADC_Get_All(ADC_HandleTypeDef *hadc, uint32_t *buf)
Get all ADC data register value.
- Parameters:
hadc – ADC handle.
buf – all adc channel register value
- Return values:
HAL_StatusTypeDeft. –
-
HAL_StatusTypeDef HAL_ADC_SetSource(ADC_HandleTypeDef *hadc, HAL_ADC_SRC__T src)
Set ADC triger mode.
- Parameters:
hadc – ADC handle.
src – triger source mode.
- Return values:
HAL_StatusTypeDef. –
-
HAL_StatusTypeDef HAL_ADC_SetTimer(ADC_HandleTypeDef *hadc, HAL_ADC_SRC_TIME_T src)
set ADC timer triger mode.
- Parameters:
hadc – ADC handle.
src – timer index.
- Return values:
HAL_StatusTypeDef. –
-
HAL_StatusTypeDef HAL_ADC_EnableSlot(ADC_HandleTypeDef *hadc, uint32_t slot, uint8_t en)
Enable/Disable ADC slot/channel.
- Parameters:
hadc – ADC handle.
slot – ADC slot number.
en – enable 1 for disable 0.
- Return values:
HAL_StatusTypeDef. –
-
HAL_StatusTypeDef HAL_ADC_Set_MultiMode(ADC_HandleTypeDef *hadc, uint8_t multi_mode)
Configure use multi slots or fixed slot.
- Parameters:
hadc – ADC handle.
multi_mode – when set to 1 channels set to same slot number, when set to 0 fix use slot 0 for all channel.
- Return values:
HAL_StatusTypeDef. –
-
int HAL_ADC_Get_Offset(ADC_HandleTypeDef *hadc)
Get GPADC offset.
- Parameters:
hadc – ADC handle.
- Return values:
adc – offset.
-
HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef *hadc, ADC_ChannelConfTypeDef *sConfig)
Configures the the selected channel to be linked to the regular group.
Note
In case of usage of internal measurement channels: VrefInt/Vbat/TempSensor. Sampling time constraints must be respected (sampling time can be adjusted in function of ADC clock frequency and sampling time setting). Refer to device datasheet for timings values, parameters TS_vrefint, TS_vbat, TS_temp (values rough order: 5us to 17us). These internal paths can be be disabled using function HAL_ADC_DeInit().
Note
Possibility to update parameters on the fly: This function initializes channel into regular group, following calls to this function can be used to reconfigure some parameters of structure “ADC_ChannelConfTypeDef” on the fly, without reseting the ADC. The setting of these parameters is conditioned to ADC state. For parameters constraints, see comments of structure “ADC_ChannelConfTypeDef”.
- Parameters:
hadc – ADC handle
sConfig – Structure of ADC channel for regular group.
- Return values:
HAL – status
-
uint32_t HAL_ADC_SetFreq(ADC_HandleTypeDef *hadc, uint32_t freq)
Set ADC sampling frequency.
- Parameters:
hadc – ADC handle.
freq – frequence want to be set.
- Return values:
actual – work frequency, 0 if fail.
-
uint32_t HAL_ADC_GetState(ADC_HandleTypeDef *hadc)
Get ADC status.
- Parameters:
hadc – ADC handle.
- Return values:
current – status.
-
uint32_t HAL_ADC_GetError(ADC_HandleTypeDef *hadc)
Get ADC error code.
- Parameters:
hadc – ADC handle.
- Return values:
current – error code.
-
void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc)
Initialize the ADC MSP.
- Parameters:
hadc – pointer to a ADC_HandleTypeDef structure that contains the configuration information for ADC module.
- Return values:
None –
-
void HAL_ADC_MspDeInit(ADC_HandleTypeDef *hadc)
De-Initialize the ADC MSP.
- Parameters:
hadc – pointer to a ADC_HandleTypeDef structure that contains the configuration information for ADC module.
- Return values:
None –
-
struct ADC_InitTypeDef
- #include <bf0_hal_adc.h>
Structure definition of ADC initialization and regular group.
Note
The setting of these parameters with function HAL_ADC_Init() is conditioned to ADC state. ADC state can be either:
For all parameters: ADC disabled (this is the only possible ADC state to modify parameter ‘ClockPrescaler’)
For all parameters except ‘ClockPrescaler’ and ‘resolution’: ADC enabled without conversion on going on regular group. If ADC is not in the appropriate state to modify some parameters, these parameters setting is bypassed without error reporting (as it can be the expected behaviour in case of intended action to update another parameter (which fulfills the ADC state condition) on the fly).
-
struct ADC_ChannelConfTypeDef
- #include <bf0_hal_adc.h>
Structure definition of ADC channel for regular group.
Note
The setting of these parameters with function HAL_ADC_ConfigChannel() is conditioned to ADC state. ADC state can be either:
For all parameters: ADC disabled or enabled without conversion on going on regular group. If ADC is not in the appropriate state to modify some parameters, these parameters setting is bypassed without error reporting (as it can be the expected behaviour in case of intended action to update another parameter (which fulfills the ADC state condition) on the fly).
-
struct ADC_HandleTypeDef
- #include <bf0_hal_adc.h>
ADC handle Structure definition.
Public Members
-
GPADC_TypeDef *Instance
Register base address
-
ADC_InitTypeDef Init
ADC required parameters
-
DMA_HandleTypeDef *DMA_Handle
Pointer DMA Handler
-
HAL_LockTypeDef Lock
ADC locking object
-
uint32_t State
ADC communication state (bitmap of ADC states)
-
uint32_t ErrorCode
ADC Error code
-
GPADC_TypeDef *Instance