Skip to content

Commit 0d0a674

Browse files
committed
add RP2040 SerialPIO
1 parent 2682f41 commit 0d0a674

File tree

882 files changed

+95274
-95179
lines changed

Some content is hidden

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

882 files changed

+95274
-95179
lines changed

examples/01.Quadcopter/madflight_config.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// processor families. Default pinouts are defined in the board header files library/src/madflight_board_default_XXX.h
99
//
1010
// 2) Header - #include the BetaFlight flight controller you want to use. See library/madflight/src for all available
11-
// boards. For example: #include <madflight_board_betaflight_MTKS-MATEKH743.h>
11+
// boards. For example: #include <madflight_zzz_MTKS-MATEKH743.h>
1212
//
1313
// 3) Custom - Do not include a board file here, and set your own board definition in the CUSTOM PINS section below.
1414
//
@@ -21,7 +21,7 @@
2121
// HARDWARE CONFIG //
2222
//========================================================================================================================//
2323
//
24-
// Hardware configuration is a simple key-value list. Anything after '#' or '/' is ignored as comment
24+
// Hardware configuration is a raw string with a key-value list. On a line, anything after '#' or '/' is ignored as comment
2525
//
2626
//========================================================================================================================//
2727

@@ -183,5 +183,8 @@ imu_i2c_bus -1
183183
//-- AHRS sensor fusion
184184
#define AHR_USE AHR_USE_MAHONY // Select one: AHRS_USE_MAHONY, AHRS_USE_MAHONY_BF, AHRS_USE_MADGWICK, AHRS_USE_VQF
185185

186-
// Reset config eeprom to defaults (uncomment this, upload, then comment out again)
186+
// Reset config eeprom to defaults (uncomment this, upload, then comment out, and upload again)
187187
//#define MF_CONFIG_CLEAR
188+
189+
// Uncomment to print additional debug information and reduce startup delay
190+
//#define MF_DEBUG

examples/02.QuadcopterAdvanced/madflight_config.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// processor families. Default pinouts are defined in the board header files library/src/madflight_board_default_XXX.h
99
//
1010
// 2) Header - #include the BetaFlight flight controller you want to use. See library/madflight/src for all available
11-
// boards. For example: #include <madflight_board_betaflight_MTKS-MATEKH743.h>
11+
// boards. For example: #include <madflight_zzz_MTKS-MATEKH743.h>
1212
//
1313
// 3) Custom - Do not include a board file here, and set your own board definition in the CUSTOM PINS section below.
1414
//
@@ -21,7 +21,7 @@
2121
// HARDWARE CONFIG //
2222
//========================================================================================================================//
2323
//
24-
// Hardware configuration is a simple key-value list. Anything after '#' or '/' is ignored as comment
24+
// Hardware configuration is a raw string with a key-value list. On a line, anything after '#' or '/' is ignored as comment
2525
//
2626
//========================================================================================================================//
2727

@@ -180,10 +180,11 @@ imu_i2c_bus -1
180180
// COMPILER OPTIONS //
181181
//========================================================================================================================//
182182

183-
#define BBX_USE BBX_USE_SDSPI
184-
185183
//-- AHRS sensor fusion
186184
#define AHR_USE AHR_USE_MAHONY // Select one: AHRS_USE_MAHONY, AHRS_USE_MAHONY_BF, AHRS_USE_MADGWICK, AHRS_USE_VQF
187185

188-
// Reset config eeprom to defaults (uncomment this, upload, then comment out again)
186+
// Reset config eeprom to defaults (uncomment this, upload, then comment out, and upload again)
189187
//#define MF_CONFIG_CLEAR
188+
189+
// Uncomment to print additional debug information and reduce startup delay
190+
//#define MF_DEBUG

examples/03.Plane/madflight_config.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// processor families. Default pinouts are defined in the board header files library/src/madflight_board_default_XXX.h
99
//
1010
// 2) Header - #include the BetaFlight flight controller you want to use. See library/madflight/src for all available
11-
// boards. For example: #include <madflight_board_betaflight_MTKS-MATEKH743.h>
11+
// boards. For example: #include <madflight_zzz_MTKS-MATEKH743.h>
1212
//
1313
// 3) Custom - Do not include a board file here, and set your own board definition in the CUSTOM PINS section below.
1414
//
@@ -21,7 +21,7 @@
2121
// HARDWARE CONFIG //
2222
//========================================================================================================================//
2323
//
24-
// Hardware configuration is a simple key-value list. Anything after '#' or '/' is ignored as comment
24+
// Hardware configuration is a raw string with a key-value list. On a line, anything after '#' or '/' is ignored as comment
2525
//
2626
//========================================================================================================================//
2727

@@ -183,5 +183,8 @@ imu_i2c_bus -1
183183
//-- AHRS sensor fusion
184184
#define AHR_USE AHR_USE_MAHONY // Select one: AHRS_USE_MAHONY, AHRS_USE_MAHONY_BF, AHRS_USE_MADGWICK, AHRS_USE_VQF
185185

186-
// Reset config eeprom to defaults (uncomment this, upload, then comment out again)
186+
// Reset config eeprom to defaults (uncomment this, upload, then comment out, and upload again)
187187
//#define MF_CONFIG_CLEAR
188+
189+
// Uncomment to print additional debug information and reduce startup delay
190+
//#define MF_DEBUG

extras/betaflight_target_converter/betaflight_target_converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
source_dirname = "betaflight_source" # copy from https://github.com/betaflight/unified-targets/tree/master/configs/default
99
destination_path = "../../src/"
10-
destination_prefix = "madflight_board_"
10+
destination_prefix = "madflight_zzz_"
1111

1212
CMT = " // "
1313

src/madflight/cfg/cfg_cpp.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class CfgClass : public CfgParam {
103103
void begin();
104104
uint16_t paramCount(); //get number of parameters
105105
bool getNameAndValue(uint16_t index, String* name, float* value); //get parameter name and value for index
106-
void list(); //CLI print all config values
106+
void list(const char* filter = nullptr); //CLI print all config values
107107
bool setParam(String namestr, String val); //CLI set a parameter value, returns true on success
108108
bool setParamMavlink(String namestr, float val); //set a parameter value, returns true on success
109109
int getIndex(String namestr); //get parameter index for a parameter name
@@ -287,9 +287,11 @@ void CfgClass::printValue(uint16_t i) {
287287
}
288288

289289
//CLI print all config values
290-
void CfgClass::list() {
290+
void CfgClass::list(const char* filter) {
291291
for(int i=0;i<paramCount();i++) {
292-
printNameAndValue(i);
292+
if(strstr(Cfg::param_list[i].name, filter)) {
293+
printNameAndValue(i);
294+
}
293295
}
294296
}
295297

src/madflight/cli/cli_cpp.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,10 @@ class CLI {
272272
"bbbench Benchmark\n"
273273
"bbinfo Info\n"
274274
"-- CONFIG --\n"
275-
"set [name] [value]\n"
276-
"clist List config\n"
277-
"cclear Clear config\n"
278-
"cwrite Write config to flash\n"
275+
"set <name> <value> Set config parameter\n"
276+
"clist <filter> List config\n"
277+
"cclear Clear config\n"
278+
"cwrite Write config to flash\n"
279279
"-- CALIBRATE --\n"
280280
"calinfo Sensor info\n"
281281
"calimu Calibrate IMU error\n"
@@ -395,7 +395,7 @@ class CLI {
395395
}else if (cmd == "set") {
396396
cfg.setParam(arg1, arg2);
397397
}else if (cmd == "clist") {
398-
cfg.list();
398+
cfg.list(arg1.c_str());
399399
}else if (cmd == "cclear") {
400400
cfg.clear();
401401
Serial.println("Config cleared, use 'cwrite' to write to flash");

src/madflight/hal/MF_Serial.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,17 @@ class MF_SerialPtrWrapper : public MF_Serial {
3737
};
3838

3939
/*
40-
// Dummy interface
41-
class MF_SerialNone : public MF_Serial {
40+
============ Template for new classes ================
41+
42+
class MF_SerialXXX : public MF_Serial {
4243
public:
4344
void begin(int baud) override { (void)baud; }
4445
int available() override { return 0; }
4546
int availableForWrite() override { return 0; }
4647
int read(uint8_t *buf, int len) override { (void)buf; (void)len; return 0; }
4748
int write(uint8_t *buf, int len) override { (void)buf; (void)len; return 0; }
4849
};
50+
4951
*/
5052

5153
/*--------------------------------------------------------------------------------------
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//MF_Serial wrapper around SerialPIO with task based TX buffer
2+
3+
#pragma once
4+
5+
#include "hal_RP2040.h"
6+
#include "../MF_Serial.h"
7+
#include <stream_buffer.h>
8+
9+
void MF_SerialPIO_task( void * pvParameters );
10+
11+
class MF_SerialPIO : public MF_Serial {
12+
public:
13+
SerialPIO *_serial;
14+
StreamBufferHandle_t xStreamBuffer = NULL;
15+
16+
17+
MF_SerialPIO(SerialPIO *_serial, const char* taskname) {
18+
this->_serial = _serial;
19+
20+
xStreamBuffer = xStreamBufferCreate(256, 1); // length, triggerlevel
21+
22+
xTaskCreate( MF_SerialPIO_task, // The function that implements the task
23+
taskname, // Human readable name for the task
24+
configMINIMAL_STACK_SIZE, // Stack size (in words!)
25+
(void*)this, // Task parameter
26+
uxTaskPriorityGet(NULL), // The priority at which the task is created
27+
NULL ); // No use for the task handle
28+
}
29+
30+
void begin(int baud) override {
31+
_serial->begin(baud);
32+
}
33+
34+
int read(uint8_t *buf, int len) override {
35+
return _serial->readBytes(buf, len);
36+
}
37+
38+
int available() override {
39+
return _serial->available();
40+
}
41+
42+
int availableForWrite() override {
43+
return xStreamBufferSpacesAvailable(xStreamBuffer);
44+
}
45+
46+
int write(uint8_t *buf, int len) override {
47+
if(availableForWrite() < len) return 0;
48+
return xStreamBufferSend( xStreamBuffer, (const void *)buf, len, 0 ); //0 = no wait
49+
}
50+
};
51+
52+
void MF_SerialPIO_task( void * pvParameters ) {
53+
MF_SerialPIO *self = (MF_SerialPIO*) pvParameters;
54+
uint8_t b;
55+
for( ;; ) {
56+
xStreamBufferReceive( self->xStreamBuffer, &b, 1, portMAX_DELAY );
57+
self->_serial->write(b);
58+
}
59+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//MF_Serial wrapper around SerialUART with task based TX buffer
2+
3+
#pragma once
4+
5+
#include "hal_RP2040.h"
6+
#include "../MF_Serial.h"
7+
#include <stream_buffer.h>
8+
9+
void MF_SerialUART_task( void * pvParameters );
10+
11+
class MF_SerialUART : public MF_Serial {
12+
public:
13+
SerialUART *_serial;
14+
StreamBufferHandle_t xStreamBuffer = NULL;
15+
16+
17+
18+
MF_SerialUART(SerialUART *_serial, const char* taskname) {
19+
this->_serial = _serial;
20+
21+
xStreamBuffer = xStreamBufferCreate(256, 1); // length, triggerlevel
22+
23+
xTaskCreate( MF_SerialUART_task, // The function that implements the task
24+
taskname, // Human readable name for the task
25+
configMINIMAL_STACK_SIZE, // Stack size (in words!)
26+
(void*)this, // Task parameter
27+
uxTaskPriorityGet(NULL), // The priority at which the task is created
28+
NULL ); // No use for the task handle
29+
}
30+
31+
void begin(int baud) override {
32+
_serial->begin(baud);
33+
}
34+
35+
int read(uint8_t *buf, int len) override {
36+
return _serial->readBytes(buf, len);
37+
}
38+
39+
int available() override {
40+
return _serial->available();
41+
}
42+
43+
int availableForWrite() override {
44+
return xStreamBufferSpacesAvailable(xStreamBuffer);
45+
}
46+
47+
int write(uint8_t *buf, int len) override {
48+
if(availableForWrite() < len) return 0;
49+
return xStreamBufferSend( xStreamBuffer, (const void *)buf, len, 0 ); //0 = no wait
50+
}
51+
};
52+
53+
void MF_SerialUART_task( void * pvParameters ) {
54+
MF_SerialUART *self = (MF_SerialUART*) pvParameters;
55+
uint8_t b;
56+
for( ;; ) {
57+
xStreamBufferReceive( self->xStreamBuffer, &b, 1, portMAX_DELAY );
58+
self->_serial->write(b);
59+
}
60+
}

src/madflight/hal/RP2040/MF_SerialUartTask_RP2040.h

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)