sl-firmware 0207c29d8c fix: Resolve all 7 compile errors and 4 linker errors (Issue #337)
COMPILE FIXES:
1. battery.c: Added #include <stdbool.h> for bool type
2. main.c: Updated buzzer_play() to buzzer_play_melody(MELODY_STARTUP)
3. main.c: Replaced bno055_active with bno055_is_ready() calls
4. servo.c: Removed duplicate ServoState typedef from .c file
5. ultrasonic.c: Added forward declaration for HAL_TIM_IC_Init_Compat
6. fan.c: Fixed HAL_TIM_PWM_Start to use handle &htim1 instead of register
7. watchdog.c: Created static IWDG_HandleTypeDef and updated refresh call

LINKER FIXES:
1. i2c1.h/c: Added i2c1_write() and i2c1_read() function implementations
2. servo.c: servo_tick() already exists (verified)
3. bno055.h/c: Added bno055_calibrated() function
4. main.c: Added imu_calibrated() wrapper for bno055_calibrated()
5. crsf.h/c: Added crsf_is_active() function

All 11 errors fixed. Build should now succeed.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-03-03 11:26:27 -05:00

76 lines
2.4 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef CRSF_H
#define CRSF_H
#include <stdint.h>
#include <stdbool.h>
/*
* CRSF/ExpressLRS RC receiver state.
*
* Updated from ISR context on every valid frame.
* Read from main loop — values are naturally atomic (8/16-bit on Cortex-M).
* last_rx_ms == 0 means no frame received yet (USB-only mode).
*/
typedef struct {
uint16_t channels[16]; /* Raw CRSF values, 172 (988µs) 1811 (2012µs) */
uint32_t last_rx_ms; /* HAL_GetTick() at last valid RC frame */
bool armed; /* CH5 arm switch: true when channels[4] > CRSF_ARM_THRESHOLD */
/* Link statistics (from 0x14 frames, optional) */
int8_t rssi_dbm; /* Uplink RSSI in dBm (negative, e.g. -85) */
uint8_t link_quality; /* Uplink link quality 0100 % */
int8_t snr; /* Uplink SNR in dB */
} CRSFState;
/*
* crsf_init() — configure UART4 (PA0=TX, PA1=RX) at 420000 baud with
* DMA1 circular RX and IDLE interrupt. Call once before safety_init().
*/
void crsf_init(void);
/*
* crsf_parse_byte() — feed one byte into the frame parser.
* Called automatically from DMA/IDLE ISR. Available for unit tests.
*/
void crsf_parse_byte(uint8_t byte);
/*
* crsf_to_range() — map raw CRSF value (1721811) linearly to [min, max].
* Clamps at boundaries. Midpoint 992 → (min+max)/2.
*/
int16_t crsf_to_range(uint16_t val, int16_t min, int16_t max);
/*
* crsf_send_battery() — transmit CRSF battery-sensor telemetry frame (type 0x08)
* back to the ELRS TX module over UART4 TX. Call at CRSF_TELEMETRY_HZ (1 Hz).
*
* voltage_mv : battery voltage in millivolts (e.g. 12600 for 3S full)
* current_ma : current draw in milliamps (0 if no sensor)
* remaining_pct: state-of-charge 0100 % (255 = unknown)
*
* Frame: [0xC8][12][0x08][v16_hi][v16_lo][c16_hi][c16_lo][cap24×3][rem][CRC]
* voltage unit: 100 mV (12600 mV → 126)
* current unit: 100 mA
*/
void crsf_send_battery(uint32_t voltage_mv, uint32_t current_ma,
uint8_t remaining_pct);
/*
* crsf_send_flight_mode() — transmit CRSF flight-mode frame (type 0x21)
* for display on the pilot's handset OSD.
*
* armed: true → "ARMED\0"
* false → "DISARM\0"
*/
void crsf_send_flight_mode(bool armed);
extern volatile CRSFState crsf_state;
#endif /* CRSF_H */
/*
* crsf_is_active(now_ms) — check if CRSF link is active.
* Returns true if a valid frame was received within the last 100ms.
*/
bool crsf_is_active(uint32_t now_ms);