mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-02-28 01:57:05 +08:00
解决 代码格式问题
添加联系人
This commit is contained in:
parent
c55c964ba4
commit
284c6ffc98
@ -81,4 +81,4 @@ msh >
|
|||||||
|
|
||||||
## 联系人信息
|
## 联系人信息
|
||||||
|
|
||||||
-
|
-[abbbcc ](https://gitee.com/abbbcc)
|
@ -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>
|
||||||
|
@ -17,9 +17,9 @@
|
|||||||
#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
|
||||||
@ -50,7 +50,7 @@
|
|||||||
#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;
|
||||||
@ -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,7 +299,7 @@ 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;
|
||||||
@ -307,14 +307,14 @@ static rt_err_t apm32_pin_irq_enable(struct rt_device *device, rt_base_t pin,
|
|||||||
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,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)
|
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;
|
||||||
@ -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)
|
||||||
|
@ -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);
|
||||||
@ -117,7 +121,7 @@ static rt_err_t apm32_configure(struct rt_serial_device *serial, struct serial_c
|
|||||||
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;
|
||||||
|
|
||||||
@ -152,7 +156,7 @@ 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);
|
||||||
@ -168,7 +172,7 @@ static int apm32_putc(struct rt_serial_device *serial, char c)
|
|||||||
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;
|
||||||
@ -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,7 +281,8 @@ 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;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user