mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-24 10:43:34 +08:00
adc:Add that ability to select an ADC
This commit is contained in:
committed by
Daniel Agar
parent
0ebb87357f
commit
890f805b37
@@ -196,6 +196,30 @@
|
||||
# error Unsuported BOARD_NUMBER_BRICKS number.
|
||||
#endif
|
||||
|
||||
/* Historically PX4 used one ADC1 With FMUvnX this has changes.
|
||||
* These defines maintain compatibility while allowing the
|
||||
* new boards to override the ADC used from HW VER/REV and
|
||||
* the system one.
|
||||
*
|
||||
* Depending on HW configuration (VER/REV POP options) hardware detection
|
||||
* may or may NOT initialize a given ADC. SYSTEM_ADC_COUNT is used to size the
|
||||
* singleton array to ensure this is only done once per ADC.
|
||||
*/
|
||||
|
||||
#if !defined(HW_REV_VER_ADC_BASE)
|
||||
# define HW_REV_VER_ADC_BASE STM32_ADC1_BASE
|
||||
#endif
|
||||
|
||||
#if !defined(SYSTEM_ADC_BASE)
|
||||
# define SYSTEM_ADC_BASE STM32_ADC1_BASE
|
||||
#endif
|
||||
|
||||
#if SYSTEM_ADC_BASE == HW_REV_VER_ADC_BASE
|
||||
# define SYSTEM_ADC_COUNT 1
|
||||
#else
|
||||
# define SYSTEM_ADC_COUNT 2
|
||||
#endif
|
||||
|
||||
/* Choose the source for ADC_SCALED_V5_SENSE */
|
||||
#if defined(ADC_5V_RAIL_SENSE)
|
||||
#define ADC_SCALED_V5_SENSE ADC_5V_RAIL_SENSE
|
||||
|
||||
@@ -52,14 +52,14 @@
|
||||
* boards may provide this function to allow complex version-ing.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None.
|
||||
* base_address - base address of the ADC
|
||||
*
|
||||
* Returned Value:
|
||||
*
|
||||
* OK, or -1 if the function failed.
|
||||
*/
|
||||
|
||||
__EXPORT int board_adc_init(void);
|
||||
__EXPORT int board_adc_init(uint32_t base_address);
|
||||
|
||||
/************************************************************************************
|
||||
* Name: board_adc_sample
|
||||
@@ -68,14 +68,15 @@ __EXPORT int board_adc_init(void);
|
||||
* boards provide this function to allow complex version-ing.
|
||||
*
|
||||
* Input Parameters:
|
||||
* channel - The number of the adc channel to read.
|
||||
* base_address - base address of the ADC
|
||||
* channel - The number of the adc channel to read.
|
||||
*
|
||||
* Returned Value:
|
||||
* The ADC DN read for the channel or 0xffff if there
|
||||
* is an error reading the channel.
|
||||
*/
|
||||
|
||||
__EXPORT uint16_t board_adc_sample(unsigned channel);
|
||||
__EXPORT uint16_t board_adc_sample(uint32_t base_address, unsigned channel);
|
||||
|
||||
|
||||
/************************************************************************************
|
||||
|
||||
@@ -199,11 +199,11 @@ static int read_id_dn(int *id, uint32_t gpio_drive, uint32_t gpio_sense, int adc
|
||||
|
||||
/* Yes - Fire up the ADC (it has once control) */
|
||||
|
||||
if (board_adc_init() == OK) {
|
||||
if (board_adc_init(HW_REV_VER_ADC_BASE) == OK) {
|
||||
|
||||
/* Read the value */
|
||||
for (unsigned av = 0; av < samples; av++) {
|
||||
dn = board_adc_sample(adc_channel);
|
||||
dn = board_adc_sample(HW_REV_VER_ADC_BASE, adc_channel);
|
||||
|
||||
if (dn == 0xffff) {
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user