1.新增PIN驱动。
2.优化原有驱动。
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
menu "Driver configure"
|
||||
|
||||
# ADC
|
||||
source "driver/adc/Kconfig"
|
||||
|
||||
# Serial
|
||||
source "driver/serial/Kconfig"
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -107,8 +107,31 @@ extern "C" {
|
||||
.port = NULL, \
|
||||
.pin = 0}, \
|
||||
}
|
||||
#define _DRIVER_ADC_CHANNELS (0x3ffff)
|
||||
#define _DRIVER_ADC_RESOLUTION (12)
|
||||
#endif /* defined(MR_USE_ADC1) || defined(MR_USE_ADC2) */
|
||||
|
||||
#define _DRIVER_PIN_IRQ_CONFIG \
|
||||
{ \
|
||||
EXTI0_IRQn, EXTI1_IRQn, EXTI2_IRQn, EXTI3_IRQn, EXTI4_IRQn, \
|
||||
EXTI9_5_IRQn, EXTI9_5_IRQn, EXTI9_5_IRQn, EXTI9_5_IRQn, \
|
||||
EXTI9_5_IRQn, EXTI15_10_IRQn, EXTI15_10_IRQn, EXTI15_10_IRQn, \
|
||||
EXTI15_10_IRQn, EXTI15_10_IRQn, EXTI15_10_IRQn, \
|
||||
}
|
||||
|
||||
#define _DRIVER_PIN_PORT_CONFIG \
|
||||
{ \
|
||||
GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, \
|
||||
}
|
||||
|
||||
#define _DRIVER_PIN_PIN_CONFIG \
|
||||
{ \
|
||||
GPIO_Pin_0, GPIO_Pin_1, GPIO_Pin_2, GPIO_Pin_3, GPIO_Pin_4, \
|
||||
GPIO_Pin_5, GPIO_Pin_6, GPIO_Pin_7, GPIO_Pin_8, GPIO_Pin_9, \
|
||||
GPIO_Pin_10, GPIO_Pin_11, GPIO_Pin_12, GPIO_Pin_13, GPIO_Pin_14, \
|
||||
GPIO_Pin_15, \
|
||||
}
|
||||
|
||||
#if (MR_CFG_UART1_GROUP == 1)
|
||||
#define _DRIVER_UART1_CONFIG \
|
||||
{ \
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
menu "Driver configure"
|
||||
# Replace driver prompt
|
||||
comment "Please use the driver of the corresponding model to replace the driver"
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -3,13 +3,14 @@ menu "ADC driver configure"
|
||||
if MR_USE_ADC
|
||||
# ADC1
|
||||
config MR_USE_ADC1
|
||||
bool "Use ADC1 driver"
|
||||
bool "Use adc1 driver"
|
||||
default n
|
||||
|
||||
# ADC2
|
||||
config MR_USE_ADC2
|
||||
bool "Use ADC2 driver"
|
||||
bool "Use adc2 driver"
|
||||
default n
|
||||
endif
|
||||
|
||||
# Unused adc prompt
|
||||
if !MR_USE_ADC
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
#if !defined(MR_USE_ADC1) && !defined(MR_USE_ADC2)
|
||||
#warning "Please enable at least one ADC driver"
|
||||
#endif /* !defined(MR_USE_ADC1) && !defined(MR_USE_ADC2) */
|
||||
#else
|
||||
|
||||
enum _adc_driver_index
|
||||
{
|
||||
@@ -50,6 +50,10 @@ static struct mr_adc _adc_device[MR_ARRAY_NUM(_adc_device_path)];
|
||||
|
||||
MR_INLINE struct mr_adc_driver_channel *_adc_channel_get(uint32_t channel)
|
||||
{
|
||||
if (channel >= MR_ARRAY_NUM(_adc_driver_channel))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
return &_adc_driver_channel[channel];
|
||||
}
|
||||
|
||||
@@ -84,6 +88,11 @@ static int adc_driver_channel_configure(struct mr_driver *driver,
|
||||
struct mr_adc_driver_channel *adc_channel = _adc_channel_get(channel);
|
||||
GPIO_InitTypeDef GPIO_InitStructure = {0};
|
||||
|
||||
if (adc_channel == NULL)
|
||||
{
|
||||
return MR_EINVAL;
|
||||
}
|
||||
|
||||
/* Configure clock */
|
||||
RCC_APB2PeriphClockCmd(adc_channel->gpio_clock, ENABLE);
|
||||
|
||||
@@ -113,6 +122,11 @@ static int adc_driver_read(struct mr_driver *driver, uint32_t channel,
|
||||
struct mr_adc_driver_channel *adc_channel = _adc_channel_get(channel);
|
||||
size_t i = 0;
|
||||
|
||||
if (adc_channel == NULL)
|
||||
{
|
||||
return MR_EINVAL;
|
||||
}
|
||||
|
||||
/* Read data */
|
||||
#ifdef MR_USE_CH32V00X
|
||||
ADC_RegularChannelConfig(adc->instance, adc_channel->channel, 1,
|
||||
@@ -141,14 +155,20 @@ static void adc_driver_init(void)
|
||||
.channel_configure =
|
||||
adc_driver_channel_configure,
|
||||
.read = adc_driver_read};
|
||||
static struct mr_adc_driver_data data = {
|
||||
.channels = _DRIVER_ADC_CHANNELS,
|
||||
.resolution = _DRIVER_ADC_RESOLUTION};
|
||||
|
||||
for (size_t i = 0; i < MR_ARRAY_NUM(_adc_device); i++)
|
||||
{
|
||||
_adc_driver[i].driver.ops = &ops;
|
||||
_adc_driver[i].driver.data = &data;
|
||||
mr_adc_register(&_adc_device[i], _adc_device_path[i],
|
||||
(struct mr_driver *)&_adc_driver[i]);
|
||||
}
|
||||
}
|
||||
MR_INIT_DRIVER_EXPORT(adc_driver_init);
|
||||
|
||||
#endif /* !defined(MR_USE_ADC1) && !defined(MR_USE_ADC2) */
|
||||
|
||||
#endif /* MR_USE_ADC */
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
* @date 2023-11-11 MacRsh First version
|
||||
*/
|
||||
|
||||
#ifndef _MR_DRIVER_ADC_H_
|
||||
#define _MR_DRIVER_ADC_H_
|
||||
#ifndef _MR_ADC_DRIVER_H_
|
||||
#define _MR_ADC_DRIVER_H_
|
||||
|
||||
#include "../mr-library/device/include/mr_adc.h"
|
||||
#include "../mr-library/driver/include/mr_board.h"
|
||||
@@ -39,4 +39,4 @@ struct mr_adc_driver_channel
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _MR_DRIVER_ADC_H_ */
|
||||
#endif /* _MR_ADC_DRIVER_H_ */
|
||||
|
||||
37
bsp/wch/driver/include/mr_pin.h
Normal file
37
bsp/wch/driver/include/mr_pin.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* @copyright (c) 2023-2024, MR Development Team
|
||||
*
|
||||
* @license SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* @date 2023-11-11 MacRsh First version
|
||||
*/
|
||||
|
||||
#ifndef _MR_PIN_DRIVER_H_
|
||||
#define _MR_PIN_DRIVER_H_
|
||||
|
||||
#include "../mr-library/device/include/mr_pin.h"
|
||||
#include "../mr-library/driver/include/mr_board.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifdef MR_USE_PIN
|
||||
|
||||
struct mr_pin_driver_port
|
||||
{
|
||||
GPIO_TypeDef *port;
|
||||
};
|
||||
|
||||
struct mr_pin_driver_pin
|
||||
{
|
||||
uint32_t pin;
|
||||
};
|
||||
|
||||
#endif /* MR_USE_PIN */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _MR_PIN_DRIVER_H_ */
|
||||
@@ -6,8 +6,8 @@
|
||||
* @date 2023-11-10 MacRsh First version
|
||||
*/
|
||||
|
||||
#ifndef _MR_DRIVER_SERIAL_H_
|
||||
#define _MR_DRIVER_SERIAL_H_
|
||||
#ifndef _MR_SERIAL_DRIVER_H_
|
||||
#define _MR_SERIAL_DRIVER_H_
|
||||
|
||||
#include "../mr-library/device/include/mr_serial.h"
|
||||
#include "../mr-library/driver/include/mr_board.h"
|
||||
@@ -38,4 +38,4 @@ struct mr_serial_driver
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _MR_DRIVER_SERIAL_H_ */
|
||||
#endif /* _MR_SERIAL_DRIVER_H_ */
|
||||
|
||||
449
bsp/wch/driver/pin/pin.c
Normal file
449
bsp/wch/driver/pin/pin.c
Normal file
@@ -0,0 +1,449 @@
|
||||
/*
|
||||
* @copyright (c) 2023-2024, MR Development Team
|
||||
*
|
||||
* @license SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* @date 2023-11-11 MacRsh First version
|
||||
*/
|
||||
|
||||
#include "../mr-library/driver/include/mr_pin.h"
|
||||
|
||||
#ifdef MR_USE_PIN
|
||||
|
||||
static IRQn_Type _pin_driver_irq[] = _DRIVER_PIN_IRQ_CONFIG;
|
||||
static int _pin_irq_mask[] = {-1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1};
|
||||
static struct mr_pin_driver_port _pin_driver_port[] = _DRIVER_PIN_PORT_CONFIG;
|
||||
static struct mr_pin_driver_pin _pin_driver_pin[] = _DRIVER_PIN_PIN_CONFIG;
|
||||
|
||||
static struct mr_driver _pin_driver;
|
||||
static struct mr_pin _pin_device;
|
||||
|
||||
MR_INLINE struct mr_pin_driver_port *_pin_port_get(uint32_t number)
|
||||
{
|
||||
number >>= 4;
|
||||
if ((number >= MR_ARRAY_NUM(_pin_driver_port)) ||
|
||||
(_pin_driver_port[number].port == NULL))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
return &_pin_driver_port[number];
|
||||
}
|
||||
|
||||
MR_INLINE struct mr_pin_driver_pin *_pin_pin_get(uint32_t number)
|
||||
{
|
||||
number &= 0x0f;
|
||||
if (number >= MR_ARRAY_NUM(_pin_driver_pin))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
return &_pin_driver_pin[number];
|
||||
}
|
||||
|
||||
static int pin_driver_configure(struct mr_driver *driver, uint32_t number,
|
||||
uint32_t mode)
|
||||
{
|
||||
struct mr_pin_driver_port *pin_port = _pin_port_get(number);
|
||||
struct mr_pin_driver_pin *pin_pin = _pin_pin_get(number);
|
||||
uint32_t exti_line = number & 0x0f;
|
||||
GPIO_InitTypeDef GPIO_InitStructure = {0};
|
||||
EXTI_InitTypeDef EXTI_InitStructure = {0};
|
||||
NVIC_InitTypeDef NVIC_InitStructure = {0};
|
||||
|
||||
if (pin_port == NULL || pin_pin == NULL)
|
||||
{
|
||||
return MR_EINVAL;
|
||||
}
|
||||
|
||||
/* Configure clock */
|
||||
#ifdef GPIOA
|
||||
if (pin_port->port == GPIOA)
|
||||
{
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
|
||||
}
|
||||
#endif /* GPIOA */
|
||||
#ifdef GPIOB
|
||||
if (pin_port->port == GPIOB)
|
||||
{
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
|
||||
}
|
||||
#endif /* GPIOB */
|
||||
#ifdef GPIOC
|
||||
if (pin_port->port == GPIOC)
|
||||
{
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
|
||||
}
|
||||
#endif /* GPIOC */
|
||||
#ifdef GPIOD
|
||||
if (pin_port->port == GPIOD)
|
||||
{
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
|
||||
}
|
||||
#endif /* GPIOD */
|
||||
#ifdef GPIOE
|
||||
if (pin_port->port == GPIOE)
|
||||
{
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
|
||||
}
|
||||
#endif /* GPIOE */
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case MR_PIN_MODE_NONE:
|
||||
{
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||
break;
|
||||
}
|
||||
case MR_PIN_MODE_OUTPUT:
|
||||
{
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
break;
|
||||
}
|
||||
case MR_PIN_MODE_OUTPUT_OD:
|
||||
{
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
|
||||
break;
|
||||
}
|
||||
case MR_PIN_MODE_INPUT:
|
||||
{
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||
break;
|
||||
}
|
||||
case MR_PIN_MODE_INPUT_DOWN:
|
||||
{
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
|
||||
break;
|
||||
}
|
||||
case MR_PIN_MODE_INPUT_UP:
|
||||
{
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
break;
|
||||
}
|
||||
case MR_PIN_MODE_IRQ_RISING:
|
||||
{
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
|
||||
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
|
||||
break;
|
||||
}
|
||||
case MR_PIN_MODE_IRQ_FALLING:
|
||||
{
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
|
||||
break;
|
||||
}
|
||||
case MR_PIN_MODE_IRQ_EDGE:
|
||||
{
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
return MR_EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Configure EXTI */
|
||||
if (mode >= MR_PIN_MODE_IRQ_RISING)
|
||||
{
|
||||
if ((_pin_irq_mask[exti_line] != -1) &&
|
||||
(_pin_irq_mask[exti_line] != number))
|
||||
{
|
||||
return MR_EBUSY;
|
||||
}
|
||||
_pin_irq_mask[exti_line] = number;
|
||||
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
|
||||
EXTI_InitStructure.EXTI_Line = pin_pin->pin;
|
||||
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
|
||||
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
||||
GPIO_EXTILineConfig(number >> 4, exti_line);
|
||||
EXTI_Init(&EXTI_InitStructure);
|
||||
|
||||
/* Configure NVIC */
|
||||
NVIC_InitStructure.NVIC_IRQChannel = _pin_driver_irq[exti_line];
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
} else if (number == _pin_irq_mask[exti_line])
|
||||
{
|
||||
#ifdef MR_USING_CH32V00X
|
||||
if ((_pin_irq_mask[0] == -1) && (_pin_irq_mask[1] == -1) &&
|
||||
(_pin_irq_mask[2] == -1) && (_pin_irq_mask[3] == -1) &&
|
||||
(_pin_irq_mask[4] == -1) && (_pin_irq_mask[5] == -1) &&
|
||||
(_pin_irq_mask[6] == -1) && (_pin_irq_mask[7] == -1))
|
||||
{
|
||||
EXTI_InitStructure.EXTI_LineCmd = DISABLE;
|
||||
} else
|
||||
{
|
||||
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
||||
}
|
||||
#else
|
||||
if ((exti_line >= 5) && (exti_line <= 9))
|
||||
{
|
||||
if ((_pin_irq_mask[5] == -1) && (_pin_irq_mask[6] == -1) &&
|
||||
(_pin_irq_mask[7] == -1) && (_pin_irq_mask[8] == -1) &&
|
||||
(_pin_irq_mask[9] == -1))
|
||||
{
|
||||
EXTI_InitStructure.EXTI_LineCmd = DISABLE;
|
||||
} else
|
||||
{
|
||||
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
||||
}
|
||||
} else
|
||||
{
|
||||
if ((_pin_irq_mask[10] == -1) && (_pin_irq_mask[11] == -1) &&
|
||||
(_pin_irq_mask[12] == -1) && (_pin_irq_mask[13] == -1) &&
|
||||
(_pin_irq_mask[14] == -1) && (_pin_irq_mask[15] == -1))
|
||||
{
|
||||
EXTI_InitStructure.EXTI_LineCmd = DISABLE;
|
||||
} else
|
||||
{
|
||||
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
||||
}
|
||||
}
|
||||
#endif /* MR_USING_CH32V00X */
|
||||
_pin_irq_mask[exti_line] = -1;
|
||||
|
||||
EXTI_InitStructure.EXTI_Line = pin_pin->pin;
|
||||
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
|
||||
GPIO_EXTILineConfig(number >> 4, exti_line);
|
||||
EXTI_Init(&EXTI_InitStructure);
|
||||
}
|
||||
|
||||
/* Configure GPIO */
|
||||
GPIO_InitStructure.GPIO_Pin = pin_pin->pin;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(pin_port->port, &GPIO_InitStructure);
|
||||
return MR_EOK;
|
||||
}
|
||||
|
||||
static int pin_driver_read(struct mr_driver *driver, uint32_t number,
|
||||
uint8_t *value)
|
||||
{
|
||||
struct mr_pin_driver_port *pin_port = _pin_port_get(number);
|
||||
struct mr_pin_driver_pin *pin_pin = _pin_pin_get(number);
|
||||
|
||||
if (pin_port == NULL || pin_pin == NULL)
|
||||
{
|
||||
return MR_EINVAL;
|
||||
}
|
||||
|
||||
*value = GPIO_ReadInputDataBit(pin_port->port, pin_pin->pin);
|
||||
return MR_EOK;
|
||||
}
|
||||
|
||||
static int pin_driver_write(struct mr_driver *driver, uint32_t number, uint8_t value)
|
||||
{
|
||||
struct mr_pin_driver_port *pin_port = _pin_port_get(number);
|
||||
struct mr_pin_driver_pin *pin_pin = _pin_pin_get(number);
|
||||
|
||||
if (pin_port == NULL || pin_pin == NULL)
|
||||
{
|
||||
return MR_EINVAL;
|
||||
}
|
||||
|
||||
GPIO_WriteBit(pin_port->port, pin_pin->pin, value);
|
||||
return MR_EOK;
|
||||
}
|
||||
|
||||
#ifdef MR_USING_CH32V00X
|
||||
void EXTI7_0_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
void EXTI7_0_IRQHandler(void)
|
||||
{
|
||||
if (EXTI_GetITStatus(EXTI_Line0) != RESET)
|
||||
{
|
||||
mr_device_isr((struct mr_device *)&_pin_device, MR_EVENT_PIN_EXTI_INT,
|
||||
&_pin_irq_mask[0]);
|
||||
EXTI_ClearITPendingBit(EXTI_Line0);
|
||||
}
|
||||
if (EXTI_GetITStatus(EXTI_Line1) != RESET)
|
||||
{
|
||||
mr_device_isr((struct mr_device *)&_pin_device, MR_EVENT_PIN_EXTI_INT,
|
||||
&_pin_irq_mask[1]);
|
||||
EXTI_ClearITPendingBit(EXTI_Line1);
|
||||
}
|
||||
if (EXTI_GetITStatus(EXTI_Line2) != RESET)
|
||||
{
|
||||
mr_device_isr((struct mr_device *)&_pin_device, MR_EVENT_PIN_EXTI_INT,
|
||||
&_pin_irq_mask[2]);
|
||||
EXTI_ClearITPendingBit(EXTI_Line2);
|
||||
}
|
||||
if (EXTI_GetITStatus(EXTI_Line3) != RESET)
|
||||
{
|
||||
mr_device_isr((struct mr_device *)&_pin_device, MR_EVENT_PIN_EXTI_INT,
|
||||
&_pin_irq_mask[3]);
|
||||
EXTI_ClearITPendingBit(EXTI_Line3);
|
||||
}
|
||||
if (EXTI_GetITStatus(EXTI_Line4) != RESET)
|
||||
{
|
||||
mr_device_isr((struct mr_device *)&_pin_device, MR_EVENT_PIN_EXTI_INT,
|
||||
&_pin_irq_mask[4]);
|
||||
EXTI_ClearITPendingBit(EXTI_Line4);
|
||||
}
|
||||
if (EXTI_GetITStatus(EXTI_Line5) != RESET)
|
||||
{
|
||||
mr_device_isr((struct mr_device *)&_pin_device, MR_EVENT_PIN_EXTI_INT,
|
||||
&_pin_irq_mask[5]);
|
||||
EXTI_ClearITPendingBit(EXTI_Line5);
|
||||
}
|
||||
if (EXTI_GetITStatus(EXTI_Line6) != RESET)
|
||||
{
|
||||
mr_device_isr((struct mr_device *)&_pin_device, MR_EVENT_PIN_EXTI_INT,
|
||||
&_pin_irq_mask[6]);
|
||||
EXTI_ClearITPendingBit(EXTI_Line6);
|
||||
}
|
||||
if (EXTI_GetITStatus(EXTI_Line7) != RESET)
|
||||
{
|
||||
mr_device_isr((struct mr_device *)&_pin_device, MR_EVENT_PIN_EXTI_INT,
|
||||
&_pin_irq_mask[7]);
|
||||
EXTI_ClearITPendingBit(EXTI_Line7);
|
||||
}
|
||||
}
|
||||
#else
|
||||
void EXTI0_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
void EXTI0_IRQHandler(void)
|
||||
{
|
||||
if (EXTI_GetITStatus(EXTI_Line0) != RESET)
|
||||
{
|
||||
mr_device_isr((struct mr_device *)&_pin_device, MR_EVENT_PIN_EXTI_INT,
|
||||
&_pin_irq_mask[0]);
|
||||
EXTI_ClearITPendingBit(EXTI_Line0);
|
||||
}
|
||||
}
|
||||
|
||||
void EXTI1_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
void EXTI1_IRQHandler(void)
|
||||
{
|
||||
if (EXTI_GetITStatus(EXTI_Line1) != RESET)
|
||||
{
|
||||
mr_device_isr((struct mr_device *)&_pin_device, MR_EVENT_PIN_EXTI_INT,
|
||||
&_pin_irq_mask[1]);
|
||||
EXTI_ClearITPendingBit(EXTI_Line1);
|
||||
}
|
||||
}
|
||||
|
||||
void EXTI2_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
void EXTI2_IRQHandler(void)
|
||||
{
|
||||
if (EXTI_GetITStatus(EXTI_Line2) != RESET)
|
||||
{
|
||||
mr_device_isr((struct mr_device *)&_pin_device, MR_EVENT_PIN_EXTI_INT,
|
||||
&_pin_irq_mask[2]);
|
||||
EXTI_ClearITPendingBit(EXTI_Line2);
|
||||
}
|
||||
}
|
||||
|
||||
void EXTI3_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
void EXTI3_IRQHandler(void)
|
||||
{
|
||||
if (EXTI_GetITStatus(EXTI_Line3) != RESET)
|
||||
{
|
||||
mr_device_isr((struct mr_device *)&_pin_device, MR_EVENT_PIN_EXTI_INT,
|
||||
&_pin_irq_mask[3]);
|
||||
EXTI_ClearITPendingBit(EXTI_Line3);
|
||||
}
|
||||
}
|
||||
|
||||
void EXTI4_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
void EXTI4_IRQHandler(void)
|
||||
{
|
||||
if (EXTI_GetITStatus(EXTI_Line4) != RESET)
|
||||
{
|
||||
mr_device_isr((struct mr_device *)&_pin_device, MR_EVENT_PIN_EXTI_INT,
|
||||
&_pin_irq_mask[4]);
|
||||
EXTI_ClearITPendingBit(EXTI_Line4);
|
||||
}
|
||||
}
|
||||
|
||||
void EXTI9_5_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
void EXTI9_5_IRQHandler(void)
|
||||
{
|
||||
if (EXTI_GetITStatus(EXTI_Line5) != RESET)
|
||||
{
|
||||
mr_device_isr((struct mr_device *)&_pin_device, MR_EVENT_PIN_EXTI_INT,
|
||||
&_pin_irq_mask[5]);
|
||||
EXTI_ClearITPendingBit(EXTI_Line5);
|
||||
}
|
||||
if (EXTI_GetITStatus(EXTI_Line6) != RESET)
|
||||
{
|
||||
mr_device_isr((struct mr_device *)&_pin_device, MR_EVENT_PIN_EXTI_INT,
|
||||
&_pin_irq_mask[6]);
|
||||
EXTI_ClearITPendingBit(EXTI_Line6);
|
||||
}
|
||||
if (EXTI_GetITStatus(EXTI_Line7) != RESET)
|
||||
{
|
||||
mr_device_isr((struct mr_device *)&_pin_device, MR_EVENT_PIN_EXTI_INT,
|
||||
&_pin_irq_mask[7]);
|
||||
EXTI_ClearITPendingBit(EXTI_Line7);
|
||||
}
|
||||
if (EXTI_GetITStatus(EXTI_Line8) != RESET)
|
||||
{
|
||||
mr_device_isr((struct mr_device *)&_pin_device, MR_EVENT_PIN_EXTI_INT,
|
||||
&_pin_irq_mask[8]);
|
||||
EXTI_ClearITPendingBit(EXTI_Line8);
|
||||
}
|
||||
if (EXTI_GetITStatus(EXTI_Line9) != RESET)
|
||||
{
|
||||
mr_device_isr((struct mr_device *)&_pin_device, MR_EVENT_PIN_EXTI_INT,
|
||||
&_pin_irq_mask[9]);
|
||||
EXTI_ClearITPendingBit(EXTI_Line9);
|
||||
}
|
||||
}
|
||||
|
||||
void EXTI15_10_IRQHandler(void)
|
||||
__attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
void EXTI15_10_IRQHandler(void)
|
||||
{
|
||||
if (EXTI_GetITStatus(EXTI_Line10) != RESET)
|
||||
{
|
||||
mr_device_isr((struct mr_device *)&_pin_device, MR_EVENT_PIN_EXTI_INT,
|
||||
&_pin_irq_mask[10]);
|
||||
EXTI_ClearITPendingBit(EXTI_Line10);
|
||||
}
|
||||
if (EXTI_GetITStatus(EXTI_Line11) != RESET)
|
||||
{
|
||||
mr_device_isr((struct mr_device *)&_pin_device, MR_EVENT_PIN_EXTI_INT,
|
||||
&_pin_irq_mask[11]);
|
||||
EXTI_ClearITPendingBit(EXTI_Line11);
|
||||
}
|
||||
if (EXTI_GetITStatus(EXTI_Line12) != RESET)
|
||||
{
|
||||
mr_device_isr((struct mr_device *)&_pin_device, MR_EVENT_PIN_EXTI_INT,
|
||||
&_pin_irq_mask[12]);
|
||||
EXTI_ClearITPendingBit(EXTI_Line12);
|
||||
}
|
||||
if (EXTI_GetITStatus(EXTI_Line13) != RESET)
|
||||
{
|
||||
mr_device_isr((struct mr_device *)&_pin_device, MR_EVENT_PIN_EXTI_INT,
|
||||
&_pin_irq_mask[13]);
|
||||
EXTI_ClearITPendingBit(EXTI_Line13);
|
||||
}
|
||||
if (EXTI_GetITStatus(EXTI_Line14) != RESET)
|
||||
{
|
||||
mr_device_isr((struct mr_device *)&_pin_device, MR_EVENT_PIN_EXTI_INT,
|
||||
&_pin_irq_mask[14]);
|
||||
EXTI_ClearITPendingBit(EXTI_Line14);
|
||||
}
|
||||
if (EXTI_GetITStatus(EXTI_Line15) != RESET)
|
||||
{
|
||||
mr_device_isr((struct mr_device *)&_pin_device, MR_EVENT_PIN_EXTI_INT,
|
||||
&_pin_irq_mask[15]);
|
||||
EXTI_ClearITPendingBit(EXTI_Line15);
|
||||
}
|
||||
}
|
||||
#endif /* MR_USING_CH32V00X */
|
||||
|
||||
static void pin_driver_init(void)
|
||||
{
|
||||
static struct mr_pin_driver_ops ops = {.configure = pin_driver_configure,
|
||||
.read = pin_driver_read,
|
||||
.write = pin_driver_write};
|
||||
|
||||
_pin_driver.ops = &ops;
|
||||
mr_pin_register(&_pin_device, "pin", &_pin_driver);
|
||||
}
|
||||
MR_INIT_DRIVER_EXPORT(pin_driver_init);
|
||||
|
||||
#endif /* MR_USE_PIN */
|
||||
@@ -3,112 +3,112 @@ menu "UART driver configure"
|
||||
if MR_USE_SERIAL
|
||||
# UART1
|
||||
config MR_USE_UART1
|
||||
bool "Use UART1 driver"
|
||||
bool "Use uart1 driver"
|
||||
default n
|
||||
|
||||
menu "UART1 driver configure"
|
||||
depends on MR_USE_UART1
|
||||
|
||||
config MR_CFG_UART1_GROUP
|
||||
int "UART1 Group"
|
||||
int "Uart1 group"
|
||||
default 1
|
||||
range 1 4
|
||||
endmenu
|
||||
|
||||
# UART2
|
||||
config MR_USE_UART2
|
||||
bool "Use UART2 driver"
|
||||
bool "Use uart2 driver"
|
||||
default n
|
||||
|
||||
menu "UART2 driver configure"
|
||||
depends on MR_USE_UART2
|
||||
|
||||
config MR_CFG_UART2_GROUP
|
||||
int "UART2 Group"
|
||||
int "Uart2 group"
|
||||
default 1
|
||||
range 1 2
|
||||
endmenu
|
||||
|
||||
# UART3
|
||||
config MR_USE_UART3
|
||||
bool "Use UART3 driver"
|
||||
bool "Use uart3 driver"
|
||||
default n
|
||||
|
||||
menu "UART3 driver configure"
|
||||
depends on MR_USE_UART3
|
||||
|
||||
config MR_CFG_UART3_GROUP
|
||||
int "UART3 Group"
|
||||
int "Uart3 group"
|
||||
default 1
|
||||
range 1 4
|
||||
endmenu
|
||||
|
||||
# UART4
|
||||
config MR_USE_UART4
|
||||
bool "Use UART4 driver"
|
||||
bool "Use uart4 driver"
|
||||
default n
|
||||
|
||||
menu "UART4 driver configure"
|
||||
depends on MR_USE_UART4
|
||||
|
||||
config MR_CFG_UART4_GROUP
|
||||
int "UART4 Group"
|
||||
int "Uart4 group"
|
||||
default 1
|
||||
range 1 3
|
||||
endmenu
|
||||
|
||||
# UART5
|
||||
config MR_USE_UART5
|
||||
bool "Use UART5 driver"
|
||||
bool "Use uart5 driver"
|
||||
default n
|
||||
|
||||
menu "UART5 driver configure"
|
||||
depends on MR_USE_UART5
|
||||
|
||||
config MR_CFG_UART5_GROUP
|
||||
int "UART5 Group"
|
||||
int "Uart5 group"
|
||||
default 1
|
||||
range 1 3
|
||||
endmenu
|
||||
|
||||
# UART6
|
||||
config MR_USE_UART6
|
||||
bool "Use UART6 driver"
|
||||
bool "Use uart6 driver"
|
||||
default n
|
||||
|
||||
menu "UART6 driver configure"
|
||||
depends on MR_USE_UART6
|
||||
|
||||
config MR_CFG_UART6_GROUP
|
||||
int "UART6 Group"
|
||||
int "Uart6 group"
|
||||
default 1
|
||||
range 1 3
|
||||
endmenu
|
||||
|
||||
# UART7
|
||||
config MR_USE_UART7
|
||||
bool "Use UART7 driver"
|
||||
bool "Use uart7 driver"
|
||||
default n
|
||||
|
||||
menu "UART7 driver configure"
|
||||
depends on MR_USE_UART7
|
||||
|
||||
config MR_CFG_UART7_GROUP
|
||||
int "UART7 Group"
|
||||
int "Uart7 group"
|
||||
default 1
|
||||
range 1 3
|
||||
endmenu
|
||||
|
||||
# UART8
|
||||
config MR_USE_UART8
|
||||
bool "Use UART8 driver"
|
||||
bool "Use uart8 driver"
|
||||
default n
|
||||
|
||||
menu "UART8 driver configure"
|
||||
depends on MR_USE_UART8
|
||||
|
||||
config MR_CFG_UART8_GROUP
|
||||
int "UART8 Group"
|
||||
int "Uart8 group"
|
||||
default 1
|
||||
range 1 3
|
||||
endmenu
|
||||
|
||||
@@ -15,10 +15,7 @@
|
||||
!defined(MR_USE_UART5) && !defined(MR_USE_UART6) && \
|
||||
!defined(MR_USE_UART7) && !defined(MR_USE_UART8)
|
||||
#warning "Please enable at least one Serial driver"
|
||||
#endif /* !defined(MR_USE_UART1) && !defined(MR_USE_UART2) && \
|
||||
* !defined(MR_USE_UART3) && !defined(MR_USE_UART4) && \
|
||||
* !defined(MR_USE_UART5) && !defined(MR_USE_UART6) && \
|
||||
* !defined(MR_USE_UART7) && !defined(MR_USE_UART8) */
|
||||
#else
|
||||
|
||||
enum _serial_driver_index
|
||||
{
|
||||
@@ -411,4 +408,9 @@ static void serial_driver_init(void)
|
||||
}
|
||||
MR_INIT_DRIVER_EXPORT(serial_driver_init);
|
||||
|
||||
#endif /* !defined(MR_USE_UART1) && !defined(MR_USE_UART2) && \
|
||||
* !defined(MR_USE_UART3) && !defined(MR_USE_UART4) && \
|
||||
* !defined(MR_USE_UART5) && !defined(MR_USE_UART6) && \
|
||||
* !defined(MR_USE_UART7) && !defined(MR_USE_UART8) */
|
||||
|
||||
#endif /* MR_USE_SERIAL */
|
||||
|
||||
Reference in New Issue
Block a user