Skip to content
Open
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
57 changes: 57 additions & 0 deletions bsp/gd32/risc-v/gd32vw553h-eval/board/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,63 @@ menu "On-chip Peripheral Drivers"
select RT_SERIAL_USING_DMA
default n
endif
menuconfig BSP_USING_HW_I2C
bool "Enable Hardware I2C"
default n
select RT_USING_I2C
if BSP_USING_HW_I2C
config BSP_USING_HW_I2C0
bool "Enable Hardware I2C0"
default n

# config i2c0 pins
choice
prompt "Select I2C0 pins"
depends on BSP_USING_HW_I2C0
config BSP_HW_I2C0_PIN_PA2_PA3
bool "SCL=PA2, SDA=PA3"
config BSP_HW_I2C0_PIN_PA15_PC8
bool "SCL=PA15, SDA=PC8"
config BSP_HW_I2C0_PIN_PB0_PB1
bool "SCL=PB0, SDA=PB1"
config BSP_HW_I2C0_PIN_PB15_PA8
bool "SCL=PB15, SDA=PA8"
endchoice

# config i2c0 clock
config BSP_HW_I2C0_CLK
int "I2C0 clock frequency(KHz)"
default 100
depends on BSP_USING_HW_I2C0
range 50 400
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I2C clock frequency range may be too restrictive.

English: The I2C clock frequency is limited to 50-400 KHz range (lines 108, 135). While this covers standard (100 KHz) and fast mode (400 KHz), it excludes low-speed mode (10 KHz) which might be useful for some devices. Also, some modern I2C devices support Fast Mode Plus (1 MHz). Consider if these additional modes should be supported, or if the current range is intentionally restrictive for hardware limitations.

中文:I2C 时钟频率限制在 50-400 KHz 范围内(第 108、135 行)。虽然这涵盖了标准模式(100 KHz)和快速模式(400 KHz),但排除了可能对某些设备有用的低速模式(10 KHz)。此外,一些现代 I2C 设备支持快速模式增强型(1 MHz)。考虑是否应支持这些附加模式,或者当前范围是否因硬件限制而有意限制。

Copilot uses AI. Check for mistakes.

config BSP_USING_HW_I2C1
bool "Enable Hardware I2C1"
default n

# config i2c1 pins
choice
prompt "Select I2C1 pins"
depends on BSP_USING_HW_I2C1
config BSP_HW_I2C1_PIN_PA6_PA7
bool "SCL=PA6, SDA=PA7"
config BSP_HW_I2C1_PIN_PA13_PA14
bool "SCL=PA13, SDA=PA14"
config BSP_HW_I2C1_PIN_PA15_PC8
bool "SCL=PA15, SDA=PC8"
config BSP_HW_I2C1_PIN_PB12_PB13
bool "SCL=PB12, SDA=PB13"
config BSP_HW_I2C1_PIN_PB15_PA8
bool "SCL=PB15, SDA=PA8"
endchoice

# config i2c1 clock
config BSP_HW_I2C1_CLK
int "I2C1 clock frequency(KHz)"
default 100
depends on BSP_USING_HW_I2C1
range 50 400
endif

source "$(BSP_DIR)/../libraries/gd32_drivers/Kconfig"

Expand Down
3 changes: 3 additions & 0 deletions bsp/gd32/risc-v/libraries/gd32_drivers/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ if GetDepend(['RT_USING_SERIAL']):
if GetDepend(['RT_USING_I2C', 'RT_USING_I2C_BITOPS']):
if GetDepend('BSP_USING_I2C0') or GetDepend('BSP_USING_I2C1') or GetDepend('BSP_USING_I2C2') or GetDepend('BSP_USING_I2C3'):
src += ['drv_soft_i2c.c']
if GetDepend(['RT_USING_I2C', 'BSP_USING_HW_I2C']):
if GetDepend('BSP_USING_HW_I2C0') or GetDepend('BSP_USING_HW_I2C1'):
src += ['drv_i2c.c']
Comment on lines 20 to +25
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential conflict with soft I2C configuration check.

English: The condition checking on lines 23-25 verifies BSP_USING_HW_I2C0 or BSP_USING_HW_I2C1, but this is nested inside a check for RT_USING_I2C and BSP_USING_HW_I2C. The check is redundant since if neither HW_I2C0 nor HW_I2C1 is defined, the drv_i2c.c file itself has an #error directive (lines 15-23 of drv_i2c.c) that would catch this. However, it's good defensive programming. Consider if both soft I2C and hardware I2C can be enabled simultaneously, as they check for the same RT_USING_I2C flag. This might need clarification in documentation.

中文:第 23-25 行的条件检查验证 BSP_USING_HW_I2C0 或 BSP_USING_HW_I2C1,但这嵌套在 RT_USING_I2C 和 BSP_USING_HW_I2C 的检查中。该检查是冗余的,因为如果既未定义 HW_I2C0 也未定义 HW_I2C1,drv_i2c.c 文件本身就有一个 #error 指令(drv_i2c.c 的第 15-23 行)会捕获这一点。但是,这是良好的防御性编程。考虑软件 I2C 和硬件 I2C 是否可以同时启用,因为它们检查相同的 RT_USING_I2C 标志。这可能需要在文档中澄清。

Suggested change
if GetDepend(['RT_USING_I2C', 'RT_USING_I2C_BITOPS']):
if GetDepend('BSP_USING_I2C0') or GetDepend('BSP_USING_I2C1') or GetDepend('BSP_USING_I2C2') or GetDepend('BSP_USING_I2C3'):
src += ['drv_soft_i2c.c']
if GetDepend(['RT_USING_I2C', 'BSP_USING_HW_I2C']):
if GetDepend('BSP_USING_HW_I2C0') or GetDepend('BSP_USING_HW_I2C1'):
src += ['drv_i2c.c']
if GetDepend('RT_USING_I2C'):
if GetDepend('RT_USING_I2C_BITOPS'):
if GetDepend('BSP_USING_I2C0') or GetDepend('BSP_USING_I2C1') or GetDepend('BSP_USING_I2C2') or GetDepend('BSP_USING_I2C3'):
src += ['drv_soft_i2c.c']
if GetDepend('BSP_USING_HW_I2C'):
if GetDepend('BSP_USING_HW_I2C0') or GetDepend('BSP_USING_HW_I2C1'):
src += ['drv_i2c.c']

Copilot uses AI. Check for mistakes.

# add spi drivers.
if GetDepend('RT_USING_SPI'):
Expand Down
26 changes: 26 additions & 0 deletions bsp/gd32/risc-v/libraries/gd32_drivers/drv_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2006-2026, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2026-01-25 yefeng first version
*/

#ifndef __DRV_CONFIG_H__
#define __DRV_CONFIG_H__

#include <board.h>
#include <rtthread.h>

#ifdef __cplusplus
extern "C" {
#endif


#ifdef __cplusplus
}
#endif

#endif
Loading