bf0_hal_adc.h
Header file containing functions prototypes of ADC HAL library.
- Author
Sifli software development team
- Attention
Defines
-
HAL_ADC_STATE_RESET
HAL ADC state machine: ADC states definition (bitfields)
备注
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.
- 参数:
__HANDLE__ – ADC handle
__FLAG__ – ADC flag
- 返回值:
None –
-
__HAL_ADC_CLEAR_FLAG(__HANDLE__, __FLAG__)
Clear the ADC’s pending flags.
- 参数:
__HANDLE__ – ADC handle
__FLAG__ – ADC flag
- 返回值:
None –
-
__HAL_ADC_ENABLE_IRQ(__HANDLE__, __FLAG__)
Enable ADC irq.
- 参数:
__HANDLE__ – ADC handle
__FLAG__ – ADC irq flag
- 返回值:
None –
-
__HAL_ADC_DISABLE_IRQ(__HANDLE__, __FLAG__)
Disable ADC irq.
- 参数:
__HANDLE__ – ADC handle
__FLAG__ – ADC irq flag
- 返回值:
None –
-
__HAL_ADC_ENABLE_LDO_REF(__HANDLE__)
Enable ADC LdoRef.
- 参数:
__HANDLE__ – ADC handle
- 返回值:
None –
-
__HAL_ADC_DISABLE_LDO_REF(__HANDLE__)
Disable ADC LdoRef.
- 参数:
__HANDLE__ – ADC handle
- 返回值:
None –
-
__HAL_ADC_SET_LDO_REF_SEL(__HANDLE__, value)
Set ADC LdoRef Sel.
- 参数:
__HANDLE__ – ADC handle
LdoRef – Sel Value.
- 返回值:
None –
-
__HAL_ADC_RESET_HANDLE_STATE(__HANDLE__)
Reset ADC handle state.
- 参数:
__HANDLE__ – ADC handle
- 返回值:
None –
-
__HAL_ADC_SET_CLOCK_DIV(__HANDLE__, div)
Set ADC clock divider.
- 参数:
__HANDLE__ – ADC handle
div – Clock divider
- 返回值:
None –
-
__HAL_ADC_START_CONV(__HANDLE__)
Start ADC convert.
- 参数:
__HANDLE__ – ADC handle
- 返回值:
None –
-
__HAL_ADC_STOP_CONV(__HANDLE__)
Stop ADC convert, only work for infinite mode.
- 参数:
__HANDLE__ – ADC handle
- 返回值:
None –
-
__HAL_ADC_SINGLE_END(__HANDLE__)
Set ADC to single end mode.
- 参数:
__HANDLE__ – ADC handle
- 返回值:
None –
-
__HAL_ADC_DIFF_MODE(__HANDLE__)
Set ADC to differential mode.
- 参数:
__HANDLE__ – ADC handle
- 返回值:
None –
-
ADC_IS_ENABLE(__HANDLE__)
Verification of ADC state: enabled or disabled.
- 参数:
__HANDLE__ – ADC handle
- 返回值:
SET – (ADC enabled) or RESET (ADC disabled)
-
ADC_STATE_CLR_SET
Simultaneously clears and sets specific bits of the handle State.
备注
: 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.
- 返回值:
None –
-
ADC_CLEAR_ERRORCODE(__HANDLE__)
Clear ADC error code (set it to error code: “no error”)
- 参数:
__HANDLE__ – ADC handle
- 返回值:
None –
-
ADC_CHSELR_CHANNEL(_CHANNEL_)
Configure the channel number into channel selection register.
- 参数:
_CHANNEL_ – ADC Channel
- 返回值:
None –
-
ADC_CFGR_CONTINUOUS(__HANDLE__, _CONTINUOUS_MODE_)
Enable ADC continuous conversion mode.
- 参数:
__HANDLE__ – ADC handle.
_CONTINUOUS_MODE_ – Continuous mode.
- 返回值:
None –
-
ADC_CFGR_DMACONTREQ(_DMACONTREQ_MODE_)
Enable the ADC DMA continuous request.
- 参数:
_DMACONTREQ_MODE_ – DMA continuous request mode.
- 返回值:
None –
-
ADC_DMA_ENABLE(__HANDLE__)
Enable ADC DMA mode.
- 参数:
__HANDLE__ – ADC handle.
- 返回值:
None –
-
ADC_DMA_RAW_DATA(__HANDLE__)
ADC DMA output raw data.
- 参数:
__HANDLE__ – ADC handle.
- 返回值:
None –
-
ADC_DMA_COMB_DATA(__HANDLE__)
ADC DMA output combined data.
- 参数:
__HANDLE__ – ADC handle.
- 返回值:
None –
-
ADC_DMA_DISABLE(__HANDLE__)
Disable ADC DMA mode.
- 参数:
__HANDLE__ – ADC handle.
- 返回值:
None –
-
IS_ADC_SRC_TIMER(__HANDLE__)
Check if timer triger enable.
- 参数:
__HANDLE__ – ADC handle.
- 返回值:
Not – 0 if timer triger enable
-
ADC_ENABLE_TIMER_TRIGER(__HANDLE__)
Enable timer triger.
- 参数:
__HANDLE__ – ADC handle.
- 返回值:
None –
-
ADC_DISABLE_TIMER_TRIGER(__HANDLE__)
Enable timer triger.
- 参数:
__HANDLE__ – ADC handle.
- 返回值:
None –
-
ADC_ENABLE_GPIO_TRIGER(__HANDLE__)
Enable GPIO triger.
- 参数:
__HANDLE__ – ADC handle.
- 返回值:
None –
-
ADC_DISABLE_GPIO_TRIGER(__HANDLE__)
Enable GPIO triger.
- 参数:
__HANDLE__ – ADC handle.
- 返回值:
None –
-
ADC_TIMER_TRIGER_LEVEL(__HANDLE__)
ADC TIMER triger with level mode, need edge detect.
- 参数:
__HANDLE__ – ADC handle.
- 返回值:
None –
-
ADC_TIMER_TRIGER_PULSE(__HANDLE__)
ADC TIMER triger with pulse mode, no edge detect.
- 参数:
__HANDLE__ – ADC handle.
- 返回值:
None –
-
ADC_FRC_EN(__HANDLE__)
Manual open ADC power.
- 参数:
__HANDLE__ – ADC handle.
- 返回值:
None –
-
ADC_CLR_FRC_EN(__HANDLE__)
AUTO open ADC power.
- 参数:
__HANDLE__ – ADC handle.
- 返回值:
None –
-
ADC_CHNL_SEL_FRC_EN(__HANDLE__)
Use auto chnel selet in configure register.
- 参数:
__HANDLE__ – ADC handle.
- 返回值:
None –
-
ADC_CHNL_CLR_FRC_EN(__HANDLE__)
Disable channel auto select.
- 参数:
__HANDLE__ – ADC handle.
- 返回值:
None –
-
ADC_SET_MUTE(__HANDLE__)
Set ADC mute.
- 参数:
__HANDLE__ – ADC handle.
- 返回值:
None –
-
ADC_SET_UNMUTE(__HANDLE__)
Set ADC unmute.
- 参数:
__HANDLE__ – ADC handle.
- 返回值:
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.
备注
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”.
备注
As prerequisite, ADC clock must be configured at RCC top level depending on both possible clock sources: APB clock of HSI clock.
备注
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”.
备注
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”.
- 参数:
hadc – ADC handle
- 返回值:
HAL – status
-
HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef *hadc)
Deinitial ADC hardware.
- 参数:
hadc – ADC handle.
- 返回值:
HAL_StatusTypeDef –
-
HAL_StatusTypeDef HAL_ADC_Prepare(ADC_HandleTypeDef *hadc)
Prepare ADC setting before start triger.
- 参数:
hadc – ADC handle
- 返回值:
HAL – status
-
HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef *hadc)
Enables ADC, starts conversion of regular group. Interruptions enabled in this function: None.
- 参数:
hadc – ADC handle
- 返回值:
HAL – status
-
HAL_StatusTypeDef HAL_ADC_Stop(ADC_HandleTypeDef *hadc)
Stop ADC conversion of regular group, disable ADC peripheral.
- 参数:
hadc – ADC handle
- 返回值:
HAL – status.
-
HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef *hadc, uint32_t Timeout)
Wait for regular group conversion to be completed.
- 参数:
hadc – ADC handle
Timeout – Timeout value in millisecond.
- 返回值:
HAL – status
-
HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef *hadc)
Start ADC with IRQ mode.
- 参数:
hadc – ADC handle.
- 返回值:
HAL_StatusTypeDef –
-
HAL_StatusTypeDef HAL_ADC_Stop_IT(ADC_HandleTypeDef *hadc)
Stop ADC irq mode.
- 参数:
hadc – ADC handle.
- 返回值:
HAL_StatusTypeDef –
-
HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef *hadc, uint32_t *pData, uint32_t Length)
start ADC convert with dma mode.
- 参数:
hadc – ADC handle.
pData – data buffer.
Length – data lenght.
- 返回值:
HAL_StatusTypeDef –
-
HAL_StatusTypeDef HAL_ADC_Stop_DMA(ADC_HandleTypeDef *hadc)
Stop ADC DMA transmit.
- 参数:
hadc – ADC handle.
- 返回值:
HAL_StatusTypeDef –
-
HAL_StatusTypeDef HAL_ADC_DMA_PREPARE(ADC_HandleTypeDef *hadc)
Configure adc power before start dma.
- 参数:
hadc – ADC handle.
- 返回值:
HAL_StatusTypeDef –
-
HAL_StatusTypeDef HAL_ADC_DMA_WAIT_DONE(ADC_HandleTypeDef *hadc, uint32_t timeout)
Wait ADC DMA done by polling mode.
- 参数:
hadc – ADC handle.
timeout – wait time out in ms
- 返回值:
HAL_StatusTypeDef –
-
uint32_t HAL_ADC_GetValue(ADC_HandleTypeDef *hadc, uint32_t slot)
Get ADC convert result.
- 参数:
hadc – ADC handle.
slot – ADC slot number.
- 返回值:
ADC – convert result.
-
HAL_StatusTypeDef HAL_ADC_Get_All(ADC_HandleTypeDef *hadc, uint32_t *buf)
Get all ADC data register value.
- 参数:
hadc – ADC handle.
buf – all adc channel register value
- 返回值:
HAL_StatusTypeDeft. –
-
HAL_StatusTypeDef HAL_ADC_SetSource(ADC_HandleTypeDef *hadc, HAL_ADC_SRC__T src)
Set ADC triger mode.
- 参数:
hadc – ADC handle.
src – triger source mode.
- 返回值:
HAL_StatusTypeDef. –
-
HAL_StatusTypeDef HAL_ADC_SetTimer(ADC_HandleTypeDef *hadc, HAL_ADC_SRC_TIME_T src)
set ADC timer triger mode.
- 参数:
hadc – ADC handle.
src – timer index.
- 返回值:
HAL_StatusTypeDef. –
-
HAL_StatusTypeDef HAL_ADC_EnableSlot(ADC_HandleTypeDef *hadc, uint32_t slot, uint8_t en)
Enable/Disable ADC slot/channel.
- 参数:
hadc – ADC handle.
slot – ADC slot number.
en – enable 1 for disable 0.
- 返回值:
HAL_StatusTypeDef. –
-
HAL_StatusTypeDef HAL_ADC_Set_MultiMode(ADC_HandleTypeDef *hadc, uint8_t multi_mode)
Configure use multi slots or fixed slot.
- 参数:
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.
- 返回值:
HAL_StatusTypeDef. –
-
int HAL_ADC_Get_Offset(ADC_HandleTypeDef *hadc)
Get GPADC offset.
- 参数:
hadc – ADC handle.
- 返回值:
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.
备注
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().
备注
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”.
- 参数:
hadc – ADC handle
sConfig – Structure of ADC channel for regular group.
- 返回值:
HAL – status
-
uint32_t HAL_ADC_SetFreq(ADC_HandleTypeDef *hadc, uint32_t freq)
Set ADC sampling frequency.
- 参数:
hadc – ADC handle.
freq – frequence want to be set.
- 返回值:
actual – work frequency, 0 if fail.
-
uint32_t HAL_ADC_GetState(ADC_HandleTypeDef *hadc)
Get ADC status.
- 参数:
hadc – ADC handle.
- 返回值:
current – status.
-
uint32_t HAL_ADC_GetError(ADC_HandleTypeDef *hadc)
Get ADC error code.
- 参数:
hadc – ADC handle.
- 返回值:
current – error code.
-
void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc)
Initialize the ADC MSP.
- 参数:
hadc – pointer to a ADC_HandleTypeDef structure that contains the configuration information for ADC module.
- 返回值:
None –
-
void HAL_ADC_MspDeInit(ADC_HandleTypeDef *hadc)
De-Initialize the ADC MSP.
- 参数:
hadc – pointer to a ADC_HandleTypeDef structure that contains the configuration information for ADC module.
- 返回值:
None –
-
struct ADC_InitTypeDef
- #include <bf0_hal_adc.h>
Structure definition of ADC initialization and regular group.
备注
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.
备注
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