- 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>
77 lines
1.5 KiB
C
77 lines
1.5 KiB
C
#include "uart.h"
|
|
|
|
int uart_init(uart_t *uart, int ch, const uart_config_t *cfg)
|
|
{
|
|
if (!uart || !cfg)
|
|
return -1;
|
|
|
|
uart->ch = ch;
|
|
uart->config = *cfg;
|
|
|
|
int ret = uart_if_init(ch, cfg);
|
|
if (ret == 0)
|
|
uart->initialized = 1;
|
|
|
|
return ret;
|
|
}
|
|
|
|
int uart_deinit(uart_t *uart)
|
|
{
|
|
if (!uart || !uart->initialized)
|
|
return -1;
|
|
|
|
int ret = uart_if_deinit(uart->ch);
|
|
if (ret == 0)
|
|
uart->initialized = 0;
|
|
|
|
return ret;
|
|
}
|
|
|
|
int uart_send(uart_t *uart, const uint8_t *data, size_t size, uint32_t timeout)
|
|
{
|
|
if (!uart || !uart->initialized || !data)
|
|
return -1;
|
|
|
|
return uart_if_send(uart->ch, data, size, timeout);
|
|
}
|
|
|
|
int uart_receive(uart_t *uart, uint8_t *data, size_t size, uint32_t timeout)
|
|
{
|
|
if (!uart || !uart->initialized || !data)
|
|
return -1;
|
|
|
|
return uart_if_receive(uart->ch, data, size, timeout);
|
|
}
|
|
|
|
int uart_send_it(uart_t *uart, const uint8_t *data, size_t size)
|
|
{
|
|
if (!uart || !uart->initialized || !data)
|
|
return -1;
|
|
|
|
return uart_if_send_it(uart->ch, data, size);
|
|
}
|
|
|
|
int uart_receive_it(uart_t *uart, uint8_t *data, size_t size)
|
|
{
|
|
if (!uart || !uart->initialized || !data)
|
|
return -1;
|
|
|
|
return uart_if_receive_it(uart->ch, data, size);
|
|
}
|
|
|
|
int uart_putc(uart_t *uart, uint8_t c)
|
|
{
|
|
if (!uart || !uart->initialized)
|
|
return -1;
|
|
|
|
return uart_if_putc(uart->ch, c);
|
|
}
|
|
|
|
int uart_getc(uart_t *uart, uint8_t *c)
|
|
{
|
|
if (!uart || !uart->initialized || !c)
|
|
return -1;
|
|
|
|
return uart_if_getc(uart->ch, c);
|
|
}
|