2019-03-22 23:32:56 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <AP_Common/AP_Common.h>
|
2023-06-17 19:26:56 -03:00
|
|
|
|
2018-05-10 21:37:01 -03:00
|
|
|
/*
|
|
|
|
common protocol definitions between AP_IOMCU and iofirmware
|
|
|
|
*/
|
|
|
|
|
2018-10-31 19:06:08 -03:00
|
|
|
// 22 is enough for the rc_input page in one transfer
|
|
|
|
#define PKT_MAX_REGS 22
|
2024-04-27 04:44:31 -03:00
|
|
|
// The number of channels that can be propagated - due to SBUS_OUT is higher than the physical channels
|
2023-11-13 15:58:36 -04:00
|
|
|
#define IOMCU_MAX_RC_CHANNELS 16
|
2024-04-27 04:44:31 -03:00
|
|
|
// The actual number of output channels
|
2023-11-13 15:58:36 -04:00
|
|
|
#define IOMCU_MAX_CHANNELS 8
|
|
|
|
#define IOMCU_MAX_TELEM_CHANNELS 4
|
2018-05-10 21:37:01 -03:00
|
|
|
|
|
|
|
//#define IOMCU_DEBUG
|
|
|
|
|
|
|
|
struct PACKED IOPacket {
|
2018-09-14 07:06:59 -03:00
|
|
|
uint8_t count:6;
|
|
|
|
uint8_t code:2;
|
|
|
|
uint8_t crc;
|
|
|
|
uint8_t page;
|
|
|
|
uint8_t offset;
|
|
|
|
uint16_t regs[PKT_MAX_REGS];
|
2018-05-10 21:37:01 -03:00
|
|
|
|
|
|
|
// get packet size in bytes
|
2018-09-14 07:06:59 -03:00
|
|
|
uint8_t get_size(void) const
|
|
|
|
{
|
2018-05-10 21:37:01 -03:00
|
|
|
return count*2 + 4;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
values for pkt.code
|
|
|
|
*/
|
|
|
|
enum iocode {
|
|
|
|
// read types
|
|
|
|
CODE_READ = 0,
|
|
|
|
CODE_WRITE = 1,
|
2023-12-21 11:06:36 -04:00
|
|
|
CODE_NOOP = 2,
|
2018-05-10 21:37:01 -03:00
|
|
|
|
|
|
|
// reply codes
|
|
|
|
CODE_SUCCESS = 0,
|
|
|
|
CODE_CORRUPT = 1,
|
|
|
|
CODE_ERROR = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
// IO pages
|
|
|
|
enum iopage {
|
|
|
|
PAGE_CONFIG = 0,
|
|
|
|
PAGE_STATUS = 1,
|
|
|
|
PAGE_ACTUATORS = 2,
|
|
|
|
PAGE_SERVOS = 3,
|
|
|
|
PAGE_RAW_RCIN = 4,
|
|
|
|
PAGE_RCIN = 5,
|
|
|
|
PAGE_RAW_ADC = 6,
|
|
|
|
PAGE_PWM_INFO = 7,
|
|
|
|
PAGE_SETUP = 50,
|
|
|
|
PAGE_DIRECT_PWM = 54,
|
|
|
|
PAGE_FAILSAFE_PWM = 55,
|
2018-10-30 21:07:47 -03:00
|
|
|
PAGE_MIXING = 200,
|
2021-09-20 10:43:32 -03:00
|
|
|
PAGE_GPIO = 201,
|
2023-05-24 17:43:17 -03:00
|
|
|
PAGE_DSHOT = 202,
|
2023-06-23 17:15:14 -03:00
|
|
|
PAGE_RAW_DSHOT_ERPM = 203,
|
|
|
|
PAGE_RAW_DSHOT_TELEM_1_4 = 204,
|
|
|
|
PAGE_RAW_DSHOT_TELEM_5_8 = 205,
|
|
|
|
PAGE_RAW_DSHOT_TELEM_9_12 = 206,
|
|
|
|
PAGE_RAW_DSHOT_TELEM_13_16 = 207,
|
2018-05-10 21:37:01 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
// setup page registers
|
|
|
|
#define PAGE_REG_SETUP_FEATURES 0
|
|
|
|
#define P_SETUP_FEATURES_SBUS1_OUT 1
|
|
|
|
#define P_SETUP_FEATURES_SBUS2_OUT 2
|
|
|
|
#define P_SETUP_FEATURES_PWM_RSSI 4
|
|
|
|
#define P_SETUP_FEATURES_ADC_RSSI 8
|
|
|
|
#define P_SETUP_FEATURES_ONESHOT 16
|
2018-07-13 01:44:16 -03:00
|
|
|
#define P_SETUP_FEATURES_BRUSHED 32
|
2023-03-01 00:05:02 -04:00
|
|
|
#define P_SETUP_FEATURES_HEATER 64
|
2018-05-10 21:37:01 -03:00
|
|
|
|
|
|
|
#define PAGE_REG_SETUP_ARMING 1
|
|
|
|
#define P_SETUP_ARMING_IO_ARM_OK (1<<0)
|
|
|
|
#define P_SETUP_ARMING_FMU_ARMED (1<<1)
|
|
|
|
#define P_SETUP_ARMING_RC_HANDLING_DISABLED (1<<6)
|
|
|
|
#define P_SETUP_ARMING_SAFETY_DISABLE_ON (1 << 11) // disable use of safety button for safety off->on
|
|
|
|
#define P_SETUP_ARMING_SAFETY_DISABLE_OFF (1 << 12) // disable use of safety button for safety on->off
|
|
|
|
|
|
|
|
#define PAGE_REG_SETUP_PWM_RATE_MASK 2
|
|
|
|
#define PAGE_REG_SETUP_DEFAULTRATE 3
|
|
|
|
#define PAGE_REG_SETUP_ALTRATE 4
|
2020-07-11 09:22:05 -03:00
|
|
|
#define PAGE_REG_SETUP_OUTPUT_MODE 5
|
2018-05-10 21:37:01 -03:00
|
|
|
#define PAGE_REG_SETUP_REBOOT_BL 10
|
|
|
|
#define PAGE_REG_SETUP_CRC 11
|
|
|
|
#define PAGE_REG_SETUP_SBUS_RATE 19
|
|
|
|
#define PAGE_REG_SETUP_IGNORE_SAFETY 20 /* bitmask of surfaces to ignore the safety status */
|
|
|
|
#define PAGE_REG_SETUP_HEATER_DUTY_CYCLE 21
|
2018-10-31 19:18:13 -03:00
|
|
|
#define PAGE_REG_SETUP_DSM_BIND 22
|
2020-08-12 23:28:47 -03:00
|
|
|
#define PAGE_REG_SETUP_RC_PROTOCOLS 23 // uses 2 slots, 23 and 24
|
2023-05-24 17:43:17 -03:00
|
|
|
#define PAGE_REG_SETUP_DSHOT_PERIOD 25
|
|
|
|
#define PAGE_REG_SETUP_CHANNEL_MASK 27
|
2018-05-10 21:37:01 -03:00
|
|
|
|
2018-10-30 21:07:47 -03:00
|
|
|
// config page registers
|
2018-11-01 03:39:24 -03:00
|
|
|
#define PAGE_CONFIG_PROTOCOL_VERSION 0
|
|
|
|
#define PAGE_CONFIG_PROTOCOL_VERSION2 1
|
|
|
|
#define IOMCU_PROTOCOL_VERSION 4
|
|
|
|
#define IOMCU_PROTOCOL_VERSION2 10
|
2018-10-30 21:07:47 -03:00
|
|
|
|
2018-05-10 21:37:01 -03:00
|
|
|
// magic value for rebooting to bootloader
|
|
|
|
#define REBOOT_BL_MAGIC 14662
|
|
|
|
|
|
|
|
#define PAGE_REG_SETUP_FORCE_SAFETY_OFF 12
|
|
|
|
#define PAGE_REG_SETUP_FORCE_SAFETY_ON 14
|
|
|
|
#define FORCE_SAFETY_MAGIC 22027
|
|
|
|
|
2019-08-13 21:07:48 -03:00
|
|
|
struct page_config {
|
2018-10-30 21:24:51 -03:00
|
|
|
uint16_t protocol_version;
|
2018-11-01 03:39:24 -03:00
|
|
|
uint16_t protocol_version2;
|
2023-06-17 19:26:56 -03:00
|
|
|
uint32_t mcuid;
|
2023-06-24 15:16:43 -03:00
|
|
|
uint32_t cpuid;
|
2018-10-30 21:07:47 -03:00
|
|
|
};
|
|
|
|
|
2019-08-13 21:07:48 -03:00
|
|
|
struct page_reg_status {
|
2018-05-10 21:37:01 -03:00
|
|
|
uint16_t freemem;
|
2023-05-24 17:43:17 -03:00
|
|
|
uint16_t freemstack;
|
|
|
|
uint16_t freepstack;
|
2019-04-23 22:33:42 -03:00
|
|
|
uint32_t timestamp_ms;
|
2018-05-10 21:37:01 -03:00
|
|
|
uint16_t vservo;
|
|
|
|
uint16_t vrssi;
|
2019-08-13 21:07:48 -03:00
|
|
|
uint32_t num_errors;
|
|
|
|
uint32_t total_pkts;
|
2023-06-01 12:06:52 -03:00
|
|
|
uint32_t total_ticks;
|
|
|
|
uint32_t total_events;
|
2019-08-13 21:07:48 -03:00
|
|
|
uint8_t flag_safety_off;
|
2023-06-17 19:26:56 -03:00
|
|
|
uint8_t rcout_mask;
|
|
|
|
uint8_t rcout_mode;
|
2019-08-13 21:07:48 -03:00
|
|
|
uint8_t err_crc;
|
|
|
|
uint8_t err_bad_opcode;
|
|
|
|
uint8_t err_read;
|
|
|
|
uint8_t err_write;
|
|
|
|
uint8_t err_uart;
|
2023-06-01 12:06:52 -03:00
|
|
|
uint8_t err_lock;
|
2023-11-13 15:58:36 -04:00
|
|
|
uint8_t spare;
|
2018-05-10 21:37:01 -03:00
|
|
|
};
|
|
|
|
|
2019-08-13 21:07:48 -03:00
|
|
|
struct page_rc_input {
|
|
|
|
uint8_t count;
|
|
|
|
uint8_t flags_failsafe:1;
|
|
|
|
uint8_t flags_rc_ok:1;
|
|
|
|
uint8_t rc_protocol;
|
2023-11-13 15:58:36 -04:00
|
|
|
uint16_t pwm[IOMCU_MAX_RC_CHANNELS];
|
2019-12-02 03:46:36 -04:00
|
|
|
int16_t rssi;
|
2018-05-10 21:37:01 -03:00
|
|
|
};
|
2018-10-30 21:07:47 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
data for mixing on FMU failsafe
|
|
|
|
*/
|
2019-08-13 21:07:48 -03:00
|
|
|
struct page_mixing {
|
2024-04-27 04:44:31 -03:00
|
|
|
uint16_t servo_min[IOMCU_MAX_RC_CHANNELS];
|
|
|
|
uint16_t servo_max[IOMCU_MAX_RC_CHANNELS];
|
|
|
|
uint16_t servo_trim[IOMCU_MAX_RC_CHANNELS];
|
|
|
|
uint8_t servo_function[IOMCU_MAX_RC_CHANNELS];
|
|
|
|
uint8_t servo_reversed[IOMCU_MAX_RC_CHANNELS];
|
2018-10-30 21:07:47 -03:00
|
|
|
|
|
|
|
// RC input arrays are in AETR order
|
|
|
|
uint16_t rc_min[4];
|
|
|
|
uint16_t rc_max[4];
|
|
|
|
uint16_t rc_trim[4];
|
2024-04-27 04:44:31 -03:00
|
|
|
uint8_t rc_reversed[IOMCU_MAX_RC_CHANNELS];
|
2018-10-30 21:07:47 -03:00
|
|
|
uint8_t rc_channel[4];
|
|
|
|
|
2018-10-31 00:16:17 -03:00
|
|
|
// gain for elevon and vtail mixing, x1000
|
|
|
|
uint16_t mixing_gain;
|
|
|
|
|
2018-10-30 21:07:47 -03:00
|
|
|
// channel which when high forces mixer
|
|
|
|
int8_t rc_chan_override;
|
|
|
|
|
2018-10-30 23:10:51 -03:00
|
|
|
// is the throttle an angle input?
|
|
|
|
uint8_t throttle_is_angle;
|
2018-10-31 00:16:17 -03:00
|
|
|
|
2018-10-31 01:09:49 -03:00
|
|
|
// mask of channels which are pure manual in override
|
|
|
|
uint16_t manual_rc_mask;
|
|
|
|
|
2018-10-30 21:07:47 -03:00
|
|
|
// enabled needs to be 1 to enable mixing
|
|
|
|
uint8_t enabled;
|
2018-10-30 23:10:51 -03:00
|
|
|
|
2022-03-16 07:03:09 -03:00
|
|
|
uint8_t pad;
|
2018-10-30 21:07:47 -03:00
|
|
|
};
|
2021-09-20 10:43:32 -03:00
|
|
|
|
2022-03-16 07:03:09 -03:00
|
|
|
static_assert(sizeof(struct page_mixing) % 2 == 0, "page_mixing must be even size");
|
|
|
|
|
2021-09-29 05:20:47 -03:00
|
|
|
struct __attribute__((packed, aligned(2))) page_GPIO {
|
2021-09-20 10:43:32 -03:00
|
|
|
uint8_t channel_mask;
|
|
|
|
uint8_t output_mask;
|
|
|
|
};
|
2023-05-24 17:43:17 -03:00
|
|
|
|
2023-10-23 10:36:02 -03:00
|
|
|
struct page_mode_out {
|
2023-06-23 17:15:14 -03:00
|
|
|
uint16_t mask;
|
|
|
|
uint16_t mode;
|
|
|
|
uint16_t bdmask;
|
|
|
|
uint16_t esc_type;
|
|
|
|
};
|
|
|
|
|
2023-10-23 10:36:02 -03:00
|
|
|
struct page_dshot {
|
2023-05-24 17:43:17 -03:00
|
|
|
uint16_t telem_mask;
|
|
|
|
uint8_t command;
|
|
|
|
uint8_t chan;
|
|
|
|
uint32_t command_timeout_ms;
|
|
|
|
uint8_t repeat_count;
|
|
|
|
uint8_t priority;
|
|
|
|
};
|
2023-06-23 17:15:14 -03:00
|
|
|
|
2023-10-23 10:36:02 -03:00
|
|
|
struct page_dshot_erpm {
|
2023-11-13 15:58:36 -04:00
|
|
|
uint16_t erpm[IOMCU_MAX_TELEM_CHANNELS];
|
2023-06-23 17:15:14 -03:00
|
|
|
uint32_t update_mask;
|
|
|
|
};
|
|
|
|
|
|
|
|
// separate telemetry packet because (a) it's too big otherwise and (b) slower update rate
|
2023-10-23 10:36:02 -03:00
|
|
|
struct page_dshot_telem {
|
2023-06-23 17:15:14 -03:00
|
|
|
uint16_t error_rate[4]; // as a centi-percentage
|
|
|
|
uint16_t voltage_cvolts[4];
|
|
|
|
uint16_t current_camps[4];
|
|
|
|
uint16_t temperature_cdeg[4];
|
|
|
|
uint16_t types[4];
|
2024-05-13 20:16:23 -03:00
|
|
|
// if EDTv2 needs to be disabled, IOMCU firmware should be recompiled too, this is the reason
|
|
|
|
#if AP_EXTENDED_DSHOT_TELEM_V2_ENABLED
|
|
|
|
uint8_t edt2_status[4];
|
|
|
|
uint8_t edt2_stress[4];
|
|
|
|
#endif
|
2023-06-23 17:15:14 -03:00
|
|
|
};
|