From 8e0574f396433137213c06b8378db924287b74aa Mon Sep 17 00:00:00 2001 From: ligenxxxx <59721724+ligenxxxx@users.noreply.github.com> Date: Wed, 21 Aug 2024 10:02:24 +0800 Subject: [PATCH] remove smartaudio --- src/common.h | 7 +- src/dm5680_fw_tx.uvproj | 5 - src/hardware.c | 111 +------ src/hardware.h | 2 - src/mcu.c | 53 +--- src/msp_displayport.c | 71 ++--- src/smartaudio_protocol.c | 538 -------------------------------- src/smartaudio_protocol.h | 44 --- src/uart.c | 163 ---------- src/uart.h | 20 -- targets/foxeer_vtx.ini | 1 - targets/hdzero_freestyle_v1.ini | 1 - targets/hdzero_freestyle_v2.ini | 1 - targets/hdzero_race_v1.ini | 1 - targets/hdzero_race_v2.ini | 1 - targets/hdzero_whoop_lite.ini | 1 - 16 files changed, 30 insertions(+), 990 deletions(-) delete mode 100644 src/smartaudio_protocol.c delete mode 100644 src/smartaudio_protocol.h diff --git a/src/common.h b/src/common.h index dc0a4f7e..4aa0673d 100644 --- a/src/common.h +++ b/src/common.h @@ -89,7 +89,6 @@ // #define _DEBUG_TC3587 // #define _DEBUG_CAMERA // #define _DEBUG_LIFETIME -// #define _DEBUG_SMARTAUDIO // #define _DEBUG_DISPLAYPORT // #define _DEBUG_RUNCAM // #define _DEBUG_SPI @@ -117,7 +116,7 @@ #define PRESS_LL 8 #define PWR_LMT_SEC 10 -#if defined USE_SMARTAUDIO_SW || defined USE_SMARTAUDIO_HW || defined USE_TRAMP +#if defined USE_TRAMP #define WAIT_SA_LOCK 4 #define WAIT_SA_CONFIG 9 #else @@ -138,9 +137,7 @@ #elif !defined USE_TC3587_LED #define LED_1 P0_2 #endif -#if defined USE_SMARTAUDIO_SW -#define SUART_PORT P0_3 -#elif defined USE_TC3587_RSTB +#if defined USE_TC3587_RSTB #define TC3587_RSTB P0_3 #elif defined USE_USB_DET #define USB_DET P0_3 diff --git a/src/dm5680_fw_tx.uvproj b/src/dm5680_fw_tx.uvproj index ed7c7d4c..de1e12b4 100644 --- a/src/dm5680_fw_tx.uvproj +++ b/src/dm5680_fw_tx.uvproj @@ -433,11 +433,6 @@ 1 .\msp_displayport.c - - smartaudio_protocol.c - 1 - .\smartaudio_protocol.c - camera.c 1 diff --git a/src/hardware.c b/src/hardware.c index 4bfc9eff..f45c554c 100644 --- a/src/hardware.c +++ b/src/hardware.c @@ -11,7 +11,6 @@ #include "msp_displayport.h" #include "print.h" #include "sfr_ext.h" -#include "smartaudio_protocol.h" #include "spi.h" #include "tramp_protocol.h" #include "uart.h" @@ -59,7 +58,6 @@ int16_t temperature = 0; uint8_t pwr_offset = 0; uint8_t heat_protect = 0; -uint8_t last_SA_lock = 0; /* cur_pwr: 0: 25mW @@ -482,18 +480,6 @@ void GetVtxParameter() { 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 -// last_SA_lock -#if defined USE_SMARTAUDIO_SW || defined USE_SMARTAUDIO_HW - last_SA_lock = I2C_Read8_Wait(10, ADDR_EEPROM, EEP_ADDR_SA_LOCK); - if (last_SA_lock == 0xff) { - last_SA_lock = 0; - I2C_Write8_Wait(10, ADDR_EEPROM, EEP_ADDR_SA_LOCK, last_SA_lock); - } -#ifdef _DEBUG_MODE - debugf("\r\nlast_SA_lock %x", (uint16_t)last_SA_lock); -#endif -#endif - #if defined HDZERO_FREESTYLE_V1 || HDZERO_FREESTYLE_V2 // powerLock powerLock = 0x01 & I2C_Read8_Wait(10, ADDR_EEPROM, EEP_ADDR_POWER_LOCK); @@ -932,60 +918,6 @@ void PwrLMT() { return; #ifndef _RF_CALIB - if (SA_lock) { // Smart Audio - HeatProtect(); - if (!heat_protect) { - if (pwr_lmt_done == 0) { - if (pwr_tflg) { - pwr_tflg = 0; - pwr_lmt_sec++; - -#if defined HDZERO_FREESTYLE_V1 || HDZERO_FREESTYLE_V2 - // test: power plus every sec - if (pwr_lmt_sec >= 3) { - if (RF_POWER == 3) { - if (p_init) { - p = table_power[RF_FREQ][3] - 0x1C; - p_init = 0; - } - - SPI_Write(0x6, 0xFF0, 0x00000018); - - if (p >= table_power[RF_FREQ][3]) { - p = table_power[RF_FREQ][3]; - } else { - p += 0x4; - debugf("\r\npwr_plus 2dbm,p=%x", (uint16_t)p); - } - - SPI_Write(0x3, 0xD1C, (uint32_t)p); - SPI_Write(0x3, 0x330, 0x31F); // 1W - } - } -#endif - -#ifdef _DEBUG_MODE - debugf("\r\npwr_lmt_sec %x", (uint16_t)pwr_lmt_sec); -#endif - if (pwr_lmt_sec >= PWR_LMT_SEC) { - DM6300_SetPower(RF_POWER, RF_FREQ, pwr_offset); - cur_pwr = RF_POWER; - pwr_lmt_done = 1; - pwr_lmt_sec = 0; - // test: power init reset - p_init = 1; - -#ifdef _DEBUG_MODE - debugf("\r\nPower limit done."); -#endif - Prompt(); - } - } - } else { - PowerAutoSwitch(); - } - } - } /* else if(!fc_lock){ //No FC connected HeatProtect(); @@ -993,7 +925,7 @@ void PwrLMT() { PowerAutoSwitch(); } */ - else if (g_IS_ARMED) { // Armed + if (g_IS_ARMED) { // Armed PowerAutoSwitch(); HeatProtect(); } else { // Disarmed @@ -1440,9 +1372,6 @@ void OnButton1() { static uint16_t cur_sec = 0; static uint8_t last_keyon = 0; - if (SA_lock) - return; - if (cur_sec != seconds) { cur_sec = seconds; @@ -1638,8 +1567,6 @@ void timer_task() { } void RF_Delay_Init() { - static uint8_t SA_saved = 0; - #ifdef _RF_CALIB return; #endif @@ -1647,22 +1574,10 @@ void RF_Delay_Init() { if (tramp_lock) return; - if (SA_saved == 0) { - if (seconds >= WAIT_SA_CONFIG) { - I2C_Write8_Wait(10, ADDR_EEPROM, EEP_ADDR_SA_LOCK, SA_lock); - SA_saved = 1; -#ifdef _DEBUG_MODE - debugf("\r\nSave SA_lock(%x) to EEPROM", (uint16_t)SA_lock); -#endif - } - } - // init_rf if (seconds < WAIT_SA_CONFIG) { // wait for SA config vtx if (seconds < WAIT_SA_LOCK) return; - else if (SA_lock) - return; else seconds = WAIT_SA_CONFIG; } else if (rf_delay_init_done) @@ -1672,29 +1587,7 @@ void RF_Delay_Init() { else rf_delay_init_done = 1; - if (last_SA_lock) { -#ifdef _DEBUG_MODE - debugf("\r\nRF_Delay_Init: SA"); -#endif - pwr_lmt_sec = PWR_LMT_SEC; - if (SA_lock) { - if (pwr_init == POWER_MAX + 2) { // 0mW - RF_POWER = POWER_MAX + 2; - cur_pwr = POWER_MAX + 2; - } else if (PIT_MODE) { - Init_6300RF(ch_init, POWER_MAX + 1); -#ifdef _DEBUG_MODE - debugf("\r\n ch%x, pwr%x", (uint16_t)ch_init, (uint16_t)cur_pwr); -#endif - } else { - Init_6300RF(ch_init, pwr_init); -#ifdef _DEBUG_MODE - debugf("\r\n ch%x, pwr%x", (uint16_t)ch_init, (uint16_t)cur_pwr); -#endif - } - DM6300_AUXADC_Calib(); - } - } else if (!mspVtxLock) { + if (!mspVtxLock) { #ifdef _DEBUG_MODE debugf("\r\nRF_Delay_Init: None"); #endif diff --git a/src/hardware.h b/src/hardware.h index 30c8e7a5..f45adf22 100644 --- a/src/hardware.h +++ b/src/hardware.h @@ -131,13 +131,11 @@ extern uint8_t heat_protect; extern uint8_t fc_lock; extern uint8_t vtx_pit; extern uint8_t vtx_pit_save; -extern uint8_t SA_lock; extern uint8_t pwr_lmt_sec; extern uint8_t pwr_lmt_done; extern uint8_t cur_pwr; -extern uint8_t last_SA_lock; extern uint8_t pwr_init; extern uint8_t ch_init; diff --git a/src/mcu.c b/src/mcu.c index 6276088f..ce320d4d 100644 --- a/src/mcu.c +++ b/src/mcu.c @@ -13,7 +13,6 @@ #include "rom.h" #include "runcam.h" #include "sfr_ext.h" -#include "smartaudio_protocol.h" #include "tramp_protocol.h" #include "uart.h" #include "version.h" @@ -26,17 +25,6 @@ BIT_TYPE int1_req = 0; void Timer0_isr(void) INTERRUPT(1) { TH0 = 138; - -#ifdef USE_SMARTAUDIO_SW - if (SA_config) { - if (suart_tx_en) { - // TH0 = 139; - suart_txint(); - } else - suart_rxint(); - } -#endif - timer_ms10x++; } @@ -66,30 +54,6 @@ void UART0_isr() INTERRUPT(4) { RS_Xbusy = 0; } } -#ifdef USE_SMARTAUDIO_HW -void UART1_isr() INTERRUPT(6) { - - if (RI1) { // RX int - RI1 = 0; - if (sa_status == SA_ST_IDLE) { - uart_set_baudrate(3); - sa_status = SA_ST_RX; - sa_start_ms = timer_ms10x; - } - if (sa_status == SA_ST_TX) - return; - - RS_buf1[RS_in1++] = SBUF1; - if (RS_in1 >= BUF1_MAX) - RS_in1 = 0; - } - - if (TI1) { // TX int - TI1 = 0; - RS_Xbusy1 = 0; - } -} -#else void UART1_isr() INTERRUPT(6) { if (RI1 && (tr_tx_busy == 0)) { // RX int @@ -104,7 +68,6 @@ void UART1_isr() INTERRUPT(6) { RS_Xbusy1 = 0; } } -#endif void version_info(void) { #ifdef _DEBUG_MODE @@ -135,9 +98,7 @@ void main(void) { Init_HW(); // init fc_init(); // init displayport -#ifdef USE_SMARTAUDIO_SW - SA_Init(); -#elif defined USE_TRAMP +#if defined USE_TRAMP tramp_init(); #endif @@ -148,15 +109,7 @@ void main(void) { // main loop while (1) { timer_task(); -#if defined USE_SMARTAUDIO_SW - while (SA_task()) - ; -#elif defined USE_SMARTAUDIO_HW - while (SA_task()) { - if (SA_timeout()) - break; - } -#elif defined USE_TRAMP +#if defined USE_TRAMP tramp_receive(); #endif @@ -168,7 +121,7 @@ void main(void) { video_detect(); OnButton1(); - if (last_SA_lock && seconds < WAIT_SA_CONFIG) + if (seconds < WAIT_SA_CONFIG) ; else { LED_Task(); diff --git a/src/msp_displayport.c b/src/msp_displayport.c index 43693559..b3bbd155 100644 --- a/src/msp_displayport.c +++ b/src/msp_displayport.c @@ -7,7 +7,6 @@ #include "isr.h" #include "lifetime.h" #include "print.h" -#include "smartaudio_protocol.h" #include "spi.h" #include "tramp_protocol.h" #include "uart.h" @@ -1143,9 +1142,9 @@ void parseMspVtx_V2(uint16_t const cmd_u16) { debugf("\r\n fc_powerLevels %x", (uint16_t)msp_rx_buf[14]); #endif - if (SA_lock || (init_table_done == 0 && !init_table_unsupported)) { + if ((init_table_done == 0 && !init_table_unsupported)) { #ifdef _DEBUG_MODE - debugf("\r\nparseMspVtx_V2 skipped. (SA_lock: %i, init_table_done: %i, init_table_unsupported: %i)\r\n", SA_lock, init_table_done, init_table_unsupported); + debugf("\r\nparseMspVtx_V2 skipped. (init_table_done: %i, init_table_unsupported: %i)\r\n", init_table_done, init_table_unsupported); #endif return; } @@ -1485,15 +1484,7 @@ void update_cms_menu(uint16_t roll, uint16_t pitch, uint16_t yaw, uint16_t throt PIT_MODE = PIT_0MW; vtx_pit = PIT_0MW; vtx_shortcut = SHORTCUT; - if (!SA_lock) { - save_vtx_param(); - } else { - msp_set_vtx_config(POWER_MAX + 1, 0); // enter 0mW for SA - WriteReg(0, 0x8F, 0x10); - dm6300_init_done = 0; - cur_pwr = POWER_MAX + 2; - temp_err = 1; - } + save_vtx_param(); } break; @@ -1508,28 +1499,16 @@ void update_cms_menu(uint16_t roll, uint16_t pitch, uint16_t yaw, uint16_t throt vtx_offset = OFFSET_25MW; vtx_team_race = TEAM_RACE; vtx_shortcut = SHORTCUT; - if (SA_lock) { - // PIT_MODE = 2; - vtx_pit = PIT_P1MW; - Init_6300RF(RF_FREQ, POWER_MAX + 1); - cur_pwr = POWER_MAX + 1; - DM6300_AUXADC_Calib(); -#ifdef _DEBUG_MODE - debugf("\r\nExit 0mW\r\n"); -#endif - // debugf("\r\n exit0"); - } else { - save_vtx_param(); - pit_mode_cfg_done = 1; // avoid to config DM6300 again - // SPI_Write(0x6, 0xFF0, 0x00000018); - // SPI_Write(0x3, 0xd00, 0x00000003); - Init_6300RF(RF_FREQ, RF_POWER); - DM6300_AUXADC_Calib(); + save_vtx_param(); + pit_mode_cfg_done = 1; // avoid to config DM6300 again + // SPI_Write(0x6, 0xFF0, 0x00000018); + // SPI_Write(0x3, 0xd00, 0x00000003); + Init_6300RF(RF_FREQ, RF_POWER); + DM6300_AUXADC_Calib(); #ifdef _DEBUG_MODE - debugf("\r\nExit 0mW\r\n"); + debugf("\r\nExit 0mW\r\n"); #endif - // debugf("\r\n exit0"); - } + // debugf("\r\n exit0"); } if (!(IS_HI_yaw && IS_LO_throttle && IS_LO_roll && IS_LO_pitch)) @@ -1552,13 +1531,13 @@ void update_cms_menu(uint16_t roll, uint16_t pitch, uint16_t yaw, uint16_t throt else if (VirtualBtn == BTN_UP) vtx_menu_state = VTX_MENU_SAVE_EXIT; else if (VirtualBtn == BTN_RIGHT) { - if ((SA_lock || tramp_lock) == 0) { + if (tramp_lock == 0) { vtx_channel++; if (vtx_channel == FREQ_NUM) vtx_channel = 0; } } else if (VirtualBtn == BTN_LEFT) { - if ((SA_lock || tramp_lock) == 0) { + if (tramp_lock == 0) { vtx_channel--; if (vtx_channel >= FREQ_NUM) vtx_channel = FREQ_NUM - 1; @@ -1573,7 +1552,7 @@ void update_cms_menu(uint16_t roll, uint16_t pitch, uint16_t yaw, uint16_t throt else if (VirtualBtn == BTN_UP) vtx_menu_state = VTX_MENU_CHANNEL; else if (VirtualBtn == BTN_RIGHT) { - if ((SA_lock || tramp_lock) == 0) { + if (tramp_lock == 0) { vtx_power++; #if defined HDZERO_FREESTYLE_V1 || HDZERO_FREESTYLE_V2 if (powerLock) @@ -1583,7 +1562,7 @@ void update_cms_menu(uint16_t roll, uint16_t pitch, uint16_t yaw, uint16_t throt vtx_power = 0; } } else if (VirtualBtn == BTN_LEFT) { - if ((SA_lock || tramp_lock) == 0) { + if (tramp_lock == 0) { vtx_power--; #if defined HDZERO_FREESTYLE_V1 || HDZERO_FREESTYLE_V2 if (powerLock) @@ -1602,13 +1581,13 @@ void update_cms_menu(uint16_t roll, uint16_t pitch, uint16_t yaw, uint16_t throt else if (VirtualBtn == BTN_UP) vtx_menu_state = VTX_MENU_POWER; else if (VirtualBtn == BTN_LEFT) { - if ((SA_lock || tramp_lock) == 0) { + if (tramp_lock == 0) { vtx_lp--; if (vtx_lp > 2) vtx_lp = 2; } } else if (VirtualBtn == BTN_RIGHT) { - if ((SA_lock || tramp_lock) == 0) { + if (tramp_lock == 0) { vtx_lp++; if (vtx_lp > 2) vtx_lp = 0; @@ -1623,14 +1602,14 @@ void update_cms_menu(uint16_t roll, uint16_t pitch, uint16_t yaw, uint16_t throt else if (VirtualBtn == BTN_UP) vtx_menu_state = VTX_MENU_LP_MODE; else if (VirtualBtn == BTN_RIGHT) { - if ((SA_lock || tramp_lock) == 0) { + if (tramp_lock == 0) { if (vtx_pit == PIT_0MW) vtx_pit = PIT_OFF; else vtx_pit++; } } else if (VirtualBtn == BTN_LEFT) { - if ((SA_lock || tramp_lock) == 0) { + if (tramp_lock == 0) { if (vtx_pit == PIT_OFF) vtx_pit = PIT_0MW; else @@ -1673,13 +1652,13 @@ void update_cms_menu(uint16_t roll, uint16_t pitch, uint16_t yaw, uint16_t throt else if (VirtualBtn == BTN_UP) vtx_menu_state = VTX_MENU_OFFSET_25MW; else if (VirtualBtn == BTN_LEFT) { - if ((SA_lock || tramp_lock) == 0) { + if (tramp_lock == 0) { vtx_team_race--; if (vtx_team_race > 2) vtx_team_race = 2; } } else if (VirtualBtn == BTN_RIGHT) { - if ((SA_lock || tramp_lock) == 0) { + if (tramp_lock == 0) { vtx_team_race++; if (vtx_team_race > 2) vtx_team_race = 0; @@ -1724,7 +1703,7 @@ void update_cms_menu(uint16_t roll, uint16_t pitch, uint16_t yaw, uint16_t throt } else if (VirtualBtn == BTN_RIGHT) { vtx_menu_state = VTX_MENU_CHANNEL; cms_state = CMS_OSD; - if (SA_lock || tramp_lock) { + if (tramp_lock) { RF_FREQ = vtx_channel; RF_POWER = vtx_power; LP_MODE = vtx_lp; @@ -1942,9 +1921,7 @@ void save_vtx_param() { if (TEAM_RACE) boot_0mw_done = 1; - if (SA_lock) - ; - else if (tramp_lock) + if (tramp_lock) ; else { if (vtx_pit == PIT_0MW) @@ -1963,8 +1940,6 @@ void set_vtx_param() { g_IS_ARMED = 1; } */ - if (SA_lock) - return; if (tramp_lock) return; if (!rf_delay_init_done) diff --git a/src/smartaudio_protocol.c b/src/smartaudio_protocol.c deleted file mode 100644 index d90d19e6..00000000 --- a/src/smartaudio_protocol.c +++ /dev/null @@ -1,538 +0,0 @@ -#include "smartaudio_protocol.h" -#include "common.h" -#include "dm6300.h" -#include "global.h" -#include "hardware.h" -#include "i2c_device.h" -#include "isr.h" -#include "monitor.h" -#include "msp_displayport.h" -#include "print.h" -#include "rom.h" -#include "sfr_ext.h" -#include "uart.h" - -uint8_t SA_lock = 0; - -uint8_t pwr_init = 0; // 0:POWER_MAX+2 -uint8_t ch_init = 0; // 0~9 -uint8_t ch_bf = 0; - -#if defined USE_SMARTAUDIO_SW || defined USE_SMARTAUDIO_HW -uint8_t SA_is_0 = 1; // detect pre hreder 0x00 -uint8_t SA_config = 0; - -uint8_t sa_rbuf[8]; -uint8_t SA_dbm = 14; -uint8_t SA_dbm_last; -uint8_t mode_o = 0x04; -// Bit0: 1=set freq 0=set ch 0 -// Bit1: pitmode active 0 -// Bit2: PIR active 1 -// Bit3: POR active 0 -// Bit4: 1 = Unclocked VTX 1 - -uint8_t mode_p = 0x05; -// Bit0: PIR active 1 -// Bit1: POR active 0 -// Bit2: pitmode active 0 -// Bit3: 1 = Unclocked VTX 1 - -uint8_t freq_new_h; -uint8_t freq_new_l; - -uint8_t sa_status = SA_ST_IDLE; -uint32_t sa_start_ms = 0; - -uint8_t dbm_to_pwr(uint8_t dbm) { - if (dbm == 0) - return POWER_MAX + 2; - else if (dbm == 14) // 25mw - return 0; - else if (dbm == 23) // 200mw - return 1; -#if (POWER_MAX > 1) - else if (dbm == 27) // 500mw - return 2; -#endif -#if (POWER_MAX > 2) - else if (dbm == 30) // 1W - return 3; -#endif - else - return 0; -} - -uint8_t pwr_to_dbm(uint8_t pwr) { - if (pwr == 0) // 25mw - return 14; - else if (pwr == 1) // 200mw - return 23; -#if (POWER_MAX > 1) - else if (pwr == 2) // 500mw - return 27; -#endif -#if (POWER_MAX > 2) - else if (pwr == 3) // 1W - return 30; -#endif - else if (pwr == POWER_MAX + 2) - return 0; - else - return 14; -} - -void SA_Response(uint8_t cmd) { - uint8_t i, crc, tx_len; - uint8_t tbuf[20]; - switch (cmd) { - case SA_GET_SETTINGS: - tbuf[0] = 0xAA; - tbuf[1] = 0x55; - tbuf[2] = 0x11; // version V2.1 - tbuf[3] = 0x0A + POWER_MAX; // length - tbuf[4] = ch_bf; // channel - tbuf[5] = dbm_to_pwr(SA_dbm); // power level - tbuf[6] = mode_o; // operation mode - tbuf[7] = freq_new_h; // cur_freq_h - tbuf[8] = freq_new_l; // cur_freq_l - tbuf[9] = SA_dbm; // power dbm -#if defined HDZERO_FREESTYLE_V1 || HDZERO_FREESTYLE_V2 - if (powerLock) { - tbuf[10] = 1 + 1; // amount of power level - for (i = 0; i <= 1; i++) - tbuf[11 + i] = pwr_to_dbm(i); - tbuf[12 + 1] = 0; - } else -#endif - tbuf[10] = POWER_MAX + 1; // amount of power level - for (i = 0; i <= POWER_MAX; i++) - tbuf[11 + i] = pwr_to_dbm(i); - tbuf[12 + POWER_MAX] = 0; - - tx_len = tbuf[3] + 4; - break; - - case SA_SET_PWR: - tbuf[0] = 0xAA; - tbuf[1] = 0x55; - tbuf[2] = 2; - tbuf[3] = 3; - tbuf[4] = SA_dbm; - tbuf[5] = 1; // reserved - tx_len = 7; - break; - - case SA_SET_CH: - tbuf[0] = 0xaa; - tbuf[1] = 0x55; - tbuf[2] = 3; - tbuf[3] = 3; - tbuf[4] = ch_bf; - tbuf[5] = 1; // reserved - tx_len = 7; - break; - - case SA_SET_FREQ: - tbuf[0] = 0xaa; - tbuf[1] = 0x55; - tbuf[2] = 4; - tbuf[3] = 4; - tbuf[4] = freq_new_h; - tbuf[5] = freq_new_l; - tbuf[6] = 0x01; // reserved - tx_len = 8; - break; - - case SA_SET_MODE: - tbuf[0] = 0xaa; - tbuf[1] = 0x55; - tbuf[2] = 5; - tbuf[3] = 3; - tbuf[4] = mode_p; - tbuf[5] = 0x01; // reserved - tx_len = 7; - break; - - default: - return; - } // switch(cmd) - - // calculate CRC - crc = 0; - for (i = 2; i < tx_len - 1; i++) - crc = crc8tab[crc ^ tbuf[i]]; - - tbuf[tx_len - 1] = crc; - SUART_tx(tbuf, tx_len); -} - -void SA_Update(uint8_t cmd) { -#ifdef _DEBUG_SMARTAUDIO - if (SUART_ready()) { - _outchar('^'); - return; - } -#endif - switch (cmd) { -#ifdef _DEBUG_SMARTAUDIO - case SA_GET_SETTINGS: - _outchar('G'); - debugf(" ch:%x", (uint16_t)ch_init); - debugf(" pwr:%x", (uint16_t)pwr_init); - debugf(" mode:%x", (uint16_t)mode_o); - break; -#endif - - case SA_SET_PWR: - if (!(sa_rbuf[0] >> 7)) - return; - SA_dbm = sa_rbuf[0] & 0x7f; - -#ifdef _DEBUG_SMARTAUDIO - debugf("dbm:%x", (uint16_t)SA_dbm); -#endif - - if (SA_dbm_last != SA_dbm) { // need to update power - if (SA_dbm == 0) { // Enter 0mW - cur_pwr = POWER_MAX + 2; - PIT_MODE = 0; - vtx_pit = PIT_0MW; - - if (last_SA_lock && seconds < WAIT_SA_CONFIG) { - pwr_init = cur_pwr; - } else { -#ifdef _DEBUG_SMARTAUDIO - debugf("\n\rEnter 0mW"); -#endif - WriteReg(0, 0x8F, 0x10); // reset RF_chip - dm6300_init_done = 0; - temp_err = 1; - } - } else if (SA_dbm_last == 0) { // Exit 0mW - cur_pwr = dbm_to_pwr(SA_dbm); - PIT_MODE = 0; - RF_POWER = cur_pwr; - - if (last_SA_lock && seconds < WAIT_SA_CONFIG) - pwr_init = cur_pwr; - else { -#ifdef _DEBUG_MDOE - debugf("\n\rExit 0mW"); -#endif - - Init_6300RF(RF_FREQ, RF_POWER); - PIT_MODE = 0; - - DM6300_AUXADC_Calib(); - } - } else { - cur_pwr = dbm_to_pwr(SA_dbm); -#if defined HDZERO_FREESTYLE_V1 || HDZERO_FREESTYLE_V2 - if (powerLock) - cur_pwr &= 0x01; -#endif - RF_POWER = cur_pwr; - if (last_SA_lock && seconds < WAIT_SA_CONFIG) - pwr_init = cur_pwr; - else { -#ifndef VIDEO_PAT -#if defined HDZERO_FREESTYLE_V1 || HDZERO_FREESTYLE_V2 - if ((RF_POWER == 3) && (!g_IS_ARMED)) - pwr_lmt_done = 0; - else -#endif -#endif - DM6300_SetPower(RF_POWER, RF_FREQ, pwr_offset); - } - - Setting_Save(); - } - SA_dbm_last = SA_dbm; - } - break; - - case SA_SET_CH: { - uint8_t const channel = bfChannel_to_channel(sa_rbuf[0]); - if (channel < INVALID_CHANNEL) { - ch_bf = sa_rbuf[0]; - -#ifdef _DEBUG_SMARTAUDIO - _outchar('C'); - debugf("%x", (uint16_t)channel); -#endif - - if (channel != RF_FREQ) { - RF_FREQ = channel; - if (last_SA_lock && (seconds < WAIT_SA_CONFIG)) - ch_init = channel; - else - DM6300_SetChannel(channel); - Setting_Save(); - } - } - break; - } - - case SA_SET_FREQ: { - uint16_t const freq = ((uint16_t)sa_rbuf[0] << 8) + sa_rbuf[1]; - uint8_t const channel = DM6300_GetChannelByFreq(freq); - if (channel < INVALID_CHANNEL) { - ch_bf = channel_to_bfChannel(channel); - -#ifdef _DEBUG_SMARTAUDIO - _outchar('F'); - debugf("%x", (uint16_t)channel); -#endif - - if (channel != RF_FREQ) { - RF_FREQ = channel; - if (last_SA_lock && (seconds < WAIT_SA_CONFIG)) - ch_init = channel; - else - DM6300_SetChannel(channel); - Setting_Save(); - } - } - break; - } - - case SA_SET_MODE: - if (mode_p != sa_rbuf[0]) { - mode_p = sa_rbuf[0] & 0x07; - - if (mode_p & 0x04) { // deactive pitmode - PIT_MODE = 0; - mode_o &= 0x1d; - } else { // active pitmode - PIT_MODE = 2; - mode_o |= 0x02; - } - if (cur_pwr == (POWER_MAX + 2)) - return; - - if (PIT_MODE) { - if (last_SA_lock && seconds < WAIT_SA_CONFIG) - pwr_init = cur_pwr; - else if (dbm_to_pwr(SA_dbm) == (POWER_MAX + 2)) { - cur_pwr = POWER_MAX + 2; - PIT_MODE = 0; - vtx_pit = PIT_0MW; -#ifdef _DEBUG_SMARTAUDIO - debugf("\n\rSA:Enter 0mW"); -#endif - WriteReg(0, 0x8F, 0x10); // reset RF_chip - dm6300_init_done = 0; - temp_err = 1; - } else { - DM6300_SetPower(POWER_MAX + 1, RF_FREQ, 0); - cur_pwr = POWER_MAX + 1; - } - } else { - if (last_SA_lock && seconds < WAIT_SA_CONFIG) - pwr_init = cur_pwr; - else if (dbm_to_pwr(SA_dbm) == (POWER_MAX + 2)) { - cur_pwr = POWER_MAX + 2; - PIT_MODE = 0; - vtx_pit = PIT_0MW; -#ifdef _DEBUG_SMARTAUDIO - debugf("\n\rSA:Enter 0mW"); -#endif - WriteReg(0, 0x8F, 0x10); // reset RF_chip - dm6300_init_done = 0; - temp_err = 1; - } else { -#ifndef VIDEO_PAT -#if defined HDZERO_FREESTYLE_V1 || HDZERO_FREESTYLE_V2 - if ((RF_POWER == 3) && (!g_IS_ARMED)) { - pwr_lmt_done = 0; - cur_pwr = 3; -#ifdef _DEBUG_SMARTAUDIO - debugf("\r\npwr_lmt_done reset"); -#endif - } else -#endif -#endif - { - DM6300_SetPower(RF_POWER, RF_FREQ, pwr_offset); - cur_pwr = RF_POWER; - } - } - } - - Setting_Save(); - } -#ifdef _DEBUG_SMARTAUDIO - debugf("M_P:%x ", (uint16_t)mode_p); - debugf("M_O:%x", (uint16_t)mode_o); -#endif - break; - - default: -#ifdef _DEBUG_SMARTAUDIO - _outchar('#'); -#endif - break; - } -} -#if defined USE_SMARTAUDIO_SW -uint8_t SA_task(void) { - static uint8_t st = 0, SA = 0xFF; - - if (st == 0) { // monitor SA pin - SA = (SA << 1) | SUART_PORT; - if (SA == 0xfe) { - SA_config = 1; - SA_is_0 = 1; - IE = 0xC2; // UART1 & Timer0 enabled, UART0 disabled - st = 1; -#ifdef _DEBUG_SMARTAUDIO - _outchar('\n'); - _outchar('\r'); - _outchar('<'); -#endif - } - } else { - if (SA_Process()) { - SA_config = 0; - IE = 0xD2; // UART1 & Timer0 enabled, UART0 0 enable - st = 0; - SA = 0xFF; -#ifdef _DEBUG_SMARTAUDIO - _outchar('>'); -#endif - } - } - return st; -} -#elif defined USE_SMARTAUDIO_HW -uint8_t SA_task(void) { - return 1 - SA_Process(); -} -uint8_t SA_timeout(void) { - if (timer_ms10x - sa_start_ms > 5000) { - uart_set_baudrate(BAUDRATE); - sa_status = SA_ST_IDLE; - return 1; - } - return 0; -} -#endif - -uint8_t SA_Process() { - static uint8_t rx = 0; - static uint8_t status = SA_HEADER0; - static uint8_t cmd = 0; - static uint8_t crc = 0; - static uint8_t len = 0; - static uint8_t index = 0; - uint8_t ret = 0; - - if (SUART_ready()) { - rx = SUART_rx(); -#if (1) - CMS_tx(rx); -#endif -#ifdef _DEBUG_SMARTAUDIO -// debugf("%x ", (uint16_t)rx); -#endif - switch (status) { - case SA_HEADER0: - if (rx == SA_HEADER0_BYTE) { - crc = crc8tab[rx]; // 0 ^ rx = rx - index = 0; - status = SA_HEADER1; - } else { - ret = 1; - } - break; - - case SA_HEADER1: - if (rx == SA_HEADER1_BYTE) { - crc = crc8tab[crc ^ rx]; - status = SA_CMD; - } else { - status = SA_HEADER0; - ret = 1; - } - break; - - case SA_CMD: - if (rx & 1) { - cmd = rx >> 1; - crc = crc8tab[crc ^ rx]; - status = SA_LENGTH; - } else { - status = SA_HEADER0; - ret = 1; - } - break; - - case SA_LENGTH: - len = rx; - if (len > 16) { - status = SA_HEADER0; - ret = 1; - } else { - crc = crc8tab[crc ^ rx]; - if (len == 0) - status = SA_CRC; - else { - status = SA_PAYLOAD; - index = 0; - } - } - break; - - case SA_PAYLOAD: - crc = crc8tab[crc ^ rx]; - sa_rbuf[index++] = rx; - len--; - if (len == 0) - status = SA_CRC; - break; - - case SA_CRC: - if (crc == rx) { - SA_lock = 1; - SA_Update(cmd); - SA_Response(cmd); - } else { -#ifdef _DEBUG_SMARTAUDIO - _outchar('$'); -#endif - } - ret = 1; - status = SA_HEADER0; - break; - - default: - ret = 1; - status = SA_HEADER0; - break; - } - } else { -#ifdef _DEBUG_SMARTAUDIO - _outchar('.'); -#endif - } - return ret; -} - -void SA_Init() { - uint16_t freq; - SA_dbm = pwr_to_dbm(RF_POWER); - SA_dbm_last = SA_dbm; - mode_o |= PIT_MODE; - mode_p |= (PIT_MODE << 1); - - ch_init = RF_FREQ; - pwr_init = RF_POWER; - - ch_bf = channel_to_bfChannel(ch_init); - freq = DM6300_GetFreqByChannel(ch_init); - freq_new_h = (uint8_t)(freq >> 8); - freq_new_l = (uint8_t)(freq & 0xff); -} - -#endif diff --git a/src/smartaudio_protocol.h b/src/smartaudio_protocol.h deleted file mode 100644 index 675d5385..00000000 --- a/src/smartaudio_protocol.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef __SMARTAUDIO_PROTOCOL_H_ -#define __SMARTAUDIO_PROTOCOL_H_ - -#include "common.h" - -#if defined USE_SMARTAUDIO_SW || defined USE_SMARTAUDIO_HW - -#define SA_HEADER0_BYTE 0xAA -#define SA_HEADER1_BYTE 0x55 -#define SA_VERSION_BYTE 0x09 -#define SA_GET_SETTINGS 0x01 -#define SA_SET_PWR 0x02 -#define SA_SET_CH 0x03 -#define SA_SET_FREQ 0x04 -#define SA_SET_MODE 0x05 - -typedef enum { - SA_HEADER0, - SA_HEADER1, - SA_CMD, - SA_LENGTH, - SA_PAYLOAD, - SA_CRC -} rx_status_e; - -typedef enum { - SA_ST_IDLE, - SA_ST_RX, - SA_ST_TX, -} sa_status_e; - -uint8_t SA_task(); -uint8_t SA_Process(); -void SA_Init(); -uint8_t pwr_to_dbm(uint8_t pwr); -uint8_t SA_timeout(void); - -extern uint8_t SA_dbm; -extern uint8_t crc8tab[256]; -extern uint8_t sa_status; -extern uint32_t sa_start_ms; -#endif // USE_SMARTAUDIO_SW - -#endif /* __SMARTAUDIO_PROTOCOL_H_ */ diff --git a/src/uart.c b/src/uart.c index a10a7b5a..d982064b 100644 --- a/src/uart.c +++ b/src/uart.c @@ -3,7 +3,6 @@ #include "global.h" #include "hardware.h" #include "print.h" -#include "smartaudio_protocol.h" #include XDATA_SEG uint8_t RS_buf[BUF_MAX]; @@ -88,7 +87,6 @@ uint8_t RS_rx_len(void) return RS_out - RS_in; } -#ifdef USE_SMARTAUDIO_HW uint8_t RS_ready1(void) { if (RS_in1 == RS_out1) return 0; @@ -117,35 +115,6 @@ void RS_tx1(uint8_t c) { } } -#else -uint8_t RS_ready1(void) { - if (RS_in1 == RS_out1) - return 0; - else - return 1; -} - -uint8_t RS_rx1(void) { - uint8_t ret; - ret = RS_buf1[RS_out1]; - RS_out1++; - if (RS_out1 >= BUF1_MAX) - RS_out1 = 0; - - return ret; -} - -void RS_tx1(uint8_t c) { - timer_ms10x_lst = timer_ms10x; - while (1) { - if ((!RS_Xbusy1) || (timer_ms10x - timer_ms10x_lst > 100)) { - SBUF1 = c; - RS_Xbusy1 = 1; - break; - } - } -} -#endif /* #ifdef EXTEND_BUF uint16_t RS_rx1_len(void) @@ -158,135 +127,3 @@ uint8_t RS_rx1_len(void) else return RS_out1 - RS_in1; }*/ - -//////////////////////////////////////////////////////////////////////////// -// SUART TX -#ifdef USE_SMARTAUDIO_SW -XDATA_SEG uint8_t SUART_rbuf[SUART_BUF_MAX]; -XDATA_SEG uint8_t SUART_rin = 0, SUART_rout = 0, SUART_rERR = 0; - -void suart_rxint() // ISR -{ - static uint8_t isSearchingStart = 1; - static uint8_t si_d = 1; - static uint8_t bcnt = 0; - static uint8_t rxbyte = 0; - static uint8_t cnt = 0; - uint8_t si; - - si = SUART_PORT; - - if (si) - SA_is_0 = 0; - - if (isSearchingStart) { - if (si_d && !si && !SA_is_0) { - isSearchingStart = 0; - bcnt = 0; - rxbyte = 0; - cnt = 0x0; - } - si_d = si; - return; - } else { - cnt++; - if (cnt >= 2) { - cnt = 0; - if (bcnt < 8) { - rxbyte >>= 1; - if (si) - rxbyte |= 0x80; - bcnt++; - } else { - isSearchingStart = 1; - si_d = 1; - - SUART_rbuf[SUART_rin++] = rxbyte; - SUART_rin &= (SUART_BUF_MAX - 1); -#ifdef _DEBUG_SMARTAUDIO - if (SUART_rin == SUART_rout) - SUART_rERR = 1; -#endif - } - } - } -} - -uint8_t SUART_ready() { - if (SUART_rin == SUART_rout) - return 0; - else - return 1; -} - -uint8_t SUART_rx() { - uint8_t ret; -#ifdef _DEBUG_SMARTAUDIO - if (SUART_rERR) { - SUART_rERR = 0; - _outchar('&'); - } -#endif - - ret = SUART_rbuf[SUART_rout]; - SUART_rout++; - SUART_rout &= (SUART_BUF_MAX - 1); - - return ret; -} - -//////////////////////////////////////////////////////////////////////////// -// SUART TX -uint8_t suart_tx_en = 0; -uint8_t suart_txbcnt = 0; -uint16_t suart_txdat; - -void suart_txint() // ISR -{ - static uint8_t cnt = 0; - - cnt++; - if (cnt >= 2) { - cnt = 0; - SUART_PORT = suart_txdat & 1; - suart_txdat >>= 1; - suart_txbcnt++; - if (suart_txbcnt >= 11) { - suart_tx_en = 0; - SUART_PORT = 1; - } - } -} - -void SUART_tx_byte(uint8_t dat) { - suart_txdat = (dat << 1) | 0xFE00; - suart_txbcnt = 0; - suart_tx_en = 1; -} - -void SUART_tx(uint8_t *tbuf, uint8_t len) { - uint8_t i; - for (i = 0; i < len; i++) { - SUART_tx_byte(tbuf[i]); - while (suart_tx_en) - ; - } -} -#elif defined USE_SMARTAUDIO_HW -uint8_t SUART_ready() { - return RS_ready1(); -} -uint8_t SUART_rx() { - return RS_rx1(); -} -void SUART_tx(uint8_t *tbuf, uint8_t len) { - uint8_t i; - sa_status = SA_ST_TX; - for (i = 0; i < len; i++) { - RS_tx1(tbuf[i]); - WAIT(2); // extern 1 stop bits - } - sa_status = SA_ST_IDLE; - uart_set_baudrate(BAUDRATE); -} -#endif \ No newline at end of file diff --git a/src/uart.h b/src/uart.h index 81268286..de8ad1aa 100644 --- a/src/uart.h +++ b/src/uart.h @@ -59,24 +59,4 @@ extern XDATA_SEG volatile uint8_t RS_in1; extern XDATA_SEG volatile uint8_t RS_out1; #endif -#ifdef USE_SMARTAUDIO_SW -#define SUART_BUF_MAX 32 // has to be power of 2 - -extern uint8_t suart_tx_en; -void suart_txint(); -void suart_rxint(); - -uint8_t SUART_ready(); -uint8_t SUART_rx(); - -void SUART_tx(uint8_t *tbuf, uint8_t len); -extern uint8_t SA_is_0; -extern uint8_t SA_config; - -#elif defined USE_SMARTAUDIO_HW -uint8_t SUART_ready(); -uint8_t SUART_rx(); -void SUART_tx(uint8_t *tbuf, uint8_t len); -#endif - #endif /* __UART_H_ */ diff --git a/targets/foxeer_vtx.ini b/targets/foxeer_vtx.ini index a46d5df8..f69c035d 100644 --- a/targets/foxeer_vtx.ini +++ b/targets/foxeer_vtx.ini @@ -3,4 +3,3 @@ extends = DM5680 build_flags = ${DM5680.build_flags} -DFOXEER_VTX - -DUSE_SMARTAUDIO_SW \ No newline at end of file diff --git a/targets/hdzero_freestyle_v1.ini b/targets/hdzero_freestyle_v1.ini index 6fac002c..21042c6b 100644 --- a/targets/hdzero_freestyle_v1.ini +++ b/targets/hdzero_freestyle_v1.ini @@ -3,7 +3,6 @@ extends = DM5680 build_flags = ${DM5680.build_flags} -DHDZERO_FREESTYLE_V1 - -DUSE_SMARTAUDIO_SW -DUSE_TEMPERATURE_SENSOR -DUSE_PA_EN -DUSE_TC3587_LED \ No newline at end of file diff --git a/targets/hdzero_freestyle_v2.ini b/targets/hdzero_freestyle_v2.ini index 882f80c9..0a109bda 100644 --- a/targets/hdzero_freestyle_v2.ini +++ b/targets/hdzero_freestyle_v2.ini @@ -3,7 +3,6 @@ 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 diff --git a/targets/hdzero_race_v1.ini b/targets/hdzero_race_v1.ini index 41639b23..bc90d40a 100644 --- a/targets/hdzero_race_v1.ini +++ b/targets/hdzero_race_v1.ini @@ -3,4 +3,3 @@ extends = DM5680 build_flags = ${DM5680.build_flags} -DHDZERO_RACE_V1 - -DUSE_SMARTAUDIO_SW \ No newline at end of file diff --git a/targets/hdzero_race_v2.ini b/targets/hdzero_race_v2.ini index 02dfa740..ac458b9f 100644 --- a/targets/hdzero_race_v2.ini +++ b/targets/hdzero_race_v2.ini @@ -3,4 +3,3 @@ extends = DM5680 build_flags = ${DM5680.build_flags} -DHDZERO_RACE_V2 - -DUSE_SMARTAUDIO_SW \ No newline at end of file diff --git a/targets/hdzero_whoop_lite.ini b/targets/hdzero_whoop_lite.ini index 1ef24748..d7ddae78 100644 --- a/targets/hdzero_whoop_lite.ini +++ b/targets/hdzero_whoop_lite.ini @@ -3,5 +3,4 @@ extends = DM5680 build_flags = ${DM5680.build_flags} -DHDZERO_WHOOP_LITE - -DUSE_SMARTAUDIO_SW -DUSE_TEMPERATURE_SENSOR \ No newline at end of file