1.新增驱动适配模板。
This commit is contained in:
77
driver/drv_adc.c
Normal file
77
driver/drv_adc.c
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2023, mr-library Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-10-08 MacRsh first version
|
||||
*/
|
||||
|
||||
#include "drv_adc.h"
|
||||
|
||||
#if (MR_CFG_ADC == MR_CFG_ENABLE)
|
||||
|
||||
static struct drv_adc_data drv_adc_data[] =
|
||||
{
|
||||
#ifdef MR_BSP_ADC_1
|
||||
{"adc1", /* ... */},
|
||||
#endif
|
||||
#ifdef MR_BSP_ADC_2
|
||||
{"adc2", /* ... */},
|
||||
#endif
|
||||
/* ... */
|
||||
};
|
||||
|
||||
static struct mr_adc adc_device[mr_array_num(drv_adc_data)];
|
||||
|
||||
static mr_err_t drv_adc_configure(mr_adc_t adc, mr_state_t state)
|
||||
{
|
||||
struct drv_adc_data *adc_data = (struct drv_adc_data *)adc->device.data;
|
||||
|
||||
/* ... */
|
||||
|
||||
return MR_ERR_OK;
|
||||
}
|
||||
|
||||
static mr_err_t drv_adc_channel_configure(mr_adc_t adc, mr_adc_config_t config)
|
||||
{
|
||||
struct drv_adc_data *adc_data = (struct drv_adc_data *)adc->device.data;
|
||||
|
||||
/* ... */
|
||||
|
||||
return MR_ERR_OK;
|
||||
}
|
||||
|
||||
static mr_uint32_t drv_adc_read(mr_adc_t adc, mr_off_t channel)
|
||||
{
|
||||
struct drv_adc_data *adc_data = (struct drv_adc_data *)adc->device.data;
|
||||
mr_uint32_t data = 0;
|
||||
|
||||
/* ... */
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
mr_err_t drv_adc_init(void)
|
||||
{
|
||||
static struct mr_adc_ops drv_ops =
|
||||
{
|
||||
drv_adc_configure,
|
||||
drv_adc_channel_configure,
|
||||
drv_adc_read,
|
||||
};
|
||||
mr_size_t count = mr_array_num(adc_device);
|
||||
mr_err_t ret = MR_ERR_OK;
|
||||
|
||||
while (count--)
|
||||
{
|
||||
ret = mr_adc_device_add(&adc_device[count], drv_adc_data[count].name, &drv_ops, &drv_adc_data[count]);
|
||||
MR_ASSERT(ret == MR_ERR_OK);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
MR_INIT_DRIVER_EXPORT(drv_adc_init);
|
||||
|
||||
#endif
|
||||
31
driver/drv_adc.h
Normal file
31
driver/drv_adc.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2023, mr-library Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-10-08 MacRsh first version
|
||||
*/
|
||||
|
||||
#ifndef _DRV_ADC_H_
|
||||
#define _DRV_ADC_H_
|
||||
|
||||
#include "device/adc.h"
|
||||
#include "mrboard.h"
|
||||
|
||||
#if (MR_CFG_ADC == MR_CFG_ENABLE)
|
||||
|
||||
/**
|
||||
* @struct Driver adc data
|
||||
*/
|
||||
struct drv_adc_data
|
||||
{
|
||||
const char *name;
|
||||
|
||||
/* ... */
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _DRV_ADC_H_ */
|
||||
74
driver/drv_dac.c
Normal file
74
driver/drv_dac.c
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2023, mr-library Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-10-08 MacRsh first version
|
||||
*/
|
||||
|
||||
#include "drv_dac.h"
|
||||
|
||||
#if (MR_CFG_DAC == MR_CFG_ENABLE)
|
||||
|
||||
static struct drv_dac_data drv_dac_data[] =
|
||||
{
|
||||
#ifdef MR_BSP_DAC_1
|
||||
{"dac1", /* ... */},
|
||||
#endif
|
||||
#ifdef MR_BSP_DAC_2
|
||||
{"dac2", /* ... */},
|
||||
#endif
|
||||
/* ... */
|
||||
};
|
||||
|
||||
static struct mr_dac dac_device[mr_array_num(drv_dac_data)];
|
||||
|
||||
static mr_err_t drv_dac_configure(mr_dac_t dac, mr_state_t state)
|
||||
{
|
||||
struct drv_dac_data *dac_data = (struct drv_dac_data *)dac->device.data;
|
||||
|
||||
/* ... */
|
||||
|
||||
return MR_ERR_OK;
|
||||
}
|
||||
|
||||
static mr_err_t drv_dac_channel_configure(mr_dac_t dac, mr_dac_config_t config)
|
||||
{
|
||||
struct drv_dac_data *dac_data = (struct drv_dac_data *)dac->device.data;
|
||||
|
||||
/* ... */
|
||||
|
||||
return MR_ERR_OK;
|
||||
}
|
||||
|
||||
static void drv_dac_write(mr_dac_t dac, mr_off_t channel, mr_uint32_t value)
|
||||
{
|
||||
struct drv_dac_data *dac_data = (struct drv_dac_data *)dac->device.data;
|
||||
|
||||
/* ... */
|
||||
}
|
||||
|
||||
mr_err_t drv_dac_init(void)
|
||||
{
|
||||
static struct mr_dac_ops drv_ops =
|
||||
{
|
||||
drv_dac_configure,
|
||||
drv_dac_channel_configure,
|
||||
drv_dac_write,
|
||||
};
|
||||
mr_size_t count = mr_array_num(dac_device);
|
||||
mr_err_t ret = MR_ERR_OK;
|
||||
|
||||
while (count--)
|
||||
{
|
||||
ret = mr_dac_device_add(&dac_device[count], drv_dac_data[count].name, &drv_ops, &drv_dac_data[count]);
|
||||
MR_ASSERT(ret == MR_ERR_OK);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
MR_INIT_DRIVER_EXPORT(drv_dac_init);
|
||||
|
||||
#endif
|
||||
31
driver/drv_dac.h
Normal file
31
driver/drv_dac.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2023, mr-library Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-10-08 MacRsh first version
|
||||
*/
|
||||
|
||||
#ifndef _DRV_DAC_H_
|
||||
#define _DRV_DAC_H_
|
||||
|
||||
#include "device/dac.h"
|
||||
#include "mrboard.h"
|
||||
|
||||
#if (MR_CFG_DAC == MR_CFG_ENABLE)
|
||||
|
||||
/**
|
||||
* @struct Driver dac data
|
||||
*/
|
||||
struct drv_dac_data
|
||||
{
|
||||
const char *name;
|
||||
|
||||
/* ... */
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _DRV_DAC_H_ */
|
||||
65
driver/drv_gpio.c
Normal file
65
driver/drv_gpio.c
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2023, mr-library Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-10-8 MacRsh first version
|
||||
*/
|
||||
|
||||
#include "drv_gpio.h"
|
||||
|
||||
#if (MR_CFG_PIN == MR_CFG_ENABLE)
|
||||
|
||||
static struct drv_gpio_data drv_gpio_data[] =
|
||||
{
|
||||
{"pin", /* ... */},
|
||||
};
|
||||
|
||||
static struct mr_pin pin_device;
|
||||
|
||||
static mr_err_t drv_pin_configure(mr_pin_t pin, mr_pin_config_t config)
|
||||
{
|
||||
struct drv_gpio_data *pin_data = (struct drv_gpio_data *)pin->device.data;
|
||||
|
||||
/* ... */
|
||||
|
||||
return MR_ERR_OK;
|
||||
}
|
||||
|
||||
static mr_level_t drv_pin_read(mr_pin_t pin, mr_off_t number)
|
||||
{
|
||||
struct drv_gpio_data *pin_data = (struct drv_gpio_data *)pin->device.data;
|
||||
mr_level_t level = MR_LOW;
|
||||
|
||||
/* ... */
|
||||
|
||||
return level;
|
||||
}
|
||||
|
||||
static void drv_pin_write(mr_pin_t pin, mr_off_t number, mr_level_t level)
|
||||
{
|
||||
struct drv_gpio_data *pin_data = (struct drv_gpio_data *)pin->device.data;
|
||||
|
||||
/* ... */
|
||||
}
|
||||
|
||||
mr_err_t drv_gpio_init(void)
|
||||
{
|
||||
static struct mr_pin_ops drv_ops =
|
||||
{
|
||||
drv_pin_configure,
|
||||
drv_pin_read,
|
||||
drv_pin_write,
|
||||
};
|
||||
mr_err_t ret = MR_ERR_OK;
|
||||
|
||||
ret = mr_pin_device_add(&pin_device, drv_gpio_data[0].name, &drv_ops, &drv_gpio_data[0]);
|
||||
MR_ASSERT(ret == MR_ERR_OK);
|
||||
|
||||
return ret;
|
||||
}
|
||||
MR_INIT_DRIVER_EXPORT(drv_gpio_init);
|
||||
|
||||
#endif
|
||||
31
driver/drv_gpio.h
Normal file
31
driver/drv_gpio.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2023, mr-library Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-10-8 MacRsh first version
|
||||
*/
|
||||
|
||||
#ifndef _DRV_GPIO_H_
|
||||
#define _DRV_GPIO_H_
|
||||
|
||||
#include "device/pin.h"
|
||||
#include "mrboard.h"
|
||||
|
||||
#if (MR_CFG_PIN == MR_CFG_ENABLE)
|
||||
|
||||
/**
|
||||
* @struct Driver gpio data
|
||||
*/
|
||||
struct drv_gpio_data
|
||||
{
|
||||
const char *name;
|
||||
|
||||
/* ... */
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _DRV_GPIO_H_ */
|
||||
89
driver/drv_i2c.c
Normal file
89
driver/drv_i2c.c
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (c) 2023, mr-library Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-10-08 MacRsh first version
|
||||
*/
|
||||
|
||||
#include "drv_i2c.h"
|
||||
|
||||
#if (MR_CFG_I2C == MR_CFG_ENABLE)
|
||||
|
||||
static struct drv_soft_i2c_bus_data drv_soft_i2c_bus_data[] =
|
||||
{
|
||||
#ifdef MR_BSP_I2C_1
|
||||
{"i2c1", /* ... */},
|
||||
#endif
|
||||
#ifdef MR_BSP_I2C_2
|
||||
{"i2c2", /* ... */},
|
||||
#endif
|
||||
#ifdef MR_BSP_I2C_3
|
||||
{"i2c3", /* ... */},
|
||||
#endif
|
||||
/* ... */
|
||||
};
|
||||
|
||||
static struct mr_soft_i2c_bus soft_i2c_bus_device[mr_array_num(drv_soft_i2c_bus_data)];
|
||||
|
||||
static mr_err_t drv_soft_i2c_bus_configure(mr_soft_i2c_bus_t i2c_bus, mr_state_t state)
|
||||
{
|
||||
struct drv_soft_i2c_bus_data *soft_i2c_bus_data = (struct drv_soft_i2c_bus_data *)i2c_bus->i2c_bus.device.data;
|
||||
|
||||
/* ... */
|
||||
|
||||
return MR_ERR_OK;
|
||||
}
|
||||
|
||||
static void drv_soft_i2c_bus_scl_write(mr_soft_i2c_bus_t i2c_bus, mr_level_t level)
|
||||
{
|
||||
struct drv_soft_i2c_bus_data *soft_i2c_bus_data = (struct drv_soft_i2c_bus_data *)i2c_bus->i2c_bus.device.data;
|
||||
|
||||
/* ... */
|
||||
}
|
||||
|
||||
static void drv_soft_i2c_bus_sda_write(mr_soft_i2c_bus_t i2c_bus, mr_level_t level)
|
||||
{
|
||||
struct drv_soft_i2c_bus_data *soft_i2c_bus_data = (struct drv_soft_i2c_bus_data *)i2c_bus->i2c_bus.device.data;
|
||||
|
||||
/* ... */
|
||||
}
|
||||
|
||||
static mr_level_t drv_soft_i2c_bus_sda_read(mr_soft_i2c_bus_t i2c_bus)
|
||||
{
|
||||
struct drv_soft_i2c_bus_data *soft_i2c_bus_data = (struct drv_soft_i2c_bus_data *)i2c_bus->i2c_bus.device.data;
|
||||
mr_level_t level = MR_LOW;
|
||||
|
||||
/* ... */
|
||||
|
||||
return level;
|
||||
}
|
||||
|
||||
mr_err_t drv_soft_i2c_bus_init(void)
|
||||
{
|
||||
static struct mr_soft_i2c_ops drv_ops =
|
||||
{
|
||||
drv_soft_i2c_bus_configure,
|
||||
drv_soft_i2c_bus_scl_write,
|
||||
drv_soft_i2c_bus_sda_write,
|
||||
drv_soft_i2c_bus_sda_read,
|
||||
};
|
||||
mr_size_t count = mr_array_num(soft_i2c_bus_device);
|
||||
mr_err_t ret = MR_ERR_OK;
|
||||
|
||||
while (count--)
|
||||
{
|
||||
ret = mr_soft_i2c_bus_add(&soft_i2c_bus_device[count],
|
||||
drv_soft_i2c_bus_data[count].name,
|
||||
&drv_ops,
|
||||
&drv_soft_i2c_bus_data[count]);
|
||||
MR_ASSERT(ret == MR_ERR_OK);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
MR_INIT_DRIVER_EXPORT(drv_soft_i2c_bus_init);
|
||||
|
||||
#endif
|
||||
31
driver/drv_i2c.h
Normal file
31
driver/drv_i2c.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2023, mr-library Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-10-08 MacRsh first version
|
||||
*/
|
||||
|
||||
#ifndef _DRV_I2C_H_
|
||||
#define _DRV_I2C_H_
|
||||
|
||||
#include "device/i2c.h"
|
||||
#include "mrboard.h"
|
||||
|
||||
#if (MR_CFG_I2C == MR_CFG_ENABLE)
|
||||
|
||||
/**
|
||||
* @struct Driver soft i2c bus data
|
||||
*/
|
||||
struct drv_soft_i2c_bus_data
|
||||
{
|
||||
const char *name;
|
||||
|
||||
/* ... */
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _DRV_I2C_H_ */
|
||||
98
driver/drv_spi.c
Normal file
98
driver/drv_spi.c
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (c) 2023, mr-library Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-10-8 MacRsh first version
|
||||
*/
|
||||
|
||||
#include "drv_spi.h"
|
||||
|
||||
#if (MR_CFG_SPI == MR_CFG_ENABLE)
|
||||
|
||||
static struct drv_spi_bus_data drv_spi_bus_data[] =
|
||||
{
|
||||
#ifdef MR_BSP_SPI_1
|
||||
{"spi1", /* ... */},
|
||||
#endif
|
||||
#ifdef MR_BSP_SPI_2
|
||||
{"spi2", /* ... */},
|
||||
#endif
|
||||
#ifdef MR_BSP_SPI_3
|
||||
{"spi3", /* ... */},
|
||||
#endif
|
||||
/* ... */
|
||||
};
|
||||
|
||||
static struct mr_spi_bus spi_bus_device[mr_array_num(drv_spi_bus_data)];
|
||||
|
||||
static mr_err_t drv_spi_configure(mr_spi_bus_t spi_bus, mr_spi_config_t config)
|
||||
{
|
||||
struct drv_spi_bus_data *spi_bus_data = (struct drv_spi_bus_data *)spi_bus->device.data;
|
||||
|
||||
/* ... */
|
||||
|
||||
return MR_ERR_OK;
|
||||
}
|
||||
|
||||
static void drv_spi_write(mr_spi_bus_t spi_bus, mr_uint32_t data)
|
||||
{
|
||||
struct drv_spi_bus_data *spi_bus_data = (struct drv_spi_bus_data *)spi_bus->device.data;
|
||||
|
||||
/* ... */
|
||||
}
|
||||
|
||||
static mr_uint32_t drv_spi_read(mr_spi_bus_t spi_bus)
|
||||
{
|
||||
struct drv_spi_bus_data *spi_bus_data = (struct drv_spi_bus_data *)spi_bus->device.data;
|
||||
mr_uint32_t data = 0;
|
||||
|
||||
/* ... */
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
static void drv_spi_cs_write(mr_spi_bus_t spi_bus, mr_off_t cs_number, mr_level_t level)
|
||||
{
|
||||
struct drv_spi_bus_data *spi_bus_data = (struct drv_spi_bus_data *)spi_bus->device.data;
|
||||
|
||||
/* ... */
|
||||
}
|
||||
|
||||
static mr_level_t drv_spi_cs_read(mr_spi_bus_t spi_bus, mr_off_t cs_number)
|
||||
{
|
||||
struct drv_spi_bus_data *spi_bus_data = (struct drv_spi_bus_data *)spi_bus->device.data;
|
||||
mr_level_t level = MR_LOW;
|
||||
|
||||
/* ... */
|
||||
|
||||
return level;
|
||||
}
|
||||
|
||||
mr_err_t drv_spi_bus_init(void)
|
||||
{
|
||||
static struct mr_spi_bus_ops drv_ops =
|
||||
{
|
||||
drv_spi_configure,
|
||||
drv_spi_write,
|
||||
drv_spi_read,
|
||||
drv_spi_cs_write,
|
||||
drv_spi_cs_read,
|
||||
};
|
||||
mr_size_t count = mr_array_num(spi_bus_device);
|
||||
mr_err_t ret = MR_ERR_OK;
|
||||
|
||||
while (count--)
|
||||
{
|
||||
ret =
|
||||
mr_spi_bus_add(&spi_bus_device[count], drv_spi_bus_data[count].name, &drv_ops, &drv_spi_bus_data[count]);
|
||||
MR_ASSERT(ret == MR_ERR_OK);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
MR_INIT_DRIVER_EXPORT(drv_spi_bus_init);
|
||||
|
||||
#endif
|
||||
31
driver/drv_spi.h
Normal file
31
driver/drv_spi.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2023, mr-library Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-10-8 MacRsh first version
|
||||
*/
|
||||
|
||||
#ifndef _DRV_SPI_H_
|
||||
#define _DRV_SPI_H_
|
||||
|
||||
#include "device/spi.h"
|
||||
#include "mrboard.h"
|
||||
|
||||
#if (MR_CFG_SPI == MR_CFG_ENABLE)
|
||||
|
||||
/**
|
||||
* @struct Driver spi bus data
|
||||
*/
|
||||
struct drv_spi_bus_data
|
||||
{
|
||||
const char *name;
|
||||
|
||||
/* ... */
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _DRV_SPI_H_ */
|
||||
92
driver/drv_timer.c
Normal file
92
driver/drv_timer.c
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2023, mr-library Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-10-8 MacRsh first version
|
||||
*/
|
||||
|
||||
#include "drv_timer.h"
|
||||
|
||||
#if (MR_CFG_TIMER == MR_CFG_ENABLE)
|
||||
|
||||
static struct drv_timer_data drv_timer_data[] =
|
||||
{
|
||||
#ifdef MR_BSP_TIMER_1
|
||||
{"timer1", /* ... */},
|
||||
#endif
|
||||
#ifdef MR_BSP_TIMER_2
|
||||
{"timer2", /* ... */},
|
||||
#endif
|
||||
#ifdef MR_BSP_TIMER_3
|
||||
{"timer3", /* ... */},
|
||||
#endif
|
||||
/* ... */
|
||||
};
|
||||
|
||||
static struct mr_timer_data timer_device_data = {/* ... */};
|
||||
|
||||
static struct mr_timer timer_device[mr_array_num(drv_timer_data)];
|
||||
|
||||
static mr_err_t drv_timer_configure(mr_timer_t timer, mr_state_t state)
|
||||
{
|
||||
struct drv_timer_data *timer_data = (struct drv_timer_data *)timer->device.data;
|
||||
|
||||
/* ... */
|
||||
|
||||
return MR_ERR_OK;
|
||||
}
|
||||
|
||||
static void drv_timer_start(mr_timer_t timer, mr_uint32_t prescaler, mr_uint32_t period)
|
||||
{
|
||||
struct drv_timer_data *timer_data = (struct drv_timer_data *)timer->device.data;
|
||||
|
||||
/* ... */
|
||||
}
|
||||
|
||||
static void drv_timer_stop(mr_timer_t timer)
|
||||
{
|
||||
struct drv_timer_data *timer_data = (struct drv_timer_data *)timer->device.data;
|
||||
|
||||
/* ... */
|
||||
}
|
||||
|
||||
static mr_uint32_t drv_timer_get_count(mr_timer_t timer)
|
||||
{
|
||||
struct drv_timer_data *timer_data = (struct drv_timer_data *)timer->device.data;
|
||||
mr_uint32_t count = 0;
|
||||
|
||||
/* ... */
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
mr_err_t drv_timer_init(void)
|
||||
{
|
||||
static struct mr_timer_ops drv_ops =
|
||||
{
|
||||
drv_timer_configure,
|
||||
drv_timer_start,
|
||||
drv_timer_stop,
|
||||
drv_timer_get_count,
|
||||
};
|
||||
mr_size_t count = mr_array_num(timer_device);
|
||||
mr_err_t ret = MR_ERR_OK;
|
||||
|
||||
while (count--)
|
||||
{
|
||||
ret = mr_timer_device_add(&timer_device[count],
|
||||
drv_timer_data[count].name,
|
||||
&drv_ops,
|
||||
&timer_device_data,
|
||||
&drv_timer_data[count]);
|
||||
MR_ASSERT(ret == MR_ERR_OK);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
MR_INIT_DRIVER_EXPORT(drv_timer_init);
|
||||
|
||||
#endif
|
||||
31
driver/drv_timer.h
Normal file
31
driver/drv_timer.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2023, mr-library Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-10-8 MacRsh first version
|
||||
*/
|
||||
|
||||
#ifndef _DRV_TIMER_H_
|
||||
#define _DRV_TIMER_H_
|
||||
|
||||
#include "device/timer.h"
|
||||
#include "mrboard.h"
|
||||
|
||||
#if (MR_CFG_TIMER == MR_CFG_ENABLE)
|
||||
|
||||
/**
|
||||
* @struct Driver timer data
|
||||
*/
|
||||
struct drv_timer_data
|
||||
{
|
||||
const char *name;
|
||||
|
||||
/* ... */
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _DRV_TIMER_H_ */
|
||||
94
driver/drv_uart.c
Normal file
94
driver/drv_uart.c
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) 2023, mr-library Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-10-8 MacRsh first version
|
||||
*/
|
||||
|
||||
#include "drv_uart.h"
|
||||
|
||||
#if (MR_CFG_SERIAL == MR_CFG_ENABLE)
|
||||
|
||||
static struct drv_uart_data drv_uart_data[] =
|
||||
{
|
||||
#ifdef MR_BSP_UART_1
|
||||
{"uart1", /* ... */},
|
||||
#endif
|
||||
#ifdef MR_BSP_UART_2
|
||||
{"uart2", /* ... */},
|
||||
#endif
|
||||
#ifdef MR_BSP_UART_3
|
||||
{"uart3", /* ... */},
|
||||
#endif
|
||||
/* ... */
|
||||
};
|
||||
|
||||
static struct mr_serial serial_device[mr_array_num(drv_uart_data)];
|
||||
|
||||
static mr_err_t drv_serial_configure(mr_serial_t serial, struct mr_serial_config *config)
|
||||
{
|
||||
struct drv_uart_data *uart_data = (struct drv_uart_data *)serial->device.data;
|
||||
|
||||
/* ... */
|
||||
|
||||
return MR_ERR_OK;
|
||||
}
|
||||
|
||||
static void drv_serial_write(mr_serial_t serial, mr_uint8_t data)
|
||||
{
|
||||
struct drv_uart_data *uart_data = (struct drv_uart_data *)serial->device.data;
|
||||
|
||||
/* ... */
|
||||
}
|
||||
|
||||
static mr_uint8_t drv_serial_read(mr_serial_t serial)
|
||||
{
|
||||
struct drv_uart_data *uart_data = (struct drv_uart_data *)serial->device.data;
|
||||
mr_uint8_t data = 0;
|
||||
|
||||
/* ... */
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
static void drv_serial_start_tx(mr_serial_t serial)
|
||||
{
|
||||
struct drv_uart_data *uart_data = (struct drv_uart_data *)serial->device.data;
|
||||
|
||||
/* ... */
|
||||
}
|
||||
|
||||
static void drv_serial_stop_tx(mr_serial_t serial)
|
||||
{
|
||||
struct drv_uart_data *uart_data = (struct drv_uart_data *)serial->device.data;
|
||||
|
||||
/* ... */
|
||||
}
|
||||
|
||||
mr_err_t drv_uart_init(void)
|
||||
{
|
||||
static struct mr_serial_ops drv_ops =
|
||||
{
|
||||
drv_serial_configure,
|
||||
drv_serial_write,
|
||||
drv_serial_read,
|
||||
drv_serial_start_tx,
|
||||
drv_serial_stop_tx,
|
||||
};
|
||||
mr_size_t count = mr_array_num(serial_device);
|
||||
mr_err_t ret = MR_ERR_OK;
|
||||
|
||||
while (count--)
|
||||
{
|
||||
ret = mr_serial_device_add(&serial_device[count], drv_uart_data[count].name, &drv_ops, &drv_uart_data[count]);
|
||||
MR_ASSERT(ret == MR_ERR_OK);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
MR_INIT_DRIVER_EXPORT(drv_uart_init);
|
||||
|
||||
#endif
|
||||
31
driver/drv_uart.h
Normal file
31
driver/drv_uart.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2023, mr-library Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-10-8 MacRsh first version
|
||||
*/
|
||||
|
||||
#ifndef _DRV_UART_H_
|
||||
#define _DRV_UART_H_
|
||||
|
||||
#include "device/serial.h"
|
||||
#include "mrboard.h"
|
||||
|
||||
#if (MR_CFG_SERIAL == MR_CFG_ENABLE)
|
||||
|
||||
/**
|
||||
* @struct Driver uart data
|
||||
*/
|
||||
struct drv_uart_data
|
||||
{
|
||||
const char *name;
|
||||
|
||||
/* ... */
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _DRV_UART_H_ */
|
||||
@@ -8,4 +8,38 @@
|
||||
* 2023-09-11 MacRsh first version
|
||||
*/
|
||||
|
||||
#include "mrboard.h"
|
||||
#include "mrboard.h"
|
||||
|
||||
int mr_board_init(void)
|
||||
{
|
||||
return MR_ERR_OK;
|
||||
}
|
||||
MR_INIT_BOARD_EXPORT(mr_board_init);
|
||||
|
||||
void mr_assert_handle(char *file, int line)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void mr_interrupt_disable(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void mr_interrupt_enable(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void mr_delay_us(mr_size_t us)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void mr_delay_ms(mr_size_t ms)
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user