From 194bc83e859f50e57d7774d42824c5901fdf4676 Mon Sep 17 00:00:00 2001 From: ligenxxxx <59721724+ligenxxxx@users.noreply.github.com> Date: Mon, 17 Jul 2023 09:20:39 +0800 Subject: [PATCH 01/14] add HDZ FREESTYLE V2 target --- platformio.ini | 1 + src/common.h | 5 +++ src/dm6300.c | 4 ++- src/dm6300.h | 2 +- src/hardware.c | 35 +++++++++++-------- src/hardware.h | 4 +-- src/msp_displayport.c | 60 ++++++++++++++++++++++----------- src/smartaudio_protocol.c | 8 ++--- targets/hdzero_freestyle_v2.ini | 9 +++++ 9 files changed, 86 insertions(+), 42 deletions(-) create mode 100644 targets/hdzero_freestyle_v2.ini diff --git a/platformio.ini b/platformio.ini index b6c1235..82d6085 100644 --- a/platformio.ini +++ b/platformio.ini @@ -19,4 +19,5 @@ extra_configs = targets/hdzero_race_v2.ini targets/foxeer_vtx.ini targets/hdzero_race_v3.ini + targets/hdzero_freestyle_v2.ini \ No newline at end of file diff --git a/src/common.h b/src/common.h index b62fcda..3d0b86f 100644 --- a/src/common.h +++ b/src/common.h @@ -15,6 +15,7 @@ // #define HDZERO_FREESTYLE // #define FOXEER_VTX // #define HDZERO_RACE_V3 +// define HDZERO_FREESTYLE_V2 /* define VTX ID start */ #if defined HDZERO_WHOOP @@ -31,6 +32,8 @@ #define VTX_ID 0x59 #elif defined HDZERO_RACE_V3 #define VTX_ID 0x5a +#elif defined HDZERO_FREESTYLE_V2 +#define VTX_ID 0x5b #else #define VTX_ID 0x00 #endif @@ -50,6 +53,8 @@ #define VTX_NAME "FOX VTX" #elif defined HDZERO_RACE_V3 #define VTX_NAME "HDZ RACE V3" +#elif defined HDZERO_FREESTYLE_V2 +#define VTX_NAME "HDZ FREESTYLE V2" #else #define VTX_NAME " " #endif diff --git a/src/dm6300.c b/src/dm6300.c index cabc32f..2195ce6 100644 --- a/src/dm6300.c +++ b/src/dm6300.c @@ -23,7 +23,7 @@ uint32_t dcoc_ih = 0x075F0000; uint32_t dcoc_qh = 0x075F0000; uint8_t dm6300_init_done = 0; -#ifdef HDZERO_FREESTYLE +#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 uint8_t table_power[FREQ_MAX_EXT + 1][POWER_MAX + 1] = { {0x70, 0x68, 0x5c, 0x60}, {0x70, 0x68, 0x5c, 0x60}, @@ -164,6 +164,8 @@ uint16_t DM6300_GetFreqByChannel(uint8_t const ch) { void DM6300_SetPower(uint8_t pwr, uint8_t freq, uint8_t offset) { #ifdef HDZERO_FREESTYLE uint16_t a_tab[4] = {0x204, 0x11F, 0x21F, 0x31F}; +#elif defined HDZERO_FREESTYLE_V2 + uint16_t a_tab[4] = {0x21F, 0x21F, 0x31F, 0x31F}; #else uint16_t a_tab[2] = {0x21F, 0x41F}; #endif diff --git a/src/dm6300.h b/src/dm6300.h index a8494d1..1872878 100644 --- a/src/dm6300.h +++ b/src/dm6300.h @@ -4,7 +4,7 @@ #include "common.h" #include "hardware.h" -#ifdef HDZERO_FREESTYLE +#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 #define PIT_POWER 0x18 // 2dbm #else #define PIT_POWER 0x26 diff --git a/src/hardware.c b/src/hardware.c index e4f1221..8bd805e 100644 --- a/src/hardware.c +++ b/src/hardware.c @@ -18,7 +18,7 @@ uint8_t KEYBOARD_ON = 0; // avoid conflict between keyboard and cam_control uint8_t EE_VALID = 0; -#ifdef HDZERO_FREESTYLE +#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 uint8_t powerLock = 1; #endif @@ -26,7 +26,7 @@ uint8_t powerLock = 1; // // POWER MODE // -// HDZERO_FREESTYLE +// HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 // 0------------25mW (14dBm) // 1------------200mW (23dBm) // 2------------500mW (27dBm) @@ -349,7 +349,8 @@ void GetVtxParameter() { for (j = 0; j <= POWER_MAX; j++) { table_power[i][j] = tab[i][j]; #ifndef _RF_CALIB -#ifndef HDZERO_FREESTYLE +#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 +#else if (j == 0) // 25mw +3dbm table_power[i][j] += 0xC; #endif @@ -362,7 +363,8 @@ void GetVtxParameter() { table_power[8][j] = tab[3][j]; table_power[9][j] = tab[4][j]; if (j == 0) { // 25mw +3dbm -#ifndef HDZERO_FREESTYLE +#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 +#else table_power[8][j] += 0x0C; table_power[9][j] += 0x0C; #endif @@ -413,7 +415,7 @@ void GetVtxParameter() { #endif #endif -#ifdef HDZERO_FREESTYLE +#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 // powerLock powerLock = 0x01 & I2C_Read8_Wait(10, ADDR_EEPROM, EEP_ADDR_POWER_LOCK); #endif @@ -471,7 +473,7 @@ void Init_6300RF(uint8_t freq, uint8_t pwr) { DM6300_Init(freq, RF_BW); DM6300_SetChannel(freq); #ifndef VIDEO_PAT -#ifdef HDZERO_FREESTYLE +#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 if ((pwr == 3) && (!g_IS_ARMED)) pwr_lmt_done = 0; else @@ -789,7 +791,11 @@ void HeatProtect() { int16_t temp; #ifdef USE_TEMPERATURE_SENSOR - int16_t temp_max = 0x5A; +#ifdef HDZERO_FREESTYLE_V2 + int16_t temp_max = 95; +#else + int16_t temp_max = 90; +#endif #else int16_t temp_max = 0x5C0; int16_t temp_err_data = 0x700; @@ -833,7 +839,7 @@ void HeatProtect() { debugf("\r\nHeat Protect."); #endif heat_protect = 1; -#ifdef HDZERO_FREESTYLE +#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 WriteReg(0, 0x8F, 0x00); msp_set_vtx_config(POWER_MAX + 1, 0); #else @@ -870,7 +876,7 @@ void PwrLMT() { pwr_tflg = 0; pwr_lmt_sec++; -#ifdef HDZERO_FREESTYLE +#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 // test: power plus every sec if (pwr_lmt_sec >= 3) { if (RF_POWER == 3) { @@ -925,6 +931,7 @@ void PwrLMT() { */ else if (g_IS_ARMED) { // Armed PowerAutoSwitch(); + HeatProtect(); } else { // Disarmed if (PIT_MODE) { /*if(cur_pwr == 0mW) @@ -942,7 +949,7 @@ void PwrLMT() { pwr_tflg = 0; pwr_lmt_sec++; -#ifdef HDZERO_FREESTYLE +#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 // test: power plus every sec if (pwr_lmt_sec >= 3) { if (RF_POWER == 3) { @@ -962,7 +969,7 @@ void PwrLMT() { SPI_Write(0x3, 0x330, 0x31F); // analog offset 1W } } -#endif // HDZERO_FREESTYLE +#endif // HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 #ifdef _DEBUG_MODE debugf("\r\npwr_lmt_sec %x", (uint16_t)pwr_lmt_sec); @@ -1117,7 +1124,7 @@ void Imp_RF_Param() { if (LP_MODE && !g_IS_ARMED) return; #ifndef VIDEO_PAT -#ifdef HDZERO_FREESTYLE +#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 if (RF_POWER == 3 && !g_IS_ARMED) pwr_lmt_done = 0; else @@ -1180,7 +1187,7 @@ void Button1_SP() { RF_POWER = 0; else RF_POWER++; -#ifdef HDZERO_FREESTYLE +#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 if (powerLock) RF_POWER &= 0x01; #endif @@ -1193,7 +1200,7 @@ void Button1_SP() { cur_pwr = 0; } else { #ifndef VIDEO_PAT -#ifdef HDZERO_FREESTYLE +#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 if (RF_POWER == 3 && !g_IS_ARMED) pwr_lmt_done = 0; else diff --git a/src/hardware.h b/src/hardware.h index 3c0b124..adb22d6 100644 --- a/src/hardware.h +++ b/src/hardware.h @@ -50,7 +50,7 @@ typedef enum { #define FREQ_MAX 7 #define FREQ_MAX_EXT 9 -#if defined HDZERO_FREESTYLE +#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 #define POWER_MAX 3 #else #define POWER_MAX 1 @@ -97,7 +97,7 @@ void vtx_paralized(void); void timer_task(); -#ifdef HDZERO_FREESTYLE +#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 extern uint8_t powerLock; #endif extern uint8_t RF_FREQ; diff --git a/src/msp_displayport.c b/src/msp_displayport.c index 4624423..0dda710 100644 --- a/src/msp_displayport.c +++ b/src/msp_displayport.c @@ -474,9 +474,31 @@ uint8_t get_tx_data_5680() // prepare data to VRX // VTX temp and overhot #ifdef USE_TEMPERATURE_SENSOR +#if defined HDZERO_FREESTYLE_V2 + temp = temperature >> 2; + if (temp > 90) + temp = 8; + else if (temp > 85) + temp = 7; + else if (temp > 80) + temp = 6; + else if (temp > 75) + temp = 5; + else if (temp > 70) + temp = 4; + else if (temp > 60) + temp = 3; + else if (temp > 50) + temp = 2; + else if (temp > 40) + temp = 1; + else + temp = 0; +#else temp = temperature_level() >> 1; if (temp > 8) temp = 8; +#endif tx_buf[10] = 0x80 | (heat_protect << 6) | temp; #else tx_buf[10] = 0; @@ -723,10 +745,10 @@ void msp_set_vtx_config(uint8_t power, uint8_t save) { uint8_t band; uint16_t const freq = DM6300_GetFreqByChannel(channel); - if (channel < 8) { // race band + if (channel < 8) { // race band band = 5; channel = channel + 1; - } else { // fatshark band + } else { // fatshark band band = 4; if (channel == 8) channel = 2; @@ -769,7 +791,7 @@ void msp_set_vtx_config(uint8_t power, uint8_t save) { crc ^= 0x05; // band count CMS_tx(0x08); crc ^= 0x08; // channel count -#ifdef HDZERO_FREESTYLE +#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 if (powerLock) { CMS_tx(3); crc ^= (3); // power count @@ -834,9 +856,9 @@ void parse_rc() { } uint8_t parse_vtx_band_and_channel(uint8_t const band, uint8_t const channel) { - if (band == 5) { // race band + if (band == 5) { // race band return (channel - 1); - } else if (band == 4) { // fatshark band + } else if (band == 4) { // fatshark band if (channel == 2) { return 8; } @@ -862,9 +884,8 @@ uint8_t msp_vtx_set_channel(uint8_t const channel) { void parse_vtx_config() { uint8_t nxt_ch; - //uint8_t const power = msp_rx_buf[3]; - //uint8_t const pitmode = msp_rx_buf[4]; - + // uint8_t const power = msp_rx_buf[3]; + // uint8_t const pitmode = msp_rx_buf[4]; /* nxt_pwr: @@ -873,9 +894,9 @@ void parse_vtx_config() { ..... POWER_MAX+1: 0mw */ - //uint8_t nxt_pwr = 0; - //uint8_t pit_update = 0; - //uint8_t needSaveEEP = 0; + // uint8_t nxt_pwr = 0; + // uint8_t pit_update = 0; + // uint8_t needSaveEEP = 0; fc_lock |= FC_VTX_CONFIG_LOCK; @@ -901,7 +922,6 @@ void parse_vtx_config() { msp_vtx_set_channel(nxt_ch); // PIT_MODE ? // RF_POWER ? - } void msp_set_osd_canvas(void) { @@ -1022,7 +1042,7 @@ void parseMspVtx_V2(uint16_t const cmd_u16) { vtx_pit_save = PIT_MODE; } else { #ifndef VIDEO_PAT -#ifdef HDZERO_FREESTYLE +#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 if ((RF_POWER == 3) && (!g_IS_ARMED)) pwr_lmt_done = 0; else @@ -1074,7 +1094,7 @@ void parseMspVtx_V2(uint16_t const cmd_u16) { if (dm6300_init_done) { if (cur_pwr != RF_POWER) { #ifndef VIDEO_PAT -#ifdef HDZERO_FREESTYLE +#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 if ((RF_POWER == 3) && (!g_IS_ARMED)) pwr_lmt_done = 0; else @@ -1393,7 +1413,7 @@ void update_cms_menu(uint16_t roll, uint16_t pitch, uint16_t yaw, uint16_t throt ; else { vtx_power++; -#ifdef HDZERO_FREESTYLE +#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 if (powerLock) vtx_power &= 0x01; #endif @@ -1407,7 +1427,7 @@ void update_cms_menu(uint16_t roll, uint16_t pitch, uint16_t yaw, uint16_t throt ; else { vtx_power--; -#ifdef HDZERO_FREESTYLE +#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 if (powerLock) vtx_power &= 0x01; #endif @@ -1843,7 +1863,7 @@ void set_vtx_param() { debugf("\n\rExit PIT or LP"); #endif #ifndef VIDEO_PAT -#ifdef HDZERO_FREESTYLE +#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 if (RF_POWER == 3 && !g_IS_ARMED) pwr_lmt_done = 0; else @@ -1854,7 +1874,7 @@ void set_vtx_param() { cur_pwr = RF_POWER; } } else if (heat_protect) { -#ifdef HDZERO_FREESTYLE +#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 WriteReg(0, 0x8F, 0x00); WriteReg(0, 0x8F, 0x01); DM6300_Init(RF_FREQ, RF_BW); @@ -1887,7 +1907,7 @@ void set_vtx_param() { } #ifdef INIT_VTX_TABLE -#define FACTORY_BAND 0 // BF requires band to be CUSTOM with VTX_MSP +#define FACTORY_BAND 0 // BF requires band to be CUSTOM with VTX_MSP CODE_SEG const uint8_t bf_vtx_band_table[6][31] = { /*BOSCAM_A*/ @@ -1943,7 +1963,7 @@ void InitVtxTable() { power_table[0] = bf_vtx_power_table[0]; power_table[1] = bf_vtx_power_table[1]; -#if defined HDZERO_FREESTYLE +#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 if (!powerLock) { // if we dont have power lock, enable 500mw and 1W power_table[2] = bf_vtx_power_500mW; diff --git a/src/smartaudio_protocol.c b/src/smartaudio_protocol.c index 2bf41fd..600c7ae 100644 --- a/src/smartaudio_protocol.c +++ b/src/smartaudio_protocol.c @@ -118,7 +118,7 @@ void SA_Response(uint8_t cmd) { tbuf[7] = freq_new_h; // cur_freq_h tbuf[8] = freq_new_l; // cur_freq_l tbuf[9] = SA_dbm; // power dbm -#ifdef HDZERO_FREESTYLE +#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 if (powerLock) { tbuf[10] = 1 + 1; // amount of power level for (i = 0; i <= 1; i++) @@ -249,7 +249,7 @@ void SA_Update(uint8_t cmd) { } } else { cur_pwr = dbm_to_pwr(SA_dbm); -#ifdef HDZERO_FREESTYLE +#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 if (powerLock) cur_pwr &= 0x01; #endif @@ -258,7 +258,7 @@ void SA_Update(uint8_t cmd) { pwr_init = cur_pwr; else { #ifndef VIDEO_PAT -#ifdef HDZERO_FREESTYLE +#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 if ((RF_POWER == 3) && (!g_IS_ARMED)) pwr_lmt_done = 0; else @@ -364,7 +364,7 @@ void SA_Update(uint8_t cmd) { temp_err = 1; } else { #ifndef VIDEO_PAT -#ifdef HDZERO_FREESTYLE +#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 if ((RF_POWER == 3) && (!g_IS_ARMED)) { pwr_lmt_done = 0; cur_pwr = 3; diff --git a/targets/hdzero_freestyle_v2.ini b/targets/hdzero_freestyle_v2.ini new file mode 100644 index 0000000..882f80c --- /dev/null +++ b/targets/hdzero_freestyle_v2.ini @@ -0,0 +1,9 @@ +[env:hdzero_freestyle_v2] +extends = DM5680 +build_flags = + ${DM5680.build_flags} + -DHDZERO_FREESTYLE_V2 + -DUSE_SMARTAUDIO_SW + -DUSE_TEMPERATURE_SENSOR + -DUSE_PA_EN + -DUSE_TC3587_LED \ No newline at end of file From 7f25fdcfc3076810ae751ab8929adedb0da3de7e Mon Sep 17 00:00:00 2001 From: ligenxxxx <59721724+ligenxxxx@users.noreply.github.com> Date: Fri, 25 Aug 2023 14:27:07 +0800 Subject: [PATCH 02/14] Update msp_displayport.c --- src/msp_displayport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/msp_displayport.c b/src/msp_displayport.c index f0ba1f6..3ad71be 100644 --- a/src/msp_displayport.c +++ b/src/msp_displayport.c @@ -1121,7 +1121,7 @@ void parseMspVtx_V2(uint16_t const cmd_u16) { if (dm6300_init_done) { if (cur_pwr != nxt_pwr) { #ifndef VIDEO_PAT -#ifdef HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 +#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2 if ((nxt_pwr == 3) && (!g_IS_ARMED)) pwr_lmt_done = 0; else From 16eb03705359cd34781d42631d51302fde5347d5 Mon Sep 17 00:00:00 2001 From: ligenxxxx <59721724+ligenxxxx@users.noreply.github.com> Date: Fri, 25 Aug 2023 15:57:34 +0800 Subject: [PATCH 03/14] add SPI_DLY1 for HDZ_L2 --- src/hardware.c | 2 +- src/monitor.c | 2 +- src/rom.c | 6 +++--- src/spi.c | 12 ++++++++++++ src/uart.c | 3 +++ 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/hardware.c b/src/hardware.c index 838b928..de4201c 100644 --- a/src/hardware.c +++ b/src/hardware.c @@ -384,7 +384,7 @@ void GetVtxParameter() { #ifdef _RF_CALIB for (i = 0; i < FREQ_NUM_INTERNAL; i++) { for (j = 0; j <= POWER_MAX; j++) { - I2C_Write8_Wait(10, ADDR_EEPROM, i * (POWER_MAX + 1) + j, table_power[0][i][j]); + I2C_Write8_Wait(10, ADDR_EEPROM, i * (POWER_MAX + 1) + j, table_power[i][j]); } } #endif diff --git a/src/monitor.c b/src/monitor.c index 6c2eeaa..8c2cd0e 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -188,7 +188,7 @@ void MonEE(uint8_t op, uint8_t d) { } val = I2C_Read8_Wait(10, ADDR_EEPROM, addr); - table_power[0][RF_FREQ][RF_POWER] = val; + table_power[RF_FREQ][RF_POWER] = val; debugf("\r\nRF TAB[%d][%d] = %x", (uint16_t)RF_FREQ, (uint16_t)RF_POWER, val); DM6300_SetPower(RF_POWER, RF_FREQ, pwr_offset); diff --git a/src/rom.c b/src/rom.c index c29e351..23ba178 100644 --- a/src/rom.c +++ b/src/rom.c @@ -29,16 +29,16 @@ void CalibProc() { switch (rxbuf[0]) { case 'r': for (cnt = 0; cnt < FREQ_NUM_INTERNAL * (POWER_MAX + 1); cnt++) { - Rom_tx(table_power[0][cnt / (POWER_MAX + 1)][cnt % (POWER_MAX + 1)]); + Rom_tx(table_power[cnt / (POWER_MAX + 1)][cnt % (POWER_MAX + 1)]); } break; case 'w': - table_power[0][RF_FREQ][RF_POWER] = rxbuf[1]; + table_power[RF_FREQ][RF_POWER] = rxbuf[1]; DM6300_SetPower(RF_POWER, RF_FREQ, pwr_offset); - I2C_Write8_Wait(10, ADDR_EEPROM, RF_FREQ * (POWER_MAX + 1) + RF_POWER, table_power[0][RF_FREQ][RF_POWER]); + I2C_Write8_Wait(10, ADDR_EEPROM, RF_FREQ * (POWER_MAX + 1) + RF_POWER, table_power[RF_FREQ][RF_POWER]); break; case 'c': diff --git a/src/spi.c b/src/spi.c index 498b70a..179442f 100644 --- a/src/spi.c +++ b/src/spi.c @@ -15,6 +15,14 @@ while (i--) \ ; \ } +#ifdef HDZERO_FREESTYLE_V2 +#define SPI_DLY1 \ + { \ + int i = 5; \ + while (i--) \ + ; \ + } +#endif void SPI_Init() { SET_CS(1); @@ -29,7 +37,11 @@ void SPI_Write_Byte(uint8_t dat) { SPI_DLY; SET_DO((dat >> i) & 0x01); +#ifdef HDZERO_FREESTYLE_V2 + SPI_DLY1; +#else SPI_DLY; +#endif SET_CK(1); SPI_DLY; diff --git a/src/uart.c b/src/uart.c index 9ccbf74..a10a7b5 100644 --- a/src/uart.c +++ b/src/uart.c @@ -29,6 +29,9 @@ volatile BIT_TYPE RS_Xbusy1 = 0; #endif void uart_set_baudrate(uint8_t baudIndex) { +#if defined _DEBUG_MODE || defined _RF_CALIB + baudIndex = 0; +#endif switch (baudIndex) { case 0: // 115200 CKCON = 0x1F; From 4529e4037fafa120fd1264e6df2591092a112977 Mon Sep 17 00:00:00 2001 From: ligenxxxx <59721724+ligenxxxx@users.noreply.github.com> Date: Mon, 28 Aug 2023 15:03:15 +0800 Subject: [PATCH 04/14] spi dly is 1 --- src/spi.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/spi.c b/src/spi.c index 179442f..498b70a 100644 --- a/src/spi.c +++ b/src/spi.c @@ -15,14 +15,6 @@ while (i--) \ ; \ } -#ifdef HDZERO_FREESTYLE_V2 -#define SPI_DLY1 \ - { \ - int i = 5; \ - while (i--) \ - ; \ - } -#endif void SPI_Init() { SET_CS(1); @@ -37,11 +29,7 @@ void SPI_Write_Byte(uint8_t dat) { SPI_DLY; SET_DO((dat >> i) & 0x01); -#ifdef HDZERO_FREESTYLE_V2 - SPI_DLY1; -#else SPI_DLY; -#endif SET_CK(1); SPI_DLY; From ed8942b6c3f26074b7c72e7c3d60fe1d7c97c958 Mon Sep 17 00:00:00 2001 From: ligenxxxx <59721724+ligenxxxx@users.noreply.github.com> Date: Wed, 30 Aug 2023 11:54:47 +0800 Subject: [PATCH 05/14] Do not init rf if calib --- src/mcu.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/mcu.c b/src/mcu.c index f80d412..78ac210 100644 --- a/src/mcu.c +++ b/src/mcu.c @@ -210,6 +210,10 @@ void timer_task() { void RF_Delay_Init() { static uint8_t SA_saved = 0; +#ifdef _RF_CALIB + return; +#endif + if (tramp_lock) return; From bbd27f2ea78f1febb828ab793475d6fb1196126a Mon Sep 17 00:00:00 2001 From: ligenxxxx <59721724+ligenxxxx@users.noreply.github.com> Date: Tue, 19 Sep 2023 14:35:42 +0800 Subject: [PATCH 06/14] L2 is too hot, so adjust pwr_offset --- src/hardware.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/hardware.c b/src/hardware.c index de4201c..5d40868 100644 --- a/src/hardware.c +++ b/src/hardware.c @@ -623,6 +623,9 @@ void PowerAutoSwitch() { #ifdef HDZERO_WHOOP_LITE pwr_offset >>= 1; +#elif defined HDZERO_FREESTYLE_V2 + if (pwr_offset > 16) + pwr_offset = 16; #endif if ((!g_IS_ARMED) && (last_ofs == pwr_offset)) From 7ae455c158d352894e709d87361d0f1a52b3a394 Mon Sep 17 00:00:00 2001 From: ligenxxxx <59721724+ligenxxxx@users.noreply.github.com> Date: Tue, 19 Sep 2023 17:42:16 +0800 Subject: [PATCH 07/14] check warning band and channel for msp vtx --- src/msp_displayport.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/msp_displayport.c b/src/msp_displayport.c index be8cdec..2b60ca0 100644 --- a/src/msp_displayport.c +++ b/src/msp_displayport.c @@ -854,9 +854,15 @@ uint8_t parse_vtx_band_and_channel(uint8_t const band, uint8_t const channel) { return INVALID_CHANNEL; } } else if (band == 5) { // race band - return (channel - 1); - } else if (band == 6) { - return (channel + 9); // low band + if (channel >= 1 && channel <= 8) + return (channel - 1); + else + return INVALID_CHANNEL; + } else if (band == 6) { // low band + if (channel >= 1 && channel <= 8) + return (channel + 1); + else + return INVALID_CHANNEL; } else { return INVALID_CHANNEL; } From a1d6887a919e7bb88ce61a677337f2649c61ec7a Mon Sep 17 00:00:00 2001 From: ligen Date: Wed, 20 Sep 2023 12:11:49 +0800 Subject: [PATCH 08/14] reset config --- src/common.h | 1 + src/hardware.c | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/common.h b/src/common.h index 8b2d8e8..ff7ccba 100644 --- a/src/common.h +++ b/src/common.h @@ -66,6 +66,7 @@ // #define REV_UART // #define VIDEO_PAT // #define FIX_EEP +#define RESET_CONFIG #ifndef _RF_CALIB // #define _DEBUG_MODE diff --git a/src/hardware.c b/src/hardware.c index 5760a9b..087c3f7 100644 --- a/src/hardware.c +++ b/src/hardware.c @@ -390,7 +390,7 @@ void GetVtxParameter() { } // VTX Setting - lowband_lock = 0x01 & I2C_Read8_Wait(10, ADDR_EEPROM, EEP_ADDR_LOWBAND_LOCK); + lowband_lock = I2C_Read8_Wait(10, ADDR_EEPROM, EEP_ADDR_LOWBAND_LOCK); RF_FREQ = I2C_Read8(ADDR_EEPROM, EEP_ADDR_RF_FREQ); RF_POWER = I2C_Read8(ADDR_EEPROM, EEP_ADDR_RF_POWER); LP_MODE = I2C_Read8(ADDR_EEPROM, EEP_ADDR_LPMODE); @@ -404,6 +404,22 @@ void GetVtxParameter() { BAUDRATE = I2C_Read8(ADDR_EEPROM, EEP_ADDR_BAUDRATE); #endif CFG_Back(); +#ifdef RESET_CONFIG + RF_FREQ = 0; + RF_POWER = 0; + LP_MODE = 0; + PIT_MODE = 0; + OFFSET_25MW = 0; + TEAM_RACE = 0; + BAUDRATE = 0; + I2C_Write8_Wait(10, ADDR_EEPROM, EEP_ADDR_RF_FREQ, RF_FREQ); + I2C_Write8_Wait(10, ADDR_EEPROM, EEP_ADDR_RF_POWER, RF_POWER); + I2C_Write8_Wait(10, ADDR_EEPROM, EEP_ADDR_LPMODE, LP_MODE); + I2C_Write8_Wait(10, ADDR_EEPROM, EEP_ADDR_PITMODE, PIT_MODE); + I2C_Write8_Wait(10, ADDR_EEPROM, EEP_ADDR_25MW, OFFSET_25MW); + I2C_Write8_Wait(10, ADDR_EEPROM, EEP_ADDR_TEAM_RACE, TEAM_RACE); + I2C_Write8_Wait(10, ADDR_EEPROM, EEP_ADDR_BAUDRATE, BAUDRATE); +#endif #ifdef _DEBUG_MODE debugf("\r\nUSE EEPROM for VTX setting:RF_FREQ=%d, RF_POWER=%d, LPMODE=%d PIT_MODE=%d", (uint16_t)RF_FREQ, (uint16_t)RF_POWER, (uint16_t)LP_MODE, (uint16_t)PIT_MODE); #endif From dff320cfaf75298b0494b31f92477bdaf7e713d4 Mon Sep 17 00:00:00 2001 From: ligen Date: Wed, 20 Sep 2023 12:20:41 +0800 Subject: [PATCH 09/14] reset camera config --- src/camera.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/camera.c b/src/camera.c index 0d7e7af..16199be 100644 --- a/src/camera.c +++ b/src/camera.c @@ -240,6 +240,9 @@ void camera_setting_read(void) { return; camera_type_last = camera_reg_read_eep(EEP_ADDR_CAM_TYPE); +#ifdef RESET_CONFIG + camera_type_last = CAMERA_TYPE_UNKNOW; +#endif if (camera_type_last != camera_type) { camera_profile_reset(); camera_profile_write(); From e0cf00fb3b3cbd8a2e9c5d51e2c702f74899c65b Mon Sep 17 00:00:00 2001 From: ligen Date: Wed, 20 Sep 2023 12:31:27 +0800 Subject: [PATCH 10/14] block define RESET_CONFIG --- src/common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common.h b/src/common.h index ff7ccba..3ab2d5b 100644 --- a/src/common.h +++ b/src/common.h @@ -66,7 +66,7 @@ // #define REV_UART // #define VIDEO_PAT // #define FIX_EEP -#define RESET_CONFIG +// #define RESET_CONFIG #ifndef _RF_CALIB // #define _DEBUG_MODE From d6e230bd8f9046f499d77c18d2028a4b3175dadf Mon Sep 17 00:00:00 2001 From: ligenxxxx <59721724+ligenxxxx@users.noreply.github.com> Date: Thu, 21 Sep 2023 11:46:22 +0800 Subject: [PATCH 11/14] add MSP_CMD_GET_OSD_CANVAS_BYTE to get osd resolution --- src/msp_displayport.c | 24 +++++++++++++----------- src/msp_displayport.h | 3 ++- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/msp_displayport.c b/src/msp_displayport.c index be8cdec..e5b5263 100644 --- a/src/msp_displayport.c +++ b/src/msp_displayport.c @@ -95,7 +95,7 @@ uint8_t boot_0mw_done = 0; #ifdef USE_MSP void msp_set_osd_canvas(void); void msp_set_inav_osd_canvas(void); -void parse_set_osd_canvas(void); +void parse_get_osd_canvas(void); uint8_t msp_cmp_fc_variant(const char *variant) { uint8_t i; @@ -273,8 +273,8 @@ uint8_t msp_read_one_frame() { cur_cmd = CUR_FC_VARIANT; } else if (rx == MSP_CMD_VTX_CONFIG_BYTE) { cur_cmd = CUR_VTX_CONFIG; - } else if (rx == MSP_CMD_SET_OSD_CANVAS_BYTE) { - cur_cmd = CUR_SET_OSD_CANVAS; + } else if (rx == MSP_CMD_GET_OSD_CANVAS_BYTE) { + cur_cmd = CUR_GET_OSD_CANVAS; } else cur_cmd = CUR_OTHERS; @@ -305,8 +305,8 @@ uint8_t msp_read_one_frame() { parse_variant(); else if (cur_cmd == CUR_VTX_CONFIG) parse_vtx_config(); - else if (cur_cmd == CUR_SET_OSD_CANVAS) - parse_set_osd_canvas(); + else if (cur_cmd == CUR_GET_OSD_CANVAS) + parse_get_osd_canvas(); else if (cur_cmd == CUR_DISPLAYPORT) ret = parse_displayport(osd_len); full_frame = 1; @@ -702,11 +702,12 @@ void msp_send_header(uint8_t dl) { void msp_cmd_tx() // send 3 commands to FC { uint8_t i; - uint8_t const count = (fc_lock & FC_VTX_CONFIG_LOCK) ? 3 : 4; - uint8_t msp_cmd[4] = { + uint8_t const count = (fc_lock & FC_VTX_CONFIG_LOCK) ? 4 : 5; + uint8_t const msp_cmd[5] = { MSP_CMD_FC_VARIANT_BYTE, MSP_CMD_STATUS_BYTE, MSP_CMD_RC_BYTE, + MSP_CMD_GET_OSD_CANVAS_BYTE, MSP_CMD_VTX_CONFIG_BYTE, }; @@ -941,10 +942,11 @@ void msp_set_inav_osd_canvas(void) { } } -void parse_set_osd_canvas(void) { - resolution = HD_5018; - // debugf("\r\nparse_set_osd_canvas"); - osd_menu_offset = 8; +void parse_get_osd_canvas(void) { + if (msp_rx_buf[0] == HD_HMAX0 && msp_rx_buf[1] == HD_VMAX0) { + resolution = HD_5018; + osd_menu_offset = 8; + } } void parseMspVtx_V2(uint16_t const cmd_u16) { diff --git a/src/msp_displayport.h b/src/msp_displayport.h index 9e74454..137af3c 100644 --- a/src/msp_displayport.h +++ b/src/msp_displayport.h @@ -28,6 +28,7 @@ #define MSP_CMD_RC_BYTE 0x69 // 105 //out message #define MSP_CMD_DISPLAYPORT_BYTE 0xB6 // 182 // in message #define MSP_CMD_SET_OSD_CANVAS_BYTE 0xBC // 188 // in message +#define MSP_CMD_GET_OSD_CANVAS_BYTE 0xBD // 188 //out message #define DP_HEADER0 0x56 #define DP_HEADER1 0x80 @@ -97,7 +98,7 @@ typedef enum { CUR_STATUS, CUR_FC_VARIANT, CUR_VTX_CONFIG, - CUR_SET_OSD_CANVAS, + CUR_GET_OSD_CANVAS, CUR_OTHERS } cur_cmd_e; From 698dcbe3d9d37600e65ea3a091d02ce6469744e8 Mon Sep 17 00:00:00 2001 From: ligenxxxx <59721724+ligenxxxx@users.noreply.github.com> Date: Thu, 21 Sep 2023 12:03:12 +0800 Subject: [PATCH 12/14] Supports dynamic change from HD5018 to SD3016 --- src/msp_displayport.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/msp_displayport.c b/src/msp_displayport.c index e5b5263..738cd5e 100644 --- a/src/msp_displayport.c +++ b/src/msp_displayport.c @@ -946,6 +946,9 @@ void parse_get_osd_canvas(void) { if (msp_rx_buf[0] == HD_HMAX0 && msp_rx_buf[1] == HD_VMAX0) { resolution = HD_5018; osd_menu_offset = 8; + } else if (msp_rx_buf[0] == SD_HMAX && msp_rx_buf[1] == SD_VMAX) { + resolution = SD_3016; + osd_menu_offset = 0; } } From a6bdee941f8dd2611cfb319dcb9b27d4f92e13b4 Mon Sep 17 00:00:00 2001 From: ligen Date: Thu, 21 Sep 2023 15:22:02 +0800 Subject: [PATCH 13/14] throttle must be in the mid when enter cam menu --- src/msp_displayport.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/msp_displayport.c b/src/msp_displayport.c index be8cdec..31e9139 100644 --- a/src/msp_displayport.c +++ b/src/msp_displayport.c @@ -1240,7 +1240,7 @@ void update_cms_menu(uint16_t roll, uint16_t pitch, uint16_t yaw, uint16_t throt uint8_t IS_HI_throttle = IS_HI(throttle); uint8_t IS_LO_throttle = IS_LO(throttle); - // uint8_t IS_MID_throttle = IS_MID(throttle); + uint8_t IS_MID_throttle = IS_MID(throttle); uint8_t IS_HI_pitch = IS_HI(pitch); uint8_t IS_LO_pitch = IS_LO(pitch); @@ -1261,7 +1261,7 @@ void update_cms_menu(uint16_t roll, uint16_t pitch, uint16_t yaw, uint16_t throt VirtualBtn = BTN_MID; } else { mid = 0; - if (IS_HI_yaw && IS_MID_roll && IS_MID_pitch) + if (IS_HI_yaw && IS_MID_roll && IS_MID_pitch && IS_MID_throttle) VirtualBtn = BTN_ENTER; else if (IS_LO_yaw && IS_MID_roll && IS_MID_pitch) VirtualBtn = BTN_EXIT; From d7c3b4e0a459bcfdcac177a58b9809e61e7d0176 Mon Sep 17 00:00:00 2001 From: ligen Date: Thu, 21 Sep 2023 18:25:08 +0800 Subject: [PATCH 14/14] Solve the possible conflict with iNav about stick cmd BTN_up, down, left and right --- src/msp_displayport.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/msp_displayport.c b/src/msp_displayport.c index 31e9139..3ff552c 100644 --- a/src/msp_displayport.c +++ b/src/msp_displayport.c @@ -1265,13 +1265,13 @@ void update_cms_menu(uint16_t roll, uint16_t pitch, uint16_t yaw, uint16_t throt VirtualBtn = BTN_ENTER; else if (IS_LO_yaw && IS_MID_roll && IS_MID_pitch) VirtualBtn = BTN_EXIT; - else if (IS_MID_yaw && IS_MID_roll && IS_HI_pitch) + else if (IS_MID_yaw && IS_MID_roll && IS_HI_pitch && !IS_HI_throttle) VirtualBtn = BTN_UP; - else if (IS_MID_yaw && IS_MID_roll && IS_LO_pitch) + else if (IS_MID_yaw && IS_MID_roll && IS_LO_pitch && !IS_HI_throttle) VirtualBtn = BTN_DOWN; - else if (IS_MID_yaw && IS_LO_roll && IS_MID_pitch) + else if (IS_MID_yaw && IS_LO_roll && IS_MID_pitch && !IS_HI_throttle) VirtualBtn = BTN_LEFT; - else if (IS_MID_yaw && IS_HI_roll && IS_MID_pitch) + else if (IS_MID_yaw && IS_HI_roll && IS_MID_pitch && !IS_HI_throttle) VirtualBtn = BTN_RIGHT; else VirtualBtn = BTN_INVALID;