Initial commit - sync AliceRC to Gitea

This commit is contained in:
2026-08-03 15:54:25 +08:00
commit 493b7d81d7
1510 changed files with 185319 additions and 0 deletions
@@ -0,0 +1,76 @@
/**
* @file protocol.h
* @brief AliceRC communication protocol definitions
*
* Matches the AliceRX_STC receiver protocol:
* - NRF24L01 32-byte payload
* - Frame ID 0xA0 for channel data
* - ACK payload 0xB0 for telemetry
* - 16 SBUS channels packed as 11-bit little-endian bitstream
*/
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Protocol constants */
#define FRAME_ID_CHANNELS 0xA0
#define FRAME_ID_TELEMETRY 0xB0
#define RF_PAYLOAD_SIZE 32
#define RF_ADDR_SIZE 5
#define SBUS_CHANNEL_COUNT 16
#define SBUS_CHANNEL_BITS 11
/* NRF24L01 TX payload (32 bytes) */
typedef struct __attribute__((packed)) {
uint8_t frame_id; /* 0xA0 = FRAME_ID_CHANNELS */
uint8_t seq; /* Sequence number, wraps around */
uint8_t model_id; /* Currently selected model ID */
uint8_t flags; /* Flags (reserved for future use) */
uint8_t sbus_data[22]; /* 16 channels × 11 bit = 176 bit, little-endian */
uint8_t reserved[6]; /* Reserved for future use */
} rf_tx_payload_t;
/* NRF24L01 ACK payload from receiver (32 bytes) */
typedef struct __attribute__((packed)) {
uint8_t frame_id; /* 0xB0 = FRAME_ID_TELEMETRY */
uint8_t seq; /* Sequence number */
uint16_t battery_mv; /* Battery voltage in mV (big-endian) */
uint8_t reserved[28]; /* Reserved for future use */
} rf_rx_telemetry_t;
/* SBUS channel value range */
#define SBUS_MIN 200
#define SBUS_CENTER 1024
#define SBUS_MAX 1844
/* Function declarations */
/* Initialize protocol module */
void protocol_init(void);
/* Pack SBUS channels into 22-byte bitstream */
void protocol_pack_sbus(const uint16_t *channels, uint8_t *sbus_data);
/* Unpack SBUS channels from 22-byte bitstream */
void protocol_unpack_sbus(const uint8_t *sbus_data, uint16_t *channels);
/* Build TX payload from ADC channel values */
void protocol_build_tx_payload(rf_tx_payload_t *payload,
const uint16_t *adc_channels,
uint8_t model_id,
uint8_t seq);
/* Parse telemetry data from receiver */
void protocol_parse_telemetry(const rf_rx_telemetry_t *telemetry,
uint16_t *battery_mv);
/* Map ADC value (0-4095) to SBUS range (200-1844) */
uint16_t protocol_map_to_sbus(uint16_t adc_value);
#ifdef __cplusplus
}
#endif