1.未使能设备时自动屏蔽,同时报错。

This commit is contained in:
MacRsh
2023-11-15 12:36:07 +08:00
parent 821266ee97
commit d794c74fef
6 changed files with 35 additions and 31 deletions

View File

@@ -12,9 +12,9 @@
#if !defined(MR_USING_ADC1) && !defined(MR_USING_ADC2)
#error "Please define at least one ADC macro like MR_USING_ADC1. Otherwise undefine MR_USING_ADC."
#endif
#else
enum adc_drv_index
static enum drv_adc_index
{
#ifdef MR_USING_ADC1
DRV_INDEX_ADC1,
@@ -34,6 +34,16 @@ static const char *adc_name[] =
#endif /* MR_USING_ADC2 */
};
static struct drv_adc_data adc_drv_data[] =
{
#ifdef MR_USING_ADC1
{ADC1, RCC_APB2Periph_ADC1},
#endif /* MR_USING_ADC1 */
#ifdef MR_USING_ADC2
{ADC2, RCC_APB2Periph_ADC2},
#endif /* MR_USING_ADC2 */
};
static struct drv_adc_channel_data adc_channel_drv_data[] =
{
{ADC_Channel_0, RCC_APB2Periph_GPIOA, GPIOA, GPIO_Pin_0},
@@ -56,16 +66,6 @@ static struct drv_adc_channel_data adc_channel_drv_data[] =
{ADC_Channel_17, 0, MR_NULL, 0},
};
static struct drv_adc_data adc_drv_data[] =
{
#ifdef MR_USING_ADC1
{ADC1, RCC_APB2Periph_ADC1},
#endif /* MR_USING_ADC1 */
#ifdef MR_USING_ADC2
{ADC2, RCC_APB2Periph_ADC2},
#endif /* MR_USING_ADC2 */
};
static struct mr_adc adc_dev[mr_array_num(adc_drv_data)];
static struct drv_adc_channel_data *drv_adc_get_channel_data(int channel)
@@ -83,7 +83,7 @@ static int drv_adc_configure(struct mr_adc *adc, int state)
ADC_InitTypeDef ADC_InitStructure = {0};
/* Configure clock */
RCC_APB2PeriphClockCmd(adc_data->clock, (FunctionalState)state);
RCC_APB2PeriphClockCmd(adc_data->clock, state);
RCC_ADCCLKConfig(RCC_PCLK2_Div8);
/* Configure ADC */
@@ -94,7 +94,7 @@ static int drv_adc_configure(struct mr_adc *adc, int state)
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = 1;
ADC_Init(adc_data->instance, &ADC_InitStructure);
ADC_Cmd(adc_data->instance, (FunctionalState)state);
ADC_Cmd(adc_data->instance, state);
return MR_EOK;
}
@@ -123,15 +123,7 @@ static int drv_adc_channel_configure(struct mr_adc *adc, int channel, int state)
/* Configure temp-sensor */
if ((adc_channel_data->channel == ADC_Channel_16) || (adc_channel_data->channel == ADC_Channel_17))
{
static uint8_t mask = 0;
mask = (state == MR_ENABLE) ? (mask + 1) : (mask - 1);
if (mask > 0)
{
ADC_TempSensorVrefintCmd(MR_ENABLE);
} else
{
ADC_TempSensorVrefintCmd(MR_DISABLE);
}
ADC_TempSensorVrefintCmd(ENABLE);
}
return MR_EOK;
}
@@ -200,4 +192,6 @@ int drv_adc_init(void)
}
MR_INIT_DRV_EXPORT(drv_adc_init);
#endif /* !defined(MR_USING_ADC1) && !defined(MR_USING_ADC2) */
#endif /* MR_USING_ADC */

View File

@@ -10,9 +10,9 @@
#ifdef MR_USING_GPIO
#if !defined(MR_USING_GPIOA) && !defined(MR_USING_GPIOB) && !defined(MR_USING_GPIOC) && !defined(MR_USING_GPIOD) && !defined(MR_USING_GPIOE) && !defined(MR_USING_GPIOF)
#if !defined(MR_USING_GPIOA) && !defined(MR_USING_GPIOB) && !defined(MR_USING_GPIOC) && !defined(MR_USING_GPIOD) && !defined(MR_USING_GPIOE)
#error "Please define at least one GPIO macro like MR_USING_GPIOA. Otherwise undefine MR_USING_GPIO."
#endif
#else
static IRQn_Type gpio_irq_map[] =
{
@@ -549,4 +549,6 @@ int drv_gpio_init(void)
}
MR_INIT_DRV_EXPORT(drv_gpio_init);
#endif /* !defined(MR_USING_GPIOA) && !defined(MR_USING_GPIOB) && !defined(MR_USING_GPIOC) && !defined(MR_USING_GPIOD) && !defined(MR_USING_GPIOE) */
#endif /* MR_USING_GPIO */

View File

@@ -12,9 +12,9 @@
#if !defined(MR_USING_I2C1) && !defined(MR_USING_I2C2)
#error "Please define at least one I2C macro like MR_USING_I2C1. Otherwise undefine MR_USING_I2C."
#endif
#else
enum drv_i2c_index
static enum drv_i2c_index
{
#ifdef MR_USING_I2C1
DRV_INDEX_I2C1,
@@ -344,4 +344,6 @@ int drv_i2c_bus_init(void)
}
MR_INIT_DRV_EXPORT(drv_i2c_bus_init);
#endif /* !defined(MR_USING_I2C1) && !defined(MR_USING_I2C2) */
#endif /* MR_USING_I2C */

View File

@@ -12,9 +12,9 @@
#if !defined(MR_USING_SPI1) && !defined(MR_USING_SPI2) && !defined(MR_USING_SPI3)
#error "Please define at least one SPI macro like MR_USING_SPI1. Otherwise undefine MR_USING_SPI."
#endif
#else
enum drv_spi_bus_index
static enum drv_spi_bus_index
{
#ifdef MR_USING_SPI1
DRV_INDEX_SPI1,
@@ -461,4 +461,6 @@ int drv_spi_bus_init(void)
}
MR_INIT_DRV_EXPORT(drv_spi_bus_init);
#endif /* !defined(MR_USING_SPI1) && !defined(MR_USING_SPI2) && !defined(MR_USING_SPI3) */
#endif /* MR_USING_SPI */

View File

@@ -12,9 +12,9 @@
#if !defined(MR_USING_UART1) && !defined(MR_USING_UART2) && !defined(MR_USING_UART3) && !defined(MR_USING_UART4) && !defined(MR_USING_UART5) && !defined(MR_USING_UART6) && !defined(MR_USING_UART7) && !defined(MR_USING_UART8)
#error "Please define at least one UART macro like MR_USING_UART1. Otherwise undefine MR_USING_UART."
#endif
#else
enum drv_uart_index
static enum drv_uart_index
{
#ifdef MR_USING_UART1
DRV_INDEX_UART1,
@@ -805,4 +805,6 @@ int drv_uart_init(void)
}
MR_INIT_CONSOLE_EXPORT(drv_uart_init);
#endif /* !defined(MR_USING_UART1) && !defined(MR_USING_UART2) && !defined(MR_USING_UART3) && !defined(MR_USING_UART4) && !defined(MR_USING_UART5) && !defined(MR_USING_UART6) && !defined(MR_USING_UART7) && !defined(MR_USING_UART8) */
#endif /* MR_USING_UART */

View File

@@ -16,6 +16,8 @@ extern "C" {
#define MR_USING_ADC1
#define MR_USING_ADC2
#define MR_USING_DAC1
#define MR_USING_GPIOA
#define MR_USING_GPIOB
#define MR_USING_GPIOC