diff --git a/Bsp/Inc/Bsp.h b/Bsp/Inc/Bsp.h index 13d7714..7706cd5 100644 --- a/Bsp/Inc/Bsp.h +++ b/Bsp/Inc/Bsp.h @@ -1,8 +1,6 @@ #ifndef __BSP_H__ #define __BSP_H__ -/* Voilet Bsp */ -#include "VoiletPort.h" /* Board */ #include "Board.h" diff --git a/Bsp/Inc/VoiletPort.h b/Bsp/Inc/VoiletPort.h index 9651097..b657848 100644 --- a/Bsp/Inc/VoiletPort.h +++ b/Bsp/Inc/VoiletPort.h @@ -16,7 +16,23 @@ typedef enum { false = 0, true = 1, -} bool_t; +} BOOL_MAP_T; + +/* DI数字信号采集枚举 */ +enum { + DI_OFF = 0, + DI_ON +}; +/* DO数字信号输出枚举 */ +enum { + DO_OFF = 0, + DO_ON +}; +/* LED灯输出枚举 */ +enum { + LED_OFF = 0, + LED_ON +}; /* Interrupt Irq */ typedef struct { @@ -181,6 +197,8 @@ typedef struct { #define GPIO111 {RCC_APB2PeriphClockCmd, RCC_APB2Periph_GPIOG, {GPIOG, GPIO_Pin_15}} #endif +// #define GPIO_NULL ((COM_CONFIG){0, 0, {0, 0}}) + /* COM */ typedef struct { USART_TypeDef *UartId; @@ -191,15 +209,19 @@ typedef struct { void (*ClockCmd)(uint32_t RccPeriph, FunctionalState State); unsigned int ClockTree; COM_PERIPH_T Periph; + // GPIO_MAP_T TxRxEn; //收发使能 } COM_MAP_T; typedef struct { - COM_MAP_T *ComX; - GPIO_MAP_T TxPort; - GPIO_MAP_T RxPort; - GPIOSpeed_TypeDef Speed; + COM_MAP_T *ComX; //串口外设 + GPIO_MAP_T TxPort; //发送端口 + GPIO_MAP_T RxPort; //接收端口 + unsigned char Rs485; //是否是Rs485 + GPIO_MAP_T TxRxEn; //收发使能 + GPIOSpeed_TypeDef Speed; //IO口速度 }COM_CONFIG; +#define COM_NUM 5 #ifdef USART1 #define COM0 (&(COM_MAP_T){RCC_APB2PeriphClockCmd, RCC_APB2Periph_USART1, {USART1,USART1_IRQn}}) #endif diff --git a/Bsp/Src/Bsp.c b/Bsp/Src/Bsp.c index c4dd95c..a07c6e6 100644 --- a/Bsp/Src/Bsp.c +++ b/Bsp/Src/Bsp.c @@ -25,8 +25,8 @@ const GPIO_CONFIG DO_PERIPH[] = { #endif //串口配置表 const COM_CONFIG COM_PERIPH[] = { - {COM0,.TxPort = GPIO9, .RxPort =GPIO10, .Speed = GPIO_Speed_50MHz}, - {COM1,.TxPort = GPIO2, .RxPort = GPIO3, .Speed = GPIO_Speed_50MHz}, + {COM0,.TxPort = GPIO9, .RxPort =GPIO10, .Speed = GPIO_Speed_50MHz,.Rs485 = false}, + {COM1,.TxPort = GPIO2, .RxPort = GPIO3, .Speed = GPIO_Speed_50MHz,.Rs485 = true,.TxRxEn = GPIO55}, }; void BspExtraInit(void); @@ -80,6 +80,9 @@ void BspInit(void) { 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].RxPort, GPIO_Mode_IPU, COM_PERIPH[i].Speed); + if (COM_PERIPH[i].Rs485 == true) { + GpioConfig(&COM_PERIPH[i].TxRxEn, GPIO_Mode_AF_PP, COM_PERIPH[i].Speed); + } } INTERRUPT_ENABLE diff --git a/Bsp/Src/Uart.c b/Bsp/Src/Uart.c index bf2e2eb..2796a41 100644 --- a/Bsp/Src/Uart.c +++ b/Bsp/Src/Uart.c @@ -1,5 +1,7 @@ #include "Bsp.h" +extern const COM_CONFIG COM_PERIPH[]; + /** * @brief 初始化UART口外设的时钟 * @note void