2018-01-05 02:19:51 -04:00
|
|
|
/*
|
|
|
|
* This file is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
2019-10-20 10:31:12 -03:00
|
|
|
*
|
2018-01-05 02:19:51 -04:00
|
|
|
* Code by Andrew Tridgell and Siddharth Bharat Purohit
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "AP_HAL_ChibiOS.h"
|
2018-03-06 18:41:03 -04:00
|
|
|
#include "Semaphores.h"
|
2018-01-17 15:30:21 -04:00
|
|
|
|
2018-03-11 11:47:54 -03:00
|
|
|
#if HAL_RCINPUT_WITH_AP_RADIO
|
2018-01-05 02:19:51 -04:00
|
|
|
#include <AP_Radio/AP_Radio.h>
|
|
|
|
#endif
|
|
|
|
|
2019-08-27 04:43:30 -03:00
|
|
|
#include <AP_RCProtocol/AP_RCProtocol.h>
|
|
|
|
|
2018-01-17 15:30:21 -04:00
|
|
|
#if HAL_USE_ICU == TRUE
|
2018-04-22 09:43:49 -03:00
|
|
|
#include "SoftSigReader.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAL_USE_EICU == TRUE
|
|
|
|
#include "SoftSigReaderInt.h"
|
2018-01-17 15:30:21 -04:00
|
|
|
#endif
|
|
|
|
|
2018-01-05 02:19:51 -04:00
|
|
|
#ifndef RC_INPUT_MAX_CHANNELS
|
|
|
|
#define RC_INPUT_MAX_CHANNELS 18
|
|
|
|
#endif
|
|
|
|
|
2018-01-13 00:02:05 -04:00
|
|
|
class ChibiOS::RCInput : public AP_HAL::RCInput {
|
2018-01-05 02:19:51 -04:00
|
|
|
public:
|
|
|
|
void init() override;
|
|
|
|
bool new_input() override;
|
|
|
|
uint8_t num_channels() override;
|
|
|
|
uint16_t read(uint8_t ch) override;
|
|
|
|
uint8_t read(uint16_t* periods, uint8_t len) override;
|
|
|
|
|
2020-01-28 22:23:18 -04:00
|
|
|
/* enable or disable pulse input for RC input. This is used to
|
|
|
|
reduce load when we are decoding R/C via a UART */
|
|
|
|
void pulse_input_enable(bool enable) override;
|
|
|
|
|
2018-01-05 02:19:51 -04:00
|
|
|
int16_t get_rssi(void) override {
|
|
|
|
return _rssi;
|
|
|
|
}
|
2021-07-12 16:03:44 -03:00
|
|
|
int16_t get_rx_link_quality(void) override {
|
|
|
|
return _rx_link_quality;
|
|
|
|
}
|
2019-06-17 09:10:10 -03:00
|
|
|
const char *protocol() const override { return last_protocol; }
|
|
|
|
|
2018-01-05 02:19:51 -04:00
|
|
|
void _timer_tick(void);
|
|
|
|
bool rc_bind(int dsmMode) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint16_t _rc_values[RC_INPUT_MAX_CHANNELS] = {0};
|
|
|
|
|
|
|
|
uint64_t _last_read;
|
|
|
|
uint8_t _num_channels;
|
2018-03-06 18:41:03 -04:00
|
|
|
Semaphore rcin_mutex;
|
2018-01-05 02:19:51 -04:00
|
|
|
int16_t _rssi = -1;
|
2021-07-12 16:03:44 -03:00
|
|
|
int16_t _rx_link_quality = -1;
|
2018-01-05 02:19:51 -04:00
|
|
|
uint32_t _rcin_timestamp_last_signal;
|
2022-03-17 04:01:03 -03:00
|
|
|
uint32_t _rcin_last_iomcu_ms;
|
2018-01-05 02:19:51 -04:00
|
|
|
bool _init;
|
2018-11-02 19:49:41 -03:00
|
|
|
const char *last_protocol;
|
2022-03-27 03:31:20 -03:00
|
|
|
|
|
|
|
enum class RCSource {
|
|
|
|
NONE = 0,
|
|
|
|
IOMCU = 1,
|
|
|
|
RCPROT_PULSES = 2,
|
|
|
|
RCPROT_BYTES = 3,
|
|
|
|
APRADIO = 4,
|
|
|
|
} last_source;
|
|
|
|
|
2020-01-28 22:23:18 -04:00
|
|
|
bool pulse_input_enabled;
|
2018-11-02 19:49:41 -03:00
|
|
|
|
2018-03-11 11:47:54 -03:00
|
|
|
#if HAL_RCINPUT_WITH_AP_RADIO
|
2018-01-05 02:19:51 -04:00
|
|
|
bool _radio_init;
|
|
|
|
AP_Radio *radio;
|
|
|
|
uint32_t last_radio_us;
|
|
|
|
#endif
|
2018-01-17 15:30:21 -04:00
|
|
|
|
2018-01-17 19:54:37 -04:00
|
|
|
#if HAL_USE_ICU == TRUE
|
2018-01-17 15:30:21 -04:00
|
|
|
ChibiOS::SoftSigReader sig_reader;
|
|
|
|
#endif
|
|
|
|
|
2018-04-22 09:43:49 -03:00
|
|
|
#if HAL_USE_EICU == TRUE
|
|
|
|
ChibiOS::SoftSigReaderInt sig_reader;
|
|
|
|
#endif
|
|
|
|
|
2018-01-05 02:19:51 -04:00
|
|
|
#if HAL_WITH_IO_MCU
|
|
|
|
uint32_t last_iomcu_us;
|
|
|
|
#endif
|
|
|
|
};
|