2012-08-04 19:12:36 -03:00
|
|
|
/****************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 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
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name PX4 nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-12-29 20:01:24 -04:00
|
|
|
/**
|
|
|
|
* @file px4io.h
|
|
|
|
*
|
|
|
|
* General defines and structures for the PX4IO module firmware.
|
|
|
|
*/
|
2012-08-04 19:12:36 -03:00
|
|
|
|
2012-11-02 03:42:36 -03:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include <drivers/boards/px4io/px4io_internal.h>
|
|
|
|
|
2012-08-04 19:12:36 -03:00
|
|
|
#include "protocol.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Constants and limits.
|
|
|
|
*/
|
|
|
|
#define MAX_CONTROL_CHANNELS 12
|
|
|
|
#define IO_SERVO_COUNT 8
|
|
|
|
|
2012-11-04 20:44:36 -04:00
|
|
|
/*
|
|
|
|
* Debug logging
|
|
|
|
*/
|
|
|
|
|
2012-11-29 04:33:44 -04:00
|
|
|
#ifdef DEBUG
|
|
|
|
# include <debug.h>
|
|
|
|
# define debug(fmt, args...) lib_lowprintf(fmt "\n", ##args)
|
2012-11-04 20:44:36 -04:00
|
|
|
#else
|
2012-11-29 04:33:44 -04:00
|
|
|
# define debug(fmt, args...) do {} while(0)
|
2012-11-04 20:44:36 -04:00
|
|
|
#endif
|
|
|
|
|
2012-08-04 19:12:36 -03:00
|
|
|
/*
|
|
|
|
* System state structure.
|
|
|
|
*/
|
2012-12-29 20:01:24 -04:00
|
|
|
struct sys_state_s {
|
2012-08-04 19:12:36 -03:00
|
|
|
|
2012-12-04 03:20:28 -04:00
|
|
|
bool armed; /* IO armed */
|
|
|
|
bool arm_ok; /* FMU says OK to arm */
|
2012-12-13 05:23:02 -04:00
|
|
|
uint16_t servo_rate; /* output rate of servos in Hz */
|
2012-11-30 09:57:54 -04:00
|
|
|
|
2013-01-05 17:13:12 -04:00
|
|
|
/**
|
|
|
|
* Remote control input(s) channel mappings
|
|
|
|
*/
|
2013-01-06 09:43:37 -04:00
|
|
|
uint8_t rc_map[4];
|
2013-01-05 17:13:12 -04:00
|
|
|
|
|
|
|
/**
|
2013-01-11 02:44:17 -04:00
|
|
|
* Remote control channel attributes
|
2013-01-05 17:13:12 -04:00
|
|
|
*/
|
|
|
|
uint16_t rc_min[4];
|
|
|
|
uint16_t rc_trim[4];
|
|
|
|
uint16_t rc_max[4];
|
2013-01-06 09:43:37 -04:00
|
|
|
int16_t rc_rev[4];
|
2013-01-05 17:13:12 -04:00
|
|
|
uint16_t rc_dz[4];
|
2013-01-05 23:21:04 -04:00
|
|
|
|
2012-12-01 11:30:21 -04:00
|
|
|
/**
|
2012-08-04 19:12:36 -03:00
|
|
|
* Data from the remote control input(s)
|
|
|
|
*/
|
2012-12-05 02:00:24 -04:00
|
|
|
unsigned rc_channels;
|
2012-08-04 19:12:36 -03:00
|
|
|
uint16_t rc_channel_data[PX4IO_INPUT_CHANNELS];
|
2012-11-30 09:57:54 -04:00
|
|
|
uint64_t rc_channels_timestamp;
|
2012-08-04 19:12:36 -03:00
|
|
|
|
2012-12-01 11:30:21 -04:00
|
|
|
/**
|
2012-08-04 19:12:36 -03:00
|
|
|
* Control signals from FMU.
|
|
|
|
*/
|
2012-12-29 21:15:48 -04:00
|
|
|
uint16_t fmu_channel_data[PX4IO_CONTROL_CHANNELS];
|
2012-08-04 19:12:36 -03:00
|
|
|
|
2012-12-30 05:03:05 -04:00
|
|
|
/**
|
2012-12-29 16:58:41 -04:00
|
|
|
* Mixed servo outputs
|
|
|
|
*/
|
|
|
|
uint16_t servos[IO_SERVO_COUNT];
|
|
|
|
|
2012-12-01 11:30:21 -04:00
|
|
|
/**
|
2012-08-04 19:12:36 -03:00
|
|
|
* Relay controls
|
|
|
|
*/
|
|
|
|
bool relays[PX4IO_RELAY_CHANNELS];
|
|
|
|
|
2012-12-01 11:30:21 -04:00
|
|
|
/**
|
|
|
|
* If true, we are using the FMU controls, else RC input if available.
|
2012-08-04 19:12:36 -03:00
|
|
|
*/
|
2012-12-13 05:23:02 -04:00
|
|
|
bool mixer_manual_override;
|
2012-08-04 19:12:36 -03:00
|
|
|
|
2012-12-01 11:30:21 -04:00
|
|
|
/**
|
|
|
|
* If true, FMU input is available.
|
|
|
|
*/
|
|
|
|
bool mixer_fmu_available;
|
|
|
|
|
|
|
|
/**
|
2012-08-04 19:12:36 -03:00
|
|
|
* If true, state that should be reported to FMU has been updated.
|
|
|
|
*/
|
|
|
|
bool fmu_report_due;
|
|
|
|
|
2012-12-01 11:30:21 -04:00
|
|
|
/**
|
2012-12-15 18:28:03 -04:00
|
|
|
* Last FMU receive time, in microseconds since system boot
|
2012-08-04 19:12:36 -03:00
|
|
|
*/
|
2012-12-15 18:28:03 -04:00
|
|
|
uint64_t fmu_data_received_time;
|
2012-11-05 04:55:22 -04:00
|
|
|
|
2012-12-01 11:30:21 -04:00
|
|
|
/**
|
2012-11-05 04:55:22 -04:00
|
|
|
* Current serial interface mode, per the serial_rx_mode parameter
|
|
|
|
* in the config packet.
|
|
|
|
*/
|
|
|
|
uint8_t serial_rx_mode;
|
2012-12-01 11:30:21 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If true, the RC signal has been lost for more than a timeout interval
|
|
|
|
*/
|
|
|
|
bool rc_lost;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If true, the connection to FMU has been lost for more than a timeout interval
|
|
|
|
*/
|
|
|
|
bool fmu_lost;
|
2012-12-13 05:23:02 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If true, FMU is ready for autonomous position control. Only used for LED indication
|
|
|
|
*/
|
|
|
|
bool vector_flight_mode_ok;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If true, IO performs an on-board manual override with the RC channel values
|
|
|
|
*/
|
|
|
|
bool manual_override_ok;
|
2012-11-05 04:55:22 -04:00
|
|
|
|
|
|
|
/*
|
2013-01-01 01:06:26 -04:00
|
|
|
* Measured battery voltage in mV
|
2012-11-05 04:55:22 -04:00
|
|
|
*/
|
2013-01-01 01:06:26 -04:00
|
|
|
uint16_t battery_mv;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ADC IN5 measurement
|
|
|
|
*/
|
|
|
|
uint16_t adc_in5;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Power supply overcurrent status bits.
|
|
|
|
*/
|
|
|
|
uint8_t overcurrent;
|
|
|
|
|
2012-08-04 19:12:36 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
extern struct sys_state_s system_state;
|
|
|
|
|
2013-01-01 01:06:26 -04:00
|
|
|
#if 0
|
2012-08-04 19:12:36 -03:00
|
|
|
/*
|
|
|
|
* Software countdown timers.
|
|
|
|
*
|
|
|
|
* Each timer counts down to zero at one tick per ms.
|
|
|
|
*/
|
|
|
|
#define TIMER_BLINK_AMBER 0
|
|
|
|
#define TIMER_BLINK_BLUE 1
|
|
|
|
#define TIMER_STATUS_PRINT 2
|
|
|
|
#define TIMER_SANITY 7
|
|
|
|
#define TIMER_NUM_TIMERS 8
|
|
|
|
extern volatile int timers[TIMER_NUM_TIMERS];
|
2013-01-01 01:06:26 -04:00
|
|
|
#endif
|
2012-08-04 19:12:36 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* GPIO handling.
|
|
|
|
*/
|
2012-11-05 04:54:08 -04:00
|
|
|
#define LED_BLUE(_s) stm32_gpiowrite(GPIO_LED1, !(_s))
|
|
|
|
#define LED_AMBER(_s) stm32_gpiowrite(GPIO_LED2, !(_s))
|
2012-11-02 03:42:36 -03:00
|
|
|
#define LED_SAFETY(_s) stm32_gpiowrite(GPIO_LED3, !(_s))
|
|
|
|
|
|
|
|
#define POWER_SERVO(_s) stm32_gpiowrite(GPIO_SERVO_PWR_EN, (_s))
|
2012-12-28 15:19:47 -04:00
|
|
|
#define POWER_ACC1(_s) stm32_gpiowrite(GPIO_ACC1_PWR_EN, (_s))
|
|
|
|
#define POWER_ACC2(_s) stm32_gpiowrite(GPIO_ACC2_PWR_EN, (_s))
|
2012-11-02 03:42:36 -03:00
|
|
|
#define POWER_RELAY1(_s) stm32_gpiowrite(GPIO_RELAY1_EN, (_s))
|
|
|
|
#define POWER_RELAY2(_s) stm32_gpiowrite(GPIO_RELAY2_EN, (_s))
|
|
|
|
|
2013-01-01 01:06:26 -04:00
|
|
|
#define OVERCURRENT_ACC (!stm32_gpioread(GPIO_ACC_OC_DETECT))
|
|
|
|
#define OVERCURRENT_SERVO (!stm32_gpioread(GPIO_SERVO_OC_DETECT))
|
2012-11-02 03:42:36 -03:00
|
|
|
#define BUTTON_SAFETY stm32_gpioread(GPIO_BTN_SAFETY)
|
2012-08-04 19:12:36 -03:00
|
|
|
|
2013-01-01 01:06:26 -04:00
|
|
|
#define ADC_VBATT 4
|
|
|
|
#define ADC_IN5 5
|
|
|
|
|
2012-08-04 19:12:36 -03:00
|
|
|
/*
|
|
|
|
* Mixer
|
|
|
|
*/
|
2012-11-30 04:02:47 -04:00
|
|
|
extern void mixer_tick(void);
|
2012-12-29 16:58:41 -04:00
|
|
|
extern void mixer_handle_text(const void *buffer, size_t length);
|
2012-08-04 19:12:36 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Safety switch/LED.
|
|
|
|
*/
|
|
|
|
extern void safety_init(void);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FMU communications
|
|
|
|
*/
|
2012-11-30 04:02:47 -04:00
|
|
|
extern void comms_main(void) __attribute__((noreturn));
|
2012-08-04 19:12:36 -03:00
|
|
|
|
2012-12-31 23:41:18 -04:00
|
|
|
/*
|
|
|
|
* Sensors/misc inputs
|
|
|
|
*/
|
|
|
|
extern int adc_init(void);
|
|
|
|
extern uint16_t adc_measure(unsigned channel);
|
|
|
|
|
2012-11-07 18:56:03 -04:00
|
|
|
/*
|
2012-11-30 04:02:47 -04:00
|
|
|
* R/C receiver handling.
|
2012-11-07 18:56:03 -04:00
|
|
|
*/
|
2012-11-30 04:02:47 -04:00
|
|
|
extern void controls_main(void);
|
|
|
|
extern int dsm_init(const char *device);
|
2012-12-04 13:52:16 -04:00
|
|
|
extern bool dsm_input(void);
|
2012-11-30 04:02:47 -04:00
|
|
|
extern int sbus_init(const char *device);
|
2013-01-06 05:13:53 -04:00
|
|
|
extern bool sbus_input(void);
|
2012-11-07 18:56:03 -04:00
|
|
|
|
2012-08-04 19:12:36 -03:00
|
|
|
/*
|
|
|
|
* Assertion codes
|
|
|
|
*/
|
|
|
|
#define A_GPIO_OPEN_FAIL 100
|
|
|
|
#define A_SERVO_OPEN_FAIL 101
|
|
|
|
#define A_INPUTQ_OPEN_FAIL 102
|