-
Notifications
You must be signed in to change notification settings - Fork 12
feat(vacuum-module): more sensor hardware + sensor read functionality #543
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
base: edge
Are you sure you want to change the base?
Conversation
| uint8_t read_buff[4] = {0x00}; | ||
| bool sensor_busy = true; | ||
|
|
||
| policy->i2c_write(0x18 << 1, 0xAA, read_buff, 0); |
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.
lets use the DEV_ADDRESS and MEASURE_PRESSURE_COMMAND defines, lets add write_buff.
| } | ||
|
|
||
| auto read_pressure(int retries) -> uint16_t { | ||
| uint8_t read_buff[4] = {0x00}; |
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.
this gets allocated on the call stack, so lets create a global read/write buffer like so.
constexpr uint8_t PRESSURE_FRAME_LEN = 10;
std::array<uint8_t, PRESSURE_FRAME_LEN> READ_BUFF = {0};
std::array<uint8_t, PRESSURE_FRAME_LEN> WRITE_BUFF = {0};then we can pass these buffers to the i2c_write and i2c_read functions like so
policy->i2c_write(DEVICE_ADDRESS, MEASURE_PRESSURE_COMMAND, READ_BUFF.data(), 4);| { p.i2c_write(dev_addr, reg, data, size) } -> std::same_as<RxTxReturn>; | ||
| }; | ||
|
|
||
| constexpr uint8_t DEVICE_ADDRESS = 0xB8; |
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.
- lets use the 7bit address (0x5C) and bitshift this instead, so we know explicitly what address we are targeting.
- lets also add a comment that we are grounding the SA0 pin to use 0x5C address
| { p.i2c_write(dev_addr, reg, data, size) } -> std::same_as<RxTxReturn>; | ||
| }; | ||
|
|
||
| constexpr uint8_t DEVICE_ADDRESS = 0xB8; |
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.
- lets use the 7bit address (0x5C) and bitshift this instead, so we know explicitly what address we are targeting.
- lets also add a comment that we are grounding the SA0 pin to use 0x5C address
vegano1
left a comment
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.
Left a few comments
sfoster1
left a comment
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.
Confused by those min and max reading numbers - those need 24 or so bits, so either the data type is wrong or the numbers are wrong
| constexpr uint8_t DEV_ADDRESS = 0x30; | ||
| constexpr uint8_t MEASURE_PRESSURE_COMMAND = 0xAA; | ||
| constexpr uint8_t STATUS_BUSY_FLAG = 0x20; | ||
| constexpr uint16_t OUTPUT_MAX = 15099494; |
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.
this doesn't seem right, it's not a 16 bit number
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.
you're right- the pressure output is 3 bytes, it's a 24 bit number. I've changed it to uint32_t
| constexpr uint8_t MEASURE_PRESSURE_COMMAND = 0xAA; | ||
| constexpr uint8_t STATUS_BUSY_FLAG = 0x20; | ||
| constexpr uint16_t OUTPUT_MAX = 15099494; | ||
| constexpr uint16_t OUTPUT_MIN = 1677722; |
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.
ditto
stm32-modules/include/vacuum-module/vacuum-module/MPRLL0025PA00001A.hpp
Outdated
Show resolved
Hide resolved
stm32-modules/include/vacuum-module/vacuum-module/MPRLL0025PA00001A.hpp
Outdated
Show resolved
Hide resolved
| auto read_pressure(int retries) -> uint16_t { | ||
| bool sensor_busy = true; | ||
|
|
||
| _policy->i2c_write(DEVICE_ADDRESS, MEASURE_PRESSURE_COMMAND, READ_BUFF, |
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.
- this should use a WRITE_BUFF
- this should write 1 byte instead of 0
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.
also, should this be using i2c_master_write instead? i remember we were having issues with the i2c_write
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## edge #543 +/- ##
==========================================
+ Coverage 77.52% 77.84% +0.31%
==========================================
Files 83 86 +3
Lines 7743 7773 +30
==========================================
+ Hits 6003 6051 +48
+ Misses 1740 1722 -18 🚀 New features to boost your workflow:
|
Overview
With this code, once a FreeRTOSTask is connected to the sensor policies, you should be able to read from all sensors, as well as interact with the eoc and reset pins on the MPR pressure sensor.
Another note: the atmosphere pressure sensor (lps22df)'s pins aren't actually connected to the MCU as of this hardware revision. There's just a TODO noting that we should add that when it's connected.
Changelog
system_hardwareto its own filemain.hand reference those, rather than theHAL_GPIOdefs directly