[feat] UART command interface, per-motor control, filtering modules
- 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>
This commit is contained in:
85
interfaces/uart/uart_if.c
Normal file
85
interfaces/uart/uart_if.c
Normal file
@@ -0,0 +1,85 @@
|
||||
#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);
|
||||
}
|
||||
46
interfaces/uart/uart_if.h
Normal file
46
interfaces/uart/uart_if.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef UART_IF_H
|
||||
#define UART_IF_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
/* UART 配置参数 */
|
||||
typedef struct {
|
||||
uint32_t baud_rate;
|
||||
uint32_t word_length; /* UART_WORDLENGTH_8B / UART_WORDLENGTH_9B */
|
||||
uint32_t stop_bits; /* UART_STOPBITS_1 / UART_STOPBITS_2 */
|
||||
uint32_t parity; /* UART_PARITY_NONE / UART_PARITY_EVEN / UART_PARITY_ODD */
|
||||
} uart_config_t;
|
||||
|
||||
/* 默认配置: 115200-8N1 */
|
||||
#define UART_CONFIG_DEFAULT { 115200, UART_WORDLENGTH_8B, UART_STOPBITS_1, UART_PARITY_NONE }
|
||||
|
||||
typedef struct {
|
||||
int (*init)(int ch, const uart_config_t *cfg);
|
||||
int (*deinit)(int ch);
|
||||
int (*send)(int ch, const uint8_t *data, size_t size, uint32_t timeout);
|
||||
int (*receive)(int ch, uint8_t *data, size_t size, uint32_t timeout);
|
||||
int (*send_it)(int ch, const uint8_t *data, size_t size);
|
||||
int (*receive_it)(int ch, uint8_t *data, size_t size);
|
||||
int (*send_dma)(int ch, const uint8_t *data, size_t size);
|
||||
int (*receive_dma)(int ch, uint8_t *data, size_t size);
|
||||
int (*abort)(int ch);
|
||||
int (*putc)(int ch, uint8_t c);
|
||||
int (*getc)(int ch, uint8_t *c);
|
||||
} uart_ops_t;
|
||||
|
||||
void uart_register_ops(const uart_ops_t *ops);
|
||||
|
||||
int uart_if_init(int ch, const uart_config_t *cfg);
|
||||
int uart_if_deinit(int ch);
|
||||
int uart_if_send(int ch, const uint8_t *data, size_t size, uint32_t timeout);
|
||||
int uart_if_receive(int ch, uint8_t *data, size_t size, uint32_t timeout);
|
||||
int uart_if_send_it(int ch, const uint8_t *data, size_t size);
|
||||
int uart_if_receive_it(int ch, uint8_t *data, size_t size);
|
||||
int uart_if_send_dma(int ch, const uint8_t *data, size_t size);
|
||||
int uart_if_receive_dma(int ch, uint8_t *data, size_t size);
|
||||
int uart_if_abort(int ch);
|
||||
int uart_if_putc(int ch, uint8_t c);
|
||||
int uart_if_getc(int ch, uint8_t *c);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user