mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-07 09:13:32 +08:00
Simplify ADC driver
This commit is contained in:
@@ -314,7 +314,9 @@ ADC::_tick()
|
||||
void
|
||||
ADC::update_system_power(void)
|
||||
{
|
||||
#if defined (CONFIG_ARCH_BOARD_PX4FMU_V2) || defined (CONFIG_ARCH_BOARD_MINDPX_V2)
|
||||
#if defined (CONFIG_ARCH_BOARD_PX4FMU_V2) || \
|
||||
defined (CONFIG_ARCH_BOARD_MINDPX_V2) || \
|
||||
defined (CONFIG_ARCH_BOARD_PX4FMU_V4)
|
||||
system_power_s system_power = {};
|
||||
system_power.timestamp = hrt_absolute_time();
|
||||
|
||||
@@ -339,6 +341,14 @@ ADC::update_system_power(void)
|
||||
// OC pins are active low
|
||||
system_power.periph_5V_OC = 1;
|
||||
system_power.hipower_5V_OC = 1;
|
||||
#elif defined (CONFIG_ARCH_BOARD_PX4FMU_V4)
|
||||
// note that the valid pins are active high
|
||||
system_power.brick_valid = stm32_gpioread(GPIO_VDD_BRICK_VALID);
|
||||
system_power.servo_valid = 1;
|
||||
|
||||
// OC pins are not supported
|
||||
system_power.periph_5V_OC = 0;
|
||||
system_power.hipower_5V_OC = 0;
|
||||
#else
|
||||
// note that the valid pins are active low
|
||||
system_power.brick_valid = !stm32_gpioread(GPIO_VDD_BRICK_VALID);
|
||||
@@ -358,40 +368,6 @@ ADC::update_system_power(void)
|
||||
}
|
||||
|
||||
#endif // CONFIG_ARCH_BOARD_PX4FMU_V2
|
||||
#ifdef CONFIG_ARCH_BOARD_PX4FMU_V4
|
||||
system_power_s system_power = {};
|
||||
system_power.timestamp = hrt_absolute_time();
|
||||
|
||||
system_power.voltage5V_v = 0;
|
||||
|
||||
for (unsigned i = 0; i < _channel_count; i++) {
|
||||
if (_samples[i].am_channel == ADC_5V_RAIL_SENSE) {
|
||||
// it is 2:1 scaled
|
||||
system_power.voltage5V_v = _samples[i].am_data * (6.6f / 4096);
|
||||
}
|
||||
}
|
||||
|
||||
// these are not ADC related, but it is convenient to
|
||||
// publish these to the same topic
|
||||
system_power.usb_connected = stm32_gpioread(GPIO_OTGFS_VBUS);
|
||||
|
||||
// note that the valid pins are active High
|
||||
system_power.brick_valid = stm32_gpioread(GPIO_VDD_BRICK_VALID);
|
||||
system_power.servo_valid = 1;
|
||||
|
||||
// OC pins are not supported
|
||||
system_power.periph_5V_OC = 0;
|
||||
system_power.hipower_5V_OC = 0;
|
||||
|
||||
/* lazily publish */
|
||||
if (_to_system_power != nullptr) {
|
||||
orb_publish(ORB_ID(system_power), _to_system_power, &system_power);
|
||||
|
||||
} else {
|
||||
_to_system_power = orb_advertise(ORB_ID(system_power), &system_power);
|
||||
}
|
||||
|
||||
#endif // CONFIG_ARCH_BOARD_PX4FMU_V4
|
||||
}
|
||||
|
||||
uint16_t
|
||||
|
||||
Reference in New Issue
Block a user