-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[gd32][i2c]Add an example for measuring the onboard peripherals of the I2C board #11161
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
Open
CXSforHPU
wants to merge
1
commit into
RT-Thread:master
Choose a base branch
from
CXSforHPU:gd32
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 changes: 35 additions & 0 deletions
35
bsp/gd32/risc-v/gd32vw553h-eval/board/port/at24c02/at24c02.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
12 changes: 12 additions & 0 deletions
12
bsp/gd32/risc-v/gd32vw553h-eval/board/port/at24c02/at24c02.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #ifndef AT24C02_H | ||
| #define AT24C02_H | ||
|
|
||
| #include <rtthread.h> | ||
| #include "at24cxx.h" | ||
|
|
||
| #define AT24C02_I2C_NAME "i2c0" | ||
| #define AT24C02_ADDR_INPUT 0x0 | ||
|
|
||
| extern at24cxx_device_t gd32_at24c02; | ||
|
|
||
| #endif // AT24C02_H |
82 changes: 82 additions & 0 deletions
82
bsp/gd32/risc-v/gd32vw553h-eval/board/port/at24c02/test_at24c02.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| #include "rtconfig.h" | ||
|
|
||
| #ifdef BSP_USING_AT24C02 | ||
|
|
||
| #include "at24cxx.h" | ||
| #include <rtthread.h> | ||
| #include "utest.h" | ||
|
|
||
| #define AT24C02_I2C_NAME "i2c0" | ||
| #define TEST_DATA "WELCOM 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_ERROR) | ||
| { | ||
| LOG_E("Failed to write data to AT24C02\n"); | ||
| } | ||
| LOG_I("Successfully wrote to AT24C02: %s\n", write_buffer); | ||
|
|
||
| /* 读取数据 */ | ||
| result = at24cxx_read(dev, 0, read_buffer, data_size); | ||
| if (result == RT_ERROR) | ||
| { | ||
| LOG_E("Failed to read data from AT24C02\n"); | ||
| } | ||
| 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 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.