gateway/Hardware/src/UART.c

158 lines
3.4 KiB
C
Raw Normal View History

2024-07-13 02:22:47 +00:00
/*
* UART.c
*
* Created on: 2024<EFBFBD><EFBFBD>5<EFBFBD><EFBFBD>18<EFBFBD><EFBFBD>
* Author: 34509
*/
#include "UART.h"
void USARTx_SendByte(USART_TypeDef* pUSARTx, uint8_t data)
{
if (pUSARTx == J5_0_USART) {
rt_pin_write(USART3_DE, write);
}
else if (pUSARTx == J1_USART) {
rt_pin_write(J1_DE, write);
}
else if (pUSARTx == J2_USART) {
rt_pin_write(J2_DE, write);
}
else if (pUSARTx == J3_USART) {
rt_pin_write(J3_DE, write);
}
else if (pUSARTx == J4_USART) {
rt_pin_write(J4_DE, write);
}
else {
return;
}
USART_SendData(pUSARTx, data);
while(USART_GetFlagStatus(pUSARTx, USART_FLAG_TXE) == RESET);
if (pUSARTx == J5_0_USART) {
rt_pin_write(USART3_DE, read);
}
else if (pUSARTx == J1_USART) {
rt_pin_write(J1_DE, read);
}
else if (pUSARTx == J2_USART) {
rt_pin_write(J2_DE, read);
}
else if (pUSARTx == J3_USART) {
rt_pin_write(J3_DE, read);
}
else if (pUSARTx == J4_USART) {
rt_pin_write(J4_DE, read);
}
else {
return;
}
}
2024-07-13 02:22:47 +00:00
void USARTx_SendByte_str(USART_TypeDef* pUSARTx, uint8_t data)
{
USART_SendData(pUSARTx, data);
while(USART_GetFlagStatus(pUSARTx, USART_FLAG_TXE) == RESET);
}
void USARTx_SendStr(USART_TypeDef* pUSARTx, char *str)
{
if (pUSARTx == J5_0_USART) {
rt_pin_write(USART3_DE, write);
}
else if (pUSARTx == J1_USART) {
rt_pin_write(J1_DE, write);
}
else if (pUSARTx == J2_USART) {
rt_pin_write(J2_DE, write);
}
else if (pUSARTx == J3_USART) {
rt_pin_write(J3_DE, write);
}
else if (pUSARTx == J4_USART) {
rt_pin_write(J4_DE, write);
}
else {
return;
}
uint8_t i = 0;
do
{
USARTx_SendByte_str(pUSARTx, *(str+i));
i++;
}while(*(str+i) != '\0');
while(USART_GetFlagStatus(pUSARTx, USART_FLAG_TC) == RESET);
if (pUSARTx == J5_0_USART) {
rt_pin_write(USART3_DE, read);
}
else if (pUSARTx == J1_USART) {
rt_pin_write(J1_DE, read);
}
else if (pUSARTx == J2_USART) {
rt_pin_write(J2_DE, read);
}
else if (pUSARTx == J3_USART) {
rt_pin_write(J3_DE, read);
}
else if (pUSARTx == J4_USART) {
rt_pin_write(J4_DE, read);
}
else {
return;
}
}
void USARTx_SendStr_Len(USART_TypeDef* pUSARTx, char *str, int len)
{
if (pUSARTx == J5_0_USART) {
rt_pin_write(USART3_DE, write);
}
else if (pUSARTx == J1_USART) {
rt_pin_write(J1_DE, write);
}
else if (pUSARTx == J2_USART) {
rt_pin_write(J2_DE, write);
}
else if (pUSARTx == J3_USART) {
rt_pin_write(J3_DE, write);
}
else if (pUSARTx == J4_USART) {
rt_pin_write(J4_DE, write);
}
else {
return;
}
uint8_t i = 0;
do
{
USARTx_SendByte_str(pUSARTx, *(str+i));
i++;
}while(--len);
while(USART_GetFlagStatus(pUSARTx, USART_FLAG_TC) == RESET);
if (pUSARTx == J5_0_USART) {
rt_pin_write(USART3_DE, read);
}
else if (pUSARTx == J1_USART) {
rt_pin_write(J1_DE, read);
}
else if (pUSARTx == J2_USART) {
rt_pin_write(J2_DE, read);
}
else if (pUSARTx == J3_USART) {
rt_pin_write(J3_DE, read);
}
else if (pUSARTx == J4_USART) {
rt_pin_write(J4_DE, read);
}
else {
return;
}
}