Skip to content

Commit 3fb3be7

Browse files
authored
Merge pull request #45 from openppg/develop/free-rtos
Rewrite threading to use FreeRTOS
2 parents 5bf5464 + 5b6b09b commit 3fb3be7

17 files changed

+725
-738
lines changed

.github/workflows/config.yml

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ jobs:
99
name: CPP Lint
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v2
12+
- uses: actions/checkout@v3
1313
- name: Setup Python
14-
uses: actions/setup-python@v2
14+
uses: actions/setup-python@v3
1515
with:
1616
python-version: 3.x
1717
- run: pip install cpplint
18-
- run: cpplint --linelength 140 --filter=-runtime/int,-build/include_subdir --recursive ./inc/ ./lib/ ./src/
18+
- run: cpplint --linelength 140 --filter=-legal/copyright,-runtime/int,-build/include_subdir --recursive ./inc/ ./lib/ ./src/
1919
pio-build:
2020
name: PlatformIO Build
2121
runs-on: ubuntu-latest
2222
steps:
23-
- uses: actions/checkout@v2
23+
- uses: actions/checkout@v3
2424
- name: Setup Python
25-
uses: actions/setup-python@v2
25+
uses: actions/setup-python@v3
2626
with:
2727
python-version: 3.x
2828
- name: Install Platform IO
@@ -41,28 +41,29 @@ jobs:
4141
with:
4242
name: OpenPPG-CRP2040-SP140.uf2
4343
path: .pio/build/OpenPPG-CRP2040-SP140/firmware.uf2
44-
generate-uf2:
45-
name: Save uf2 for ${{ matrix.device }}
46-
needs: pio-build
47-
runs-on: ubuntu-latest
48-
strategy:
49-
matrix:
50-
device: [OpenPPG-CM0-SP140]
51-
fail-fast: false
52-
steps:
53-
- name: Setup Python
54-
uses: actions/setup-python@v2
55-
- name: Checkout Microsoft uf2 repo
56-
uses: actions/checkout@v2
57-
with:
58-
repository: microsoft/uf2
59-
- name: Download built binary
60-
uses: actions/download-artifact@v2
61-
with:
62-
name: bins
63-
- name: Run uf2 conversion
64-
run: python3 utils/uf2conv.py ${{ matrix.device }}/firmware.bin -c -o ${{ matrix.device }}.uf2
65-
- uses: actions/upload-artifact@v3
66-
with:
67-
name: ${{ matrix.device }}.uf2
68-
path: ${{ matrix.device }}.uf2
44+
# Skip until M0 builds running by default
45+
# generate-uf2:
46+
# name: Save uf2 for ${{ matrix.device }}
47+
# needs: pio-build
48+
# runs-on: ubuntu-latest
49+
# strategy:
50+
# matrix:
51+
# device: [OpenPPG-CM0-SP140]
52+
# fail-fast: false
53+
# steps:
54+
# - name: Setup Python
55+
# uses: actions/setup-python@v2
56+
# - name: Checkout Microsoft uf2 repo
57+
# uses: actions/checkout@v3
58+
# with:
59+
# repository: microsoft/uf2
60+
# - name: Download built binary
61+
# uses: actions/download-artifact@v2
62+
# with:
63+
# name: bins
64+
# - name: Run uf2 conversion
65+
# run: python3 utils/uf2conv.py ${{ matrix.device }}/firmware.bin -c -o ${{ matrix.device }}.uf2
66+
# - uses: actions/upload-artifact@v3
67+
# with:
68+
# name: ${{ matrix.device }}.uf2
69+
# path: ${{ matrix.device }}.uf2

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ X4 code has been migrated to a separate repo - https://github.com/openppg/x4-con
1111
It may not be stable and is not recommended for flying.
1212
See stable releases [here](https://github.com/openppg/eppg-controller/releases)
1313

14+
> Version 6.0 introduced [FreeRTOS](https://www.freertos.org/index.html) and is currently only working with RP2040 processors. For M0/SAMD21 processors please use [version/5 branch](https://github.com/openppg/eppg-controller/tree/version/5).
15+
1416
> For batch 3 (non-telemetry) controllers please see the [batch-3 branch](https://github.com/openppg/eppg-controller/tree/batch-3).
1517
1618
> For batch 2 (Arduino nano based) controllers please see the [batch-2 branch](https://github.com/openppg/eppg-controller/tree/batch-2).

inc/sp140/altimeter.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef INC_SP140_ALTIMETER_H_
2+
#define INC_SP140_ALTIMETER_H_
3+
4+
#include <Arduino.h>
5+
6+
#include "sp140/structs.h"
7+
8+
// Set up the barometer
9+
void setupAltimeter();
10+
11+
// Get the altitude (in meters)
12+
float getAltitude(const STR_DEVICE_DATA_140_V1& deviceData);
13+
14+
// Set the ground altitude to the current altitude to compute AGL
15+
void setGroundAltitude(const STR_DEVICE_DATA_140_V1& deviceData);
16+
17+
#endif // INC_SP140_ALTIMETER_H_

inc/sp140/display.h

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#ifndef INC_SP140_DISPLAY_H_
2+
#define INC_SP140_DISPLAY_H_
3+
4+
#include <Arduino.h>
5+
6+
#include "sp140/structs.h"
7+
#include <Adafruit_ST7735.h>
8+
#include "utilities.h"
9+
10+
// Library config
11+
#define NO_ADAFRUIT_SSD1306_COLOR_COMPATIBILITY
12+
13+
#define BLACK ST77XX_BLACK
14+
#define WHITE ST77XX_WHITE
15+
#define GREEN ST77XX_GREEN
16+
#define YELLOW ST77XX_YELLOW
17+
#define RED ST77XX_RED
18+
#define BLUE ST77XX_BLUE
19+
#define ORANGE ST77XX_ORANGE
20+
#define CYAN ST77XX_CYAN
21+
#define PURPLE 0x780F
22+
#define GRAY 0xDEFB
23+
24+
// Light mode (default)
25+
// #define DEFAULT_TEXT_COLOR BLACK
26+
// #define ERROR_TEXT_COLOR RED
27+
// #define CHILL_TEXT_COLOR CYAN
28+
29+
// #define DEFAULT_BG_COLOR WHITE
30+
// #define ARMED_BG_COLOR CYAN
31+
// #define CRUISE_BG_COLOR YELLOW
32+
// #define UI_ACCENT_COLOR BLACK
33+
34+
// Dark mode
35+
// #define DEFAULT_TEXT_COLOR WHITE
36+
// #define ERROR_TEXT_COLOR RED
37+
// #define CHILL_TEXT_COLOR CYAN
38+
39+
// #define DEFAULT_BG_COLOR BLACK
40+
// #define ARMED_BG_COLOR BLUE
41+
// #define CRUISE_BG_COLOR ORANGE
42+
// #define UI_ACCENT_COLOR GRAY
43+
44+
struct UIColors {
45+
uint16_t default_text;
46+
uint16_t error_text;
47+
uint16_t chill_text;
48+
uint16_t default_bg;
49+
uint16_t armed_bg;
50+
uint16_t cruise_bg;
51+
uint16_t ui_accent;
52+
};
53+
54+
extern float watts;
55+
extern float wattHoursUsed;
56+
57+
// Set up the display and show splash screen
58+
void setupDisplay(const STR_DEVICE_DATA_140_V1& deviceData);
59+
60+
void displayMeta(const STR_DEVICE_DATA_140_V1& deviceData, int duration = 2000);
61+
62+
// Clear screen and reset properties
63+
void resetRotation(unsigned int orientation);
64+
65+
// Show data on screen
66+
void updateDisplay(const STR_DEVICE_DATA_140_V1& deviceData,
67+
const STR_ESC_TELEMETRY_140& escTelemetry,
68+
float altitude, bool armed, bool cruising,
69+
unsigned int armedStartMillis);
70+
71+
void setTheme(int theme); // 0,1
72+
73+
#endif // INC_SP140_DISPLAY_H_

inc/sp140/globals.h

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
byte escData[ESC_DATA_SIZE];
66
byte escDataV2[ESC_DATA_V2_SIZE];
7-
unsigned long cruisedAtMilis = 0;
7+
unsigned long cruisedAtMillis = 0;
88
unsigned long transmitted = 0;
99
unsigned long failed = 0;
1010
bool cruising = false;
@@ -17,42 +17,17 @@ bool batteryFlag = true;
1717
bool throttledFlag = true;
1818
bool throttled = false;
1919
unsigned long throttledAtMillis = 0;
20-
unsigned int throttleSecs = 0;
21-
float minutes = 0;
22-
float prevMinutes = 0;
23-
float seconds = 0;
24-
float prevSeconds = 0;
25-
float hours = 0; // logged flight hours
26-
float wattsHoursUsed = 0;
20+
21+
float watts = 0;
22+
float wattHoursUsed = 0;
2723

2824
// sensor states
29-
bool bmpPresent = false;
3025
bool vibePresent = false;
3126

32-
uint16_t _volts = 0;
33-
uint16_t _temperatureC = 0;
3427
int16_t _amps = 0;
35-
uint32_t _eRPM = 0;
36-
uint16_t _inPWM = 0;
37-
uint16_t _outPWM = 0;
38-
39-
// ESC Telemetry
40-
float prevVolts = 0;
41-
float prevAmps = 0;
42-
float watts = 0;
43-
float prevKilowatts = 0;
44-
float prevKwh = 0;
45-
46-
// ALTIMETER
47-
float ambientTempC = 0;
48-
float altitudeM = 0;
49-
float lastAltM = 0;
5028

51-
Adafruit_BMP3XX bmp;
5229
Servo esc; // Creating a servo class with name of esc
5330

5431
static STR_DEVICE_DATA_140_V1 deviceData;
5532

56-
uint16_t bottom_bg_color = DEFAULT_BG_COLOR;
57-
5833
#endif // INC_SP140_GLOBALS_H_

inc/sp140/shared-config.h

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#define MAMP_OFFSET 200
1010
#define VOLT_OFFSET 1.5
1111

12-
#define VERSION_MAJOR 5
13-
#define VERSION_MINOR 9
12+
#define VERSION_MAJOR 6
13+
#define VERSION_MINOR 0
1414

1515
#define CRUISE_GRACE 1.5 // 1.5 sec period to get off throttle
1616
#define POT_SAFE_LEVEL 0.05 * 4096 // 5% or less
@@ -24,26 +24,14 @@
2424
#define ESC_MIN_PWM 1030 // ESC min is 1050
2525
#define ESC_MAX_PWM 1990 // ESC max 1950
2626

27-
#define BLACK ST77XX_BLACK
28-
#define WHITE ST77XX_WHITE
29-
#define GREEN ST77XX_GREEN
30-
#define YELLOW ST77XX_YELLOW
31-
#define RED ST77XX_RED
32-
#define BLUE ST77XX_BLUE
33-
#define ORANGE ST77XX_ORANGE
34-
#define PURPLE 0x780F
3527

36-
#define DEFAULT_BG_COLOR WHITE
37-
#define ARMED_BG_COLOR ST77XX_CYAN
38-
#define CRUISE_BG_COLOR YELLOW
39-
40-
#define DIGIT_ARRAY_SIZE 7
4128
#define ESC_BAUD_RATE 115200
4229
#define ESC_DATA_SIZE 20
4330
#define ESC_DATA_V2_SIZE 22
4431
#define READ_INTERVAL 0
4532
#define ESC_TIMEOUT 15
4633
#define ENABLE_BUZ true // enable buzzer
4734
#define ENABLE_VIB_LOW_BAT false // vibrate if armed and battery voltage sags below min volts. Gets pilot's attention.
35+
#define POT_MAX_VALUE 4095 // 12 bit ADC //TODO use calibration and store in EEPROM
4836

4937
#endif // INC_SP140_SHARED_CONFIG_H_

inc/sp140/structs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ typedef struct {
2727
bool metric_alt; // false
2828
uint8_t performance_mode; // 0,1,2
2929
uint16_t batt_size; // 4000 (4kw) or 2000 (2kw)
30-
uint8_t btn_mode; // for future use
30+
uint8_t theme; // 0,1 for light/dark
3131
uint8_t unused; // for future use
3232
uint16_t crc; // error check
3333
}STR_DEVICE_DATA_140_V1;

inc/sp140/utilities.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef INC_SP140_UTILITIES_H_
2+
#define INC_SP140_UTILITIES_H_
3+
4+
double mapd(double x, double in_min, double in_max, double out_min, double out_max);
5+
6+
#endif // INC_SP140_UTILITIES_H_

platformio.ini

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
libr_dir = libraries
1313
include_dir = inc
1414
default_envs =
15-
OpenPPG-CM0-SP140
15+
;OpenPPG-CM0-SP140 ; not currently supported
1616
OpenPPG-CRP2040-SP140
1717

1818
[extra]
@@ -46,7 +46,7 @@ lib_ignore =
4646
${extra.lib_ignore}
4747

4848
[env:OpenPPG-CRP2040-SP140]
49-
platform = https://github.com/openppg/platform-raspberrypi.git#190d06ec0ece2f38031389c8b5eccf2bd3d349e9
49+
platform = https://github.com/openppg/platform-raspberrypi.git#d558b307a404efbfc4282ce9e61d16f338f1c172
5050
board = sparkfun_promicrorp2040
5151
framework = arduino
5252
board_build.core = earlephilhower
@@ -58,17 +58,16 @@ board_build.filesystem_size = 14M ; 14 Mbyte for filesystem and 2 Mbyte for prog
5858
src_folder = sp140
5959
extra_scripts = pre:extra_script.py
6060
lib_deps =
61-
62-
63-
[email protected] ; deprecated
61+
62+
6463
[email protected] ; deprecated
6564
6665
adafruit/Adafruit [email protected]
6766
adafruit/Adafruit BMP3XX [email protected]
6867
adafruit/Adafruit DRV2605 [email protected]
69-
adafruit/Adafruit ST7735 and ST7789 Library@1.9.3
68+
adafruit/Adafruit ST7735 and ST7789 Library@1.10.2
7069
https://github.com/rlogiacco/CircularBuffer
71-
Adafruit GFX [email protected].5
70+
Adafruit GFX [email protected].7
7271
lib_ignore =
7372
Adafruit SleepyDog Library
7473
${extra.lib_ignore}

src/sp140/altimeter.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include "sp140/altimeter.h"
2+
#include "sp140/structs.h"
3+
4+
#include <Adafruit_BMP3XX.h>
5+
6+
Adafruit_BMP3XX bmp;
7+
bool bmpPresent = false;
8+
float groundAltitude = 0;
9+
10+
float getAltitude(const STR_DEVICE_DATA_140_V1& deviceData) {
11+
if (bmpPresent) {
12+
const float altitude = bmp.readAltitude(deviceData.sea_pressure);
13+
return altitude - groundAltitude;
14+
}
15+
return __FLT_MIN__;
16+
}
17+
18+
// set the ground altitude to the current altitude
19+
void setGroundAltitude(const STR_DEVICE_DATA_140_V1& deviceData) {
20+
groundAltitude = bmp.readAltitude(deviceData.sea_pressure);
21+
}
22+
23+
// Start the bmp388 sensor
24+
void setupAltimeter() {
25+
if (!bmp.begin_I2C()) return;
26+
bmp.setOutputDataRate(BMP3_ODR_25_HZ);
27+
bmp.setTemperatureOversampling(BMP3_OVERSAMPLING_2X);
28+
bmp.setPressureOversampling(BMP3_OVERSAMPLING_4X);
29+
bmp.setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_15);
30+
bmp.readPressure(); // throw away first reading
31+
bmpPresent = true;
32+
}

0 commit comments

Comments
 (0)