From 07104eb34789a85934348f2324a93779e8762e1b Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 19 Nov 2021 12:40:15 +0200 Subject: [PATCH 01/20] Declare header files for PlatformIO --- library.json | 1 + 1 file changed, 1 insertion(+) diff --git a/library.json b/library.json index b547977..61e71e6 100644 --- a/library.json +++ b/library.json @@ -25,6 +25,7 @@ "version": "1.2.6", "framework": "arduino", "platforms": "espressif32", + "headers": "ESP32-Chimera-Core.h", "build": { "libArchive": false } From c313c5cb6ebd4481cd69d0c98dc0cab33071fbaf Mon Sep 17 00:00:00 2001 From: tobozo Date: Fri, 19 Nov 2021 14:25:48 +0100 Subject: [PATCH 02/20] I2CUtils + MPU tweaks --- src/Config.h | 4 + src/ESP32-Chimera-Core.cpp | 11 +- src/ESP32-Chimera-Core.h | 37 +- src/M5Display.cpp | 11 +- src/M5Display.h | 2 +- src/drivers/common/I2C/I2CUtil.cpp | 153 ++++-- src/drivers/common/I2C/I2CUtil.h | 18 +- src/drivers/common/IP5306/Power.cpp | 73 ++- src/drivers/common/IP5306/Power.h | 2 + src/drivers/common/MPU6886/MPU6886.cpp | 88 ++-- src/drivers/common/MPU6886/MPU6886.h | 100 ++-- src/drivers/common/MPU9250/MPU9250.cpp | 6 +- src/drivers/common/MPU9250/MPU9250.h | 473 +++++++++--------- src/drivers/common/RTC_PCF8563/pcf8563.h | 1 + src/gitTagVersion.h | 2 +- src/{helpers => utility}/M5Timer.cpp | 0 src/{helpers => utility}/M5Timer.h | 0 src/{helpers => utility}/Memory.h | 0 .../ScreenShotService/BMP/TinyBMPEncoder.cpp | 0 .../ScreenShotService/BMP/TinyBMPEncoder.h | 0 .../ScreenShotService/GIF/TinyGIFEncoder.cpp | 0 .../ScreenShotService/GIF/TinyGIFEncoder.h | 0 .../ScreenShotService/JPG/TinyJPEGEncoder.cpp | 0 .../ScreenShotService/JPG/TinyJPEGEncoder.h | 0 .../ScreenShotService/PNG/FatPNGEncoder.cpp | 0 .../ScreenShotService/PNG/FatPNGEncoder.h | 0 .../ScreenShotService/ScreenShot.cpp | 0 .../ScreenShotService/ScreenShot.h | 0 src/{helpers => utility}/TouchButton.cpp | 0 src/{helpers => utility}/TouchButton.h | 0 .../quaternionFilters.cpp | 0 src/{helpers => utility}/quaternionFilters.h | 0 32 files changed, 562 insertions(+), 419 deletions(-) rename src/{helpers => utility}/M5Timer.cpp (100%) rename src/{helpers => utility}/M5Timer.h (100%) rename src/{helpers => utility}/Memory.h (100%) rename src/{helpers => utility}/ScreenShotService/BMP/TinyBMPEncoder.cpp (100%) rename src/{helpers => utility}/ScreenShotService/BMP/TinyBMPEncoder.h (100%) rename src/{helpers => utility}/ScreenShotService/GIF/TinyGIFEncoder.cpp (100%) rename src/{helpers => utility}/ScreenShotService/GIF/TinyGIFEncoder.h (100%) rename src/{helpers => utility}/ScreenShotService/JPG/TinyJPEGEncoder.cpp (100%) rename src/{helpers => utility}/ScreenShotService/JPG/TinyJPEGEncoder.h (100%) rename src/{helpers => utility}/ScreenShotService/PNG/FatPNGEncoder.cpp (100%) rename src/{helpers => utility}/ScreenShotService/PNG/FatPNGEncoder.h (100%) rename src/{helpers => utility}/ScreenShotService/ScreenShot.cpp (100%) rename src/{helpers => utility}/ScreenShotService/ScreenShot.h (100%) rename src/{helpers => utility}/TouchButton.cpp (100%) rename src/{helpers => utility}/TouchButton.h (100%) rename src/{helpers => utility}/quaternionFilters.cpp (100%) rename src/{helpers => utility}/quaternionFilters.h (100%) diff --git a/src/Config.h b/src/Config.h index fe89c75..8e27b6f 100644 --- a/src/Config.h +++ b/src/Config.h @@ -389,6 +389,10 @@ #define TFCARD_SPI_FREQ 25000000 #endif +#if defined M5STACK_MPU6886 && !defined HAS_MPU6886 + #define HAS_MPU6886 +#endif + #if defined ESP_ARDUINO_VERSION_VAL #if __has_include("core_version.h") // for platformio diff --git a/src/ESP32-Chimera-Core.cpp b/src/ESP32-Chimera-Core.cpp index 05a96fe..c0d0fbc 100644 --- a/src/ESP32-Chimera-Core.cpp +++ b/src/ESP32-Chimera-Core.cpp @@ -9,7 +9,6 @@ M5Stack::M5Stack() : isInited(0) } - void M5Stack::begin(bool LCDEnable, bool SDEnable, bool SerialEnable, bool I2CEnable, bool ScreenShotEnable) { // Correct init once @@ -120,7 +119,7 @@ void M5Stack::begin(bool LCDEnable, bool SDEnable, bool SerialEnable, bool I2CEn #if !defined( ARDUINO_M5STACK_Core2 ) // need I2C init for RTC ? if (I2CEnable == true) { - log_d("Enabling I2C"); + log_d("Will start I2C"); if (M5.Lcd.getBoard() != lgfx::board_M5StackCore2) { I2C.begin(SDA, SCL); } else { @@ -129,10 +128,6 @@ void M5Stack::begin(bool LCDEnable, bool SDEnable, bool SerialEnable, bool I2CEn } #endif - if (SerialEnable == true) { - Serial.println("OK"); - } - #if defined HAS_BM8563 Rtc.begin(); #elif defined( HAS_PCF8563 ) @@ -142,6 +137,10 @@ void M5Stack::begin(bool LCDEnable, bool SDEnable, bool SerialEnable, bool I2CEn #if defined HAS_RTC setSystemTimeFromRtc(); #endif + + if (SerialEnable == true) { + Serial.println("ESP32-Chimera-Core started"); + } } diff --git a/src/ESP32-Chimera-Core.h b/src/ESP32-Chimera-Core.h index 2027ebd..28b77cb 100644 --- a/src/ESP32-Chimera-Core.h +++ b/src/ESP32-Chimera-Core.h @@ -127,14 +127,14 @@ #include "M5Display.h" - #include "helpers/Memory.h" - #include "helpers/ScreenShotService/ScreenShot.h" // ScreenShot Service + #include "utility/Memory.h" + #include "utility/ScreenShotService/ScreenShot.h" // ScreenShot Service #include "drivers/common/Button/Button.h" // BtnA/BtnB/BtnC Support #include "drivers/common/I2C/I2CUtil.h" // I2C Scanner #include "drivers/common/NVS/NVSUtils.h" // NVS Utilities #if defined HAS_TOUCH - #include "helpers/TouchButton.h" + #include "utility/TouchButton.h" #endif #if defined HAS_SPEAKER @@ -181,7 +181,17 @@ #endif #if defined( ARDUINO_M5Stack_Core_ESP32 ) || defined( ARDUINO_M5STACK_FIRE) // m5stack classic/fire - #if defined HAS_MPU9250 + #if defined HAS_MPU6886 + #define HAS_PRIMARY_IMU + #define PRIMARY_IMU MPU6886 + #define PRIMARY_IMU_ARG &Wire + #if defined HAS_MPU9250 + #pragma message "Enabling secondary IMU (MPU9250)" + #define HAS_SECONDARY_IMU + #define SECONDARY_IMU MPU9250 + #define SECONDARY_IMU_ARG &I2C + #endif + #elif defined HAS_MPU9250 #define HAS_PRIMARY_IMU #define PRIMARY_IMU MPU9250 #define PRIMARY_IMU_ARG &I2C @@ -189,15 +199,19 @@ #endif #if defined HAS_MPU6886 - #define HAS_PRIMARY_IMU - #define PRIMARY_IMU MPU6886 - #define PRIMARY_IMU_ARG + #if !defined HAS_PRIMARY_IMU + #define HAS_PRIMARY_IMU + #define PRIMARY_IMU MPU6886 + #define PRIMARY_IMU_ARG &I2C + #endif // allow secondary MPU #if defined HAS_MPU9250 - #warning "Enabling secondary IMU (MPU9250)" - #define HAS_SECONDARY_IMU - #define SECONDARY_IMU MPU9250 - #define SECONDARY_IMU_ARG &I2C + #if !defined HAS_SECONDARY_IMU + #pragma message "Enabling secondary IMU (MPU9250)" + #define HAS_SECONDARY_IMU + #define SECONDARY_IMU MPU9250 + #define SECONDARY_IMU_ARG &I2C + #endif #endif #endif @@ -220,6 +234,7 @@ ScreenShotService ScreenShot; // ScreenShots ! NVSUtils NVS; // NVS Utilities I2CUtil I2C = I2CUtil(); // I2C Scanner && Twatch I2C bus + //I2CUtil I2C = I2CUtil_Core; Button BtnA = Button(BUTTON_A_PIN, true, DEBOUNCE_MS); Button BtnB = Button(BUTTON_B_PIN, true, DEBOUNCE_MS); Button BtnC = Button(BUTTON_C_PIN, true, DEBOUNCE_MS); diff --git a/src/M5Display.cpp b/src/M5Display.cpp index 3e5d54a..bfe1cca 100644 --- a/src/M5Display.cpp +++ b/src/M5Display.cpp @@ -1,7 +1,14 @@ #include "M5Display.h" -void M5Display::progressBar(int x, int y, int w, int h, uint8_t val, uint16_t color) { +void M5Display::progressBar(int x, int y, int w, int h, uint8_t val, uint16_t color, uint16_t bgcolor) { drawRect(x, y, w, h, color); if( val>100) val = 100; - fillRect(x + 1, y + 1, w * (((float)val) / 100.0), h - 1, color); + if( val==0 ) { + fillRect(x+1, y+1, w-2, h-2, bgcolor); + } else { + int fillw = (w * (((float)val) / 100.0)) -2; + fillRect(x + 1, y + 1, fillw, h - 2, color); + fillRect(x + 1, y + 1 + fillw, w-fillw, h - 2, bgcolor); + } + } diff --git a/src/M5Display.h b/src/M5Display.h index 1c1629e..32c81f1 100644 --- a/src/M5Display.h +++ b/src/M5Display.h @@ -42,7 +42,7 @@ class M5Display : public TFT_eSPI { void display() {} - void progressBar(int x, int y, int w, int h, uint8_t val, uint16_t color=0x09F1 ); + void progressBar(int x, int y, int w, int h, uint8_t val, uint16_t color=0x09F1, uint16_t bgcolor=0x0000 ); const uint32_t &textcolor = _text_style.fore_rgb888; const uint32_t &textbgcolor = _text_style.back_rgb888; diff --git a/src/drivers/common/I2C/I2CUtil.cpp b/src/drivers/common/I2C/I2CUtil.cpp index af5ef9f..a8f59ee 100644 --- a/src/drivers/common/I2C/I2CUtil.cpp +++ b/src/drivers/common/I2C/I2CUtil.cpp @@ -1,26 +1,77 @@ #include "I2CUtil.h" -I2CUtil::I2CUtil() { + +bool I2CUtil::begin( signed char sdaPin, signed char sclPin, TwoWire *i2cPort ) +{ + if( sdaPin != _sdaPin || sclPin != _sclPin ) { + log_d("New I2C pins Context (old=%d/%d, new=%d/%d)", _sdaPin, _sclPin, sdaPin, sclPin ); + _begun = false; + } + if( i2cPort != nullptr ) { + if( _i2cPort != i2cPort ) { + log_d("New I2C port Context"); + _begun = false; + _i2cPort = i2cPort; + } + } + if( _i2cPort == nullptr ) { + log_e("Can't start I2CUtils without proper I2C Port"); + return false; + } + if( _begun ) { + log_w("Skipping I2C start (already started) on %s with SDA/SCL: %d/%d", i2cPort == &Wire?"Wire":"Wire1", _sdaPin, _sclPin ); + return true; + } + _sdaPin = sdaPin; + _sclPin = sclPin; + bool ret = _i2cPort->begin( _sdaPin, _sclPin ); + uint32_t currentClockSpeed = _i2cPort->getClock(); + bool wire_started = currentClockSpeed > 0; + + if( !wire_started ) { + log_e("Failed to get freq from Wire, aborting"); + return false; + } + + _lastclockspeed = currentClockSpeed; + if( _clockspeed == 0 ) { + _clockspeed = currentClockSpeed; // inherit clock speed + } + + _i2cPort->setClock( _clockspeed ); + + log_d("Begin I2C %s on %s with SDA/SCL: %d/%d at %d Hz", ret?"SUCCESS":"FAIL", _i2cPort == &Wire?"Wire":"Wire1", _sdaPin, _sclPin, _clockspeed ); + if( ret ) _begun = true; + return ret; } -bool I2CUtil::begin( signed char sdaPin, signed char sclPin ) +void I2CUtil::checkFreq( bool unset ) { - return Wire.begin( sdaPin, sclPin ); + uint32_t currentClockSpeed = _i2cPort->getClock(); + if( unset ) { // restore speed + if( currentClockSpeed == _lastclockspeed ) return; + //log_d("Restoring freq from %d to %d", currentClockSpeed, _lastclockspeed ); + _i2cPort->setClock( _lastclockspeed ); + } else { + if( currentClockSpeed == _clockspeed ) return; + log_d("Setting freq to %d (was: %d)", _clockspeed, currentClockSpeed ); + _lastclockspeed = currentClockSpeed; + _i2cPort->setClock( _clockspeed ); + } } - bool I2CUtil::writeCommand( unsigned char i2c_addr, unsigned char reg ) { bool res = false; - - Wire.beginTransmission(i2c_addr); - Wire.write(reg); - res = (Wire.endTransmission() == 0); + checkFreq(false); + _i2cPort->beginTransmission(i2c_addr); + _i2cPort->write(reg); + res = (_i2cPort->endTransmission() == 0); log_d("send to 0x%02x [0x%02x] result:%s", i2c_addr, reg, res ? "OK" : "NG"); - + checkFreq(true); return res; } @@ -29,12 +80,12 @@ bool I2CUtil::writeCommand( unsigned char i2c_addr, unsigned char reg ) bool I2CUtil::writeByte( unsigned char i2c_addr, unsigned char reg, unsigned char data ) { bool res = false; - - Wire.beginTransmission(i2c_addr); - Wire.write(reg); - Wire.write(data); - res = (Wire.endTransmission() == 0); - + checkFreq(false); + _i2cPort->beginTransmission(i2c_addr); + _i2cPort->write(reg); + _i2cPort->write(data); + res = (_i2cPort->endTransmission() == 0); + checkFreq(true); log_d("send to 0x%02x [0x%2x] data=0x%02x result:%s", i2c_addr, reg, data, res ? "OK" : "NG"); return res; @@ -45,18 +96,18 @@ bool I2CUtil::writeByte( unsigned char i2c_addr, unsigned char reg, unsigned cha bool I2CUtil::writeBytes( unsigned char i2c_addr, unsigned char reg, unsigned char *data, unsigned char length ) { bool res = false; - - Wire.beginTransmission(i2c_addr); - Wire.write(reg); + checkFreq(false); + _i2cPort->beginTransmission(i2c_addr); + _i2cPort->write(reg); for(int i = 0; i < length; i++) { - Wire.write(*(data+i)); + _i2cPort->write(*(data+i)); log_v("sent 1 byte (0x%2x) to 0x%02x [0x%02x]", *(data+i), i2c_addr, reg); } - res = Wire.endTransmission() == 0; + res = _i2cPort->endTransmission() == 0; log_d("sent to 0x%02x [0x%02x], result:%s", i2c_addr,reg, res ? "OK" : "NG"); - + checkFreq(true); return res; } @@ -65,17 +116,17 @@ bool I2CUtil::writeBytes( unsigned char i2c_addr, unsigned char reg, unsigned ch bool I2CUtil::readByte( unsigned char i2c_addr, unsigned char *buf ) { log_v("read 1 byte from 0x%02x receive=", i2c_addr); - - if ( Wire.requestFrom(i2c_addr, (unsigned char)1)) { - *buf = Wire.read(); + checkFreq(false); + if ( _i2cPort->requestFrom(i2c_addr, (unsigned char)1)) { + *buf = _i2cPort->read(); log_v("read 1 byte from 0x%02x received: 0x%02x", i2c_addr, buf); - + checkFreq(true); return true; } log_d("tried to read 1 byte from i2c addr 0x%02x and received none", i2c_addr); - + checkFreq(true); return false; } @@ -83,19 +134,20 @@ bool I2CUtil::readByte( unsigned char i2c_addr, unsigned char *buf ) bool I2CUtil::readByte( unsigned char i2c_addr, unsigned char reg, unsigned char *buf ) { - Wire.beginTransmission(i2c_addr); - Wire.write(reg); + checkFreq(false); + _i2cPort->beginTransmission(i2c_addr); + _i2cPort->write(reg); - if (Wire.endTransmission(false) == 0 && Wire.requestFrom(i2c_addr, (unsigned char)1)) { - *buf = Wire.read(); + if (_i2cPort->endTransmission(false) == 0 && _i2cPort->requestFrom(i2c_addr, (unsigned char)1)) { + *buf = _i2cPort->read(); log_v("read 1 byte from 0x%02x [0x%02x] received: 0x%02x", i2c_addr, reg, *buf); - + checkFreq(true); return true; } log_d("tried to read 1 byte from i2c addr 0x%02x / reg 0x%02x and received none", i2c_addr, reg); - + checkFreq(true); return false; } @@ -103,24 +155,25 @@ bool I2CUtil::readByte( unsigned char i2c_addr, unsigned char reg, unsigned char bool I2CUtil::readBytes( unsigned char i2c_addr, unsigned char reg, unsigned char count,unsigned char *dest ) { - Wire.beginTransmission(i2c_addr); - Wire.write(reg); + checkFreq(false); + _i2cPort->beginTransmission(i2c_addr); + _i2cPort->write(reg); unsigned char i = 0; - if (Wire.endTransmission(false) == 0 && Wire.requestFrom(i2c_addr, (unsigned char)count)) { - while (Wire.available()) { - dest[i++] = Wire.read(); + if (_i2cPort->endTransmission(false) == 0 && _i2cPort->requestFrom(i2c_addr, (unsigned char)count)) { + while (_i2cPort->available()) { + dest[i++] = _i2cPort->read(); log_v("%02x ", dest[i-1]); } log_v("read from 0x%02x [0x%02x] (%d bytes) received %d bytes", i2c_addr, reg, count, i); - + checkFreq(true); return true; } log_d("tried to read %d bytes from i2c addr 0x%02x / reg 0x%02x and received none", count, i2c_addr, reg); - + checkFreq(true); return false; } @@ -129,16 +182,17 @@ bool I2CUtil::readBytes( unsigned char i2c_addr, unsigned char reg, unsigned cha bool I2CUtil::readBytes( unsigned char i2c_addr, unsigned char count,unsigned char * dest ) { unsigned char i = 0; - - if (Wire.requestFrom(i2c_addr, (unsigned char)count)) { - while (Wire.available()) { - dest[i++] = Wire.read(); + checkFreq(false); + if (_i2cPort->requestFrom(i2c_addr, (unsigned char)count)) { + while (_i2cPort->available()) { + dest[i++] = _i2cPort->read(); } + checkFreq(true); return true; } log_d("tried to read %d bytes from i2c addr 0x%02x and received none", count, i2c_addr); - + checkFreq(true); return false; } @@ -164,6 +218,10 @@ void I2CUtil::defaultPrintCb(const char* format, ...) // I2C Scanner, scavengered from https://github.com/MartyMacGyver/Arduino_I2C_Scanner void I2CUtil::scan() { + if( !_begun ) { + log_d("Call I2C.begin(sda,scl) first!"); + return; + } if( printCb == nullptr ) { printCb = defaultPrintCb; } @@ -179,9 +237,9 @@ void I2CUtil::scan() printCb(" "); for(unsigned char addr = 0x03; addr <= 0x77; addr++ ) { // Address the device - Wire.beginTransmission(addr); + _i2cPort->beginTransmission(addr); // Check for ACK (detection of device), NACK or error - unsigned char deviceStatus = Wire.endTransmission(); + unsigned char deviceStatus = _i2cPort->endTransmission(); if (!(addr % 0x10)) { // Start of a line printCb("%02x:", addr / 0x10); @@ -199,3 +257,6 @@ void I2CUtil::scan() } printCb("\n"); } + + +//I2CUtil I2CUtil_Core; diff --git a/src/drivers/common/I2C/I2CUtil.h b/src/drivers/common/I2C/I2CUtil.h index 9890e3b..7a631ec 100644 --- a/src/drivers/common/I2C/I2CUtil.h +++ b/src/drivers/common/I2C/I2CUtil.h @@ -1,4 +1,4 @@ -#ifndef I2CUtil_h +#pragma once #define I2CUtil_h #include @@ -10,9 +10,11 @@ class I2CUtil { public: - I2CUtil(); + I2CUtil( TwoWire *i2cPort = &Wire, uint32_t clockspeed = 0 ) { _i2cPort = i2cPort; _clockspeed = clockspeed; } - bool begin( signed char sdaPin, signed char sclPin ); + //bool begin( signed char sdaPin, signed char sclPin ); + bool begin( signed char sdaPin, signed char sclPin, TwoWire *i2cPort = nullptr ); + bool begun() { return _begun; }; bool writeCommand( unsigned char i2c_addr, unsigned char reg); @@ -30,9 +32,17 @@ class I2CUtil private: + TwoWire *_i2cPort; + uint32_t _clockspeed = 0; + uint32_t _lastclockspeed = 0; + int _sdaPin = -1, _sclPin = -1; + bool _begun = false; + + void checkFreq( bool unset = false ); + I2CPrintCb printCb = nullptr; static void defaultPrintCb(const char* format, ...); }; -#endif +//extern I2CUtil I2CUtil_Core; // I2C Scanner && Twatch I2C bus diff --git a/src/drivers/common/IP5306/Power.cpp b/src/drivers/common/IP5306/Power.cpp index 934e04d..236a716 100644 --- a/src/drivers/common/IP5306/Power.cpp +++ b/src/drivers/common/IP5306/Power.cpp @@ -40,6 +40,9 @@ #define IP5306_REG_READ0 (0x70) #define IP5306_REG_READ1 (0x71) #define IP5306_REG_READ3 (0x78) +#define IP5306_REG_CHG_CTL0 (0x20) +#define IP5306_REG_CHG_CTL1 (0x21) +#define IP5306_REG_CHG_DIG (0x24) //- REG_CTL0 #define BOOST_ENABLE_BIT (0x20) @@ -71,24 +74,50 @@ #define LIGHT_LOAD_BIT (0x20) #define LOWPOWER_SHUTDOWN_BIT (0x01) +//- CHG +#define CURRENT_100MA (0x01 << 0) +#define CURRENT_200MA (0x01 << 1) +#define CURRENT_400MA (0x01 << 2) +#define CURRENT_800MA (0x01 << 3) +#define CURRENT_1600MA (0x01 << 4) + +#define BAT_4_2V (0x00) +#define BAT_4_3V (0x01) +#define BAT_4_3_5V (0x02) +#define BAT_4_4V (0x03) + +#define CHG_CC_BIT (0x20) + extern M5Stack M5; POWER::POWER() { } void POWER::begin() { + uint8_t data; //Initial I2C - Wire.begin(21, 22); -} - - -__attribute__((unused)) static bool getI2CReg(uint8_t *result, uint8_t address, uint8_t *reg) { - return (M5.I2C.readByte(address, *reg, result)); -} + if( ! M5.I2C.begun() ) { + M5.I2C.begin( 21, 22, &Wire ); + } -__attribute__((unused)) static bool setI2CReg(uint8_t address, uint8_t reg, uint8_t value) { - return (M5.I2C.writeByte(address, reg, value)); + #if defined ARDUINO_M5STACK_FIRE + // 450ma + setVinMaxCurrent(CURRENT_400MA); + setChargeVolt(BAT_4_2V); + // End charge current 200ma + if(M5.I2C.readByte(IP5306_ADDR, 0x21, &data) == true) { + M5.I2C.writeByte(IP5306_ADDR, 0x21, (data & 0x3f) | 0x00); + } + // Add volt 28mv + if(M5.I2C.readByte(IP5306_ADDR, 0x22, &data) == true) { + M5.I2C.writeByte(IP5306_ADDR, 0x22, (data & 0xfc) | 0x02); + } + // Vin charge CC + if(M5.I2C.readByte(IP5306_ADDR, 0x23, &data) == true) { + M5.I2C.writeByte(IP5306_ADDR, 0x23, (data & 0xdf) | 0x20); + } + #endif } bool POWER::setPowerBoostOnOff(bool en) { @@ -207,6 +236,22 @@ bool POWER::setAutoBootOnLoad(bool en) { return false; } +bool POWER::setVinMaxCurrent(uint8_t cur) { + uint8_t data; + if(M5.I2C.readByte(IP5306_ADDR, IP5306_REG_CHG_DIG, &data) == true) { + return M5.I2C.writeByte(IP5306_ADDR, IP5306_REG_CHG_DIG, (data & 0xe0) | cur); + } + return false; +} + +bool POWER::setChargeVolt(uint8_t volt) { + uint8_t data; + if (M5.I2C.readByte(IP5306_ADDR, IP5306_REG_CHG_CTL0, &data) == true) { + return M5.I2C.writeByte(IP5306_ADDR, IP5306_REG_CHG_CTL0, (data & 0xfc) | volt); + } + return false; +} + // if charge full,try set charge enable->disable->enable,can be recharged bool POWER::setCharge(bool en) { uint8_t data; @@ -299,7 +344,6 @@ bool POWER::isResetbyPowerSW() { void POWER::deepSleep(uint64_t time_in_us){ // Keep power keep boost on - setLowPowerShutdown(false); setPowerBoostKeepOn(true); // power off the Lcd @@ -369,9 +413,12 @@ void POWER::powerOFF(){ M5.I2C.writeByte(IP5306_ADDR, IP5306_REG_SYS_CTL1, (data & (~BOOST_ENABLE_BIT))); } - //stop wifi - esp_wifi_disconnect(); - esp_wifi_stop(); + // if wifi was initialized, stop it + wifi_mode_t mode; + if (esp_wifi_get_mode(&mode) == ESP_OK) { + esp_wifi_disconnect(); + esp_wifi_stop(); + } //stop bt esp_bluedroid_disable(); diff --git a/src/drivers/common/IP5306/Power.h b/src/drivers/common/IP5306/Power.h index c3e8109..2056682 100644 --- a/src/drivers/common/IP5306/Power.h +++ b/src/drivers/common/IP5306/Power.h @@ -44,6 +44,8 @@ bool setPowerBtnEn(bool en); // -- control for battery + bool setVinMaxCurrent(uint8_t cur); + bool setChargeVolt(uint8_t volt); bool setCharge(bool en); bool isChargeFull(); bool isCharging(); diff --git a/src/drivers/common/MPU6886/MPU6886.cpp b/src/drivers/common/MPU6886/MPU6886.cpp index 5d8e217..d719a74 100644 --- a/src/drivers/common/MPU6886/MPU6886.cpp +++ b/src/drivers/common/MPU6886/MPU6886.cpp @@ -1,106 +1,94 @@ #include "MPU6886.h" -#include -#include -MPU6886::MPU6886(){ - -} - -void MPU6886::I2C_Read_NBytes(uint8_t driver_Addr, uint8_t start_Addr, uint8_t number_Bytes, uint8_t *read_Buffer){ +bool MPU6886::Init( int sdaPin, int sclPin ){ + unsigned char tempdata[1]; + unsigned char regdata; - Wire1.beginTransmission(driver_Addr); - Wire1.write(start_Addr); - Wire1.endTransmission(false); - uint8_t i = 0; - Wire1.requestFrom(driver_Addr,number_Bytes); + log_e("Will Init MPU6886 on I2C ports SDA/SCL: %d/%d", sdaPin, sclPin ); - //! Put read results in the Rx buffer - while (Wire1.available()) { - read_Buffer[i++] = Wire1.read(); + if( _i2cUtil == nullptr ) { + if( _i2cPort == nullptr ) { + _i2cUtil = new I2CUtil( &Wire ); + log_w("New I2C port specified (Wire). on SDA/SCL: %d/%d", sdaPin, sclPin ); + } else { + _i2cUtil = new I2CUtil( _i2cPort ); + log_w("New I2C port specified (%s). on SDA/SCL: %d/%d", _i2cPort==&Wire?"Wire":"Wire1", sdaPin, sclPin ); + } } -} -void MPU6886::I2C_Write_NBytes(uint8_t driver_Addr, uint8_t start_Addr, uint8_t number_Bytes, uint8_t *write_Buffer){ + _i2cUtil->begin( sdaPin, sclPin ); - Wire1.beginTransmission(driver_Addr); - Wire1.write(start_Addr); - Wire1.write(*write_Buffer); - Wire1.endTransmission(); + _i2cUtil->readByte(MPU6886_ADDRESS, MPU6886_WHOAMI, tempdata); -} - -int MPU6886::Init(void){ - unsigned char tempdata[1]; - unsigned char regdata; - - Wire1.begin(21,22); + switch( tempdata[0] ) { + case 0x19: log_d("MPU for Core2 detected"); break; + case 0x71: log_d("MPU for M5Gray detected"); break; + default: log_e("Magic byte reading failed (was expecting 0x19 or 0x71, got 0x%2x)", tempdata[0] ); return false; break; + } - I2C_Read_NBytes(MPU6886_ADDRESS, MPU6886_WHOAMI, 1, tempdata); - if(tempdata[0] != 0x19) - return -1; delay(1); regdata = 0x00; - I2C_Write_NBytes(MPU6886_ADDRESS, MPU6886_PWR_MGMT_1, 1, ®data); + _i2cUtil->writeByte(MPU6886_ADDRESS, MPU6886_PWR_MGMT_1, regdata); delay(10); regdata = (0x01<<7); - I2C_Write_NBytes(MPU6886_ADDRESS, MPU6886_PWR_MGMT_1, 1, ®data); + _i2cUtil->writeByte(MPU6886_ADDRESS, MPU6886_PWR_MGMT_1, regdata); delay(10); regdata = (0x01<<0); - I2C_Write_NBytes(MPU6886_ADDRESS, MPU6886_PWR_MGMT_1, 1, ®data); + _i2cUtil->writeByte(MPU6886_ADDRESS, MPU6886_PWR_MGMT_1, regdata); delay(10); regdata = 0x10; - I2C_Write_NBytes(MPU6886_ADDRESS, MPU6886_ACCEL_CONFIG, 1, ®data); + _i2cUtil->writeByte(MPU6886_ADDRESS, MPU6886_ACCEL_CONFIG, regdata); delay(1); regdata = 0x18; - I2C_Write_NBytes(MPU6886_ADDRESS, MPU6886_GYRO_CONFIG, 1, ®data); + _i2cUtil->writeByte(MPU6886_ADDRESS, MPU6886_GYRO_CONFIG, regdata); delay(1); regdata = 0x01; - I2C_Write_NBytes(MPU6886_ADDRESS, MPU6886_CONFIG, 1, ®data); + _i2cUtil->writeByte(MPU6886_ADDRESS, MPU6886_CONFIG, regdata); delay(1); regdata = 0x05; - I2C_Write_NBytes(MPU6886_ADDRESS, MPU6886_SMPLRT_DIV, 1,®data); + _i2cUtil->writeByte(MPU6886_ADDRESS, MPU6886_SMPLRT_DIV, regdata); delay(1); regdata = 0x00; - I2C_Write_NBytes(MPU6886_ADDRESS, MPU6886_INT_ENABLE, 1, ®data); + _i2cUtil->writeByte(MPU6886_ADDRESS, MPU6886_INT_ENABLE, regdata); delay(1); regdata = 0x00; - I2C_Write_NBytes(MPU6886_ADDRESS, MPU6886_ACCEL_CONFIG2, 1, ®data); + _i2cUtil->writeByte(MPU6886_ADDRESS, MPU6886_ACCEL_CONFIG2, regdata); delay(1); regdata = 0x00; - I2C_Write_NBytes(MPU6886_ADDRESS, MPU6886_USER_CTRL, 1, ®data); + _i2cUtil->writeByte(MPU6886_ADDRESS, MPU6886_USER_CTRL, regdata); delay(1); regdata = 0x00; - I2C_Write_NBytes(MPU6886_ADDRESS, MPU6886_FIFO_EN, 1, ®data); + _i2cUtil->writeByte(MPU6886_ADDRESS, MPU6886_FIFO_EN, regdata); delay(1); regdata = 0x22; - I2C_Write_NBytes(MPU6886_ADDRESS, MPU6886_INT_PIN_CFG, 1, ®data); + _i2cUtil->writeByte(MPU6886_ADDRESS, MPU6886_INT_PIN_CFG, regdata); delay(1); regdata = 0x01; - I2C_Write_NBytes(MPU6886_ADDRESS, MPU6886_INT_ENABLE, 1, ®data); + _i2cUtil->writeByte(MPU6886_ADDRESS, MPU6886_INT_ENABLE, regdata); delay(100); getGres(); getAres(); - return 0; + return true; } void MPU6886::getAccelAdc(int16_t* ax, int16_t* ay, int16_t* az){ uint8_t buf[6]; - I2C_Read_NBytes(MPU6886_ADDRESS,MPU6886_ACCEL_XOUT_H,6,buf); + _i2cUtil->readBytes(MPU6886_ADDRESS,MPU6886_ACCEL_XOUT_H,6,buf); *ax=((int16_t)buf[0]<<8)|buf[1]; *ay=((int16_t)buf[2]<<8)|buf[3]; @@ -110,7 +98,7 @@ void MPU6886::getAccelAdc(int16_t* ax, int16_t* ay, int16_t* az){ void MPU6886::getGyroAdc(int16_t* gx, int16_t* gy, int16_t* gz){ uint8_t buf[6]; - I2C_Read_NBytes(MPU6886_ADDRESS,MPU6886_GYRO_XOUT_H,6,buf); + _i2cUtil->readBytes(MPU6886_ADDRESS,MPU6886_GYRO_XOUT_H,6,buf); *gx=((uint16_t)buf[0]<<8)|buf[1]; *gy=((uint16_t)buf[2]<<8)|buf[3]; @@ -121,7 +109,7 @@ void MPU6886::getGyroAdc(int16_t* gx, int16_t* gy, int16_t* gz){ void MPU6886::getTempAdc(int16_t *t){ uint8_t buf[2]; - I2C_Read_NBytes(MPU6886_ADDRESS,MPU6886_TEMP_OUT_H,2,buf); + _i2cUtil->readBytes(MPU6886_ADDRESS,MPU6886_TEMP_OUT_H,2,buf); *t=((uint16_t)buf[0]<<8)|buf[1]; } @@ -196,7 +184,7 @@ void MPU6886::SetGyroFsr(Gscale scale) //return IIC_Write_Byte(MPU_GYRO_CFG_REG,scale<<3);//设置陀螺仪满量程范围 unsigned char regdata; regdata = (scale<<3); - I2C_Write_NBytes(MPU6886_ADDRESS, MPU6886_GYRO_CONFIG, 1, ®data); + _i2cUtil->writeByte(MPU6886_ADDRESS, MPU6886_GYRO_CONFIG, regdata); delay(10); Gyscale = scale; @@ -207,7 +195,7 @@ void MPU6886::SetAccelFsr(Ascale scale) { unsigned char regdata; regdata = (scale<<3); - I2C_Write_NBytes(MPU6886_ADDRESS, MPU6886_ACCEL_CONFIG, 1, ®data); + _i2cUtil->writeByte(MPU6886_ADDRESS, MPU6886_ACCEL_CONFIG, regdata); delay(10); Acscale = scale; diff --git a/src/drivers/common/MPU6886/MPU6886.h b/src/drivers/common/MPU6886/MPU6886.h index fe16a7d..5115855 100644 --- a/src/drivers/common/MPU6886/MPU6886.h +++ b/src/drivers/common/MPU6886/MPU6886.h @@ -5,12 +5,13 @@ library in the Wire.h/twi.c utility file. We are also using the 400 kHz fast I2C mode by setting the TWI_FREQ to 400000L /twi.h utility file. */ -#ifndef _MPU6886_H_ +#pragma once #define _MPU6886_H_ #include -#include #include "MahonyAHRS.h" +#include "../../common/I2C/I2CUtil.h" +#include #define MPU6886_ADDRESS 0x68 #define MPU6886_WHOAMI 0x75 @@ -49,50 +50,57 @@ #define AtR 0.0174533 #define Gyro_Gr 0.0010653 + +#if ! defined DEG_TO_RAD + #define DEG_TO_RAD 0.017453292519943295769236907684886 +#endif + +extern I2CUtil I2CUtil_Core; + class MPU6886 { - public: - enum Ascale { - AFS_2G = 0, - AFS_4G, - AFS_8G, - AFS_16G - }; - - enum Gscale { - GFS_250DPS = 0, - GFS_500DPS, - GFS_1000DPS, - GFS_2000DPS - }; - - Gscale Gyscale = GFS_2000DPS; - Ascale Acscale = AFS_8G; - public: - MPU6886(); - int Init(void); - void getAccelAdc(int16_t* ax, int16_t* ay, int16_t* az); - void getGyroAdc(int16_t* gx, int16_t* gy, int16_t* gz); - void getTempAdc(int16_t *t); - - void getAccelData(float* ax, float* ay, float* az); - void getGyroData(float* gx, float* gy, float* gz); - void getTempData(float *t); - - void SetGyroFsr(Gscale scale); - void SetAccelFsr(Ascale scale); - - void getAhrsData(float *pitch,float *roll,float *yaw); - - public: - float aRes, gRes; - - private: - - private: - void I2C_Read_NBytes(uint8_t driver_Addr, uint8_t start_Addr, uint8_t number_Bytes, uint8_t *read_Buffer); - void I2C_Write_NBytes(uint8_t driver_Addr, uint8_t start_Addr, uint8_t number_Bytes, uint8_t *write_Buffer); - void getGres(); - void getAres(); + public: + enum Ascale { + AFS_2G = 0, + AFS_4G, + AFS_8G, + AFS_16G + }; + + enum Gscale { + GFS_250DPS = 0, + GFS_500DPS, + GFS_1000DPS, + GFS_2000DPS + }; + + Gscale Gyscale = GFS_2000DPS; + Ascale Acscale = AFS_8G; + public: + + MPU6886( TwoWire *port ) { _i2cPort = port; } + MPU6886( I2CUtil *i2cUtil ) { _i2cUtil = i2cUtil; } + bool Init( int sdaPin=21, int sclPin=22 ); + void getAccelAdc(int16_t* ax, int16_t* ay, int16_t* az); + void getGyroAdc(int16_t* gx, int16_t* gy, int16_t* gz); + void getTempAdc(int16_t *t); + + void getAccelData(float* ax, float* ay, float* az); + void getGyroData(float* gx, float* gy, float* gz); + void getTempData(float *t); + + void SetGyroFsr(Gscale scale); + void SetAccelFsr(Ascale scale); + + void getAhrsData(float *pitch,float *roll,float *yaw); + I2CUtil *getI2C() { return _i2cUtil; } + + public: + float aRes, gRes; + + private: + I2CUtil *_i2cUtil = nullptr; + TwoWire *_i2cPort = nullptr; + void getGres(); + void getAres(); }; -#endif diff --git a/src/drivers/common/MPU9250/MPU9250.cpp b/src/drivers/common/MPU9250/MPU9250.cpp index 66b4cd7..2e4ccc0 100644 --- a/src/drivers/common/MPU9250/MPU9250.cpp +++ b/src/drivers/common/MPU9250/MPU9250.cpp @@ -429,15 +429,15 @@ void MPU9250::MPU9250SelfTest(float * destination) { // Should return percent de // Wire.h read and write protocols void MPU9250::writeByte(uint8_t address, uint8_t subAddress, uint8_t data) { - _i2cPort->writeByte(address, subAddress, data); + _i2cUtil->writeByte(address, subAddress, data); } uint8_t MPU9250::readByte(uint8_t address, uint8_t subAddress) { uint8_t result; - _i2cPort->readByte(address, subAddress,&result); + _i2cUtil->readByte(address, subAddress,&result); return (result); } void MPU9250::readBytes(uint8_t address, uint8_t subAddress, uint8_t count,uint8_t * dest) { - _i2cPort->readBytes(address, subAddress,count,dest); + _i2cUtil->readBytes(address, subAddress,count,dest); } diff --git a/src/drivers/common/MPU9250/MPU9250.h b/src/drivers/common/MPU9250/MPU9250.h index b135430..53a7005 100644 --- a/src/drivers/common/MPU9250/MPU9250.h +++ b/src/drivers/common/MPU9250/MPU9250.h @@ -1,260 +1,261 @@ /* - Note: The MPU9250 is an I2C sensor and uses the Arduino Wire library. - Because the sensor is not 5V tolerant, we are using a 3.3 V 8 MHz Pro Mini or - a 3.3 V Teensy 3.1. We have disabled the internal pull-ups used by the Wire - library in the Wire.h/twi.c utility file. We are also using the 400 kHz fast - I2C mode by setting the TWI_FREQ to 400000L /twi.h utility file. - */ -#ifndef _MPU9250_H_ - #define _MPU9250_H_ +Note: The MPU9250 is an I2C sensor and uses the Arduino Wire library. +Because the sensor is not 5V tolerant, we are using a 3.3 V 8 MHz Pro Mini or +a 3.3 V Teensy 3.1. We have disabled the internal pull-ups used by the Wire +library in the Wire.h/twi.c utility file. We are also using the 400 kHz fast +I2C mode by setting the TWI_FREQ to 400000L /twi.h utility file. +*/ +#pragma once - #include - #include - #include "../../common/I2C/I2CUtil.h" +#define _MPU9250_H_ - // See also MPU-9250 Register Map and Descriptions, Revision 4.0, - // RM-MPU-9250A-00, Rev. 1.4, 9/9/2013 for registers not listed in above - // document; the MPU9250 and MPU9150 are virtually identical but the latter has - // a different register map +//#include +#include +#include "../../common/I2C/I2CUtil.h" - //Magnetometer Registers - #define AK8963_ADDRESS 0x0C - #define WHO_AM_I_AK8963 0x00 // should return 0x48 - #define INFO 0x01 - #define AK8963_ST1 0x02 // data ready status bit 0 - #define AK8963_XOUT_L 0x03 // data - #define AK8963_XOUT_H 0x04 - #define AK8963_YOUT_L 0x05 - #define AK8963_YOUT_H 0x06 - #define AK8963_ZOUT_L 0x07 - #define AK8963_ZOUT_H 0x08 - #define AK8963_ST2 0x09 // Data overflow bit 3 and data read error status bit 2 - #define AK8963_CNTL 0x0A // Power down (0000), single-measurement (0001), self-test (1000) and Fuse ROM (1111) modes on bits 3:0 - #define AK8963_ASTC 0x0C // Self test control - #define AK8963_I2CDIS 0x0F // I2C disable - #define AK8963_ASAX 0x10 // Fuse ROM x-axis sensitivity adjustment value - #define AK8963_ASAY 0x11 // Fuse ROM y-axis sensitivity adjustment value - #define AK8963_ASAZ 0x12 // Fuse ROM z-axis sensitivity adjustment value +// See also MPU-9250 Register Map and Descriptions, Revision 4.0, +// RM-MPU-9250A-00, Rev. 1.4, 9/9/2013 for registers not listed in above +// document; the MPU9250 and MPU9150 are virtually identical but the latter has +// a different register map - #define SELF_TEST_X_GYRO 0x00 - #define SELF_TEST_Y_GYRO 0x01 - #define SELF_TEST_Z_GYRO 0x02 +//Magnetometer Registers +#define AK8963_ADDRESS 0x0C +#define WHO_AM_I_AK8963 0x00 // should return 0x48 +#define INFO 0x01 +#define AK8963_ST1 0x02 // data ready status bit 0 +#define AK8963_XOUT_L 0x03 // data +#define AK8963_XOUT_H 0x04 +#define AK8963_YOUT_L 0x05 +#define AK8963_YOUT_H 0x06 +#define AK8963_ZOUT_L 0x07 +#define AK8963_ZOUT_H 0x08 +#define AK8963_ST2 0x09 // Data overflow bit 3 and data read error status bit 2 +#define AK8963_CNTL 0x0A // Power down (0000), single-measurement (0001), self-test (1000) and Fuse ROM (1111) modes on bits 3:0 +#define AK8963_ASTC 0x0C // Self test control +#define AK8963_I2CDIS 0x0F // I2C disable +#define AK8963_ASAX 0x10 // Fuse ROM x-axis sensitivity adjustment value +#define AK8963_ASAY 0x11 // Fuse ROM y-axis sensitivity adjustment value +#define AK8963_ASAZ 0x12 // Fuse ROM z-axis sensitivity adjustment value - /*#define X_FINE_GAIN 0x03 // [7:0] fine gain - #define Y_FINE_GAIN 0x04 - #define Z_FINE_GAIN 0x05 - #define XA_OFFSET_H 0x06 // User-defined trim values for accelerometer - #define XA_OFFSET_L_TC 0x07 - #define YA_OFFSET_H 0x08 - #define YA_OFFSET_L_TC 0x09 - #define ZA_OFFSET_H 0x0A - #define ZA_OFFSET_L_TC 0x0B */ +#define SELF_TEST_X_GYRO 0x00 +#define SELF_TEST_Y_GYRO 0x01 +#define SELF_TEST_Z_GYRO 0x02 - #define SELF_TEST_X_ACCEL 0x0D - #define SELF_TEST_Y_ACCEL 0x0E - #define SELF_TEST_Z_ACCEL 0x0F +/*#define X_FINE_GAIN 0x03 // [7:0] fine gain +#define Y_FINE_GAIN 0x04 +#define Z_FINE_GAIN 0x05 +#define XA_OFFSET_H 0x06 // User-defined trim values for accelerometer +#define XA_OFFSET_L_TC 0x07 +#define YA_OFFSET_H 0x08 +#define YA_OFFSET_L_TC 0x09 +#define ZA_OFFSET_H 0x0A +#define ZA_OFFSET_L_TC 0x0B */ - #define SELF_TEST_A 0x10 +#define SELF_TEST_X_ACCEL 0x0D +#define SELF_TEST_Y_ACCEL 0x0E +#define SELF_TEST_Z_ACCEL 0x0F - #define XG_OFFSET_H 0x13 // User-defined trim values for gyroscope - #define XG_OFFSET_L 0x14 - #define YG_OFFSET_H 0x15 - #define YG_OFFSET_L 0x16 - #define ZG_OFFSET_H 0x17 - #define ZG_OFFSET_L 0x18 - #define SMPLRT_DIV 0x19 - #define CONFIG 0x1A - #define GYRO_CONFIG 0x1B - #define ACCEL_CONFIG 0x1C - #define ACCEL_CONFIG2 0x1D - #define LP_ACCEL_ODR 0x1E - #define WOM_THR 0x1F +#define SELF_TEST_A 0x10 - // Duration counter threshold for motion interrupt generation, 1 kHz rate, - // LSB = 1 ms - #define MOT_DUR 0x20 - // Zero-motion detection threshold bits [7:0] - #define ZMOT_THR 0x21 - // Duration counter threshold for zero motion interrupt generation, 16 Hz rate, - // LSB = 64 ms - #define ZRMOT_DUR 0x22 +#define XG_OFFSET_H 0x13 // User-defined trim values for gyroscope +#define XG_OFFSET_L 0x14 +#define YG_OFFSET_H 0x15 +#define YG_OFFSET_L 0x16 +#define ZG_OFFSET_H 0x17 +#define ZG_OFFSET_L 0x18 +#define SMPLRT_DIV 0x19 +#define CONFIG 0x1A +#define GYRO_CONFIG 0x1B +#define ACCEL_CONFIG 0x1C +#define ACCEL_CONFIG2 0x1D +#define LP_ACCEL_ODR 0x1E +#define WOM_THR 0x1F - #define FIFO_EN 0x23 - #define I2C_MST_CTRL 0x24 - #define I2C_SLV0_ADDR 0x25 - #define I2C_SLV0_REG 0x26 - #define I2C_SLV0_CTRL 0x27 - #define I2C_SLV1_ADDR 0x28 - #define I2C_SLV1_REG 0x29 - #define I2C_SLV1_CTRL 0x2A - #define I2C_SLV2_ADDR 0x2B - #define I2C_SLV2_REG 0x2C - #define I2C_SLV2_CTRL 0x2D - #define I2C_SLV3_ADDR 0x2E - #define I2C_SLV3_REG 0x2F - #define I2C_SLV3_CTRL 0x30 - #define I2C_SLV4_ADDR 0x31 - #define I2C_SLV4_REG 0x32 - #define I2C_SLV4_DO 0x33 - #define I2C_SLV4_CTRL 0x34 - #define I2C_SLV4_DI 0x35 - #define I2C_MST_STATUS 0x36 - #define INT_PIN_CFG 0x37 - #define INT_ENABLE 0x38 - #define DMP_INT_STATUS 0x39 // Check DMP interrupt - #define INT_STATUS 0x3A - #define ACCEL_XOUT_H 0x3B - #define ACCEL_XOUT_L 0x3C - #define ACCEL_YOUT_H 0x3D - #define ACCEL_YOUT_L 0x3E - #define ACCEL_ZOUT_H 0x3F - #define ACCEL_ZOUT_L 0x40 - #define TEMP_OUT_H 0x41 - #define TEMP_OUT_L 0x42 - #define GYRO_XOUT_H 0x43 - #define GYRO_XOUT_L 0x44 - #define GYRO_YOUT_H 0x45 - #define GYRO_YOUT_L 0x46 - #define GYRO_ZOUT_H 0x47 - #define GYRO_ZOUT_L 0x48 - #define EXT_SENS_DATA_00 0x49 - #define EXT_SENS_DATA_01 0x4A - #define EXT_SENS_DATA_02 0x4B - #define EXT_SENS_DATA_03 0x4C - #define EXT_SENS_DATA_04 0x4D - #define EXT_SENS_DATA_05 0x4E - #define EXT_SENS_DATA_06 0x4F - #define EXT_SENS_DATA_07 0x50 - #define EXT_SENS_DATA_08 0x51 - #define EXT_SENS_DATA_09 0x52 - #define EXT_SENS_DATA_10 0x53 - #define EXT_SENS_DATA_11 0x54 - #define EXT_SENS_DATA_12 0x55 - #define EXT_SENS_DATA_13 0x56 - #define EXT_SENS_DATA_14 0x57 - #define EXT_SENS_DATA_15 0x58 - #define EXT_SENS_DATA_16 0x59 - #define EXT_SENS_DATA_17 0x5A - #define EXT_SENS_DATA_18 0x5B - #define EXT_SENS_DATA_19 0x5C - #define EXT_SENS_DATA_20 0x5D - #define EXT_SENS_DATA_21 0x5E - #define EXT_SENS_DATA_22 0x5F - #define EXT_SENS_DATA_23 0x60 - #define MOT_DETECT_STATUS 0x61 - #define I2C_SLV0_DO 0x63 - #define I2C_SLV1_DO 0x64 - #define I2C_SLV2_DO 0x65 - #define I2C_SLV3_DO 0x66 - #define I2C_MST_DELAY_CTRL 0x67 - #define SIGNAL_PATH_RESET 0x68 - #define MOT_DETECT_CTRL 0x69 - #define USER_CTRL 0x6A // Bit 7 enable DMP, bit 3 reset DMP - #define PWR_MGMT_1 0x6B // Device defaults to the SLEEP mode - #define PWR_MGMT_2 0x6C - #define DMP_BANK 0x6D // Activates a specific bank in the DMP - #define DMP_RW_PNT 0x6E // Set read/write pointer to a specific start address in specified DMP bank - #define DMP_REG 0x6F // Register in DMP from which to read or to which to write - #define DMP_REG_1 0x70 - #define DMP_REG_2 0x71 - #define FIFO_COUNTH 0x72 - #define FIFO_COUNTL 0x73 - #define FIFO_R_W 0x74 - #define WHO_AM_I_MPU9250 0x75 // Should return 0x71 - #define XA_OFFSET_H 0x77 - #define XA_OFFSET_L 0x78 - #define YA_OFFSET_H 0x7A - #define YA_OFFSET_L 0x7B - #define ZA_OFFSET_H 0x7D - #define ZA_OFFSET_L 0x7E +// Duration counter threshold for motion interrupt generation, 1 kHz rate, +// LSB = 1 ms +#define MOT_DUR 0x20 +// Zero-motion detection threshold bits [7:0] +#define ZMOT_THR 0x21 +// Duration counter threshold for zero motion interrupt generation, 16 Hz rate, +// LSB = 64 ms +#define ZRMOT_DUR 0x22 - // Using the MPU-9250 breakout board, ADO is set to 0 - // Seven-bit device address is 110100 for ADO = 0 and 110101 for ADO = 1 - #define ADO 0 - #if ADO - #define MPU9250_ADDRESS 0x69 // Device address when ADO = 1 - #else - #define MPU9250_ADDRESS 0x68 // Device address when ADO = 0 - #define AK8963_ADDRESS 0x0C // Address of magnetometer - #endif // AD0 +#define FIFO_EN 0x23 +#define I2C_MST_CTRL 0x24 +#define I2C_SLV0_ADDR 0x25 +#define I2C_SLV0_REG 0x26 +#define I2C_SLV0_CTRL 0x27 +#define I2C_SLV1_ADDR 0x28 +#define I2C_SLV1_REG 0x29 +#define I2C_SLV1_CTRL 0x2A +#define I2C_SLV2_ADDR 0x2B +#define I2C_SLV2_REG 0x2C +#define I2C_SLV2_CTRL 0x2D +#define I2C_SLV3_ADDR 0x2E +#define I2C_SLV3_REG 0x2F +#define I2C_SLV3_CTRL 0x30 +#define I2C_SLV4_ADDR 0x31 +#define I2C_SLV4_REG 0x32 +#define I2C_SLV4_DO 0x33 +#define I2C_SLV4_CTRL 0x34 +#define I2C_SLV4_DI 0x35 +#define I2C_MST_STATUS 0x36 +#define INT_PIN_CFG 0x37 +#define INT_ENABLE 0x38 +#define DMP_INT_STATUS 0x39 // Check DMP interrupt +#define INT_STATUS 0x3A +#define ACCEL_XOUT_H 0x3B +#define ACCEL_XOUT_L 0x3C +#define ACCEL_YOUT_H 0x3D +#define ACCEL_YOUT_L 0x3E +#define ACCEL_ZOUT_H 0x3F +#define ACCEL_ZOUT_L 0x40 +#define TEMP_OUT_H 0x41 +#define TEMP_OUT_L 0x42 +#define GYRO_XOUT_H 0x43 +#define GYRO_XOUT_L 0x44 +#define GYRO_YOUT_H 0x45 +#define GYRO_YOUT_L 0x46 +#define GYRO_ZOUT_H 0x47 +#define GYRO_ZOUT_L 0x48 +#define EXT_SENS_DATA_00 0x49 +#define EXT_SENS_DATA_01 0x4A +#define EXT_SENS_DATA_02 0x4B +#define EXT_SENS_DATA_03 0x4C +#define EXT_SENS_DATA_04 0x4D +#define EXT_SENS_DATA_05 0x4E +#define EXT_SENS_DATA_06 0x4F +#define EXT_SENS_DATA_07 0x50 +#define EXT_SENS_DATA_08 0x51 +#define EXT_SENS_DATA_09 0x52 +#define EXT_SENS_DATA_10 0x53 +#define EXT_SENS_DATA_11 0x54 +#define EXT_SENS_DATA_12 0x55 +#define EXT_SENS_DATA_13 0x56 +#define EXT_SENS_DATA_14 0x57 +#define EXT_SENS_DATA_15 0x58 +#define EXT_SENS_DATA_16 0x59 +#define EXT_SENS_DATA_17 0x5A +#define EXT_SENS_DATA_18 0x5B +#define EXT_SENS_DATA_19 0x5C +#define EXT_SENS_DATA_20 0x5D +#define EXT_SENS_DATA_21 0x5E +#define EXT_SENS_DATA_22 0x5F +#define EXT_SENS_DATA_23 0x60 +#define MOT_DETECT_STATUS 0x61 +#define I2C_SLV0_DO 0x63 +#define I2C_SLV1_DO 0x64 +#define I2C_SLV2_DO 0x65 +#define I2C_SLV3_DO 0x66 +#define I2C_MST_DELAY_CTRL 0x67 +#define SIGNAL_PATH_RESET 0x68 +#define MOT_DETECT_CTRL 0x69 +#define USER_CTRL 0x6A // Bit 7 enable DMP, bit 3 reset DMP +#define PWR_MGMT_1 0x6B // Device defaults to the SLEEP mode +#define PWR_MGMT_2 0x6C +#define DMP_BANK 0x6D // Activates a specific bank in the DMP +#define DMP_RW_PNT 0x6E // Set read/write pointer to a specific start address in specified DMP bank +#define DMP_REG 0x6F // Register in DMP from which to read or to which to write +#define DMP_REG_1 0x70 +#define DMP_REG_2 0x71 +#define FIFO_COUNTH 0x72 +#define FIFO_COUNTL 0x73 +#define FIFO_R_W 0x74 +#define WHO_AM_I_MPU9250 0x75 // Should return 0x71 +#define XA_OFFSET_H 0x77 +#define XA_OFFSET_L 0x78 +#define YA_OFFSET_H 0x7A +#define YA_OFFSET_L 0x7B +#define ZA_OFFSET_H 0x7D +#define ZA_OFFSET_L 0x7E - class MPU9250 { - protected: - // Set initial input parameters - enum Ascale { - AFS_2G = 0, - AFS_4G, - AFS_8G, - AFS_16G - }; +// Using the MPU-9250 breakout board, ADO is set to 0 +// Seven-bit device address is 110100 for ADO = 0 and 110101 for ADO = 1 +#define ADO 0 +#if ADO + #define MPU9250_ADDRESS 0x69 // Device address when ADO = 1 +#else + #define MPU9250_ADDRESS 0x68 // Device address when ADO = 0 + #define AK8963_ADDRESS 0x0C // Address of magnetometer +#endif // AD0 - enum Gscale { - GFS_250DPS = 0, - GFS_500DPS, - GFS_1000DPS, - GFS_2000DPS - }; +class MPU9250 { + protected: + // Set initial input parameters + enum Ascale { + AFS_2G = 0, + AFS_4G, + AFS_8G, + AFS_16G + }; - enum Mscale { - MFS_14BITS = 0, // 0.6 mG per LSB - MFS_16BITS // 0.15 mG per LSB - }; + enum Gscale { + GFS_250DPS = 0, + GFS_500DPS, + GFS_1000DPS, + GFS_2000DPS + }; - // Specify sensor full scale - uint8_t Gscale = GFS_250DPS; - uint8_t Ascale = AFS_2G; - // Choose either 14-bit or 16-bit magnetometer resolution - uint8_t Mscale = MFS_16BITS; - // 2 for 8 Hz, 6 for 100 Hz continuous magnetometer data read - uint8_t Mmode = 0x02; + enum Mscale { + MFS_14BITS = 0, // 0.6 mG per LSB + MFS_16BITS // 0.15 mG per LSB + }; - public: - float pitch, yaw, roll; - float temperature; // Stores the real internal chip temperature in Celsius - int16_t tempCount; // Temperature raw count output - uint32_t delt_t = 0; // Used to control display output rate + // Specify sensor full scale + uint8_t Gscale = GFS_250DPS; + uint8_t Ascale = AFS_2G; + // Choose either 14-bit or 16-bit magnetometer resolution + uint8_t Mscale = MFS_16BITS; + // 2 for 8 Hz, 6 for 100 Hz continuous magnetometer data read + uint8_t Mmode = 0x02; - uint32_t count = 0, sumCount = 0; // used to control display output rate - float deltat = 0.0f, sum = 0.0f; // integration interval for both filter schemes - uint32_t lastUpdate = 0, firstUpdate = 0; // used to calculate integration interval - uint32_t Now = 0; // used to calculate integration interval + public: + float pitch, yaw, roll; + float temperature; // Stores the real internal chip temperature in Celsius + int16_t tempCount; // Temperature raw count output + uint32_t delt_t = 0; // Used to control display output rate - int16_t gyroCount[3]; // Stores the 16-bit signed gyro sensor output - int16_t magCount[3]; // Stores the 16-bit signed magnetometer sensor output - // Scale resolutions per LSB for the sensors - float aRes, gRes, mRes; - // Variables to hold latest sensor data values - float ax, ay, az, gx, gy, gz, mx, my, mz; - // Factory mag calibration and mag bias - float magCalibration[3] = {0, 0, 0}, magbias[3] = {0, 0, 0}; - // Bias corrections for gyro and accelerometer - float gyroBias[3] = {0, 0, 0}, accelBias[3] = {0, 0, 0}; - float SelfTest[6]; - // Stores the 16-bit signed accelerometer sensor output - int16_t accelCount[3]; + uint32_t count = 0, sumCount = 0; // used to control display output rate + float deltat = 0.0f, sum = 0.0f; // integration interval for both filter schemes + uint32_t lastUpdate = 0, firstUpdate = 0; // used to calculate integration interval + uint32_t Now = 0; // used to calculate integration interval - public: - MPU9250(I2CUtil *port ) { _i2cPort = port; } - void getMres(); - void getGres(); - void getAres(); - void readAccelData(int16_t *); - void readGyroData(int16_t *); - void readMagData(int16_t *); - int16_t readTempData(); - void updateTime(); - void initAK8963(float *); - void initMPU9250(); - void calibrateMPU9250(float * gyroBias, float * accelBias); - void MPU9250SelfTest(float * destination); - void writeByte(uint8_t, uint8_t, uint8_t); - uint8_t readByte(uint8_t, uint8_t); - void readBytes(uint8_t, uint8_t, uint8_t, uint8_t *); + int16_t gyroCount[3]; // Stores the 16-bit signed gyro sensor output + int16_t magCount[3]; // Stores the 16-bit signed magnetometer sensor output + // Scale resolutions per LSB for the sensors + float aRes, gRes, mRes; + // Variables to hold latest sensor data values + float ax, ay, az, gx, gy, gz, mx, my, mz; + // Factory mag calibration and mag bias + float magCalibration[3] = {0, 0, 0}, magbias[3] = {0, 0, 0}; + // Bias corrections for gyro and accelerometer + float gyroBias[3] = {0, 0, 0}, accelBias[3] = {0, 0, 0}; + float SelfTest[6]; + // Stores the 16-bit signed accelerometer sensor output + int16_t accelCount[3]; + I2CUtil *getI2C() { return _i2cUtil; } + public: + MPU9250(I2CUtil *port ) { _i2cUtil = port; } + void getMres(); + void getGres(); + void getAres(); + void readAccelData(int16_t *); + void readGyroData(int16_t *); + void readMagData(int16_t *); + int16_t readTempData(); + void updateTime(); + void initAK8963(float *); + void initMPU9250(); + void calibrateMPU9250(float * gyroBias, float * accelBias); + void MPU9250SelfTest(float * destination); + void writeByte(uint8_t, uint8_t, uint8_t); + uint8_t readByte(uint8_t, uint8_t); + void readBytes(uint8_t, uint8_t, uint8_t, uint8_t *); - private: - I2CUtil *_i2cPort; - }; // class MPU9250 +private: + I2CUtil *_i2cUtil = nullptr; + +}; // class MPU9250 -#endif // _MPU9250_H_ diff --git a/src/drivers/common/RTC_PCF8563/pcf8563.h b/src/drivers/common/RTC_PCF8563/pcf8563.h index 009ebcf..9393006 100644 --- a/src/drivers/common/RTC_PCF8563/pcf8563.h +++ b/src/drivers/common/RTC_PCF8563/pcf8563.h @@ -29,6 +29,7 @@ github:https://github.com/lewisxhe/PCF8563_Library ///////////////////////////////////////////////////////////////// #pragma once +// TODO: get rid of #include #include "../../common/I2C/I2CUtil.h" diff --git a/src/gitTagVersion.h b/src/gitTagVersion.h index 5a7956e..16a3da6 100644 --- a/src/gitTagVersion.h +++ b/src/gitTagVersion.h @@ -1,6 +1,6 @@ #define ECC_VERSION_MAJOR 1 #define ECC_VERSION_MINOR 2 -#define ECC_VERSION_PATCH 6 +#define ECC_VERSION_PATCH 7 #define _ECC_STR(x) #x #define ECC_STR(x) _ECC_STR(x) // Macro to convert library version number into an integer diff --git a/src/helpers/M5Timer.cpp b/src/utility/M5Timer.cpp similarity index 100% rename from src/helpers/M5Timer.cpp rename to src/utility/M5Timer.cpp diff --git a/src/helpers/M5Timer.h b/src/utility/M5Timer.h similarity index 100% rename from src/helpers/M5Timer.h rename to src/utility/M5Timer.h diff --git a/src/helpers/Memory.h b/src/utility/Memory.h similarity index 100% rename from src/helpers/Memory.h rename to src/utility/Memory.h diff --git a/src/helpers/ScreenShotService/BMP/TinyBMPEncoder.cpp b/src/utility/ScreenShotService/BMP/TinyBMPEncoder.cpp similarity index 100% rename from src/helpers/ScreenShotService/BMP/TinyBMPEncoder.cpp rename to src/utility/ScreenShotService/BMP/TinyBMPEncoder.cpp diff --git a/src/helpers/ScreenShotService/BMP/TinyBMPEncoder.h b/src/utility/ScreenShotService/BMP/TinyBMPEncoder.h similarity index 100% rename from src/helpers/ScreenShotService/BMP/TinyBMPEncoder.h rename to src/utility/ScreenShotService/BMP/TinyBMPEncoder.h diff --git a/src/helpers/ScreenShotService/GIF/TinyGIFEncoder.cpp b/src/utility/ScreenShotService/GIF/TinyGIFEncoder.cpp similarity index 100% rename from src/helpers/ScreenShotService/GIF/TinyGIFEncoder.cpp rename to src/utility/ScreenShotService/GIF/TinyGIFEncoder.cpp diff --git a/src/helpers/ScreenShotService/GIF/TinyGIFEncoder.h b/src/utility/ScreenShotService/GIF/TinyGIFEncoder.h similarity index 100% rename from src/helpers/ScreenShotService/GIF/TinyGIFEncoder.h rename to src/utility/ScreenShotService/GIF/TinyGIFEncoder.h diff --git a/src/helpers/ScreenShotService/JPG/TinyJPEGEncoder.cpp b/src/utility/ScreenShotService/JPG/TinyJPEGEncoder.cpp similarity index 100% rename from src/helpers/ScreenShotService/JPG/TinyJPEGEncoder.cpp rename to src/utility/ScreenShotService/JPG/TinyJPEGEncoder.cpp diff --git a/src/helpers/ScreenShotService/JPG/TinyJPEGEncoder.h b/src/utility/ScreenShotService/JPG/TinyJPEGEncoder.h similarity index 100% rename from src/helpers/ScreenShotService/JPG/TinyJPEGEncoder.h rename to src/utility/ScreenShotService/JPG/TinyJPEGEncoder.h diff --git a/src/helpers/ScreenShotService/PNG/FatPNGEncoder.cpp b/src/utility/ScreenShotService/PNG/FatPNGEncoder.cpp similarity index 100% rename from src/helpers/ScreenShotService/PNG/FatPNGEncoder.cpp rename to src/utility/ScreenShotService/PNG/FatPNGEncoder.cpp diff --git a/src/helpers/ScreenShotService/PNG/FatPNGEncoder.h b/src/utility/ScreenShotService/PNG/FatPNGEncoder.h similarity index 100% rename from src/helpers/ScreenShotService/PNG/FatPNGEncoder.h rename to src/utility/ScreenShotService/PNG/FatPNGEncoder.h diff --git a/src/helpers/ScreenShotService/ScreenShot.cpp b/src/utility/ScreenShotService/ScreenShot.cpp similarity index 100% rename from src/helpers/ScreenShotService/ScreenShot.cpp rename to src/utility/ScreenShotService/ScreenShot.cpp diff --git a/src/helpers/ScreenShotService/ScreenShot.h b/src/utility/ScreenShotService/ScreenShot.h similarity index 100% rename from src/helpers/ScreenShotService/ScreenShot.h rename to src/utility/ScreenShotService/ScreenShot.h diff --git a/src/helpers/TouchButton.cpp b/src/utility/TouchButton.cpp similarity index 100% rename from src/helpers/TouchButton.cpp rename to src/utility/TouchButton.cpp diff --git a/src/helpers/TouchButton.h b/src/utility/TouchButton.h similarity index 100% rename from src/helpers/TouchButton.h rename to src/utility/TouchButton.h diff --git a/src/helpers/quaternionFilters.cpp b/src/utility/quaternionFilters.cpp similarity index 100% rename from src/helpers/quaternionFilters.cpp rename to src/utility/quaternionFilters.cpp diff --git a/src/helpers/quaternionFilters.h b/src/utility/quaternionFilters.h similarity index 100% rename from src/helpers/quaternionFilters.h rename to src/utility/quaternionFilters.h From d967bcdba6f1fc5d422e3b966dfb95dcf423743a Mon Sep 17 00:00:00 2001 From: tobozo Date: Fri, 19 Nov 2021 14:26:18 +0100 Subject: [PATCH 03/20] Platformio espressif32 3.4.0 test --- examples/Tests/build_test/platformio.ini | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/Tests/build_test/platformio.ini b/examples/Tests/build_test/platformio.ini index ac53a20..1abe1af 100644 --- a/examples/Tests/build_test/platformio.ini +++ b/examples/Tests/build_test/platformio.ini @@ -5,8 +5,10 @@ src_dir = main [env] framework = arduino ;platform = espressif32 -platform = https://github.com/platformio/platform-espressif32.git#feature/arduino-upstream -platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.0 +;platform = https://github.com/platformio/platform-espressif32.git#feature/arduino-upstream +;platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.0 +platform = https://github.com/platformio/platform-espressif32.git#3.4.0 +platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.1 ; this assumes the CI has copied the library folder under this path ; otherwise enable "ESP32-Chimera-Core" in "lib_deps" lib_extra_dirs = From e3a2c6de3e6ae987947800b00a2dff0438b4b669 Mon Sep 17 00:00:00 2001 From: tobozo Date: Fri, 19 Nov 2021 14:27:04 +0100 Subject: [PATCH 04/20] raising version --- library.json | 2 +- library.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.json b/library.json index b547977..88cc598 100644 --- a/library.json +++ b/library.json @@ -22,7 +22,7 @@ "name": "LovyanGFX" } ], - "version": "1.2.6", + "version": "1.2.7", "framework": "arduino", "platforms": "espressif32", "build": { diff --git a/library.properties b/library.properties index d892a27..b731c41 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ESP32-Chimera-Core -version=1.2.6 +version=1.2.7 author=tobozo,Lovyan03 maintainer=tobozo@noreply.github.com sentence=Alternate library M5Stack/M5Core2/Odroid-Go/D-Duino and possiblly other ESP32/TFT/SD bundles From 62ac002407ed5172f659d1fad5922c4820c3d3bc Mon Sep 17 00:00:00 2001 From: tobozo Date: Fri, 19 Nov 2021 14:29:51 +0100 Subject: [PATCH 05/20] platformio tweaks --- examples/Tests/build_test/platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Tests/build_test/platformio.ini b/examples/Tests/build_test/platformio.ini index 1abe1af..005871e 100644 --- a/examples/Tests/build_test/platformio.ini +++ b/examples/Tests/build_test/platformio.ini @@ -7,7 +7,7 @@ framework = arduino ;platform = espressif32 ;platform = https://github.com/platformio/platform-espressif32.git#feature/arduino-upstream ;platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.0 -platform = https://github.com/platformio/platform-espressif32.git#3.4.0 +platform = https://github.com/platformio/platform-espressif32.git platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.1 ; this assumes the CI has copied the library folder under this path ; otherwise enable "ESP32-Chimera-Core" in "lib_deps" From 411b675b4421cc0414a03b808fe5fa553f24cf15 Mon Sep 17 00:00:00 2001 From: tobozo Date: Fri, 19 Nov 2021 14:31:20 +0100 Subject: [PATCH 06/20] platformio tweaks --- .github/workflows/ArduinoBuild.yml | 1 + .github/workflows/PlatformioBuild.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/ArduinoBuild.yml b/.github/workflows/ArduinoBuild.yml index 0cc0c41..e1b7df1 100644 --- a/.github/workflows/ArduinoBuild.yml +++ b/.github/workflows/ArduinoBuild.yml @@ -13,6 +13,7 @@ on: - '**.c' - '**ArduinoBuild.yml' pull_request: + workflow_dispatch: jobs: build: diff --git a/.github/workflows/PlatformioBuild.yml b/.github/workflows/PlatformioBuild.yml index 70653e8..7b80d93 100644 --- a/.github/workflows/PlatformioBuild.yml +++ b/.github/workflows/PlatformioBuild.yml @@ -13,6 +13,7 @@ on: - '**.c' - '**PlatformioBuild.yml' pull_request: + workflow_dispatch: jobs: build: From b4bf48b8a369f466d711bfc846f8c86f76450164 Mon Sep 17 00:00:00 2001 From: tobozo Date: Sun, 28 Nov 2021 13:30:01 +0100 Subject: [PATCH 07/20] platformio tweaks --- examples/Tests/build_test/platformio.ini | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/Tests/build_test/platformio.ini b/examples/Tests/build_test/platformio.ini index 005871e..c8b81ef 100644 --- a/examples/Tests/build_test/platformio.ini +++ b/examples/Tests/build_test/platformio.ini @@ -5,9 +5,8 @@ src_dir = main [env] framework = arduino ;platform = espressif32 -;platform = https://github.com/platformio/platform-espressif32.git#feature/arduino-upstream -;platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.0 -platform = https://github.com/platformio/platform-espressif32.git +;platform = https://github.com/platformio/platform-espressif32.git +platform = https://github.com/platformio/platform-espressif32.git#feature/arduino-upstream platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.1 ; this assumes the CI has copied the library folder under this path ; otherwise enable "ESP32-Chimera-Core" in "lib_deps" From ffdf5d4662cb72f2c44a0be6146010da40ee3f08 Mon Sep 17 00:00:00 2001 From: tobozo Date: Sun, 28 Nov 2021 13:30:24 +0100 Subject: [PATCH 08/20] merged all license texts --- LICENSE | 286 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 285 insertions(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 4251c6a..ad75aac 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -MIT License +ESP32-Chimera-Core MIT License Copyright (c) 2020 tobozo @@ -19,3 +19,287 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +******************************************************************************* + +This codebase also contains recycled/edited elements from external projects: + +******************************************************************************* + +https://github.com/m5stack/M5Stack + +MIT License + +Copyright (c) 2017 M5Stack + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +******************************************************************************* + +https://github.com/lewisxhe/AXP202X_Libraries + +Arduino library for X-Power AXP202 chip. +Created by Lewis he on April 1, 2019. + +MIT License + +Copyright (c) 2019 lewis he + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +******************************************************************************* + +https://github.com/JChristensen/ + +Arduino Button Library v1.0 +Jack Christensen Mar 2012 + +This work is licensed under the Creative Commons Attribution- +ShareAlike 3.0 Unported License. To view a copy of this license, +visit http://creativecommons.org/licenses/by-sa/3.0/ or send a +letter to Creative Commons, 171 Second Street, Suite 300, +San Francisco, California, 94105, USA. + +******************************************************************************* + +LoRaWAN for M5Stack (fork from https://github.com/toddkrein/OTAA-LoRaWAN-Seeed) + +2013 Copyright (c) Seeed Technology Inc. All right reserved. +Author: Wayne Weng +Date: 2016-10-17 +add rgb backlight fucnction @ 2013-10-15 + +The MIT License (MIT) +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +******************************************************************************* + +M5Stack Bettery/Power Control Library v1.0 + +This work is licensed under the GNU Lesser General Public +License v2.1 +https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html + +******************************************************************************* + +MahonyAHRS +Madgwick's implementation of Mayhony's AHRS algorithm. +See: http://www.x-io.co.uk/node/8#open_source_ahrs_and_imu_algorithms +Date Author Notes +29/09/2011 SOH Madgwick Initial release +02/10/2011 SOH Madgwick Optimised for reduced CPU load + +******************************************************************************* + +Arduino library for NXP PCF8563 RTC chip. +Created by Lewis he on April 1, 2019. +github:https://github.com/lewisxhe/PCF8563_Library + +MIT License + +Copyright (c) 2019 lewis he + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +******************************************************************************* + +Arduino library for FT5206 chip. +Created by Lewis on April 17, 2019. +github:https://github.com/lewisxhe/FT5206_Library + +MIT License + +Copyright (c) 2019 lewis he + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +******************************************************************************* + +Touchscreen library for XPT2046 Touch Controller Chip +Copyright (c) 2015, Paul Stoffregen, paul@pjrc.com + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice, development funding notice, and this permission +notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +******************************************************************************* + +M5LoRa +Copyright (c) Sandeep Mistry. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice, development funding notice, and this permission +notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +******************************************************************************* + +Battery.h by @mdrjr https://github.com/mdrjr/ODROID-GO +[NO LICENSE] + +******************************************************************************* + +M5Timer.h + +M5Timer - A timer library for Arduino. +Author: mromani@ottotecnica.com +Copyright (c) 2010 OTTOTECNICA Italy + +This library is free software; you can redistribute it +and/or modify it under the terms of the GNU Lesser +General Public License as published by the Free Software +Foundation; either version 2.1 of the License, or (at +your option) any later version. + +This library is distributed in the hope that it will +be useful, but WITHOUT ANY WARRANTY; without even the +implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser +General Public License along with this library; if not, +write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +******************************************************************************* + +TFT_eSPI (some code snippets) from @Bodmer + +Software License Agreement (FreeBSD License) + +Copyright (c) 2020 Bodmer (https://github.com/Bodmer) + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +The views and conclusions contained in the software and documentation are those +of the authors and should not be interpreted as representing official policies, +either expressed or implied, of the FreeBSD Project. + +******************************************************************************* + From a1883c3034fb6de20abdd4698549199e661a24a8 Mon Sep 17 00:00:00 2001 From: tobozo Date: Sun, 28 Nov 2021 13:31:38 +0100 Subject: [PATCH 09/20] Adding TTGO-LoRa32-v2 board profile --- boards/boards.local.txt | 64 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/boards/boards.local.txt b/boards/boards.local.txt index 044d4a0..718a9a3 100644 --- a/boards/boards.local.txt +++ b/boards/boards.local.txt @@ -190,3 +190,67 @@ esp32_marauder.menu.DebugLevel.debug=Debug esp32_marauder.menu.DebugLevel.debug.build.code_debug=4 esp32_marauder.menu.DebugLevel.verbose=Verbose esp32_marauder.menu.DebugLevel.verbose.build.code_debug=5 + + + + + +ttgo-lora32-v2.name=TTGO LoRa32-OLED V2 + +ttgo-lora32-v2.upload.tool=esptool_py +ttgo-lora32-v2.upload.maximum_size=1310720 +ttgo-lora32-v2.upload.maximum_data_size=294912 +ttgo-lora32-v2.upload.flags= +ttgo-lora32-v2.upload.extra_flags= + +ttgo-lora32-v2.serial.disableDTR=true +ttgo-lora32-v2.serial.disableRTS=true + +ttgo-lora32-v2.build.tarch=xtensa +ttgo-lora32-v2.build.bootloader_addr=0x1000 +ttgo-lora32-v2.build.target=esp32 +ttgo-lora32-v2.build.mcu=esp32 +ttgo-lora32-v2.build.core=esp32 +ttgo-lora32-v2.build.variant=ttgo-lora32-v2 +ttgo-lora32-v2.build.board=TTGO_LoRa32_V2 + +ttgo-lora32-v2.build.f_cpu=240000000L +ttgo-lora32-v2.build.flash_mode=dio +ttgo-lora32-v2.build.flash_size=4MB +ttgo-lora32-v2.build.boot=dio +ttgo-lora32-v2.build.partitions=default + +ttgo-lora32-v2.menu.FlashFreq.80=80MHz +ttgo-lora32-v2.menu.FlashFreq.80.build.flash_freq=80m +ttgo-lora32-v2.menu.FlashFreq.40=40MHz +ttgo-lora32-v2.menu.FlashFreq.40.build.flash_freq=40m + +ttgo-lora32-v2.menu.UploadSpeed.921600=921600 +ttgo-lora32-v2.menu.UploadSpeed.921600.upload.speed=921600 +ttgo-lora32-v2.menu.UploadSpeed.115200=115200 +ttgo-lora32-v2.menu.UploadSpeed.115200.upload.speed=115200 +ttgo-lora32-v2.menu.UploadSpeed.256000.windows=256000 +ttgo-lora32-v2.menu.UploadSpeed.256000.upload.speed=256000 +ttgo-lora32-v2.menu.UploadSpeed.230400.windows.upload.speed=256000 +ttgo-lora32-v2.menu.UploadSpeed.230400=230400 +ttgo-lora32-v2.menu.UploadSpeed.230400.upload.speed=230400 +ttgo-lora32-v2.menu.UploadSpeed.460800.linux=460800 +ttgo-lora32-v2.menu.UploadSpeed.460800.macosx=460800 +ttgo-lora32-v2.menu.UploadSpeed.460800.upload.speed=460800 +ttgo-lora32-v2.menu.UploadSpeed.512000.windows=512000 +ttgo-lora32-v2.menu.UploadSpeed.512000.upload.speed=512000 + +ttgo-lora32-v2.menu.DebugLevel.none=None +ttgo-lora32-v2.menu.DebugLevel.none.build.code_debug=0 +ttgo-lora32-v2.menu.DebugLevel.error=Error +ttgo-lora32-v2.menu.DebugLevel.error.build.code_debug=1 +ttgo-lora32-v2.menu.DebugLevel.warn=Warn +ttgo-lora32-v2.menu.DebugLevel.warn.build.code_debug=2 +ttgo-lora32-v2.menu.DebugLevel.info=Info +ttgo-lora32-v2.menu.DebugLevel.info.build.code_debug=3 +ttgo-lora32-v2.menu.DebugLevel.debug=Debug +ttgo-lora32-v2.menu.DebugLevel.debug.build.code_debug=4 +ttgo-lora32-v2.menu.DebugLevel.verbose=Verbose +ttgo-lora32-v2.menu.DebugLevel.verbose.build.code_debug=5 + + From ee4bc46d2d7c3c8198c339aeeee1cd98ac45ef31 Mon Sep 17 00:00:00 2001 From: tobozo Date: Sun, 28 Nov 2021 13:31:46 +0100 Subject: [PATCH 10/20] Adding TTGO-LoRa32-v2 board profile --- src/Config.h | 154 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 137 insertions(+), 17 deletions(-) diff --git a/src/Config.h b/src/Config.h index 8e27b6f..4a18aea 100644 --- a/src/Config.h +++ b/src/Config.h @@ -5,9 +5,25 @@ // buttons debounce time (milliseconds) #define DEBOUNCE_MS 10 +#include "esp32-hal-log.h" + +#if defined ESP_ARDUINO_VERSION_VAL + #if __has_include("core_version.h") // for platformio + #include "core_version.h" + #endif + #if ESP_ARDUINO_VERSION_VAL(2,0,1) >= ESP_ARDUINO_VERSION || ARDUINO_ESP32_GIT_VER == 0x15bbd0a || ARDUINO_ESP32_GIT_VER == 0xd218e58f + // #pragma message "Filesystem can create subfolders on file creation" + #define FS_CAN_CREATE_PATH + #endif +#endif + #if defined( LGFX_ONLY ) // LGFX config loaded externally + #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE + #pragma message "LGFX Only" + #endif + #define SPEAKER_PIN -1 #define SD_ENABLE 0 #define BUTTON_A_PIN -1 @@ -18,6 +34,10 @@ #elif defined(ARDUINO_ESP32_DEV) + #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE + #pragma message "ESP32_DEV SELECTED" + #endif + #define TFT_LED_PIN -1 #define TFT_DC_PIN 32 #define TFT_CS_PIN 5 @@ -60,7 +80,11 @@ #elif defined( ARDUINO_LOLIN_D32_PRO ) - //#warning "USING LoLin D32 Pro setup with Touch enabled for ESP32Marauder" + #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE + #pragma message "LOLIN_D32_PRO SELECTED" + #endif + + //#pragma message "USING LoLin D32 Pro setup with Touch enabled for ESP32Marauder" #define SPEAKER_PIN -1 #define SD_ENABLE 1 #define BUTTON_A_PIN -1 @@ -77,6 +101,10 @@ #elif defined( ARDUINO_ESP32_WROVER_KIT ) + #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE + #pragma message "WROVER_KIT SELECTED" + #endif + #define TFT_LED_PIN 14 #define TFT_DC_PIN 21 #define TFT_CS_PIN 5 @@ -94,6 +122,10 @@ #elif defined(ARDUINO_D) || defined(ARDUINO_DDUINO32_XS) + #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE + #pragma message "DDUINO32_XS SELECTED" + #endif + #define TFT_LED_PIN 22 #define TFT_DC_PIN 23 #define TFT_RST_PIN 32 @@ -133,8 +165,11 @@ #define SPEAKER_PIN 4 #if defined( LILYGO_WATCH_2019_WITH_TOUCH ) + #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE + #pragma message "LILYGO_WATCH_2019_WITH_TOUCH SELECTED" + #endif // #include "board/twatch2019_with_touch.h" - //#warning "Selected LILYGO_WATCH_2019_WITH_TOUCH" + //#pragma message "Selected LILYGO_WATCH_2019_WITH_TOUCH" #define SD_ENABLE 1 #define LILYGO_WATCH_HAS_BMA423 #define HAS_AXP202 @@ -142,16 +177,22 @@ #define LILYGO_WATCH_HAS_BUTTON #define HAS_TOUCH #elif defined(LILYGO_WATCH_2019_NO_TOUCH) + #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE + #pragma message "LILYGO_WATCH_2019_NO_TOUCH SELECTED" + #endif //#include "board/twatch2019_with_not_touch.h" - //#warning "Selected LILYGO_WATCH_2019_NO_TOUCH" + //#pragma message "Selected LILYGO_WATCH_2019_NO_TOUCH" #define SD_ENABLE 1 #define LILYGO_WATCH_HAS_BMA423 #define HAS_AXP202 #define LILYGO_WATCH_HAS_BACKLIGHT #define LILYGO_WATCH_HAS_BUTTON #elif defined(LILYGO_WATCH_BLOCK) // should be called "brick" :-) + #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE + #pragma message "LILYGO_WATCH_BLOCK SELECTED" + #endif //#include "board/twatch_block.h" - //#warning "Selected LILYGO_WATCH_BLOCK" + //#pragma message "Selected LILYGO_WATCH_BLOCK" #define SD_ENABLE 0 #undef HAS_SDCARD #define HAS_AXP202 @@ -159,6 +200,9 @@ #define LILYGO_WATCH_HAS_MPU6050 #define HAS_TOUCH #else // all LILYGO_WATCH_2020 models + #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE + #pragma message "LILYGO_WATCH_2020 SELECTED" + #endif // common settings across v1/v2/v3 #define SD_ENABLE 0 #undef HAS_SDCARD @@ -167,7 +211,7 @@ #define HAS_TOUCH #if defined(BOARD_HAS_PSRAM) //#include "board/twatch2020_v1.h" - //#warning "Defaulting to LILYGO_WATCH_2020_V1" + //#pragma message "Defaulting to LILYGO_WATCH_2020_V1" #define LILYGO_WATCH_HAS_MOTOR #define LILYGO_WATCH_HAS_BMA423 #define HAS_AXP202 @@ -177,7 +221,7 @@ //#define LILYGO_WATCH_HAS_BACKLIGHT #else // TODO: implement v3 //#include "board/twatch2020_v2.h" - //#warning "Defaulting to LILYGO_WATCH_2020_V2" + //#pragma message "Defaulting to LILYGO_WATCH_2020_V2" #define TOUCH_RST 4 // !! 2020_v2 only #define LILYGO_WATCH_HAS_BMA423 #define HAS_AXP202 @@ -189,7 +233,9 @@ #elif defined(ARDUINO_TTGO_T1) - + #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE + #pragma message "ARDUINO_TTGO_T1 SELECTED" + #endif // TFT/OLED display #define TFT_CS_PIN 16 #define TFT_RST_PIN 9 // you can also connect this to the Arduino reset @@ -208,8 +254,61 @@ #define BUTTON_C_PIN 35 + +#elif defined ARDUINO_TTGO_LoRa32_V2 // || defined ARDUINO_TTGO_LoRa32_V1 || defined ARDUINO_TTGO_LoRa32_v21new + + // ARDUINO_BOARD="TTGO_LoRa32_V2" + // ARDUINO_VARIANT="ttgo-lora32-v2" + + #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE + #pragma message "TTGO_LoRa32_v2 SELECTED" + #endif + + // !!! ARDUINO_TTGO_LoRa32_v2 does not exist in boards.txt !!! + // this profile will only be loaded if a custom entry is inserted in boards.local.txt + // or if -D ARDUINO_TTGO_LoRa32_v2 is added to the compile flags. + // Similar boards exist in board.txt but use a different pinout: ARDUINO_TTGO_LoRa32_V1, ARDUINO_TTGO_LoRa32_v21new + // TFT/OLED display + #define OLED_SDA 21 + #define OLED_SCL 22 + #define OLED_RST 16 + // LoRa device + #define LORA_MOSI_PIN 27 + #define LORA_MISO_PIN 19 + #define LORA_CS_PIN 18 + #define LORA_SCK_PIN 5 + #define LORA_RST_PIN 12 // attached to EN + #define LORA_IRQ_PIN 26 // DIO0 + #define LORA_SPI_HOST VSPI_HOST + // SD-MMC used as 1bit SD + #define TFCARD_SCLK_PIN 14 + #define TFCARD_MISO_PIN 2 + #define TFCARD_MOSI_PIN 15 + #define TFCARD_CS_PIN 13 + #define SD_ENABLE 1 + #define TFCARD_USE_WIRE1 + #define TFCARD_SPI_HOST HSPI_HOST + // disabled features + #define SPEAKER_PIN -1 + #define BUTTON_A_PIN -1 + #define BUTTON_B_PIN -1 + #define BUTTON_C_PIN -1 + +/* + SPI.begin(14, 2, 15); + if(!SD.begin(13)){ + Serial.println("Card Mount Failed"); + return; + } +*/ + + #elif defined( ARDUINO_ODROID_ESP32 ) + #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE + #pragma message "ODROID_ESP32 SELECTED" + #endif + #define TFT_LED_PIN 32 #define TFT_DC_PIN 27 #define TFT_CS_PIN 14 @@ -234,6 +333,10 @@ #elif defined( ARDUINO_M5Stick_C ) // M5Stick C + #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE + #pragma message "M5Stick_C SELECTED" + #endif + #define SPEAKER_PIN -1 #define TFT_DC_PIN 23 #define TFT_CS_PIN 5 @@ -258,6 +361,10 @@ #elif defined( ARDUINO_M5Stick_C_Plus ) // M5Stick C Plus + #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE + #pragma message "M5Stick_C_Plus SELECTED" + #endif + #define SPEAKER_PIN -1 #define TFT_DC_PIN 23 #define TFT_CS_PIN 5 @@ -282,6 +389,10 @@ #elif defined( ARDUINO_M5STACK_Core2 ) // M5Core2 + #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE + #pragma message "M5STACK_Core2 SELECTED" + #endif + #define TFT_LED_PIN -1 #define TFT_DC_PIN 15 #define TFT_CS_PIN 5 @@ -306,6 +417,10 @@ #elif defined( ARDUINO_M5Stack_Core_ESP32 ) || defined( ARDUINO_M5STACK_FIRE) // m5stack classic/fire + #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE + #pragma message "M5Stack_Core_ESP32 / M5STACK_FIRE SELECTED" + #endif + #define HAS_IP5306 #define HAS_MPU9250 @@ -327,6 +442,10 @@ #elif defined CONFIG_IDF_TARGET_ESP32S2 // ESP32-S2 basic support + #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE + #pragma message "ESP32S2 SELECTED" + #endif + #define BUTTON_A_PIN -1 #define BUTTON_B_PIN -1 #define BUTTON_C_PIN -1 @@ -336,7 +455,12 @@ #undef HAS_SDCARD #else - #pragma "No know board detected, disabling Buttons and SD" + + #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_WARN + #pragma message "NO BOARD SELECTED" + #endif + + #pragma message "No know board detected, disabling Buttons and SD" #define SD_ENABLE 0 #define BUTTON_A_PIN -1 #define BUTTON_B_PIN -1 @@ -365,6 +489,10 @@ #if SPEAKER_PIN != -1 #define HAS_SPEAKER +#else + #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_WARN + #pragma message "Speaker disabled" + #endif #endif @@ -394,13 +522,5 @@ #endif -#if defined ESP_ARDUINO_VERSION_VAL - #if __has_include("core_version.h") // for platformio - #include "core_version.h" - #endif - #if ESP_ARDUINO_VERSION_VAL(2,0,1) >= ESP_ARDUINO_VERSION || ARDUINO_ESP32_GIT_VER == 0x15bbd0a || ARDUINO_ESP32_GIT_VER == 0xd218e58f - // #pragma message "Filesystem can create subfolders on file creation" - #define FS_CAN_CREATE_PATH - #endif -#endif + From 31febd666c988afb5f47ddcf5d91fa8cddecdce4 Mon Sep 17 00:00:00 2001 From: tobozo Date: Sun, 28 Nov 2021 13:32:50 +0100 Subject: [PATCH 11/20] code formatting and tweaks --- src/ESP32-Chimera-Core.cpp | 9 +- src/ESP32-Chimera-Core.h | 478 ++++++++++++----------------- src/M5Display.cpp | 7 +- src/drivers/common/Button/Button.h | 3 +- 4 files changed, 205 insertions(+), 292 deletions(-) diff --git a/src/ESP32-Chimera-Core.cpp b/src/ESP32-Chimera-Core.cpp index c0d0fbc..87125c3 100644 --- a/src/ESP32-Chimera-Core.cpp +++ b/src/ESP32-Chimera-Core.cpp @@ -24,7 +24,14 @@ void M5Stack::begin(bool LCDEnable, bool SDEnable, bool SerialEnable, bool I2CEn Serial.begin(115200); Serial.flush(); delay(50); - Serial.print("ESP32-Chimera-Core initializing..."); + Serial.print("ESP32-Chimera-Core initializing "); + #if defined ARDUINO_BOARD + Serial.printf("[Board=%s] ", ARDUINO_BOARD ); + #endif + #if defined ARDUINO_VARIANT + Serial.printf("[Variant=%s] ", ARDUINO_VARIANT ); + #endif + Serial.println(); } #if defined HAS_AXP192 diff --git a/src/ESP32-Chimera-Core.h b/src/ESP32-Chimera-Core.h index 28b77cb..6833482 100644 --- a/src/ESP32-Chimera-Core.h +++ b/src/ESP32-Chimera-Core.h @@ -1,323 +1,229 @@ -// Copyright (c) M5Stack. All rights reserved. - -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -/** - * \par Copyright (C), 2016-2017, M5Stack - * \class M5Stack - * \brief A clone of M5Stack library with multiple devices support - * @file ESP32-Chimera-Core - * @author M5Stack, tobozo - * @version V1.1.0 - * @date 2020/09/19 - * @brief Header for ESP32-Chimera-Core.cpp module - * - * \par Description - * This file is a drive for M5Stack/M5Core2/Odroid-Go/TWatch (and more) core. - * - * \par Method List: - * - * System: - M5.begin(); - M5.update(); - - Power: - M5.Power.setPowerBoostKeepOn() - M5.Power.setCharge(uint8_t mode); - M5.Power.setPowerBoostKeepOn(bool en); - M5.Power.isChargeFull(); - M5.Power.setWakeupButton(uint8_t button); - M5.Power.powerOFF(); - - bool setPowerBoostOnOff(bool en); - bool setPowerBoostSet(bool en); - bool setPowerVin(bool en); - bool setPowerWLEDSet(bool en); - - LCD: - M5.lcd.setBrightness(uint8_t brightness); - M5.Lcd.drawPixel(int16_t x, int16_t y, uint16_t color); - M5.Lcd.drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color); - M5.Lcd.fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); - M5.Lcd.fillScreen(uint16_t color); - M5.Lcd.drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color); - M5.Lcd.drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,uint16_t color); - M5.Lcd.fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color); - M5.Lcd.fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,int16_t delta, uint16_t color); - M5.Lcd.drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color); - M5.Lcd.fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color); - M5.Lcd.drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color); - M5.Lcd.fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color); - M5.Lcd.drawBitmap(int16_t x, int16_t y, const uint8_t bitmap[], int16_t w, int16_t h, uint16_t color); - M5.Lcd.drawRGBBitmap(int16_t x, int16_t y, const uint16_t bitmap[], int16_t w, int16_t h), - M5.Lcd.drawChar(uint16_t x, uint16_t y, char c, uint16_t color, uint16_t bg, uint8_t size); - M5.Lcd.setCursor(uint16_t x0, uint16_t y0); - M5.Lcd.setTextColor(uint16_t color); - M5.Lcd.setTextColor(uint16_t color, uint16_t backgroundcolor); - M5.Lcd.setTextSize(uint8_t size); - M5.Lcd.setTextWrap(boolean w); - M5.Lcd.printf(); - M5.Lcd.print(); - M5.Lcd.println(); - M5.Lcd.drawCentreString(const char *string, int dX, int poY, int font); - M5.Lcd.drawRightString(const char *string, int dX, int poY, int font); - M5.Lcd.drawJpg(const uint8_t *jpg_data, size_t jpg_len, uint16_t x, uint16_t y); - M5.Lcd.drawJpgFile(fs::FS &fs, const char *path, uint16_t x, uint16_t y); - M5.Lcd.drawBmpFile(fs::FS &fs, const char *path, uint16_t x, uint16_t y); - - Button: - M5.BtnA/B/C.read(); - M5.BtnA/B/C.isPressed(); - M5.BtnA/B/C.isReleased(); - M5.BtnA/B/C.wasPressed(); - M5.BtnA/B/C.wasReleased(); - M5.BtnA/B/C.wasreleasedFor() - M5.BtnA/B/C.pressedFor(uint32_t ms); - M5.BtnA/B/C.releasedFor(uint32_t ms); - M5.BtnA/B/C.lastChange(); - - Speaker: - M5.Speaker.tone(uint32_t freq); - M5.Speaker.tone(freq, time); - M5.Speaker.beep(); - M5.Speaker.setBeep(uint16_t frequency, uint16_t duration); - M5.Speaker.mute(); - - * - * \par History: - *
- * ``         `
- * - */ - -#ifndef _CHIMERA_CORE_H_ - #define _CHIMERA_CORE_H_ - // create marker to ease core (legacy or chimera) detection - // e.g.: - // #ifdef _CHIMERA_CORE_ - // M5.ScreenShot.snap(); - // #endif - #define _CHIMERA_CORE_ - - #if ! defined ESP32 - #error “This library only supports boards with ESP32 family processors” - #endif +#pragma once + +// create marker to ease core (legacy or chimera) detection +// e.g.: +// #ifdef _CHIMERA_CORE_ +// M5.ScreenShot.snap(); +// #endif +#define _CHIMERA_CORE_H_ +#define _CHIMERA_CORE_ + +#if ! defined ESP32 + #error “This library only supports boards with ESP32 family processors” +#endif - // #define MPU9250_INSDE // M5Core2 : enable this only if plugging a secondary MPU ! - - #include "gitTagVersion.h" - #include - #include - #include - #include - #include "Config.h" - - #ifdef BOARD_HAS_1BIT_SDMMC - #include "SD_MMC.h" - #define M5STACK_SD SD_MMC - #else - #if defined HAS_SDCARD - #include "SD.h" - #define M5STACK_SD SD - #define USE_TFCARD_CS_PIN - #endif +// #define MPU9250_INSDE // M5Core2 : enable this only if plugging a secondary MPU ! + +#include "gitTagVersion.h" +#include +#include +#include +#include +#include "Config.h" + +#ifdef BOARD_HAS_1BIT_SDMMC + #include "SD_MMC.h" + #define M5STACK_SD SD_MMC +#else + #if defined HAS_SDCARD + #include "SD.h" + #define M5STACK_SD SD + #define USE_TFCARD_CS_PIN #endif +#endif - #include "M5Display.h" +#include "M5Display.h" - #include "utility/Memory.h" - #include "utility/ScreenShotService/ScreenShot.h" // ScreenShot Service - #include "drivers/common/Button/Button.h" // BtnA/BtnB/BtnC Support - #include "drivers/common/I2C/I2CUtil.h" // I2C Scanner - #include "drivers/common/NVS/NVSUtils.h" // NVS Utilities +#include "utility/Memory.h" +#include "utility/ScreenShotService/ScreenShot.h" // ScreenShot Service +#include "drivers/common/Button/Button.h" // BtnA/BtnB/BtnC Support +#include "drivers/common/I2C/I2CUtil.h" // I2C Scanner +#include "drivers/common/NVS/NVSUtils.h" // NVS Utilities - #if defined HAS_TOUCH - #include "utility/TouchButton.h" - #endif +#if defined HAS_TOUCH + #include "utility/TouchButton.h" +#endif - #if defined HAS_SPEAKER - #include "drivers/common/Speaker/Speaker.h" - #endif +#if defined HAS_SPEAKER + #include "drivers/common/Speaker/Speaker.h" +#endif - #if defined HAS_IP5306 - #include "drivers/common/IP5306/Power.h" - #endif +#if defined HAS_IP5306 + #include "drivers/common/IP5306/Power.h" +#endif - #if defined HAS_AXP192 - #include "drivers/common/AXP192/AXP192.h" - #endif +#if defined HAS_AXP192 + #include "drivers/common/AXP192/AXP192.h" +#endif - #if defined HAS_AXP202 - #include "drivers/common/AXP202/axp20x.h" - #endif +#if defined HAS_AXP202 + #include "drivers/common/AXP202/axp20x.h" +#endif - #if defined HAS_BM8563 - #include "drivers/common/RTC_BM8563/RTC_BM8563.h" - #endif +#if defined HAS_BM8563 + #include "drivers/common/RTC_BM8563/RTC_BM8563.h" +#endif - #if defined HAS_PCF8563 - #include "drivers/common/RTC_PCF8563/pcf8563.h" - #endif +#if defined HAS_PCF8563 + #include "drivers/common/RTC_PCF8563/pcf8563.h" +#endif - #if defined HAS_MPU6886 - #include "drivers/common/MPU6886/MPU6886.h" - #endif +#if defined HAS_MPU6886 + #include "drivers/common/MPU6886/MPU6886.h" +#endif - #if defined HAS_MPU9250 - #include "drivers/common/MPU9250/MPU9250.h" - #endif +#if defined HAS_MPU9250 + #include "drivers/common/MPU9250/MPU9250.h" +#endif - #if defined ARDUINO_ODROID_ESP32 - #include "drivers/Odroid-Go/Battery/battery.h" - #endif +#if defined ARDUINO_ODROID_ESP32 + #include "drivers/Odroid-Go/Battery/battery.h" +#endif - #if defined ARDUINO_M5STACK_Core2 // M5Core2 - // M5Core2 'Physical' Button emulation using off-display touch zone - #include "drivers/M5Core2/ButtonTouchReader/ButtonTouchReader.h" - #undef DEBOUNCE_MS // unset base debounce - #define DEBOUNCE_MS 100 // this device has emulated touch screen buttons and needs slower polls - #endif +#if defined ARDUINO_M5STACK_Core2 // M5Core2 + // M5Core2 'Physical' Button emulation using off-display touch zone + #include "drivers/M5Core2/ButtonTouchReader/ButtonTouchReader.h" + #undef DEBOUNCE_MS // unset base debounce + #define DEBOUNCE_MS 100 // this device has emulated touch screen buttons and needs slower polls +#endif - #if defined( ARDUINO_M5Stack_Core_ESP32 ) || defined( ARDUINO_M5STACK_FIRE) // m5stack classic/fire - #if defined HAS_MPU6886 - #define HAS_PRIMARY_IMU - #define PRIMARY_IMU MPU6886 - #define PRIMARY_IMU_ARG &Wire - #if defined HAS_MPU9250 - #pragma message "Enabling secondary IMU (MPU9250)" - #define HAS_SECONDARY_IMU - #define SECONDARY_IMU MPU9250 - #define SECONDARY_IMU_ARG &I2C - #endif - #elif defined HAS_MPU9250 - #define HAS_PRIMARY_IMU - #define PRIMARY_IMU MPU9250 - #define PRIMARY_IMU_ARG &I2C +#if defined( ARDUINO_M5Stack_Core_ESP32 ) || defined( ARDUINO_M5STACK_FIRE) // m5stack classic/fire + #if defined HAS_MPU6886 + #define HAS_PRIMARY_IMU + #define PRIMARY_IMU MPU6886 + #define PRIMARY_IMU_ARG &Wire + #if defined HAS_MPU9250 + #pragma message "Enabling secondary IMU (MPU9250)" + #define HAS_SECONDARY_IMU + #define SECONDARY_IMU MPU9250 + #define SECONDARY_IMU_ARG &I2C #endif + #elif defined HAS_MPU9250 + #define HAS_PRIMARY_IMU + #define PRIMARY_IMU MPU9250 + #define PRIMARY_IMU_ARG &I2C #endif +#endif - #if defined HAS_MPU6886 - #if !defined HAS_PRIMARY_IMU - #define HAS_PRIMARY_IMU - #define PRIMARY_IMU MPU6886 - #define PRIMARY_IMU_ARG &I2C - #endif - // allow secondary MPU - #if defined HAS_MPU9250 - #if !defined HAS_SECONDARY_IMU - #pragma message "Enabling secondary IMU (MPU9250)" - #define HAS_SECONDARY_IMU - #define SECONDARY_IMU MPU9250 - #define SECONDARY_IMU_ARG &I2C - #endif +#if defined HAS_MPU6886 + #if !defined HAS_PRIMARY_IMU + #define HAS_PRIMARY_IMU + #define PRIMARY_IMU MPU6886 + #define PRIMARY_IMU_ARG &I2C + #endif + // allow secondary MPU + #if defined HAS_MPU9250 + #if !defined HAS_SECONDARY_IMU + #pragma message "Enabling secondary IMU (MPU9250)" + #define HAS_SECONDARY_IMU + #define SECONDARY_IMU MPU9250 + #define SECONDARY_IMU_ARG &I2C #endif #endif +#endif - class M5Stack - { - public: - M5Stack(); - void begin(bool LCDEnable = true, bool SDEnable = SD_ENABLE, bool SerialEnable = true, bool I2CEnable = false, bool ScreenShotEnable = false); - void update(); - - bool sd_force_enable = SD_ENABLE; - bool sd_begin(void); - bool sd_begun = false; - void sd_end(void); - SPIClass *SD_SPI = nullptr; - BaseType_t SD_CORE_ID = 1; - - M5Display Lcd; // LCD - ScreenShotService ScreenShot; // ScreenShots ! - NVSUtils NVS; // NVS Utilities - I2CUtil I2C = I2CUtil(); // I2C Scanner && Twatch I2C bus - //I2CUtil I2C = I2CUtil_Core; - Button BtnA = Button(BUTTON_A_PIN, true, DEBOUNCE_MS); - Button BtnB = Button(BUTTON_B_PIN, true, DEBOUNCE_MS); - Button BtnC = Button(BUTTON_C_PIN, true, DEBOUNCE_MS); - - #if defined ARDUINO_ODROID_ESP32 - #define DEBOUNCE_MS_XY 5 - Button JOY_Y = Button(BUTTON_JOY_Y_PIN, true, DEBOUNCE_MS_XY); - Button JOY_X = Button(BUTTON_JOY_X_PIN, true, DEBOUNCE_MS_XY); - Button BtnMenu = Button(BUTTON_MENU_PIN, true, DEBOUNCE_MS); - Button BtnVolume = Button(BUTTON_VOLUME_PIN, true, DEBOUNCE_MS); - Button BtnSelect = Button(BUTTON_SELECT_PIN, true, DEBOUNCE_MS); - Button BtnStart = Button(BUTTON_START_PIN, true, DEBOUNCE_MS); - // Odroid-Go battery controller uses raw readings on adc1 - Battery battery; - #endif +class M5Stack +{ + public: + M5Stack(); + void begin(bool LCDEnable = true, bool SDEnable = SD_ENABLE, bool SerialEnable = true, bool I2CEnable = false, bool ScreenShotEnable = false); + void update(); + + bool sd_force_enable = SD_ENABLE; + bool sd_begin(void); + bool sd_begun = false; + void sd_end(void); + SPIClass *SD_SPI = nullptr; + BaseType_t SD_CORE_ID = 1; + + M5Display Lcd; // LCD + ScreenShotService ScreenShot; // ScreenShots ! + NVSUtils NVS; // NVS Utilities + I2CUtil I2C = I2CUtil(); // I2C Scanner && Twatch I2C bus + //I2CUtil I2C = I2CUtil_Core; + Button BtnA = Button(BUTTON_A_PIN, true, DEBOUNCE_MS); + Button BtnB = Button(BUTTON_B_PIN, true, DEBOUNCE_MS); + Button BtnC = Button(BUTTON_C_PIN, true, DEBOUNCE_MS); + + #if defined ARDUINO_ODROID_ESP32 + #define DEBOUNCE_MS_XY 5 + Button JOY_Y = Button(BUTTON_JOY_Y_PIN, true, DEBOUNCE_MS_XY); + Button JOY_X = Button(BUTTON_JOY_X_PIN, true, DEBOUNCE_MS_XY); + Button BtnMenu = Button(BUTTON_MENU_PIN, true, DEBOUNCE_MS); + Button BtnVolume = Button(BUTTON_VOLUME_PIN, true, DEBOUNCE_MS); + Button BtnSelect = Button(BUTTON_SELECT_PIN, true, DEBOUNCE_MS); + Button BtnStart = Button(BUTTON_START_PIN, true, DEBOUNCE_MS); + // Odroid-Go battery controller uses raw readings on adc1 + Battery battery; + #endif - #if defined HAS_BM8563 - RTC_BM8563 Rtc; - #endif + #if defined HAS_BM8563 + RTC_BM8563 Rtc; + #endif - #if defined( ARDUINO_M5STACK_Core2 ) // M5Core2 C - // Buttons emulation - ButtonTouchReader *M5Core2TouchButtonEmu = nullptr; - #endif + #if defined( ARDUINO_M5STACK_Core2 ) // M5Core2 C + // Buttons emulation + ButtonTouchReader *M5Core2TouchButtonEmu = nullptr; + #endif - #if defined HAS_PCF8563 - PCF8563_Class *Rtc = nullptr; - #endif - #if defined HAS_AXP202 - AXP20X_Class *Axp = new AXP20X_Class(); - #endif + #if defined HAS_PCF8563 + PCF8563_Class *Rtc = nullptr; + #endif + #if defined HAS_AXP202 + AXP20X_Class *Axp = new AXP20X_Class(); + #endif - #if defined HAS_RTC - void setSystemTimeFromRtc(); - void setRtcTime( uint16_t year, uint8_t month, uint8_t day , uint8_t hours, uint8_t minutes, uint8_t seconds ); - #endif + #if defined HAS_RTC + void setSystemTimeFromRtc(); + void setRtcTime( uint16_t year, uint8_t month, uint8_t day , uint8_t hours, uint8_t minutes, uint8_t seconds ); + #endif - #if defined HAS_SPEAKER - // Can make noise - SPEAKER Speaker; - #endif + #if defined HAS_SPEAKER + // Can make noise + SPEAKER Speaker; + #endif - #if defined HAS_PRIMARY_IMU - // primary accel/gyro from board config - PRIMARY_IMU IMU = PRIMARY_IMU(PRIMARY_IMU_ARG); - #else - #if defined HAS_MPU9250 - // default primary accel/gyro - MPU9250 IMU = MPU9250( &I2C ); - #endif + #if defined HAS_PRIMARY_IMU + // primary accel/gyro from board config + PRIMARY_IMU IMU = PRIMARY_IMU(PRIMARY_IMU_ARG); + #else + #if defined HAS_MPU9250 + // default primary accel/gyro + MPU9250 IMU = MPU9250( &I2C ); #endif + #endif - #if defined HAS_SECONDARY_IMU - SECONDARY_IMU IMU2 = SECONDARY_IMU(SECONDARY_IMU_ARG); - #endif + #if defined HAS_SECONDARY_IMU + SECONDARY_IMU IMU2 = SECONDARY_IMU(SECONDARY_IMU_ARG); + #endif - #if defined HAS_AXP192 - //!Power - AXP192 Axp = AXP192(); - void setPowerBoostKeepOn(bool en) __attribute__((deprecated)); // Function has been moved to Power class.(for compatibility) This name will be removed in a future release. - void setWakeupButton(uint8_t button) __attribute__((deprecated)); // Function has been moved to Power class.(for compatibility) This name will be removed in a future release. - void powerOFF() { Axp.PowerOff(); } - void powerOff() { Axp.PowerOff(); } - #endif + #if defined HAS_AXP192 + //!Power + AXP192 Axp = AXP192(); + void setPowerBoostKeepOn(bool en) __attribute__((deprecated)); // Function has been moved to Power class.(for compatibility) This name will be removed in a future release. + void setWakeupButton(uint8_t button) __attribute__((deprecated)); // Function has been moved to Power class.(for compatibility) This name will be removed in a future release. + void powerOFF() { Axp.PowerOff(); } + void powerOff() { Axp.PowerOff(); } + #endif - #if defined HAS_IP5306 // legacy M5Stack/M5Fire support - POWER Power; - void setPowerBoostKeepOn(bool en) { Power.setPowerBoostKeepOn(en); } ; - void setWakeupButton(uint8_t button) { Power.setWakeupButton(button); }; - void powerOFF() { Power.deepSleep(); } - void powerOff() { powerOFF(); } - #endif + #if defined HAS_IP5306 // legacy M5Stack/M5Fire support + POWER Power; + void setPowerBoostKeepOn(bool en) { Power.setPowerBoostKeepOn(en); } ; + void setWakeupButton(uint8_t button) { Power.setWakeupButton(button); }; + void powerOFF() { Power.deepSleep(); } + void powerOff() { powerOFF(); } + #endif - // UART - // HardwareSerial Serial0 = HardwareSerial(0); - // HardwareSerial Serial2 = HardwareSerial(2); + // UART + // HardwareSerial Serial0 = HardwareSerial(0); + // HardwareSerial Serial2 = HardwareSerial(2); - private: - bool isInited; - }; + private: + bool isInited; +}; - extern M5Stack M5; - #define m5 M5 - #define lcd Lcd +extern M5Stack M5; +#define m5 M5 +#define lcd Lcd -#endif diff --git a/src/M5Display.cpp b/src/M5Display.cpp index bfe1cca..bdc155b 100644 --- a/src/M5Display.cpp +++ b/src/M5Display.cpp @@ -4,11 +4,10 @@ void M5Display::progressBar(int x, int y, int w, int h, uint8_t val, uint16_t co drawRect(x, y, w, h, color); if( val>100) val = 100; if( val==0 ) { - fillRect(x+1, y+1, w-2, h-2, bgcolor); + fillRect(x + 1, y + 1, w-2, h - 2, bgcolor); } else { int fillw = (w * (((float)val) / 100.0)) -2; - fillRect(x + 1, y + 1, fillw, h - 2, color); - fillRect(x + 1, y + 1 + fillw, w-fillw, h - 2, bgcolor); + fillRect(x + 1, y + 1, fillw-2, h - 2, color); + fillRect(x + fillw + 1, y + 1, w-fillw-2, h - 2, bgcolor); } - } diff --git a/src/drivers/common/Button/Button.h b/src/drivers/common/Button/Button.h index ed5076e..53df20f 100644 --- a/src/drivers/common/Button/Button.h +++ b/src/drivers/common/Button/Button.h @@ -17,7 +17,8 @@ #define DPAD_V_HALF 1 #define DPAD_V_NONE 0 -class Button { +class Button +{ public: Button(uint8_t pin, uint8_t invert, uint32_t dbTime); uint8_t read(); From 8f750589fd242fdc03e38cbebf7f145c83f4bceb Mon Sep 17 00:00:00 2001 From: tobozo Date: Sun, 28 Nov 2021 13:33:17 +0100 Subject: [PATCH 12/20] macro tweak --- src/gitTagVersion.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gitTagVersion.h b/src/gitTagVersion.h index 16a3da6..caaba49 100644 --- a/src/gitTagVersion.h +++ b/src/gitTagVersion.h @@ -1,3 +1,5 @@ +#pragma once + #define ECC_VERSION_MAJOR 1 #define ECC_VERSION_MINOR 2 #define ECC_VERSION_PATCH 7 From af71a2b9f72fe5c2c25b1170449eb5b09caa8f0c Mon Sep 17 00:00:00 2001 From: tobozo Date: Thu, 9 Dec 2021 14:06:27 +0100 Subject: [PATCH 13/20] TTGO Lora32_v2 tweaks --- src/Config.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Config.h b/src/Config.h index 4a18aea..4bcf52b 100644 --- a/src/Config.h +++ b/src/Config.h @@ -260,8 +260,9 @@ // ARDUINO_BOARD="TTGO_LoRa32_V2" // ARDUINO_VARIANT="ttgo-lora32-v2" - #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE + #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG #pragma message "TTGO_LoRa32_v2 SELECTED" + #undef LGFX_AUTODETECT #endif // !!! ARDUINO_TTGO_LoRa32_v2 does not exist in boards.txt !!! @@ -287,7 +288,7 @@ #define TFCARD_CS_PIN 13 #define SD_ENABLE 1 #define TFCARD_USE_WIRE1 - #define TFCARD_SPI_HOST HSPI_HOST + #define TFCARD_SPI_HOST SPI_HOST // disabled features #define SPEAKER_PIN -1 #define BUTTON_A_PIN -1 From 7d3ef15ee2b64b4758ff9c2947c7a8d7f42de0db Mon Sep 17 00:00:00 2001 From: tobozo Date: Thu, 9 Dec 2021 14:08:11 +0100 Subject: [PATCH 14/20] BREAKING CHANGE: changed ScreenShot type from object to pointer --- src/ESP32-Chimera-Core.cpp | 32 +- src/ESP32-Chimera-Core.h | 7 +- .../ScreenShotService/BMP/TinyBMPEncoder.cpp | 5 - .../ScreenShotService/BMP/TinyBMPEncoder.h | 7 +- .../ScreenShotService/GIF/TinyGIFEncoder.cpp | 1108 ++++++++--------- .../ScreenShotService/GIF/TinyGIFEncoder.h | 11 +- .../ScreenShotService/JPG/TinyJPEGEncoder.cpp | 3 - .../ScreenShotService/JPG/TinyJPEGEncoder.h | 5 +- .../ScreenShotService/PNG/FatPNGEncoder.cpp | 6 +- .../ScreenShotService/PNG/FatPNGEncoder.h | 8 +- src/utility/ScreenShotService/ScreenShot.cpp | 98 +- src/utility/ScreenShotService/ScreenShot.h | 18 +- 12 files changed, 622 insertions(+), 686 deletions(-) diff --git a/src/ESP32-Chimera-Core.cpp b/src/ESP32-Chimera-Core.cpp index 87125c3..ce6069e 100644 --- a/src/ESP32-Chimera-Core.cpp +++ b/src/ESP32-Chimera-Core.cpp @@ -63,7 +63,7 @@ void M5Stack::begin(bool LCDEnable, bool SDEnable, bool SerialEnable, bool I2CEn //#ifdef LILYGO_WATCH_2020_V1 //In the 2020V1 version, the ST7789 chip power supply //is shared with the backlight, so LDO2 cannot be turned off - log_w("Setting power output for ST7789"); + log_d("Setting power output for ST7789"); Axp->setPowerOutPut(AXP202_LDO2, AXP202_ON); //#endif /*LILYGO_WATCH_2020_V1*/ //#ifdef LILYGO_WATCH_2020_V2 @@ -83,10 +83,13 @@ void M5Stack::begin(bool LCDEnable, bool SDEnable, bool SerialEnable, bool I2CEn log_d("Enabling LCD"); Lcd.begin(); + + ScreenShot = new ScreenShotService( &Lcd, &M5STACK_SD ); + if( ScreenShotEnable == true ) { #if defined HAS_SDCARD - ScreenShot.init( &Lcd, M5STACK_SD ); - ScreenShot.begin(); + ScreenShot->init(); + ScreenShot->begin(); #endif } } @@ -107,7 +110,6 @@ void M5Stack::begin(bool LCDEnable, bool SDEnable, bool SerialEnable, bool I2CEn //Speaker.begin(); #endif - // Buttons init #ifdef ARDUINO_DDUINO32_XS pinMode(BUTTON_A_PIN, INPUT_PULLUP); @@ -198,23 +200,23 @@ bool M5Stack::sd_begin(void) #if defined TFCARD_SPI_HOST if( TFCARD_SPI_HOST==VSPI_HOST ) { SD_SPI = new SPIClass(VSPI); - log_i("SD will use VSPI"); + log_d("SD will use VSPI"); }else if( TFCARD_SPI_HOST==HSPI_HOST ) { SD_SPI = new SPIClass(HSPI); - log_i("SD will use HSPI"); + log_d("SD will use HSPI"); } else if( TFCARD_SPI_HOST==SPI_HOST ) { SD_SPI = new SPIClass(SPI); - log_i("SD will use SPI"); + log_d("SD will use SPI"); } else { log_e("No TFCARD_SPI_HOST selected in config"); return false; } - log_i("TFCARD_SPI_HOST=%d, SPI_HOST=%d, HSPI_HOST=%d, VSPI_HOST=%d from core #%d", TFCARD_SPI_HOST, SPI_HOST, HSPI_HOST, VSPI_HOST, SD_CORE_ID ); -// #define SPI_HOST SPI1_HOST -// #define HSPI_HOST SPI2_HOST -// #define VSPI_HOST SPI3_HOST + log_d("TFCARD_SPI_HOST=%d, SPI_HOST=%d, HSPI_HOST=%d, VSPI_HOST=%d from core #%d", TFCARD_SPI_HOST, SPI_HOST, HSPI_HOST, VSPI_HOST, SD_CORE_ID ); + // #define SPI_HOST SPI1_HOST + // #define HSPI_HOST SPI2_HOST + // #define VSPI_HOST SPI3_HOST #else - log_i("SD will use HSPI (default)"); + log_d("SD will use HSPI (default)"); SD_SPI = new SPIClass(HSPI); #endif SD_SPI->begin(TFCARD_SCLK_PIN, TFCARD_MISO_PIN, TFCARD_MOSI_PIN, TFCARD_CS_PIN); @@ -223,7 +225,7 @@ bool M5Stack::sd_begin(void) log_e("SD Card Mount Failed pins scl/miso/mosi/cs %d/%d/%d/%d from core #%d", TFCARD_SCLK_PIN, TFCARD_MISO_PIN, TFCARD_MOSI_PIN, TFCARD_CS_PIN, SD_CORE_ID ); return false; } else { - log_w( "SD Card Mount Success on pins scl/miso/mosi/cs %d/%d/%d/%d from core #%d", TFCARD_SCLK_PIN, TFCARD_MISO_PIN, TFCARD_MOSI_PIN, TFCARD_CS_PIN, SD_CORE_ID ); + log_d( "SD Card Mount Success on pins scl/miso/mosi/cs %d/%d/%d/%d from core #%d", TFCARD_SCLK_PIN, TFCARD_MISO_PIN, TFCARD_MOSI_PIN, TFCARD_CS_PIN, SD_CORE_ID ); } sd_begun = true; return true; @@ -231,7 +233,7 @@ bool M5Stack::sd_begin(void) #else #if defined HAS_SDCARD - log_w("Enabling SD from TFCARD_CS_PIN #%d at %d Hz from core #%d", TFCARD_CS_PIN, TFCARD_SPI_FREQ, SD_CORE_ID ); + log_d("Enabling SD from TFCARD_CS_PIN #%d at %d Hz from core #%d", TFCARD_CS_PIN, TFCARD_SPI_FREQ, SD_CORE_ID ); M5STACK_SD.end(); ret = M5STACK_SD.begin(TFCARD_CS_PIN, SPI, TFCARD_SPI_FREQ); #endif @@ -313,7 +315,7 @@ void M5Stack::sd_end(void) ); Serial.println(&sysnow,"System Date/Time set to: %B %d %Y %H:%M:%S (%A)"); } else { - log_e("System time could not be adjusted from RTC"); + log_w("System time could not be adjusted from RTC"); } } diff --git a/src/ESP32-Chimera-Core.h b/src/ESP32-Chimera-Core.h index 6833482..a9491df 100644 --- a/src/ESP32-Chimera-Core.h +++ b/src/ESP32-Chimera-Core.h @@ -138,7 +138,7 @@ class M5Stack BaseType_t SD_CORE_ID = 1; M5Display Lcd; // LCD - ScreenShotService ScreenShot; // ScreenShots ! + ScreenShotService *ScreenShot; // ScreenShots ! NVSUtils NVS; // NVS Utilities I2CUtil I2C = I2CUtil(); // I2C Scanner && Twatch I2C bus //I2CUtil I2C = I2CUtil_Core; @@ -224,6 +224,5 @@ class M5Stack }; extern M5Stack M5; -#define m5 M5 -#define lcd Lcd - +//#define m5 M5 // <<< is this really needed ? +//#define lcd Lcd // <<< also this ? diff --git a/src/utility/ScreenShotService/BMP/TinyBMPEncoder.cpp b/src/utility/ScreenShotService/BMP/TinyBMPEncoder.cpp index ea985e3..eb2e1b9 100644 --- a/src/utility/ScreenShotService/BMP/TinyBMPEncoder.cpp +++ b/src/utility/ScreenShotService/BMP/TinyBMPEncoder.cpp @@ -29,11 +29,6 @@ #include "TinyBMPEncoder.h" -void BMP_Encoder::init( M5Display *tft, fs::FS &fileSystem ) { - _tft = tft; - _fileSystem = &fileSystem; -} - bool BMP_Encoder::encodeToFile( const char* filename, const int imageW, const int imageH ) { return encodeToFile( filename, 0, 0, imageW, imageH ); } diff --git a/src/utility/ScreenShotService/BMP/TinyBMPEncoder.h b/src/utility/ScreenShotService/BMP/TinyBMPEncoder.h index 5dcefb5..e598b7e 100644 --- a/src/utility/ScreenShotService/BMP/TinyBMPEncoder.h +++ b/src/utility/ScreenShotService/BMP/TinyBMPEncoder.h @@ -26,7 +26,7 @@ * OTHER DEALINGS IN THE SOFTWARE. * */ -#ifndef __TINY_BMP_ENCODER_H +#pragma once #define __TINY_BMP_ENCODER_H #include "../../../M5Display.h" @@ -35,7 +35,8 @@ class BMP_Encoder { public: - void init( M5Display *tft, fs::FS &fileSystem ); + BMP_Encoder( M5Display *tft, fs::FS *fileSystem ) : _tft(tft), _fileSystem(fileSystem) { }; + bool encodeToFile( const char* filename, const int imageW, const int imageH ); bool encodeToFile( const char* filename, const int imageX, const int imageY, const int imageW, const int imageH ); @@ -47,4 +48,4 @@ class BMP_Encoder { }; -#endif // __TINY_BMP_ENCODER_H + diff --git a/src/utility/ScreenShotService/GIF/TinyGIFEncoder.cpp b/src/utility/ScreenShotService/GIF/TinyGIFEncoder.cpp index 1acec5a..78b16f1 100644 --- a/src/utility/ScreenShotService/GIF/TinyGIFEncoder.cpp +++ b/src/utility/ScreenShotService/GIF/TinyGIFEncoder.cpp @@ -29,11 +29,9 @@ #include "TinyGIFEncoder.h" -void GIF_Encoder::init( M5Display *tft, fs::FS &fileSystem ) { - _tft = tft; - _fileSystem = &fileSystem; +void GIF_Encoder::init() { if( !psramInit() ) { - log_n("[INFO] No PSRAM found, GIF Encoding is disabled"); + log_n("[INFO] No PSRAM found, GIF Encoding won't work"); } } @@ -45,7 +43,6 @@ bool GIF_Encoder::encodeToFile( const char* filename, const int imageW, const in bool GIF_Encoder::encodeToFile( const char* filename, const int imageX, const int imageY, const int width, const int height ) { - uint8_t *imageRGB = (uint8_t*)ps_calloc( width*height*3, sizeof(uint8_t) ); if( imageRGB == nullptr ) { log_n("Unable to allocate %d bytes for rgb image capture", width*height*3 ); @@ -104,236 +101,208 @@ int GIF_Encoder::IAbs(int i) // this is the major hotspot in the code at the moment. void GIF_Encoder::GetClosestPaletteColor(GifPalette* pPal, int r, int g, int b, int& bestInd, int& bestDiff, int treeRoot) { - // base case, reached the bottom of the tree - if(treeRoot > (1<bitDepth)-1) - { - int ind = treeRoot-(1<bitDepth); - if(ind == kGifTransIndex) return; - - // check whether this color is better than the current winner - int r_err = r - ((int32_t)pPal->r[ind]); - int g_err = g - ((int32_t)pPal->g[ind]); - int b_err = b - ((int32_t)pPal->b[ind]); - int diff = IAbs(r_err)+IAbs(g_err)+IAbs(b_err); - - if(diff < bestDiff) - { - bestInd = ind; - bestDiff = diff; - } - - return; + // base case, reached the bottom of the tree + if(treeRoot > (1<bitDepth)-1) { + int ind = treeRoot-(1<bitDepth); + if(ind == kGifTransIndex) return; + + // check whether this color is better than the current winner + int r_err = r - ((int32_t)pPal->r[ind]); + int g_err = g - ((int32_t)pPal->g[ind]); + int b_err = b - ((int32_t)pPal->b[ind]); + int diff = IAbs(r_err)+IAbs(g_err)+IAbs(b_err); + + if(diff < bestDiff) { + bestInd = ind; + bestDiff = diff; } + return; + } - // take the appropriate color (r, g, or b) for this node of the k-d tree - int comps[3]; comps[0] = r; comps[1] = g; comps[2] = b; - int splitComp = comps[pPal->treeSplitElt[treeRoot]]; - - int splitPos = pPal->treeSplit[treeRoot]; - if(splitPos > splitComp) - { - // check the left subtree - GetClosestPaletteColor(pPal, r, g, b, bestInd, bestDiff, treeRoot*2); - if( bestDiff > splitPos - splitComp ) - { - // cannot prove there's not a better value in the right subtree, check that too - GetClosestPaletteColor(pPal, r, g, b, bestInd, bestDiff, treeRoot*2+1); - } + // take the appropriate color (r, g, or b) for this node of the k-d tree + int comps[3]; comps[0] = r; comps[1] = g; comps[2] = b; + int splitComp = comps[pPal->treeSplitElt[treeRoot]]; + + int splitPos = pPal->treeSplit[treeRoot]; + if(splitPos > splitComp) { + // check the left subtree + GetClosestPaletteColor(pPal, r, g, b, bestInd, bestDiff, treeRoot*2); + if( bestDiff > splitPos - splitComp ) { + // cannot prove there's not a better value in the right subtree, check that too + GetClosestPaletteColor(pPal, r, g, b, bestInd, bestDiff, treeRoot*2+1); } - else - { - GetClosestPaletteColor(pPal, r, g, b, bestInd, bestDiff, treeRoot*2+1); - if( bestDiff > splitComp - splitPos ) - { - GetClosestPaletteColor(pPal, r, g, b, bestInd, bestDiff, treeRoot*2); - } + } else { + GetClosestPaletteColor(pPal, r, g, b, bestInd, bestDiff, treeRoot*2+1); + if( bestDiff > splitComp - splitPos ) { + GetClosestPaletteColor(pPal, r, g, b, bestInd, bestDiff, treeRoot*2); } + } } + void GIF_Encoder::SwapPixels(uint8_t* image, int pixA, int pixB) { - uint8_t rA = image[pixA*4]; - uint8_t gA = image[pixA*4+1]; - uint8_t bA = image[pixA*4+2]; - uint8_t aA = image[pixA*4+3]; - - uint8_t rB = image[pixB*4]; - uint8_t gB = image[pixB*4+1]; - uint8_t bB = image[pixB*4+2]; - uint8_t aB = image[pixA*4+3]; - - image[pixA*4] = rB; - image[pixA*4+1] = gB; - image[pixA*4+2] = bB; - image[pixA*4+3] = aB; - - image[pixB*4] = rA; - image[pixB*4+1] = gA; - image[pixB*4+2] = bA; - image[pixB*4+3] = aA; + uint8_t rA = image[pixA*4]; + uint8_t gA = image[pixA*4+1]; + uint8_t bA = image[pixA*4+2]; + uint8_t aA = image[pixA*4+3]; + + uint8_t rB = image[pixB*4]; + uint8_t gB = image[pixB*4+1]; + uint8_t bB = image[pixB*4+2]; + uint8_t aB = image[pixA*4+3]; + + image[pixA*4] = rB; + image[pixA*4+1] = gB; + image[pixA*4+2] = bB; + image[pixA*4+3] = aB; + + image[pixB*4] = rA; + image[pixB*4+1] = gA; + image[pixB*4+2] = bA; + image[pixB*4+3] = aA; } // just the partition operation from quicksort int GIF_Encoder::Partition(uint8_t* image, const int left, const int right, const int elt, int pivotIndex) { - const int pivotValue = image[(pivotIndex)*4+elt]; - SwapPixels(image, pivotIndex, right-1); - int storeIndex = left; - bool split = 0; - for(int ii=left; ii neededCenter) - PartitionByMedian(image, left, pivotIndex, com, neededCenter); - - if(pivotIndex < neededCenter) - PartitionByMedian(image, pivotIndex+1, right, com, neededCenter); - } + if(left < right-1) { + int pivotIndex = left + (right-left)/2; + pivotIndex = Partition(image, left, right, com, pivotIndex); + // Only "sort" the section of the array that contains the median + if(pivotIndex > neededCenter) + PartitionByMedian(image, left, pivotIndex, com, neededCenter); + if(pivotIndex < neededCenter) + PartitionByMedian(image, pivotIndex+1, right, com, neededCenter); + } } // Builds a palette by creating a balanced k-d tree of all pixels in the image void GIF_Encoder::SplitPalette(uint8_t* image, int numPixels, int firstElt, int lastElt, int splitElt, int splitDist, int treeNode, bool buildForDither, GifPalette* pal) { - if(lastElt <= firstElt || numPixels == 0) - return; - - // base case, bottom of the tree - if(lastElt == firstElt+1) - { - if(buildForDither) - { - // Dithering needs at least one color as dark as anything - // in the image and at least one brightest color - - // otherwise it builds up error and produces strange artifacts - if( firstElt == 1 ) - { - // special case: the darkest color in the image - uint32_t r=255, g=255, b=255; - for(int ii=0; iir[firstElt] = (uint8_t)r; - pal->g[firstElt] = (uint8_t)g; - pal->b[firstElt] = (uint8_t)b; - - return; - } - - if( firstElt == (1 << pal->bitDepth)-1 ) - { - // special case: the lightest color in the image - uint32_t r=0, g=0, b=0; - for(int ii=0; iir[firstElt] = (uint8_t)r; - pal->g[firstElt] = (uint8_t)g; - pal->b[firstElt] = (uint8_t)b; - - return; - } + if(lastElt <= firstElt || numPixels == 0) + return; + + // base case, bottom of the tree + if(lastElt == firstElt+1) { + if(buildForDither) { + // Dithering needs at least one color as dark as anything + // in the image and at least one brightest color - + // otherwise it builds up error and produces strange artifacts + if( firstElt == 1 ) { + // special case: the darkest color in the image + uint32_t r=255, g=255, b=255; + for(int ii=0; iir[firstElt] = (uint8_t)r; + pal->g[firstElt] = (uint8_t)g; + pal->b[firstElt] = (uint8_t)b; + return; + } + + if( firstElt == (1 << pal->bitDepth)-1 ) { + // special case: the lightest color in the image + uint32_t r=0, g=0, b=0; + for(int ii=0; iir[firstElt] = (uint8_t)r; pal->g[firstElt] = (uint8_t)g; pal->b[firstElt] = (uint8_t)b; - return; + } } - // Find the axis with the largest range - int minR = 255, maxR = 0; - int minG = 255, maxG = 0; - int minB = 255, maxB = 0; - for(int ii=0; ii maxR) maxR = r; - if(r < minR) minR = r; + r += (uint64_t)numPixels / 2; // round to nearest + g += (uint64_t)numPixels / 2; + b += (uint64_t)numPixels / 2; - if(g > maxG) maxG = g; - if(g < minG) minG = g; + r /= (uint64_t)numPixels; + g /= (uint64_t)numPixels; + b /= (uint64_t)numPixels; - if(b > maxB) maxB = b; - if(b < minB) minB = b; - } + pal->r[firstElt] = (uint8_t)r; + pal->g[firstElt] = (uint8_t)g; + pal->b[firstElt] = (uint8_t)b; + + return; + } + + // Find the axis with the largest range + int minR = 255, maxR = 0; + int minG = 255, maxG = 0; + int minB = 255, maxB = 0; + for(int ii=0; ii maxR) maxR = r; + if(r < minR) minR = r; + + if(g > maxG) maxG = g; + if(g < minG) minG = g; - int rRange = maxR - minR; - int gRange = maxG - minG; - int bRange = maxB - minB; + if(b > maxB) maxB = b; + if(b < minB) minB = b; + } + + int rRange = maxR - minR; + int gRange = maxG - minG; + int bRange = maxB - minB; - // and split along that axis. (incidentally, this means this isn't a "proper" k-d tree but I don't know what else to call it) - int splitCom = 1; - if(bRange > gRange) splitCom = 2; - if(rRange > bRange && rRange > gRange) splitCom = 0; + // and split along that axis. (incidentally, this means this isn't a "proper" k-d tree but I don't know what else to call it) + int splitCom = 1; + if(bRange > gRange) splitCom = 2; + if(rRange > bRange && rRange > gRange) splitCom = 0; - int subPixelsA = numPixels * (splitElt - firstElt) / (lastElt - firstElt); - int subPixelsB = numPixels-subPixelsA; + int subPixelsA = numPixels * (splitElt - firstElt) / (lastElt - firstElt); + int subPixelsB = numPixels-subPixelsA; - PartitionByMedian(image, 0, numPixels, splitCom, subPixelsA); + PartitionByMedian(image, 0, numPixels, splitCom, subPixelsA); - pal->treeSplitElt[treeNode] = (uint8_t)splitCom; - pal->treeSplit[treeNode] = image[subPixelsA*4+splitCom]; + pal->treeSplitElt[treeNode] = (uint8_t)splitCom; + pal->treeSplit[treeNode] = image[subPixelsA*4+splitCom]; - SplitPalette(image, subPixelsA, firstElt, splitElt, splitElt-splitDist, splitDist/2, treeNode*2, buildForDither, pal); - SplitPalette(image+subPixelsA*4, subPixelsB, splitElt, lastElt, splitElt+splitDist, splitDist/2, treeNode*2+1, buildForDither, pal); + SplitPalette(image, subPixelsA, firstElt, splitElt, splitElt-splitDist, splitDist/2, treeNode*2, buildForDither, pal); + SplitPalette(image+subPixelsA*4, subPixelsB, splitElt, lastElt, splitElt+splitDist, splitDist/2, treeNode*2+1, buildForDither, pal); } // Finds all pixels that have changed from the previous image and @@ -342,252 +311,238 @@ void GIF_Encoder::SplitPalette(uint8_t* image, int numPixels, int firstElt, int // changed pixels only. int GIF_Encoder::PickChangedPixels( const uint8_t* lastFrame, uint8_t* frame, int numPixels ) { - int numChanged = 0; - uint8_t* writeIter = frame; + int numChanged = 0; + uint8_t* writeIter = frame; - for (int ii=0; iibitDepth = bitDepth; - - // SplitPalette is destructive (it sorts the pixels by color) so - // we must create a copy of the image for it to destroy - size_t imageSize = (size_t)(width * height * 4 * sizeof(uint8_t)); - uint8_t* destroyableImage = (uint8_t*)GIF_TEMP_MALLOC(imageSize); - if( destroyableImage == nullptr ) { - log_n("Unable to allocate %d bytes", imageSize); - } - memcpy(destroyableImage, nextFrame, imageSize); + pPal->bitDepth = bitDepth; + + // SplitPalette is destructive (it sorts the pixels by color) so + // we must create a copy of the image for it to destroy + size_t imageSize = (size_t)(width * height * 4 * sizeof(uint8_t)); + uint8_t* destroyableImage = (uint8_t*)GIF_TEMP_MALLOC(imageSize); + if( destroyableImage == nullptr ) { + log_n("Unable to allocate %d bytes", imageSize); + } + memcpy(destroyableImage, nextFrame, imageSize); - int numPixels = (int)(width * height); - if(lastFrame) - numPixels = PickChangedPixels(lastFrame, destroyableImage, numPixels); + int numPixels = (int)(width * height); + if(lastFrame) + numPixels = PickChangedPixels(lastFrame, destroyableImage, numPixels); - const int lastElt = 1 << bitDepth; - const int splitElt = lastElt/2; - const int splitDist = splitElt/2; + const int lastElt = 1 << bitDepth; + const int splitElt = lastElt/2; + const int splitDist = splitElt/2; - SplitPalette(destroyableImage, numPixels, 1, lastElt, splitElt, splitDist, 1, buildForDither, pPal); + SplitPalette(destroyableImage, numPixels, 1, lastElt, splitElt, splitDist, 1, buildForDither, pPal); - GIF_TEMP_FREE(destroyableImage); + GIF_TEMP_FREE(destroyableImage); - // add the bottom node for the transparency index - pPal->treeSplit[1 << (bitDepth-1)] = 0; - pPal->treeSplitElt[1 << (bitDepth-1)] = 0; + // add the bottom node for the transparency index + pPal->treeSplit[1 << (bitDepth-1)] = 0; + pPal->treeSplitElt[1 << (bitDepth-1)] = 0; - pPal->r[0] = pPal->g[0] = pPal->b[0] = 0; + pPal->r[0] = pPal->g[0] = pPal->b[0] = 0; } // Implements Floyd-Steinberg dithering, writes palette value to alpha void GIF_Encoder::DitherImage( const uint8_t* lastFrame, const uint8_t* nextFrame, uint8_t* outFrame, uint32_t width, uint32_t height, GifPalette* pPal ) { - int numPixels = (int)(width * height); - - // quantPixels initially holds color*256 for all pixels - // The extra 8 bits of precision allow for sub-single-color error values - // to be propagated - int32_t *quantPixels = (int32_t *)GIF_TEMP_MALLOC(sizeof(int32_t) * (size_t)numPixels * 4); - if( quantPixels == nullptr ) { - log_n("Unable to allocate %d bytes", sizeof(int32_t) * (size_t)numPixels * 4); - } + int numPixels = (int)(width * height); + + // quantPixels initially holds color*256 for all pixels + // The extra 8 bits of precision allow for sub-single-color error values + // to be propagated + int32_t *quantPixels = (int32_t *)GIF_TEMP_MALLOC(sizeof(int32_t) * (size_t)numPixels * 4); + if( quantPixels == nullptr ) { + log_n("Unable to allocate %d bytes", sizeof(int32_t) * (size_t)numPixels * 4); + } - for( int ii=0; iir[bestInd]) * 256; - int32_t g_err = nextPix[1] - int32_t(pPal->g[bestInd]) * 256; - int32_t b_err = nextPix[2] - int32_t(pPal->b[bestInd]) * 256; - - nextPix[0] = pPal->r[bestInd]; - nextPix[1] = pPal->g[bestInd]; - nextPix[2] = pPal->b[bestInd]; - nextPix[3] = bestInd; - - // Propagate the error to the four adjacent locations - // that we haven't touched yet - int quantloc_7 = (int)(yy * width + xx + 1); - int quantloc_3 = (int)(yy * width + width + xx - 1); - int quantloc_5 = (int)(yy * width + width + xx); - int quantloc_1 = (int)(yy * width + width + xx + 1); - - if(quantloc_7 < numPixels) - { - int32_t* pix7 = quantPixels+4*quantloc_7; - pix7[0] += IMax( -pix7[0], r_err * 7 / 16 ); - pix7[1] += IMax( -pix7[1], g_err * 7 / 16 ); - pix7[2] += IMax( -pix7[2], b_err * 7 / 16 ); - } - - if(quantloc_3 < numPixels) - { - int32_t* pix3 = quantPixels+4*quantloc_3; - pix3[0] += IMax( -pix3[0], r_err * 3 / 16 ); - pix3[1] += IMax( -pix3[1], g_err * 3 / 16 ); - pix3[2] += IMax( -pix3[2], b_err * 3 / 16 ); - } - - if(quantloc_5 < numPixels) - { - int32_t* pix5 = quantPixels+4*quantloc_5; - pix5[0] += IMax( -pix5[0], r_err * 5 / 16 ); - pix5[1] += IMax( -pix5[1], g_err * 5 / 16 ); - pix5[2] += IMax( -pix5[2], b_err * 5 / 16 ); - } - - if(quantloc_1 < numPixels) - { - int32_t* pix1 = quantPixels+4*quantloc_1; - pix1[0] += IMax( -pix1[0], r_err / 16 ); - pix1[1] += IMax( -pix1[1], g_err / 16 ); - pix1[2] += IMax( -pix1[2], b_err / 16 ); - } - } + for( uint32_t yy=0; yyr[bestInd]) * 256; + int32_t g_err = nextPix[1] - int32_t(pPal->g[bestInd]) * 256; + int32_t b_err = nextPix[2] - int32_t(pPal->b[bestInd]) * 256; + + nextPix[0] = pPal->r[bestInd]; + nextPix[1] = pPal->g[bestInd]; + nextPix[2] = pPal->b[bestInd]; + nextPix[3] = bestInd; + + // Propagate the error to the four adjacent locations + // that we haven't touched yet + int quantloc_7 = (int)(yy * width + xx + 1); + int quantloc_3 = (int)(yy * width + width + xx - 1); + int quantloc_5 = (int)(yy * width + width + xx); + int quantloc_1 = (int)(yy * width + width + xx + 1); + + if(quantloc_7 < numPixels){ + int32_t* pix7 = quantPixels+4*quantloc_7; + pix7[0] += IMax( -pix7[0], r_err * 7 / 16 ); + pix7[1] += IMax( -pix7[1], g_err * 7 / 16 ); + pix7[2] += IMax( -pix7[2], b_err * 7 / 16 ); + } + + if(quantloc_3 < numPixels){ + int32_t* pix3 = quantPixels+4*quantloc_3; + pix3[0] += IMax( -pix3[0], r_err * 3 / 16 ); + pix3[1] += IMax( -pix3[1], g_err * 3 / 16 ); + pix3[2] += IMax( -pix3[2], b_err * 3 / 16 ); + } + + if(quantloc_5 < numPixels){ + int32_t* pix5 = quantPixels+4*quantloc_5; + pix5[0] += IMax( -pix5[0], r_err * 5 / 16 ); + pix5[1] += IMax( -pix5[1], g_err * 5 / 16 ); + pix5[2] += IMax( -pix5[2], b_err * 5 / 16 ); + } + + if(quantloc_1 < numPixels){ + int32_t* pix1 = quantPixels+4*quantloc_1; + pix1[0] += IMax( -pix1[0], r_err / 16 ); + pix1[1] += IMax( -pix1[1], g_err / 16 ); + pix1[2] += IMax( -pix1[2], b_err / 16 ); + } } + } - // Copy the palettized result to the output buffer - for( int ii=0; iir[bestInd]; - outFrame[1] = pPal->g[bestInd]; - outFrame[2] = pPal->b[bestInd]; - outFrame[3] = (uint8_t)bestInd; - } - - if(lastFrame) lastFrame += 4; - outFrame += 4; - nextFrame += 4; + outFrame[0] = lastFrame[0]; + outFrame[1] = lastFrame[1]; + outFrame[2] = lastFrame[2]; + outFrame[3] = kGifTransIndex; + } else { + // palettize the pixel + int32_t bestDiff = 1000000; + int32_t bestInd = 1; + GetClosestPaletteColor(pPal, nextFrame[0], nextFrame[1], nextFrame[2], bestInd, bestDiff); + + // write the resulting color to the output buffer + outFrame[0] = pPal->r[bestInd]; + outFrame[1] = pPal->g[bestInd]; + outFrame[2] = pPal->b[bestInd]; + outFrame[3] = (uint8_t)bestInd; } + + if(lastFrame) lastFrame += 4; + outFrame += 4; + nextFrame += 4; + } } // insert a single bit void GIF_Encoder::writeBit( GifBitStatus& stat, uint32_t bit ) { - bit = bit & 1; - bit = bit << stat.bitIndex; - stat.byte |= bit; - - ++stat.bitIndex; - if( stat.bitIndex > 7 ) - { - // move the newly-finished byte to the chunk buffer - stat.chunk[stat.chunkIndex++] = stat.byte; - // and start a new byte - stat.bitIndex = 0; - stat.byte = 0; - } + bit = bit & 1; + bit = bit << stat.bitIndex; + stat.byte |= bit; + + ++stat.bitIndex; + if( stat.bitIndex > 7 ) { + // move the newly-finished byte to the chunk buffer + stat.chunk[stat.chunkIndex++] = stat.byte; + // and start a new byte + stat.bitIndex = 0; + stat.byte = 0; + } } // write all bytes so far to the file void GIF_Encoder::writeChunk( fs::File f, GifBitStatus& stat ) { - f.write((int)stat.chunkIndex); - f.write(stat.chunk, stat.chunkIndex); - stat.bitIndex = 0; - stat.byte = 0; - stat.chunkIndex = 0; + f.write((int)stat.chunkIndex); + f.write(stat.chunk, stat.chunkIndex); + stat.bitIndex = 0; + stat.byte = 0; + stat.chunkIndex = 0; } void GIF_Encoder::writeCode( fs::File f, GifBitStatus& stat, uint32_t code, uint32_t length ) { - for( uint32_t ii=0; ii> 1; + for( uint32_t ii=0; ii> 1; - if( stat.chunkIndex == 255 ) - { - writeChunk(f, stat); - } + if( stat.chunkIndex == 255 ) { + writeChunk(f, stat); } + } } @@ -595,142 +550,128 @@ void GIF_Encoder::writeCode( fs::File f, GifBitStatus& stat, uint32_t code, uint // write a 256-color (8-bit) image palette to the file void GIF_Encoder::writePalette( const GifPalette* pPal, fs::File f ) { - f.write(0); // first color: transparency - f.write(0); - f.write(0); - - for(int ii=1; ii<(1 << pPal->bitDepth); ++ii) - { - uint32_t r = pPal->r[ii]; - uint32_t g = pPal->g[ii]; - uint32_t b = pPal->b[ii]; - - f.write((int)r); - f.write((int)g); - f.write((int)b); - } + f.write(0); // first color: transparency + f.write(0); + f.write(0); + + for(int ii=1; ii<(1 << pPal->bitDepth); ++ii) { + uint32_t r = pPal->r[ii]; + uint32_t g = pPal->g[ii]; + uint32_t b = pPal->b[ii]; + + f.write((int)r); + f.write((int)g); + f.write((int)b); + } } // write the image header, LZW-compress and write out the image void GIF_Encoder::writeLzwImage(fs::File f, uint8_t* image, uint32_t left, uint32_t top, uint32_t width, uint32_t height, uint32_t frameDelay, GifPalette* pPal) { - // graphics control extension - f.write(0x21); - f.write(0xf9); - f.write(0x04); - f.write(0x05); // leave prev frame in place, this frame has transparency - f.write(frameDelay & 0xff); - f.write((frameDelay >> 8) & 0xff); - f.write(kGifTransIndex); // transparent color index - f.write(0); - - f.write(0x2c); // image descriptor block - - f.write(left & 0xff); // corner of image in canvas space - f.write((left >> 8) & 0xff); - f.write(top & 0xff); - f.write((top >> 8) & 0xff); - - f.write(width & 0xff); // width and height of image - f.write((width >> 8) & 0xff); - f.write(height & 0xff); - f.write((height >> 8) & 0xff); - - //f.write(0, f); // no local color table, no transparency - //f.write(0x80, f); // no local color table, but transparency - - f.write(0x80 + pPal->bitDepth-1); // local color table present, 2 ^ bitDepth entries - writePalette(pPal, f); - - const int minCodeSize = pPal->bitDepth; - const uint32_t clearCode = 1 << pPal->bitDepth; - - f.write(minCodeSize); // min code size 8 bits - - GifLzwNode* codetree = (GifLzwNode*)GIF_TEMP_MALLOC(sizeof(GifLzwNode)*4096); - if( codetree == nullptr ) { - log_n("Unable to allocate %d bytes", sizeof(GifLzwNode)*4096); - } - - memset(codetree, 0, sizeof(GifLzwNode)*4096); - int32_t curCode = -1; - uint32_t codeSize = (uint32_t)minCodeSize + 1; - uint32_t maxCode = clearCode+1; - - GifBitStatus stat; - stat.byte = 0; - stat.bitIndex = 0; - stat.chunkIndex = 0; + // graphics control extension + f.write(0x21); + f.write(0xf9); + f.write(0x04); + f.write(0x05); // leave prev frame in place, this frame has transparency + f.write(frameDelay & 0xff); + f.write((frameDelay >> 8) & 0xff); + f.write(kGifTransIndex); // transparent color index + f.write(0); + + f.write(0x2c); // image descriptor block + + f.write(left & 0xff); // corner of image in canvas space + f.write((left >> 8) & 0xff); + f.write(top & 0xff); + f.write((top >> 8) & 0xff); + + f.write(width & 0xff); // width and height of image + f.write((width >> 8) & 0xff); + f.write(height & 0xff); + f.write((height >> 8) & 0xff); + + //f.write(0, f); // no local color table, no transparency + //f.write(0x80, f); // no local color table, but transparency + + f.write(0x80 + pPal->bitDepth-1); // local color table present, 2 ^ bitDepth entries + writePalette(pPal, f); + + const int minCodeSize = pPal->bitDepth; + const uint32_t clearCode = 1 << pPal->bitDepth; + + f.write(minCodeSize); // min code size 8 bits + + GifLzwNode* codetree = (GifLzwNode*)GIF_TEMP_MALLOC(sizeof(GifLzwNode)*4096); + if( codetree == nullptr ) { + log_n("Unable to allocate %d bytes", sizeof(GifLzwNode)*4096); + } - writeCode(f, stat, clearCode, codeSize); // start with a fresh LZW dictionary + memset(codetree, 0, sizeof(GifLzwNode)*4096); + int32_t curCode = -1; + uint32_t codeSize = (uint32_t)minCodeSize + 1; + uint32_t maxCode = clearCode+1; + + GifBitStatus stat; + stat.byte = 0; + stat.bitIndex = 0; + stat.chunkIndex = 0; + + writeCode(f, stat, clearCode, codeSize); // start with a fresh LZW dictionary + + for(uint32_t yy=0; yy= (1ul << codeSize) ) { + // dictionary entry count has broken a size barrier, + // we need more bits for codes + codeSize++; + } + if( maxCode == 4095 ) { + // the dictionary is full, clear it out and begin anew + writeCode(f, stat, clearCode, codeSize); // clear tree - for(uint32_t yy=0; yy= (1ul << codeSize) ) - { - // dictionary entry count has broken a size barrier, - // we need more bits for codes - codeSize++; - } - if( maxCode == 4095 ) - { - // the dictionary is full, clear it out and begin anew - writeCode(f, stat, clearCode, codeSize); // clear tree - - memset(codetree, 0, sizeof(GifLzwNode)*4096); - codeSize = (uint32_t)(minCodeSize + 1); - maxCode = clearCode+1; - } - - curCode = nextValue; - } + memset(codetree, 0, sizeof(GifLzwNode)*4096); + codeSize = (uint32_t)(minCodeSize + 1); + maxCode = clearCode+1; } + + curCode = nextValue; + } } + } - // compression footer - writeCode(f, stat, (uint32_t)curCode, codeSize); - writeCode(f, stat, clearCode, codeSize); - writeCode(f, stat, clearCode + 1, (uint32_t)minCodeSize + 1); + // compression footer + writeCode(f, stat, (uint32_t)curCode, codeSize); + writeCode(f, stat, clearCode, codeSize); + writeCode(f, stat, clearCode + 1, (uint32_t)minCodeSize + 1); - // write out the last partial chunk - while( stat.bitIndex ) writeBit(stat, 0); - if( stat.chunkIndex ) writeChunk(f, stat); + // write out the last partial chunk + while( stat.bitIndex ) writeBit(stat, 0); + if( stat.chunkIndex ) writeChunk(f, stat); - f.write(0); // image block terminator + f.write(0); // image block terminator - GIF_TEMP_FREE(codetree); + GIF_TEMP_FREE(codetree); } @@ -740,65 +681,64 @@ void GIF_Encoder::writeLzwImage(fs::File f, uint8_t* image, uint32_t left, uint3 // The delay value is the time between frames in hundredths of a second - note that not all viewers pay much attention to this value. bool GIF_Encoder::begin( fs::FS &fs, const char* filename, uint32_t width, uint32_t height, uint32_t frameDelay, int32_t bitDepth, bool dither ) { - (void)bitDepth; (void)dither; // Mute "Unused argument" warnings + (void)bitDepth; (void)dither; // Mute "Unused argument" warnings - log_d("Will open %s file for writing", filename); - outFile = fs.open( filename, "wb" ); + log_d("Will open %s file for writing", filename); + outFile = fs.open( filename, "wb" ); - if(!outFile) { - log_n("Could not open %s file for writing", filename); - return false; - } + if(!outFile) { + log_n("Could not open %s file for writing", filename); + return false; + } - writerFirstFrame = true; + writerFirstFrame = true; - log_d("Will try to allocate %d bytes", width*height*4); - // allocate - writerOldImage = (uint8_t*)GIF_MALLOC(width*height*4); - if( writerOldImage == nullptr ) { - log_n("Unable to allocate %d bytes", width*height*4); - return false; - } + log_d("Will try to allocate %d bytes", width*height*4); + // allocate + writerOldImage = (uint8_t*)GIF_MALLOC(width*height*4); + if( writerOldImage == nullptr ) { + log_n("Unable to allocate %d bytes", width*height*4); + return false; + } - outFile.print("GIF89a"); - - // screen descriptor - outFile.write(width & 0xff); - outFile.write((width >> 8) & 0xff); - outFile.write(height & 0xff); - outFile.write((height >> 8) & 0xff); - - outFile.write(0xf0); // there is an unsorted global color table of 2 entries - outFile.write(0); // background color - outFile.write(0); // pixels are square (we need to specify this because it's 1989) - - // now the "global" palette (really just a dummy palette) - // color 0: black - outFile.write(0); - outFile.write(0); - outFile.write(0); - // color 1: also black - outFile.write(0); - outFile.write(0); - outFile.write(0); - - if( frameDelay != 0 ) - { - // animation header - outFile.write(0x21); // extension - outFile.write(0xff); // application specific - outFile.write(11); // length 11 - outFile.print("NETSCAPE2.0"); // yes, really - outFile.write(3); // 3 bytes of NETSCAPE2.0 data - - outFile.write(1); // JUST BECAUSE - outFile.write(0); // loop infinitely (byte 0) - outFile.write(0); // loop infinitely (byte 1) - - outFile.write(0); // block terminator - } + outFile.print("GIF89a"); + + // screen descriptor + outFile.write(width & 0xff); + outFile.write((width >> 8) & 0xff); + outFile.write(height & 0xff); + outFile.write((height >> 8) & 0xff); + + outFile.write(0xf0); // there is an unsorted global color table of 2 entries + outFile.write(0); // background color + outFile.write(0); // pixels are square (we need to specify this because it's 1989) + + // now the "global" palette (really just a dummy palette) + // color 0: black + outFile.write(0); + outFile.write(0); + outFile.write(0); + // color 1: also black + outFile.write(0); + outFile.write(0); + outFile.write(0); + + if( frameDelay != 0 ) { + // animation header + outFile.write(0x21); // extension + outFile.write(0xff); // application specific + outFile.write(11); // length 11 + outFile.print("NETSCAPE2.0"); // yes, really + outFile.write(3); // 3 bytes of NETSCAPE2.0 data + + outFile.write(1); // JUST BECAUSE + outFile.write(0); // loop infinitely (byte 0) + outFile.write(0); // loop infinitely (byte 1) + + outFile.write(0); // block terminator + } - return true; + return true; } // writes out a new frame to a GIF in progress. @@ -807,22 +747,22 @@ bool GIF_Encoder::begin( fs::FS &fs, const char* filename, uint32_t width, uint3 // this may be handy to save bits in animations that don't change much. bool GIF_Encoder::writeFrame( const uint8_t* image, uint32_t width, uint32_t height, uint32_t frameDelay, int bitDepth, bool dither ) { - if(!outFile) return false; + if(!outFile) return false; - const uint8_t* oldImage = writerFirstFrame? NULL : writerOldImage; - writerFirstFrame = false; + const uint8_t* oldImage = writerFirstFrame? NULL : writerOldImage; + writerFirstFrame = false; - GifPalette pal; - MakePalette((dither? NULL : oldImage), image, width, height, bitDepth, dither, &pal); + GifPalette pal; + MakePalette((dither? NULL : oldImage), image, width, height, bitDepth, dither, &pal); - if(dither) - DitherImage(oldImage, image, writerOldImage, width, height, &pal); - else - ThresholdImage(oldImage, image, writerOldImage, width, height, &pal); + if(dither) + DitherImage(oldImage, image, writerOldImage, width, height, &pal); + else + ThresholdImage(oldImage, image, writerOldImage, width, height, &pal); - writeLzwImage(outFile, writerOldImage, 0, 0, width, height, frameDelay, &pal); + writeLzwImage(outFile, writerOldImage, 0, 0, width, height, frameDelay, &pal); - return true; + return true; } // writes the EOF code, closes the file handle, and frees temp memory used by a GIF. @@ -830,16 +770,16 @@ bool GIF_Encoder::writeFrame( const uint8_t* image, uint32_t width, uint32_t hei // but it's still a good idea to write it out. bool GIF_Encoder::end() { - if(!outFile) return false; + if(!outFile) return false; - outFile.write( 0x3b); - outFile.close(); + outFile.write( 0x3b); + outFile.close(); - GIF_FREE(writerOldImage); + GIF_FREE(writerOldImage); - writerOldImage = NULL; + writerOldImage = NULL; - return true; + return true; } diff --git a/src/utility/ScreenShotService/GIF/TinyGIFEncoder.h b/src/utility/ScreenShotService/GIF/TinyGIFEncoder.h index eae6072..f1ec8c3 100644 --- a/src/utility/ScreenShotService/GIF/TinyGIFEncoder.h +++ b/src/utility/ScreenShotService/GIF/TinyGIFEncoder.h @@ -26,7 +26,7 @@ // Finally, call GifEnd() to close the file handle and free memory. // -#ifndef gif_h +#pragma once #define gif_h #include "../../../M5Display.h" @@ -89,11 +89,12 @@ struct GifLzwNode -class GIF_Encoder { +class GIF_Encoder +{ public: - - void init( M5Display *tft, fs::FS &fileSystem ); + GIF_Encoder( M5Display *tft, fs::FS *fileSystem ) : _tft(tft), _fileSystem(fileSystem) { }; + void init(); bool encodeToFile( const char* filename, const int width, const int height ); bool encodeToFile( const char* filename, const int imageX, const int imageY, const int width, const int height ); @@ -165,5 +166,3 @@ class GIF_Encoder { }; -#endif - diff --git a/src/utility/ScreenShotService/JPG/TinyJPEGEncoder.cpp b/src/utility/ScreenShotService/JPG/TinyJPEGEncoder.cpp index 4bcf487..02e0cee 100644 --- a/src/utility/ScreenShotService/JPG/TinyJPEGEncoder.cpp +++ b/src/utility/ScreenShotService/JPG/TinyJPEGEncoder.cpp @@ -183,9 +183,6 @@ static uint16_t tjei_be_word( const uint16_t le_word ) { } -void JPEG_Encoder::init( fs::FS &fileSystem ) { - _fileSystem = &fileSystem; -} void JPEG_Encoder::begin( bool ifPsram ) { diff --git a/src/utility/ScreenShotService/JPG/TinyJPEGEncoder.h b/src/utility/ScreenShotService/JPG/TinyJPEGEncoder.h index b39751b..f2cd978 100644 --- a/src/utility/ScreenShotService/JPG/TinyJPEGEncoder.h +++ b/src/utility/ScreenShotService/JPG/TinyJPEGEncoder.h @@ -53,7 +53,7 @@ */ -#ifndef __TINY_JPEG_ENCODER__ +#pragma once #define __TINY_JPEG_ENCODER__ #include "../../../M5Display.h" @@ -189,6 +189,7 @@ typedef void (*jpeg_encoder_callback_t)(uint32_t y, uint32_t h, unsigned char* r class JPEG_Encoder { public: + JPEG_Encoder( fs::FS * fileSystem ) : _fileSystem( fileSystem ) { } fs::File jpegFile; fs::FS * _fileSystem; @@ -196,7 +197,6 @@ class JPEG_Encoder { uint8_t** huffsize = NULL; uint16_t** huffcode = NULL; - void init( fs::FS &fileSystem ); void begin( bool ifPsram = true ); int encodeToFile( const char* dest_path, const int width, const int height, const int numComponents, unsigned char* src_data, jpeg_encoder_callback_t fp, void* device ); int encodeWithFunc( writeFunc* func, fs::File jpegFile, const int quality, const int width, const int height, const int numComponents, unsigned char* src_data, jpeg_encoder_callback_t fp, void* device ); @@ -221,4 +221,3 @@ class JPEG_Encoder { }; // end class -#endif // defined __TINY_JPEG_ENCODER__ diff --git a/src/utility/ScreenShotService/PNG/FatPNGEncoder.cpp b/src/utility/ScreenShotService/PNG/FatPNGEncoder.cpp index 5b7e595..d7c7f39 100644 --- a/src/utility/ScreenShotService/PNG/FatPNGEncoder.cpp +++ b/src/utility/ScreenShotService/PNG/FatPNGEncoder.cpp @@ -38,12 +38,10 @@ #error "miniz.h not found, please update to the latest version of LovyanGFX" #endif -void PNG_Encoder::init( M5Display *tft, fs::FS &fileSystem ) +void PNG_Encoder::init() { - _tft = tft; - _fileSystem = &fileSystem; if( !psramInit() ) { - log_n("[INFO] No PSRAM found, PNG Encoding is disabled"); + log_n("[INFO] No PSRAM found, PNG Encoding won't work"); } } diff --git a/src/utility/ScreenShotService/PNG/FatPNGEncoder.h b/src/utility/ScreenShotService/PNG/FatPNGEncoder.h index 43a5866..616f41f 100644 --- a/src/utility/ScreenShotService/PNG/FatPNGEncoder.h +++ b/src/utility/ScreenShotService/PNG/FatPNGEncoder.h @@ -26,7 +26,7 @@ * OTHER DEALINGS IN THE SOFTWARE. * \*/ -#ifndef __FAT_PNG_ENCODER_H +#pragma once #define __FAT_PNG_ENCODER_H @@ -35,8 +35,8 @@ class PNG_Encoder { public: - - void init( M5Display *tft, fs::FS &fileSystem ); + PNG_Encoder( M5Display *tft, fs::FS *fileSystem ) : _tft(tft), _fileSystem(fileSystem) { }; + void init(); bool encodeToFile( const char* filename, const int imageW, const int imageH ); bool encodeToFile( const char* filename, const int imageX, const int imageY, const int imageW, const int imageH ); @@ -47,4 +47,4 @@ class PNG_Encoder { }; -#endif + diff --git a/src/utility/ScreenShotService/ScreenShot.cpp b/src/utility/ScreenShotService/ScreenShot.cpp index ee81f2d..7b17f8e 100644 --- a/src/utility/ScreenShotService/ScreenShot.cpp +++ b/src/utility/ScreenShotService/ScreenShot.cpp @@ -29,12 +29,12 @@ #include "ScreenShot.h" - -ScreenShotService::ScreenShotService() +/* +ScreenShotService::ScreenShotService( M5Display *tft, fs::FS &fileSystem ) { // wut ? } - +*/ ScreenShotService::~ScreenShotService() { if( _begun ) { @@ -43,15 +43,9 @@ ScreenShotService::~ScreenShotService() } } -void ScreenShotService::init( M5Display *tft, fs::FS &fileSystem ) +void ScreenShotService::init() { if( _inited ) return; - _tft = tft; - _fileSystem = &fileSystem; - BMPEncoder.init( tft, fileSystem ); - PNGEncoder.init( tft, fileSystem ); - JPEGEncoder.init( fileSystem ); - GIFEncoder.init( tft, fileSystem ); // default capture mode is full screen setWindow(0, 0, _tft->width(), _tft->height() ); _inited = true; @@ -77,33 +71,21 @@ void ScreenShotService::setWindow( uint32_t x, uint32_t y, uint32_t w, uint32_t _y = y; _w = w; _h = h; - } bool ScreenShotService::begin( bool ifPsram ) { - if( !_inited ) return false; + if( !_inited ) { + //return false; + init(); + } if( _begun ) return true; if( !displayCanReadPixels() ) { - log_e( "readPixel() test failed, screenshots are disabled" ); + log_n( "readPixel() test failed, screenshots are disabled" ); return false; } - if( ifPsram && psramInit() ) { - log_w("Will attempt to allocate psram for screenshots"); - rgbBuffer = (uint8_t*)ps_calloc( (_w*8*3)+1, sizeof( uint8_t ) ); - } else { - log_w("Will attempt to allocate ram for screenshots"); - // attempt to allocate anyway, and use BMP stream on failure - rgbBuffer = (uint8_t*)calloc( (_w*8*3)+1, sizeof( uint8_t ) ); - } - if( rgbBuffer != NULL ) { - log_w( "ScreenShot Service can use JPG capture" ); - JPEGEncoder.begin( ifPsram ); - } else { - log_w( "ScreenShot Service can use BMP capture" ); - jpegCapture = false; - } + _psram = ifPsram; _begun = true; return true; } @@ -116,13 +98,11 @@ bool ScreenShotService::displayCanReadPixels() uint16_t value_in = _tft->color565(r, g, b); uint16_t value_out; __attribute__((unused)) byte testnum = 0; - - log_w( "Testing display readpixel" ); -// log_w( "Testing display#%04x", TFT_DRIVER ); - + log_d( "Testing display readpixel" ); + // log_w( "Testing display#%04x", TFT_DRIVER ); _tft->drawPixel( 30, 30, value_in ); // <----- Test color value_out = _tft->readPixel( 30,30 ); - log_w( "test#%d: readPixel(as rgb565), expected:0x%04x, got: 0x%04x", testnum++, value_in, value_out ); + log_d( "test#%d: readPixel(as rgb565), expected:0x%04x, got: 0x%04x", testnum++, value_in, value_out ); if( value_in == value_out ) { readPixelSuccess = true; _tft->drawPixel( 30, 30, value_initial ); @@ -166,7 +146,27 @@ void ScreenShotService::snapJPG( const char* name, bool displayAfter ) jpeg_encoder_w = _w; genFileName( name, "jpg" ); uint32_t time_start = millis(); - if ( !JPEGEncoder.encodeToFile( fileName, _w, _h, 3 /*3=RGB,4=RGBA*/, rgbBuffer, &jpeg_encoder_callback, _tft ) ) { + + if( _psram && psramInit() ) { + log_v("Will attempt to allocate psram for screenshots"); + rgbBuffer = (uint8_t*)ps_calloc( (_w*8*3)+1, sizeof( uint8_t ) ); + } else { + log_v("Will attempt to allocate ram for screenshots"); + rgbBuffer = (uint8_t*)calloc( (_w*8*3)+1, sizeof( uint8_t ) ); + _psram = false; + } + if( rgbBuffer != NULL ) { + log_v( "ScreenShot Service can use JPG capture" ); + } else { + log_n( "Not enough ram to use jpeg screenshot" ); + jpegCapture = false; + return; + } + + JPEGEncoder = new JPEG_Encoder( _fileSystem ); + JPEGEncoder->begin( _psram ); + + if ( !JPEGEncoder->encodeToFile( fileName, _w, _h, 3 /*3=RGB,4=RGBA*/, rgbBuffer, &jpeg_encoder_callback, _tft ) ) { log_n( "[ERROR] Could not write JPG file to: %s", fileName ); } else { fs::File outFile = _fileSystem->open( fileName ); @@ -179,6 +179,8 @@ void ScreenShotService::snapJPG( const char* name, bool displayAfter ) delay(5000); } } + delete JPEGEncoder; + free( rgbBuffer ); } @@ -186,7 +188,8 @@ void ScreenShotService::snapBMP( const char* name, bool displayAfter ) { genFileName( name, "bmp" ); uint32_t time_start = millis(); - if( !BMPEncoder.encodeToFile( fileName, _x, _y, _w, _h ) ) { + BMPEncoder = new BMP_Encoder( _tft, _fileSystem ); + if( !BMPEncoder->encodeToFile( fileName, _x, _y, _w, _h ) ) { log_e( "[ERROR] Could not write BMP file to: %s", fileName ); } else { fs::File outFile = _fileSystem->open( fileName ); @@ -199,13 +202,17 @@ void ScreenShotService::snapBMP( const char* name, bool displayAfter ) delay(5000); } } + delete BMPEncoder; } + void ScreenShotService::snapPNG( const char* name, bool displayAfter ) { genFileName( name, "png" ); uint32_t time_start = millis(); - if( !PNGEncoder.encodeToFile( fileName, _x, _y, _w, _h ) ) { + PNGEncoder = new PNG_Encoder( _tft, _fileSystem ); + PNGEncoder->init(); + if( !PNGEncoder->encodeToFile( fileName, _x, _y, _w, _h ) ) { log_e( "[ERROR] Could not write PNG file to: %s", fileName ); } else { fs::File outFile = _fileSystem->open( fileName ); @@ -218,6 +225,7 @@ void ScreenShotService::snapPNG( const char* name, bool displayAfter ) delay(5000); } } + delete PNGEncoder; } @@ -225,7 +233,8 @@ void ScreenShotService::snapGIF( const char* name, bool displayAfter ) { genFileName( name, "gif" ); uint32_t time_start = millis(); - if( !GIFEncoder.encodeToFile( fileName, _x, _y, _w, _h ) ) { + GIFEncoder = new GIF_Encoder( _tft, _fileSystem ); + if( !GIFEncoder->encodeToFile( fileName, _x, _y, _w, _h ) ) { log_e( "[ERROR] Could not write GIF file to: %s", fileName ); } else { fs::File outFile = _fileSystem->open( fileName ); @@ -238,22 +247,19 @@ void ScreenShotService::snapGIF( const char* name, bool displayAfter ) // delay(5000); //} } + delete GIFEncoder; } void ScreenShotService::checkFolder( const char* path ) { *folderName = {0}; - if( path[0] =='/' ) { - sprintf( folderName, "%s", path ); - } else { - sprintf( folderName, "/%s", path ); - } + sprintf( folderName, "%s%s", path[0] =='/'?"":"/", path ); if( ! _fileSystem->exists( folderName ) ) { - log_d( "Creating path %s", folderName ); + log_v( "Creating path %s", folderName ); _fileSystem->mkdir( folderName ); } else { - log_d( "Path %s exists", folderName ); + log_v( "Path %s exists", folderName ); } } @@ -267,9 +273,9 @@ void ScreenShotService::genFileName( const char* name, const char* extension ) struct tm now; getLocalTime( &now, 0 ); sprintf( fileName, "%s/%s-%04d-%02d-%02d_%02dh%02dm%02ds.%s", folderName, name, (now.tm_year)+1900,( now.tm_mon)+1, now.tm_mday,now.tm_hour , now.tm_min, now.tm_sec, extension ); - log_d( "has prefix: %s, has folder:%s, has extension: /%s, got fileName: %s", name, folderName, extension, fileName ); + log_v( "has prefix: %s, has folder:%s, has extension: /%s, got fileName: %s", name, folderName, extension, fileName ); } else { - log_d( "has path: %s", name ); + log_v( "has path: %s", name ); sprintf( fileName, "%s", name ); } } diff --git a/src/utility/ScreenShotService/ScreenShot.h b/src/utility/ScreenShotService/ScreenShot.h index adaaa50..8612e75 100644 --- a/src/utility/ScreenShotService/ScreenShot.h +++ b/src/utility/ScreenShotService/ScreenShot.h @@ -27,7 +27,7 @@ * */ -#ifndef __SCREENSHOT_SERVICE_H_ +#pragma once #define __SCREENSHOT_SERVICE_H_ @@ -42,10 +42,10 @@ class ScreenShotService { public: - ScreenShotService(); + ScreenShotService( M5Display *tft, fs::FS *fileSystem ) : _tft(tft), _fileSystem(fileSystem) { }; ~ScreenShotService(); - void init( M5Display *tft, fs::FS &fileSystem ); + void init(); bool begin( bool ifPsram = true ); // ram test and allocation /* * M5.ScreenShot.snap() => /jpg/screenshot-YYYY-MM-DD_HH-MM-SS.jpg @@ -67,26 +67,26 @@ class ScreenShotService { bool _begun = false; // prevent begin() from being called more than once bool _inited = false; // prevent memory to be allocated more than once + bool _psram = false; char fileName[255] = {0}; char folderName[32] = {0}; M5Display* _tft; - fs::FS * _fileSystem; + fs::FS* _fileSystem; void genFileName( const char* name, const char* extension ); void checkFolder( const char* path ); void snapAnimation(); bool displayCanReadPixels(); - JPEG_Encoder JPEGEncoder; - BMP_Encoder BMPEncoder; - PNG_Encoder PNGEncoder; - GIF_Encoder GIFEncoder; + JPEG_Encoder *JPEGEncoder = nullptr; + BMP_Encoder *BMPEncoder = nullptr; + PNG_Encoder *PNGEncoder = nullptr; + GIF_Encoder *GIFEncoder = nullptr; uint8_t* rgbBuffer = NULL; // used for jpeg only, bmp has his own }; // end class -#endif // __SCREENSHOT_SERVICE_H_ From 4887c7bd7cde9ef7643fd8dea75a08a9b45a6552 Mon Sep 17 00:00:00 2001 From: tobozo Date: Thu, 9 Dec 2021 14:09:10 +0100 Subject: [PATCH 15/20] Lowered debugging level with drivers --- .../ButtonTouchReader/ButtonTouchReader.h | 4 +- src/drivers/M5Stack/M5Faces.cpp | 12 +- src/drivers/M5Stack/M5Faces.h | 25 +- src/drivers/M5Stack/M5LoRa.h | 134 ++++---- src/drivers/Odroid-Go/Battery/battery.cpp | 15 +- src/drivers/Odroid-Go/Battery/battery.h | 7 +- src/drivers/common/AXP192/AXP192.h | 84 +++-- src/drivers/common/Button/Button.h | 4 +- src/drivers/common/DummyTouch/DummyTouch.cpp | 33 -- src/drivers/common/DummyTouch/DummyTouch.h | 79 ----- src/drivers/common/I2C/I2CUtil.cpp | 18 +- src/drivers/common/IP5306/Power.h | 118 +++---- src/drivers/common/LoRaWan/LoRaWan.h | 4 +- src/drivers/common/MPU6886/MPU6886.cpp | 6 +- src/drivers/common/MPU6886/MahonyAHRS.cpp | 319 +++++++++--------- src/drivers/common/RTC_BM8563/RTC_BM8563.h | 4 +- src/drivers/common/RTC_PCF8563/pcf8563.h | 14 - src/drivers/common/Touch_XPT2046/XPT2046.cpp | 214 ++++++------ src/drivers/common/Touch_XPT2046/XPT2046.h | 88 +++-- 19 files changed, 528 insertions(+), 654 deletions(-) delete mode 100644 src/drivers/common/DummyTouch/DummyTouch.cpp delete mode 100644 src/drivers/common/DummyTouch/DummyTouch.h diff --git a/src/drivers/M5Core2/ButtonTouchReader/ButtonTouchReader.h b/src/drivers/M5Core2/ButtonTouchReader/ButtonTouchReader.h index 19a1f88..8a14448 100644 --- a/src/drivers/M5Core2/ButtonTouchReader/ButtonTouchReader.h +++ b/src/drivers/M5Core2/ButtonTouchReader/ButtonTouchReader.h @@ -1,4 +1,4 @@ -#if !defined _BUTTON_TOUCH_READER_H_ +#pragma once #define _BUTTON_TOUCH_READER_H_ #include "../../../Config.h" @@ -59,5 +59,3 @@ class ButtonTouchReader Button* _btns[3]; }; - -#endif diff --git a/src/drivers/M5Stack/M5Faces.cpp b/src/drivers/M5Stack/M5Faces.cpp index 13a4d60..7cc97e0 100644 --- a/src/drivers/M5Stack/M5Faces.cpp +++ b/src/drivers/M5Stack/M5Faces.cpp @@ -11,15 +11,18 @@ /*----------------------------------------------------------------------* * Extentions for Facces * *----------------------------------------------------------------------*/ -bool M5Faces::canControlFaces() { +bool M5Faces::canControlFaces() +{ return M5.I2C.writeCommand(KEYBOARD_I2C_ADDR,READI2CSUBADDR); } -M5Faces::M5Faces() { +M5Faces::M5Faces() +{ pinMode(KEYBOARD_INT, INPUT_PULLUP); } -uint8_t M5Faces::getch(void) { +uint8_t M5Faces::getch(void) +{ uint8_t data=0x00; if (kbhit()) { @@ -35,6 +38,7 @@ uint8_t M5Faces::getch(void) { return 0x00; } -bool M5Faces::kbhit(void) { +bool M5Faces::kbhit(void) +{ return(digitalRead(KEYBOARD_INT) == LOW); } diff --git a/src/drivers/M5Stack/M5Faces.h b/src/drivers/M5Stack/M5Faces.h index c99b921..be141fb 100644 --- a/src/drivers/M5Stack/M5Faces.h +++ b/src/drivers/M5Stack/M5Faces.h @@ -1,17 +1,16 @@ // Copyright (c) M5Stack. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#ifndef M5Faces_h - #define M5Faces_h +#pragma once +#define M5Faces_h - #include "../../ESP32-Chimera-Core.h" +#include "../../ESP32-Chimera-Core.h" - class M5Faces { - public: - M5Faces(); - bool canControlFaces(); - uint8_t getch(void); - bool kbhit(void); - private: - }; - -#endif +class M5Faces +{ + public: + M5Faces(); + bool canControlFaces(); + uint8_t getch(void); + bool kbhit(void); + private: +}; diff --git a/src/drivers/M5Stack/M5LoRa.h b/src/drivers/M5Stack/M5LoRa.h index b82ce4d..7746dee 100644 --- a/src/drivers/M5Stack/M5LoRa.h +++ b/src/drivers/M5Stack/M5LoRa.h @@ -4,93 +4,91 @@ // 23FEB18 gojimmypi reversed LORA_DEFAULT_RESET_PIN and LORA_DEFAULT_DIO0_PIN pin numbers // reset on pin 36; irq on pin 26 -#ifndef M5LORA_H - #define M5LORA_H +#pragma once +#define M5LORA_H - #include - #include +#include +#include - #define LORA_DEFAULT_SS_PIN 5 - #define LORA_DEFAULT_RESET_PIN 36 - #define LORA_DEFAULT_DIO0_PIN 26 +#define LORA_DEFAULT_SS_PIN 5 +#define LORA_DEFAULT_RESET_PIN 36 +#define LORA_DEFAULT_DIO0_PIN 26 - #define PA_OUTPUT_RFO_PIN 0 - #define PA_OUTPUT_PA_BOOST_PIN 1 +#define PA_OUTPUT_RFO_PIN 0 +#define PA_OUTPUT_PA_BOOST_PIN 1 - class LoRaClass : public Stream { - public: - LoRaClass(); +class LoRaClass : public Stream { + public: + LoRaClass(); - int begin(long frequency); - void end(); + int begin(long frequency); + void end(); - int beginPacket(int implicitHeader = false); - int endPacket(); + int beginPacket(int implicitHeader = false); + int endPacket(); - int parsePacket(int size = 0); - int packetRssi(); - float packetSnr(); + int parsePacket(int size = 0); + int packetRssi(); + float packetSnr(); - // from Print - virtual size_t write(uint8_t byte); - virtual size_t write(const uint8_t *buffer, size_t size); + // from Print + virtual size_t write(uint8_t byte); + virtual size_t write(const uint8_t *buffer, size_t size); - // from Stream - virtual int available(); - virtual int read(); - virtual int peek(); - virtual void flush(); + // from Stream + virtual int available(); + virtual int read(); + virtual int peek(); + virtual void flush(); - void onReceive(void(*callback)(int)); + void onReceive(void(*callback)(int)); - void receive(int size = 0); - void idle(); - void sleep(); + void receive(int size = 0); + void idle(); + void sleep(); - void setTxPower(int level, int outputPin = PA_OUTPUT_PA_BOOST_PIN); - void setFrequency(long frequency); - void setSpreadingFactor(int sf); - void setSignalBandwidth(long sbw); - void setCodingRate4(int denominator); - void setPreambleLength(long length); - void setSyncWord(int sw); - void enableCrc(); - void disableCrc(); + void setTxPower(int level, int outputPin = PA_OUTPUT_PA_BOOST_PIN); + void setFrequency(long frequency); + void setSpreadingFactor(int sf); + void setSignalBandwidth(long sbw); + void setCodingRate4(int denominator); + void setPreambleLength(long length); + void setSyncWord(int sw); + void enableCrc(); + void disableCrc(); - // deprecated - void crc() { enableCrc(); } - void noCrc() { disableCrc(); } + // deprecated + void crc() { enableCrc(); } + void noCrc() { disableCrc(); } - byte random(); + byte random(); - void setPins(int ss = LORA_DEFAULT_SS_PIN, int reset = LORA_DEFAULT_RESET_PIN, int dio0 = LORA_DEFAULT_DIO0_PIN); - void setSPIFrequency(uint32_t frequency); + void setPins(int ss = LORA_DEFAULT_SS_PIN, int reset = LORA_DEFAULT_RESET_PIN, int dio0 = LORA_DEFAULT_DIO0_PIN); + void setSPIFrequency(uint32_t frequency); - void dumpRegisters(Stream& out); + void dumpRegisters(Stream& out); - private: - void explicitHeaderMode(); - void implicitHeaderMode(); + private: + void explicitHeaderMode(); + void implicitHeaderMode(); - void handleDio0Rise(); + void handleDio0Rise(); - uint8_t readRegister(uint8_t address); - void writeRegister(uint8_t address, uint8_t value); - uint8_t singleTransfer(uint8_t address, uint8_t value); + uint8_t readRegister(uint8_t address); + void writeRegister(uint8_t address, uint8_t value); + uint8_t singleTransfer(uint8_t address, uint8_t value); - static void onDio0Rise(); + static void onDio0Rise(); - private: - SPISettings _spiSettings; - int _ss; - int _reset; - int _dio0; - int _frequency; - int _packetIndex; - int _implicitHeaderMode; - void (*_onReceive)(int); - }; + private: + SPISettings _spiSettings; + int _ss; + int _reset; + int _dio0; + int _frequency; + int _packetIndex; + int _implicitHeaderMode; + void (*_onReceive)(int); +}; - extern LoRaClass LoRa; - -#endif +extern LoRaClass LoRa; diff --git a/src/drivers/Odroid-Go/Battery/battery.cpp b/src/drivers/Odroid-Go/Battery/battery.cpp index 21eadaf..239622f 100644 --- a/src/drivers/Odroid-Go/Battery/battery.cpp +++ b/src/drivers/Odroid-Go/Battery/battery.cpp @@ -10,17 +10,20 @@ #if defined ARDUINO_ODROID_ESP32 -Battery::Battery() { +Battery::Battery() +{ this->_enable_protection = false; } -void Battery::begin() { +void Battery::begin() +{ adc1_config_width(ADC_WIDTH_BIT_12); adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_DB_11); esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12, ESP_ADC_CAL_VAL_EFUSE_TP, &_adc_chars); } -double Battery::getVoltage() { +double Battery::getVoltage() +{ uint32_t adc_reading = 0; for (int i = 0; i < BATTERY_SAMPLES; i++) { @@ -32,7 +35,8 @@ double Battery::getVoltage() { return (double) esp_adc_cal_raw_to_voltage(adc_reading, &_adc_chars) * BATTERY_RESISTANCE_NUM / 1000; } -int Battery::getPercentage() { +int Battery::getPercentage() +{ int res = 101 - (101 / pow(1 + pow(1.33 * ((int)(getVoltage() * 100) - BATTERY_VMIN)/(BATTERY_VMAX - BATTERY_VMIN), 4.5), 3)); @@ -42,7 +46,8 @@ int Battery::getPercentage() { return res; } -void Battery::setProtection(bool enable) { +void Battery::setProtection(bool enable) +{ this->_enable_protection = enable; } diff --git a/src/drivers/Odroid-Go/Battery/battery.h b/src/drivers/Odroid-Go/Battery/battery.h index 80fa4c2..09aeb39 100644 --- a/src/drivers/Odroid-Go/Battery/battery.h +++ b/src/drivers/Odroid-Go/Battery/battery.h @@ -5,7 +5,7 @@ * Author: mdrjr */ -#ifndef LIBRARIES_ODROID_GO_SRC_UTILITY_BATTERY_H_ +#pragma once #define LIBRARIES_ODROID_GO_SRC_UTILITY_BATTERY_H_ #include "Arduino.h" @@ -19,7 +19,8 @@ #define BATTERY_VMIN 330 #define BATTERY_CUTOFF 325 -class Battery { +class Battery +{ public: Battery(void); @@ -34,4 +35,4 @@ class Battery { bool _enable_protection; }; -#endif /* LIBRARIES_ODROID_GO_SRC_UTILITY_BATTERY_H_ */ + diff --git a/src/drivers/common/AXP192/AXP192.h b/src/drivers/common/AXP192/AXP192.h index 9306944..935ad2a 100644 --- a/src/drivers/common/AXP192/AXP192.h +++ b/src/drivers/common/AXP192/AXP192.h @@ -1,4 +1,4 @@ -#ifndef __AXP192_H__ +#pragma once #define __AXP192_H__ #include @@ -33,48 +33,48 @@ class AXP192 { kCHG_1320mA, }; - AXP192(); + AXP192(); #if defined ARDUINO_M5STACK_Core2 - void begin(void); + void begin(void); #endif #if defined( ARDUINO_M5Stick_C ) || defined ( ARDUINO_M5Stick_C_Plus ) // M5Stick C / Plus void begin(bool disableLDO2 = false, bool disableLDO3 = false, bool disableRTC = false, bool disableDCDC1 = false, bool disableDCDC3 = false); #endif - void ScreenBreath(uint8_t brightness); - bool GetBatState(); + void ScreenBreath(uint8_t brightness); + bool GetBatState(); - void EnableCoulombcounter(void); - void DisableCoulombcounter(void); - void StopCoulombcounter(void); - void ClearCoulombcounter(void); - uint32_t GetCoulombchargeData(void); - uint32_t GetCoulombdischargeData(void); - float GetCoulombData(void); - // -- sleep - void SetSleep(void); - void DeepSleep(uint64_t time_in_us = 0); - void LightSleep(uint64_t time_in_us = 0); - uint8_t GetWarningLeve(void); + void EnableCoulombcounter(void); + void DisableCoulombcounter(void); + void StopCoulombcounter(void); + void ClearCoulombcounter(void); + uint32_t GetCoulombchargeData(void); + uint32_t GetCoulombdischargeData(void); + float GetCoulombData(void); + // -- sleep + void SetSleep(void); + void DeepSleep(uint64_t time_in_us = 0); + void LightSleep(uint64_t time_in_us = 0); + uint8_t GetWarningLeve(void); public: - // void SetChargeVoltage( uint8_t ); - // void SetChargeCurrent( uint8_t ); - float GetBatVoltage(); - float GetBatCurrent(); - float GetVinVoltage(); - float GetVinCurrent(); - float GetVBusVoltage(); - float GetVBusCurrent(); - float GetTempInAXP192(); - float GetBatPower(); - float GetBatChargeCurrent(); - float GetAPSVoltage(); - float GetBatCoulombInput(); - float GetBatCoulombOut(); - uint8_t GetWarningLevel(void); + // void SetChargeVoltage( uint8_t ); + // void SetChargeCurrent( uint8_t ); + float GetBatVoltage(); + float GetBatCurrent(); + float GetVinVoltage(); + float GetVinCurrent(); + float GetVBusVoltage(); + float GetVBusCurrent(); + float GetTempInAXP192(); + float GetBatPower(); + float GetBatChargeCurrent(); + float GetAPSVoltage(); + float GetBatCoulombInput(); + float GetBatCoulombOut(); + uint8_t GetWarningLevel(void); void SetCoulombClear(); - void SetLDO2( bool State ); + void SetLDO2( bool State ); uint8_t AXPInState(); bool isACIN(); @@ -93,14 +93,12 @@ class AXP192 { void SetCHGCurrent(uint8_t state); void PowerOff(); private: - void Write1Byte( uint8_t Addr , uint8_t Data ); - uint8_t Read8bit( uint8_t Addr ); - uint16_t Read12Bit( uint8_t Addr); - uint16_t Read13Bit( uint8_t Addr); - uint16_t Read16bit( uint8_t Addr ); - uint32_t Read24bit( uint8_t Addr ); - uint32_t Read32bit( uint8_t Addr ); - void ReadBuff( uint8_t Addr , uint8_t Size , uint8_t *Buff ); + void Write1Byte( uint8_t Addr , uint8_t Data ); + uint8_t Read8bit( uint8_t Addr ); + uint16_t Read12Bit( uint8_t Addr); + uint16_t Read13Bit( uint8_t Addr); + uint16_t Read16bit( uint8_t Addr ); + uint32_t Read24bit( uint8_t Addr ); + uint32_t Read32bit( uint8_t Addr ); + void ReadBuff( uint8_t Addr , uint8_t Size , uint8_t *Buff ); }; - -#endif diff --git a/src/drivers/common/Button/Button.h b/src/drivers/common/Button/Button.h index 53df20f..1f739ea 100644 --- a/src/drivers/common/Button/Button.h +++ b/src/drivers/common/Button/Button.h @@ -8,7 +8,7 @@ * letter to Creative Commons, 171 Second Street, Suite 300, * * San Francisco, California, 94105, USA. * *----------------------------------------------------------------------*/ -#ifndef Button_h +#pragma once #define Button_h #include @@ -53,4 +53,4 @@ class Button uint8_t _axis; //state changed since last read }; -#endif + diff --git a/src/drivers/common/DummyTouch/DummyTouch.cpp b/src/drivers/common/DummyTouch/DummyTouch.cpp deleted file mode 100644 index 67a511b..0000000 --- a/src/drivers/common/DummyTouch/DummyTouch.cpp +++ /dev/null @@ -1,33 +0,0 @@ -// TODO: fire real touch events (e.g. M5Core2 emulation) when button is pressed - -#include "DummyTouch.h" - -touch::touch(/* args */) -{ -} - -touch::~touch(void) -{ - -} - -void touch::begin(void) -{ - -} - -bool touch::ispressed(void) -{ - return false; -} - -const TouchPoint_t& touch::getPressPoint(void) -{ - _TouchPoint.x = _TouchPoint.y = -1; - return _TouchPoint; -} - -int touch::readTouchtoBuff(void) -{ - return -1; -} diff --git a/src/drivers/common/DummyTouch/DummyTouch.h b/src/drivers/common/DummyTouch/DummyTouch.h deleted file mode 100644 index 23b519c..0000000 --- a/src/drivers/common/DummyTouch/DummyTouch.h +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef _DUMMY_TOUCH_H -#define _DUMMY_TOUCH_H - -#include -//#include - -typedef struct point -{ - int x; - int y; -}TouchPoint_t; - -typedef struct HotZone -{ - HotZone(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, void (*fun)() = nullptr){ - _x0 = x0; - _y0 = y0; - _x1 = x1; - _y1 = y1; - _fun = fun; - - } - inline void setZone(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, void (*fun)() = nullptr ) - { - _x0 = x0; - _y0 = y0; - _x1 = x1; - _y1 = y1; - _fun = fun; - } - inline bool inHotZone(TouchPoint_t point) - { - if(( point.x >= _x0 )&&( point.x <= _x1 )&& - ( point.y >= _y0 )&&( point.y <= _y1 )) - { - return true; - } - return false; - } - inline bool inHotZoneDoFun(TouchPoint_t point) - { - if(( point.x >= _x0 )&&( point.x <= _x1 )&& - ( point.y >= _y0 )&&( point.y <= _y1 )) - { - if( _fun != nullptr ) - { - _fun(); - } - return true; - } - return false; - } - uint16_t _x0; - uint16_t _y0; - uint16_t _x1; - uint16_t _y1; - - void (*_fun)(); - -}HotZone_t; - -class touch -{ -private: - /* data */ - TouchPoint_t _TouchPoint; - -public: - touch(/* args */); - ~touch(void); - void begin(void); - bool ispressed(void); - const TouchPoint_t& getPressPoint(void); - HotZone_t* creatHotZone(uint16_t x0, uint16_t y0, uint16_t w, uint16_t h); -private: - int readTouchtoBuff(void); -}; - -#endif // _DUMMY_TOUCH_H diff --git a/src/drivers/common/I2C/I2CUtil.cpp b/src/drivers/common/I2C/I2CUtil.cpp index a8f59ee..8d31feb 100644 --- a/src/drivers/common/I2C/I2CUtil.cpp +++ b/src/drivers/common/I2C/I2CUtil.cpp @@ -19,7 +19,7 @@ bool I2CUtil::begin( signed char sdaPin, signed char sclPin, TwoWire *i2cPort ) return false; } if( _begun ) { - log_w("Skipping I2C start (already started) on %s with SDA/SCL: %d/%d", i2cPort == &Wire?"Wire":"Wire1", _sdaPin, _sclPin ); + log_d("Skipping I2C start (already started) on %s with SDA/SCL: %d/%d", i2cPort == &Wire?"Wire":"Wire1", _sdaPin, _sclPin ); return true; } _sdaPin = sdaPin; @@ -55,7 +55,7 @@ void I2CUtil::checkFreq( bool unset ) _i2cPort->setClock( _lastclockspeed ); } else { if( currentClockSpeed == _clockspeed ) return; - log_d("Setting freq to %d (was: %d)", _clockspeed, currentClockSpeed ); + log_v("Setting freq to %d (was: %d)", _clockspeed, currentClockSpeed ); _lastclockspeed = currentClockSpeed; _i2cPort->setClock( _clockspeed ); } @@ -70,7 +70,7 @@ bool I2CUtil::writeCommand( unsigned char i2c_addr, unsigned char reg ) _i2cPort->write(reg); res = (_i2cPort->endTransmission() == 0); - log_d("send to 0x%02x [0x%02x] result:%s", i2c_addr, reg, res ? "OK" : "NG"); + log_v("send to 0x%02x [0x%02x] result:%s", i2c_addr, reg, res ? "OK" : "NG"); checkFreq(true); return res; } @@ -86,7 +86,7 @@ bool I2CUtil::writeByte( unsigned char i2c_addr, unsigned char reg, unsigned cha _i2cPort->write(data); res = (_i2cPort->endTransmission() == 0); checkFreq(true); - log_d("send to 0x%02x [0x%2x] data=0x%02x result:%s", i2c_addr, reg, data, res ? "OK" : "NG"); + log_v("send to 0x%02x [0x%2x] data=0x%02x result:%s", i2c_addr, reg, data, res ? "OK" : "NG"); return res; } @@ -106,7 +106,7 @@ bool I2CUtil::writeBytes( unsigned char i2c_addr, unsigned char reg, unsigned ch } res = _i2cPort->endTransmission() == 0; - log_d("sent to 0x%02x [0x%02x], result:%s", i2c_addr,reg, res ? "OK" : "NG"); + log_v("sent to 0x%02x [0x%02x], result:%s", i2c_addr,reg, res ? "OK" : "NG"); checkFreq(true); return res; } @@ -125,7 +125,7 @@ bool I2CUtil::readByte( unsigned char i2c_addr, unsigned char *buf ) return true; } - log_d("tried to read 1 byte from i2c addr 0x%02x and received none", i2c_addr); + log_v("tried to read 1 byte from i2c addr 0x%02x and received none", i2c_addr); checkFreq(true); return false; } @@ -146,7 +146,7 @@ bool I2CUtil::readByte( unsigned char i2c_addr, unsigned char reg, unsigned char return true; } - log_d("tried to read 1 byte from i2c addr 0x%02x / reg 0x%02x and received none", i2c_addr, reg); + log_v("tried to read 1 byte from i2c addr 0x%02x / reg 0x%02x and received none", i2c_addr, reg); checkFreq(true); return false; } @@ -172,7 +172,7 @@ bool I2CUtil::readBytes( unsigned char i2c_addr, unsigned char reg, unsigned cha return true; } - log_d("tried to read %d bytes from i2c addr 0x%02x / reg 0x%02x and received none", count, i2c_addr, reg); + log_v("tried to read %d bytes from i2c addr 0x%02x / reg 0x%02x and received none", count, i2c_addr, reg); checkFreq(true); return false; } @@ -191,7 +191,7 @@ bool I2CUtil::readBytes( unsigned char i2c_addr, unsigned char count,unsigned ch return true; } - log_d("tried to read %d bytes from i2c addr 0x%02x and received none", count, i2c_addr); + log_v("tried to read %d bytes from i2c addr 0x%02x and received none", count, i2c_addr); checkFreq(true); return false; } diff --git a/src/drivers/common/IP5306/Power.h b/src/drivers/common/IP5306/Power.h index 2056682..989153e 100644 --- a/src/drivers/common/IP5306/Power.h +++ b/src/drivers/common/IP5306/Power.h @@ -5,73 +5,73 @@ * License v2.1 * * https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html * *----------------------------------------------------------------------*/ -#ifndef Power_h - #define Power_h - #include - #include +#pragma once - #define SLEEP_MSEC(us) (((uint64_t)us) * 1000L) - #define SLEEP_SEC(us) (((uint64_t)us) * 1000000L) - #define SLEEP_MIN(us) (((uint64_t)us) * 60L * 1000000L) - #define SLEEP_HR(us) (((uint64_t)us) * 60L * 60L * 1000000L) +#define Power_h +#include +#include - class POWER - { - public: - POWER(); - bool canControl(); - void begin(); +#define SLEEP_MSEC(us) (((uint64_t)us) * 1000L) +#define SLEEP_SEC(us) (((uint64_t)us) * 1000000L) +#define SLEEP_MIN(us) (((uint64_t)us) * 60L * 1000000L) +#define SLEEP_HR(us) (((uint64_t)us) * 60L * 60L * 1000000L) - // -- ShutdownTimeParam - enum ShutdownTime - { - SHUTDOWN_8S = 0, - SHUTDOWN_16S, - SHUTDOWN_32S, - SHUTDOWN_64S - }; +class POWER +{ + public: + POWER(); + bool canControl(); + void begin(); - // -- control for power - bool setKeepLightLoad(bool en); - bool setPowerBoostKeepOn(bool en); - bool setAutoBootOnLoad(bool en); - bool setLowPowerShutdown(bool en); - bool setLowPowerShutdownTime(ShutdownTime time); - bool setPowerBoostOnOff(bool en); - bool setPowerBoostSet(bool en); - bool setPowerVin(bool en); - bool setPowerWLEDSet(bool en); - bool setPowerBtnEn(bool en); + // -- ShutdownTimeParam + enum ShutdownTime + { + SHUTDOWN_8S = 0, + SHUTDOWN_16S, + SHUTDOWN_32S, + SHUTDOWN_64S + }; - // -- control for battery - bool setVinMaxCurrent(uint8_t cur); - bool setChargeVolt(uint8_t volt); - bool setCharge(bool en); - bool isChargeFull(); - bool isCharging(); - int8_t getBatteryLevel(); - bool batteryMode(bool en); + // -- control for power + bool setKeepLightLoad(bool en); + bool setPowerBoostKeepOn(bool en); + bool setAutoBootOnLoad(bool en); + bool setLowPowerShutdown(bool en); + bool setLowPowerShutdownTime(ShutdownTime time); + bool setPowerBoostOnOff(bool en); + bool setPowerBoostSet(bool en); + bool setPowerVin(bool en); + bool setPowerWLEDSet(bool en); + bool setPowerBtnEn(bool en); - // -- configuration for wakeup - void setWakeupButton(uint8_t button); + // -- control for battery + bool setVinMaxCurrent(uint8_t cur); + bool setChargeVolt(uint8_t volt); + bool setCharge(bool en); + bool isChargeFull(); + bool isCharging(); + int8_t getBatteryLevel(); + bool batteryMode(bool en); - // -- get resson for startup - bool isResetbyWatchdog(); - bool isResetbyDeepsleep(); - bool isResetbySoftware(); - bool isResetbyPowerSW(); + // -- configuration for wakeup + void setWakeupButton(uint8_t button); - // -- sleep - void deepSleep(uint64_t time_in_us = 0); - void lightSleep(uint64_t time_in_us = 0); + // -- get resson for startup + bool isResetbyWatchdog(); + bool isResetbyDeepsleep(); + bool isResetbySoftware(); + bool isResetbyPowerSW(); - // -- power off - void powerOFF(); + // -- sleep + void deepSleep(uint64_t time_in_us = 0); + void lightSleep(uint64_t time_in_us = 0); - // -- software reset - void reset(); + // -- power off + void powerOFF(); - private: - uint8_t _wakeupPin; - }; -#endif + // -- software reset + void reset(); + + private: + uint8_t _wakeupPin; +}; diff --git a/src/drivers/common/LoRaWan/LoRaWan.h b/src/drivers/common/LoRaWan/LoRaWan.h index 55882cc..e495e47 100644 --- a/src/drivers/common/LoRaWan/LoRaWan.h +++ b/src/drivers/common/LoRaWan/LoRaWan.h @@ -24,7 +24,7 @@ THE SOFTWARE.1 USA */ -#ifndef _LORAWAN_H_ +#pragma once #define _LORAWAN_H_ #include @@ -501,5 +501,3 @@ class LoRaWanClass extern LoRaWanClass lora; - -#endif diff --git a/src/drivers/common/MPU6886/MPU6886.cpp b/src/drivers/common/MPU6886/MPU6886.cpp index d719a74..c21826c 100644 --- a/src/drivers/common/MPU6886/MPU6886.cpp +++ b/src/drivers/common/MPU6886/MPU6886.cpp @@ -4,15 +4,15 @@ bool MPU6886::Init( int sdaPin, int sclPin ){ unsigned char tempdata[1]; unsigned char regdata; - log_e("Will Init MPU6886 on I2C ports SDA/SCL: %d/%d", sdaPin, sclPin ); + log_w("Will Init MPU6886 on I2C ports SDA/SCL: %d/%d", sdaPin, sclPin ); if( _i2cUtil == nullptr ) { if( _i2cPort == nullptr ) { _i2cUtil = new I2CUtil( &Wire ); - log_w("New I2C port specified (Wire). on SDA/SCL: %d/%d", sdaPin, sclPin ); + log_d("New I2C port specified (Wire). on SDA/SCL: %d/%d", sdaPin, sclPin ); } else { _i2cUtil = new I2CUtil( _i2cPort ); - log_w("New I2C port specified (%s). on SDA/SCL: %d/%d", _i2cPort==&Wire?"Wire":"Wire1", sdaPin, sclPin ); + log_d("New I2C port specified (%s). on SDA/SCL: %d/%d", _i2cPort==&Wire?"Wire":"Wire1", sdaPin, sclPin ); } } diff --git a/src/drivers/common/MPU6886/MahonyAHRS.cpp b/src/drivers/common/MPU6886/MahonyAHRS.cpp index cae0050..8f64de8 100644 --- a/src/drivers/common/MPU6886/MahonyAHRS.cpp +++ b/src/drivers/common/MPU6886/MahonyAHRS.cpp @@ -45,34 +45,35 @@ volatile float integralFBx = 0.0f, integralFBy = 0.0f, integralFBz = 0.0f; // i //--------------------------------------------------------------------------------------------------- // AHRS algorithm update -void MahonyAHRSupdate(float gx, float gy, float gz, float ax, float ay, float az, float mx, float my, float mz) { - float recipNorm; +void MahonyAHRSupdate(float gx, float gy, float gz, float ax, float ay, float az, float mx, float my, float mz) +{ + float recipNorm; float q0q0, q0q1, q0q2, q0q3, q1q1, q1q2, q1q3, q2q2, q2q3, q3q3; - float hx, hy, bx, bz; - float halfvx, halfvy, halfvz, halfwx, halfwy, halfwz; - float halfex, halfey, halfez; - float qa, qb, qc; - - // Use IMU algorithm if magnetometer measurement invalid (avoids NaN in magnetometer normalisation) - if((mx == 0.0f) && (my == 0.0f) && (mz == 0.0f)) { - //MahonyAHRSupdateIMU(gx, gy, gz, ax, ay, az); - return; - } - - // Compute feedback only if accelerometer measurement valid (avoids NaN in accelerometer normalisation) - if(!((ax == 0.0f) && (ay == 0.0f) && (az == 0.0f))) { - - // Normalise accelerometer measurement - recipNorm = sqrt(ax * ax + ay * ay + az * az); - ax *= recipNorm; - ay *= recipNorm; - az *= recipNorm; - - // Normalise magnetometer measurement - recipNorm = sqrt(mx * mx + my * my + mz * mz); - mx *= recipNorm; - my *= recipNorm; - mz *= recipNorm; + float hx, hy, bx, bz; + float halfvx, halfvy, halfvz, halfwx, halfwy, halfwz; + float halfex, halfey, halfez; + float qa, qb, qc; + + // Use IMU algorithm if magnetometer measurement invalid (avoids NaN in magnetometer normalisation) + if((mx == 0.0f) && (my == 0.0f) && (mz == 0.0f)) { + //MahonyAHRSupdateIMU(gx, gy, gz, ax, ay, az); + return; + } + + // Compute feedback only if accelerometer measurement valid (avoids NaN in accelerometer normalisation) + if(!((ax == 0.0f) && (ay == 0.0f) && (az == 0.0f))) { + + // Normalise accelerometer measurement + recipNorm = sqrt(ax * ax + ay * ay + az * az); + ax *= recipNorm; + ay *= recipNorm; + az *= recipNorm; + + // Normalise magnetometer measurement + recipNorm = sqrt(mx * mx + my * my + mz * mz); + mx *= recipNorm; + my *= recipNorm; + mz *= recipNorm; // Auxiliary variables to avoid repeated arithmetic q0q0 = q0 * q0; @@ -92,137 +93,138 @@ void MahonyAHRSupdate(float gx, float gy, float gz, float ax, float ay, float az bx = sqrt(hx * hx + hy * hy); bz = 2.0f * (mx * (q1q3 - q0q2) + my * (q2q3 + q0q1) + mz * (0.5f - q1q1 - q2q2)); - // Estimated direction of gravity and magnetic field - halfvx = q1q3 - q0q2; - halfvy = q0q1 + q2q3; - halfvz = q0q0 - 0.5f + q3q3; + // Estimated direction of gravity and magnetic field + halfvx = q1q3 - q0q2; + halfvy = q0q1 + q2q3; + halfvz = q0q0 - 0.5f + q3q3; halfwx = bx * (0.5f - q2q2 - q3q3) + bz * (q1q3 - q0q2); halfwy = bx * (q1q2 - q0q3) + bz * (q0q1 + q2q3); halfwz = bx * (q0q2 + q1q3) + bz * (0.5f - q1q1 - q2q2); - // Error is sum of cross product between estimated direction and measured direction of field vectors - halfex = (ay * halfvz - az * halfvy) + (my * halfwz - mz * halfwy); - halfey = (az * halfvx - ax * halfvz) + (mz * halfwx - mx * halfwz); - halfez = (ax * halfvy - ay * halfvx) + (mx * halfwy - my * halfwx); - - // Compute and apply integral feedback if enabled - if(twoKi > 0.0f) { - integralFBx += twoKi * halfex * (1.0f / sampleFreq); // integral error scaled by Ki - integralFBy += twoKi * halfey * (1.0f / sampleFreq); - integralFBz += twoKi * halfez * (1.0f / sampleFreq); - gx += integralFBx; // apply integral feedback - gy += integralFBy; - gz += integralFBz; - } - else { - integralFBx = 0.0f; // prevent integral windup - integralFBy = 0.0f; - integralFBz = 0.0f; - } - - // Apply proportional feedback - gx += twoKp * halfex; - gy += twoKp * halfey; - gz += twoKp * halfez; - } - - // Integrate rate of change of quaternion - gx *= (0.5f * (1.0f / sampleFreq)); // pre-multiply common factors - gy *= (0.5f * (1.0f / sampleFreq)); - gz *= (0.5f * (1.0f / sampleFreq)); - qa = q0; - qb = q1; - qc = q2; - q0 += (-qb * gx - qc * gy - q3 * gz); - q1 += (qa * gx + qc * gz - q3 * gy); - q2 += (qa * gy - qb * gz + q3 * gx); - q3 += (qa * gz + qb * gy - qc * gx); - - // Normalise quaternion - recipNorm = sqrt(q0 * q0 + q1 * q1 + q2 * q2 + q3 * q3); - q0 *= recipNorm; - q1 *= recipNorm; - q2 *= recipNorm; - q3 *= recipNorm; + // Error is sum of cross product between estimated direction and measured direction of field vectors + halfex = (ay * halfvz - az * halfvy) + (my * halfwz - mz * halfwy); + halfey = (az * halfvx - ax * halfvz) + (mz * halfwx - mx * halfwz); + halfez = (ax * halfvy - ay * halfvx) + (mx * halfwy - my * halfwx); + + // Compute and apply integral feedback if enabled + if(twoKi > 0.0f) { + integralFBx += twoKi * halfex * (1.0f / sampleFreq); // integral error scaled by Ki + integralFBy += twoKi * halfey * (1.0f / sampleFreq); + integralFBz += twoKi * halfez * (1.0f / sampleFreq); + gx += integralFBx; // apply integral feedback + gy += integralFBy; + gz += integralFBz; + } + else { + integralFBx = 0.0f; // prevent integral windup + integralFBy = 0.0f; + integralFBz = 0.0f; + } + + // Apply proportional feedback + gx += twoKp * halfex; + gy += twoKp * halfey; + gz += twoKp * halfez; + } + + // Integrate rate of change of quaternion + gx *= (0.5f * (1.0f / sampleFreq)); // pre-multiply common factors + gy *= (0.5f * (1.0f / sampleFreq)); + gz *= (0.5f * (1.0f / sampleFreq)); + qa = q0; + qb = q1; + qc = q2; + q0 += (-qb * gx - qc * gy - q3 * gz); + q1 += (qa * gx + qc * gz - q3 * gy); + q2 += (qa * gy - qb * gz + q3 * gx); + q3 += (qa * gz + qb * gy - qc * gx); + + // Normalise quaternion + recipNorm = sqrt(q0 * q0 + q1 * q1 + q2 * q2 + q3 * q3); + q0 *= recipNorm; + q1 *= recipNorm; + q2 *= recipNorm; + q3 *= recipNorm; } //--------------------------------------------------------------------------------------------------- // IMU algorithm update -void MahonyAHRSupdateIMU(float gx, float gy, float gz, float ax, float ay, float az,float *pitch,float *roll,float *yaw) { - float recipNorm; - float halfvx, halfvy, halfvz; - float halfex, halfey, halfez; - float qa, qb, qc; - - - // Compute feedback only if accelerometer measurement valid (avoids NaN in accelerometer normalisation) - if(!((ax == 0.0f) && (ay == 0.0f) && (az == 0.0f))) { - - // Normalise accelerometer measurement - recipNorm = invSqrt(ax * ax + ay * ay + az * az); - ax *= recipNorm; - ay *= recipNorm; - az *= recipNorm; - - // Estimated direction of gravity and vector perpendicular to magnetic flux - halfvx = q1 * q3 - q0 * q2; - halfvy = q0 * q1 + q2 * q3; - halfvz = q0 * q0 - 0.5f + q3 * q3; - - - - // Error is sum of cross product between estimated and measured direction of gravity - halfex = (ay * halfvz - az * halfvy); - halfey = (az * halfvx - ax * halfvz); - halfez = (ax * halfvy - ay * halfvx); - - // Compute and apply integral feedback if enabled - if(twoKi > 0.0f) { - integralFBx += twoKi * halfex * (1.0f / sampleFreq); // integral error scaled by Ki - integralFBy += twoKi * halfey * (1.0f / sampleFreq); - integralFBz += twoKi * halfez * (1.0f / sampleFreq); - gx += integralFBx; // apply integral feedback - gy += integralFBy; - gz += integralFBz; - } - else { - integralFBx = 0.0f; // prevent integral windup - integralFBy = 0.0f; - integralFBz = 0.0f; - } - - // Apply proportional feedback - gx += twoKp * halfex; - gy += twoKp * halfey; - gz += twoKp * halfez; - } - - // Integrate rate of change of quaternion - gx *= (0.5f * (1.0f / sampleFreq)); // pre-multiply common factors - gy *= (0.5f * (1.0f / sampleFreq)); - gz *= (0.5f * (1.0f / sampleFreq)); - qa = q0; - qb = q1; - qc = q2; - q0 += (-qb * gx - qc * gy - q3 * gz); - q1 += (qa * gx + qc * gz - q3 * gy); - q2 += (qa * gy - qb * gz + q3 * gx); - q3 += (qa * gz + qb * gy - qc * gx); - - // Normalise quaternion - recipNorm = invSqrt(q0 * q0 + q1 * q1 + q2 * q2 + q3 * q3); - q0 *= recipNorm; - q1 *= recipNorm; - q2 *= recipNorm; - q3 *= recipNorm; - - - *pitch = asin(-2 * q1 * q3 + 2 * q0* q2); // pitch - *roll = atan2(2 * q2 * q3 + 2 * q0 * q1, -2 * q1 * q1 - 2 * q2* q2 + 1); // roll - *yaw = atan2(2*(q1*q2 + q0*q3),q0*q0+q1*q1-q2*q2-q3*q3); //yaw - - *pitch *= RAD_TO_DEG; +void MahonyAHRSupdateIMU(float gx, float gy, float gz, float ax, float ay, float az,float *pitch,float *roll,float *yaw) +{ + float recipNorm; + float halfvx, halfvy, halfvz; + float halfex, halfey, halfez; + float qa, qb, qc; + + + // Compute feedback only if accelerometer measurement valid (avoids NaN in accelerometer normalisation) + if(!((ax == 0.0f) && (ay == 0.0f) && (az == 0.0f))) { + + // Normalise accelerometer measurement + recipNorm = invSqrt(ax * ax + ay * ay + az * az); + ax *= recipNorm; + ay *= recipNorm; + az *= recipNorm; + + // Estimated direction of gravity and vector perpendicular to magnetic flux + halfvx = q1 * q3 - q0 * q2; + halfvy = q0 * q1 + q2 * q3; + halfvz = q0 * q0 - 0.5f + q3 * q3; + + + + // Error is sum of cross product between estimated and measured direction of gravity + halfex = (ay * halfvz - az * halfvy); + halfey = (az * halfvx - ax * halfvz); + halfez = (ax * halfvy - ay * halfvx); + + // Compute and apply integral feedback if enabled + if(twoKi > 0.0f) { + integralFBx += twoKi * halfex * (1.0f / sampleFreq); // integral error scaled by Ki + integralFBy += twoKi * halfey * (1.0f / sampleFreq); + integralFBz += twoKi * halfez * (1.0f / sampleFreq); + gx += integralFBx; // apply integral feedback + gy += integralFBy; + gz += integralFBz; + } + else { + integralFBx = 0.0f; // prevent integral windup + integralFBy = 0.0f; + integralFBz = 0.0f; + } + + // Apply proportional feedback + gx += twoKp * halfex; + gy += twoKp * halfey; + gz += twoKp * halfez; + } + + // Integrate rate of change of quaternion + gx *= (0.5f * (1.0f / sampleFreq)); // pre-multiply common factors + gy *= (0.5f * (1.0f / sampleFreq)); + gz *= (0.5f * (1.0f / sampleFreq)); + qa = q0; + qb = q1; + qc = q2; + q0 += (-qb * gx - qc * gy - q3 * gz); + q1 += (qa * gx + qc * gz - q3 * gy); + q2 += (qa * gy - qb * gz + q3 * gx); + q3 += (qa * gz + qb * gy - qc * gx); + + // Normalise quaternion + recipNorm = invSqrt(q0 * q0 + q1 * q1 + q2 * q2 + q3 * q3); + q0 *= recipNorm; + q1 *= recipNorm; + q2 *= recipNorm; + q3 *= recipNorm; + + + *pitch = asin(-2 * q1 * q3 + 2 * q0* q2); // pitch + *roll = atan2(2 * q2 * q3 + 2 * q0 * q1, -2 * q1 * q1 - 2 * q2* q2 + 1); // roll + *yaw = atan2(2*(q1*q2 + q0*q3),q0*q0+q1*q1-q2*q2-q3*q3); //yaw + + *pitch *= RAD_TO_DEG; *yaw *= RAD_TO_DEG; // Declination of SparkFun Electronics (40°05'26.6"N 105°11'05.9"W) is // 8° 30' E ± 0° 21' (or 8.5°) on 2016-07-19 @@ -230,7 +232,7 @@ void MahonyAHRSupdateIMU(float gx, float gy, float gz, float ax, float ay, float *yaw -= 8.5; *roll *= RAD_TO_DEG; - ///Serial.printf("%f %f %f \r\n", pitch, roll, yaw); + ///Serial.printf("%f %f %f \r\n", pitch, roll, yaw); } //--------------------------------------------------------------------------------------------------- @@ -239,14 +241,15 @@ void MahonyAHRSupdateIMU(float gx, float gy, float gz, float ax, float ay, float #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wstrict-aliasing" -float invSqrt(float x) { - float halfx = 0.5f * x; - float y = x; - long i = *(long*)&y; - i = 0x5f3759df - (i>>1); - y = *(float*)&i; - y = y * (1.5f - (halfx * y * y)); - return y; +float invSqrt(float x) +{ + float halfx = 0.5f * x; + float y = x; + long i = *(long*)&y; + i = 0x5f3759df - (i>>1); + y = *(float*)&i; + y = y * (1.5f - (halfx * y * y)); + return y; } #pragma GCC diagnostic pop //==================================================================================================== diff --git a/src/drivers/common/RTC_BM8563/RTC_BM8563.h b/src/drivers/common/RTC_BM8563/RTC_BM8563.h index f74e47a..c25787e 100644 --- a/src/drivers/common/RTC_BM8563/RTC_BM8563.h +++ b/src/drivers/common/RTC_BM8563/RTC_BM8563.h @@ -1,4 +1,4 @@ -#ifndef __RTC_H__ +#pragma once #define __RTC_H__ #include @@ -77,5 +77,3 @@ class RTC_BM8563 uint8_t ByteToBcd2(uint8_t Value); }; - -#endif diff --git a/src/drivers/common/RTC_PCF8563/pcf8563.h b/src/drivers/common/RTC_PCF8563/pcf8563.h index 9393006..d9971a1 100644 --- a/src/drivers/common/RTC_PCF8563/pcf8563.h +++ b/src/drivers/common/RTC_PCF8563/pcf8563.h @@ -187,24 +187,10 @@ class PCF8563_Class int _readByte(uint8_t reg, uint8_t nbytes, uint8_t *data) { return (int)_bus->readBytes(_address, reg, nbytes, data); - // _i2cPort->beginTransmission(_address); - // _i2cPort->write(reg); - // _i2cPort->endTransmission(); - // _i2cPort->requestFrom(_address, nbytes); - // uint8_t index = 0; - // while (_i2cPort->available()) - // data[index++] = _i2cPort->read(); } - int _writeByte(uint8_t reg, uint8_t nbytes, uint8_t *data) { return (int)_bus->writeBytes(_address, reg, data, nbytes); - // _i2cPort->beginTransmission(_address); - // _i2cPort->write(reg); - // for (uint8_t i = 0; i < nbytes; i++) { - // _i2cPort->write(data[i]); - // } - // _i2cPort->endTransmission(); } uint8_t _isValid = false; diff --git a/src/drivers/common/Touch_XPT2046/XPT2046.cpp b/src/drivers/common/Touch_XPT2046/XPT2046.cpp index 0d5de98..0bc7745 100644 --- a/src/drivers/common/Touch_XPT2046/XPT2046.cpp +++ b/src/drivers/common/Touch_XPT2046/XPT2046.cpp @@ -1,24 +1,24 @@ /* Touchscreen library for XPT2046 Touch Controller Chip - * Copyright (c) 2015, Paul Stoffregen, paul@pjrc.com - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice, development funding notice, and this permission - * notice shall be included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ +* Copyright (c) 2015, Paul Stoffregen, paul@pjrc.com +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice, development funding notice, and this permission +* notice shall be included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ #include "XPT2046.h" @@ -30,52 +30,52 @@ void isrPin(void); bool XPT2046_Touchscreen::begin() { - SPI.begin(); - pinMode(csPin, OUTPUT); - digitalWrite(csPin, HIGH); - if (255 != tirqPin) { - pinMode( tirqPin, INPUT ); - attachInterrupt(digitalPinToInterrupt(tirqPin), isrPin, FALLING); - isrPinptr = this; - } - return true; + SPI.begin(); + pinMode(csPin, OUTPUT); + digitalWrite(csPin, HIGH); + if (255 != tirqPin) { + pinMode( tirqPin, INPUT ); + attachInterrupt(digitalPinToInterrupt(tirqPin), isrPin, FALLING); + isrPinptr = this; + } + return true; } ISR_PREFIX void isrPin( void ) { - XPT2046_Touchscreen *o = isrPinptr; - o->isrWake = true; + XPT2046_Touchscreen *o = isrPinptr; + o->isrWake = true; } TS_Point XPT2046_Touchscreen::getPoint() { - update(); - return TS_Point(xraw, yraw, zraw); + update(); + return TS_Point(xraw, yraw, zraw); } bool XPT2046_Touchscreen::tirqTouched() { - return (isrWake); + return (isrWake); } bool XPT2046_Touchscreen::touched() { - update(); - return (zraw >= Z_THRESHOLD); + update(); + return (zraw >= Z_THRESHOLD); } void XPT2046_Touchscreen::readData(uint16_t *x, uint16_t *y, uint8_t *z) { - update(); - *x = xraw; - *y = yraw; - *z = zraw; + update(); + *x = xraw; + *y = yraw; + *z = zraw; } bool XPT2046_Touchscreen::bufferEmpty() { - return ((millis() - msraw) < MSEC_THRESHOLD); + return ((millis() - msraw) < MSEC_THRESHOLD); } static int16_t besttwoavg( int16_t x , int16_t y , int16_t z ) { @@ -97,70 +97,70 @@ static int16_t besttwoavg( int16_t x , int16_t y , int16_t z ) { void XPT2046_Touchscreen::update() { - int16_t data[6]; - - if (!isrWake) return; - uint32_t now = millis(); - if (now - msraw < MSEC_THRESHOLD) return; - - SPI.beginTransaction(SPI_SETTING); - digitalWrite(csPin, LOW); - SPI.transfer(0xB1 /* Z1 */); - int16_t z1 = SPI.transfer16(0xC1 /* Z2 */) >> 3; - int z = z1 + 4095; - int16_t z2 = SPI.transfer16(0x91 /* X */) >> 3; - z -= z2; - if (z >= Z_THRESHOLD) { - SPI.transfer16(0x91 /* X */); // dummy X measure, 1st is always noisy - data[0] = SPI.transfer16(0xD1 /* Y */) >> 3; - data[1] = SPI.transfer16(0x91 /* X */) >> 3; // make 3 x-y measurements - data[2] = SPI.transfer16(0xD1 /* Y */) >> 3; - data[3] = SPI.transfer16(0x91 /* X */) >> 3; - } - else data[0] = data[1] = data[2] = data[3] = 0; // Compiler warns these values may be used unset on early exit. - data[4] = SPI.transfer16(0xD0 /* Y */) >> 3; // Last Y touch power down - data[5] = SPI.transfer16(0) >> 3; - digitalWrite(csPin, HIGH); - SPI.endTransaction(); - //Serial.printf("z=%d :: z1=%d, z2=%d ", z, z1, z2); - if (z < 0) z = 0; - if (z < Z_THRESHOLD) { // if ( !touched ) { - // Serial.println(); - zraw = 0; - if (z < Z_THRESHOLD_INT) { // if ( !touched ) { - if (255 != tirqPin) isrWake = false; - } - return; - } - zraw = z; - - // Average pair with least distance between each measured x then y - //Serial.printf(" z1=%d,z2=%d ", z1, z2); - //Serial.printf("p=%d, %d,%d %d,%d %d,%d", zraw, - //data[0], data[1], data[2], data[3], data[4], data[5]); - int16_t x = besttwoavg( data[0], data[2], data[4] ); - int16_t y = besttwoavg( data[1], data[3], data[5] ); - - //Serial.printf(" %d,%d", x, y); - //Serial.println(); - if (z >= Z_THRESHOLD) { - msraw = now; // good read completed, set wait - switch (rotation) { - case 0: - xraw = 4095 - y; - yraw = x; - break; - case 1: - xraw = x; - yraw = y; - break; - case 2: - xraw = y; - yraw = 4095 - x; - break; - default: // 3 - xraw = 4095 - x; - yraw = 4095 - y; - } - } + int16_t data[6]; + + if (!isrWake) return; + uint32_t now = millis(); + if (now - msraw < MSEC_THRESHOLD) return; + + SPI.beginTransaction(SPI_SETTING); + digitalWrite(csPin, LOW); + SPI.transfer(0xB1 /* Z1 */); + int16_t z1 = SPI.transfer16(0xC1 /* Z2 */) >> 3; + int z = z1 + 4095; + int16_t z2 = SPI.transfer16(0x91 /* X */) >> 3; + z -= z2; + if (z >= Z_THRESHOLD) { + SPI.transfer16(0x91 /* X */); // dummy X measure, 1st is always noisy + data[0] = SPI.transfer16(0xD1 /* Y */) >> 3; + data[1] = SPI.transfer16(0x91 /* X */) >> 3; // make 3 x-y measurements + data[2] = SPI.transfer16(0xD1 /* Y */) >> 3; + data[3] = SPI.transfer16(0x91 /* X */) >> 3; + } + else data[0] = data[1] = data[2] = data[3] = 0; // Compiler warns these values may be used unset on early exit. + data[4] = SPI.transfer16(0xD0 /* Y */) >> 3; // Last Y touch power down + data[5] = SPI.transfer16(0) >> 3; + digitalWrite(csPin, HIGH); + SPI.endTransaction(); + //Serial.printf("z=%d :: z1=%d, z2=%d ", z, z1, z2); + if (z < 0) z = 0; + if (z < Z_THRESHOLD) { // if ( !touched ) { + // Serial.println(); + zraw = 0; + if (z < Z_THRESHOLD_INT) { // if ( !touched ) { + if (255 != tirqPin) isrWake = false; + } + return; + } + zraw = z; + + // Average pair with least distance between each measured x then y + //Serial.printf(" z1=%d,z2=%d ", z1, z2); + //Serial.printf("p=%d, %d,%d %d,%d %d,%d", zraw, + //data[0], data[1], data[2], data[3], data[4], data[5]); + int16_t x = besttwoavg( data[0], data[2], data[4] ); + int16_t y = besttwoavg( data[1], data[3], data[5] ); + + //Serial.printf(" %d,%d", x, y); + //Serial.println(); + if (z >= Z_THRESHOLD) { + msraw = now; // good read completed, set wait + switch (rotation) { + case 0: + xraw = 4095 - y; + yraw = x; + break; + case 1: + xraw = x; + yraw = y; + break; + case 2: + xraw = y; + yraw = 4095 - x; + break; + default: // 3 + xraw = 4095 - x; + yraw = 4095 - y; + } + } } diff --git a/src/drivers/common/Touch_XPT2046/XPT2046.h b/src/drivers/common/Touch_XPT2046/XPT2046.h index 6c73f5a..f16c409 100644 --- a/src/drivers/common/Touch_XPT2046/XPT2046.h +++ b/src/drivers/common/Touch_XPT2046/XPT2046.h @@ -1,26 +1,26 @@ /* Touchscreen library for XPT2046 Touch Controller Chip - * Copyright (c) 2015, Paul Stoffregen, paul@pjrc.com - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice, development funding notice, and this permission - * notice shall be included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ +* Copyright (c) 2015, Paul Stoffregen, paul@pjrc.com +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice, development funding notice, and this permission +* notice shall be included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ -#ifndef _XPT2046_Touchscreen_h_ +#pragma once #define _XPT2046_Touchscreen_h_ #include "Arduino.h" @@ -40,36 +40,37 @@ class TS_Point { public: - TS_Point(void) : x(0), y(0), z(0) {} - TS_Point(int16_t x, int16_t y, int16_t z) : x(x), y(y), z(z) {} - bool operator==(TS_Point p) { return ((p.x == x) && (p.y == y) && (p.z == z)); } - bool operator!=(TS_Point p) { return ((p.x != x) || (p.y != y) || (p.z != z)); } - int16_t x, y, z; + TS_Point(void) : x(0), y(0), z(0) {} + TS_Point(int16_t x, int16_t y, int16_t z) : x(x), y(y), z(z) {} + bool operator==(TS_Point p) { return ((p.x == x) && (p.y == y) && (p.z == z)); } + bool operator!=(TS_Point p) { return ((p.x != x) || (p.y != y) || (p.z != z)); } + int16_t x, y, z; }; class XPT2046_Touchscreen { public: - constexpr XPT2046_Touchscreen(uint8_t cspin, uint8_t tirq=255) - : csPin(cspin), tirqPin(tirq) { } - bool begin(); - TS_Point getPoint(); - bool tirqTouched(); - bool touched(); - void readData(uint16_t *x, uint16_t *y, uint8_t *z); - bool bufferEmpty(); - uint8_t bufferSize() { return 1; } - void setRotation(uint8_t n) { rotation = n % 4; } - void setZThreshold( int16_t threshold ) { zThreshold= threshold; }; + // TODO: add TwoWire* to constructor + constexpr XPT2046_Touchscreen(uint8_t cspin, uint8_t tirq=255) + : csPin(cspin), tirqPin(tirq) { } + bool begin(); + TS_Point getPoint(); + bool tirqTouched(); + bool touched(); + void readData(uint16_t *x, uint16_t *y, uint8_t *z); + bool bufferEmpty(); + uint8_t bufferSize() { return 1; } + void setRotation(uint8_t n) { rotation = n % 4; } + void setZThreshold( int16_t threshold ) { zThreshold= threshold; }; void setZThresholdInt( int16_t threshold ) { zThresholdInt = threshold; }; // protected: - volatile bool isrWake=true; + volatile bool isrWake=true; private: - void update(); - uint8_t csPin, tirqPin, rotation=1; - int16_t xraw=0, yraw=0, zraw=0; + void update(); + uint8_t csPin, tirqPin, rotation=1; + int16_t xraw=0, yraw=0, zraw=0; int16_t zThreshold = Z_THRESHOLD, zThresholdInt = Z_THRESHOLD_INT; - uint32_t msraw=0x80000000; + uint32_t msraw=0x80000000; }; #ifndef ISR_PREFIX @@ -82,6 +83,3 @@ class XPT2046_Touchscreen { #define ISR_PREFIX #endif #endif - -#endif - From bd5c104988f9736170a87f4a0c67c477c15ed818 Mon Sep 17 00:00:00 2001 From: tobozo Date: Thu, 9 Dec 2021 14:09:37 +0100 Subject: [PATCH 16/20] macro tweaks --- src/utility/M5Timer.h | 3 +-- src/utility/Memory.h | 4 ++-- src/utility/TouchButton.h | 5 ++--- src/utility/quaternionFilters.h | 18 ++++++++---------- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/utility/M5Timer.h b/src/utility/M5Timer.h index 3f4d4c2..e3e604b 100644 --- a/src/utility/M5Timer.h +++ b/src/utility/M5Timer.h @@ -25,7 +25,7 @@ */ -#ifndef M5Timer_H +#pragma once #define M5Timer_H #include @@ -119,4 +119,3 @@ class M5Timer { int numTimers; }; -#endif diff --git a/src/utility/Memory.h b/src/utility/Memory.h index 2c224ec..dfbb922 100644 --- a/src/utility/Memory.h +++ b/src/utility/Memory.h @@ -1,4 +1,4 @@ -#ifndef __MEMORY_H +#pragma once #define __MEMORY_H @@ -25,4 +25,4 @@ class Memory { }; -#endif + diff --git a/src/utility/TouchButton.h b/src/utility/TouchButton.h index 13b2ec3..714015c 100644 --- a/src/utility/TouchButton.h +++ b/src/utility/TouchButton.h @@ -1,4 +1,4 @@ -#ifndef _TOUCH_BUTTON_H +#pragma once #define _TOUCH_BUTTON_H #include "../ESP32-Chimera-Core.h" @@ -99,6 +99,5 @@ bool currstate, laststate; }; - #endif // defined LGFX_HAS_TOUCHBUTTON +#endif // defined LGFX_HAS_TOUCHBUTTON -#endif // !defined _TOUCH_BUTTON_H diff --git a/src/utility/quaternionFilters.h b/src/utility/quaternionFilters.h index b1c3d4f..01f4743 100644 --- a/src/utility/quaternionFilters.h +++ b/src/utility/quaternionFilters.h @@ -1,14 +1,12 @@ -#ifndef _QUATERNIONFILTERS_H_ - #define _QUATERNIONFILTERS_H_ +#pragma once +#define _QUATERNIONFILTERS_H_ - #include +#include - void MadgwickQuaternionUpdate(float ax, float ay, float az, float gx, float gy, - float gz, float mx, float my, float mz, - float deltat); - void MahonyQuaternionUpdate(float ax, float ay, float az, float gx, float gy, +void MadgwickQuaternionUpdate(float ax, float ay, float az, float gx, float gy, float gz, float mx, float my, float mz, float deltat); - const float * getQ(); - -#endif // _QUATERNIONFILTERS_H_ +void MahonyQuaternionUpdate(float ax, float ay, float az, float gx, float gy, + float gz, float mx, float my, float mz, + float deltat); +const float * getQ(); From dcf1df592da036f661447fe5d2995b6f424859ed Mon Sep 17 00:00:00 2001 From: tobozo Date: Thu, 9 Dec 2021 14:12:15 +0100 Subject: [PATCH 17/20] preparing for upcoming ttgo-lora32 support --- .github/workflows/ArduinoBuild.yml | 1 + .github/workflows/PlatformioBuild.yml | 1 + examples/Tests/build_test/platformio.ini | 2 ++ 3 files changed, 4 insertions(+) diff --git a/.github/workflows/ArduinoBuild.yml b/.github/workflows/ArduinoBuild.yml index e1b7df1..ee8395c 100644 --- a/.github/workflows/ArduinoBuild.yml +++ b/.github/workflows/ArduinoBuild.yml @@ -35,6 +35,7 @@ jobs: - esp32:esp32:d32_pro - esp32:esp32:twatch - esp32:esp32:ttgo-t1 + #- esp32:esp32:ttgo-lora32 #- esp32:esp32:d-duino-32-xs platform-url: diff --git a/.github/workflows/PlatformioBuild.yml b/.github/workflows/PlatformioBuild.yml index 7b80d93..b68a7c9 100644 --- a/.github/workflows/PlatformioBuild.yml +++ b/.github/workflows/PlatformioBuild.yml @@ -35,6 +35,7 @@ jobs: - d32_pro - twatch - ttgo-t1 + #- ttgo-lora32 fail-fast: false diff --git a/examples/Tests/build_test/platformio.ini b/examples/Tests/build_test/platformio.ini index c8b81ef..9ccb7cf 100644 --- a/examples/Tests/build_test/platformio.ini +++ b/examples/Tests/build_test/platformio.ini @@ -49,3 +49,5 @@ board = ttgo-t-watch [env:ttgo-t1] board = ttgo-t1 +[env:ttgo-lora32] +board = ttgo-lora32 From 33e951f4aa838037656162435bc842f3e628b2ca Mon Sep 17 00:00:00 2001 From: tobozo Date: Thu, 9 Dec 2021 14:16:27 +0100 Subject: [PATCH 18/20] ScreenShots: Fix for builds without default filesystem --- src/ESP32-Chimera-Core.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ESP32-Chimera-Core.cpp b/src/ESP32-Chimera-Core.cpp index ce6069e..0be9e06 100644 --- a/src/ESP32-Chimera-Core.cpp +++ b/src/ESP32-Chimera-Core.cpp @@ -84,14 +84,14 @@ void M5Stack::begin(bool LCDEnable, bool SDEnable, bool SerialEnable, bool I2CEn Lcd.begin(); - ScreenShot = new ScreenShotService( &Lcd, &M5STACK_SD ); - - if( ScreenShotEnable == true ) { - #if defined HAS_SDCARD - ScreenShot->init(); - ScreenShot->begin(); - #endif - } + #if defined HAS_SDCARD + // note: builds without prefefined filesystem will need to run this manually + ScreenShot = new ScreenShotService( &Lcd, &M5STACK_SD ); + if( ScreenShotEnable == true ) { + ScreenShot->init(); + ScreenShot->begin(); + } + #endif } #if defined( ARDUINO_M5STACK_Core2 ) // M5Core2 starts APX after display is on From 31e15d9543f2f57954f03770535bcc3c47a454b4 Mon Sep 17 00:00:00 2001 From: tobozo Date: Thu, 9 Dec 2021 14:28:39 +0100 Subject: [PATCH 19/20] raising version --- library.json | 2 +- library.properties | 2 +- src/gitTagVersion.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/library.json b/library.json index 52af2a2..96e964b 100644 --- a/library.json +++ b/library.json @@ -22,7 +22,7 @@ "name": "LovyanGFX" } ], - "version": "1.2.7", + "version": "1.3.0", "framework": "arduino", "platforms": "espressif32", "headers": "ESP32-Chimera-Core.h", diff --git a/library.properties b/library.properties index b731c41..8b97c7c 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ESP32-Chimera-Core -version=1.2.7 +version=1.3.0 author=tobozo,Lovyan03 maintainer=tobozo@noreply.github.com sentence=Alternate library M5Stack/M5Core2/Odroid-Go/D-Duino and possiblly other ESP32/TFT/SD bundles diff --git a/src/gitTagVersion.h b/src/gitTagVersion.h index caaba49..e874109 100644 --- a/src/gitTagVersion.h +++ b/src/gitTagVersion.h @@ -1,8 +1,8 @@ #pragma once #define ECC_VERSION_MAJOR 1 -#define ECC_VERSION_MINOR 2 -#define ECC_VERSION_PATCH 7 +#define ECC_VERSION_MINOR 3 +#define ECC_VERSION_PATCH 0 #define _ECC_STR(x) #x #define ECC_STR(x) _ECC_STR(x) // Macro to convert library version number into an integer From 50d626f2538c1d6bb2f67b38fa3f2629b16e3059 Mon Sep 17 00:00:00 2001 From: tobozo Date: Thu, 9 Dec 2021 14:32:01 +0100 Subject: [PATCH 20/20] preview upcoming changes on official boards.txt for ttgo-lora32* boards --- .github/workflows/ArduinoBuild.yml | 2 +- .github/workflows/PlatformioBuild.yml | 2 +- boards/boards.local.txt | 126 ++++++++++++----------- examples/Tests/build_test/platformio.ini | 4 +- 4 files changed, 72 insertions(+), 62 deletions(-) diff --git a/.github/workflows/ArduinoBuild.yml b/.github/workflows/ArduinoBuild.yml index ee8395c..c0ada6a 100644 --- a/.github/workflows/ArduinoBuild.yml +++ b/.github/workflows/ArduinoBuild.yml @@ -35,7 +35,7 @@ jobs: - esp32:esp32:d32_pro - esp32:esp32:twatch - esp32:esp32:ttgo-t1 - #- esp32:esp32:ttgo-lora32 + #- esp32:esp32:ttgo-lora32-v2 #- esp32:esp32:d-duino-32-xs platform-url: diff --git a/.github/workflows/PlatformioBuild.yml b/.github/workflows/PlatformioBuild.yml index b68a7c9..211f1a0 100644 --- a/.github/workflows/PlatformioBuild.yml +++ b/.github/workflows/PlatformioBuild.yml @@ -35,7 +35,7 @@ jobs: - d32_pro - twatch - ttgo-t1 - #- ttgo-lora32 + #- ttgo-lora32-v2 fail-fast: false diff --git a/boards/boards.local.txt b/boards/boards.local.txt index 718a9a3..b86ceff 100644 --- a/boards/boards.local.txt +++ b/boards/boards.local.txt @@ -194,63 +194,73 @@ esp32_marauder.menu.DebugLevel.verbose.build.code_debug=5 - -ttgo-lora32-v2.name=TTGO LoRa32-OLED V2 - -ttgo-lora32-v2.upload.tool=esptool_py -ttgo-lora32-v2.upload.maximum_size=1310720 -ttgo-lora32-v2.upload.maximum_data_size=294912 -ttgo-lora32-v2.upload.flags= -ttgo-lora32-v2.upload.extra_flags= - -ttgo-lora32-v2.serial.disableDTR=true -ttgo-lora32-v2.serial.disableRTS=true - -ttgo-lora32-v2.build.tarch=xtensa -ttgo-lora32-v2.build.bootloader_addr=0x1000 -ttgo-lora32-v2.build.target=esp32 -ttgo-lora32-v2.build.mcu=esp32 -ttgo-lora32-v2.build.core=esp32 -ttgo-lora32-v2.build.variant=ttgo-lora32-v2 -ttgo-lora32-v2.build.board=TTGO_LoRa32_V2 - -ttgo-lora32-v2.build.f_cpu=240000000L -ttgo-lora32-v2.build.flash_mode=dio -ttgo-lora32-v2.build.flash_size=4MB -ttgo-lora32-v2.build.boot=dio -ttgo-lora32-v2.build.partitions=default - -ttgo-lora32-v2.menu.FlashFreq.80=80MHz -ttgo-lora32-v2.menu.FlashFreq.80.build.flash_freq=80m -ttgo-lora32-v2.menu.FlashFreq.40=40MHz -ttgo-lora32-v2.menu.FlashFreq.40.build.flash_freq=40m - -ttgo-lora32-v2.menu.UploadSpeed.921600=921600 -ttgo-lora32-v2.menu.UploadSpeed.921600.upload.speed=921600 -ttgo-lora32-v2.menu.UploadSpeed.115200=115200 -ttgo-lora32-v2.menu.UploadSpeed.115200.upload.speed=115200 -ttgo-lora32-v2.menu.UploadSpeed.256000.windows=256000 -ttgo-lora32-v2.menu.UploadSpeed.256000.upload.speed=256000 -ttgo-lora32-v2.menu.UploadSpeed.230400.windows.upload.speed=256000 -ttgo-lora32-v2.menu.UploadSpeed.230400=230400 -ttgo-lora32-v2.menu.UploadSpeed.230400.upload.speed=230400 -ttgo-lora32-v2.menu.UploadSpeed.460800.linux=460800 -ttgo-lora32-v2.menu.UploadSpeed.460800.macosx=460800 -ttgo-lora32-v2.menu.UploadSpeed.460800.upload.speed=460800 -ttgo-lora32-v2.menu.UploadSpeed.512000.windows=512000 -ttgo-lora32-v2.menu.UploadSpeed.512000.upload.speed=512000 - -ttgo-lora32-v2.menu.DebugLevel.none=None -ttgo-lora32-v2.menu.DebugLevel.none.build.code_debug=0 -ttgo-lora32-v2.menu.DebugLevel.error=Error -ttgo-lora32-v2.menu.DebugLevel.error.build.code_debug=1 -ttgo-lora32-v2.menu.DebugLevel.warn=Warn -ttgo-lora32-v2.menu.DebugLevel.warn.build.code_debug=2 -ttgo-lora32-v2.menu.DebugLevel.info=Info -ttgo-lora32-v2.menu.DebugLevel.info.build.code_debug=3 -ttgo-lora32-v2.menu.DebugLevel.debug=Debug -ttgo-lora32-v2.menu.DebugLevel.debug.build.code_debug=4 -ttgo-lora32-v2.menu.DebugLevel.verbose=Verbose -ttgo-lora32-v2.menu.DebugLevel.verbose.build.code_debug=5 +ttgo-lora32.name=TTGO LoRa32-OLED + +ttgo-lora32.upload.tool=esptool_py +ttgo-lora32.upload.maximum_size=1310720 +ttgo-lora32.upload.maximum_data_size=294912 +ttgo-lora32.upload.flags= +ttgo-lora32.upload.extra_flags= + +ttgo-lora32.serial.disableDTR=true +ttgo-lora32.serial.disableRTS=true + +ttgo-lora32.build.tarch=xtensa +ttgo-lora32.build.bootloader_addr=0x1000 +ttgo-lora32.build.target=esp32 +ttgo-lora32.build.mcu=esp32 +ttgo-lora32.build.core=esp32 +ttgo-lora32.build.board=TTGO_LoRa32 + +ttgo-lora32.menu.Revision.TTGO_LoRa32_V1=TTGO LoRa32 V1 (No TFCard) +ttgo-lora32.menu.Revision.TTGO_LoRa32_V1.build.board=TTGO_LoRa32_V1 +ttgo-lora32.menu.Revision.TTGO_LoRa32_V1.build.variant=ttgo-lora32-v1 + +ttgo-lora32.menu.Revision.TTGO_LoRa32_V2=TTGO LoRa32 V2 +ttgo-lora32.menu.Revision.TTGO_LoRa32_V2.build.board=TTGO_LoRa32_V2 +ttgo-lora32.menu.Revision.TTGO_LoRa32_V2.build.variant=ttgo-lora32-v2 + +ttgo-lora32.menu.Revision.TTGO_LoRa32_v21new=TTGO LoRa32 V2.1 (1.6.1) +ttgo-lora32.menu.Revision.TTGO_LoRa32_v21new.build.board=TTGO_LoRa32_v21new +ttgo-lora32.menu.Revision.TTGO_LoRa32_v21new.build.variant=ttgo-lora32-v21new + +ttgo-lora32.build.f_cpu=240000000L +ttgo-lora32.build.flash_mode=dio +ttgo-lora32.build.flash_size=4MB +ttgo-lora32.build.boot=dio +ttgo-lora32.build.partitions=default + +ttgo-lora32.menu.FlashFreq.80=80MHz +ttgo-lora32.menu.FlashFreq.80.build.flash_freq=80m +ttgo-lora32.menu.FlashFreq.40=40MHz +ttgo-lora32.menu.FlashFreq.40.build.flash_freq=40m + +ttgo-lora32.menu.UploadSpeed.921600=921600 +ttgo-lora32.menu.UploadSpeed.921600.upload.speed=921600 +ttgo-lora32.menu.UploadSpeed.115200=115200 +ttgo-lora32.menu.UploadSpeed.115200.upload.speed=115200 +ttgo-lora32.menu.UploadSpeed.256000.windows=256000 +ttgo-lora32.menu.UploadSpeed.256000.upload.speed=256000 +ttgo-lora32.menu.UploadSpeed.230400.windows.upload.speed=256000 +ttgo-lora32.menu.UploadSpeed.230400=230400 +ttgo-lora32.menu.UploadSpeed.230400.upload.speed=230400 +ttgo-lora32.menu.UploadSpeed.460800.linux=460800 +ttgo-lora32.menu.UploadSpeed.460800.macosx=460800 +ttgo-lora32.menu.UploadSpeed.460800.upload.speed=460800 +ttgo-lora32.menu.UploadSpeed.512000.windows=512000 +ttgo-lora32.menu.UploadSpeed.512000.upload.speed=512000 + +ttgo-lora32.menu.DebugLevel.none=None +ttgo-lora32.menu.DebugLevel.none.build.code_debug=0 +ttgo-lora32.menu.DebugLevel.error=Error +ttgo-lora32.menu.DebugLevel.error.build.code_debug=1 +ttgo-lora32.menu.DebugLevel.warn=Warn +ttgo-lora32.menu.DebugLevel.warn.build.code_debug=2 +ttgo-lora32.menu.DebugLevel.info=Info +ttgo-lora32.menu.DebugLevel.info.build.code_debug=3 +ttgo-lora32.menu.DebugLevel.debug=Debug +ttgo-lora32.menu.DebugLevel.debug.build.code_debug=4 +ttgo-lora32.menu.DebugLevel.verbose=Verbose +ttgo-lora32.menu.DebugLevel.verbose.build.code_debug=5 diff --git a/examples/Tests/build_test/platformio.ini b/examples/Tests/build_test/platformio.ini index 9ccb7cf..8fd6a5b 100644 --- a/examples/Tests/build_test/platformio.ini +++ b/examples/Tests/build_test/platformio.ini @@ -49,5 +49,5 @@ board = ttgo-t-watch [env:ttgo-t1] board = ttgo-t1 -[env:ttgo-lora32] -board = ttgo-lora32 +[env:ttgo-lora32-v2] +board = ttgo-lora32-v2