Skip to content

Commit a60c9c2

Browse files
authored
Merge pull request #46 from openppg/rp2040-module
Support multiple RP2040 boards
2 parents e90dfd6 + 549f458 commit a60c9c2

19 files changed

+717
-253
lines changed

inc/sp140/altimeter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "sp140/structs.h"
77

88
// Set up the barometer
9-
void setupAltimeter();
9+
bool setupAltimeter(bool alt_wire = false);
1010

1111
// Get the altitude (in meters)
1212
float getAltitude(const STR_DEVICE_DATA_140_V1& deviceData);

inc/sp140/display.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
#include <Arduino.h>
55

66
#include "sp140/structs.h"
7+
8+
#ifdef M0_PIO
9+
#include "../../inc/sp140/m0-config.h"
10+
#else
11+
#include "../../inc/sp140/rp2040-config.h"
12+
#endif
13+
714
#include <Adafruit_ST7735.h>
815
#include "utilities.h"
916

@@ -55,7 +62,7 @@ extern float watts;
5562
extern float wattHoursUsed;
5663

5764
// Set up the display and show splash screen
58-
void setupDisplay(const STR_DEVICE_DATA_140_V1& deviceData);
65+
void setupDisplay(const STR_DEVICE_DATA_140_V1& deviceData, const HardwareConfig& board_config);
5966

6067
void displayMeta(const STR_DEVICE_DATA_140_V1& deviceData, int duration = 2000);
6168

inc/sp140/globals.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,11 @@
55
byte escData[ESC_DATA_SIZE];
66
byte escDataV2[ESC_DATA_V2_SIZE];
77
unsigned long cruisedAtMillis = 0;
8-
unsigned long transmitted = 0;
9-
unsigned long failed = 0;
10-
bool cruising = false;
8+
volatile bool cruising = false;
119
int prevPotLvl = 0;
1210
int cruisedPotVal = 0;
13-
float throttlePWM = 0;
14-
float batteryPercent = 0;
15-
float prevBatteryPercent = 0;
16-
bool batteryFlag = true;
11+
volatile float throttlePWM = 0;
1712
bool throttledFlag = true;
18-
bool throttled = false;
19-
unsigned long throttledAtMillis = 0;
2013

2114
float watts = 0;
2215
float wattHoursUsed = 0;

inc/sp140/m0-config.h

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
// Arduino Pins
88
#define BUTTON_TOP 6 // arm/disarm button_top
9-
#define BUTTON_SIDE 7 // secondary button_top
109
#define BUZZER_PIN 5 // output for buzzer speaker
1110
#define LED_SW LED_BUILTIN // output for LED
1211
#define LED_2 0 // output for LED 2
@@ -24,4 +23,38 @@
2423
#define ESC_PIN 12
2524
#define ENABLE_VIB true // enable vibration
2625

26+
struct HardwareConfig {
27+
int button_top;
28+
int buzzer_pin;
29+
int led_sw;
30+
int led_2;
31+
int led_3;
32+
int throttle_pin;
33+
HardwareSerial* serial_esc;
34+
int pot_pin;
35+
int tft_rst;
36+
int tft_cs;
37+
int tft_dc;
38+
int tft_lite;
39+
int esc_pin;
40+
bool enable_vib;
41+
};
42+
43+
HardwareConfig m0_config = {
44+
.button_top = 6,
45+
.buzzer_pin = 5,
46+
.led_sw = LED_BUILTIN,
47+
.led_2 = 0,
48+
.led_3 = 38,
49+
.throttle_pin = A0,
50+
.serial_esc = &Serial5,
51+
.pot_pin = A0,
52+
.tft_rst = 9,
53+
.tft_cs = 10,
54+
.tft_dc = 11,
55+
.tft_lite = A1,
56+
.esc_pin = 12,
57+
.enable_vib = true
58+
};
59+
2760
#endif // INC_SP140_M0_CONFIG_H_

inc/sp140/rp2040-config.h

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,26 @@
44

55
#include "shared-config.h"
66

7-
// Arduino Pins
8-
#define BUTTON_TOP 15 // arm/disarm button_top
9-
#define BUTTON_SIDE 7 // secondary button_top
10-
#define BUZZER_PIN 10 // output for buzzer speaker
11-
#define LED_SW 12 // output for LED
12-
#define THROTTLE_PIN A0 // throttle pot input
13-
147
#define SerialESC Serial1 // ESC UART connection
158

16-
// SP140
17-
#define POT_PIN A0
18-
#define TFT_RST 5
19-
#define TFT_CS 13
20-
#define TFT_DC 11
21-
#define TFT_LITE 25
22-
#define ESC_PIN 14
23-
#define ENABLE_VIB false // enable vibration
9+
struct HardwareConfig {
10+
int button_top;
11+
int buzzer_pin;
12+
int led_sw;
13+
int throttle_pin;
14+
int bmp_pin;
15+
HardwareSerial* serial_esc;
16+
bool alt_wire;
17+
int tft_rst;
18+
int tft_cs;
19+
int tft_dc;
20+
int tft_lite;
21+
int esc_pin;
22+
bool enable_vib;
23+
bool enable_neopixel;
24+
};
25+
26+
extern HardwareConfig v1_config;
27+
extern HardwareConfig v2_config;
2428

2529
#endif // INC_SP140_RP2040_CONFIG_H_

inc/sp140/shared-config.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// Copyright 2021 <Zach Whitehead>
2+
#include "../version.h"
3+
24
#ifndef INC_SP140_SHARED_CONFIG_H_
35
#define INC_SP140_SHARED_CONFIG_H_
46

@@ -9,8 +11,6 @@
911
#define MAMP_OFFSET 200
1012
#define VOLT_OFFSET 1.5
1113

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
@@ -34,4 +34,10 @@
3434
#define ENABLE_VIB_LOW_BAT false // vibrate if armed and battery voltage sags below min volts. Gets pilot's attention.
3535
#define POT_MAX_VALUE 4095 // 12 bit ADC //TODO use calibration and store in EEPROM
3636

37+
enum DeviceRevision {
38+
M0 = 0,
39+
V1 = 1,
40+
MODULE = 2
41+
};
42+
3743
#endif // INC_SP140_SHARED_CONFIG_H_

inc/sp140/structs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ typedef struct {
2828
uint8_t performance_mode; // 0,1,2
2929
uint16_t batt_size; // 4000 (4kw) or 2000 (2kw)
3030
uint8_t theme; // 0,1 for light/dark
31-
uint8_t unused; // for future use
31+
uint8_t revision; // 2040 board revision (1=original, 2=rev1)
3232
uint16_t crc; // error check
3333
}STR_DEVICE_DATA_140_V1;
3434

inc/sp140/utilities.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,17 @@
33

44
double mapd(double x, double in_min, double in_max, double out_min, double out_max);
55

6+
// Definitions for main rainbow colors in WRGB format for NeoPixel.
7+
// The 32-bit color value is WRGB. W (White) is ignored for RGB pixels.
8+
// The next bytes are R (Red), G (Green), and B (Blue).
9+
// For example, YELLOW is 0x00FFFF00, with FF for Red and Green, and 00 for Blue.
10+
11+
#define LED_RED 0x00FF0000
12+
#define LED_ORANGE 0x00FF7F00
13+
#define LED_YELLOW 0x00FFFF00
14+
#define LED_GREEN 0x0000FF00
15+
#define LED_BLUE 0x000000FF
16+
#define LED_INDIGO 0x004B0082
17+
#define LED_VIOLET 0x008000FF
18+
619
#endif // INC_SP140_UTILITIES_H_

inc/version.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Copyright <Zach Whitehead>
2+
#pragma once
3+
4+
#define VERSION_MAJOR 6
5+
#define VERSION_MINOR 2

platformio.ini

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,33 +41,40 @@ lib_deps =
4141
adafruit/Adafruit [email protected]
4242
adafruit/Adafruit BMP3XX [email protected]
4343
adafruit/Adafruit ST7735 and ST7789 [email protected]
44-
https://github.com/rlogiacco/CircularBuffer
44+
https://github.com/rlogiacco/CircularBuffer@1.4.0
4545
lib_ignore =
4646
${extra.lib_ignore}
4747

4848
[env:OpenPPG-CRP2040-SP140]
49-
platform = https://github.com/openppg/platform-raspberrypi.git#d558b307a404efbfc4282ce9e61d16f338f1c172
49+
platform = https://github.com/openppg/platform-raspberrypi.git#de3a06a0d358567da4b175d6590971d6bfa1408f
5050
board = sparkfun_promicrorp2040
5151
framework = arduino
5252
board_build.core = earlephilhower
5353
build_flags = -DRP_PIO -DUSE_TINYUSB
54+
test_framework = unity
55+
monitor_filters =
56+
time
5457

5558
; configure filesystem size. Default 0 Mbyte.
5659
; Out of 16Mbyte available
5760
board_build.filesystem_size = 14M ; 14 Mbyte for filesystem and 2 Mbyte for program
5861
src_folder = sp140
5962
extra_scripts = pre:extra_script.py
6063
lib_deps =
64+
Wire
65+
Adafruit TinyUSB Library
66+
SPI
6167
6268
6369
[email protected] ; deprecated
6470
65-
adafruit/Adafruit [email protected]
66-
adafruit/Adafruit BMP3XX [email protected]
67-
adafruit/Adafruit DRV2605 [email protected]
68-
adafruit/Adafruit ST7735 and ST7789 [email protected]
69-
https://github.com/rlogiacco/CircularBuffer
70-
Adafruit GFX [email protected]
71+
adafruit/Adafruit [email protected]
72+
adafruit/Adafruit BMP3XX [email protected]
73+
adafruit/Adafruit DRV2605 [email protected]
74+
adafruit/Adafruit ST7735 and ST7789 [email protected]
75+
adafruit/Adafruit [email protected]
76+
https://github.com/rlogiacco/[email protected]
77+
Adafruit GFX [email protected]
7178
lib_ignore =
7279
Adafruit SleepyDog Library
7380
${extra.lib_ignore}

0 commit comments

Comments
 (0)