79 lines
1.7 KiB
C
79 lines
1.7 KiB
C
/**
|
|
* @file rcsignal.h
|
|
* @brief RC PWM signal reading and parsing module
|
|
*/
|
|
|
|
#ifndef RCSIGNAL_H
|
|
#define RCSIGNAL_H
|
|
|
|
#include "esp_err.h"
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
|
|
// Define to switch between PWM and SBUS mode
|
|
// Comment out to use PWM mode, uncomment to use SBUS mode
|
|
#define USE_SBUS_MODE
|
|
|
|
#ifdef USE_SBUS_MODE
|
|
#define SBUS_NUM_CHANNELS 16 // SBUS supports 16 proportional channels
|
|
#define SBUS_TRIGGER_CHANNEL 3 // Channel 4 (index 3) for mode trigger
|
|
#endif
|
|
|
|
/**
|
|
* @brief Callback function type for mode changes
|
|
*/
|
|
typedef void (*rcsignal_mode_change_callback_t)();
|
|
|
|
/**
|
|
* @brief Initialize RC signal reading
|
|
* @param pin GPIO pin for PWM input (-1 to disable)
|
|
* @return ESP_OK on success
|
|
*/
|
|
esp_err_t rcsignal_init(int8_t pin);
|
|
|
|
/**
|
|
* @brief Deinitialize RC signal reading
|
|
*/
|
|
void rcsignal_deinit(void);
|
|
|
|
/**
|
|
* @brief Register callback for mode changes
|
|
* @param callback Callback function
|
|
*/
|
|
void rcsignal_register_callback(rcsignal_mode_change_callback_t callback);
|
|
|
|
/**
|
|
* @brief Get current PWM pulse width in microseconds
|
|
* @return Pulse width in µs (0 if no signal)
|
|
*/
|
|
uint32_t rcsignal_get_pulse_width(void);
|
|
|
|
/**
|
|
* @brief Check if PWM signal is active
|
|
* @return true if signal detected in last 100ms
|
|
*/
|
|
bool rcsignal_is_active(void);
|
|
|
|
/**
|
|
* @brief Get current mode
|
|
* @return Current animation mode (0-13)
|
|
*/
|
|
uint8_t rcsignal_get_current_mode(void);
|
|
|
|
#ifdef USE_SBUS_MODE
|
|
/**
|
|
* @brief Get SBUS channel value
|
|
* @param channel Channel index (0-15)
|
|
* @return Channel value (172-1811) or 0 if invalid
|
|
*/
|
|
uint16_t rcsignal_get_sbus_channel(uint8_t channel);
|
|
|
|
/**
|
|
* @brief Debug function to print all SBUS channels
|
|
*/
|
|
void rcsignal_debug_print_channels(void);
|
|
#endif
|
|
|
|
#endif // RCSIGNAL_H
|