-
Notifications
You must be signed in to change notification settings - Fork 5
feat(I3C): adding support for I3C #5
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
Aymane-ST
wants to merge
3
commits into
stm32duino:main
Choose a base branch
from
Aymane-ST:I3C
base: main
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # v3.21 implemented semantic changes regarding $<TARGET_OBJECTS:...> | ||
| # See https://cmake.org/cmake/help/v3.21/command/target_link_libraries.html#linking-object-libraries-via-target-objects | ||
| cmake_minimum_required(VERSION 3.21) | ||
|
|
||
| add_library(LPS22DF INTERFACE) | ||
| add_library(LPS22DF_usage INTERFACE) | ||
|
|
||
| target_include_directories(LPS22DF_usage INTERFACE | ||
| src | ||
| ) | ||
|
|
||
|
|
||
| target_link_libraries(LPS22DF_usage INTERFACE | ||
| base_config | ||
| ) | ||
|
|
||
| target_link_libraries(LPS22DF INTERFACE LPS22DF_usage) | ||
|
|
||
|
|
||
|
|
||
| add_library(LPS22DF_bin OBJECT EXCLUDE_FROM_ALL | ||
| src/lps22df_reg.c | ||
| src/LPS22DFSensor.cpp | ||
| ) | ||
| target_link_libraries(LPS22DF_bin PUBLIC LPS22DF_usage) | ||
|
|
||
| target_link_libraries(LPS22DF INTERFACE | ||
| LPS22DF_bin | ||
| $<TARGET_OBJECTS:LPS22DF_bin> | ||
| ) | ||
|
|
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,55 @@ | ||
| #include "I3C.h" | ||
| #include "LPS22DFSensor.h" | ||
|
|
||
| #define I3C_BUS I3C1Bus | ||
|
|
||
| static const uint8_t LPS22DF_DYN_ADDR = 0x30; | ||
|
|
||
| LPS22DFSensor sensor(&I3C_BUS, LPS22DF_I3C_ADD_H, LPS22DF_DYN_ADDR); | ||
|
|
||
| void setup() { | ||
| Serial.begin(115200); | ||
| while (!Serial) {} | ||
| delay(1000); | ||
|
|
||
| Serial.println("=== LPS22DF SETDASA ==="); | ||
|
|
||
| if (!I3C_BUS.begin(I3C_SDA, I3C_SCL, 1000000U)) { | ||
| Serial.println("begin() failed"); | ||
| while (1) {} | ||
| } | ||
|
|
||
| if (!I3C_BUS.resetDynamicAddresses()) { | ||
| Serial.println("resetDynamicAddresses() failed"); | ||
| while (1) {} | ||
| } | ||
|
|
||
| if (sensor.begin() != LPS22DF_OK) { | ||
| Serial.println("sensor.begin() failed"); | ||
| while (1) {} | ||
| } | ||
|
|
||
| if (sensor.Enable() != LPS22DF_OK) { | ||
| Serial.println("sensor.Enable() failed"); | ||
| while (1) {} | ||
| } | ||
|
|
||
| Serial.println("LPS22DF ready"); | ||
| } | ||
|
|
||
| void loop() { | ||
| float p = 0.0f; | ||
| float t = 0.0f; | ||
|
|
||
| if (sensor.GetPressure(&p) == LPS22DF_OK && sensor.GetTemperature(&t) == LPS22DF_OK) { | ||
| Serial.print("P = "); | ||
| Serial.print(p, 2); | ||
| Serial.print(" hPa T = "); | ||
| Serial.print(t, 1); | ||
| Serial.println(" C"); | ||
| } else { | ||
| Serial.println("Read failed"); | ||
| } | ||
|
|
||
| delay(500); | ||
| } | ||
73 changes: 73 additions & 0 deletions
73
examples/LPS22DF_I3C_DynAddrAssign/LPS22DF_I3C_DynAddrAssign.ino
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,73 @@ | ||
| #include "I3C.h" | ||
| #include "LPS22DFSensor.h" | ||
|
|
||
| #define I3C_BUS I3C1Bus | ||
|
|
||
| LPS22DFSensor sensor(&I3C_BUS, 0x00); | ||
|
|
||
| void setup() { | ||
| Serial.begin(115200); | ||
| while (!Serial) {} | ||
| delay(1000); | ||
|
|
||
| Serial.println("=== LPS22DF DAA ==="); | ||
|
|
||
| if (!I3C_BUS.begin(I3C_SDA, I3C_SCL, 1000000U)) { | ||
| Serial.println("begin() failed"); | ||
| while (1) {} | ||
| } | ||
|
|
||
| I3CDiscoveredDevice devices[8]{}; | ||
| size_t found = 0; | ||
|
|
||
| if (I3C_BUS.discover(devices, 8, &found)) { | ||
| Serial.println("discover() failed"); | ||
| while (1) {} | ||
| } | ||
|
|
||
| uint8_t lpsDynAddr = 0U; | ||
|
|
||
| for (size_t i = 0; i < found; ++i) { | ||
| Serial.println(devices[i].pid,HEX); | ||
| if (devices[i].pid == LPS22DF_I3C_PID_H) { | ||
| lpsDynAddr = devices[i].dynAddr; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| sensor.set_address(lpsDynAddr); | ||
|
|
||
| if (lpsDynAddr == 0U) { | ||
| Serial.println("Sensor not found failed"); | ||
| while (1) {} | ||
| } | ||
|
|
||
| if (sensor.begin() != LPS22DF_OK) { | ||
| Serial.println("sensor.begin() failed"); | ||
| while (1) {} | ||
| } | ||
|
|
||
| if (sensor.Enable() != LPS22DF_OK) { | ||
| Serial.println("sensor.Enable() failed"); | ||
| while (1) {} | ||
| } | ||
|
|
||
| Serial.println("LPS22DF ready"); | ||
| } | ||
|
|
||
| void loop() { | ||
| float p = 0.0f; | ||
| float t = 0.0f; | ||
|
|
||
| if (sensor.GetPressure(&p) == LPS22DF_OK && sensor.GetTemperature(&t) == LPS22DF_OK) { | ||
| Serial.print("P = "); | ||
| Serial.print(p, 2); | ||
| Serial.print(" hPa T = "); | ||
| Serial.print(t, 1); | ||
| Serial.println(" C"); | ||
| } else { | ||
| Serial.println("Read failed"); | ||
| } | ||
|
|
||
| delay(500); | ||
| } |
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,50 @@ | ||
| #include "I3C.h" | ||
| #include "LPS22DFSensor.h" | ||
|
|
||
| #define I3C_BUS I3C1Bus | ||
|
|
||
| LPS22DFSensor sensor(&I3C_BUS, LPS22DF_I3C_ADD_H, 0x30); | ||
| static volatile bool ibiPending = false; | ||
|
|
||
|
|
||
|
|
||
| void setup() { | ||
| Serial.begin(115200); | ||
| while (!Serial) {} | ||
|
|
||
| I3C_BUS.begin(I3C_SDA, I3C_SCL, 1000000U); | ||
| I3C_BUS.onIbi([](const I3CControllerIbiInfo&, void*) { | ||
| ibiPending = true; | ||
| }, | ||
| nullptr); | ||
|
|
||
| sensor.begin(); | ||
| sensor.SetOutputDataRate(10.0f); | ||
| sensor.ConfigureDataReadyOnI3cIbi(); | ||
| sensor.EnableIbiOnBus(); | ||
| sensor.Enable(); | ||
|
|
||
| Serial.println("Waiting for IBI ..."); | ||
| } | ||
|
|
||
| void loop() { | ||
| if (!ibiPending && !I3C_BUS.hasIbi()) { | ||
| return; | ||
| } | ||
|
|
||
| ibiPending = false; | ||
|
|
||
| I3CControllerIbiInfo ibi{}; | ||
| if (!I3C_BUS.readIbi(ibi)) { | ||
| return; | ||
| } | ||
|
|
||
| float p, t; | ||
| if (sensor.GetPressure(&p) == LPS22DF_OK && sensor.GetTemperature(&t) == LPS22DF_OK) { | ||
| Serial.print(" P = "); | ||
| Serial.print(p, 2); | ||
| Serial.print(" hPa, T = "); | ||
| Serial.print(t, 1); | ||
| Serial.println(" 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 |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| daa | ||
| ths |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rename all the I3C examples "LPS22DF_I3C_Basic.ino", "LPS22DF_I3C_DynAddrAssign.ino" and "LPS22DF_I3C_IBI.ino" putting them in the root of the "examples" folder and avoiding the inner folders. What about this proposal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done