Skip to content

Commit be79333

Browse files
committed
完善ra6w1的基础BSP驱动
1 parent 9d04b6b commit be79333

45 files changed

Lines changed: 11756 additions & 471 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bsp/renesas/libraries/HAL_Drivers/drivers/config/drv_config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ extern "C"
290290
#if defined(SOC_FAMILY_RENESAS_RA_WIRELESS)
291291
#if defined(SOC_SERIES_R7SA6W1)
292292
#include "raw/ra6w1/uart_config.h"
293+
#ifdef BSP_USING_ADC
294+
#include "raw/ra6w1/adc_config.h"
295+
#endif
296+
293297
#endif /* SOC_SERIES_R7SA6W1 */
294298
#endif /* SOC_FAMILY_RENESAS_RA_WIRELESS */
295299

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2006-2026, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2026-07-29 rcitach first version
9+
*/
10+
11+
#ifndef __ADC_CONFIG_H__
12+
#define __ADC_CONFIG_H__
13+
14+
#include <rtthread.h>
15+
#include <rtdevice.h>
16+
#include "hal_data.h"
17+
18+
#ifdef __cplusplus
19+
extern "C" {
20+
#endif
21+
22+
#if defined(BSP_USING_ADC)
23+
24+
#ifndef BSP_USING_ADC0
25+
#define BSP_USING_ADC0
26+
#endif
27+
28+
struct rt_adc_dev
29+
{
30+
struct rt_adc_ops ops;
31+
struct rt_adc_device adc_device;
32+
};
33+
34+
struct ra_adc_map
35+
{
36+
const char *device_name;
37+
const adc_cfg_t *g_cfg;
38+
const adc_ctrl_t *g_ctrl;
39+
const void *g_channel_cfg;
40+
};
41+
#endif
42+
43+
#ifdef __cplusplus
44+
}
45+
#endif
46+
47+
#endif /* __ADC_CONFIG_H__ */

bsp/renesas/libraries/HAL_Drivers/drivers/config/raw/ra6w1/uart_config.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ extern "C" {
2323
#define UART0_CONFIG \
2424
{ \
2525
.name = "uart0", \
26-
.p_api_ctrl = &g_uart1_ctrl, \
27-
.p_cfg = &g_uart1_cfg, \
26+
.p_api_ctrl = &g_uart0_ctrl, \
27+
.p_cfg = &g_uart0_cfg, \
2828
}
2929
#endif /* UART0_CONFIG */
3030
#endif /* BSP_USING_UART0 */
@@ -34,8 +34,8 @@ extern "C" {
3434
#define UART1_CONFIG \
3535
{ \
3636
.name = "uart1", \
37-
.p_api_ctrl = &g_uart2_ctrl, \
38-
.p_cfg = &g_uart2_cfg, \
37+
.p_api_ctrl = &g_uart1_ctrl, \
38+
.p_cfg = &g_uart1_cfg, \
3939
}
4040
#endif /* UART1_CONFIG */
4141
#endif /* BSP_USING_UART1 */
@@ -45,8 +45,8 @@ extern "C" {
4545
#define UART2_CONFIG \
4646
{ \
4747
.name = "uart2", \
48-
.p_api_ctrl = &g_uart3_ctrl, \
49-
.p_cfg = &g_uart3_cfg, \
48+
.p_api_ctrl = &g_uart2_ctrl, \
49+
.p_cfg = &g_uart2_cfg, \
5050
}
5151
#endif /* UART2_CONFIG */
5252
#endif /* BSP_USING_UART2 */

bsp/renesas/libraries/HAL_Drivers/drivers/drv_adc.c

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
#ifdef RT_USING_ADC
1313

1414
#define DRV_DEBUG
15-
#define DBG_TAG "drv.adc"
15+
#define DBG_TAG "drv.adc"
1616
#ifdef DRV_DEBUG
17-
#define DBG_LVL DBG_LOG
17+
#define DBG_LVL DBG_LOG
1818
#else
19-
#define DBG_LVL DBG_INFO
19+
#define DBG_LVL DBG_INFO
2020
#endif /* DRV_DEBUG */
2121
#include <rtdbg.h>
2222

@@ -26,36 +26,46 @@
2626
#define R_ADC_ScanCfg R_ADC_B_ScanCfg
2727
#define R_ADC_ScanStart R_ADC_B_ScanStart
2828
#define R_ADC_Read32 R_ADC_B_Read32
29-
#define R_ADC_Read R_ADC_B_Read
29+
#define R_ADC_Read R_ADC_B_Read
3030
#define R_ADC_ScanStop R_ADC_B_ScanStop
31+
#define R_ADC_Close R_ADC_B_Close
32+
33+
#elif defined(SOC_SERIES_R7SA6W1)
34+
35+
#define R_ADC_Open R_ADC_W_Open
36+
#define R_ADC_ScanCfg R_ADC_W_ScanCfg
37+
#define R_ADC_ScanStart R_ADC_W_ScanStart
38+
#define R_ADC_Read32 R_ADC_W_Read32
39+
#define R_ADC_Read R_ADC_W_Read
40+
#define R_ADC_ScanStop R_ADC_W_ScanStop
41+
#define R_ADC_Close R_ADC_W_Close
3142

3243
#endif
3344

34-
struct ra_adc_map ra_adc[] =
35-
{
45+
struct ra_adc_map ra_adc[] = {
3646
#ifdef BSP_USING_ADC0
3747
{
38-
.device_name = "adc0",
39-
.g_cfg = &g_adc0_cfg,
40-
.g_ctrl = &g_adc0_ctrl,
48+
.device_name = "adc0",
49+
.g_cfg = &g_adc0_cfg,
50+
.g_ctrl = &g_adc0_ctrl,
4151
#ifdef SOC_SERIES_R7KA8P1
42-
.g_channel_cfg = &g_adc0_scan_cfg,
52+
.g_channel_cfg = &g_adc0_scan_cfg,
4353
#else
44-
.g_channel_cfg = &g_adc0_channel_cfg,
54+
.g_channel_cfg = &g_adc0_channel_cfg,
4555
#endif
4656
},
4757
#endif
4858
#ifdef BSP_USING_ADC1
4959
{
50-
.device_name = "adc1",
51-
.g_cfg = &g_adc1_cfg,
52-
.g_ctrl = &g_adc1_ctrl,
53-
.g_channel_cfg = &g_adc1_channel_cfg,
60+
.device_name = "adc1",
61+
.g_cfg = &g_adc1_cfg,
62+
.g_ctrl = &g_adc1_ctrl,
63+
.g_channel_cfg = &g_adc1_channel_cfg,
5464
},
5565
#endif
5666
};
5767

58-
static struct rt_adc_dev adc_obj[sizeof(ra_adc) / sizeof(ra_adc[0])] = {0};
68+
static struct rt_adc_dev adc_obj[sizeof(ra_adc) / sizeof(ra_adc[0])] = { 0 };
5969

6070
static rt_err_t ra_adc_enabled(struct rt_adc_device *device, rt_int8_t channel, rt_bool_t enabled)
6171
{
@@ -106,10 +116,22 @@ static rt_err_t ra_get_adc_value(struct rt_adc_device *device, rt_int8_t channel
106116
return RT_EOK;
107117
}
108118

109-
static const struct rt_adc_ops ra_adc_ops =
119+
static rt_uint8_t ra_adc_get_resolution(struct rt_adc_device *device)
110120
{
121+
LOG_W("ra_adc_get_resolution is not supported.");
122+
return 0;
123+
}
124+
static rt_int16_t ra_adc_get_vref(struct rt_adc_device *device)
125+
{
126+
LOG_W("ra_adc_get_vref is not supported.");
127+
return 0;
128+
}
129+
130+
static const struct rt_adc_ops ra_adc_ops = {
111131
.enabled = ra_adc_enabled,
112132
.convert = ra_get_adc_value,
133+
.get_resolution = ra_adc_get_resolution,
134+
.get_vref = ra_adc_get_vref,
113135
};
114136

115137
static int ra_adc_init(void)
@@ -125,10 +147,10 @@ static int ra_adc_init(void)
125147
result = R_ADC_ScanCfg((adc_ctrl_t *)ra_adc[i].g_ctrl, ra_adc[i].g_channel_cfg);
126148

127149
/* register ADC device */
128-
if(rt_hw_adc_register(&adc_obj[i].adc_device,
129-
ra_adc[i].device_name,
130-
&ra_adc_ops,
131-
&ra_adc[i]) == RT_EOK)
150+
if (rt_hw_adc_register(&adc_obj[i].adc_device,
151+
ra_adc[i].device_name,
152+
&ra_adc_ops,
153+
&ra_adc[i]) == RT_EOK)
132154
{
133155
LOG_D("%s init success", ra_adc[i].device_name);
134156
}

bsp/renesas/libraries/HAL_Drivers/drivers/drv_i2c.c

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,33 @@
1717
#ifdef BSP_USING_HW_I2C
1818

1919
#define DRV_DEBUG
20-
#define LOG_TAG "drv.hwi2c"
20+
#define LOG_TAG "drv.hwi2c"
2121
#include <drv_log.h>
2222

2323
#include <hal_data.h>
2424

25-
#ifndef BIT
26-
#define BIT(idx) (1ul << (idx))
27-
#endif
25+
#define RA_SCI_EVENT_ABORTED 0x01
26+
#define RA_SCI_EVENT_RX_COMPLETE 0x02
27+
#define RA_SCI_EVENT_TX_COMPLETE 0x04
28+
#define RA_SCI_EVENT_ERROR 0x08
29+
#define RA_SCI_EVENT_ALL 0x0F
2830

29-
#ifndef BITS
30-
#define BITS(b,e) ((((uint32_t)-1)<<(b))&(((uint32_t)-1)>>(31-(e))))
31-
#endif
31+
#if defined(SOC_SERIES_R7FA2E2)
32+
33+
#define R_IIC_MASTER_Open R_IIC_B_MASTER_Open
34+
#define R_IIC_MASTER_Write R_IIC_B_MASTER_Write
35+
#define R_IIC_MASTER_Read R_IIC_B_MASTER_Read
36+
#define R_IIC_MASTER_SlaveAddressSet R_IIC_B_MASTER_SlaveAddressSet
37+
#define R_IIC_MASTER_CallbackSet R_IIC_B_MASTER_CallbackSet
38+
39+
#elif defined(SOC_SERIES_R7SA6W1)
40+
41+
#define R_IIC_MASTER_Open R_I2C_MASTER_W_Open
42+
#define R_IIC_MASTER_Write R_I2C_MASTER_W_Write
43+
#define R_IIC_MASTER_Read R_I2C_MASTER_W_Read
44+
#define R_IIC_MASTER_SlaveAddressSet R_I2C_MASTER_W_SlaveAddressSet
45+
#define R_IIC_MASTER_CallbackSet R_I2C_MASTER_W_CallbackSet
3246

33-
#define RA_SCI_EVENT_ABORTED BIT(0)
34-
#define RA_SCI_EVENT_RX_COMPLETE BIT(1)
35-
#define RA_SCI_EVENT_TX_COMPLETE BIT(2)
36-
#define RA_SCI_EVENT_ERROR BIT(3)
37-
#define RA_SCI_EVENT_ALL BITS(0,3)
38-
39-
#ifdef SOC_SERIES_R7FA2E2
40-
#define R_IIC_MASTER_Open R_IIC_B_MASTER_Open
41-
#define R_IIC_MASTER_Write R_IIC_B_MASTER_Write
42-
#define R_IIC_MASTER_Read R_IIC_B_MASTER_Read
43-
#define R_IIC_MASTER_SlaveAddressSet R_IIC_B_MASTER_SlaveAddressSet
44-
#define R_IIC_MASTER_CallbackSet R_IIC_B_MASTER_CallbackSet
4547
#endif
4648

4749
struct ra_i2c_handle
@@ -53,16 +55,27 @@ struct ra_i2c_handle
5355
struct rt_event event;
5456
};
5557

56-
static struct ra_i2c_handle ra_i2cs[] =
57-
{
58+
static struct ra_i2c_handle ra_i2cs[] = {
5859
#ifdef BSP_USING_HW_I2C0
59-
{.bus_name = "i2c0", .i2c_cfg = &g_i2c_master0_cfg, .i2c_ctrl = &g_i2c_master0_ctrl,},
60+
{
61+
.bus_name = "i2c0",
62+
.i2c_cfg = &g_i2c_master0_cfg,
63+
.i2c_ctrl = &g_i2c_master0_ctrl,
64+
},
6065
#endif
6166
#ifdef BSP_USING_HW_I2C1
62-
{.bus_name = "i2c1", .i2c_cfg = &g_i2c_master1_cfg, .i2c_ctrl = &g_i2c_master1_ctrl,},
67+
{
68+
.bus_name = "i2c1",
69+
.i2c_cfg = &g_i2c_master1_cfg,
70+
.i2c_ctrl = &g_i2c_master1_ctrl,
71+
},
6372
#endif
6473
#ifdef BSP_USING_HW_I2C2
65-
{.bus_name = "i2c2", .i2c_cfg = &g_i2c_master2_cfg, .i2c_ctrl = &g_i2c_master2_ctrl,},
74+
{
75+
.bus_name = "i2c2",
76+
.i2c_cfg = &g_i2c_master2_cfg,
77+
.i2c_ctrl = &g_i2c_master2_ctrl,
78+
},
6679
#endif
6780
};
6881

@@ -177,16 +190,15 @@ static rt_ssize_t ra_i2c_mst_xfer(struct rt_i2c_bus_device *bus,
177190
return (rt_ssize_t)i;
178191
}
179192

180-
static const struct rt_i2c_bus_device_ops ra_i2c_ops =
181-
{
182-
.master_xfer = ra_i2c_mst_xfer,
183-
.slave_xfer = RT_NULL,
184-
.i2c_bus_control = RT_NULL
193+
static const struct rt_i2c_bus_device_ops ra_i2c_ops = {
194+
.master_xfer = ra_i2c_mst_xfer,
195+
.slave_xfer = RT_NULL,
196+
.i2c_bus_control = RT_NULL
185197
};
186198

187199
int ra_hw_i2c_init(void)
188200
{
189-
fsp_err_t err = FSP_SUCCESS;
201+
fsp_err_t err = FSP_SUCCESS;
190202
for (rt_uint32_t i = 0; i < sizeof(ra_i2cs) / sizeof(ra_i2cs[0]); i++)
191203
{
192204
ra_i2cs[i].bus.ops = &ra_i2c_ops;

0 commit comments

Comments
 (0)