mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-20 21:23:35 +08:00
px4io cleanup LED and heater handling
- most px4_io-v2 boards have a blue LED that breathes for status - the pixhawk 2.1 (hex) re-used this blue LED for as an IMU heater (active low), but kept the same board id (so we have to detect at runtime) - the new cubepilot boards (yellow, orange) inverted the polarity of this heater pin - untangle the mess slightly so that things we know statically (eg cubepilot cubeorange LEDs and heater polarity) are handled at build time.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2012-2017 PX4 Development Team. All rights reserved.
|
||||
* Copyright (c) 2012-2022 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -173,18 +173,20 @@ update_mem_usage(void)
|
||||
static void
|
||||
heartbeat_blink(void)
|
||||
{
|
||||
#if defined(LED_BLUE)
|
||||
static bool heartbeat = false;
|
||||
LED_BLUE(heartbeat = !heartbeat);
|
||||
#endif /* LED_BLUE */
|
||||
}
|
||||
|
||||
static void
|
||||
ring_blink(void)
|
||||
{
|
||||
#ifdef GPIO_LED4
|
||||
#if defined(LED_GREEN)
|
||||
|
||||
if (/* IO armed */ (r_status_flags & PX4IO_P_STATUS_FLAGS_SAFETY_OFF)
|
||||
/* and FMU is armed */ && (r_setup_arming & PX4IO_P_SETUP_ARMING_FMU_ARMED)) {
|
||||
LED_RING(1);
|
||||
LED_GREEN(true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -205,7 +207,7 @@ ring_blink(void)
|
||||
// remove the ! in the line below
|
||||
// to return to the proper breathe
|
||||
// animation / pattern (currently inverted)
|
||||
LED_RING(!on);
|
||||
LED_GREEN(!on);
|
||||
brightness_counter++;
|
||||
|
||||
if (on) {
|
||||
@@ -301,11 +303,13 @@ user_start(int argc, char *argv[])
|
||||
|
||||
/* default all the LEDs to off while we start */
|
||||
LED_AMBER(false);
|
||||
#if defined(LED_BLUE)
|
||||
LED_BLUE(false);
|
||||
#endif /* LED_BLUE */
|
||||
LED_SAFETY(false);
|
||||
#ifdef GPIO_LED4
|
||||
LED_RING(false);
|
||||
#endif
|
||||
#if defined(LED_GREEN)
|
||||
LED_GREEN(false);
|
||||
#endif /* LED_GREEN */
|
||||
|
||||
/* turn off S.Bus out (if supported) */
|
||||
#ifdef ENABLE_SBUS_OUT
|
||||
@@ -377,34 +381,35 @@ user_start(int argc, char *argv[])
|
||||
perf_end(controls_perf);
|
||||
#endif
|
||||
|
||||
/* some boards such as Pixhawk 2.1 made
|
||||
the unfortunate choice to combine the blue led channel with
|
||||
the IMU heater. We need a software hack to fix the hardware hack
|
||||
by allowing to disable the LED / heater.
|
||||
*/
|
||||
if (r_page_setup[PX4IO_P_SETUP_THERMAL] == PX4IO_THERMAL_IGNORE) {
|
||||
/*
|
||||
blink blue LED at 4Hz in normal operation. When in
|
||||
override blink 4x faster so the user can clearly see
|
||||
that override is happening. This helps when
|
||||
pre-flight testing the override system
|
||||
*/
|
||||
uint32_t heartbeat_period_us = 250 * 1000UL;
|
||||
|
||||
if ((hrt_absolute_time() - last_heartbeat_time) > heartbeat_period_us) {
|
||||
last_heartbeat_time = hrt_absolute_time();
|
||||
heartbeat_blink();
|
||||
}
|
||||
/*
|
||||
blink blue LED at 4Hz in normal operation. When in
|
||||
override blink 4x faster so the user can clearly see
|
||||
that override is happening. This helps when
|
||||
pre-flight testing the override system
|
||||
*/
|
||||
uint32_t heartbeat_period_us = 250 * 1000UL;
|
||||
|
||||
} else if (r_page_setup[PX4IO_P_SETUP_THERMAL] < PX4IO_THERMAL_FULL) {
|
||||
/* switch resistive heater off */
|
||||
LED_BLUE(false);
|
||||
|
||||
} else {
|
||||
/* switch resistive heater hard on */
|
||||
LED_BLUE(true);
|
||||
if ((hrt_absolute_time() - last_heartbeat_time) > heartbeat_period_us) {
|
||||
last_heartbeat_time = hrt_absolute_time();
|
||||
heartbeat_blink();
|
||||
}
|
||||
|
||||
#if defined(HEATER_OUTPUT_EN)
|
||||
|
||||
if (r_page_setup[PX4IO_P_SETUP_THERMAL] != PX4IO_THERMAL_IGNORE) {
|
||||
if (r_page_setup[PX4IO_P_SETUP_THERMAL] < PX4IO_THERMAL_FULL) {
|
||||
/* switch resistive heater off */
|
||||
HEATER_OUTPUT_EN(false);
|
||||
|
||||
} else {
|
||||
/* switch resistive heater hard on */
|
||||
HEATER_OUTPUT_EN(true);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* HEATER_OUTPUT_EN */
|
||||
|
||||
update_mem_usage();
|
||||
|
||||
ring_blink();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2012-2017 PX4 Development Team. All rights reserved.
|
||||
* Copyright (c) 2012-2022 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -123,20 +123,6 @@ extern struct sys_state_s system_state;
|
||||
extern bool update_mc_thrust_param;
|
||||
extern bool update_trims;
|
||||
|
||||
/*
|
||||
* GPIO handling.
|
||||
*/
|
||||
/* HEX Cube Orange and Cube Yellow uses an inverted signal to control the IMU heater */
|
||||
#ifdef CONFIG_ARCH_BOARD_CUBEPILOT_IO_V2
|
||||
#define LED_BLUE(_s) px4_arch_gpiowrite(GPIO_LED1, (_s))
|
||||
#else
|
||||
#define LED_BLUE(_s) px4_arch_gpiowrite(GPIO_LED1, !(_s))
|
||||
#endif
|
||||
#define LED_AMBER(_s) px4_arch_gpiowrite(GPIO_LED2, !(_s))
|
||||
#define LED_SAFETY(_s) px4_arch_gpiowrite(GPIO_LED3, !(_s))
|
||||
#define LED_RING(_s) px4_arch_gpiowrite(GPIO_LED4, (_s))
|
||||
|
||||
|
||||
# define ENABLE_SBUS_OUT(_s) px4_arch_gpiowrite(GPIO_SBUS_OENABLE, !(_s))
|
||||
|
||||
# define VDD_SERVO_FAULT (!px4_arch_gpioread(GPIO_SERVO_FAULT_DETECT))
|
||||
|
||||
Reference in New Issue
Block a user