diff --git a/T-Beam_v10.cfg b/T-Beam_v10.cfg index d14132d..b1c1029 100644 --- a/T-Beam_v10.cfg +++ b/T-Beam_v10.cfg @@ -4,7 +4,9 @@ #define DEFAULT_PPSdelay 100 #define DEFAULT_FreqPlan 0 + // #define WITH_HELTEC // HELTEC module: PCB LED on GPI025 +// #define WITH_HELTEC_V2 // HELTEC module v2 // #define WITH_TTGO // TTGO module: PCB LED on GPIO2, GPIO25 free to use as DAC2 output // #define WITH_TBEAM // T-Beam module #define WITH_TBEAM_V10 // T-Beam module @@ -17,7 +19,7 @@ // #define WITH_TFT_LCD // TFT LCD // #define WITH_OLED // OLED display on the I2C: some TTGO modules are without OLED display // #define WITH_OLED2 // 2nd OLED display, I2C address next higher -// #define WITH_U8G2_OLED // I2C OLED through the U8g2 library +#define WITH_U8G2_OLED // I2C OLED through the U8g2 library // #define WITH_U8G2_SH1106 #define WITH_RFM95 // RF chip selection: both HELTEC and TTGO use sx1276 which is same as RFM95 @@ -46,6 +48,7 @@ // #define WITH_BMP280 // BMP280 pressure sensor #define WITH_BME280 // BMP280 with humidity (but still works with BMP280) // #define WITH_MS5607 // MS5607 pressure sensor +// #define WITH_MS5611 // MS5611 pressure sensor #define WITH_PFLAA // PFLAU and PFLAA for compatibility with XCsoar and LK8000 // #define WITH_POGNT @@ -67,5 +70,5 @@ // #define WITH_WIFI // attempt to connect to the wifi router for uploading the log files // #define WITH_SPIFFS_LOG // log transmitted and received packets to SPIFFS -// #define WITH_ENCRYPT // Encrypt (optionally) the position +#define WITH_ENCRYPT // Encrypt (optionally) the position diff --git a/main/config.h b/main/config.h index 590a51b..b1c1029 100644 --- a/main/config.h +++ b/main/config.h @@ -4,7 +4,9 @@ #define DEFAULT_PPSdelay 100 #define DEFAULT_FreqPlan 0 + // #define WITH_HELTEC // HELTEC module: PCB LED on GPI025 +// #define WITH_HELTEC_V2 // HELTEC module v2 // #define WITH_TTGO // TTGO module: PCB LED on GPIO2, GPIO25 free to use as DAC2 output // #define WITH_TBEAM // T-Beam module #define WITH_TBEAM_V10 // T-Beam module @@ -17,7 +19,7 @@ // #define WITH_TFT_LCD // TFT LCD // #define WITH_OLED // OLED display on the I2C: some TTGO modules are without OLED display // #define WITH_OLED2 // 2nd OLED display, I2C address next higher -// #define WITH_U8G2_OLED // I2C OLED through the U8g2 library +#define WITH_U8G2_OLED // I2C OLED through the U8g2 library // #define WITH_U8G2_SH1106 #define WITH_RFM95 // RF chip selection: both HELTEC and TTGO use sx1276 which is same as RFM95 @@ -54,7 +56,7 @@ #define WITH_CONFIG // interpret the console input: $POGNS to change parameters -#define WITH_BEEPER // with digital buzzer +// #define WITH_BEEPER // with digital buzzer // #define WITH_SOUND // with analog sound produced by DAC on pin 25 // #define WITH_KNOB @@ -68,5 +70,5 @@ // #define WITH_WIFI // attempt to connect to the wifi router for uploading the log files // #define WITH_SPIFFS_LOG // log transmitted and received packets to SPIFFS -// #define WITH_ENCRYPT // Encrypt (optionally) the position +#define WITH_ENCRYPT // Encrypt (optionally) the position diff --git a/main/ctrl.cpp b/main/ctrl.cpp index bfea6a0..f7b33f3 100644 --- a/main/ctrl.cpp +++ b/main/ctrl.cpp @@ -261,7 +261,11 @@ void SleepIn(void) #endif PowerMode=0; - vTaskDelay(1000); } + for(int Idx=0; Idx<1500; Idx++) + { LED_TimerCheck(1); + vTaskDelay(1); } + +} void SleepOut(void) { @@ -472,7 +476,7 @@ void vTaskCTRL(void* pvParameters) #endif #ifdef WITH_AXP -// #ifdef DEBUG_PRINT +#ifdef DEBUG_PRINT if(TimeChange) { uint16_t Batt=AXP.readBatteryVoltage(); // [mV] uint16_t InpCurr=AXP.readBatteryInpCurrent(); // [mA] @@ -501,7 +505,7 @@ void vTaskCTRL(void* pvParameters) Format_SignDec(CONS_UART_Write, Temp, 2, 1); Format_String(CONS_UART_Write, "degC\n"); xSemaphoreGive(CONS_Mutex); } -// #endif +#endif #endif #ifdef DEBUG_PRINT diff --git a/main/disp.cpp b/main/disp.cpp index 2f759f4..b59ef36 100644 --- a/main/disp.cpp +++ b/main/disp.cpp @@ -25,7 +25,11 @@ #include "disp_lcd.h" #ifdef WITH_U8G2_OLED +#ifdef WITH_U8G2_LISTS +const uint8_t DISP_Pages = 6+3; +#else const uint8_t DISP_Pages = 6; +#endif static uint8_t DISP_Page = 1; #endif #if defined(WITH_ST7789) || defined(WITH_ILI9341) @@ -39,8 +43,9 @@ void vTaskDISP(void* pvParameters) { #ifdef WITH_U8G2_OLED u8g2_ClearBuffer(&U8G2_OLED); - OLED_DrawLogo(&U8G2_OLED); + OLED_DrawLogo(&U8G2_OLED); // draw logo u8g2_SendBuffer(&U8G2_OLED); + vTaskDelay(5000); // allow 5sec for the user to see the logo #endif #if defined(WITH_ST7789) || defined(WITH_ILI9341) // LCD_Start(); @@ -48,6 +53,7 @@ void vTaskDISP(void* pvParameters) LCD_SetBacklightLevel(6); // backlight level #endif + uint32_t PrevTime=0; GPS_Position *PrevGPS=0; for( ; ; ) // @@ -65,19 +71,22 @@ void vTaskDISP(void* pvParameters) bool PageChange = 0; uint8_t Key = 0; KeyBuffer.Read(Key); // read key pressed from the buffer - if(Key) PageChange=1; // page-change on any key + // if(Key) PageChange=1; // page-change on any key uint32_t Time=TimeSync_Time(); bool TimeChange = Time!=PrevTime; // did time change = a new second ? uint32_t Sec = (Time-1)%60; GPS_Position *GPS = GPS_getPosition(Sec); bool GPSchange = GPS!=PrevGPS; // did GPS data change = new position ? - if(!PageChange) // if no page change was requested + if(Key==0) // { if( (!TimeChange) && (!GPSchange) ) continue; PrevTime=Time; PrevGPS=GPS; } #if defined(WITH_U8G2_OLED) || defined(WITH_ST7789) || defined(WITH_ILI9341) - if(PageChange) DISP_Page++; if(DISP_Page>=DISP_Pages) DISP_Page=0; + if(Key) + { if(Key&0x40) { if(DISP_Page==0) DISP_Page=DISP_Pages-1; else DISP_Page--; } + else { DISP_Page++; if(DISP_Page>=DISP_Pages) DISP_Page=0; } + PageChange=1; } #endif #if defined(WITH_ST7789) || defined(WITH_ILI9341) @@ -155,9 +164,11 @@ void vTaskDISP(void* pvParameters) // else if(PageChange || ( GPS?GPSchange:TimeChange) ) { u8g2_ClearBuffer(&U8G2_OLED); - // if(Look.WarnLevel) - // { OLED_DrawTrafWarn(&U8G2_OLED, GPS); } - // else +// #ifdef WITH_LOOKOUT +// if(Look.WarnLevel) +// { OLED_DrawTrafWarn(&U8G2_OLED, GPS); } +// else +// #endif { switch(DISP_Page) { case 2: OLED_DrawGPS (&U8G2_OLED, GPS); break; case 3: OLED_DrawRF (&U8G2_OLED); break; @@ -167,7 +178,11 @@ void vTaskDISP(void* pvParameters) // case 6: OLED_DrawRelay (&U8G2_OLED, GPS); break; // case 7: OLED_DrawLookout(&U8G2_OLED, GPS); break; case 0: OLED_DrawBattery(&U8G2_OLED); break; - // case 9: OLED_DrawTrafWarn(&U8G2_OLED, GPS); break; +#ifdef WITH_U8G2_LISTS + case 6: OLED_DrawRelay (&U8G2_OLED, GPS); break; + case 7: OLED_DrawLookout(&U8G2_OLED, GPS); break; + case 9: OLED_DrawTrafWarn(&U8G2_OLED, GPS); break; +#endif // default: // { OLED_DrawStatus(&U8G2_OLED, Time, 0); // OLED_DrawPosition(&U8G2_OLED, GPS, 2); } diff --git a/main/disp_oled.cpp b/main/disp_oled.cpp index 95f6f32..e3d498c 100644 --- a/main/disp_oled.cpp +++ b/main/disp_oled.cpp @@ -97,7 +97,7 @@ void OLED_DrawLogo(u8g2_t *OLED) // draw logo and hardware options in software #ifdef WITH_TTGO u8g2_DrawStr(OLED, 0, 16 ,"TTGO"); #endif -#ifdef WITH_HELTEC +#if defined(WITH_HELTEC) || defined(WITH_HELTEC_V2) u8g2_DrawStr(OLED, 0, 16 ,"HELTEC"); #endif #if defined(WITH_TBEAM) || defined(WITH_TBEAM_V10) @@ -301,8 +301,8 @@ void OLED_DrawRF(u8g2_t *OLED) // RF void OLED_DrawRelay(u8g2_t *OLED, GPS_Position *GPS) { u8g2_SetFont(OLED, u8g2_font_amstrad_cpc_extended_8r); - uint8_t Len=Format_String(Line, "Relay queue :"); - if(GPS && GPS->Sec>=0) Len+=Format_UnsDec(Line+Len, (uint16_t)(GPS->Sec), 2); + uint8_t Len=Format_String(Line, "Relay:"); + if(GPS && GPS->Sec>=0) { Len+=Format_UnsDec(Line+Len, (uint16_t)(GPS->Sec), 2); Line[Len++]='s'; } Line[Len]=0; u8g2_DrawStr(OLED, 0, 24, Line); uint8_t LineIdx=1; @@ -325,7 +325,7 @@ void OLED_DrawRelay(u8g2_t *OLED, GPS_Position *GPS) void OLED_DrawLookout(u8g2_t *OLED, GPS_Position *GPS) { u8g2_SetFont(OLED, u8g2_font_amstrad_cpc_extended_8r); - uint8_t Len=Format_String(Line, "Look "); + uint8_t Len=Format_String(Line, "=> "); if(Look.WarnLevel) { const LookOut_Target *Tgt = Look.Target+Look.WorstTgtIdx; Len+=Format_Hex(Line+Len, Tgt->ID, 7); @@ -363,26 +363,26 @@ void OLED_DrawTrafWarn(u8g2_t *OLED, GPS_Position *GPS) if(Look.WarnLevel==0) return; const LookOut_Target *Tgt = Look.Target+Look.WorstTgtIdx; uint8_t Len=0; - Len+=Format_Hex(Line+Len, Tgt->ID, 7); + Len+=Format_Hex(Line+Len, Tgt->ID, 7); // ID of the target Line[Len++]='/'; - Line[Len++]='0'+Tgt->WarnLevel; + Line[Len++]='0'+Tgt->WarnLevel; // warning level Line[Len]=0; u8g2_DrawStr(OLED, 0, 30, Line); Len=0; - Len+=Format_UnsDec(Line+Len, Tgt->TimeMargin*5, 2, 1); + Len+=Format_UnsDec(Line+Len, Tgt->TimeMargin*5, 2, 1); // time-to-impact Line[Len++]='s'; Line[Len++]=' '; - Len+=Format_UnsDec(Line+Len, Tgt->MissDist*5, 2, 1); + Len+=Format_UnsDec(Line+Len, Tgt->MissDist*5, 2, 1); // miss-distance Line[Len++]='m'; Line[Len]=0; u8g2_DrawStr(OLED, 0, 45, Line); Len=0; - Len+=Format_UnsDec(Line+Len, Tgt->getRelHorSpeed()*5, 2, 1); + Len+=Format_UnsDec(Line+Len, Tgt->getRelHorSpeed()*5, 2, 1); // horizontal speed Line[Len++]='m'; Line[Len++]='/'; Line[Len++]='s'; Line[Len++]=' '; - Len+=Format_UnsDec(Line+Len, Tgt->HorDist*5, 2, 1); + Len+=Format_UnsDec(Line+Len, Tgt->HorDist*5, 2, 1); // horizontal distance Line[Len++]='m'; Line[Len]=0; u8g2_DrawStr(OLED, 0, 60, Line); @@ -408,8 +408,8 @@ void OLED_DrawBaro(u8g2_t *OLED, GPS_Position *GPS) #endif if(GPS && GPS->hasBaro) { Len+=Format_UnsDec(Line+Len, GPS->Pressure/4, 5, 2); - Len+=Format_String(Line+Len, "Pa "); } - else Len+=Format_String(Line+Len, "----.--Pa "); + Len+=Format_String(Line+Len, "hPa "); } + else Len+=Format_String(Line+Len, "----.--hPa "); Line[Len]=0; u8g2_DrawStr(OLED, 0, 24, Line); Len=0; @@ -439,8 +439,8 @@ static uint8_t BattCapacity(uint16_t mVolt) if(mVolt<=3600) return 0; return (mVolt-3600+2)/5; } -void OLED_DrawBattery(u8g2_t *OLED) -{ uint8_t Cap=BattCapacity(BatteryVoltage>>8); +void OLED_DrawBattery(u8g2_t *OLED) // draw battery status page +{ uint8_t Cap=BattCapacity(BatteryVoltage>>8); // est. battery capacity based on the voltage readout // u8g2_SetFont(OLED, u8g2_font_battery19_tn); // u8g2_DrawGlyph(OLED, 120, 60, '0'+(Cap+10)/20); @@ -455,25 +455,34 @@ void OLED_DrawBattery(u8g2_t *OLED) if(Cap>=100) Format_UnsDec(Line, Cap, 3); else if(Cap>=10) Format_UnsDec(Line+1, Cap, 2); else Line[2]='0'+Cap; - u8g2_DrawStr (OLED, 16, 32, Line); - u8g2_DrawFrame(OLED, 12, 20, 42, 14); - u8g2_DrawBox (OLED, 8, 23, 4, 8); + u8g2_DrawStr (OLED, 16, 32, Line); // print battery est. capacity + u8g2_DrawFrame(OLED, 12, 20, 42, 14); // draw battery empty box around it + u8g2_DrawBox (OLED, 8, 23, 4, 8); // and the battery tip strcpy(Line, " . V"); - Format_UnsDec(Line, BatteryVoltage>>8, 4, 3); + Format_UnsDec(Line, BatteryVoltage>>8, 4, 3); // print the battery voltage readout u8g2_DrawStr(OLED, 0, 48, Line); - strcpy(Line, " . mV/min "); + strcpy(Line, " . mV/min "); // print the battery voltage rate Format_SignDec(Line, (600*BatteryVoltageRate+128)>>8, 3, 1); u8g2_DrawStr(OLED, 0, 60, Line); #ifdef WITH_BQ - // uint8_t Status = BQ.readStatus(); - // uint8_t State = (Status>>4)&0x03; - // const char *StateName[4] = { "Not charging", "Pre-charge", "Fast charge", "Full" } ; + uint8_t Fault = BQ.readFault(); // read fault register + uint8_t ChargeErr = (Fault>>4)&0x3F; // charging fault: + bool BattErr = Fault&0x08; // Battery OVP + bool OTGerr = Fault&0x40; // VBus problem + uint8_t NTCerr = Fault&0x03; // + uint8_t Status = BQ.readStatus(); // read status register + uint8_t State = (Status>>4)&0x03; // charging status + const char *StateName[4] = { "" /* "Not charging" */ , "Pre-charge", "Charging", "Full" } ; // u8g2_SetFont(OLED, u8g2_font_amstrad_cpc_extended_8r); - // u8g2_SetFont(OLED, u8g2_font_6x10_tr); - // u8g2_DrawStr(OLED, 0, 50, StateName[State]); + u8g2_SetFont(OLED, u8g2_font_6x10_tr); + if(Fault) + { strcpy(Line, "Fault: "); Format_Hex(Line+7, Fault); Line[9]=0; + u8g2_DrawStr(OLED, 60, 28, Line); } + else + u8g2_DrawStr(OLED, 60, 28, StateName[State]); // u8g2_DrawStr(OLED, 0, 60, Status&0x04?"Power-is-Good":"Power-is-not-Good"); /* print BQ registers for debug @@ -490,9 +499,9 @@ void OLED_DrawBattery(u8g2_t *OLED) void OLED_DrawStatusBar(u8g2_t *OLED, GPS_Position *GPS) { static bool Odd=0; - uint8_t Cap=BattCapacity(BatteryVoltage>>8); - uint8_t BattLev = (Cap+10)/20; - uint8_t Charging = 0; + uint8_t Cap = BattCapacity(BatteryVoltage>>8); // est. battery capacity + uint8_t BattLev = (Cap+10)/20; // [0..5] convert to display scale + uint8_t Charging = 0; // charging or not changing ? #ifdef WITH_BQ uint8_t Status = BQ.readStatus(); Charging = (Status>>4)&0x03; @@ -503,14 +512,18 @@ void OLED_DrawStatusBar(u8g2_t *OLED, GPS_Position *GPS) uint8_t &DispLev = BattLev; #endif if(BattLev==0 && !Charging && Odd) // when battery is empty, then flash it at 0.5Hz - { } - else + { } // thus here avoid printing the battery symbol for flashing effect + else // print the battery symbol with DispLev { u8g2_SetFont(OLED, u8g2_font_battery19_tn); u8g2_SetFontDirection(OLED, 3); - u8g2_DrawGlyph(OLED, 24, 10, '0'+DispLev); + u8g2_DrawGlyph(OLED, 20, 10, '0'+DispLev); u8g2_SetFontDirection(OLED, 0); } Odd=!Odd; - +#ifdef WITH_SD + if(SD_isMounted()) + { u8g2_SetFont(OLED, u8g2_font_twelvedings_t_all); + u8g2_DrawGlyph(OLED, 30, 12, 0x73); } +#endif // u8g2_SetFont(OLED, u8g2_font_5x7_tr); // u8g2_SetFont(OLED, u8g2_font_5x8_tr); static uint8_t Sec=0; @@ -528,7 +541,7 @@ void OLED_DrawStatusBar(u8g2_t *OLED, GPS_Position *GPS) { Format_UnsDec(Line, (uint16_t)(GPS_SatSNR+2)/4, 2); memcpy(Line+2, "dB ", 3);} } else Format_String(Line, "--sat"); - u8g2_DrawStr(OLED, 40, 10, Line); + u8g2_DrawStr(OLED, 52, 10, Line); Sec++; if(Sec>=3) Sec=0; } void OLED_DrawSystem(u8g2_t *OLED) @@ -625,16 +638,25 @@ void OLED_DrawSystem(u8g2_t *OLED) void OLED_DrawID(u8g2_t *OLED) { u8g2_SetFont(OLED, u8g2_font_9x15_tr); - strcpy(Line, "ID "); Parameters.Print(Line+3); Line[13]=0; - u8g2_DrawStr(OLED, 0, 28, Line); + Parameters.Print(Line); Line[10]=0; + u8g2_DrawStr(OLED, 26, 28, Line); // u8g2_SetFont(OLED, u8g2_font_10x20_tr); -#ifdef WITH_FollowMe u8g2_SetFont(OLED, u8g2_font_7x13_tf); + u8g2_DrawStr(OLED, 0, 27, "ID:"); + if(Parameters.Pilot[0] || Parameters.Reg[0]) + { strcpy(Line, "Reg: "); strcat(Line, Parameters.Reg); + u8g2_DrawStr(OLED, 0, 54, Line); + strcpy(Line, "Pilot: "); strcat(Line, Parameters.Pilot); + u8g2_DrawStr(OLED, 0, 42, Line); } + else + { +#ifdef WITH_FollowMe u8g2_DrawStr(OLED, 15, 44, "FollowMe868"); u8g2_DrawStr(OLED, 20, 56, "by AVIONIX"); #endif + } u8g2_SetFont(OLED, u8g2_font_5x8_tr); - u8g2_DrawStr(OLED, 96, 62, "v0.0.0"); + u8g2_DrawStr(OLED, 96, 62, "v0.1.1"); } #endif diff --git a/main/gps.cpp b/main/gps.cpp index 675f671..1fe1ca6 100644 --- a/main/gps.cpp +++ b/main/gps.cpp @@ -368,7 +368,7 @@ static void GPS_BurstComplete(void) // wh int32_t Alt = GPS->Altitude; // [0.1m] thus it appears to give pressure readout lower by a factor of two. int32_t Delta1 = StdAlt1-Alt; // [0.1m] Here we check which pressure fits better the GPS altitude int32_t Delta2 = StdAlt2-Alt; // [0.1m] - if(fabs(Delta1)StdAltitude=StdAlt1; } // + if( abs(Delta1)< abs(Delta2)) { GPS->StdAltitude=StdAlt1; } // else { GPS->Pressure*=2; GPS->StdAltitude=StdAlt2; } } #endif @@ -499,7 +499,7 @@ GPS_Position *GPS_getPosition(uint8_t &BestIdx, int16_t &BestRes, int8_t Sec, in int16_t Diff = TargetTime - (Pos->FracSec + (int16_t)Pos->Sec*100); // difference from the target time if(Diff<(-3000)) Diff+=6000; // wrap-around 60 sec else if(Diff>=3000) Diff-=6000; - if(fabs(Diff)data_ind.handle, Param->data_ind.data, Param->data_ind.len Format_String(CONS_UART_Write, "BT_SPP: ["); Format_UnsDec(CONS_UART_Write, Param->data_ind.len); Format_String(CONS_UART_Write, "]\n"); @@ -783,6 +797,8 @@ int CONS_UART_Read (uint8_t &Byte) { int Ret=getchar(); if(Ret>=0) { Byte=Ret // int CONS_UART_Free (void) { return UART2_Free(); } // int CONS_UART_Full (void) { return UART2_Full(); } +void CONS_UART_SetBaudrate(int BaudRate) { uart_set_baudrate(CONS_UART, BaudRate); } + //-------------------------------------------------------------------------------------------------------- // ADS-B UART @@ -1330,9 +1346,19 @@ void U8G2_Init(void) #ifdef WITH_SD -static sdmmc_host_t Host; -static sdspi_slot_config_t SlotConfig; -static esp_vfs_fat_sdmmc_mount_config_t MountConfig = +static sdmmc_host_t SD_Host = SDSPI_HOST_DEFAULT(); +// static spi_bus_config_t SD_BusConfig = { +// .mosi_io_num = PIN_SD_MOSI, +// .miso_io_num = PIN_SD_MISO, +// .sclk_io_num = PIN_SD_SCK, +// .quadwp_io_num = -1, +// .quadhd_io_num = -1, +// .max_transfer_sz = 4000, +// } ; +// static sdspi_device_config_t SD_SlotConfig = SDSPI_DEVICE_CONFIG_DEFAULT(); +static sdspi_slot_config_t SD_SlotConfig; + +static esp_vfs_fat_sdmmc_mount_config_t SD_MountConfig = { .format_if_mount_failed = false, .max_files = 5, /* .allocation_unit_size = 16 * 1024 */ }; @@ -1347,21 +1373,22 @@ void SD_Unmount(void) { esp_vfs_fat_sdmmc_unmount(); SD_Card=0; } esp_err_t SD_Mount(void) -{ esp_err_t Ret = esp_vfs_fat_sdmmc_mount("/sdcard", &Host, &SlotConfig, &MountConfig, &SD_Card); // ESP_OK => good, ESP_FAIL => failed to mound the file system, other => HW not working +{ esp_err_t Ret = esp_vfs_fat_sdmmc_mount("/sdcard", &SD_Host, &SD_SlotConfig, &SD_MountConfig, &SD_Card); // ESP_OK => good, ESP_FAIL => failed to mound the file system, other => HW not working if(Ret!=ESP_OK) SD_Unmount(); return Ret; } // ESP_OK => all good, ESP_FAIL => failed to mount file system, other => failed to init. the SD card static esp_err_t SD_Init(void) { - Host = SDSPI_HOST_DEFAULT(); + // Host = SDSPI_HOST_DEFAULT(); // Host.max_freq_khz = SDMMC_FREQ_PROBING; - - SlotConfig = SDSPI_SLOT_CONFIG_DEFAULT(); - SlotConfig.gpio_miso = PIN_SD_MISO; - SlotConfig.gpio_mosi = PIN_SD_MOSI; - SlotConfig.gpio_sck = PIN_SD_SCK; - SlotConfig.gpio_cs = PIN_SD_CS; - SlotConfig.dma_channel = SD_SPI_DMA; // otherwise it conflicts with RFM SPI or LCD SPI + // esp_err_t Ret = spi_bus_initialize((spi_host_device_t)SD_Host.slot, &SD_BusConfig, SD_SPI_DMA); + SD_SlotConfig = SDSPI_SLOT_CONFIG_DEFAULT(); + SD_SlotConfig.gpio_miso = PIN_SD_MISO; + SD_SlotConfig.gpio_mosi = PIN_SD_MOSI; + SD_SlotConfig.gpio_sck = PIN_SD_SCK; + SD_SlotConfig.gpio_cs = PIN_SD_CS; + // SD_SlotConfig.host_id = (spi_host_device_t)SD_Host.slot; + SD_SlotConfig.dma_channel = SD_SPI_DMA; // otherwise it conflicts with RFM SPI or LCD SPI return SD_Mount(); } // ESP_OK => all good, ESP_FAIL => failed to mount file system, other => failed to init. the SD card #endif // WITH_SD @@ -1588,7 +1615,7 @@ void IO_Configuration(void) { #ifdef PIN_LED_PCB - LED_PCB_Dir(); + LED_PCB_Dir(); // PCB LED LED_PCB_Off(); #endif #ifdef WITH_LED_TX @@ -1597,11 +1624,11 @@ void IO_Configuration(void) #endif #ifdef PIN_BUTTON - Button_Dir(); + Button_Dir(); // Push-button #endif #ifdef WITH_JACEK - POWER_LDO_Dir(); + POWER_LDO_Dir(); // speific power control POWER_Dir(); POWER_LDO_On(); POWER_On(); @@ -1609,7 +1636,7 @@ void IO_Configuration(void) #ifdef WITH_M5_JACEK GPS_ANT_Dir(); - GPS_ANT_Sel(1); // 0 = external entenna + GPS_ANT_Sel(1); // 0 = external entenna #endif #ifdef PIN_PERIPH_RST @@ -1689,7 +1716,7 @@ void IO_Configuration(void) BQ.checkID(); // BQ.writeSource(0x05); // Reg #00 // BQ.writePowerON(0x2F); // Reg #01, disable charging - BQ.writeChargeCurr(0x00); // Reg #02 + BQ.writeChargeCurr(0x20); // Reg #02 00 = 512mA, 0x20 = 512+512mA BQ.writePreCharge(0x00); // Reg #03 BQ.writeChargeVolt(0x9A); // Reg #04 // BQ.writePowerON(0x3F); // Reg #01, enable charging @@ -1803,7 +1830,9 @@ void IO_Configuration(void) LCD_WIDTH=240; LCD_HEIGHT=240; LCD_TYPE=0; #ifdef WITH_TBEAM_V10 - LCD_PIN_RST = GPIO_NUM_15; + LCD_PIN_RST = GPIO_NUM_33; + LCD_PIN_DC = GPIO_NUM_2; + LCD_PIN_BCKL = GPIO_NUM_35; // on one baord it is 15 #endif LCD_Init(LCD_SPI_HOST, LCD_SPI_MODE, LCD_SPI_SPEED); LCD_Start(); diff --git a/main/main.cpp b/main/main.cpp index 9f29031..068f26d 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -42,13 +42,18 @@ void app_main(void) IO_Configuration(); // initialize the GPIO/UART/I2C/SPI for Radio, GPS, OLED, Baro #ifdef WITH_SD - if(SD_isMounted()) + if(SD_isMounted()) // if SD card succesfully mounted at startup { Parameters.SaveToFlash=0; - if(Parameters.ReadFromFile("/sdcard/TRACKER.CFG")>0) - { if(Parameters.SaveToFlash) Parameters.WriteToNVS(); } + if(Parameters.ReadFromFile("/sdcard/TRACKER.CFG")>0) // try to read parameters from the TRACKER.CFG file + { if(Parameters.SaveToFlash) Parameters.WriteToNVS(); } // if succesfull and SaveToFlash==1 then save them to flash +// #ifdef WITH_SPIFFS +// SPIFFSlog_CopyToSD(); // copy all flash log files to the SD card +// #endif } #endif + CONS_UART_SetBaudrate(Parameters.CONbaud); + #ifdef WITH_BT_SPP { int32_t Err=BT_SPP_Init(); // start BT SPP // #ifdef DEBUG_PRINT @@ -63,7 +68,7 @@ void app_main(void) xTaskCreate(vTaskRF, "RF", 2048, 0, tskIDLE_PRIORITY+4, 0); #ifdef WITH_LOG - xTaskCreate(vTaskLOG , "LOG", 2560, 0, tskIDLE_PRIORITY+1, 0); + xTaskCreate(vTaskLOG , "LOG", 4096, 0, tskIDLE_PRIORITY+1, 0); #endif xTaskCreate(vTaskPROC, "PROC", 2048, 0, tskIDLE_PRIORITY+3, 0); xTaskCreate(vTaskGPS, "GPS", 2048, 0, tskIDLE_PRIORITY+4, 0); diff --git a/main/parameters.h b/main/parameters.h index fc34642..712efba 100644 --- a/main/parameters.h +++ b/main/parameters.h @@ -44,9 +44,16 @@ class FlashParameters int8_t RFchipTxPower; // [dBm] highest bit set => HW module (up to +20dBm Tx power) int8_t RFchipTempCorr; // [degC] correction to the temperature measured in the RF chip - uint32_t CONbaud; // [bps] Console baud rate + union + { uint32_t Console; + struct + { uint32_t CONbaud:24; // [bps] Console baud rate + uint8_t CONprot: 8; // [bit-mask] Console protocol mask: 0=minGPS, 1=allGPS, 2=Baro, 3=UBX, 4=OGN, 5=FLARM, 6=GDL90, 7= + } ; + } ; int16_t PressCorr; // [0.25Pa] pressure correction for the baro + union { uint16_t Flags; struct @@ -179,6 +186,7 @@ class FlashParameters RFchipTempCorr = 0; // [degC] CONbaud = DEFAULT_CONbaud; // [bps] + CONprot = 0xFF; PressCorr = 0; // [0.25Pa] TimeCorr = 0; // [sec] GeoidSepar = 10*DEFAULT_GeoidSepar; // [0.1m] @@ -438,9 +446,12 @@ class FlashParameters if(strcmp(Name, "AcftType")==0) { uint32_t Type=0; if(Read_Int(Type, Value)<=0) return 0; AcftType=Type; return 1; } - if(strcmp(Name, "Console")==0) + if(strcmp(Name, "CONbaud")==0) { uint32_t Baud=0; if(Read_Int(Baud, Value)<=0) return 0; CONbaud=Baud; return 1; } + if(strcmp(Name, "CONprot")==0) + { uint32_t Prot=0; if(Read_Int(Prot, Value)<=0) return 0; + CONprot=Prot; return 1; } if(strcmp(Name, "TxHW")==0) { int32_t HW=1; if(Read_Int(HW, Value)<=0) return 0; if(HW) setTxTypeHW(); else clrTxTypeHW(); } @@ -585,7 +596,8 @@ class FlashParameters Write_Hex (Line, "Address" , Address , 6); strcat(Line, " # [24-bit]\n"); if(fputs(Line, File)==EOF) return EOF; Write_Hex (Line, "AddrType" , AddrType, 1); strcat(Line, " # [2-bit]\n"); if(fputs(Line, File)==EOF) return EOF; Write_Hex (Line, "AcftType" , AcftType, 1); strcat(Line, " # [4-bit]\n"); if(fputs(Line, File)==EOF) return EOF; - Write_UnsDec (Line, "Console" , CONbaud ); strcat(Line, " # [ bps]\n"); if(fputs(Line, File)==EOF) return EOF; + Write_UnsDec (Line, "CONbaud" , CONbaud ); strcat(Line, " # [ bps]\n"); if(fputs(Line, File)==EOF) return EOF; + Write_Hex (Line, "CONprot" , CONprot, 1); strcat(Line, " # [ mask]\n"); if(fputs(Line, File)==EOF) return EOF; Write_SignDec(Line, "TxPower" , getTxPower() ); strcat(Line, " # [ dBm]\n"); if(fputs(Line, File)==EOF) return EOF; Write_UnsDec (Line, "TxHW" ,(uint32_t)isTxTypeHW() ); strcat(Line, " # [ bool]\n"); if(fputs(Line, File)==EOF) return EOF; Write_UnsDec (Line, "FreqPlan" ,(uint32_t)FreqPlan ); strcat(Line, " # [ 0..5]\n"); if(fputs(Line, File)==EOF) return EOF; @@ -634,7 +646,8 @@ class FlashParameters Write_Hex (Line, "Address" , Address , 6); strcat(Line, " # [24-bit]\n"); Format_String(Output, Line); Write_Hex (Line, "AddrType" , AddrType, 1); strcat(Line, " # [2-bit]\n"); Format_String(Output, Line); Write_Hex (Line, "AcftType" , AcftType, 1); strcat(Line, " # [4-bit]\n"); Format_String(Output, Line); - Write_UnsDec (Line, "Console" , CONbaud ); strcat(Line, " # [ bps]\n"); Format_String(Output, Line); + Write_UnsDec (Line, "CONbaud" , CONbaud ); strcat(Line, " # [ bps]\n"); Format_String(Output, Line); + Write_Hex (Line, "CONprot" , CONprot, 1); strcat(Line, " # [ mask]\n"); Format_String(Output, Line); Write_SignDec(Line, "TxPower" , getTxPower() ); strcat(Line, " # [ dBm]\n"); Format_String(Output, Line); Write_UnsDec (Line, "TxHW" ,(uint32_t)isTxTypeHW() ); strcat(Line, " # [ bool]\n"); Format_String(Output, Line); Write_UnsDec (Line, "FreqPlan" ,(uint32_t)FreqPlan ); strcat(Line, " # [ 0..5]\n"); Format_String(Output, Line); @@ -648,10 +661,10 @@ class FlashParameters Write_UnsDec (Line, "NavRate" , (uint32_t)NavRate ); strcat(Line, " # [ 1,2]\n"); Format_String(Output, Line); #ifdef WITH_ENCRYPT Write_UnsDec (Line, "Encrypt" , Encrypt ); strcat(Line, " # [ 1|0]\n"); Format_String(Output, Line); - Write_Hex (Line, "EncryptKey[0]", EncryptKey[0] , 8); strcat(Line, " # [32-bit]\n"); Format_String(Output, Line); - Write_Hex (Line, "EncryptKey[1]", EncryptKey[1] , 8); strcat(Line, " # [32-bit]\n"); Format_String(Output, Line); - Write_Hex (Line, "EncryptKey[2]", EncryptKey[2] , 8); strcat(Line, " # [32-bit]\n"); Format_String(Output, Line); - Write_Hex (Line, "EncryptKey[3]", EncryptKey[3] , 8); strcat(Line, " # [32-bit]\n"); Format_String(Output, Line); + // Write_Hex (Line, "EncryptKey[0]", EncryptKey[0] , 8); strcat(Line, " # [32-bit]\n"); Format_String(Output, Line); + // Write_Hex (Line, "EncryptKey[1]", EncryptKey[1] , 8); strcat(Line, " # [32-bit]\n"); Format_String(Output, Line); + // Write_Hex (Line, "EncryptKey[2]", EncryptKey[2] , 8); strcat(Line, " # [32-bit]\n"); Format_String(Output, Line); + // Write_Hex (Line, "EncryptKey[3]", EncryptKey[3] , 8); strcat(Line, " # [32-bit]\n"); Format_String(Output, Line); #endif Write_UnsDec (Line, "Verbose" , (uint32_t)Verbose ); strcat(Line, " # [ 0..3]\n"); Format_String(Output, Line); Write_UnsDec (Line, "PPSdelay" ,(uint32_t)PPSdelay ); strcat(Line, " # [ ms]\n"); Format_String(Output, Line);