Add USB command interface for live PID gain adjustment without reflashing:
P<kp> I<ki> D<kd> T<setpoint_deg> M<max_speed> ?
Command parsing runs in main loop (sscanf-safe), not in USB IRQ.
USB IRQ copies command to shared volatile buffer (cdc_cmd_buf), sets flag.
Acknowledgement echoes current gains: {"kp":...,"ki":...,"kd":...}
Bounds checking: kp 0-500, ki/kd 0-50, setpoint ±20°, max_speed 0-1000.
Gains validated before write — silently ignored if out of range.
Telemetry updated from raw counts to physical tuning signals:
pitch (°x10), pitch_rate (°/s x10), error (°x10),
integral (x10 for windup monitoring), motor_cmd, state
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
18 lines
450 B
C
18 lines
450 B
C
#ifndef USBD_CDC_IF_H
|
|
#define USBD_CDC_IF_H
|
|
|
|
#include "usbd_cdc.h"
|
|
|
|
extern USBD_CDC_ItfTypeDef USBD_CDC_fops;
|
|
|
|
/* Send data over USB CDC */
|
|
uint8_t CDC_Transmit(uint8_t *buf, uint16_t len);
|
|
|
|
/* Betaflight-style DFU reboot check — call early in main() */
|
|
void checkForBootloader(void);
|
|
|
|
/* PID tuning command interface (written by USB IRQ, read by main loop) */
|
|
extern volatile uint8_t cdc_cmd_ready;
|
|
extern volatile char cdc_cmd_buf[32];
|
|
#endif
|