From 13910390699501049a0db150a99833f21034215e Mon Sep 17 00:00:00 2001 From: rtlopez Date: Sat, 23 Nov 2024 01:52:39 +0100 Subject: [PATCH] fix esc drivers and pgm imports --- lib/EscDriver/src/EscDriverEsp32c3.cpp | 35 +++++++++++++------------- lib/EscDriver/src/EscDriverEsp32c3.h | 22 ++++++++-------- lib/EscDriver/src/EscDriverEsp8266.cpp | 27 ++++++++++---------- lib/EscDriver/src/EscDriverEsp8266.h | 31 +++++++++++------------ lib/EscDriver/src/EscDriverRP2040.cpp | 11 ++++---- lib/EscDriver/src/EscDriverRP2040.h | 10 ++++---- lib/Espfc/src/Device/BaroDevice.cpp | 19 ++++++++++++++ lib/Espfc/src/Device/BaroDevice.h | 18 +++---------- lib/Espfc/src/Device/BusDevice.cpp | 19 ++++++++++++++ lib/Espfc/src/Device/BusDevice.h | 19 +++----------- lib/Espfc/src/Device/GyroDevice.cpp | 19 ++++++++++++++ lib/Espfc/src/Device/GyroDevice.h | 18 +++---------- lib/Espfc/src/Device/MagDevice.cpp | 19 ++++++++++++++ lib/Espfc/src/Device/MagDevice.h | 18 +++---------- 14 files changed, 156 insertions(+), 129 deletions(-) create mode 100644 lib/Espfc/src/Device/BaroDevice.cpp create mode 100644 lib/Espfc/src/Device/BusDevice.cpp create mode 100644 lib/Espfc/src/Device/GyroDevice.cpp create mode 100644 lib/Espfc/src/Device/MagDevice.cpp diff --git a/lib/EscDriver/src/EscDriverEsp32c3.cpp b/lib/EscDriver/src/EscDriverEsp32c3.cpp index 1e2d4e26..439b1041 100644 --- a/lib/EscDriver/src/EscDriverEsp32c3.cpp +++ b/lib/EscDriver/src/EscDriverEsp32c3.cpp @@ -1,6 +1,7 @@ #if defined(ESP32C3) #include "EscDriverEsp32c3.h" +#include #include #include @@ -18,12 +19,12 @@ void EscDriverEsp32c3::_isr_init(EscDriverTimer timer, void * driver) { timer_group_t group = (timer_group_t)timer; timer_config_t config = { - .alarm_en = TIMER_ALARM_EN, - .counter_en = TIMER_PAUSE, - .intr_type = TIMER_INTR_LEVEL, - .counter_dir = TIMER_COUNT_UP, - .auto_reload = TIMER_AUTORELOAD_DIS, - .divider = ESC_TIMER_DIVIDER, + .alarm_en = TIMER_ALARM_EN, + .counter_en = TIMER_PAUSE, + .intr_type = TIMER_INTR_LEVEL, + .counter_dir = TIMER_COUNT_UP, + .auto_reload = TIMER_AUTORELOAD_DIS, + .divider = ESC_TIMER_DIVIDER, }; timer_init(group, ESC_TIMER_IDX, &config); timer_set_counter_value(group, ESC_TIMER_IDX, 0); @@ -32,7 +33,7 @@ void EscDriverEsp32c3::_isr_init(EscDriverTimer timer, void * driver) timer_start(group, ESC_TIMER_IDX); } -bool EscDriverEsp32c3::_isr_wait(EscDriverTimer timer, const uint32_t ticks) +bool IRAM_ATTR EscDriverEsp32c3::_isr_wait(EscDriverTimer timer, const uint32_t ticks) { if(ticks >= TIMER_WAIT_EDGE) { // yield uint64_t value = timer_group_get_counter_value_in_isr((timer_group_t)timer, ESC_TIMER_IDX); @@ -53,7 +54,7 @@ bool EscDriverEsp32c3::_isr_wait(EscDriverTimer timer, const uint32_t ticks) } // run as soon as possible -void EscDriverEsp32c3::_isr_start(EscDriverTimer timer) +void IRAM_ATTR EscDriverEsp32c3::_isr_start(EscDriverTimer timer) { _isr_wait(timer, TIMER_WAIT_EDGE + 10); //timer_start((timer_group_t)timer, ESC_TIMER_IDX); @@ -65,7 +66,7 @@ void EscDriverEsp32c3::_isr_end(EscDriverTimer timer, void* p) timer_disable_intr((timer_group_t)timer, ESC_TIMER_IDX); } -int EscDriverEsp32c3::attach(size_t channel, int pin, int pulse) +int IRAM_ATTR EscDriverEsp32c3::attach(size_t channel, int pin, int pulse) { if(channel < 0 || channel >= ESC_CHANNEL_COUNT) return 0; _slots[channel].pin = pin; @@ -75,7 +76,7 @@ int EscDriverEsp32c3::attach(size_t channel, int pin, int pulse) return 1; } -int EscDriverEsp32c3::write(size_t channel, int pulse) +int IRAM_ATTR EscDriverEsp32c3::write(size_t channel, int pulse) { if(channel < 0 || channel >= ESC_CHANNEL_COUNT) return 0; _slots[channel].pulse = usToTicks(pulse); @@ -93,7 +94,7 @@ uint32_t EscDriverEsp32c3::telemetry(size_t channel) const return 0; } -void EscDriverEsp32c3::apply() +void IRAM_ATTR EscDriverEsp32c3::apply() { if(_protocol == ESC_PROTOCOL_DISABLED) return; if(_protocol >= ESC_PROTOCOL_DSHOT150) @@ -105,7 +106,7 @@ void EscDriverEsp32c3::apply() _isr_start(_timer); } -bool EscDriverEsp32c3::handle(void * p) +bool IRAM_ATTR EscDriverEsp32c3::handle(void * p) { // Time critical section EscDriver * instance = (EscDriver *)p; @@ -145,7 +146,7 @@ bool EscDriverEsp32c3::handle(void * p) return false; } -void EscDriverEsp32c3::commit() +void IRAM_ATTR EscDriverEsp32c3::commit() { Slot sorted[ESC_CHANNEL_COUNT]; std::copy(_slots, _slots + ESC_CHANNEL_COUNT, sorted); @@ -208,17 +209,17 @@ void EscDriverEsp32c3::commit() } } -uint32_t EscDriverEsp32c3::usToTicksReal(EscDriverTimer timer, uint32_t us) +uint32_t IRAM_ATTR EscDriverEsp32c3::usToTicksReal(EscDriverTimer timer, uint32_t us) { return (APB_CLK_FREQ / ESC_TIMER_DIVIDER / 1000000L) * us; } -int32_t EscDriverEsp32c3::minTicks(EscDriverTimer timer) +int32_t IRAM_ATTR EscDriverEsp32c3::minTicks(EscDriverTimer timer) { return 150L; } -uint32_t EscDriverEsp32c3::usToTicks(uint32_t us) +uint32_t IRAM_ATTR EscDriverEsp32c3::usToTicks(uint32_t us) { uint32_t ticks = 0; switch(_protocol) @@ -312,7 +313,7 @@ static inline void dshotDelay(int delay) while(delay--) __asm__ __volatile__ ("nop"); } -void EscDriverEsp32c3::dshotWrite() +void IRAM_ATTR EscDriverEsp32c3::dshotWrite() { // zero mask arrays mask_t * sm = dshotSetMask; diff --git a/lib/EscDriver/src/EscDriverEsp32c3.h b/lib/EscDriver/src/EscDriverEsp32c3.h index 93134dd2..325ad9b3 100644 --- a/lib/EscDriver/src/EscDriverEsp32c3.h +++ b/lib/EscDriver/src/EscDriverEsp32c3.h @@ -45,23 +45,23 @@ class EscDriverEsp32c3: public EscDriverBase int begin(const EscConfig& conf); void end(); - int attach(size_t channel, int pin, int pulse) IRAM_ATTR; - int write(size_t channel, int pulse) IRAM_ATTR; - void apply() IRAM_ATTR; + int attach(size_t channel, int pin, int pulse); + int write(size_t channel, int pulse); + void apply(); int pin(size_t channel) const; uint32_t telemetry(size_t channel) const; - static bool handle(void * p) IRAM_ATTR; + static bool handle(void * p); private: - void commit() IRAM_ATTR; - uint32_t usToTicks(uint32_t us) IRAM_ATTR; - uint32_t usToTicksReal(EscDriverTimer timer, uint32_t us) IRAM_ATTR; - int32_t minTicks(EscDriverTimer timer) IRAM_ATTR; - void dshotWrite() IRAM_ATTR; + void commit(); + uint32_t usToTicks(uint32_t us); + uint32_t usToTicksReal(EscDriverTimer timer, uint32_t us); + int32_t minTicks(EscDriverTimer timer); + void dshotWrite(); static void _isr_init(EscDriverTimer timer, void * driver); - static bool _isr_wait(EscDriverTimer timer, const uint32_t ticks) IRAM_ATTR; - static void _isr_start(EscDriverTimer timer) IRAM_ATTR; + static bool _isr_wait(EscDriverTimer timer, const uint32_t ticks); + static void _isr_start(EscDriverTimer timer); static void _isr_end(EscDriverTimer timer, void* p); volatile bool _busy; diff --git a/lib/EscDriver/src/EscDriverEsp8266.cpp b/lib/EscDriver/src/EscDriverEsp8266.cpp index 06ec9448..47684197 100644 --- a/lib/EscDriver/src/EscDriverEsp8266.cpp +++ b/lib/EscDriver/src/EscDriverEsp8266.cpp @@ -1,6 +1,7 @@ #if defined(ESP8266) #include "EscDriverEsp8266.h" +#include #include #include @@ -40,7 +41,7 @@ void EscDriverEsp8266::_isr_init(EscDriverTimer timer, void * driver) } } -void EscDriverEsp8266::_isr_begin(EscDriverTimer timer) +void IRAM_ATTR EscDriverEsp8266::_isr_begin(EscDriverTimer timer) { switch(timer) { @@ -62,7 +63,7 @@ void EscDriverEsp8266::_isr_begin(EscDriverTimer timer) #define TIMER1_WAIT_EDGE 140UL #define TIMER1_WAIT_COMP 115UL -bool EscDriverEsp8266::_isr_wait(EscDriverTimer timer, const uint32_t ticks) +bool IRAM_ATTR EscDriverEsp8266::_isr_wait(EscDriverTimer timer, const uint32_t ticks) { switch(timer) { @@ -103,7 +104,7 @@ bool EscDriverEsp8266::_isr_wait(EscDriverTimer timer, const uint32_t ticks) } // run as soon as possible -void EscDriverEsp8266::_isr_start(EscDriverTimer timer) +void IRAM_ATTR EscDriverEsp8266::_isr_start(EscDriverTimer timer) { switch(timer) { @@ -122,7 +123,7 @@ void EscDriverEsp8266::_isr_start(EscDriverTimer timer) } } -void EscDriverEsp8266::_isr_reboot(void* p) +void IRAM_ATTR EscDriverEsp8266::_isr_reboot(void* p) { EscDriver* d = (EscDriver*)p; _isr_begin(d->_timer); @@ -152,7 +153,7 @@ void EscDriverEsp8266::_isr_end(EscDriverTimer timer, void* p) } } -int EscDriverEsp8266::attach(size_t channel, int pin, int pulse) +int IRAM_ATTR EscDriverEsp8266::attach(size_t channel, int pin, int pulse) { if(channel < 0 || channel >= ESC_CHANNEL_COUNT) return 0; _slots[channel].pin = pin; @@ -173,14 +174,14 @@ uint32_t EscDriverEsp8266::telemetry(size_t channel) const return 0; } -int EscDriverEsp8266::write(size_t channel, int pulse) +int IRAM_ATTR EscDriverEsp8266::write(size_t channel, int pulse) { if(channel < 0 || channel >= ESC_CHANNEL_COUNT) return 0; _slots[channel].pulse = usToTicks(pulse); return 1; } -void EscDriverEsp8266::apply() +void IRAM_ATTR EscDriverEsp8266::apply() { if(_protocol == ESC_PROTOCOL_DISABLED) return; if(_protocol >= ESC_PROTOCOL_DSHOT150) @@ -192,7 +193,7 @@ void EscDriverEsp8266::apply() _isr_start(_timer); } -void EscDriverEsp8266::handle(void * p, void * x) +void IRAM_ATTR EscDriverEsp8266::handle(void * p, void * x) { // Time critical section EscDriver * instance = (EscDriver *)p; @@ -234,7 +235,7 @@ void EscDriverEsp8266::handle(void * p, void * x) } } -void EscDriverEsp8266::commit() +void IRAM_ATTR EscDriverEsp8266::commit() { Slot sorted[ESC_CHANNEL_COUNT]; std::copy(_slots, _slots + ESC_CHANNEL_COUNT, sorted); @@ -296,7 +297,7 @@ void EscDriverEsp8266::commit() } } -uint32_t EscDriverEsp8266::usToTicksReal(EscDriverTimer timer, uint32_t us) +uint32_t IRAM_ATTR EscDriverEsp8266::usToTicksReal(EscDriverTimer timer, uint32_t us) { switch(timer) { @@ -307,7 +308,7 @@ uint32_t EscDriverEsp8266::usToTicksReal(EscDriverTimer timer, uint32_t us) } } -int32_t EscDriverEsp8266::minTicks(EscDriverTimer timer) +int32_t IRAM_ATTR EscDriverEsp8266::minTicks(EscDriverTimer timer) { switch(timer) { @@ -318,7 +319,7 @@ int32_t EscDriverEsp8266::minTicks(EscDriverTimer timer) } } -uint32_t EscDriverEsp8266::usToTicks(uint32_t us) +uint32_t IRAM_ATTR EscDriverEsp8266::usToTicks(uint32_t us) { uint32_t ticks = 0; switch(_protocol) @@ -415,7 +416,7 @@ static IRAM_ATTR void dshotDelay(int delay) while(delay--) __asm__ __volatile__ ("nop"); } -void EscDriverEsp8266::dshotWrite() +void IRAM_ATTR EscDriverEsp8266::dshotWrite() { // zero mask arrays mask_t smask[DSHOT_BIT_COUNT]; diff --git a/lib/EscDriver/src/EscDriverEsp8266.h b/lib/EscDriver/src/EscDriverEsp8266.h index b0bc9c6c..81c449d0 100644 --- a/lib/EscDriver/src/EscDriverEsp8266.h +++ b/lib/EscDriver/src/EscDriverEsp8266.h @@ -1,5 +1,4 @@ -#ifndef _ESC_DRIVER_ESP8266_H_ -#define _ESC_DRIVER_ESP8266_H_ +#pragma once #if defined(ESP8266) @@ -52,25 +51,25 @@ class EscDriverEsp8266: public EscDriverBase int begin(const EscConfig& conf); void end(); - int attach(size_t channel, int pin, int pulse) IRAM_ATTR; - int write(size_t channel, int pulse) IRAM_ATTR; - void apply() IRAM_ATTR; + int attach(size_t channel, int pin, int pulse); + int write(size_t channel, int pulse); + void apply(); int pin(size_t channel) const; uint32_t telemetry(size_t channel) const; - static void handle(void * p, void * x) IRAM_ATTR; + static void handle(void * p, void * x); private: - void commit() IRAM_ATTR; - uint32_t usToTicks(uint32_t us) IRAM_ATTR; - uint32_t usToTicksReal(EscDriverTimer timer, uint32_t us) IRAM_ATTR; - int32_t minTicks(EscDriverTimer timer) IRAM_ATTR; - void dshotWrite() IRAM_ATTR; + void commit(); + uint32_t usToTicks(uint32_t us); + uint32_t usToTicksReal(EscDriverTimer timer, uint32_t us); + int32_t minTicks(EscDriverTimer timer); + void dshotWrite(); static void _isr_init(EscDriverTimer timer, void * driver); - static void _isr_begin(EscDriverTimer timer) IRAM_ATTR; - static bool _isr_wait(EscDriverTimer timer, const uint32_t ticks) IRAM_ATTR; - static void _isr_start(EscDriverTimer timer) IRAM_ATTR; - static void _isr_reboot(void* p) IRAM_ATTR; + static void _isr_begin(EscDriverTimer timer); + static bool _isr_wait(EscDriverTimer timer, const uint32_t ticks); + static void _isr_start(EscDriverTimer timer); + static void _isr_reboot(void* p); static void _isr_end(EscDriverTimer timer, void* p); volatile bool _busy; @@ -94,5 +93,3 @@ class EscDriverEsp8266: public EscDriverBase }; #endif // ESP8266 - -#endif diff --git a/lib/EscDriver/src/EscDriverRP2040.cpp b/lib/EscDriver/src/EscDriverRP2040.cpp index fbc13fb3..6b9ae673 100644 --- a/lib/EscDriver/src/EscDriverRP2040.cpp +++ b/lib/EscDriver/src/EscDriverRP2040.cpp @@ -1,6 +1,7 @@ #if defined(ARCH_RP2040) #include "EscDriverRP2040.h" +#include #include #include #include @@ -15,7 +16,7 @@ #define DSHOT150_T1H 4666u #define DSHOT150_T 6666u -int EscDriverRP2040::attach(size_t channel, int pin, int pulse) +int IRAM_ATTR EscDriverRP2040::attach(size_t channel, int pin, int pulse) { if(channel >= ESC_CHANNEL_COUNT) return 0; if(pin > 28) return 0; @@ -96,14 +97,14 @@ bool EscDriverRP2040::isSliceDriven(int slice) return false; } -int EscDriverRP2040::write(size_t channel, int pulse) +int IRAM_ATTR EscDriverRP2040::write(size_t channel, int pulse) { if(channel >= ESC_CHANNEL_COUNT) return 0; _slots[channel].pulse = usToTicks(pulse); return 1; } -void EscDriverRP2040::apply() +void IRAM_ATTR EscDriverRP2040::apply() { if(_protocol >= ESC_PROTOCOL_DSHOT150 && _protocol <= ESC_PROTOCOL_DSHOT600) { @@ -117,7 +118,7 @@ void EscDriverRP2040::apply() } } -uint32_t EscDriverRP2040::usToTicks(uint32_t us) +uint32_t IRAM_ATTR EscDriverRP2040::usToTicks(uint32_t us) { uint32_t ticks = 0; switch(_protocol) @@ -146,7 +147,7 @@ uint32_t EscDriverRP2040::usToTicks(uint32_t us) return ticks; } -uint32_t EscDriverRP2040::usToTicksReal(uint32_t us) +uint32_t IRAM_ATTR EscDriverRP2040::usToTicksReal(uint32_t us) { uint64_t t = (uint64_t)us * (F_CPU / _divider); return t / 1000000ul; diff --git a/lib/EscDriver/src/EscDriverRP2040.h b/lib/EscDriver/src/EscDriverRP2040.h index 75abfef3..bdbe9cc9 100644 --- a/lib/EscDriver/src/EscDriverRP2040.h +++ b/lib/EscDriver/src/EscDriverRP2040.h @@ -40,15 +40,15 @@ class EscDriverRP2040: public EscDriverBase int begin(const EscConfig& conf); void end(); - int attach(size_t channel, int pin, int pulse) IRAM_ATTR; - int write(size_t channel, int pulse) IRAM_ATTR; + int attach(size_t channel, int pin, int pulse); + int write(size_t channel, int pulse); int pin(size_t channel) const; uint32_t telemetry(size_t channel) const; - void apply() IRAM_ATTR; + void apply(); private: - uint32_t usToTicks(uint32_t us) IRAM_ATTR; - uint32_t usToTicksReal(uint32_t us) IRAM_ATTR; + uint32_t usToTicks(uint32_t us); + uint32_t usToTicksReal(uint32_t us); uint32_t nsToDshotTicks(uint32_t ns); void dshotWriteDMA(); bool isSliceDriven(int slice); diff --git a/lib/Espfc/src/Device/BaroDevice.cpp b/lib/Espfc/src/Device/BaroDevice.cpp new file mode 100644 index 00000000..bcfcf2ad --- /dev/null +++ b/lib/Espfc/src/Device/BaroDevice.cpp @@ -0,0 +1,19 @@ +#include "Device/BaroDevice.h" +#include "Hal/Pgm.h" +#include + +namespace Espfc::Device { + +const char ** BaroDevice::getNames() +{ + static const char* devChoices[] = { PSTR("AUTO"), PSTR("NONE"), PSTR("BMP085"), PSTR("MS5611"), PSTR("BMP280"), PSTR("SPL06-001"), NULL }; + return devChoices; +} + +const char * BaroDevice::getName(DeviceType type) +{ + if(type >= BARO_MAX) return PSTR("?"); + return getNames()[type]; +} + +} diff --git a/lib/Espfc/src/Device/BaroDevice.h b/lib/Espfc/src/Device/BaroDevice.h index e94f327a..f3227796 100644 --- a/lib/Espfc/src/Device/BaroDevice.h +++ b/lib/Espfc/src/Device/BaroDevice.h @@ -1,5 +1,4 @@ -#ifndef _ESPFC_DEVICE_BARO_DEVICE_H_ -#define _ESPFC_DEVICE_BARO_DEVICE_H_ +#pragma once #include "BusDevice.h" #include "BusAwareDevice.h" @@ -40,21 +39,10 @@ class BaroDevice: public BusAwareDevice virtual bool testConnection() = 0; - static const char ** getNames() - { - static const char* devChoices[] = { PSTR("AUTO"), PSTR("NONE"), PSTR("BMP085"), PSTR("MS5611"), PSTR("BMP280"), PSTR("SPL06-001"), NULL }; - return devChoices; - } - - static const char * getName(DeviceType type) - { - if(type >= BARO_MAX) return PSTR("?"); - return getNames()[type]; - } + static const char ** getNames(); + static const char * getName(DeviceType type); }; } } - -#endif diff --git a/lib/Espfc/src/Device/BusDevice.cpp b/lib/Espfc/src/Device/BusDevice.cpp new file mode 100644 index 00000000..a9ca598d --- /dev/null +++ b/lib/Espfc/src/Device/BusDevice.cpp @@ -0,0 +1,19 @@ +#include "Device/BusDevice.h" +#include "Hal/Pgm.h" +#include + +namespace Espfc::Device { + +const char ** BusDevice::getNames() +{ + static const char* busDevChoices[] = { PSTR("NONE"), PSTR("AUTO"), PSTR("I2C"), PSTR("SPI"), PSTR("SLV"), NULL }; + return busDevChoices; +} + +const char * BusDevice::getName(BusType type) +{ + if(type >= BUS_MAX) return PSTR("?"); + return getNames()[type]; +} + +} diff --git a/lib/Espfc/src/Device/BusDevice.h b/lib/Espfc/src/Device/BusDevice.h index 1f3a38cb..49cc0c19 100644 --- a/lib/Espfc/src/Device/BusDevice.h +++ b/lib/Espfc/src/Device/BusDevice.h @@ -1,9 +1,7 @@ -#ifndef _ESPFC_DEVICE_BUSDEVICE_H_ -#define _ESPFC_DEVICE_BUSDEVICE_H_ +#pragma once #include #include -#include "Hal/Pgm.h" #include "Utils/Bits.hpp" #define ESPFC_BUS_TIMEOUT 100 @@ -126,17 +124,8 @@ class BusDevice } } - static const char ** getNames() - { - static const char* busDevChoices[] = { PSTR("NONE"), PSTR("AUTO"), PSTR("I2C"), PSTR("SPI"), PSTR("SLV"), NULL }; - return busDevChoices; - } - - static const char * getName(BusType type) - { - if(type >= BUS_MAX) return PSTR("?"); - return getNames()[type]; - } + static const char ** getNames(); + static const char * getName(BusType type); std::function onError; @@ -147,5 +136,3 @@ class BusDevice } } - -#endif diff --git a/lib/Espfc/src/Device/GyroDevice.cpp b/lib/Espfc/src/Device/GyroDevice.cpp new file mode 100644 index 00000000..e56a8a52 --- /dev/null +++ b/lib/Espfc/src/Device/GyroDevice.cpp @@ -0,0 +1,19 @@ +#include "Device/GyroDevice.h" +#include "Hal/Pgm.h" +#include + +namespace Espfc::Device { + +const char ** GyroDevice::getNames() +{ + static const char* devChoices[] = { PSTR("AUTO"), PSTR("NONE"), PSTR("MPU6000"), PSTR("MPU6050"), PSTR("MPU6500"), PSTR("MPU9250"), PSTR("LSM6DSO"), PSTR("ICM20602"),PSTR("BMI160"), NULL }; + return devChoices; +} + +const char * GyroDevice::getName(DeviceType type) +{ + if(type >= GYRO_MAX) return PSTR("?"); + return getNames()[type]; +} + +} diff --git a/lib/Espfc/src/Device/GyroDevice.h b/lib/Espfc/src/Device/GyroDevice.h index 1abf53e9..0f49d5ee 100644 --- a/lib/Espfc/src/Device/GyroDevice.h +++ b/lib/Espfc/src/Device/GyroDevice.h @@ -1,5 +1,4 @@ -#ifndef _ESPFC_DEVICE_GYRO_DEVICE_H_ -#define _ESPFC_DEVICE_GYRO_DEVICE_H_ +#pragma once #include #include "BusDevice.h" @@ -41,21 +40,10 @@ class GyroDevice: public BusAwareDevice virtual bool testConnection() = 0; - static const char ** getNames() - { - static const char* devChoices[] = { PSTR("AUTO"), PSTR("NONE"), PSTR("MPU6000"), PSTR("MPU6050"), PSTR("MPU6500"), PSTR("MPU9250"), PSTR("LSM6DSO"), PSTR("ICM20602"),PSTR("BMI160"), NULL }; - return devChoices; - } - - static const char * getName(DeviceType type) - { - if(type >= GYRO_MAX) return PSTR("?"); - return getNames()[type]; - } + static const char ** getNames(); + static const char * getName(DeviceType type); }; } } - -#endif diff --git a/lib/Espfc/src/Device/MagDevice.cpp b/lib/Espfc/src/Device/MagDevice.cpp new file mode 100644 index 00000000..63a20384 --- /dev/null +++ b/lib/Espfc/src/Device/MagDevice.cpp @@ -0,0 +1,19 @@ +#include "Device/MagDevice.h" +#include "Hal/Pgm.h" +#include + +namespace Espfc::Device { + +const char ** MagDevice::getNames() +{ + static const char* devChoices[] = { PSTR("AUTO"), PSTR("NONE"), PSTR("HMC5883L"), PSTR("AK8975"), PSTR("AK8963"), PSTR("QMC5883L"),NULL }; + return devChoices; +} + +const char * MagDevice::getName(DeviceType type) +{ + if(type >= MAG_MAX) return PSTR("?"); + return getNames()[type]; +} + +} \ No newline at end of file diff --git a/lib/Espfc/src/Device/MagDevice.h b/lib/Espfc/src/Device/MagDevice.h index 2c77bef3..6bb5823b 100644 --- a/lib/Espfc/src/Device/MagDevice.h +++ b/lib/Espfc/src/Device/MagDevice.h @@ -1,5 +1,4 @@ -#ifndef _ESPFC_DEVICE_MAG_DEVICE_H_ -#define _ESPFC_DEVICE_MAG_DEVICE_H_ +#pragma once #include "helper_3dmath.h" #include "BusAwareDevice.h" @@ -34,21 +33,10 @@ class MagDevice: public BusAwareDevice virtual bool testConnection() = 0; - static const char ** getNames() - { - static const char* devChoices[] = { PSTR("AUTO"), PSTR("NONE"), PSTR("HMC5883L"), PSTR("AK8975"), PSTR("AK8963"), PSTR("QMC5883L"),NULL }; - return devChoices; - } - - static const char * getName(DeviceType type) - { - if(type >= MAG_MAX) return PSTR("?"); - return getNames()[type]; - } + static const char ** getNames(); + static const char * getName(DeviceType type); }; } } - -#endif