Skip to content

Commit 6481998

Browse files
committed
Merge branch 'master' of https://github.com/RT-Thread/rt-thread into nuvoton
2 parents 1577e91 + e665bac commit 6481998

File tree

137 files changed

+6551
-43763
lines changed

Some content is hidden

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

137 files changed

+6551
-43763
lines changed

bsp/gd32/gd32103c-eval/board/Kconfig

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,66 @@ menu "On-chip Peripheral Drivers"
7474
range 1 216
7575
default 25
7676
endif
77+
78+
config BSP_USING_WDT
79+
bool "Enable Watchdog Timer"
80+
select RT_USING_WDT
81+
default n
82+
83+
config BSP_USING_RTC
84+
bool "Enable Internal RTC"
85+
select RT_USING_RTC
86+
default n
87+
88+
menuconfig BSP_USING_HWTIMER
89+
bool "Enable hwtimer"
90+
default n
91+
select RT_USING_HWTIMER
92+
if BSP_USING_HWTIMER
93+
config BSP_USING_HWTIMER0
94+
bool "using hwtimer0"
95+
default n
96+
config BSP_USING_HWTIMER1
97+
bool "using hwtimer1"
98+
default n
99+
config BSP_USING_HWTIMER2
100+
bool "using hwtimer2"
101+
default n
102+
config BSP_USING_HWTIMER3
103+
bool "using hwtimer3"
104+
default n
105+
config BSP_USING_HWTIMER4
106+
bool "using hwtimer4"
107+
default n
108+
config BSP_USING_HWTIMER5
109+
bool "using hwtimer5"
110+
default n
111+
config BSP_USING_HWTIMER6
112+
bool "using hwtimer6"
113+
default n
114+
config BSP_USING_HWTIMER7
115+
bool "using hwtimer7"
116+
default n
117+
endif
118+
119+
menuconfig BSP_USING_ADC
120+
bool "Enable ADC"
121+
default n
122+
select RT_USING_ADC
123+
if BSP_USING_ADC
124+
config BSP_USING_ADC0
125+
bool "using adc0"
126+
default n
127+
config BSP_USING_ADC1
128+
bool "using adc1"
129+
default n
130+
endif
77131
source "../libraries/gd32_drivers/Kconfig"
78-
132+
79133
endmenu
80134

81135
menu "Board extended module Drivers"
82136

83137
endmenu
84-
138+
85139
endmenu

bsp/gd32/libraries/GD32F10x_Firmware_Library/SConscript

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ if GetDepend(['RT_USING_HWTIMER']):
4040

4141
if GetDepend(['RT_USING_RTC']):
4242
src += ['GD32F10x_standard_peripheral/Source/gd32f10x_rtc.c']
43+
src += ['GD32F10x_standard_peripheral/Source/gd32f10x_pmu.c']
4344

4445
if GetDepend(['RT_USING_WDT']):
4546
src += ['GD32F10x_standard_peripheral/Source/gd32f10x_wwdgt.c']

bsp/gd32/libraries/gd32_drivers/SConscript

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,21 @@ if GetDepend('RT_USING_SPI'):
2727

2828
# add spi flash drivers.
2929
if GetDepend('RT_USING_SFUD'):
30-
src += ['drv_spi_flash.c', 'drv_spi.c']
30+
src += ['drv_spi_flash.c', 'drv_spi.c']
3131

32-
path = [cwd]
32+
if GetDepend('RT_USING_WDT'):
33+
src += ['drv_wdt.c']
34+
35+
if GetDepend('RT_USING_RTC'):
36+
src += ['drv_rtc.c']
37+
38+
if GetDepend('RT_USING_HWTIMER'):
39+
src += ['drv_hwtimer.c']
40+
41+
if GetDepend('RT_USING_ADC'):
42+
src += ['drv_adc.c']
43+
44+
path = [cwd]
3345

3446
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = path)
3547

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
/*
2-
* Copyright (c) 2006-2021, RT-Thread Development Team
2+
* Copyright (c) 2006-2022, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
66
* Change Logs:
77
* Date Author Notes
8-
* 2021-01-03 iysheng first version
8+
* 2021-02-25 iysheng first version
99
*/
1010

1111
#include <board.h>
12-
#include <drivers/drv_comm.h>
1312
#include <drivers/adc.h>
1413

1514
#define DBG_TAG "drv.adc"
@@ -39,7 +38,7 @@ static gd32_adc_device g_gd32_devs[] = {
3938
GET_PIN(B, 0), GET_PIN(B, 1), GET_PIN(C, 0), GET_PIN(C, 1),
4039
GET_PIN(C, 2), GET_PIN(C, 3), GET_PIN(C, 4), GET_PIN(C, 5),
4140
},
42-
ADC0,
41+
(void *)ADC0,
4342
},
4443
#endif
4544

@@ -53,78 +52,67 @@ static gd32_adc_device g_gd32_devs[] = {
5352
GET_PIN(B, 0), GET_PIN(B, 1), GET_PIN(C, 0), GET_PIN(C, 1),
5453
GET_PIN(C, 2), GET_PIN(C, 3), GET_PIN(C, 4), GET_PIN(C, 5),
5554
},
56-
ADC1,
55+
(void *)ADC1,
5756
},
5857
#endif
5958
};
6059

6160
/*
6261
* static void init_pin4adc
6362
*
64-
* 初始化指定的管腳爲 analog 模式
6563
* @ rt_uint32_t pin: pin information
6664
* return: N/A
6765
*/
6866
static void init_pin4adc(rt_base_t pin)
6967
{
70-
GPIO_InitPara GPIO_InitStruct = {0};
71-
72-
GPIO_InitStruct.GPIO_Pin = PIN_GDPIN(pin);
73-
GPIO_InitStruct.GPIO_Speed = GPIO_SPEED_50MHZ;
74-
GPIO_InitStruct.GPIO_Mode = GPIO_MODE_AIN;
75-
GPIO_Init(PIN_GDPORT(pin), &GPIO_InitStruct);
68+
gpio_init(PIN_GDPORT(pin), GPIO_MODE_AIN, GPIO_OSPEED_50MHZ, PIN_GDPIN(pin));
7669
}
7770

7871
static rt_err_t gd32_adc_enabled(struct rt_adc_device *device, rt_uint32_t channel, rt_bool_t enabled)
7972
{
80-
ADC_TypeDef *ADCx;
81-
ADC_InitPara ADC_InitParaStruct = {0};
73+
uint32_t adc_periph;
8274
gd32_adc_device * gd32_adc = (gd32_adc_device *)device;
8375

8476
if (channel >= MAX_EXTERN_ADC_CHANNEL)
8577
{
8678
LOG_E("invalid channel");
87-
return -E2BIG;
79+
return -RT_EINVAL;
8880
}
8981

90-
ADCx = (ADC_TypeDef *)(device->parent.user_data);
82+
adc_periph = (uint32_t )(device->parent.user_data);
9183

9284
if (enabled == ENABLE)
9385
{
9486
init_pin4adc(gd32_adc->adc_pins[channel]);
95-
ADC_InitParaStruct.ADC_Trig_External = ADC_EXTERNAL_TRIGGER_MODE_NONE;
96-
/* Fix the channel number to fit the firmware library */
97-
ADC_InitParaStruct.ADC_Channel_Number = 1 + channel;
98-
ADC_InitParaStruct.ADC_Data_Align = ADC_DATAALIGN_RIGHT;
99-
ADC_InitParaStruct.ADC_Mode_Scan = DISABLE;
100-
ADC_InitParaStruct.ADC_Mode = ADC_MODE_INDEPENDENT;
101-
ADC_InitParaStruct.ADC_Mode_Continuous = ENABLE;
102-
ADC_Init(ADCx, &ADC_InitParaStruct);
103-
104-
ADC_RegularChannel_Config(ADCx, channel, 1, ADC_SAMPLETIME_13POINT5);
105-
ADC_Enable(ADCx, ENABLE);
106-
ADC_SoftwareStartConv_Enable(ADCx, ENABLE);
87+
adc_deinit(adc_periph);
88+
adc_channel_length_config(adc_periph, ADC_REGULAR_CHANNEL, 1);
89+
adc_data_alignment_config(adc_periph, ADC_DATAALIGN_RIGHT);
90+
adc_external_trigger_source_config(adc_periph, ADC_REGULAR_CHANNEL, ADC0_1_2_EXTTRIG_INSERTED_NONE);
91+
adc_external_trigger_config(adc_periph, ADC_REGULAR_CHANNEL, ENABLE);
92+
adc_regular_channel_config(adc_periph, 0, channel, ADC_SAMPLETIME_13POINT5);
93+
adc_enable(adc_periph);
10794
}
10895
else
10996
{
110-
ADC_Enable(ADCx, DISABLE);
97+
adc_disable(adc_periph);
11198
}
11299

113100
return 0;
114101
}
115102

116103
static rt_err_t gd32_adc_convert(struct rt_adc_device *device, rt_uint32_t channel, rt_uint32_t *value)
117104
{
118-
ADC_TypeDef *ADCx;
105+
uint32_t adc_periph;
119106

120107
if (!value)
121108
{
122109
LOG_E("invalid param");
123-
return -EINVAL;
110+
return -RT_EINVAL;
124111
}
125112

126-
ADCx = (ADC_TypeDef *)(device->parent.user_data);
127-
*value = ADC_GetConversionValue(ADCx);
113+
adc_periph = (uint32_t )(device->parent.user_data);
114+
adc_software_trigger_enable(adc_periph, ADC_REGULAR_CHANNEL);
115+
*value = adc_regular_data_read(adc_periph);
128116

129117
return 0;
130118
}
@@ -148,11 +136,11 @@ static int rt_hw_adc_init(void)
148136
rcu_periph_clock_enable(RCU_ADC1);
149137
#endif
150138

151-
for (; i < ARRAY_SIZE(g_gd32_devs); i++)
139+
for (; i < sizeof(g_gd32_devs) / sizeof(g_gd32_devs[0]); i++)
152140
{
153141
ret = rt_hw_adc_register(&g_gd32_devs[i].adc_dev, \
154142
(const char *)g_gd32_devs[i].name, \
155-
&g_gd32_adc_ops, g_gd32_devs[i].private_data);
143+
&g_gd32_adc_ops, (void *)g_gd32_devs[i].private_data);
156144
if (ret != RT_EOK)
157145
{
158146
/* TODO err handler */

bsp/gd32/libraries/gd32_drivers/drv_gpio.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ extern "C" {
3838
EXTI_SOURCE_PIN##pin}
3939
#else
4040
#define GD32_PIN(index, port, pin) {index, RCU_GPIO##port, \
41-
GPIO##port, GPIO_PIN_##pin, \
41+
GPIO##port, GPIO_PIN_##pin, \
4242
GPIO_PORT_SOURCE_GPIO##port, \
4343
GPIO_PIN_SOURCE_##pin}
4444

@@ -48,6 +48,12 @@ extern "C" {
4848

4949
#define GET_PIN(PORTx,PIN) (rt_base_t)((16 * ( ((rt_base_t)__GD32_PORT(PORTx) - (rt_base_t)GPIO_BASE)/(0x0400UL) )) + PIN)
5050

51+
#define PIN_PORT(pin) ((uint8_t)(((pin) >> 4) & 0xFu))
52+
#define PIN_NO(pin) ((uint8_t)((pin) & 0xFu))
53+
54+
#define PIN_GDPORT(pin) (GPIO_BASE + (0x400u * PIN_PORT(pin)))
55+
#define PIN_GDPIN(pin) ((uint16_t)(1u << PIN_NO(pin)))
56+
5157
struct pin_index
5258
{
5359
rt_int16_t index;

0 commit comments

Comments
 (0)