-
Notifications
You must be signed in to change notification settings - Fork 52
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
API V2 - I2C Review #693
API V2 - I2C Review #693
Conversation
…low bug in func signature mismatch for model
src/components/i2c/hardware.cpp
Outdated
void I2cHardware::InitBus(bool is_default, const char *sda, const char *scl) { | ||
uint8_t pin_sda, pin_scl; | ||
if (!is_default && (sda == nullptr || scl == nullptr)) { | ||
_bus_status = wippersnapper_i2c_I2cBusStatus_I2C_BUS_STATUS_ERROR_WIRING; |
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 think this might be the wrong message, if nullptr then we haven't set the alt bus sda/scl pins, i.e. corrupt protobuf msg from offline config?
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'm not sure what is better here.
What I2cBusStatus
should we set instead? We could also add to I2cBusStatus
:
https://github.com/adafruit/Wippersnapper_Protobuf/blob/api-v2/proto/wippersnapper/i2c.proto#L10
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 guess back to the default of 0 (wippersnapper_i2c_I2cBusStatus_I2C_BUS_STATUS_UNSPECIFIED) might be better for now. Wasn't sure what to add rather than utilise existing.
_bus_status = wippersnapper_i2c_I2cBusStatus_I2C_BUS_STATUS_ERROR_HANG; | ||
return; | ||
} | ||
_bus->setClock(50000); |
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 know this is from V1, I wonder if we need this optionally per sensor or something, but I was sure there were a couple with very strict requirements (couple needed 100k in theory and maybe another one had issues except around 20k). Ignore me for now, but if it rings a bell or comes up again then shout.
In my head we were running at 100kHz for everything, but I must have been thinking of circuitpython or something
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.
The specification was to run at 500kHz for everything on the bus. API v1 did contain a message that sets the I2C bus' frequency (https://github.com/adafruit/Wippersnapper_Protobuf/blob/master/proto/wippersnapper/i2c/v1/i2c.proto#L45) but since we are always sending 500kHz in that message, it got dropped in API v2.
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.
Got you! I'm assuming you're aware that you're talking about 5 hundred, but mean to say 50kHz like the code is fifty kHz, but yep.
@tyeth Noting that we discussed the following over Slack Huddle: |
The two issues mentioned above have been resolved. |
Test Results6 tests 6 ✅ 1m 6s ⏱️ Results for commit ad0e794. ♻️ This comment has been updated with latest results. |
Sticking this in here so it isn't missed, the rtc not being initialised with a time via some alternative means causes a failure. We should instead initialise it at zero or ideally use a soft RTC instead and the user can work it out from the timestamps or seeing serial warning. We should not set the RTC to time at compile time. |
src/components/i2c/hardware.cpp
Outdated
void I2cHardware::InitBus(bool is_default, const char *sda, const char *scl) { | ||
uint8_t pin_sda, pin_scl; | ||
if (!is_default && (sda == nullptr || scl == nullptr)) { | ||
_bus_status = wippersnapper_i2c_I2cBusStatus_I2C_BUS_STATUS_ERROR_WIRING; |
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 guess back to the default of 0 (wippersnapper_i2c_I2cBusStatus_I2C_BUS_STATUS_UNSPECIFIED) might be better for now. Wasn't sure what to add rather than utilise existing.
_bus_status = wippersnapper_i2c_I2cBusStatus_I2C_BUS_STATUS_ERROR_HANG; | ||
return; | ||
} | ||
_bus->setClock(50000); |
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.
Got you! I'm assuming you're aware that you're talking about 5 hundred, but mean to say 50kHz like the code is fifty kHz, but yep.
Resolves #640
Pull Request Scope
src/i2c
and refactored all existing drivers to fit the new modified driver base class (drvBase
) withinsrc/i2c/drivers
config.json
file on an SD cardSensorEvent
message, fromsensor.proto
. This message can then be - published to MQTT, logged to sd, and/or published to the serialconfig.json
file into a protobuf message within classws_sd
This pull request only covers "offline mode" functionality, interfaces for publishing back to the MQTT broker have not yet been fully implemented.
Code Review Scope
This pull request adds the following new files within
src/i2c/
and replaces all existing files:I2C Model - Provides interfaces for interacting with messages within the
i2c.proto
APImodel.cpp
model.h
I2C Hardware - Manages low-level i2c bus functionality
hardware.cpp
hardware.h
I2C Controller - Manages high-level functionality for handling I2C messages
controller.cpp
controller.h
There are also refactored drivers the within
src/i2c/drivers/
folder. I do not expect all of the drivers within this folder to be reviewed as a subset was tested for functionality. However,drvBase.h
should be reviewed.Modifies functions within the
ws_sdcard
class:parseConfigFile()
Adds new functions within the
ws_sdcard
class:ParseI2cDeviceAddReplace()
LogI2cDeviceEvent()
(Optional) Hardware Testing
If you'd like to test this on hardware, I suggest building the firmware using PlatformIO. I have tested on: QT Py ESP32-S2 + RTC + SD BFF, Raspberry Pi Pico 2
Notes:
config.json
should reside on the WIPPER drive, not the MicroSD card.rtc
andsd_cs_pin
variables to match the name of the RTC you are using and the pin the MicroSD Card breakout is utilizingExample
config.json
- SHTC3 on default I2C Portshtc3.json
Example
config.json
- MCP9808 connected to PCA9546 MUX on an alternate I2C Portmuxpca-mcp.json
Example
config.json
- BME6xxmuxpca-mcp.json
Example
config.json
- AHT20aht20.json
Example
config.json
- 2x Sensors on one bus, BME280 and TSL2591config-bme280-tsl.json