|
|
|
@ -30,7 +30,9 @@
@@ -30,7 +30,9 @@
|
|
|
|
|
#include <AP_HAL_ChibiOS/hwdef/common/watchdog.h> |
|
|
|
|
#include <AP_HAL_ChibiOS/I2CDevice.h> |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#ifndef HAL_PERIPH_ENABLE_GPS |
|
|
|
|
#define HAL_PERIPH_ENABLE_GPS 1 |
|
|
|
|
#endif |
|
|
|
|
extern const AP_HAL::HAL &hal; |
|
|
|
|
|
|
|
|
|
AP_Periph_FW periph; |
|
|
|
@ -97,6 +99,8 @@ void AP_Periph_FW::init()
@@ -97,6 +99,8 @@ void AP_Periph_FW::init()
|
|
|
|
|
#if !HAL_GCS_ENABLED |
|
|
|
|
hal.serial(0)->begin(AP_SERIALMANAGER_CONSOLE_BAUD, 32, 32); |
|
|
|
|
#endif |
|
|
|
|
hal.serial(1)->begin(115200, 128, 128); |
|
|
|
|
|
|
|
|
|
hal.serial(3)->begin(115200, 128, 256); |
|
|
|
|
|
|
|
|
|
load_parameters(); |
|
|
|
@ -153,66 +157,6 @@ void AP_Periph_FW::init()
@@ -153,66 +157,6 @@ void AP_Periph_FW::init()
|
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#ifdef HAL_PERIPH_ENABLE_MAG |
|
|
|
|
compass.init(); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#ifdef HAL_PERIPH_ENABLE_BARO |
|
|
|
|
baro.init(); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#ifdef HAL_PERIPH_ENABLE_BATTERY |
|
|
|
|
battery.lib.init(); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#if defined(HAL_PERIPH_NEOPIXEL_COUNT_WITHOUT_NOTIFY) || defined(HAL_PERIPH_ENABLE_RC_OUT) |
|
|
|
|
hal.rcout->init(); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#ifdef HAL_PERIPH_NEOPIXEL_CHAN_WITHOUT_NOTIFY |
|
|
|
|
hal.rcout->set_serial_led_num_LEDs(HAL_PERIPH_NEOPIXEL_CHAN_WITHOUT_NOTIFY, HAL_PERIPH_NEOPIXEL_COUNT_WITHOUT_NOTIFY, AP_HAL::RCOutput::MODE_NEOPIXEL); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#ifdef HAL_PERIPH_ENABLE_RC_OUT |
|
|
|
|
rcout_init(); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#ifdef HAL_PERIPH_ENABLE_ADSB |
|
|
|
|
adsb_init(); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#ifdef HAL_PERIPH_ENABLE_AIRSPEED |
|
|
|
|
if (airspeed.enabled()){ |
|
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS |
|
|
|
|
const bool pins_enabled = ChibiOS::I2CBus::check_select_pins(0x01); |
|
|
|
|
if (pins_enabled) { |
|
|
|
|
ChibiOS::I2CBus::set_bus_to_floating(0); |
|
|
|
|
#ifdef HAL_GPIO_PIN_LED_CAN_I2C |
|
|
|
|
palWriteLine(HAL_GPIO_PIN_LED_CAN_I2C, 1); |
|
|
|
|
#endif |
|
|
|
|
} else { |
|
|
|
|
// Note: logging of ARSPD is not enabled currently. To enable, call airspeed.set_log_bit(); here
|
|
|
|
|
airspeed.init(); |
|
|
|
|
} |
|
|
|
|
#else |
|
|
|
|
// Note: logging of ARSPD is not enabled currently. To enable, call airspeed.set_log_bit(); here
|
|
|
|
|
airspeed.init(); |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#ifdef HAL_PERIPH_ENABLE_RANGEFINDER |
|
|
|
|
if (rangefinder.get_type(0) != RangeFinder::Type::NONE && g.rangefinder_port >= 0) { |
|
|
|
|
auto *uart = hal.serial(g.rangefinder_port); |
|
|
|
|
if (uart != nullptr) { |
|
|
|
|
uart->begin(g.rangefinder_baud); |
|
|
|
|
serial_manager.set_protocol_and_baud(g.rangefinder_port, AP_SerialManager::SerialProtocol_Rangefinder, g.rangefinder_baud); |
|
|
|
|
rangefinder.init(ROTATION_NONE); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#ifdef HAL_PERIPH_ENABLE_PWM_HARDPOINT |
|
|
|
|
pwm_hardpoint_init(); |
|
|
|
|
#endif |
|
|
|
@ -237,74 +181,6 @@ void AP_Periph_FW::init()
@@ -237,74 +181,6 @@ void AP_Periph_FW::init()
|
|
|
|
|
start_ms = AP_HAL::native_millis(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#if (defined(HAL_PERIPH_NEOPIXEL_COUNT_WITHOUT_NOTIFY) && HAL_PERIPH_NEOPIXEL_COUNT_WITHOUT_NOTIFY == 8) || defined(HAL_PERIPH_ENABLE_NOTIFY) |
|
|
|
|
/*
|
|
|
|
|
rotating rainbow pattern on startup |
|
|
|
|
*/ |
|
|
|
|
void AP_Periph_FW::update_rainbow() |
|
|
|
|
{ |
|
|
|
|
#ifdef HAL_PERIPH_ENABLE_NOTIFY |
|
|
|
|
if (notify.get_led_len() != 8) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
static bool rainbow_done; |
|
|
|
|
if (rainbow_done) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
uint32_t now = AP_HAL::native_millis(); |
|
|
|
|
if (now - start_ms > 1500) { |
|
|
|
|
rainbow_done = true; |
|
|
|
|
#if defined (HAL_PERIPH_ENABLE_NOTIFY) |
|
|
|
|
periph.notify.handle_rgb(0, 0, 0); |
|
|
|
|
#elif defined(HAL_PERIPH_NEOPIXEL_CHAN_WITHOUT_NOTIFY) |
|
|
|
|
hal.rcout->set_serial_led_rgb_data(HAL_PERIPH_NEOPIXEL_CHAN_WITHOUT_NOTIFY, -1, 0, 0, 0); |
|
|
|
|
hal.rcout->serial_led_send(HAL_PERIPH_NEOPIXEL_CHAN_WITHOUT_NOTIFY); |
|
|
|
|
#endif |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
static uint32_t last_update_ms; |
|
|
|
|
const uint8_t step_ms = 30; |
|
|
|
|
if (now - last_update_ms < step_ms) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
const struct { |
|
|
|
|
uint8_t red; |
|
|
|
|
uint8_t green; |
|
|
|
|
uint8_t blue; |
|
|
|
|
} rgb_rainbow[] = { |
|
|
|
|
{ 255, 0, 0 }, |
|
|
|
|
{ 255, 127, 0 }, |
|
|
|
|
{ 255, 255, 0 }, |
|
|
|
|
{ 0, 255, 0 }, |
|
|
|
|
{ 0, 0, 255 }, |
|
|
|
|
{ 75, 0, 130 }, |
|
|
|
|
{ 143, 0, 255 }, |
|
|
|
|
{ 0, 0, 0 }, |
|
|
|
|
}; |
|
|
|
|
last_update_ms = now; |
|
|
|
|
static uint8_t step; |
|
|
|
|
const uint8_t nsteps = ARRAY_SIZE(rgb_rainbow); |
|
|
|
|
float brightness = 0.3; |
|
|
|
|
for (uint8_t n=0; n<8; n++) { |
|
|
|
|
uint8_t i = (step + n) % nsteps; |
|
|
|
|
#if defined (HAL_PERIPH_ENABLE_NOTIFY) |
|
|
|
|
periph.notify.handle_rgb( |
|
|
|
|
#elif defined(HAL_PERIPH_NEOPIXEL_CHAN_WITHOUT_NOTIFY) |
|
|
|
|
hal.rcout->set_serial_led_rgb_data(HAL_PERIPH_NEOPIXEL_CHAN_WITHOUT_NOTIFY, n, |
|
|
|
|
#endif |
|
|
|
|
rgb_rainbow[i].red*brightness, |
|
|
|
|
rgb_rainbow[i].green*brightness, |
|
|
|
|
rgb_rainbow[i].blue*brightness); |
|
|
|
|
} |
|
|
|
|
step++; |
|
|
|
|
|
|
|
|
|
#if defined(HAL_PERIPH_NEOPIXEL_CHAN_WITHOUT_NOTIFY) |
|
|
|
|
hal.rcout->serial_led_send(HAL_PERIPH_NEOPIXEL_CHAN_WITHOUT_NOTIFY); |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
#endif // HAL_PERIPH_ENABLE_NOTIFY
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS && CH_DBG_ENABLE_STACK_CHECK == TRUE |
|
|
|
|
void AP_Periph_FW::show_stack_free() |
|
|
|
@ -333,26 +209,18 @@ void AP_Periph_FW::update()
@@ -333,26 +209,18 @@ void AP_Periph_FW::update()
|
|
|
|
|
{ |
|
|
|
|
static uint32_t last_led_ms; |
|
|
|
|
uint32_t now = AP_HAL::native_millis(); |
|
|
|
|
if (now - last_led_ms > 1000) { |
|
|
|
|
if (now - last_led_ms > 500) { |
|
|
|
|
last_led_ms = now; |
|
|
|
|
hal.serial(1)->printf("update: %lu\n", now); |
|
|
|
|
|
|
|
|
|
#ifdef HAL_GPIO_PIN_LED |
|
|
|
|
if (!no_iface_finished_dna) { |
|
|
|
|
palToggleLine(HAL_GPIO_PIN_LED); |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
#if 0 |
|
|
|
|
#if 1 |
|
|
|
|
#ifdef HAL_PERIPH_ENABLE_GPS |
|
|
|
|
hal.serial(0)->printf("GPS status: %u\n", (unsigned)gps.status()); |
|
|
|
|
#endif |
|
|
|
|
#ifdef HAL_PERIPH_ENABLE_MAG |
|
|
|
|
const Vector3f &field = compass.get_field(); |
|
|
|
|
hal.serial(0)->printf("MAG (%d,%d,%d)\n", int(field.x), int(field.y), int(field.z)); |
|
|
|
|
#endif |
|
|
|
|
#ifdef HAL_PERIPH_ENABLE_BARO |
|
|
|
|
hal.serial(0)->printf("BARO H=%u P=%.2f T=%.2f\n", baro.healthy(), baro.get_pressure(), baro.get_temperature()); |
|
|
|
|
#endif |
|
|
|
|
#ifdef HAL_PERIPH_ENABLE_RANGEFINDER |
|
|
|
|
hal.serial(0)->printf("RNG %u %ucm\n", rangefinder.num_sensors(), rangefinder.distance_cm_orient(ROTATION_NONE)); |
|
|
|
|
hal.serial(1)->printf("GPS status: %u\n", (unsigned)gps.status()); |
|
|
|
|
#endif |
|
|
|
|
hal.scheduler->delay(1); |
|
|
|
|
#endif |
|
|
|
|