- Add callback_task with ISR-based UART command parser (@command\n protocol) - Add log_printf with mutex protection to prevent printf interleaving - Add per-motor enable/disable (motor enable yaw|pitch) - Add PID tuning via UART (pid roll kp 15) - Add cmd_parser module (registration + tokenize + dispatch) - Add UART layer architecture (interface → HAL → BSP) - Add filter modules (lowpass, moving_average, notch, rate_limiter) - Rewrite I2C bus and UART bus modules - Rewrite PID controller and MF4010V2 motor driver - Fix soft I2C driver Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
86 lines
1.9 KiB
C
86 lines
1.9 KiB
C
#include "uart_if.h"
|
|
|
|
static const uart_ops_t *g_uart_ops = 0;
|
|
|
|
void uart_register_ops(const uart_ops_t *ops)
|
|
{
|
|
g_uart_ops = ops;
|
|
}
|
|
|
|
int uart_if_init(int ch, const uart_config_t *cfg)
|
|
{
|
|
if (!g_uart_ops || !g_uart_ops->init)
|
|
return -1;
|
|
return g_uart_ops->init(ch, cfg);
|
|
}
|
|
|
|
int uart_if_deinit(int ch)
|
|
{
|
|
if (!g_uart_ops || !g_uart_ops->deinit)
|
|
return -1;
|
|
return g_uart_ops->deinit(ch);
|
|
}
|
|
|
|
int uart_if_send(int ch, const uint8_t *data, size_t size, uint32_t timeout)
|
|
{
|
|
if (!g_uart_ops || !g_uart_ops->send)
|
|
return -1;
|
|
return g_uart_ops->send(ch, data, size, timeout);
|
|
}
|
|
|
|
int uart_if_receive(int ch, uint8_t *data, size_t size, uint32_t timeout)
|
|
{
|
|
if (!g_uart_ops || !g_uart_ops->receive)
|
|
return -1;
|
|
return g_uart_ops->receive(ch, data, size, timeout);
|
|
}
|
|
|
|
int uart_if_send_it(int ch, const uint8_t *data, size_t size)
|
|
{
|
|
if (!g_uart_ops || !g_uart_ops->send_it)
|
|
return -1;
|
|
return g_uart_ops->send_it(ch, data, size);
|
|
}
|
|
|
|
int uart_if_receive_it(int ch, uint8_t *data, size_t size)
|
|
{
|
|
if (!g_uart_ops || !g_uart_ops->receive_it)
|
|
return -1;
|
|
return g_uart_ops->receive_it(ch, data, size);
|
|
}
|
|
|
|
int uart_if_send_dma(int ch, const uint8_t *data, size_t size)
|
|
{
|
|
if (!g_uart_ops || !g_uart_ops->send_dma)
|
|
return -1;
|
|
return g_uart_ops->send_dma(ch, data, size);
|
|
}
|
|
|
|
int uart_if_receive_dma(int ch, uint8_t *data, size_t size)
|
|
{
|
|
if (!g_uart_ops || !g_uart_ops->receive_dma)
|
|
return -1;
|
|
return g_uart_ops->receive_dma(ch, data, size);
|
|
}
|
|
|
|
int uart_if_abort(int ch)
|
|
{
|
|
if (!g_uart_ops || !g_uart_ops->abort)
|
|
return -1;
|
|
return g_uart_ops->abort(ch);
|
|
}
|
|
|
|
int uart_if_putc(int ch, uint8_t c)
|
|
{
|
|
if (!g_uart_ops || !g_uart_ops->putc)
|
|
return -1;
|
|
return g_uart_ops->putc(ch, c);
|
|
}
|
|
|
|
int uart_if_getc(int ch, uint8_t *c)
|
|
{
|
|
if (!g_uart_ops || !g_uart_ops->getc)
|
|
return -1;
|
|
return g_uart_ops->getc(ch, c);
|
|
}
|