Compare commits

..

2 Commits

Author SHA1 Message Date
iorebuild 249409457f 优化架构 2026-06-03 19:53:57 +08:00
iorebuild 9869835739 优化架构 2026-06-01 21:08:05 +08:00
3 changed files with 28 additions and 12 deletions
+2 -5
View File
@@ -48,7 +48,7 @@ typedef struct {
typedef struct { typedef struct {
GPIO_TypeDef *GpioPort; GPIO_TypeDef *GpioPort;
unsigned short GpioPin; unsigned short GpioPin;
unsigned char Irqn; // unsigned char Irqn;
} GPIO_PERIPH_T; } GPIO_PERIPH_T;
typedef struct { typedef struct {
@@ -197,7 +197,7 @@ typedef struct {
#define GPIO111 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_15}} #define GPIO111 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_15}}
#endif #endif
// #define GPIO_NULL ((COM_CONFIG){0, 0, {0, 0}}) #define GPIO_NULL {0, 0, {0, 0}}
/* COM */ /* COM */
typedef struct { typedef struct {
@@ -209,16 +209,13 @@ typedef struct {
void (*ClockCmd)(uint32_t RccPeriph, FunctionalState State); void (*ClockCmd)(uint32_t RccPeriph, FunctionalState State);
unsigned int ClockTree; unsigned int ClockTree;
COM_PERIPH_T Periph; COM_PERIPH_T Periph;
// GPIO_MAP_T TxRxEn; //收发使能
} COM_MAP_T; } COM_MAP_T;
typedef struct { typedef struct {
COM_MAP_T *ComX; //串口外设 COM_MAP_T *ComX; //串口外设
GPIO_MAP_T TxPort; //发送端口 GPIO_MAP_T TxPort; //发送端口
GPIO_MAP_T RxPort; //接收端口 GPIO_MAP_T RxPort; //接收端口
unsigned char Rs485; //是否是Rs485
GPIO_MAP_T TxRxEn; //收发使能 GPIO_MAP_T TxRxEn; //收发使能
GPIOSpeed_TypeDef Speed; //IO口速度
}COM_CONFIG; }COM_CONFIG;
#define COM_NUM 5 #define COM_NUM 5
+22 -7
View File
@@ -25,8 +25,8 @@ const GPIO_CONFIG DO_PERIPH[] = {
#endif #endif
//串口配置表 //串口配置表
const COM_CONFIG COM_PERIPH[] = { const COM_CONFIG COM_PERIPH[] = {
{COM0,.TxPort = GPIO9, .RxPort =GPIO10, .Speed = GPIO_Speed_50MHz,.Rs485 = false}, {COM0,.TxPort = GPIO9, .RxPort =GPIO10},
{COM1,.TxPort = GPIO2, .RxPort = GPIO3, .Speed = GPIO_Speed_50MHz,.Rs485 = true,.TxRxEn = GPIO55}, {COM1,.TxPort = GPIO2, .RxPort = GPIO3,.TxRxEn = GPIO55},
}; };
void BspExtraInit(void); void BspExtraInit(void);
@@ -78,11 +78,8 @@ void BspInit(void) {
//串口配置 //串口配置
for (i = 0;i < ARRAY_LEN(COM_PERIPH);i++) { for (i = 0;i < ARRAY_LEN(COM_PERIPH);i++) {
GpioConfig(&COM_PERIPH[i].TxPort, GPIO_Mode_AF_PP, COM_PERIPH[i].Speed); GpioConfig(&COM_PERIPH[i].TxPort, GPIO_Mode_AF_PP, GPIO_Speed_2MHz);
GpioConfig(&COM_PERIPH[i].RxPort, GPIO_Mode_IPU, COM_PERIPH[i].Speed); GpioConfig(&COM_PERIPH[i].RxPort, GPIO_Mode_IPU, GPIO_Speed_2MHz);
if (COM_PERIPH[i].Rs485 == true) {
GpioConfig(&COM_PERIPH[i].TxRxEn, GPIO_Mode_AF_PP, COM_PERIPH[i].Speed);
}
} }
INTERRUPT_ENABLE INTERRUPT_ENABLE
@@ -160,6 +157,24 @@ void LedToggle(uint8_t Chnl)
GpioSet(&LED_PERIPH[Chnl].GpioX,LED_ON); GpioSet(&LED_PERIPH[Chnl].GpioX,LED_ON);
} }
} }
void Rs485StdConfig(const COM_MAP_T *ComX,unsigned int Baud)
{
for (unsigned char i = 0;i < ARRAY_LEN(COM_PERIPH);i++) {
if (ComX == COM_PERIPH[i].ComX) {
if (COM_PERIPH[i].TxRxEn.ClockTree) {
GpioSet(&COM_PERIPH[i].TxRxEn,Baud);
}
ComStdConfig(COM_PERIPH[i].ComX,Baud);
}
}
}
void Rs485AdvConfig(const COM_MAP_T *ComX, uint32_t Baud, uint8_t DataBits, uint8_t StopBits, uint8_t Parity)
{
}
/** /**
* @brief 重写Printf函数 * @brief 重写Printf函数
* @note void * @note void
+4
View File
@@ -93,4 +93,8 @@ void ComStdConfig(const COM_MAP_T *ComX, uint32_t Baud)
void ComAdvConfig(const COM_MAP_T *ComX, uint32_t Baud, uint8_t DataBits, uint8_t StopBits, uint8_t Parity) void ComAdvConfig(const COM_MAP_T *ComX, uint32_t Baud, uint8_t DataBits, uint8_t StopBits, uint8_t Parity)
{ {
ComInit(ComX, Baud, DataBits, StopBits, Parity); ComInit(ComX, Baud, DataBits, StopBits, Parity);
}
unsigned int CalcBaudTransIoSpeed(unsigned int Baud) {
} }