解决 代码格式问题

添加联系人
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>
<ToolsetNumber>0x4</ToolsetNumber>
<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>
<TargetOption>
<TargetCommonOption>

View File

@ -17,40 +17,40 @@
#define PIN_PORT(pin) ((uint8_t)(((pin) >> 4) & 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)
#define __APM32_PORT_MAX 12u
#define __APM32_PORT_MAX 12u
#elif defined(GPIOK)
#define __APM32_PORT_MAX 11u
#define __APM32_PORT_MAX 11u
#elif defined(GPIOJ)
#define __APM32_PORT_MAX 10u
#define __APM32_PORT_MAX 10u
#elif defined(GPIOI)
#define __APM32_PORT_MAX 9u
#define __APM32_PORT_MAX 9u
#elif defined(GPIOH)
#define __APM32_PORT_MAX 8u
#define __APM32_PORT_MAX 8u
#elif defined(GPIOG)
#define __APM32_PORT_MAX 7u
#define __APM32_PORT_MAX 7u
#elif defined(GPIOF)
#define __APM32_PORT_MAX 6u
#define __APM32_PORT_MAX 6u
#elif defined(GPIOE)
#define __APM32_PORT_MAX 5u
#define __APM32_PORT_MAX 5u
#elif defined(GPIOD)
#define __APM32_PORT_MAX 4u
#define __APM32_PORT_MAX 4u
#elif defined(GPIOC)
#define __APM32_PORT_MAX 3u
#define __APM32_PORT_MAX 3u
#elif defined(GPIOB)
#define __APM32_PORT_MAX 2u
#define __APM32_PORT_MAX 2u
#elif defined(GPIOA)
#define __APM32_PORT_MAX 1u
#define __APM32_PORT_MAX 1u
#else
#define __APM32_PORT_MAX 0u
#error Unsupported APM32 GPIO peripheral.
#define __APM32_PORT_MAX 0u
#error Unsupported APM32 GPIO peripheral.
#endif
#define PIN_STPORT_MAX __APM32_PORT_MAX
#define PIN_APMPORT_MAX __APM32_PORT_MAX
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])
static rt_base_t apm32_pin_get(const char *name)
static rt_base_t _pin_get(const char *name)
{
rt_base_t pin = 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;
}
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;
uint16_t gpio_pin;
if (PIN_PORT(pin) < PIN_STPORT_MAX)
if (PIN_PORT(pin) < PIN_APMPORT_MAX)
{
gpio_port = PIN_STPORT(pin);
gpio_pin = PIN_STPIN(pin);
gpio_port = PIN_APMPORT(pin);
gpio_pin = PIN_APMPIN(pin);
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;
uint16_t gpio_pin;
int value = PIN_LOW;
if (PIN_PORT(pin) < PIN_STPORT_MAX)
if (PIN_PORT(pin) < PIN_APMPORT_MAX)
{
gpio_port = PIN_STPORT(pin);
gpio_pin = PIN_STPIN(pin);
gpio_port = PIN_APMPORT(pin);
gpio_pin = PIN_APMPIN(pin);
value = GPIO_ReadInputBit(gpio_port, gpio_pin);
}
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;
if (PIN_PORT(pin) >= PIN_STPORT_MAX)
if (PIN_PORT(pin) >= PIN_APMPORT_MAX)
{
return;
}
/* Configure gpioConfigure */
gpioConfig.pin = PIN_STPIN(pin);
gpioConfig.pin = PIN_APMPIN(pin);
gpioConfig.mode = GPIO_MODE_OUT_PP;
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;
}
GPIO_Config(PIN_STPORT(pin), &gpioConfig);
GPIO_Config(PIN_APMPORT(pin), &gpioConfig);
}
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];
};
static rt_err_t apm32_pin_attach_irq(struct rt_device *device, rt_int32_t pin,
rt_uint32_t mode, void (*hdr)(void *args), void *args)
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_base_t level;
rt_int32_t irqindex = -1;
if (PIN_PORT(pin) >= PIN_STPORT_MAX)
if (PIN_PORT(pin) >= PIN_APMPORT_MAX)
{
return -RT_ENOSYS;
}
irqindex = bit2bitno(PIN_STPIN(pin));
irqindex = bit2bitno(PIN_APMPIN(pin));
if (irqindex < 0 || irqindex >= ITEM_NUM(pin_irq_map))
{
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();
if (pin_irq_hdr_tab[irqindex].pin == pin &&
pin_irq_hdr_tab[irqindex].hdr == hdr &&
pin_irq_hdr_tab[irqindex].mode == mode &&
pin_irq_hdr_tab[irqindex].args == args)
pin_irq_hdr_tab[irqindex].hdr == hdr &&
pin_irq_hdr_tab[irqindex].mode == mode &&
pin_irq_hdr_tab[irqindex].args == args)
{
rt_hw_interrupt_enable(level);
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;
}
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_int32_t irqindex = -1;
if (PIN_PORT(pin) >= PIN_STPORT_MAX)
if (PIN_PORT(pin) >= PIN_APMPORT_MAX)
{
return -RT_ENOSYS;
}
irqindex = bit2bitno(PIN_STPIN(pin));
irqindex = bit2bitno(PIN_APMPIN(pin));
if (irqindex < 0 || irqindex >= ITEM_NUM(pin_irq_map))
{
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;
}
static rt_err_t apm32_pin_irq_enable(struct rt_device *device, rt_base_t pin,
rt_uint32_t enabled)
static rt_err_t _pin_irq_enable(struct rt_device *device, rt_base_t pin,
rt_uint32_t enabled)
{
const struct pin_irq_map *irqmap;
rt_base_t level;
rt_int32_t irqindex = -1;
GPIO_Config_T gpioConfig;
if (PIN_PORT(pin) >= PIN_STPORT_MAX)
if (PIN_PORT(pin) >= PIN_APMPORT_MAX)
{
return -RT_ENOSYS;
}
if (enabled == PIN_IRQ_ENABLE)
{
irqindex = bit2bitno(PIN_STPIN(pin));
irqindex = bit2bitno(PIN_APMPIN(pin));
if (irqindex < 0 || irqindex >= ITEM_NUM(pin_irq_map))
{
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];
/* Configure gpioConfigure */
gpioConfig.pin = PIN_STPIN(pin);
gpioConfig.pin = PIN_APMPIN(pin);
gpioConfig.speed = GPIO_SPEED_50MHz;
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;
break;
}
GPIO_Config(PIN_STPORT(pin), &gpioConfig);
GPIO_Config(PIN_APMPORT(pin), &gpioConfig);
NVIC_EnableIRQRequest(irqmap->irqno, 5, 0);
pin_irq_enable_mask |= irqmap->pinbit;
@ -354,7 +354,7 @@ static rt_err_t apm32_pin_irq_enable(struct rt_device *device, rt_base_t pin,
}
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)
{
return RT_ENOSYS;
@ -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 =
{
apm32_pin_mode,
apm32_pin_write,
apm32_pin_read,
apm32_pin_attach_irq,
apm32_pin_dettach_irq,
apm32_pin_irq_enable,
apm32_pin_get,
_pin_mode,
_pin_write,
_pin_read,
_pin_attach_irq,
_pin_dettach_irq,
_pin_irq_enable,
_pin_get,
};
rt_inline void pin_irq_hdr(int irqno)
@ -421,7 +421,7 @@ void EINT0_IRQHandler(void)
{
rt_interrupt_enter();
if(EINT_ReadIntFlag(EINT_LINE_0))
if (EINT_ReadIntFlag(EINT_LINE_0))
{
EINT_ClearIntFlag(EINT_LINE_0);
GPIO_EXTI_IRQHandler(GPIO_PIN_0);
@ -433,7 +433,7 @@ void EINT0_IRQHandler(void)
void EINT1_IRQHandler(void)
{
rt_interrupt_enter();
if(EINT_ReadIntFlag(EINT_LINE_1))
if (EINT_ReadIntFlag(EINT_LINE_1))
{
EINT_ClearIntFlag(EINT_LINE_1);
GPIO_EXTI_IRQHandler(GPIO_PIN_1);
@ -444,7 +444,7 @@ void EINT1_IRQHandler(void)
void EINT2_IRQHandler(void)
{
rt_interrupt_enter();
if(EINT_ReadIntFlag(EINT_LINE_2))
if (EINT_ReadIntFlag(EINT_LINE_2))
{
EINT_ClearIntFlag(EINT_LINE_2);
GPIO_EXTI_IRQHandler(GPIO_PIN_2);
@ -455,7 +455,7 @@ void EINT2_IRQHandler(void)
void EINT3_IRQHandler(void)
{
rt_interrupt_enter();
if(EINT_ReadIntFlag(EINT_LINE_3))
if (EINT_ReadIntFlag(EINT_LINE_3))
{
EINT_ClearIntFlag(EINT_LINE_3);
GPIO_EXTI_IRQHandler(GPIO_PIN_3);
@ -466,7 +466,7 @@ void EINT3_IRQHandler(void)
void EINT4_IRQHandler(void)
{
rt_interrupt_enter();
if(EINT_ReadIntFlag(EINT_LINE_4))
if (EINT_ReadIntFlag(EINT_LINE_4))
{
EINT_ClearIntFlag(EINT_LINE_4);
GPIO_EXTI_IRQHandler(GPIO_PIN_4);
@ -477,27 +477,27 @@ void EINT4_IRQHandler(void)
void EINT9_5_IRQHandler(void)
{
rt_interrupt_enter();
if(EINT_ReadIntFlag(EINT_LINE_5))
if (EINT_ReadIntFlag(EINT_LINE_5))
{
EINT_ClearIntFlag(EINT_LINE_5);
GPIO_EXTI_IRQHandler(GPIO_PIN_5);
}
if(EINT_ReadIntFlag(EINT_LINE_6))
if (EINT_ReadIntFlag(EINT_LINE_6))
{
EINT_ClearIntFlag(EINT_LINE_6);
GPIO_EXTI_IRQHandler(GPIO_PIN_6);
}
if(EINT_ReadIntFlag(EINT_LINE_7))
if (EINT_ReadIntFlag(EINT_LINE_7))
{
EINT_ClearIntFlag(EINT_LINE_7);
GPIO_EXTI_IRQHandler(GPIO_PIN_7);
}
if(EINT_ReadIntFlag(EINT_LINE_8))
if (EINT_ReadIntFlag(EINT_LINE_8))
{
EINT_ClearIntFlag(EINT_LINE_8);
GPIO_EXTI_IRQHandler(GPIO_PIN_8);
}
if(EINT_ReadIntFlag(EINT_LINE_9))
if (EINT_ReadIntFlag(EINT_LINE_9))
{
EINT_ClearIntFlag(EINT_LINE_9);
GPIO_EXTI_IRQHandler(GPIO_PIN_9);
@ -508,32 +508,32 @@ void EINT9_5_IRQHandler(void)
void EINT15_10_IRQHandler(void)
{
rt_interrupt_enter();
if(EINT_ReadIntFlag(EINT_LINE_10))
if (EINT_ReadIntFlag(EINT_LINE_10))
{
EINT_ClearIntFlag(EINT_LINE_10);
GPIO_EXTI_IRQHandler(GPIO_PIN_10);
}
if(EINT_ReadIntFlag(EINT_LINE_11))
if (EINT_ReadIntFlag(EINT_LINE_11))
{
EINT_ClearIntFlag(EINT_LINE_11);
GPIO_EXTI_IRQHandler(GPIO_PIN_11);
}
if(EINT_ReadIntFlag(EINT_LINE_12))
if (EINT_ReadIntFlag(EINT_LINE_12))
{
EINT_ClearIntFlag(EINT_LINE_12);
GPIO_EXTI_IRQHandler(GPIO_PIN_12);
}
if(EINT_ReadIntFlag(EINT_LINE_13))
if (EINT_ReadIntFlag(EINT_LINE_13))
{
EINT_ClearIntFlag(EINT_LINE_13);
GPIO_EXTI_IRQHandler(GPIO_PIN_13);
}
if(EINT_ReadIntFlag(EINT_LINE_14))
if (EINT_ReadIntFlag(EINT_LINE_14))
{
EINT_ClearIntFlag(EINT_LINE_14);
GPIO_EXTI_IRQHandler(GPIO_PIN_14);
}
if(EINT_ReadIntFlag(EINT_LINE_15))
if (EINT_ReadIntFlag(EINT_LINE_15))
{
EINT_ClearIntFlag(EINT_LINE_15);
GPIO_EXTI_IRQHandler(GPIO_PIN_15);

View File

@ -14,8 +14,8 @@
#ifdef RT_USING_SERIAL
#if !defined(BSP_USING_UART1) && !defined(BSP_USING_UART2)
#error "Please define at least one BSP_USING_UARTx"
/* this driver can be disabled at menuconfig -> RT-Thread Components -> Device Drivers */
#error "Please define at least one BSP_USING_UARTx"
/* this driver can be disabled at menuconfig -> RT-Thread Components -> Device Drivers */
#endif
/* stm32 config class */
@ -40,18 +40,22 @@ enum
static struct apm32_usart usart_config[] =
{
#ifdef BSP_USING_UART1
{ "uart1",
{
"uart1",
USART1,
USART1_IRQn, },
USART1_IRQn,
},
#endif
#ifdef BSP_USING_UART2
{ "uart2",
{
"uart2",
USART2,
USART2_IRQn, },
USART2_IRQn,
},
#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;
RT_ASSERT(serial != RT_NULL);
@ -117,7 +121,7 @@ static rt_err_t apm32_configure(struct rt_serial_device *serial, struct serial_c
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;
@ -152,7 +156,7 @@ static rt_err_t apm32_control(struct rt_serial_device *serial, int cmd, void *ar
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;
RT_ASSERT(serial != RT_NULL);
@ -168,7 +172,7 @@ static int apm32_putc(struct rt_serial_device *serial, char c)
return 1;
}
static int apm32_getc(struct rt_serial_device *serial)
static int _uart_getc(struct rt_serial_device *serial)
{
int ch;
struct apm32_usart *usart;
@ -211,15 +215,18 @@ static void usart_isr(struct rt_serial_device *serial)
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);
}
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);
}
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);
}
}
@ -258,10 +265,10 @@ void USART2_IRQHandler(void)
static const struct rt_uart_ops apm32_usart_ops =
{
.configure = apm32_configure,
.control = apm32_control,
.putc = apm32_putc,
.getc = apm32_getc,
.configure = _uart_configure,
.control = _uart_control,
.putc = _uart_putc,
.getc = _uart_getc,
.dma_transmit = RT_NULL
};
@ -274,15 +281,16 @@ int rt_hw_usart_init(void)
struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
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.config = config;
/* register USART device */
result = rt_hw_serial_register(&usart_config[index].serial,
usart_config[index].name,
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX
| RT_DEVICE_FLAG_INT_TX, &usart_config[index]);
usart_config[index].name,
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX
| RT_DEVICE_FLAG_INT_TX, &usart_config[index]);
RT_ASSERT(result == RT_EOK);
}