2021-10-27 05:43:28 -03: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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "AP_HAL_ESP32.h"
|
|
|
|
#include "Semaphores.h"
|
2024-11-16 09:10:16 -04:00
|
|
|
|
2021-10-27 05:43:28 -03:00
|
|
|
#include <AP_RCProtocol/AP_RCProtocol.h>
|
|
|
|
|
2024-11-16 09:10:16 -04:00
|
|
|
#include "RmtSigReader.h"
|
2021-10-27 05:43:28 -03:00
|
|
|
|
|
|
|
#ifndef RC_INPUT_MAX_CHANNELS
|
|
|
|
#define RC_INPUT_MAX_CHANNELS 18
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class ESP32::RCInput : public AP_HAL::RCInput
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2024-11-16 09:10:16 -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;
|
|
|
|
|
|
|
|
int16_t get_rssi(void) override {
|
|
|
|
return _rssi;
|
|
|
|
}
|
|
|
|
int16_t get_rx_link_quality(void) override {
|
|
|
|
return _rx_link_quality;
|
2021-10-27 05:43:28 -03:00
|
|
|
}
|
2024-11-16 09:10:16 -04:00
|
|
|
const char *protocol() const override { return last_protocol; }
|
|
|
|
|
|
|
|
void _timer_tick(void);
|
|
|
|
bool rc_bind(int dsmMode) override;
|
|
|
|
|
2021-10-27 05:43:28 -03:00
|
|
|
private:
|
|
|
|
uint16_t _rc_values[RC_INPUT_MAX_CHANNELS] = {0};
|
2024-11-16 09:10:16 -04:00
|
|
|
|
2021-10-27 05:43:28 -03:00
|
|
|
uint64_t _last_read;
|
|
|
|
uint8_t _num_channels;
|
|
|
|
Semaphore rcin_mutex;
|
|
|
|
int16_t _rssi = -1;
|
2024-11-16 09:10:16 -04:00
|
|
|
int16_t _rx_link_quality = -1;
|
2021-10-27 05:43:28 -03:00
|
|
|
uint32_t _rcin_timestamp_last_signal;
|
|
|
|
bool _init;
|
|
|
|
const char *last_protocol;
|
|
|
|
|
2024-11-16 09:10:16 -04:00
|
|
|
enum class RCSource {
|
|
|
|
NONE = 0,
|
|
|
|
IOMCU = 1,
|
|
|
|
RCPROT_PULSES = 2,
|
|
|
|
RCPROT_BYTES = 3,
|
|
|
|
} last_source;
|
|
|
|
|
|
|
|
bool pulse_input_enabled;
|
|
|
|
|
2021-10-27 05:43:28 -03:00
|
|
|
ESP32::RmtSigReader sig_reader;
|
|
|
|
};
|