Skip to content

Conversation

@caila-marashaj
Copy link
Contributor

@caila-marashaj caila-marashaj commented Nov 6, 2025

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

  • added read functionality to both pressure sensor policies
  • moved sensor hardware initialization from system_hardware to its own file
  • defined pin values in main.h and reference those, rather than the HAL_GPIO defs directly

@caila-marashaj caila-marashaj marked this pull request as ready for review November 6, 2025 20:56
uint8_t read_buff[4] = {0x00};
bool sensor_busy = true;

policy->i2c_write(0x18 << 1, 0xAA, read_buff, 0);
Copy link
Contributor

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};
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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

Copy link
Contributor

@vegano1 vegano1 left a 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

Copy link
Member

@sfoster1 sfoster1 left a 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;
Copy link
Member

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

Copy link
Contributor Author

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

auto read_pressure(int retries) -> uint16_t {
bool sensor_busy = true;

_policy->i2c_write(DEVICE_ADDRESS, MEASURE_PRESSURE_COMMAND, READ_BUFF,
Copy link
Contributor

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

Copy link
Contributor

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-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.84%. Comparing base (d834200) to head (1dea21e).
⚠️ Report is 5 commits behind head on edge.

Additional details and impacted files

Impacted file tree graph

@@            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     

see 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants