Skip to content

Commit 6aa9896

Browse files
committed
Merge branch 'dev'
2 parents b97f07f + 1e28f0f commit 6aa9896

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3570
-668
lines changed

.github/workflows/firmware-release.yml

+5-7
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,14 @@ jobs:
1616

1717
- name: Install STM libs
1818
run: |
19-
arduino-cli config init --additional-urls https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json
19+
arduino-cli config init --additional-urls https://github.com/stm32duino/BoardManagerFiles/raw/master/package_stmicroelectronics_index.json
2020
arduino-cli config dump
2121
arduino-cli core update-index
22-
export STM32DUINO_VERSION="1.9.0"
23-
arduino-cli core install STM32:stm32@$STM32DUINO_VERSION
22+
export STM32DUINO_VERSION="2.0.0"
23+
arduino-cli core install STMicroelectronics:stm32@$STM32DUINO_VERSION
2424
arduino-cli lib install [email protected]
2525
arduino-cli lib install [email protected]
2626
arduino-cli lib install [email protected]
27-
sed -i '/recipe.output.tmp_file={build.project_name}.hex/d' "$HOME/.arduino15/packages/STM32/hardware/stm32/$STM32DUINO_VERSION/platform.txt"
28-
sed -i '/recipe.output.save_file={build.project_name}.{build.variant}.hex/d' "$HOME/.arduino15/packages/STM32/hardware/stm32/$STM32DUINO_VERSION/platform.txt"
2927
3028
- name: Get the version
3129
id: version
@@ -41,7 +39,7 @@ jobs:
4139
- name: Build production HW3
4240
run: |
4341
sed -Ei 's/#define MODE .+/#define MODE MODE_PROD/' includes/config.h
44-
arduino-cli compile --fqbn STM32:stm32:Nucleo_64:opt=o3std,pnum=NUCLEO_F411RE --verbose srcs/respirator.cpp --output output/respirator-production
42+
arduino-cli compile --fqbn STMicroelectronics:stm32:Nucleo_64:opt=o3std,pnum=NUCLEO_F411RE --verbose srcs/respirator.cpp --output output/respirator-production
4543
mkdir -p dist/
4644
VERSION=$(sed -En 's/#define VERSION[ ]+["](.+)["]/\1/p' includes/parameters.h)
4745
cp output/respirator-production.bin "dist/respirator-production-HW3-$VERSION-$GITHUB_SHA.bin"
@@ -50,7 +48,7 @@ jobs:
5048
run: |
5149
sed -Ei 's/#define MODE .+/#define MODE MODE_PROD/' includes/config.h
5250
sed -Ei 's/#define MASS_FLOW_METER_ENABLED/\/\/ #define MASS_FLOW_METER_ENABLED/' includes/config.h
53-
arduino-cli compile --fqbn STM32:stm32:Nucleo_64:opt=o3std,pnum=NUCLEO_F411RE --verbose srcs/respirator.cpp --output output/respirator-production
51+
arduino-cli compile --fqbn STMicroelectronics:stm32:Nucleo_64:opt=o3std,pnum=NUCLEO_F411RE --verbose srcs/respirator.cpp --output output/respirator-production
5452
mkdir -p dist/
5553
VERSION=$(sed -En 's/#define VERSION[ ]+["](.+)["]/\1/p' includes/parameters.h)
5654
cp output/respirator-production.bin "dist/respirator-production-HW3-NOMASSFLOWMETER-$VERSION-$GITHUB_SHA.bin"

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@
1010
/*.ods#
1111
build/*
1212
.scannerwork
13+
14+
flash.sh
15+
16+
srcs/srcs.ino

CHANGELOG.md

+25-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22

33
## unreleased
44

5+
_Nothing for now_
6+
7+
## v4.0.0
8+
59
- drop support of electronic hardware v1 and v2
610
(_from now on, minimum compatibility is from v3_)
711
- refactor main loop and breathing control
812
(_breathing-related computations are now triggered by a hardware timer_)
913
- support several breathing modes
10-
(_PC-CMV stays the default mode, PC-BIPAP was added_)
14+
(_PC-CMV stays the default mode, PC-VSAI and PC-AC were added_)
15+
- added volume controlled ventilation modes
16+
(_VC-CMV and VC-AC were added_)
1117
- telemetry protocol v2 was introduced
1218
(_basically, this means sending more data_)
1319
- drop support of useless "qualification" and "integration test" modes
@@ -21,9 +27,27 @@
2127
- allow to snooze alarms or start/stop breathing using the serial control protocol
2228
- drop support of old valves and pneumatic systems
2329
- make mass flow meter more reliable
30+
- support for SFM mass flow meters
31+
(_SFM3019 and SFM_3300D_)
32+
- added support for a mass flow meter on the expiratory branch
33+
(_if it is missing, the expiratory flow rate will be estimated using an algorithm_)
2434
- turn the green LED on when alarms are snoozed
35+
- added a facility to pre-configure the ventilator settings upon boot, using a patient height setting
36+
(_submitting the patient height will update all ventilation hyperparameters to optimum values_)
37+
- added configurable alarms for pressure and volume modes, adding to all existing alarms
38+
- sending more measured values for display, e.g. respiratory durations and cycles per minute
39+
- a more precise battery voltage value is now sent over the telemetry protocol
40+
(_this is used for battery SoC estimations_)
2541
- display a special message on LCD screen when watchdog reset was triggered
42+
- ability to detect in a reliable way when AC gets off, and that power is switched to battery
2643
- allow to retry pressure calibration when it fails
44+
- added a ramp-up algorithm on the blower speed controller, in order to prevent current surges in the transformer, which could trigger a temporary handover on batteries
45+
(_this is a security feature, in cases where batteries would be depleted or not connected, the ventilator would suddenly reboot during use_)
46+
- added a compilation flag to disable all hardware buttons
47+
(_this is used for touchscreen-only MakAir devices, i.e. non-traditional ones_)
48+
- added basic support for the motherboard V3 EEPROM chip over I2C
49+
(_disabled by default until stable_)
50+
- a lot of potential exceptions due to possible divisions by zero have been fixed
2751
- increase the size of the hardware buffer used by telemetry
2852
- improve Doxygen documentation
2953

Doxyfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ PROJECT_NUMBER =
4444
# for a project that appears at the top of each page and should give viewer a
4545
# quick idea about the purpose of the project. Keep the description short.
4646

47-
PROJECT_BRIEF = "Software Firmware (MakAir — Covid-19 Respirator)"
47+
PROJECT_BRIEF = "MakAir Firmware"
4848

4949
# With the PROJECT_LOGO tag one can specify a logo or an icon that is included
5050
# in the documentation. The maximum height of the logo should not exceed 55

README.md

+12-9
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
| V1.3.x | Add Hardware V2 support | ✅
1111
| V1.5.x | Rework ventilation algorithms (pressure control, alarms, code quality) | ✅
1212
| V3.0.x | Support for triggers, add mass flow meter, add Hardware V3 support | ✅
13-
| V4.0.x | Protocol V2 with ventilation modes, drop Hardware V1 & V2 support |
13+
| V4.0.x | Protocol V2 with ventilation modes, drop Hardware V1 & V2 support |
1414

1515
For a full history of all minor versions, as well as details of all changes, see [CHANGELOG.md](CHANGELOG.md).
1616

1717
## ⚛️ Latest Improvements
1818

19-
A bleeding edge firmware version is available on the [dev](https://github.com/makers-for-life/makair-firmware/tree/dev) branch, which contains our latest improvements, ventilation modes and safety fixes.
19+
A _bleeding edge_ firmware version is available on the [dev](https://github.com/makers-for-life/makair-firmware/tree/dev) branch, which contains our latest improvements. This firmware version might still be work in progress and thus might not be suitable for production use.
2020

21-
**⚠️ Note that the `master` branch contains a legacy firmware version, that will not work with the latest version of [makair-control-ui](https://github.com/makers-for-life/makair-firmware/tree/dev), please use the `dev` branch instead.**
21+
**⚠️ Note that the `master` branch may not contain the latest firmware version. It might not work with the latest version of [makair-control-ui](https://github.com/makers-for-life/makair-control-ui). In this case, please use the `dev` branch instead.**
2222

2323
## Releases
2424

@@ -30,18 +30,20 @@ Code documentation can be [found there](https://makers-for-life.github.io/makair
3030

3131
## How To Build?
3232

33+
First, make sure `arduino-cli` is installed on your system. The supported version is `0.9.0`. _Newer versions are known to cause issues with compiling the firmware code._
34+
3335
In order to setup your environment and build the code, please follow the following commands (for MacOS):
3436

3537
1. `brew install arduino-cli`
36-
2. `arduino-cli config init --additional-urls https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json`
38+
2. `arduino-cli config init --additional-urls https://github.com/stm32duino/BoardManagerFiles/raw/master/package_stmicroelectronics_index.json`
3739
3. `arduino-cli core update-index`
38-
4. `arduino-cli core install STM32:stm32@1.9.0`
40+
4. `arduino-cli core install STMicroelectronics:stm32@2.0.0`
3941
5. `arduino-cli lib install [email protected] && arduino-cli lib install [email protected] && arduino-cli lib install [email protected]`
4042

4143
Then, compile the project:
4244

4345
```sh
44-
arduino-cli compile --fqbn STM32:stm32:Nucleo_64:opt=o3std,pnum=NUCLEO_F411RE --verbose srcs/respirator.cpp --output output/respirator-production
46+
arduino-cli compile --fqbn STMicroelectronics:stm32:Nucleo_64:opt=o3std,pnum=NUCLEO_F411RE --verbose srcs/respirator.cpp --output output/respirator-production
4547
```
4648

4749
## How To Flash?
@@ -53,13 +55,14 @@ In order to flash the firmware that you just built using the instructions above:
5355
3. Make sure that [STM32CubeProgrammer](https://www.st.com/en/development-tools/stm32cubeprog.html) is installed on your computer, and run:
5456

5557
```sh
56-
arduino-cli upload --port {SERIAL_PORT} --fqbn STM32:stm32:Nucleo_64:pnum=NUCLEO_F411RE,upload_method=swdMethod --input output/respirator-production
58+
arduino-cli upload --port {SERIAL_PORT} --fqbn STMicroelectronics:stm32:Nucleo_64:pnum=NUCLEO_F411RE,upload_method=swdMethod --input output/respirator-production
5759
```
5860

5961
_Make sure to replace {SERIAL_PORT} with your serial port, which should begin with `/dev/`._
6062

6163
## Configuration
6264

63-
High-level configuration options are available and documented in [includes/config.h](includes/config.h).
65+
The configuration options can be found in the following files:
6466

65-
Low-level configuration options can be found in [includes/parameters.h](includes/parameters.h).
67+
* High-level configuration options are available and documented in [includes/config.h](includes/config.h);
68+
* Low-level configuration options can be found in [includes/parameters.h](includes/parameters.h);

flash.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
arduino-cli compile --fqbn STM32:stm32:Nucleo_64:pnum=NUCLEO_F411RE srcs/respirator.cpp --output-dir output
2+
dfu-util -a 0 --dfuse-address 0x08000000 -D output/srcs.ino.bin

includes/alarm.h

+12
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ class Alarm {
5555
/// Reset to zero the number of detection.
5656
void notDetected();
5757

58+
/// Enable this alarm
59+
void enable();
60+
61+
/// Disable this alarm
62+
void disable();
63+
64+
/// True if this alarm is enabled
65+
bool isEnabled();
66+
5867
private:
5968
/// Alarm priority
6069
AlarmPriority m_priority;
@@ -73,4 +82,7 @@ class Alarm {
7382

7483
/// Number of cycles since the alarm was triggered
7584
uint32_t m_cyclesSinceTrigger;
85+
86+
/// Whether or not this alarm is enabled
87+
bool m_enabled;
7688
};

includes/alarm_controller.h

+37-14
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,36 @@
1515

1616
// CONSTANTS ==================================================================
1717

18-
#define ALARMS_SIZE 10u
19-
20-
#define RCM_SW_1 12u
21-
#define RCM_SW_2 11u
22-
#define RCM_SW_3 14u
23-
// #define RCM_SW_6 15u - NOT IN THIS VERSION
24-
// #define RCM_SW_8 18u - NOT IN THIS VERSION
25-
#define RCM_SW_11 21u
26-
#define RCM_SW_12 13u
27-
#define RCM_SW_14 22u
28-
#define RCM_SW_15 23u
29-
#define RCM_SW_16 31u
30-
#define RCM_SW_18 17u
31-
#define RCM_SW_19 24u
18+
#define ALARMS_SIZE 21u
19+
20+
#define RCM_SW_1 12u // Plateau pressure not reached
21+
#define RCM_SW_2 11u // Patient is unplugged
22+
#define RCM_SW_3 14u // Peep not reached
23+
#define RCM_SW_11 21u // Battery Low
24+
#define RCM_SW_12 13u // Battery vers Low
25+
#define RCM_SW_14 22u // Plateau pressure not reached
26+
#define RCM_SW_15 23u // Peep not reached
27+
#define RCM_SW_16 31u // Mains disconnected
28+
#define RCM_SW_18 17u // Pressure too high
29+
#define RCM_SW_19 24u // Patient is unplugged
30+
31+
#define RCM_SW_4 40u // Inspiratory minute Volume is too low
32+
#define RCM_SW_5 41u // Inspiratory minute Volume is too high
33+
#define RCM_SW_6 42u // Expiratory minute Volume is too low
34+
#define RCM_SW_7 43u // Expiratory minute Volume is too high
35+
#define RCM_SW_8 44u // Respiratory rate is too low
36+
#define RCM_SW_9 45u // Respiratory rate is too high
37+
#define RCM_SW_10 46u // Leak is too high
38+
39+
#define RCM_SW_20 47u // Tidal Volume is too low
40+
#define RCM_SW_21 48u // Tidal Volume is too high
41+
#define RCM_SW_22 49u // peak pressure is too high
42+
#define RCM_SW_23 107u // Expiratory flow too low
43+
44+
/// List of alarms (named by their code)
45+
struct Alarms {
46+
uint8_t alarms[ALARMS_SIZE];
47+
};
3248

3349
// CLASS =====================================================================
3450

@@ -89,6 +105,13 @@ class AlarmController {
89105
/// Get the alarms triggered during this cycle
90106
uint8_t* triggeredAlarms() { return m_triggeredAlarms; }
91107

108+
/**
109+
* Update the list of enabled alarms (alarms not provided here will have no effects)
110+
*
111+
* @param enabledAlarms The new list of enabled alarms
112+
*/
113+
void updateEnabledAlarms(Alarms enabledAlarms);
114+
92115
private:
93116
/// Highest priority of the currently triggered alarms
94117
AlarmPriority m_highestPriority;

includes/battery.h

+11-11
Original file line numberDiff line numberDiff line change
@@ -17,52 +17,52 @@
1717
* RawValue = (Vbat*0.1087)*1024/3.348
1818
* So, Vbat = RawValue * (3.348/(1024*0.1087))
1919
*
20-
* 1 bit = 3.348/(1024*0.1087) = 30.07mV
20+
* 1 bit = 3.348/(4096*0.1087) = 7.5mV
2121
*/
22-
#define RAW_BATTERY_MULTIPLIER 0.0300784843606
22+
#define RAW_BATTERY_MULTIPLIER 0.0075196210
2323

2424
/**
2525
* Expected voltage in volts when power cord is plugged
2626
* 27,4 V => 27,4 / RAW_BATTERY_MULTIPLIER
2727
*/
28-
#define RAW_VOLTAGE_MAINS 907
28+
#define RAW_VOLTAGE_MAINS 3643u
2929

3030
/**
3131
* RCM_SW_16
3232
* Expected voltage in volts when power cord is unplugged
3333
* = 27 => 27 / RAW_BATTERY_MULTIPLIER
3434
*/
35-
#define RAW_VOLTAGE_ON_BATTERY_HIGH 897u
35+
#define RAW_VOLTAGE_ON_BATTERY_HIGH 3590u
3636

3737
/**
3838
* Hysteresis is used to prevent fast switching when voltage is at the limit of 2 states
3939
* analogRead(PIN) * RAW_BATTERY_MULTIPLIER = 0,1 => 0,1 / RAW_BATTERY_MULTIPLIER = 3
4040
*/
41-
#define RAW_VOLTAGE_HYSTERESIS 3u
41+
#define RAW_VOLTAGE_HYSTERESIS 12u
4242

4343
/**
4444
* RCM_SW_11
45-
* = 24,6 => 24,6 / RAW_BATTERY_MULTIPLIER
45+
* = 23,2 => 23,2 / RAW_BATTERY_MULTIPLIER
4646
*/
47-
#define RAW_VOLTAGE_ON_BATTERY 817u
47+
#define RAW_VOLTAGE_ON_BATTERY 3085u
4848

4949
/**
5050
* RCM_SW_12
51-
* = 24 => 24 / RAW_BATTERY_MULTIPLIER
51+
* = 22,6 => 22,6 / RAW_BATTERY_MULTIPLIER
5252
*/
53-
#define RAW_VOLTAGE_ON_BATTERY_LOW 797u
53+
#define RAW_VOLTAGE_ON_BATTERY_LOW 3005u
5454

5555
/**
5656
* Below this value, the machine wont start
5757
* = 22 => 22 / RAW_BATTERY_MULTIPLIER
5858
*/
59-
#define RAW_VOLTAGE_ON_BATTERY_NOT_STARTING_THRESHOLD 731u
59+
#define RAW_VOLTAGE_ON_BATTERY_NOT_STARTING_THRESHOLD 3191u
6060

6161
/**
6262
* Below this value, the machine will stop immediately
6363
* = 20 => 20 / RAW_BATTERY_MULTIPLIER
6464
*/
65-
#define RAW_VOLTAGE_ON_BATTERY_STOP_THRESHOLD 664u
65+
#define RAW_VOLTAGE_ON_BATTERY_STOP_THRESHOLD 2660u
6666

6767
/// Number of samples of the moving average
6868
#define BATTERY_MAX_SAMPLES 20u

includes/blower.h

+27-2
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,38 @@ class Blower {
4141
/// Initialize the hardware timer used to control the blower
4242
void setup();
4343

44+
/**
45+
* Run the blower to a given speed applying a ramp-up to prevent high current drain
46+
*
47+
* @param p_targetSpeed Speed between MIN_BLOWER_SPEED and MAX_BLOWER_SPEED
48+
*/
49+
void runSpeedWithRampUp(uint16_t p_targetSpeed);
50+
4451
/**
4552
* Run the blower to a given speed
4653
*
47-
* @param p_speed Speed between MIN_BLOWER_SPEED and MAX_BLOWER_SPEED
54+
* @param p_runSpeed Speed between MIN_BLOWER_SPEED and MAX_BLOWER_SPEED
4855
*/
49-
void runSpeed(uint16_t p_speed);
56+
void runSpeed(uint16_t p_runSpeed);
57+
58+
void execute();
5059

5160
/// Stops the blower
5261
void stop();
5362

5463
/// Get speed value
5564
uint16_t getSpeed() const;
5665

66+
/// Get target speed value
67+
uint16_t getTargetSpeed() const;
68+
/**
69+
* Given a flow in mL/min, return an estimated pressure just at the output of the blower. This
70+
* pressure has been determined using the pressure-flow characteristic of the blower
71+
*
72+
* @param p_flow inspiratory flow in mL/min
73+
*/
74+
int32_t getBlowerPressure(int32_t p_flow);
75+
5776
private:
5877
/// Hardware timer used to control the blower
5978
HardwareTimer* actuator;
@@ -67,8 +86,14 @@ class Blower {
6786
/// Current speed
6887
uint16_t m_speed;
6988

89+
/// target speed
90+
uint16_t m_targetSpeed;
91+
7092
/// Current state
7193
bool m_stopped;
94+
95+
// Last call of the runspeed function of the blower
96+
uint32_t m_lastCallDate;
7297
};
7398

7499
extern Blower blower;

0 commit comments

Comments
 (0)