Skip to content

Commit fd1b94c

Browse files
driver fixes
1 parent 11527dc commit fd1b94c

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

stm32-modules/include/vacuum-module/vacuum-module/MPRLL0025PA00001A.hpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@
44
#include <cstdint>
55
#include <optional>
66

7+
#include "firmware/vacuum_pressure_sensor_policy.hpp"
8+
79
namespace vacuum_pressure_sensor {
810

911
template <typename P>
1012
concept MPRPolicy = requires(P p, uint16_t dev_addr, uint16_t reg,
1113
uint16_t size, uint8_t* data) {
12-
{ p.i2c_read(dev_addr, reg, data, size) } -> std::same_as<RxTxReturn>;
13-
{ p.i2c_write(dev_addr, reg, data, size) } -> std::same_as<RxTxReturn>;
14+
{ p.i2c_read(dev_addr, reg, data, size) } -> std::same_as<i2c::hardware::RxTxReturn>;
15+
{ p.i2c_write(dev_addr, reg, data, size) } -> std::same_as<i2c::hardware::RxTxReturn>;
1416
};
1517

1618
constexpr uint8_t DEV_ADDRESS = 0x30;
1719
constexpr uint8_t MEASURE_PRESSURE_COMMAND = 0xAA;
1820
constexpr uint8_t STATUS_BUSY_FLAG = 0x20;
19-
constexpr uint16_t OUTPUT_MAX = 15099494;
20-
constexpr uint16_t OUTPUT_MIN = 1677722;
21-
constexpr uint16_t OUTPUT_RANGE_COUNTS = OUTPUT_MAX - OUTPUT_MIN;
21+
constexpr uint32_t OUTPUT_MAX = 15099494;
22+
constexpr uint32_t OUTPUT_MIN = 1677722;
23+
constexpr uint32_t OUTPUT_RANGE_COUNTS = OUTPUT_MAX - OUTPUT_MIN;
2224
// range for this particular model is 0-25 PSI
2325
constexpr uint16_t PRESSURE_RANGE_PSI = 25;
2426

@@ -31,7 +33,7 @@ struct StatusByte {
3133

3234
class MPRLL0025PA00001 {
3335
public:
34-
auto initialize(MPRPolicy* policy) -> void {
36+
auto initialize(hardware::VacuumPressureSensorPolicy* policy) -> void {
3537
if (_policy == nullptr) {
3638
_policy = policy;
3739
}
@@ -41,10 +43,10 @@ class MPRLL0025PA00001 {
4143
uint8_t read_buff[4] = {0x00};
4244
bool sensor_busy = true;
4345

44-
policy->i2c_write(0x18 << 1, 0xAA, read_buff, 0);
46+
_policy->i2c_write(0x18 << 1, 0xAA, read_buff, 0);
4547

4648
for (int i = 0; i < retries; i++) {
47-
policy->i2c_master_read(0x18 << 1, read_buff, 4);
49+
_policy->i2c_master_read(0x18 << 1, read_buff, 4);
4850
auto status_byte = read_buff[0];
4951
sensor_busy = static_cast<bool>(status_byte & STATUS_BUSY_FLAG);
5052

@@ -58,12 +60,12 @@ class MPRLL0025PA00001 {
5860
}
5961

6062
private:
61-
MPRPolicy* _policy{nullptr};
63+
hardware::VacuumPressureSensorPolicy* _policy{nullptr};
6264

6365
auto convert_pressure(uint8_t* sensor_output) -> uint16_t {
6466
auto pressure_read_counts =
65-
sensor_outputf[1] << 16 | sensor_output[2] << 8 | sensor_outputf[3];
66-
pressure_psi =
67+
sensor_output[1] << 16 | sensor_output[2] << 8 | sensor_output[3];
68+
auto pressure_psi =
6769
(pressure_read_counts * PRESSURE_RANGE_PSI) / OUTPUT_RANGE_COUNTS;
6870
return pressure_psi;
6971
}

stm32-modules/include/vacuum-module/vacuum-module/lps22df.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <cstdint>
55
#include <optional>
66

7+
#include "firmware/atmosphere_pressure_sensor_policy.hpp"
8+
79
namespace lps22df {
810

911
template <typename P>
@@ -28,7 +30,7 @@ constexpr uint8_t PRESSURE_READY_FLAG = 0x01;
2830

2931
class LPS222DF {
3032
public:
31-
auto initialize(LPS22DFPolicy* policy) -> void {
33+
auto initialize(atmosphere_pressure_sensor::hardware::AtmospherePressureSensorPolicy* policy) -> void {
3234
if (_policy == nullptr) {
3335
_policy = policy;
3436
}
@@ -61,14 +63,14 @@ class LPS222DF {
6163
}
6264

6365
private:
64-
LPS22DFPolicy* _policy{nullptr};
66+
atmosphere_pressure_sensor::hardware::AtmospherePressureSensorPolicy* _policy{nullptr};
6567

6668
auto convert_pressure(uint8_t* sensor_output) -> uint16_t {
6769
auto pressure_read_bytes = {sensor_output[1], sensor_output[2],
6870
sensor_output[3]};
6971
// test that this is accurate
7072
auto pressure_read_counts =
71-
sensor_outputf[1] << 16 | sensor_output[2] << 8 | sensor_outputf[3];
73+
sensor_output[1] << 16 | sensor_output[2] << 8 | sensor_output[3];
7274
auto pressure_hPa = pressure_read_counts / SENSOR_SENSITIVITY;
7375
return pressure_hPa
7476
}

0 commit comments

Comments
 (0)