2016-02-17 21:25:25 -04:00
|
|
|
#pragma once
|
2012-08-27 15:44:50 -03:00
|
|
|
|
|
|
|
#include "AP_HAL_Namespace.h"
|
2017-11-22 13:38:34 -04:00
|
|
|
#include <stdint.h>
|
2012-08-27 15:44:50 -03:00
|
|
|
|
2015-06-04 20:54:54 -03:00
|
|
|
#define RC_OUTPUT_MIN_PULSEWIDTH 400
|
|
|
|
#define RC_OUTPUT_MAX_PULSEWIDTH 2100
|
|
|
|
|
2012-08-28 01:05:19 -03:00
|
|
|
/* Define the CH_n names, indexed from 1, if we don't have them already */
|
|
|
|
#ifndef CH_1
|
|
|
|
#define CH_1 0
|
|
|
|
#define CH_2 1
|
|
|
|
#define CH_3 2
|
|
|
|
#define CH_4 3
|
|
|
|
#define CH_5 4
|
|
|
|
#define CH_6 5
|
|
|
|
#define CH_7 6
|
|
|
|
#define CH_8 7
|
|
|
|
#define CH_9 8
|
|
|
|
#define CH_10 9
|
|
|
|
#define CH_11 10
|
2013-04-25 06:58:49 -03:00
|
|
|
#define CH_12 11
|
2014-03-25 00:39:41 -03:00
|
|
|
#define CH_13 12
|
|
|
|
#define CH_14 13
|
|
|
|
#define CH_15 14
|
|
|
|
#define CH_16 15
|
|
|
|
#define CH_17 16
|
|
|
|
#define CH_18 17
|
2016-05-26 03:26:30 -03:00
|
|
|
#define CH_NONE 255
|
2012-08-28 01:05:19 -03:00
|
|
|
#endif
|
|
|
|
|
2018-03-16 18:49:11 -03:00
|
|
|
class ByteBuffer;
|
2012-08-28 01:05:19 -03:00
|
|
|
|
2012-08-27 15:44:50 -03:00
|
|
|
class AP_HAL::RCOutput {
|
|
|
|
public:
|
2015-12-02 11:37:22 -04:00
|
|
|
virtual void init() = 0;
|
2012-08-27 20:45:46 -03:00
|
|
|
|
|
|
|
/* Output freq (1/period) control */
|
|
|
|
virtual void set_freq(uint32_t chmask, uint16_t freq_hz) = 0;
|
2018-05-02 09:50:06 -03:00
|
|
|
virtual uint16_t get_freq(uint8_t chan) = 0;
|
2012-08-27 20:45:46 -03:00
|
|
|
|
|
|
|
/* Output active/highZ control, either by single channel at a time
|
|
|
|
* or a mask of channels */
|
2018-05-02 09:50:06 -03:00
|
|
|
virtual void enable_ch(uint8_t chan) = 0;
|
|
|
|
virtual void disable_ch(uint8_t chan) = 0;
|
2012-08-27 20:45:46 -03:00
|
|
|
|
2015-09-28 17:19:08 -03:00
|
|
|
/*
|
|
|
|
* Output a single channel, possibly grouped with previous writes if
|
|
|
|
* cork() has been called before.
|
|
|
|
*/
|
2018-05-02 09:50:06 -03:00
|
|
|
virtual void write(uint8_t chan, uint16_t period_us) = 0;
|
2012-08-27 20:45:46 -03:00
|
|
|
|
2018-11-09 06:25:13 -04:00
|
|
|
/*
|
|
|
|
* mark the channels in chanmask as reversible. This is needed for some ESC types (such as DShot)
|
|
|
|
* so that output scaling can be performed correctly. The chanmask passed is added (ORed) into
|
|
|
|
* any existing mask.
|
|
|
|
*/
|
|
|
|
virtual void set_reversible_mask(uint16_t chanmask) {}
|
|
|
|
|
2015-09-28 17:19:08 -03:00
|
|
|
/*
|
|
|
|
* Delay subsequent calls to write() going to the underlying hardware in
|
|
|
|
* order to group related writes together. When all the needed writes are
|
|
|
|
* done, call push() to commit the changes.
|
|
|
|
*/
|
2016-10-11 08:01:49 -03:00
|
|
|
virtual void cork() = 0;
|
2015-09-28 17:19:08 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Push pending changes to the underlying hardware. All changes between a
|
|
|
|
* call to cork() and push() are pushed together in a single transaction.
|
|
|
|
*/
|
2016-10-11 08:01:49 -03:00
|
|
|
virtual void push() = 0;
|
2015-09-28 17:19:08 -03:00
|
|
|
|
2012-08-27 20:45:46 -03:00
|
|
|
/* Read back current output state, as either single channel or
|
2016-03-10 17:55:42 -04:00
|
|
|
* array of channels. On boards that have a separate IO controller,
|
|
|
|
* this returns the latest output value that the IO controller has
|
|
|
|
* reported */
|
2018-05-02 09:50:06 -03:00
|
|
|
virtual uint16_t read(uint8_t chan) = 0;
|
2012-08-28 01:05:19 -03:00
|
|
|
virtual void read(uint16_t* period_us, uint8_t len) = 0;
|
2014-01-15 07:25:22 -04:00
|
|
|
|
2016-03-10 17:55:42 -04:00
|
|
|
/* Read the current input state. This returns the last value that was written. */
|
2018-05-02 09:50:06 -03:00
|
|
|
virtual uint16_t read_last_sent(uint8_t chan) { return read(chan); }
|
2016-03-10 17:55:42 -04:00
|
|
|
virtual void read_last_sent(uint16_t* period_us, uint8_t len) { read(period_us, len); };
|
|
|
|
|
2014-01-15 07:25:22 -04:00
|
|
|
/*
|
|
|
|
set PWM to send to a set of channels when the safety switch is
|
|
|
|
in the safe state
|
|
|
|
*/
|
|
|
|
virtual void set_safety_pwm(uint32_t chmask, uint16_t period_us) {}
|
2014-02-11 00:56:44 -04:00
|
|
|
|
2014-04-20 19:36:52 -03:00
|
|
|
/*
|
|
|
|
set PWM to send to a set of channels if the FMU firmware dies
|
|
|
|
*/
|
|
|
|
virtual void set_failsafe_pwm(uint32_t chmask, uint16_t period_us) {}
|
|
|
|
|
2014-09-14 05:23:13 -03:00
|
|
|
/*
|
|
|
|
force the safety switch on, disabling PWM output from the IO board
|
|
|
|
return false (indicating failure) by default so that boards with no safety switch
|
|
|
|
do not need to implement this method
|
|
|
|
*/
|
|
|
|
virtual bool force_safety_on(void) { return false; }
|
|
|
|
|
2014-02-11 00:56:44 -04:00
|
|
|
/*
|
|
|
|
force the safety switch off, enabling PWM output from the IO board
|
|
|
|
*/
|
|
|
|
virtual void force_safety_off(void) {}
|
2014-11-20 03:30:10 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
setup scaling of ESC output for ESCs that can output a
|
|
|
|
percentage of power (such as UAVCAN ESCs). The values are in
|
|
|
|
microseconds, and represent minimum and maximum PWM values which
|
|
|
|
will be used to convert channel writes into a percentage
|
|
|
|
*/
|
|
|
|
virtual void set_esc_scaling(uint16_t min_pwm, uint16_t max_pwm) {}
|
2016-04-13 03:23:11 -03:00
|
|
|
|
2018-04-02 04:57:33 -03:00
|
|
|
/*
|
|
|
|
return ESC scaling value from set_esc_scaling()
|
|
|
|
*/
|
|
|
|
virtual bool get_esc_scaling(uint16_t &min_pwm, uint16_t &max_pwm) { return false; }
|
|
|
|
|
2017-04-06 16:09:37 -03:00
|
|
|
/*
|
|
|
|
returns the pwm value scaled to [-1;1] regrading to set_esc_scaling ranges range without constraints.
|
|
|
|
*/
|
|
|
|
virtual float scale_esc_to_unity(uint16_t pwm) { return 0; }
|
|
|
|
|
2020-10-23 17:23:34 -03:00
|
|
|
/*
|
|
|
|
return the erpm and error rate for a channel if available
|
|
|
|
*/
|
|
|
|
virtual uint16_t get_erpm(uint8_t chan) const { return 0; }
|
|
|
|
virtual float get_erpm_error_rate(uint8_t chan) const { return 100.0f; }
|
|
|
|
|
2016-04-15 03:38:09 -03:00
|
|
|
/*
|
2017-11-22 13:38:34 -04:00
|
|
|
enable PX4IO SBUS out at the given rate
|
2016-04-15 03:38:09 -03:00
|
|
|
*/
|
2017-11-22 13:38:34 -04:00
|
|
|
virtual bool enable_px4io_sbus_out(uint16_t rate_hz) { return false; }
|
2017-02-07 23:45:50 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Optional method to control the update of the motors. Derived classes
|
|
|
|
* can implement it if their HAL layer requires.
|
|
|
|
*/
|
|
|
|
virtual void timer_tick(void) { }
|
|
|
|
|
2016-04-13 03:23:11 -03:00
|
|
|
/*
|
2018-03-16 18:49:11 -03:00
|
|
|
setup for serial output to an ESC using the given
|
|
|
|
baudrate. Assumes 1 start bit, 1 stop bit, LSB first and 8
|
|
|
|
databits. This is used for passthrough ESC configuration and
|
|
|
|
firmware flashing
|
|
|
|
|
2018-08-04 05:26:49 -03:00
|
|
|
While serial output is active normal output to all channels in
|
|
|
|
the chanmask is suspended. Output to some other channels (such
|
|
|
|
as those in the same channel timer groups) may also be stopped,
|
|
|
|
depending on the implementation
|
2018-03-16 18:49:11 -03:00
|
|
|
*/
|
2018-08-04 05:26:49 -03:00
|
|
|
virtual bool serial_setup_output(uint8_t chan, uint32_t baudrate, uint16_t chanmask) { return false; }
|
2018-03-16 18:49:11 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
write a set of bytes to an ESC, using settings from
|
|
|
|
serial_setup_output. This is a blocking call
|
|
|
|
*/
|
|
|
|
virtual bool serial_write_bytes(const uint8_t *bytes, uint16_t len) { return false; }
|
|
|
|
|
|
|
|
/*
|
|
|
|
read a series of bytes from a port, using serial parameters from serial_setup_output()
|
|
|
|
return the number of bytes read. This is a blocking call
|
|
|
|
*/
|
|
|
|
virtual uint16_t serial_read_bytes(uint8_t *buf, uint16_t len) { return 0; }
|
|
|
|
|
|
|
|
/*
|
|
|
|
stop serial output. This restores the previous output mode for
|
|
|
|
the channel and any other channels that were stopped by
|
|
|
|
serial_setup_output()
|
|
|
|
*/
|
|
|
|
virtual void serial_end(void) {}
|
|
|
|
|
|
|
|
/*
|
|
|
|
output modes. Allows for support of PWM, oneshot and dshot
|
2016-04-13 03:23:11 -03:00
|
|
|
*/
|
|
|
|
enum output_mode {
|
2018-03-16 18:49:11 -03:00
|
|
|
MODE_PWM_NONE,
|
2016-04-13 03:23:11 -03:00
|
|
|
MODE_PWM_NORMAL,
|
2016-11-29 06:08:30 -04:00
|
|
|
MODE_PWM_ONESHOT,
|
2018-04-03 05:10:15 -03:00
|
|
|
MODE_PWM_ONESHOT125,
|
2018-03-14 03:04:02 -03:00
|
|
|
MODE_PWM_BRUSHED,
|
|
|
|
MODE_PWM_DSHOT150,
|
|
|
|
MODE_PWM_DSHOT300,
|
|
|
|
MODE_PWM_DSHOT600,
|
|
|
|
MODE_PWM_DSHOT1200,
|
2020-02-22 19:55:21 -04:00
|
|
|
MODE_NEOPIXEL, // same as MODE_PWM_DSHOT at 800kHz but it's an LED
|
|
|
|
MODE_PROFILED, // same as MODE_PWM_DSHOT using separate clock and data
|
2016-04-13 03:23:11 -03:00
|
|
|
};
|
2018-03-14 03:04:02 -03:00
|
|
|
virtual void set_output_mode(uint16_t mask, enum output_mode mode) {}
|
2017-07-16 20:18:49 -03:00
|
|
|
|
2020-01-28 04:28:36 -04:00
|
|
|
/*
|
|
|
|
* get output mode banner to inform user of how outputs are configured
|
|
|
|
*/
|
|
|
|
virtual bool get_output_mode_banner(char banner_msg[], uint8_t banner_msg_len) const { return false; }
|
|
|
|
|
2017-07-16 20:18:49 -03:00
|
|
|
/*
|
|
|
|
set default update rate
|
|
|
|
*/
|
|
|
|
virtual void set_default_rate(uint16_t rate_hz) {}
|
2018-04-02 01:20:42 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
enable telemetry request for a mask of channels. This is used
|
|
|
|
with DShot to get telemetry feedback
|
|
|
|
*/
|
|
|
|
virtual void set_telem_request_mask(uint16_t mask) {}
|
2019-03-29 18:45:12 -03:00
|
|
|
|
2020-10-23 17:23:34 -03:00
|
|
|
/*
|
|
|
|
enable bi-directional telemetry request for a mask of channels. This is used
|
|
|
|
with DShot to get telemetry feedback
|
|
|
|
*/
|
|
|
|
virtual void set_bidir_dshot_mask(uint16_t mask) {}
|
|
|
|
|
2019-09-09 05:56:23 -03:00
|
|
|
/*
|
2020-02-22 19:55:21 -04:00
|
|
|
setup serial led output for a given channel number, with
|
2019-09-09 05:56:23 -03:00
|
|
|
the given max number of LEDs in the chain.
|
|
|
|
*/
|
2020-02-22 19:55:21 -04:00
|
|
|
virtual bool set_serial_led_num_LEDs(const uint16_t chan, uint8_t num_leds, output_mode mode = MODE_PWM_NONE, uint16_t clock_mask = 0) { return false; }
|
2019-09-09 05:56:23 -03:00
|
|
|
|
|
|
|
/*
|
2020-02-22 19:55:21 -04:00
|
|
|
setup serial led output data for a given output channel
|
2020-02-09 06:34:12 -04:00
|
|
|
and led number. A led number of -1 means all LEDs. LED 0 is the first LED
|
2019-09-09 05:56:23 -03:00
|
|
|
*/
|
2020-02-22 19:55:21 -04:00
|
|
|
virtual void set_serial_led_rgb_data(const uint16_t chan, int8_t led, uint8_t red, uint8_t green, uint8_t blue) {}
|
2020-02-09 06:34:12 -04:00
|
|
|
|
2019-09-09 05:56:23 -03:00
|
|
|
/*
|
2020-02-22 19:55:21 -04:00
|
|
|
trigger send of serial led
|
2019-09-09 05:56:23 -03:00
|
|
|
*/
|
2020-02-22 19:55:21 -04:00
|
|
|
virtual void serial_led_send(const uint16_t chan) {}
|
2020-01-28 04:28:36 -04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
// helper functions for implementation of get_output_mode_banner
|
|
|
|
void append_to_banner(char banner_msg[], uint8_t banner_msg_len, output_mode out_mode, uint8_t low_ch, uint8_t high_ch) const;
|
|
|
|
const char* get_output_mode_string(enum output_mode out_mode) const;
|
2012-08-27 15:44:50 -03:00
|
|
|
};
|