Skip to content

Commit

Permalink
Merge pull request #152 from rtlopez/compiler
Browse files Browse the repository at this point in the history
upgrade to standard c++17
  • Loading branch information
rtlopez authored Feb 5, 2025
2 parents 0a4f0c2 + aec5ccd commit 0a1a53c
Show file tree
Hide file tree
Showing 21 changed files with 118 additions and 51 deletions.
2 changes: 1 addition & 1 deletion lib/EscDriver/src/EscDriverEsp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "hal/gpio_ll.h"
#include "esp_rom_gpio.h"

static const size_t DURATION_CLOCK = 25; // [ns] doubled value to increase precision
static constexpr size_t DURATION_CLOCK = 25; // [ns] doubled value to increase precision
#define TO_INTERVAL_US(v) (1 * 1000 * 1000 / (v)) // [us]

#define RMT_RX_CHANNEL_ENCODING_START (SOC_RMT_CHANNELS_PER_GROUP - SOC_RMT_TX_CANDIDATES_PER_GROUP)
Expand Down
4 changes: 2 additions & 2 deletions lib/EscDriver/src/EscDriverEsp32.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class EscDriverEsp32: public EscDriverBase
return (int)pin != -1;
}

static const size_t ITEM_COUNT = DSHOT_BIT_COUNT + 1;
static const int32_t DURATION_MAX = 0x7fff; // max in 15 bits
static constexpr size_t ITEM_COUNT = DSHOT_BIT_COUNT + 1;
static constexpr int32_t DURATION_MAX = 0x7fff; // max in 15 bits

rmt_item32_t items[ITEM_COUNT];
int pin;
Expand Down
2 changes: 1 addition & 1 deletion lib/Espfc/src/Blackbox/BlackboxFlashfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "Utils/RingBuf.h"
#include "Utils/Math.hpp"

static const uint32_t FLASHFS_ERASED_VAL = 0xffffffff;
static constexpr uint32_t FLASHFS_ERASED_VAL = 0xffffffff;

using BufferType = Espfc::Utils::RingBuf<uint8_t, FLASHFS_WRITE_BUFFER_SIZE>;

Expand Down
16 changes: 13 additions & 3 deletions lib/Espfc/src/Blackbox/BlackboxSerialBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,22 @@ namespace Blackbox {
class BlackboxSerialBuffer: public Device::SerialDevice
{
public:
BlackboxSerialBuffer(): _dev(nullptr), _idx(0) {}
static constexpr size_t SIZE = SERIAL_TX_FIFO_SIZE;//128;

BlackboxSerialBuffer(): _dev(nullptr), _idx(0), _data(nullptr) {}

~BlackboxSerialBuffer()
{
if(!_data) return;

delete[] _data;
_data = nullptr;
}

virtual void wrap(Espfc::Device::SerialDevice * s)
{
_dev = s;
_data = new uint8_t[SIZE];
}

virtual void begin(const Espfc::SerialDeviceConfig& conf)
Expand Down Expand Up @@ -74,11 +85,10 @@ class BlackboxSerialBuffer: public Device::SerialDevice
virtual bool isSoft() const { return false; };
virtual operator bool() const { return (bool)(*_dev); }

static const size_t SIZE = SERIAL_TX_FIFO_SIZE;//128;

Device::SerialDevice * _dev;
size_t _idx;
uint8_t _data[SIZE];
uint8_t* _data;
};

}
Expand Down
8 changes: 4 additions & 4 deletions lib/Espfc/src/Connect/Cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ void Cli::execute(CliCmd& cmd, Stream& s)
else if(strcmp_P(cmd.args[0], PSTR("logs")) == 0)
{
s.print(_model.logger.c_str());
s.print(PSTR("total: "));
s.print(PSTR("usage: "));
s.println(_model.logger.length());
}
#ifdef USE_FLASHFS
Expand Down Expand Up @@ -1442,13 +1442,13 @@ void Cli::printVersion(Stream& s) const
s.print(buildDate);
s.print(' ');
s.print(buildTime);
s.print(' ');
s.print(" api=");
s.print(API_VERSION_MAJOR);
s.print('.');
s.print(API_VERSION_MINOR);
s.print(' ');
s.print(" gcc=");
s.print(__VERSION__);
s.print(' ');
s.print(" std=");
s.print(__cplusplus);
}

Expand Down
8 changes: 4 additions & 4 deletions lib/Espfc/src/Device/BusSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class BusSPI: public BusDevice
public:
BusSPI(ESPFC_SPI_0_DEV_T& spi);

static const uint8_t SPI_READ = 0x80;
static const uint8_t SPI_WRITE = 0x7f;
static constexpr uint8_t SPI_READ = 0x80;
static constexpr uint8_t SPI_WRITE = 0x7f;

static const uint32_t SPI_SPEED_NORMAL = 1000000;
static const uint32_t SPI_SPEED_FAST = 16000000;
static constexpr uint32_t SPI_SPEED_NORMAL = 1000000;
static constexpr uint32_t SPI_SPEED_FAST = 16000000;

BusType getType() const override;

Expand Down
4 changes: 2 additions & 2 deletions lib/Espfc/src/Device/InputCRSF.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class InputCRSF: public InputDevice
void applyChannels(const Rc::CrsfMessage& msg);
void applyMspReq(const Rc::CrsfMessage& msg);

static const size_t CHANNELS = 16;
static const size_t TELEMETRY_INTERVAL = 20000;
static constexpr size_t CHANNELS = 16;
static constexpr size_t TELEMETRY_INTERVAL = 20000;

Device::SerialDevice * _serial;
TelemetryManager * _telemetry;
Expand Down
2 changes: 1 addition & 1 deletion lib/Espfc/src/Device/InputEspNow.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class InputEspNow: public InputDevice

private:
EspNowRcLink::Receiver _rx;
static const size_t CHANNELS = EspNowRcLink::RC_CHANNEL_MAX + 1;
static constexpr size_t CHANNELS = EspNowRcLink::RC_CHANNEL_MAX + 1;
uint16_t _channels[CHANNELS];
};

Expand Down
4 changes: 2 additions & 2 deletions lib/Espfc/src/Device/InputPPM.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class InputPPM: public InputDevice
bool needAverage() const override;

private:
static const size_t CHANNELS = 16;
static const uint32_t BROKEN_LINK_US = 100000UL; // 100ms
static constexpr size_t CHANNELS = 16;
static constexpr uint32_t BROKEN_LINK_US = 100000UL; // 100ms

void handle();
static void handle_isr(void* args);
Expand Down
4 changes: 2 additions & 2 deletions lib/Espfc/src/Device/InputSBUS.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class InputSBUS: public InputDevice
void apply();
uint16_t convert(int v);

const static size_t SBUS_FRAME_SIZE = sizeof(SbusData);
static const size_t CHANNELS = 16;
static constexpr size_t SBUS_FRAME_SIZE = sizeof(SbusData);
static constexpr size_t CHANNELS = 16;

Device::SerialDevice * _serial;
SbusState _state;
Expand Down
4 changes: 2 additions & 2 deletions lib/Espfc/src/Input.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ class Input
Device::InputEspNow _espnow;
#endif

static const uint32_t TENTH_TO_US = 100000UL; // 1_000_000 / 10;
static const uint32_t FRAME_TIME_DEFAULT_US = 23000; // 23 ms
static constexpr uint32_t TENTH_TO_US = 100000UL; // 1_000_000 / 10;
static constexpr uint32_t FRAME_TIME_DEFAULT_US = 23000; // 23 ms
};

}
4 changes: 2 additions & 2 deletions lib/Espfc/src/ModelConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -509,11 +509,11 @@ enum ArmingDisabledFlags {
ARMING_DISABLED_ARM_SWITCH = (1 << 25), // Needs to be the last element, since it's always activated if one of the others is active when arming
};

static const size_t ARMING_DISABLED_FLAGS_COUNT = 25;
static constexpr size_t ARMING_DISABLED_FLAGS_COUNT = 25;

struct WirelessConfig
{
static const size_t MAX_LEN = 32;
static constexpr size_t MAX_LEN = 32;
int16_t port = 1111;
char ssid[MAX_LEN + 1];
char pass[MAX_LEN + 1];
Expand Down
4 changes: 4 additions & 0 deletions lib/Espfc/src/Sensor/GyroSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ GyroSensor::GyroSensor(Model &model) : _dyn_notch_denom(1), _model(model)
{
}

GyroSensor::~GyroSensor()
{
}

int GyroSensor::begin()
{
_gyro = _model.state.gyro.dev;
Expand Down
1 change: 1 addition & 0 deletions lib/Espfc/src/Sensor/GyroSensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class GyroSensor: public BaseSensor
{
public:
GyroSensor(Model& model);
~GyroSensor();

int begin();
int read();
Expand Down
22 changes: 14 additions & 8 deletions lib/Espfc/src/Utils/FFTAnalyzer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@ class FFTAnalyzer
{
public:
FFTAnalyzer();
~FFTAnalyzer();

int begin(int16_t rate, const DynamicFilterConfig& config, size_t axis);
int update(float v);

static const size_t PEAKS_MAX = 8;
static constexpr size_t PEAKS_MAX = 8;
Utils::Peak peaks[PEAKS_MAX];

private:
void clearPeaks();

static const size_t BINS = SAMPLES >> 1;
static constexpr size_t BINS = SAMPLES >> 1;

int16_t _rate;
int16_t _freq_min;
Expand All @@ -44,14 +46,18 @@ class FFTAnalyzer
size_t _end;
float _bin_width;

// fft input
__attribute__((aligned(16))) float _in[SAMPLES];
// // fft input
// __attribute__((aligned(16))) float _in[SAMPLES];

// // fft output
// __attribute__((aligned(16))) float _out[SAMPLES];

// fft output
__attribute__((aligned(16))) float _out[SAMPLES];
// // Window coefficients
// __attribute__((aligned(16))) float _win[SAMPLES];

// Window coefficients
__attribute__((aligned(16))) float _win[SAMPLES];
float* _in;
float* _out;
float* _win;
};

}
Expand Down
16 changes: 15 additions & 1 deletion lib/Espfc/src/Utils/FFTAnalyzer.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,28 @@
#include "Utils/FFTAnalyzer.hpp"
#include "dsps_fft4r.h"
#include "dsps_wind_hann.h"
#include "esp_heap_caps.h"
#include <algorithm>

namespace Espfc {

namespace Utils {

template<size_t SAMPLES>
FFTAnalyzer<SAMPLES>::FFTAnalyzer(): _idx(0), _phase(PHASE_COLLECT) {}
FFTAnalyzer<SAMPLES>::FFTAnalyzer(): _idx(0), _phase(PHASE_COLLECT), _begin(0), _end(0), _in(nullptr), _out(nullptr), _win(nullptr)
{
_in = static_cast<float*>(heap_caps_aligned_alloc(16u, SAMPLES, MALLOC_CAP_DEFAULT));
_out = static_cast<float*>(heap_caps_aligned_alloc(16u, SAMPLES, MALLOC_CAP_DEFAULT));
_win = static_cast<float*>(heap_caps_aligned_alloc(16u, SAMPLES, MALLOC_CAP_DEFAULT));
}

template<size_t SAMPLES>
FFTAnalyzer<SAMPLES>::~FFTAnalyzer()
{
heap_caps_free(_in);
heap_caps_free(_out);
heap_caps_free(_win);
}

template<size_t SAMPLES>
int FFTAnalyzer<SAMPLES>::begin(int16_t rate, const DynamicFilterConfig& config, size_t axis)
Expand Down
2 changes: 1 addition & 1 deletion lib/Espfc/src/Utils/Filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class DynamicFilterConfig {
int16_t q = 300;
int16_t min_freq = 80;
int16_t max_freq = 400;
static const int MIN_FREQ = 1000;
static constexpr int MIN_FREQ = 1000;
};

namespace Utils {
Expand Down
12 changes: 12 additions & 0 deletions lib/Espfc/src/Utils/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ namespace Utils {
class Logger
{
public:
Logger(): _buff(nullptr), _size(0), _tail(0) { }

~Logger()
{
if(!_buff) return;

delete[] _buff;
_buff = nullptr;
_size = 0;
_tail = 0;
}

int begin(size_t size = 1024)
{
_size = size;
Expand Down
6 changes: 3 additions & 3 deletions lib/Espfc/src/Utils/Storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class Storage
StorageResult save(const ModelConfig& config);

private:
static const uint8_t EEPROM_MAGIC = 0xA5;
static const uint8_t EEPROM_VERSION = 0x01;
static const size_t EEPROM_SIZE = 2048;
static constexpr uint8_t EEPROM_MAGIC = 0xA5;
static constexpr uint8_t EEPROM_VERSION = 0x01;
static constexpr size_t EEPROM_SIZE = 2048;
};

}
Expand Down
10 changes: 5 additions & 5 deletions partitions_4M_nota.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x5000,
otadata, data, ota, 0xe000, 0x2000,
app0, app, ota_0, 0x10000, 0x100000,
spiffs, data, spiffs, 0x110000,0x2E0000,
coredump, data, coredump,0x3F0000,0x10000,
nvs, data, nvs, 0x009000, 0x005000,
otadata, data, ota, 0x00e000, 0x002000,
app0, app, ota_0, 0x010000, 0x140000,
spiffs, data, spiffs, 0x150000, 0x2A0000,
coredump, data, coredump,0x3F0000, 0x010000,
Loading

0 comments on commit 0a1a53c

Please sign in to comment.