mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-03-23 22:10:39 +08:00
[gd32][i2c]Add an example for measuring the onboard peripherals of the I2C board
This commit is contained in:
@@ -17,4 +17,39 @@ devices.i2c:
|
|||||||
- CONFIG_BSP_HW_I2C0_CLK=100
|
- CONFIG_BSP_HW_I2C0_CLK=100
|
||||||
- CONFIG_BSP_USING_HW_I2C1=y
|
- CONFIG_BSP_USING_HW_I2C1=y
|
||||||
- CONFIG_BSP_HW_I2C1_PIN_PB12_PB13=y
|
- CONFIG_BSP_HW_I2C1_PIN_PB12_PB13=y
|
||||||
- CONFIG_BSP_HW_I2C1_CLK=100
|
- CONFIG_BSP_HW_I2C1_CLK=100
|
||||||
|
|
||||||
|
# ------ peripheral CI ------
|
||||||
|
peripheral.at24c02:
|
||||||
|
kconfig:
|
||||||
|
- CONFIG_RT_CONSOLEBUF_SIZE=256
|
||||||
|
- CONFIG_RT_NAME_MAX=32
|
||||||
|
- CONFIG_RT_USING_ULOG=y
|
||||||
|
- CONFIG_ULOG_OUTPUT_LVL_D=y
|
||||||
|
- CONFIG_ULOG_OUTPUT_LVL=7
|
||||||
|
- CONFIG_ULOG_USING_ISR_LOG=y
|
||||||
|
- CONFIG_ULOG_ASSERT_ENABLE=y
|
||||||
|
- CONFIG_ULOG_LINE_BUF_SIZE=128
|
||||||
|
- CONFIG_ULOG_USING_COLOR=y
|
||||||
|
- CONFIG_ULOG_OUTPUT_TIME=y
|
||||||
|
- CONFIG_ULOG_OUTPUT_LEVEL=y
|
||||||
|
- CONFIG_ULOG_OUTPUT_TAG=y
|
||||||
|
- CONFIG_ULOG_BACKEND_USING_CONSOLE=y
|
||||||
|
- CONFIG_RT_USING_UTEST=y
|
||||||
|
- CONFIG_UTEST_THR_STACK_SIZE=4096
|
||||||
|
- CONFIG_UTEST_THR_PRIORITY=20
|
||||||
|
- CONFIG_RT_UTEST_MAX_OPTIONS=64
|
||||||
|
- CONFIG_PKG_USING_AT24CXX=y
|
||||||
|
- CONFIG_PKG_AT24CXX_PATH="/packages/peripherals/at24cxx"
|
||||||
|
- CONFIG_PKG_AT24CXX_EE_TYPE_AT24C02=y
|
||||||
|
- CONFIG_PKG_AT24CXX_EE_TYPE=1
|
||||||
|
- CONFIG_PKG_USING_AT24CXX_LATEST_VERSION=y
|
||||||
|
- CONFIG_PKG_AT24CXX_VER="latest"
|
||||||
|
- CONFIG_BSP_USING_AT24C02=y
|
||||||
|
- CONFIG_BSP_USING_AT24C02_UTEST=y
|
||||||
|
- CONFIG_RT_USING_I2C=y
|
||||||
|
- CONFIG_RT_USING_I2C_BITOPS=y
|
||||||
|
- CONFIG_BSP_USING_HW_I2C=y
|
||||||
|
- CONFIG_BSP_USING_HW_I2C0=y
|
||||||
|
- CONFIG_BSP_HW_I2C0_PIN_PA2_PA3=y
|
||||||
|
- CONFIG_BSP_HW_I2C0_CLK=100
|
||||||
@@ -143,6 +143,29 @@ endmenu
|
|||||||
|
|
||||||
menu "Board extended module Drivers"
|
menu "Board extended module Drivers"
|
||||||
|
|
||||||
|
menuconfig BSP_USING_AT24C02
|
||||||
|
bool "Enable AT24C02 I2C0( SCL[PA2 : 2] SDA[PA3 : 3] )"
|
||||||
|
default n
|
||||||
|
select BSP_USING_HW_I2C
|
||||||
|
select BSP_USING_HW_I2C0
|
||||||
|
select PKG_USING_AT24CXX
|
||||||
|
select PKG_AT24CXX_EE_TYPE_AT24C02
|
||||||
|
|
||||||
|
if BSP_USING_AT24C02
|
||||||
|
|
||||||
|
config BSP_USING_AT24C02_UTEST
|
||||||
|
bool "Enable the utest of AT24C02"
|
||||||
|
default n
|
||||||
|
select RT_USING_UTEST
|
||||||
|
select RT_USING_ULOG
|
||||||
|
select ULOG_USING_ISR_LOG
|
||||||
|
|
||||||
|
config BSP_USING_AT24C02_INIT
|
||||||
|
bool "Init the model and check it"
|
||||||
|
default y
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
|||||||
@@ -24,4 +24,9 @@ if rtconfig.PLATFORM in ['gcc']:
|
|||||||
CPPDEFINES = ['GD32VW553H_EVAL']
|
CPPDEFINES = ['GD32VW553H_EVAL']
|
||||||
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = path, CPPDEFINES = CPPDEFINES)
|
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = path, CPPDEFINES = CPPDEFINES)
|
||||||
|
|
||||||
|
list = os.listdir(cwd)
|
||||||
|
for item in list:
|
||||||
|
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
|
||||||
|
group = group + SConscript(os.path.join(item, 'SConscript'))
|
||||||
|
|
||||||
Return('group')
|
Return('group')
|
||||||
|
|||||||
@@ -62,6 +62,12 @@ SECTIONS
|
|||||||
__rt_init_end = .;
|
__rt_init_end = .;
|
||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
|
|
||||||
|
/* section information for utest */
|
||||||
|
. = ALIGN(4);
|
||||||
|
__rt_utest_tc_tab_start = .;
|
||||||
|
KEEP(*(UtestTcTab))
|
||||||
|
__rt_utest_tc_tab_end = .;
|
||||||
|
|
||||||
/* section information for modules */
|
/* section information for modules */
|
||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
__rtmsymtab_start = .;
|
__rtmsymtab_start = .;
|
||||||
|
|||||||
28
bsp/gd32/risc-v/gd32vw553h-eval/board/port/SConscript
Normal file
28
bsp/gd32/risc-v/gd32vw553h-eval/board/port/SConscript
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import os
|
||||||
|
from building import *
|
||||||
|
|
||||||
|
objs = []
|
||||||
|
cwd = GetCurrentDir()
|
||||||
|
|
||||||
|
# add general drivers
|
||||||
|
src = []
|
||||||
|
path = [cwd]
|
||||||
|
|
||||||
|
if GetDepend(['BSP_USING_AT24C02']):
|
||||||
|
path += [cwd + "/at24c02"]
|
||||||
|
|
||||||
|
if GetDepend(['BSP_USING_AT24C02_UTEST']):
|
||||||
|
src += ["./at24c02/test_at24c02.c"]
|
||||||
|
|
||||||
|
if GetDepend(['BSP_USING_AT24C02_INIT']):
|
||||||
|
src += ['./at24c02/at24c02.c']
|
||||||
|
|
||||||
|
CPPDEFINES = ['GD32VW553H_EVAL']
|
||||||
|
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = path, CPPDEFINES = CPPDEFINES)
|
||||||
|
|
||||||
|
list = os.listdir(cwd)
|
||||||
|
for item in list:
|
||||||
|
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
|
||||||
|
group = group + SConscript(os.path.join(item, 'SConscript'))
|
||||||
|
|
||||||
|
Return('group')
|
||||||
35
bsp/gd32/risc-v/gd32vw553h-eval/board/port/at24c02/at24c02.c
Normal file
35
bsp/gd32/risc-v/gd32vw553h-eval/board/port/at24c02/at24c02.c
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#include "rtconfig.h"
|
||||||
|
|
||||||
|
#ifdef BSP_USING_AT24C02_INIT
|
||||||
|
|
||||||
|
#include "at24c02.h"
|
||||||
|
|
||||||
|
at24cxx_device_t gd32_at24c02 = RT_NULL;
|
||||||
|
|
||||||
|
static int init_gd32_at24c02(void)
|
||||||
|
{
|
||||||
|
rt_err_t result = RT_EOK;
|
||||||
|
|
||||||
|
gd32_at24c02 = at24cxx_init(AT24C02_I2C_NAME, AT24C02_ADDR_INPUT);
|
||||||
|
|
||||||
|
if (gd32_at24c02 == RT_NULL)
|
||||||
|
{
|
||||||
|
rt_kprintf("AT24C02 initialization failed\n");
|
||||||
|
return -RT_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = at24cxx_check(gd32_at24c02);
|
||||||
|
|
||||||
|
if (result == -RT_ERROR)
|
||||||
|
{
|
||||||
|
rt_kprintf("AT24C02 check failed\n");
|
||||||
|
return -RT_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return RT_EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
INIT_DEVICE_EXPORT(init_gd32_at24c02);
|
||||||
|
|
||||||
|
#endif
|
||||||
14
bsp/gd32/risc-v/gd32vw553h-eval/board/port/at24c02/at24c02.h
Normal file
14
bsp/gd32/risc-v/gd32vw553h-eval/board/port/at24c02/at24c02.h
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#ifndef AT24C02_H
|
||||||
|
#define AT24C02_H
|
||||||
|
|
||||||
|
#include <rtthread.h>
|
||||||
|
#include "at24cxx.h"
|
||||||
|
|
||||||
|
#define AT24C02_I2C_NAME "i2c0"
|
||||||
|
#define AT24C02_ADDR_INPUT 0x0
|
||||||
|
|
||||||
|
#ifdef BSP_USING_AT24C02_INIT
|
||||||
|
extern at24cxx_device_t gd32_at24c02;
|
||||||
|
#endif // BSP_USING_AT24C02_INIT
|
||||||
|
|
||||||
|
#endif // AT24C02_H
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
#include "rtconfig.h"
|
||||||
|
|
||||||
|
#ifdef BSP_USING_AT24C02
|
||||||
|
|
||||||
|
#include "utest.h"
|
||||||
|
#include "at24c02.h"
|
||||||
|
|
||||||
|
#define TEST_DATA "WELCOME TO RTT"
|
||||||
|
|
||||||
|
static at24cxx_device_t dev = RT_NULL;
|
||||||
|
|
||||||
|
static rt_err_t test_at24c02_init(void)
|
||||||
|
{
|
||||||
|
rt_err_t result = RT_EOK;
|
||||||
|
uint8_t AddrInput = 0x0;
|
||||||
|
|
||||||
|
dev = at24cxx_init(AT24C02_I2C_NAME, AddrInput);
|
||||||
|
if (dev == RT_NULL)
|
||||||
|
{
|
||||||
|
LOG_E("AT24C02 initialization failed\n");
|
||||||
|
result = -RT_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_at24c02_example(void)
|
||||||
|
{
|
||||||
|
uint8_t write_buffer[] = TEST_DATA;
|
||||||
|
int data_size = sizeof(write_buffer);
|
||||||
|
rt_err_t result = RT_EOK;
|
||||||
|
|
||||||
|
uint8_t read_buffer[50] = {0};
|
||||||
|
|
||||||
|
/* 写入数据 */
|
||||||
|
result = at24cxx_write(dev, 0, write_buffer, data_size);
|
||||||
|
|
||||||
|
if (result != RT_EOK)
|
||||||
|
{
|
||||||
|
LOG_E("Failed to write data to AT24C02\n");
|
||||||
|
uassert_true(RT_FALSE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_I("Successfully wrote to AT24C02: %s\n", write_buffer);
|
||||||
|
|
||||||
|
/* 读取数据 */
|
||||||
|
result = at24cxx_read(dev, 0, read_buffer, data_size);
|
||||||
|
|
||||||
|
if (result != RT_EOK)
|
||||||
|
{
|
||||||
|
LOG_E("Failed to read data from AT24C02\n");
|
||||||
|
uassert_true(RT_FALSE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_I("Successfully read from AT24C02: %s\n", read_buffer);
|
||||||
|
|
||||||
|
uassert_str_equal(write_buffer, read_buffer);
|
||||||
|
|
||||||
|
/* 检查数据 */
|
||||||
|
result = at24cxx_check(dev);
|
||||||
|
|
||||||
|
uassert_true(result == RT_EOK);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static rt_err_t test_at24c02_deinit(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (dev != RT_NULL)
|
||||||
|
{
|
||||||
|
at24cxx_deinit(dev);
|
||||||
|
dev = RT_NULL;
|
||||||
|
return RT_EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -RT_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_case(void)
|
||||||
|
{
|
||||||
|
UTEST_UNIT_RUN(test_at24c02_example);
|
||||||
|
}
|
||||||
|
|
||||||
|
UTEST_TC_EXPORT(test_case, "bsp.gd32.port.at24c02" , test_at24c02_init, test_at24c02_deinit, 100);
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user