Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bsp][renesas]Update ek-ra8d1 bsp. #8768

Merged
merged 5 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions bsp/renesas/libraries/HAL_Drivers/config/ra2l1/adc_config.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2024, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
Expand All @@ -19,18 +19,19 @@ extern "C" {
#endif

#if defined(BSP_USING_ADC0) || defined(BSP_USING_ADC1)
struct ra_adc_map

struct rt_adc_dev
{
char name;
const adc_cfg_t *g_cfg;
const adc_instance_ctrl_t *g_ctrl;
const adc_channel_cfg_t *g_channel_cfg;
struct rt_adc_ops ops;
struct rt_adc_device adc_device;
};

struct ra_dev
struct ra_adc_map
{
rt_adc_device_t ra_adc_device_t;
struct ra_adc_map *ra_adc_dev;
const char *device_name;
const adc_cfg_t *g_cfg;
const adc_ctrl_t *g_ctrl;
const adc_channel_cfg_t *g_channel_cfg;
};
#endif
#endif
Expand Down
19 changes: 10 additions & 9 deletions bsp/renesas/libraries/HAL_Drivers/config/ra4m2/adc_config.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2024, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
Expand All @@ -19,18 +19,19 @@ extern "C" {
#endif

#if defined(BSP_USING_ADC0) || defined(BSP_USING_ADC1)
struct ra_adc_map

struct rt_adc_dev
{
char name;
const adc_cfg_t *g_cfg;
const adc_instance_ctrl_t *g_ctrl;
const adc_channel_cfg_t *g_channel_cfg;
struct rt_adc_ops ops;
struct rt_adc_device adc_device;
};

struct ra_dev
struct ra_adc_map
{
rt_adc_device_t ra_adc_device_t;
struct ra_adc_map *ra_adc_dev;
const char *device_name;
const adc_cfg_t *g_cfg;
const adc_ctrl_t *g_ctrl;
const adc_channel_cfg_t *g_channel_cfg;
};
#endif
#endif
Expand Down
19 changes: 10 additions & 9 deletions bsp/renesas/libraries/HAL_Drivers/config/ra6m3/adc_config.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
* Copyright (c) 2006-2024, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
Expand All @@ -19,18 +19,19 @@ extern "C" {
#endif

#if defined(BSP_USING_ADC0) || defined(BSP_USING_ADC1)
struct ra_adc_map

struct rt_adc_dev
{
char name;
const adc_cfg_t *g_cfg;
const adc_instance_ctrl_t *g_ctrl;
const adc_channel_cfg_t *g_channel_cfg;
struct rt_adc_ops ops;
struct rt_adc_device adc_device;
};

struct ra_dev
struct ra_adc_map
{
rt_adc_device_t ra_adc_device_t;
struct ra_adc_map *ra_adc_dev;
const char *device_name;
const adc_cfg_t *g_cfg;
const adc_ctrl_t *g_ctrl;
const adc_channel_cfg_t *g_channel_cfg;
};
#endif
#endif
Expand Down
19 changes: 10 additions & 9 deletions bsp/renesas/libraries/HAL_Drivers/config/ra6m4/adc_config.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2024, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
Expand All @@ -19,18 +19,19 @@ extern "C" {
#endif

#if defined(BSP_USING_ADC0) || defined(BSP_USING_ADC1)
struct ra_adc_map

struct rt_adc_dev
{
char name;
const adc_cfg_t *g_cfg;
const adc_instance_ctrl_t *g_ctrl;
const adc_channel_cfg_t *g_channel_cfg;
struct rt_adc_ops ops;
struct rt_adc_device adc_device;
};

struct ra_dev
struct ra_adc_map
{
rt_adc_device_t ra_adc_device_t;
struct ra_adc_map *ra_adc_dev;
const char *device_name;
const adc_cfg_t *g_cfg;
const adc_ctrl_t *g_ctrl;
const adc_channel_cfg_t *g_channel_cfg;
};
#endif
#endif
Expand Down
19 changes: 10 additions & 9 deletions bsp/renesas/libraries/HAL_Drivers/config/ra6m5/adc_config.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2024, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
Expand All @@ -19,18 +19,19 @@ extern "C" {
#endif

#if defined(BSP_USING_ADC0) || defined(BSP_USING_ADC1)
struct ra_adc_map

struct rt_adc_dev
{
char name;
const adc_cfg_t *g_cfg;
const adc_instance_ctrl_t *g_ctrl;
const adc_channel_cfg_t *g_channel_cfg;
struct rt_adc_ops ops;
struct rt_adc_device adc_device;
};

struct ra_dev
struct ra_adc_map
{
rt_adc_device_t ra_adc_device_t;
struct ra_adc_map *ra_adc_dev;
const char *device_name;
const adc_cfg_t *g_cfg;
const adc_ctrl_t *g_ctrl;
const adc_channel_cfg_t *g_channel_cfg;
};
#endif
#endif
Expand Down
19 changes: 10 additions & 9 deletions bsp/renesas/libraries/HAL_Drivers/config/ra8/adc_config.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
* Copyright (c) 2006-2024, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
Expand All @@ -19,18 +19,19 @@ extern "C" {
#endif

#if defined(BSP_USING_ADC0) || defined(BSP_USING_ADC1)
struct ra_adc_map

struct rt_adc_dev
{
char name;
const adc_cfg_t *g_cfg;
const adc_instance_ctrl_t *g_ctrl;
const adc_channel_cfg_t *g_channel_cfg;
struct rt_adc_ops ops;
struct rt_adc_device adc_device;
};

struct ra_dev
struct ra_adc_map
{
rt_adc_device_t ra_adc_device_t;
struct ra_adc_map *ra_adc_dev;
const char *device_name;
const adc_cfg_t *g_cfg;
const adc_ctrl_t *g_ctrl;
const adc_channel_cfg_t *g_channel_cfg;
};
#endif
#endif
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
* Copyright (c) 2006-2024, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down
86 changes: 42 additions & 44 deletions bsp/renesas/libraries/HAL_Drivers/drv_adc.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2024, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
Expand All @@ -11,7 +11,7 @@
#include "drv_config.h"
#ifdef RT_USING_ADC

// #define DRV_DEBUG
#define DRV_DEBUG
#define DBG_TAG "drv.adc"
#ifdef DRV_DEBUG
#define DBG_LVL DBG_LOG
Expand All @@ -22,24 +22,25 @@

struct ra_adc_map ra_adc[] =
{
#if defined(BSP_USING_ADC0)
{'0', &g_adc0_cfg, &g_adc0_ctrl, &g_adc0_channel_cfg},
#ifdef BSP_USING_ADC0
{
.device_name = "adc0",
.g_cfg = &g_adc0_cfg,
.g_ctrl = &g_adc0_ctrl,
.g_channel_cfg = &g_adc0_channel_cfg,
},
#endif

#if defined(BSP_USING_ADC1)
{'1', &g_adc1_cfg, &g_adc1_ctrl, &g_adc1_channel_cfg},
#ifdef BSP_USING_ADC1
{
.device_name = "adc1",
.g_cfg = &g_adc1_cfg,
.g_ctrl = &g_adc1_ctrl,
.g_channel_cfg = &g_adc1_channel_cfg,
},
#endif
};

#if defined(BSP_USING_ADC0)
struct rt_adc_device adc0_device;
struct ra_dev _ra_adc0_device = {.ra_adc_device_t = &adc0_device, .ra_adc_dev = &ra_adc[0]};
#endif

#if defined(BSP_USING_ADC1)
struct rt_adc_device adc1_device;
struct ra_dev _ra_adc1_device = {.ra_adc_device_t = &adc1_device, .ra_adc_dev = &ra_adc[1]};
#endif
static struct rt_adc_dev adc_obj[sizeof(ra_adc) / sizeof(ra_adc[0])] = {0};

static rt_err_t ra_adc_enabled(struct rt_adc_device *device, rt_int8_t channel, rt_bool_t enabled)
{
Expand All @@ -50,7 +51,7 @@ static rt_err_t ra_adc_enabled(struct rt_adc_device *device, rt_int8_t channel,
{
if (FSP_SUCCESS != R_ADC_ScanStart((adc_ctrl_t *)adc->g_ctrl))
{
LOG_E("start adc%c failed.", adc->name);
LOG_E("start %s failed.", adc->device_name);
return -RT_ERROR;
}
}
Expand All @@ -59,7 +60,7 @@ static rt_err_t ra_adc_enabled(struct rt_adc_device *device, rt_int8_t channel,
/**< stop adc*/
if (FSP_SUCCESS != R_ADC_ScanStop((adc_ctrl_t *)adc->g_ctrl))
{
LOG_E("stop adc%c failed.", adc->name);
LOG_E("stop %s failed.", adc->device_name);
return -RT_ERROR;
}
}
Expand All @@ -69,10 +70,10 @@ static rt_err_t ra_adc_enabled(struct rt_adc_device *device, rt_int8_t channel,
rt_err_t ra_adc_close(struct rt_adc_device *device)
{
RT_ASSERT(device != RT_NULL);
struct ra_adc_map *adc = (struct ra_adc_map *)(struct ra_adc_map *)device->parent.user_data;
struct ra_adc_map *adc = (struct ra_adc_map *)device->parent.user_data;
if (FSP_SUCCESS != R_ADC_Close((adc_ctrl_t *)adc->g_ctrl))
{
LOG_E("close adc%c failed.", adc->name);
LOG_E("close %s failed.", adc->device_name);
return -RT_ERROR;
}
return RT_EOK;
Expand All @@ -98,35 +99,32 @@ static const struct rt_adc_ops ra_adc_ops =

static int ra_adc_init(void)
{
#if defined(BSP_USING_ADC0)
R_ADC_Open((adc_ctrl_t *)_ra_adc0_device.ra_adc_dev->g_ctrl,
(adc_cfg_t const * const)_ra_adc0_device.ra_adc_dev->g_cfg);

R_ADC_ScanCfg((adc_ctrl_t *)_ra_adc0_device.ra_adc_dev->g_ctrl,
(adc_cfg_t const * const)_ra_adc0_device.ra_adc_dev->g_channel_cfg);
rt_err_t result = 0;
rt_size_t obj_num = sizeof(adc_obj) / sizeof(struct rt_adc_dev);

if (RT_EOK != rt_hw_adc_register(_ra_adc0_device.ra_adc_device_t, "adc0", &ra_adc_ops, (void *)_ra_adc0_device.ra_adc_dev))
for (int i = 0; i < obj_num; i++)
{
LOG_E("adc0 register failed");
return -RT_ERROR;
}
#endif

#if defined(BSP_USING_ADC1)
R_ADC_Open((adc_ctrl_t *)_ra_adc1_device.ra_adc_dev->g_ctrl,
(adc_cfg_t const * const)_ra_adc1_device.ra_adc_dev->g_cfg);
/* init ADC object */
result = R_ADC_Open((adc_ctrl_t *)ra_adc[i].g_ctrl, ra_adc[i].g_cfg);

R_ADC_ScanCfg((adc_ctrl_t *)_ra_adc1_device.ra_adc_dev->g_ctrl,
(adc_cfg_t const * const)_ra_adc1_device.ra_adc_dev->g_channel_cfg);
result = R_ADC_ScanCfg((adc_ctrl_t *)ra_adc[i].g_ctrl, ra_adc[i].g_channel_cfg);

if (RT_EOK != rt_hw_adc_register(_ra_adc1_device.ra_adc_device_t, "adc1", &ra_adc_ops, (void *)_ra_adc1_device.ra_adc_dev))
{
LOG_E("adc1 register failed");
return -RT_ERROR;
/* register ADC device */
if(rt_hw_adc_register(&adc_obj[i].adc_device,
ra_adc[i].device_name,
&ra_adc_ops,
&ra_adc[i]) == RT_EOK)
{
LOG_D("%s init success", ra_adc[i].device_name);
}
else
{
LOG_E("%s register failed", ra_adc[i].device_name);
result = -RT_ERROR;
}
RT_ASSERT(result == RT_EOK);
}
#endif

return RT_EOK;
}
INIT_BOARD_EXPORT(ra_adc_init);
INIT_DEVICE_EXPORT(ra_adc_init);
#endif
Loading
Loading