From eb767f0c98c9b9ad5452271d45a6bdc64edccfa1 Mon Sep 17 00:00:00 2001 From: qqqlab <46283638+qqqlab@users.noreply.github.com> Date: Wed, 31 Jan 2024 17:43:05 +0100 Subject: [PATCH] Black Box --- madflight/madflight.ino | 8 +- madflight/src/bb/BlackBoxWriter.h | 14 +- madflight/src/bb/W25Qxx/W25Qxx.h | 288 ----------------------------- madflight/src/bb/W25Qxx/W25Qxx.ino | 159 ---------------- madflight/src/bb/bb.h | 178 ++++-------------- 5 files changed, 46 insertions(+), 601 deletions(-) delete mode 100644 madflight/src/bb/W25Qxx/W25Qxx.h delete mode 100644 madflight/src/bb/W25Qxx/W25Qxx.ino diff --git a/madflight/madflight.ino b/madflight/madflight.ino index f6a81f5..9b95a59 100644 --- a/madflight/madflight.ino +++ b/madflight/madflight.ino @@ -1,6 +1,4 @@ -#define APPNAME "madflight v1.0.1-dev" - -//this is a development version - random stuff does not work - use latest release if you want something more stable +#define APPNAME "madflight v1.0.1" //Arduino ESP32 / RP2040 / STM32 Flight Controller //GPL-3.0 license @@ -47,7 +45,7 @@ fast blinking - something is wrong, connect USB serial for info #define RCIN_NUM_CHANNELS 6 //number of receiver channels (minimal 6) //--- IMU SENSOR -#define IMU_USE IMU_USE_SPI_MPU9250 // IMU_USE_SPI_BMI270, IMU_USE_SPI_MPU9250, IMU_USE_SPI_MPU6500, IMU_USE_SPI_MPU6000, IMU_USE_I2C_MPU9250, IMU_USE_I2C_MPU9150, IMU_USE_I2C_MPU6500, IMU_USE_I2C_MPU6050, IMU_USE_I2C_MPU6000 +#define IMU_USE IMU_USE_SPI_MPU6500 // IMU_USE_SPI_BMI270, IMU_USE_SPI_MPU9250, IMU_USE_SPI_MPU6500, IMU_USE_SPI_MPU6000, IMU_USE_I2C_MPU9250, IMU_USE_I2C_MPU9150, IMU_USE_I2C_MPU6500, IMU_USE_I2C_MPU6050, IMU_USE_I2C_MPU6000 //Set sensor orientation. The label is yaw / roll (in that order) needed to rotate the sensor from it's normal position to it's mounted position. //if not sure what is needed: try each setting until roll-right gives positive ahrs_roll, pitch-up gives positive ahrs_pitch, and yaw-right gives positive ahrs_yaw #define IMU_ALIGN IMU_ALIGN_CW0 //IMU_ALIGN_CW0, IMU_ALIGN_CW90, IMU_ALIGN_CW180, IMU_ALIGN_CW270, IMU_ALIGN_CW0FLIP, IMU_ALIGN_CW90FLIP, IMU_ALIGN_CW180FLIP, IMU_ALIGN_CW270FLIP @@ -67,7 +65,7 @@ fast blinking - something is wrong, connect USB serial for info #define BAT_USE BAT_USE_NONE // BAT_USE_INA226, BAT_USE_ADC, BAT_USE_NONE //--- BLACKBOX LOGGER -#define BB_USE BB_USE_NONE //BB_USE_FLASH log to internal or external flash, BB_USE_RAM log to ram or psram, BB_USE_NONE +#define BB_USE BB_USE_NONE //BB_USE_INTFLASH internal flash, BB_USE_FLASH external flash, BB_USE_RAM ram or psram, BB_USE_NONE //========================================================================================================================// // BOARD // diff --git a/madflight/src/bb/BlackBoxWriter.h b/madflight/src/bb/BlackBoxWriter.h index 9555cc0..f31a18c 100644 --- a/madflight/src/bb/BlackBoxWriter.h +++ b/madflight/src/bb/BlackBoxWriter.h @@ -111,17 +111,17 @@ void writeI16(String name, int16_t value) { } } -void writeUnsignedVB(String name, uint32_t value) { +void writeU(String name, uint32_t value) { if(logStarted) { - logUnsignedVB(value); + logU(value); }else{ writeHeaderField(name, BB_DATATYPE_UVB); } } -void writeSignedVB(String name, int32_t value) { +void writeI(String name, int32_t value) { if(logStarted) { - logSignedVB((uint32_t)value); + logI((uint32_t)value); }else{ writeHeaderField(name, BB_DATATYPE_SVB); } @@ -198,7 +198,7 @@ void logFloat(float value) { } //Write an unsigned integer to the blackbox using variable byte encoding. -void logUnsignedVB(uint32_t value) +void logU(uint32_t value) { //While this isn't the final byte (we can only write 7 bits at a time) while (value > 127) { @@ -210,10 +210,10 @@ void logUnsignedVB(uint32_t value) //Write a signed integer to the blackbox using ZigZig and variable byte encoding. -void logSignedVB(int32_t value) +void logI(int32_t value) { //ZigZag encode to make the value always positive - logUnsignedVB(zigzagEncode(value)); + logU(zigzagEncode(value)); } /** diff --git a/madflight/src/bb/W25Qxx/W25Qxx.h b/madflight/src/bb/W25Qxx/W25Qxx.h deleted file mode 100644 index c5ecf11..0000000 --- a/madflight/src/bb/W25Qxx/W25Qxx.h +++ /dev/null @@ -1,288 +0,0 @@ -// madflight https://github.com/qqqlab/madflight -// Header only W25Q64/W25Q128 SPI Flash Memory class - -// adapted from https://github.com/Tamakichi/Arduino-W25Q64 - -#pragma once - -#include - -class W25Qxx { - public: - -enum { - SPI_SLAVE_SEL_PIN = 10, - MAX_BLOCKSIZE = 128, - MAX_SECTORSIZE = 2048 -}; - -enum { - CMD_WRITE_STATUS_R = 0x01, - CMD_PAGE_PROGRAM = 0x02, - CMD_READ_DATA = 0x03, - CMD_WRITE_DISABLE = 0x04, - CMD_READ_STATUS_R1 = 0x05, - CMD_WRIRE_ENABLE = 0x06, - CMD_FAST_READ = 0x0B, - CMD_SECTOR_ERASE = 0x20, - CMD_QUAD_PAGE_PROGRAM = 0x32, - CMD_READ_STATUS_R2 = 0x35, - CMD_READ_DUAL_OUTPUT = 0x3B, - CMD_READ_UNIQUE_ID = 0x4B, - CMD_READ_QUAD_OUTPUT = 0x6B, - CMD_BLOCK_ERASE32KB = 0x52, - CMD_ERASE_SUPPEND = 0x75, - CMD_ERASE_RESUME = 0x7A, - CMD_MANUFACURER_ID = 0x90, - CMD_JEDEC_ID = 0x9F, - CMD_HIGH_PERFORM_MODE = 0xA3, - CMD_RELEASE_PDOWN_ID = 0xAB, - CMD_POWER_DOWN = 0xB9, - CMD_READ_DUAL_IO = 0xBB, - CMD_CHIP_ERASE = 0xC7, - CMD_BLOCK_ERASE64KB = 0xD8, - CMD_WORD_READ = 0xE3, - CMD_READ_QUAD_IO = 0xEB, - CMD_CNT_READ_MODE_RST = 0xFF -}; - -enum { - SR1_BUSY_MASK = 0x01, - SR1_WEN_MASK = 0x02 -}; - -private: - -uint8_t _cspin ; -SPIClass* _SPI = &SPI; -SPISettings _SPISettings; - -public: - -void setSPIPort(SPIClass * SPI) { - _SPI = SPI; -} - -void begin(uint8_t cs, uint32_t frq) { - _cspin = cs; - pinMode( _cspin, OUTPUT); - deselect(); - _SPISettings = SPISettings(frq, MSBFIRST, SPI_MODE0); - _SPI->begin(); -} - -void end() { - powerDown(); - deselect(); - _SPI->end(); -} - -void select() { - _SPI->beginTransaction( _SPISettings); - digitalWrite( _cspin, LOW); -} - -void deselect() { - digitalWrite( _cspin, HIGH); - _SPI->endTransaction(); -} - -uint8_t readStatusReg1() { - uint8_t rc; - select(); - _SPI->transfer(CMD_READ_STATUS_R1); - rc = _SPI->transfer(0xFF); - deselect(); - return rc; -} - -uint8_t readStatusReg2() { - uint8_t rc; - select(); - _SPI->transfer(CMD_READ_STATUS_R2); - rc = _SPI->transfer(0xFF); - deselect(); - return rc; -} - -void readManufacturer(uint8_t* d) { - select(); - _SPI->transfer(CMD_JEDEC_ID); - for (uint8_t i =0; i <3; i++) { - d[i] = _SPI->transfer(0x00); - } - deselect(); -} - -int readSize() { - uint8_t d[3]; - readManufacturer(d); - return (2<transfer(CMD_READ_UNIQUE_ID); - _SPI->transfer(0x00); - _SPI->transfer(0x00); - _SPI->transfer(0x00); - _SPI->transfer(0x00); - for (uint8_t i =0; i <8; i++) { - d[i] = _SPI->transfer(0x00); - } - deselect(); -} - -bool IsBusy() { - uint8_t r1; - select(); - _SPI->transfer(CMD_READ_STATUS_R1); - r1 = _SPI->transfer(0xff); - deselect(); - if(r1 & SR1_BUSY_MASK) - return true; - return false; -} - -void powerDown() { - select(); - _SPI->transfer(CMD_POWER_DOWN); - deselect(); -} - -void writeEnable() { - select(); - _SPI->transfer(CMD_WRIRE_ENABLE); - deselect(); -} - -void writeDisable() { - select(); - _SPI->transfer(CMD_WRITE_DISABLE); - deselect(); -} - -uint16_t read(uint32_t addr, uint8_t *buf, uint16_t n){ - select(); - _SPI->transfer(CMD_READ_DATA); - _SPI->transfer(addr>>16); - _SPI->transfer((addr>>8) & 0xFF); - _SPI->transfer(addr & 0xFF); - - uint16_t i; - for(i = 0; itransfer(0x00); - } - - deselect(); - return i; -} - -uint16_t fastread(uint32_t addr, uint8_t *buf, uint16_t n) { - select(); - _SPI->transfer(CMD_FAST_READ); - _SPI->transfer(addr>>16); - _SPI->transfer((addr>>8) & 0xFF); - _SPI->transfer(addr & 0xFF); - _SPI->transfer(0x00); - - uint16_t i; - for(i = 0; itransfer(0x00); - - deselect(); - return i; -} - -bool eraseSector(uint16_t sect_no, bool flgwait) { - uint32_t addr = sect_no; - addr<<=12; - - writeEnable(); - select(); - _SPI->transfer(CMD_SECTOR_ERASE); - _SPI->transfer((addr>>16) & 0xff); - _SPI->transfer((addr>>8) & 0xff); - _SPI->transfer(addr & 0xff); - deselect(); - - while(IsBusy() & flgwait) { - delay(1); - } - - return true; -} - -bool erase64Block(uint16_t blk_no, bool flgwait) { - uint32_t addr = blk_no; - addr<<=16; - - writeEnable(); - select(); - _SPI->transfer(CMD_BLOCK_ERASE64KB); - _SPI->transfer((addr>>16) & 0xff); - _SPI->transfer((addr>>8) & 0xff); - _SPI->transfer(addr & 0xff); - deselect(); - - while(IsBusy() & flgwait) { - delay(5); - } - - return true; -} - -bool erase32Block(uint16_t blk_no, bool flgwait) { - - uint32_t addr = blk_no; - addr<<=15; - - writeEnable(); - select(); - _SPI->transfer(CMD_BLOCK_ERASE32KB); - _SPI->transfer((addr>>16) & 0xff); - _SPI->transfer((addr>>8) & 0xff); - _SPI->transfer(addr & 0xff); - deselect(); - - while(IsBusy() & flgwait) { - delay(5); - } - - return true; -} - -bool eraseAll(bool flgwait) { - writeEnable(); - select(); - _SPI->transfer(CMD_CHIP_ERASE); - deselect(); - - while(IsBusy() & flgwait) { - delay(50); - } - - deselect(); - return true; -} - -uint16_t pageWrite(uint32_t addr, uint8_t* data, uint16_t n, bool flgwait) { - uint16_t i; - writeEnable(); - if (IsBusy()) { - return 0; - } - select(); - _SPI->transfer(CMD_PAGE_PROGRAM); - _SPI->transfer((addr>>16) & 0xff); - _SPI->transfer((addr>>8) & 0xff); - _SPI->transfer(addr & 0xff); - for (i=0; i < n; i++) { - _SPI->transfer(data[i]); - } - deselect(); - if(flgwait) while(IsBusy()); - return i; -} - -}; \ No newline at end of file diff --git a/madflight/src/bb/W25Qxx/W25Qxx.ino b/madflight/src/bb/W25Qxx/W25Qxx.ino deleted file mode 100644 index 5ba4df3..0000000 --- a/madflight/src/bb/W25Qxx/W25Qxx.ino +++ /dev/null @@ -1,159 +0,0 @@ -#include "W25Qxx.h" - -#define HW_PIN_FLASH_CS PB3 -SPIClass MySPI(PC12,PC11,PC10); -W25Qxx w25qxx; - -void setup() { - uint32_t t; - byte buf[256]; - byte wdata[256]; - uint16_t n; - - for (int i=0; i<256; i++) { - wdata[i] = i & 0x7f; - } - - w25qxx.setSPIPort(&MySPI); - w25qxx.begin(HW_PIN_FLASH_CS,18000000); - - Serial.begin(115200); - - //3 second startup delay - for(int i=10;i>0;i--) { - Serial.printf("starting %d ...\n",i); - delay(300); - } - - w25qxx.readManufacturer(buf); - Serial.print("JEDEC ID : "); - for (byte i=0; i< 3; i++) { - Serial.print(buf[i],HEX); - Serial.print(" "); - } - Serial.println(""); - - Serial.printf("Size: %d bytes\n", w25qxx.readSize()); - - memset(buf,0,8); - w25qxx.readUniqieID(buf); - Serial.print("Unique ID : "); - for (byte i=0; i< 8; i++) { - Serial.print(buf[i],HEX); - Serial.print(" "); - } - Serial.println(""); - - //read 256 byte page - memset(buf,0,256); - t = micros(); - n = w25qxx.read(0, buf, 256); - t = micros()-t; - Serial.printf("dt=%d us - ", t); - Serial.print("Read Data: n="); - Serial.println(n,DEC); - dump(buf,256); - - //fast read 256 byte page - memset(buf,0,256); - t = micros(); - n = w25qxx.fastread(256, buf, 256); - t = micros()-t; - Serial.printf("dt=%d us - ", t); - Serial.print("Fast Read Data: n="); - Serial.println(n, DEC); - dump(buf,256); - - //erase 4K sector - t = micros(); - n = w25qxx.eraseSector(0,true); - t = micros()-t; - Serial.printf("dt=%d us - ", t); - Serial.print("Erase Sector(0): n="); - Serial.println(n, DEC); - memset(buf,0,256); - n = w25qxx.read(0, buf, 256); - dump(buf,256); - - //write 16 bytes page - t = micros(); - n = w25qxx.pageWrite(10, wdata, 16, true); - t = micros()-t; - Serial.printf("dt=%d us - ", t); - Serial.print("page_write(10,d,16): n="); - Serial.println(n, DEC); - memset(buf,0,256); - n = w25qxx.read(0,buf, 256); - dump(buf,256); - - //write 256 byte page - t = micros(); - n = w25qxx.pageWrite(256, wdata, 256, true); - t = micros()-t; - Serial.printf("dt=%d us - ", t); - Serial.print("page_write(256,d,256): n="); - Serial.println(n, DEC); - memset(buf,0,256); - n = w25qxx.read(256, buf, 256); - dump(buf,256); - - buf[0] = w25qxx.readStatusReg1(); - Serial.print("Status Register-1: "); - Serial.print(buf[0], BIN); - Serial.println(""); - - buf[0] = w25qxx.readStatusReg2(); - Serial.print("Status Register-2: "); - Serial.print(buf[0], BIN); - Serial.println(""); -} - -void loop() { - -} - -void dump(byte *dt, uint32_t n) { - char buf[64]; - uint16_t clm = 0; - byte data; - byte sum; - byte vsum[16]; - byte total =0; - uint32_t saddr =0; - uint32_t eaddr =n-1; - - Serial.println("----------------------------------------------------------"); - for (uint16_t i=0;i<16;i++) vsum[i]=0; - for (uint32_t addr = saddr; addr <= eaddr; addr++) { - data = dt[addr]; - if (clm == 0) { - sum =0; - sprintf(buf,"%05lx: ",addr); - Serial.print(buf); - } - - sum+=data; - vsum[addr % 16]+=data; - - sprintf(buf,"%02x ",data); - Serial.print(buf); - clm++; - if (clm == 16) { - sprintf(buf,"|%02x ",sum); - Serial.print(buf); - Serial.println(""); - clm = 0; - } - } - Serial.println("----------------------------------------------------------"); - Serial.print(" "); - for (uint16_t i=0; i<16;i++) { - total+=vsum[i]; - sprintf(buf,"%02x ",vsum[i]); - Serial.print(buf); - } - sprintf(buf,"|%02x ",total); - Serial.print(buf); - Serial.println(""); - Serial.println(""); -} diff --git a/madflight/src/bb/bb.h b/madflight/src/bb/bb.h index 87662ea..bdbd4c1 100644 --- a/madflight/src/bb/bb.h +++ b/madflight/src/bb/bb.h @@ -14,7 +14,7 @@ In addition there are these functions common for all blackbox variants: HOW TO ADD YOUR OWN LOGGERS 1. add a recordtype_e enum - 2. add a new BlackBoxBase::log_xxx() for your logger. Use writeU() and writeI() to write variable byte encoded integer (these take 1-5 bytes of space) + 2. add a new BlackBoxBase::log_xxx() for your logger. 3. add a call to your logger in BlackBoxBase::start() to write the header 4. call bb.log_xxx() in madflight.ino to log data @@ -22,8 +22,9 @@ Note: this header needs to be included after all globals are defined in madfligh ========================================================================================================================*/ #define BB_USE_NONE 1 -#define BB_USE_FLASH 2 -#define BB_USE_RAM 3 +#define BB_USE_INTFLASH 2 //internal QSPI/OSPI flash +#define BB_USE_FLASH 3 //external SPI flash +#define BB_USE_RAM 4 //internal RAM (or PSRAM on ESP32) #include "BlackBox_Defines.h" #include "BlackBoxWriter.h" @@ -43,59 +44,60 @@ class BlackBox { public: + //loggers - Use writeU() and writeI() to write variable byte encoded integer, which use 1-5 bytes void log_imu() { if(bbw.isBusy()) return; //sets busy flag bbw.writeBeginRecord(BB_REC_IMU, "IMU"); - bbw.writeUnsignedVB("ts",micros()); - bbw.writeSignedVB("ax*100",AccX*100); //G - bbw.writeSignedVB("ay*100",AccY*100); //G - bbw.writeSignedVB("az*100",AccZ*100); //G - bbw.writeSignedVB("gx*10",GyroX*10); //dps - bbw.writeSignedVB("gy*10",GyroY*10); //dps - bbw.writeSignedVB("gz*10",GyroZ*10); //dps - bbw.writeSignedVB("mx*100",MagX*100); //uT - bbw.writeSignedVB("my*100",MagX*100); //uT - bbw.writeSignedVB("mz*100",MagX*100); //uT - bbw.writeSignedVB("roll*10",ahrs_roll*10); //deg - bbw.writeSignedVB("pitch*10",ahrs_pitch*10);; //deg - bbw.writeSignedVB("yaw*10",ahrs_yaw*10);; //deg + bbw.writeU("ts",micros()); + bbw.writeI("ax*100",AccX*100); //G + bbw.writeI("ay*100",AccY*100); //G + bbw.writeI("az*100",AccZ*100); //G + bbw.writeI("gx*10",GyroX*10); //dps + bbw.writeI("gy*10",GyroY*10); //dps + bbw.writeI("gz*10",GyroZ*10); //dps + bbw.writeI("mx*100",MagX*100); //uT + bbw.writeI("my*100",MagX*100); //uT + bbw.writeI("mz*100",MagX*100); //uT + bbw.writeI("roll*10",ahrs_roll*10); //deg + bbw.writeI("pitch*10",ahrs_pitch*10);; //deg + bbw.writeI("yaw*10",ahrs_yaw*10);; //deg bbw.writeEndrecord(); //clears busy flag } void log_pid() { if(bbw.isBusy()) return; bbw.writeBeginRecord(BB_REC_PID, "PID"); - bbw.writeUnsignedVB("ts",micros()); - bbw.writeSignedVB("roll_PID*100",roll_PID*100); //-1 to +1 - bbw.writeSignedVB("pitch_PID*100",pitch_PID*100);; //-1 to +1 - bbw.writeSignedVB("yaw_PID*100",yaw_PID*100);; //-1 to +1 + bbw.writeU("ts",micros()); + bbw.writeI("roll_PID*100",roll_PID*100); //-1 to +1 + bbw.writeI("pitch_PID*100",pitch_PID*100);; //-1 to +1 + bbw.writeI("yaw_PID*100",yaw_PID*100);; //-1 to +1 bbw.writeEndrecord(); } void log_bat() { if(bbw.isBusy()) return; bbw.writeBeginRecord(BB_REC_BAT, "BAT"); - bbw.writeUnsignedVB("ts",micros()); - bbw.writeUnsignedVB("bat_mA",bat.i*1000); //Battery current (A) - bbw.writeUnsignedVB("bat_mV",bat.v*1000); //battery voltage (V) - bbw.writeUnsignedVB("bat_mAh",bat.mah); //battery usage (Ah) - bbw.writeUnsignedVB("bat_mWh",bat.wh*1000); //battery usage (Wh) + bbw.writeU("ts",micros()); + bbw.writeU("bat_mA",bat.i*1000); //Battery current (A) + bbw.writeU("bat_mV",bat.v*1000); //battery voltage (V) + bbw.writeU("bat_mAh",bat.mah); //battery usage (Ah) + bbw.writeU("bat_mWh",bat.wh*1000); //battery usage (Wh) bbw.writeEndrecord(); } void log_baro() { if(bbw.isBusy()) return; bbw.writeBeginRecord(BB_REC_BARO, "BARO"); - bbw.writeUnsignedVB("ts",micros()); - bbw.writeUnsignedVB("baro_pa",baro.press_pa); //Barometer pressure (Pa) - bbw.writeSignedVB("baro_t*100",baro.temp_c*100); //barometer temp (C) + bbw.writeU("ts",micros()); + bbw.writeU("baro_pa",baro.press_pa); //Barometer pressure (Pa) + bbw.writeI("baro_t*100",baro.temp_c*100); //barometer temp (C) bbw.writeEndrecord(); } void log_gps() { if(bbw.isBusy()) return; bbw.writeBeginRecord(BB_REC_GPS, "GPS"); - bbw.writeUnsignedVB("ts",micros()); + bbw.writeU("ts",micros()); bbw.writeI32("lat",gps.lat); bbw.writeI32("lon",gps.lon); bbw.writeEndrecord(); @@ -161,17 +163,12 @@ class BlackBox { //===================================================================================================================== // Logging to FLASH (internal or external) //===================================================================================================================== -#if BB_USE == BB_USE_FLASH +#if BB_USE == BB_USE_INTFLASH || BB_USE == BB_USE_FLASH #include "SPIFlash/Adafruit_SPIFlashBase.h" -//TODO -// Un-comment to run example with custom SPI and SS e.g with FRAM breakout -// #define CUSTOM_CS A5 -// #define CUSTOM_SPI SPI - -#if defined(CUSTOM_CS) && defined(CUSTOM_SPI) - Adafruit_FlashTransport_SPI flashTransport(CUSTOM_CS, CUSTOM_SPI); +#if BB_USE == BB_USE_FLASH + Adafruit_FlashTransport_SPI flashTransport(HW_PIN_BB_CS, bb_spi); #elif defined(ARDUINO_ARCH_ESP32) // ESP32 use same flash device that store code for file system. // SPIFlash will parse partition.cvs to detect FATFS/SPIFS partition to use @@ -183,7 +180,7 @@ class BlackBox { // 'Tools->Flash Size' menu selection will be used. Adafruit_FlashTransport_RP2040 flashTransport; #else - #error No (Q)SPI flash defined for your board ! + #error BB_USE_INTFLASH No internal flash defined for your board ! #endif Adafruit_SPIFlashBase flash(&flashTransport); @@ -309,7 +306,7 @@ class BlackBoxFS_Flash : public BlackBoxFS { //Serial.printf("page_min=%8d page_max=%8d page=%8d ", page_min, page_max, page); //for(int i=0;i<16;i++) Serial.printf(" %02X",buf[i]); //Serial.println(); - for(int i=0;i>1; - uint32_t stepsize = w25qxx_adr>>1; - uint8_t buf[16]; - while(stepsize>=16) { - w25qxx.read(w25qxx_adr, buf, 16); - int32_t step = -stepsize; - for(int i=0;i<16;i++) if(buf[i]!=0xff) { - step = +stepsize; - break; - } - w25qxx_adr += step; - stepsize >>= 1; - } - w25qxx_adr = ((w25qxx_adr / BB_BUF_SIZE) + 1) * BB_BUF_SIZE; //move to next BB_BUF_SIZE boundary - w25qxx_startadr = w25qxx_adr; - } - - //static callback - #include "W25Qxx/W25Qxx.h" - static W25Qxx w25qxx; - static uint8_t buf[BB_BUF_SIZE]; - static uint32_t w25qxx_size; - static uint32_t w25qxx_adr; - static uint32_t w25qxx_startadr; - static int buf_len; - static int buf_idx; - static uint32_t w25qxx_readadr; - - static uint8_t callback_bbReadChar() { - if(buf_idx >= BB_BUF_SIZE) { - w25qxx.read(w25qxx_readadr, buf, BB_BUF_SIZE); - w25qxx_readadr += BB_BUF_SIZE; - buf_idx = 0; - } - return buf[buf_idx++]; - } - - static void callback_bbWriteChar(uint8_t c) { - if(buf_len < BB_BUF_SIZE) { - buf[buf_len++] = c; - }else{ - w25qxx.pageWrite(w25qxx_adr, buf, BB_BUF_SIZE, false); //non-blocking write - w25qxx_adr += BB_BUF_SIZE; - buf_len = 0; - } - } -}; - -BlackBox::W25Qxx BlackBox::w25qxx; -uint8_t BlackBox::buf[BB_BUF_SIZE]; -uint32_t BlackBox::w25qxx_size; -uint32_t BlackBox::w25qxx_adr; -uint32_t BlackBox::w25qxx_startadr; -int BlackBox::buf_len; -int BlackBox::buf_idx; -uint32_t BlackBox::w25qxx_readadr; -*/ - //===================================================================================================================== // Logging to RAM Memory //=====================================================================================================================