解决 代码格式问题

添加联系人
This commit is contained in:
WuKaiLi 2021-09-05 21:40:55 +08:00
parent c55c964ba4
commit 284c6ffc98
5 changed files with 116 additions and 108 deletions

View File

@ -81,4 +81,4 @@ msh >
## 联系人信息 ## 联系人信息
- -[abbbcc ](https://gitee.com/abbbcc)

View File

@ -10,7 +10,7 @@
<TargetName>rt-thread</TargetName> <TargetName>rt-thread</TargetName>
<ToolsetNumber>0x4</ToolsetNumber> <ToolsetNumber>0x4</ToolsetNumber>
<ToolsetName>ARM-ADS</ToolsetName> <ToolsetName>ARM-ADS</ToolsetName>
<pCCUsed>5060750::V5.06 update 6 (build 750)::ARMCC</pCCUsed> <pCCUsed>5060960::V5.06 update 7 (build 960)::.\ARMCC</pCCUsed>
<uAC6>0</uAC6> <uAC6>0</uAC6>
<TargetOption> <TargetOption>
<TargetCommonOption> <TargetCommonOption>

View File

@ -17,40 +17,40 @@
#define PIN_PORT(pin) ((uint8_t)(((pin) >> 4) & 0xFu)) #define PIN_PORT(pin) ((uint8_t)(((pin) >> 4) & 0xFu))
#define PIN_NO(pin) ((uint8_t)((pin) & 0xFu)) #define PIN_NO(pin) ((uint8_t)((pin) & 0xFu))
#define PIN_STPORT(pin) ((GPIO_T *)(GPIOA_BASE + (0x400u * PIN_PORT(pin)))) #define PIN_APMPORT(pin) ((GPIO_T *)(GPIOA_BASE + (0x400u * PIN_PORT(pin))))
#define PIN_STPIN(pin) ((uint16_t)(1u << PIN_NO(pin))) #define PIN_APMPIN(pin) ((uint16_t)(1u << PIN_NO(pin)))
#if defined(GPIOZ) #if defined(GPIOZ)
#define __APM32_PORT_MAX 12u #define __APM32_PORT_MAX 12u
#elif defined(GPIOK) #elif defined(GPIOK)
#define __APM32_PORT_MAX 11u #define __APM32_PORT_MAX 11u
#elif defined(GPIOJ) #elif defined(GPIOJ)
#define __APM32_PORT_MAX 10u #define __APM32_PORT_MAX 10u
#elif defined(GPIOI) #elif defined(GPIOI)
#define __APM32_PORT_MAX 9u #define __APM32_PORT_MAX 9u
#elif defined(GPIOH) #elif defined(GPIOH)
#define __APM32_PORT_MAX 8u #define __APM32_PORT_MAX 8u
#elif defined(GPIOG) #elif defined(GPIOG)
#define __APM32_PORT_MAX 7u #define __APM32_PORT_MAX 7u
#elif defined(GPIOF) #elif defined(GPIOF)
#define __APM32_PORT_MAX 6u #define __APM32_PORT_MAX 6u
#elif defined(GPIOE) #elif defined(GPIOE)
#define __APM32_PORT_MAX 5u #define __APM32_PORT_MAX 5u
#elif defined(GPIOD) #elif defined(GPIOD)
#define __APM32_PORT_MAX 4u #define __APM32_PORT_MAX 4u
#elif defined(GPIOC) #elif defined(GPIOC)
#define __APM32_PORT_MAX 3u #define __APM32_PORT_MAX 3u
#elif defined(GPIOB) #elif defined(GPIOB)
#define __APM32_PORT_MAX 2u #define __APM32_PORT_MAX 2u
#elif defined(GPIOA) #elif defined(GPIOA)
#define __APM32_PORT_MAX 1u #define __APM32_PORT_MAX 1u
#else #else
#define __APM32_PORT_MAX 0u #define __APM32_PORT_MAX 0u
#error Unsupported APM32 GPIO peripheral. #error Unsupported APM32 GPIO peripheral.
#endif #endif
#define PIN_STPORT_MAX __APM32_PORT_MAX #define PIN_APMPORT_MAX __APM32_PORT_MAX
static const struct pin_irq_map pin_irq_map[] = static const struct pin_irq_map pin_irq_map[] =
{ {
@ -95,7 +95,7 @@ static uint32_t pin_irq_enable_mask = 0;
#define ITEM_NUM(items) sizeof(items) / sizeof(items[0]) #define ITEM_NUM(items) sizeof(items) / sizeof(items[0])
static rt_base_t apm32_pin_get(const char *name) static rt_base_t _pin_get(const char *name)
{ {
rt_base_t pin = 0; rt_base_t pin = 0;
int hw_port_num, hw_pin_num = 0; int hw_port_num, hw_pin_num = 0;
@ -132,47 +132,47 @@ static rt_base_t apm32_pin_get(const char *name)
return pin; return pin;
} }
static void apm32_pin_write(rt_device_t dev, rt_base_t pin, rt_base_t value) static void _pin_write(rt_device_t dev, rt_base_t pin, rt_base_t value)
{ {
GPIO_T *gpio_port; GPIO_T *gpio_port;
uint16_t gpio_pin; uint16_t gpio_pin;
if (PIN_PORT(pin) < PIN_STPORT_MAX) if (PIN_PORT(pin) < PIN_APMPORT_MAX)
{ {
gpio_port = PIN_STPORT(pin); gpio_port = PIN_APMPORT(pin);
gpio_pin = PIN_STPIN(pin); gpio_pin = PIN_APMPIN(pin);
GPIO_WriteBitValue(gpio_port, gpio_pin, (uint8_t)value); GPIO_WriteBitValue(gpio_port, gpio_pin, (uint8_t)value);
} }
} }
static int apm32_pin_read(rt_device_t dev, rt_base_t pin) static int _pin_read(rt_device_t dev, rt_base_t pin)
{ {
GPIO_T *gpio_port; GPIO_T *gpio_port;
uint16_t gpio_pin; uint16_t gpio_pin;
int value = PIN_LOW; int value = PIN_LOW;
if (PIN_PORT(pin) < PIN_STPORT_MAX) if (PIN_PORT(pin) < PIN_APMPORT_MAX)
{ {
gpio_port = PIN_STPORT(pin); gpio_port = PIN_APMPORT(pin);
gpio_pin = PIN_STPIN(pin); gpio_pin = PIN_APMPIN(pin);
value = GPIO_ReadInputBit(gpio_port, gpio_pin); value = GPIO_ReadInputBit(gpio_port, gpio_pin);
} }
return value; return value;
} }
static void apm32_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode) static void _pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode)
{ {
GPIO_Config_T gpioConfig; GPIO_Config_T gpioConfig;
if (PIN_PORT(pin) >= PIN_STPORT_MAX) if (PIN_PORT(pin) >= PIN_APMPORT_MAX)
{ {
return; return;
} }
/* Configure gpioConfigure */ /* Configure gpioConfigure */
gpioConfig.pin = PIN_STPIN(pin); gpioConfig.pin = PIN_APMPIN(pin);
gpioConfig.mode = GPIO_MODE_OUT_PP; gpioConfig.mode = GPIO_MODE_OUT_PP;
gpioConfig.speed = GPIO_SPEED_50MHz; gpioConfig.speed = GPIO_SPEED_50MHz;
@ -202,7 +202,7 @@ static void apm32_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode)
gpioConfig.mode = GPIO_MODE_OUT_OD; gpioConfig.mode = GPIO_MODE_OUT_OD;
} }
GPIO_Config(PIN_STPORT(pin), &gpioConfig); GPIO_Config(PIN_APMPORT(pin), &gpioConfig);
} }
rt_inline rt_int32_t bit2bitno(rt_uint32_t bit) rt_inline rt_int32_t bit2bitno(rt_uint32_t bit)
@ -228,18 +228,18 @@ rt_inline const struct pin_irq_map *get_pin_irq_map(uint32_t pinbit)
return &pin_irq_map[mapindex]; return &pin_irq_map[mapindex];
}; };
static rt_err_t apm32_pin_attach_irq(struct rt_device *device, rt_int32_t pin, static rt_err_t _pin_attach_irq(struct rt_device *device, rt_int32_t pin,
rt_uint32_t mode, void (*hdr)(void *args), void *args) rt_uint32_t mode, void (*hdr)(void *args), void *args)
{ {
rt_base_t level; rt_base_t level;
rt_int32_t irqindex = -1; rt_int32_t irqindex = -1;
if (PIN_PORT(pin) >= PIN_STPORT_MAX) if (PIN_PORT(pin) >= PIN_APMPORT_MAX)
{ {
return -RT_ENOSYS; return -RT_ENOSYS;
} }
irqindex = bit2bitno(PIN_STPIN(pin)); irqindex = bit2bitno(PIN_APMPIN(pin));
if (irqindex < 0 || irqindex >= ITEM_NUM(pin_irq_map)) if (irqindex < 0 || irqindex >= ITEM_NUM(pin_irq_map))
{ {
return RT_ENOSYS; return RT_ENOSYS;
@ -247,9 +247,9 @@ static rt_err_t apm32_pin_attach_irq(struct rt_device *device, rt_int32_t pin,
level = rt_hw_interrupt_disable(); level = rt_hw_interrupt_disable();
if (pin_irq_hdr_tab[irqindex].pin == pin && if (pin_irq_hdr_tab[irqindex].pin == pin &&
pin_irq_hdr_tab[irqindex].hdr == hdr && pin_irq_hdr_tab[irqindex].hdr == hdr &&
pin_irq_hdr_tab[irqindex].mode == mode && pin_irq_hdr_tab[irqindex].mode == mode &&
pin_irq_hdr_tab[irqindex].args == args) pin_irq_hdr_tab[irqindex].args == args)
{ {
rt_hw_interrupt_enable(level); rt_hw_interrupt_enable(level);
return RT_EOK; return RT_EOK;
@ -268,17 +268,17 @@ static rt_err_t apm32_pin_attach_irq(struct rt_device *device, rt_int32_t pin,
return RT_EOK; return RT_EOK;
} }
static rt_err_t apm32_pin_dettach_irq(struct rt_device *device, rt_int32_t pin) static rt_err_t _pin_dettach_irq(struct rt_device *device, rt_int32_t pin)
{ {
rt_base_t level; rt_base_t level;
rt_int32_t irqindex = -1; rt_int32_t irqindex = -1;
if (PIN_PORT(pin) >= PIN_STPORT_MAX) if (PIN_PORT(pin) >= PIN_APMPORT_MAX)
{ {
return -RT_ENOSYS; return -RT_ENOSYS;
} }
irqindex = bit2bitno(PIN_STPIN(pin)); irqindex = bit2bitno(PIN_APMPIN(pin));
if (irqindex < 0 || irqindex >= ITEM_NUM(pin_irq_map)) if (irqindex < 0 || irqindex >= ITEM_NUM(pin_irq_map))
{ {
return RT_ENOSYS; return RT_ENOSYS;
@ -299,22 +299,22 @@ static rt_err_t apm32_pin_dettach_irq(struct rt_device *device, rt_int32_t pin)
return RT_EOK; return RT_EOK;
} }
static rt_err_t apm32_pin_irq_enable(struct rt_device *device, rt_base_t pin, static rt_err_t _pin_irq_enable(struct rt_device *device, rt_base_t pin,
rt_uint32_t enabled) rt_uint32_t enabled)
{ {
const struct pin_irq_map *irqmap; const struct pin_irq_map *irqmap;
rt_base_t level; rt_base_t level;
rt_int32_t irqindex = -1; rt_int32_t irqindex = -1;
GPIO_Config_T gpioConfig; GPIO_Config_T gpioConfig;
if (PIN_PORT(pin) >= PIN_STPORT_MAX) if (PIN_PORT(pin) >= PIN_APMPORT_MAX)
{ {
return -RT_ENOSYS; return -RT_ENOSYS;
} }
if (enabled == PIN_IRQ_ENABLE) if (enabled == PIN_IRQ_ENABLE)
{ {
irqindex = bit2bitno(PIN_STPIN(pin)); irqindex = bit2bitno(PIN_APMPIN(pin));
if (irqindex < 0 || irqindex >= ITEM_NUM(pin_irq_map)) if (irqindex < 0 || irqindex >= ITEM_NUM(pin_irq_map))
{ {
return RT_ENOSYS; return RT_ENOSYS;
@ -331,7 +331,7 @@ static rt_err_t apm32_pin_irq_enable(struct rt_device *device, rt_base_t pin,
irqmap = &pin_irq_map[irqindex]; irqmap = &pin_irq_map[irqindex];
/* Configure gpioConfigure */ /* Configure gpioConfigure */
gpioConfig.pin = PIN_STPIN(pin); gpioConfig.pin = PIN_APMPIN(pin);
gpioConfig.speed = GPIO_SPEED_50MHz; gpioConfig.speed = GPIO_SPEED_50MHz;
switch (pin_irq_hdr_tab[irqindex].mode) switch (pin_irq_hdr_tab[irqindex].mode)
{ {
@ -345,7 +345,7 @@ static rt_err_t apm32_pin_irq_enable(struct rt_device *device, rt_base_t pin,
gpioConfig.mode = GPIO_MODE_IN_FLOATING; gpioConfig.mode = GPIO_MODE_IN_FLOATING;
break; break;
} }
GPIO_Config(PIN_STPORT(pin), &gpioConfig); GPIO_Config(PIN_APMPORT(pin), &gpioConfig);
NVIC_EnableIRQRequest(irqmap->irqno, 5, 0); NVIC_EnableIRQRequest(irqmap->irqno, 5, 0);
pin_irq_enable_mask |= irqmap->pinbit; pin_irq_enable_mask |= irqmap->pinbit;
@ -354,14 +354,14 @@ static rt_err_t apm32_pin_irq_enable(struct rt_device *device, rt_base_t pin,
} }
else if (enabled == PIN_IRQ_DISABLE) else if (enabled == PIN_IRQ_DISABLE)
{ {
irqmap = get_pin_irq_map(PIN_STPIN(pin)); irqmap = get_pin_irq_map(PIN_APMPIN(pin));
if (irqmap == RT_NULL) if (irqmap == RT_NULL)
{ {
return RT_ENOSYS; return RT_ENOSYS;
} }
level = rt_hw_interrupt_disable(); level = rt_hw_interrupt_disable();
pin_irq_enable_mask &= ~irqmap->pinbit; pin_irq_enable_mask &= ~irqmap->pinbit;
if ((irqmap->pinbit >= GPIO_PIN_5) && (irqmap->pinbit <= GPIO_PIN_9)) if ((irqmap->pinbit >= GPIO_PIN_5) && (irqmap->pinbit <= GPIO_PIN_9))
@ -393,13 +393,13 @@ static rt_err_t apm32_pin_irq_enable(struct rt_device *device, rt_base_t pin,
} }
const static struct rt_pin_ops _apm32_pin_ops = const static struct rt_pin_ops _apm32_pin_ops =
{ {
apm32_pin_mode, _pin_mode,
apm32_pin_write, _pin_write,
apm32_pin_read, _pin_read,
apm32_pin_attach_irq, _pin_attach_irq,
apm32_pin_dettach_irq, _pin_dettach_irq,
apm32_pin_irq_enable, _pin_irq_enable,
apm32_pin_get, _pin_get,
}; };
rt_inline void pin_irq_hdr(int irqno) rt_inline void pin_irq_hdr(int irqno)
@ -420,20 +420,20 @@ void GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
void EINT0_IRQHandler(void) void EINT0_IRQHandler(void)
{ {
rt_interrupt_enter(); rt_interrupt_enter();
if(EINT_ReadIntFlag(EINT_LINE_0)) if (EINT_ReadIntFlag(EINT_LINE_0))
{ {
EINT_ClearIntFlag(EINT_LINE_0); EINT_ClearIntFlag(EINT_LINE_0);
GPIO_EXTI_IRQHandler(GPIO_PIN_0); GPIO_EXTI_IRQHandler(GPIO_PIN_0);
} }
rt_interrupt_leave(); rt_interrupt_leave();
} }
void EINT1_IRQHandler(void) void EINT1_IRQHandler(void)
{ {
rt_interrupt_enter(); rt_interrupt_enter();
if(EINT_ReadIntFlag(EINT_LINE_1)) if (EINT_ReadIntFlag(EINT_LINE_1))
{ {
EINT_ClearIntFlag(EINT_LINE_1); EINT_ClearIntFlag(EINT_LINE_1);
GPIO_EXTI_IRQHandler(GPIO_PIN_1); GPIO_EXTI_IRQHandler(GPIO_PIN_1);
@ -444,7 +444,7 @@ void EINT1_IRQHandler(void)
void EINT2_IRQHandler(void) void EINT2_IRQHandler(void)
{ {
rt_interrupt_enter(); rt_interrupt_enter();
if(EINT_ReadIntFlag(EINT_LINE_2)) if (EINT_ReadIntFlag(EINT_LINE_2))
{ {
EINT_ClearIntFlag(EINT_LINE_2); EINT_ClearIntFlag(EINT_LINE_2);
GPIO_EXTI_IRQHandler(GPIO_PIN_2); GPIO_EXTI_IRQHandler(GPIO_PIN_2);
@ -455,7 +455,7 @@ void EINT2_IRQHandler(void)
void EINT3_IRQHandler(void) void EINT3_IRQHandler(void)
{ {
rt_interrupt_enter(); rt_interrupt_enter();
if(EINT_ReadIntFlag(EINT_LINE_3)) if (EINT_ReadIntFlag(EINT_LINE_3))
{ {
EINT_ClearIntFlag(EINT_LINE_3); EINT_ClearIntFlag(EINT_LINE_3);
GPIO_EXTI_IRQHandler(GPIO_PIN_3); GPIO_EXTI_IRQHandler(GPIO_PIN_3);
@ -466,7 +466,7 @@ void EINT3_IRQHandler(void)
void EINT4_IRQHandler(void) void EINT4_IRQHandler(void)
{ {
rt_interrupt_enter(); rt_interrupt_enter();
if(EINT_ReadIntFlag(EINT_LINE_4)) if (EINT_ReadIntFlag(EINT_LINE_4))
{ {
EINT_ClearIntFlag(EINT_LINE_4); EINT_ClearIntFlag(EINT_LINE_4);
GPIO_EXTI_IRQHandler(GPIO_PIN_4); GPIO_EXTI_IRQHandler(GPIO_PIN_4);
@ -477,27 +477,27 @@ void EINT4_IRQHandler(void)
void EINT9_5_IRQHandler(void) void EINT9_5_IRQHandler(void)
{ {
rt_interrupt_enter(); rt_interrupt_enter();
if(EINT_ReadIntFlag(EINT_LINE_5)) if (EINT_ReadIntFlag(EINT_LINE_5))
{ {
EINT_ClearIntFlag(EINT_LINE_5); EINT_ClearIntFlag(EINT_LINE_5);
GPIO_EXTI_IRQHandler(GPIO_PIN_5); GPIO_EXTI_IRQHandler(GPIO_PIN_5);
} }
if(EINT_ReadIntFlag(EINT_LINE_6)) if (EINT_ReadIntFlag(EINT_LINE_6))
{ {
EINT_ClearIntFlag(EINT_LINE_6); EINT_ClearIntFlag(EINT_LINE_6);
GPIO_EXTI_IRQHandler(GPIO_PIN_6); GPIO_EXTI_IRQHandler(GPIO_PIN_6);
} }
if(EINT_ReadIntFlag(EINT_LINE_7)) if (EINT_ReadIntFlag(EINT_LINE_7))
{ {
EINT_ClearIntFlag(EINT_LINE_7); EINT_ClearIntFlag(EINT_LINE_7);
GPIO_EXTI_IRQHandler(GPIO_PIN_7); GPIO_EXTI_IRQHandler(GPIO_PIN_7);
} }
if(EINT_ReadIntFlag(EINT_LINE_8)) if (EINT_ReadIntFlag(EINT_LINE_8))
{ {
EINT_ClearIntFlag(EINT_LINE_8); EINT_ClearIntFlag(EINT_LINE_8);
GPIO_EXTI_IRQHandler(GPIO_PIN_8); GPIO_EXTI_IRQHandler(GPIO_PIN_8);
} }
if(EINT_ReadIntFlag(EINT_LINE_9)) if (EINT_ReadIntFlag(EINT_LINE_9))
{ {
EINT_ClearIntFlag(EINT_LINE_9); EINT_ClearIntFlag(EINT_LINE_9);
GPIO_EXTI_IRQHandler(GPIO_PIN_9); GPIO_EXTI_IRQHandler(GPIO_PIN_9);
@ -508,32 +508,32 @@ void EINT9_5_IRQHandler(void)
void EINT15_10_IRQHandler(void) void EINT15_10_IRQHandler(void)
{ {
rt_interrupt_enter(); rt_interrupt_enter();
if(EINT_ReadIntFlag(EINT_LINE_10)) if (EINT_ReadIntFlag(EINT_LINE_10))
{ {
EINT_ClearIntFlag(EINT_LINE_10); EINT_ClearIntFlag(EINT_LINE_10);
GPIO_EXTI_IRQHandler(GPIO_PIN_10); GPIO_EXTI_IRQHandler(GPIO_PIN_10);
} }
if(EINT_ReadIntFlag(EINT_LINE_11)) if (EINT_ReadIntFlag(EINT_LINE_11))
{ {
EINT_ClearIntFlag(EINT_LINE_11); EINT_ClearIntFlag(EINT_LINE_11);
GPIO_EXTI_IRQHandler(GPIO_PIN_11); GPIO_EXTI_IRQHandler(GPIO_PIN_11);
} }
if(EINT_ReadIntFlag(EINT_LINE_12)) if (EINT_ReadIntFlag(EINT_LINE_12))
{ {
EINT_ClearIntFlag(EINT_LINE_12); EINT_ClearIntFlag(EINT_LINE_12);
GPIO_EXTI_IRQHandler(GPIO_PIN_12); GPIO_EXTI_IRQHandler(GPIO_PIN_12);
} }
if(EINT_ReadIntFlag(EINT_LINE_13)) if (EINT_ReadIntFlag(EINT_LINE_13))
{ {
EINT_ClearIntFlag(EINT_LINE_13); EINT_ClearIntFlag(EINT_LINE_13);
GPIO_EXTI_IRQHandler(GPIO_PIN_13); GPIO_EXTI_IRQHandler(GPIO_PIN_13);
} }
if(EINT_ReadIntFlag(EINT_LINE_14)) if (EINT_ReadIntFlag(EINT_LINE_14))
{ {
EINT_ClearIntFlag(EINT_LINE_14); EINT_ClearIntFlag(EINT_LINE_14);
GPIO_EXTI_IRQHandler(GPIO_PIN_14); GPIO_EXTI_IRQHandler(GPIO_PIN_14);
} }
if(EINT_ReadIntFlag(EINT_LINE_15)) if (EINT_ReadIntFlag(EINT_LINE_15))
{ {
EINT_ClearIntFlag(EINT_LINE_15); EINT_ClearIntFlag(EINT_LINE_15);
GPIO_EXTI_IRQHandler(GPIO_PIN_15); GPIO_EXTI_IRQHandler(GPIO_PIN_15);

View File

@ -14,8 +14,8 @@
#ifdef RT_USING_SERIAL #ifdef RT_USING_SERIAL
#if !defined(BSP_USING_UART1) && !defined(BSP_USING_UART2) #if !defined(BSP_USING_UART1) && !defined(BSP_USING_UART2)
#error "Please define at least one BSP_USING_UARTx" #error "Please define at least one BSP_USING_UARTx"
/* this driver can be disabled at menuconfig -> RT-Thread Components -> Device Drivers */ /* this driver can be disabled at menuconfig -> RT-Thread Components -> Device Drivers */
#endif #endif
/* stm32 config class */ /* stm32 config class */
@ -40,18 +40,22 @@ enum
static struct apm32_usart usart_config[] = static struct apm32_usart usart_config[] =
{ {
#ifdef BSP_USING_UART1 #ifdef BSP_USING_UART1
{ "uart1", {
"uart1",
USART1, USART1,
USART1_IRQn, }, USART1_IRQn,
},
#endif #endif
#ifdef BSP_USING_UART2 #ifdef BSP_USING_UART2
{ "uart2", {
"uart2",
USART2, USART2,
USART2_IRQn, }, USART2_IRQn,
},
#endif #endif
}; };
static rt_err_t apm32_configure(struct rt_serial_device *serial, struct serial_configure *cfg) static rt_err_t _uart_configure(struct rt_serial_device *serial, struct serial_configure *cfg)
{ {
USART_Config_T USART_ConfigStruct; USART_Config_T USART_ConfigStruct;
RT_ASSERT(serial != RT_NULL); RT_ASSERT(serial != RT_NULL);
@ -60,7 +64,7 @@ static rt_err_t apm32_configure(struct rt_serial_device *serial, struct serial_c
struct apm32_usart *usart_instance = (struct apm32_usart *) serial->parent.user_data; struct apm32_usart *usart_instance = (struct apm32_usart *) serial->parent.user_data;
apm32_usart_init(); apm32_usart_init();
USART_ConfigStruct.baudRate = cfg->baud_rate;; USART_ConfigStruct.baudRate = cfg->baud_rate;;
USART_ConfigStruct.hardwareFlow = USART_HARDWARE_FLOW_NONE; USART_ConfigStruct.hardwareFlow = USART_HARDWARE_FLOW_NONE;
USART_ConfigStruct.mode = USART_MODE_TX_RX; USART_ConfigStruct.mode = USART_MODE_TX_RX;
@ -113,14 +117,14 @@ static rt_err_t apm32_configure(struct rt_serial_device *serial, struct serial_c
USART_Config(usart_instance->usartx, &USART_ConfigStruct); USART_Config(usart_instance->usartx, &USART_ConfigStruct);
USART_Enable(usart_instance->usartx); USART_Enable(usart_instance->usartx);
return RT_EOK; return RT_EOK;
} }
static rt_err_t apm32_control(struct rt_serial_device *serial, int cmd, void *arg) static rt_err_t _uart_control(struct rt_serial_device *serial, int cmd, void *arg)
{ {
struct apm32_usart *usart; struct apm32_usart *usart;
RT_ASSERT(serial != RT_NULL); RT_ASSERT(serial != RT_NULL);
usart = (struct apm32_usart *) serial->parent.user_data; usart = (struct apm32_usart *) serial->parent.user_data;
@ -130,10 +134,10 @@ static rt_err_t apm32_control(struct rt_serial_device *serial, int cmd, void *ar
{ {
/* disable interrupt */ /* disable interrupt */
case RT_DEVICE_CTRL_CLR_INT: case RT_DEVICE_CTRL_CLR_INT:
/* disable rx irq */ /* disable rx irq */
NVIC_DisableIRQRequest(usart->irq_type); NVIC_DisableIRQRequest(usart->irq_type);
/* disable interrupt */ /* disable interrupt */
USART_DisableInterrupt(usart->usartx, USART_INT_RXBNE); USART_DisableInterrupt(usart->usartx, USART_INT_RXBNE);
@ -143,7 +147,7 @@ static rt_err_t apm32_control(struct rt_serial_device *serial, int cmd, void *ar
case RT_DEVICE_CTRL_SET_INT: case RT_DEVICE_CTRL_SET_INT:
/* enable rx irq */ /* enable rx irq */
NVIC_EnableIRQRequest(usart->irq_type, 1, 0); NVIC_EnableIRQRequest(usart->irq_type, 1, 0);
/* enable interrupt */ /* enable interrupt */
USART_EnableInterrupt(usart->usartx, USART_INT_RXBNE); USART_EnableInterrupt(usart->usartx, USART_INT_RXBNE);
break; break;
@ -152,29 +156,29 @@ static rt_err_t apm32_control(struct rt_serial_device *serial, int cmd, void *ar
return RT_EOK; return RT_EOK;
} }
static int apm32_putc(struct rt_serial_device *serial, char c) static int _uart_putc(struct rt_serial_device *serial, char c)
{ {
struct apm32_usart *usart; struct apm32_usart *usart;
RT_ASSERT(serial != RT_NULL); RT_ASSERT(serial != RT_NULL);
usart = (struct apm32_usart *) serial->parent.user_data; usart = (struct apm32_usart *) serial->parent.user_data;
RT_ASSERT(usart != RT_NULL); RT_ASSERT(usart != RT_NULL);
USART_TxData(usart->usartx, (uint8_t) c); USART_TxData(usart->usartx, (uint8_t) c);
while (USART_ReadStatusFlag(usart->usartx, USART_FLAG_TXC) == RESET); while (USART_ReadStatusFlag(usart->usartx, USART_FLAG_TXC) == RESET);
return 1; return 1;
} }
static int apm32_getc(struct rt_serial_device *serial) static int _uart_getc(struct rt_serial_device *serial)
{ {
int ch; int ch;
struct apm32_usart *usart; struct apm32_usart *usart;
RT_ASSERT(serial != RT_NULL); RT_ASSERT(serial != RT_NULL);
usart = (struct apm32_usart *) serial->parent.user_data; usart = (struct apm32_usart *) serial->parent.user_data;
RT_ASSERT(usart != RT_NULL); RT_ASSERT(usart != RT_NULL);
ch = -1; ch = -1;
@ -197,7 +201,7 @@ static void usart_isr(struct rt_serial_device *serial)
RT_ASSERT(serial != RT_NULL); RT_ASSERT(serial != RT_NULL);
RT_ASSERT(serial != RT_NULL); RT_ASSERT(serial != RT_NULL);
usart = (struct apm32_usart *) serial->parent.user_data; usart = (struct apm32_usart *) serial->parent.user_data;
RT_ASSERT(usart != RT_NULL); RT_ASSERT(usart != RT_NULL);
/* UART in mode Receiver -------------------------------------------------*/ /* UART in mode Receiver -------------------------------------------------*/
@ -211,15 +215,18 @@ static void usart_isr(struct rt_serial_device *serial)
else else
{ {
if (USART_ReadStatusFlag(usart->usartx, USART_FLAG_CTS) != RESET) { if (USART_ReadStatusFlag(usart->usartx, USART_FLAG_CTS) != RESET)
{
USART_ClearStatusFlag(usart->usartx, USART_FLAG_CTS); USART_ClearStatusFlag(usart->usartx, USART_FLAG_CTS);
} }
if (USART_ReadStatusFlag(usart->usartx, USART_FLAG_LBD) != RESET) { if (USART_ReadStatusFlag(usart->usartx, USART_FLAG_LBD) != RESET)
{
USART_ClearStatusFlag(usart->usartx, USART_FLAG_LBD); USART_ClearStatusFlag(usart->usartx, USART_FLAG_LBD);
} }
if (USART_ReadStatusFlag(usart->usartx, USART_FLAG_TXBE) != RESET) { if (USART_ReadStatusFlag(usart->usartx, USART_FLAG_TXBE) != RESET)
{
USART_ClearStatusFlag(usart->usartx, USART_FLAG_TXBE); USART_ClearStatusFlag(usart->usartx, USART_FLAG_TXBE);
} }
} }
@ -258,10 +265,10 @@ void USART2_IRQHandler(void)
static const struct rt_uart_ops apm32_usart_ops = static const struct rt_uart_ops apm32_usart_ops =
{ {
.configure = apm32_configure, .configure = _uart_configure,
.control = apm32_control, .control = _uart_control,
.putc = apm32_putc, .putc = _uart_putc,
.getc = apm32_getc, .getc = _uart_getc,
.dma_transmit = RT_NULL .dma_transmit = RT_NULL
}; };
@ -274,15 +281,16 @@ int rt_hw_usart_init(void)
struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT; struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
rt_err_t result = 0; rt_err_t result = 0;
for (index = 0; index < obj_num; index++) { for (index = 0; index < obj_num; index++)
{
usart_config[index].serial.ops = &apm32_usart_ops; usart_config[index].serial.ops = &apm32_usart_ops;
usart_config[index].serial.config = config; usart_config[index].serial.config = config;
/* register USART device */ /* register USART device */
result = rt_hw_serial_register(&usart_config[index].serial, result = rt_hw_serial_register(&usart_config[index].serial,
usart_config[index].name, usart_config[index].name,
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX
| RT_DEVICE_FLAG_INT_TX, &usart_config[index]); | RT_DEVICE_FLAG_INT_TX, &usart_config[index]);
RT_ASSERT(result == RT_EOK); RT_ASSERT(result == RT_EOK);
} }