diff --git a/src/dm6300.c b/src/dm6300.c index 799aced..d162790 100644 --- a/src/dm6300.c +++ b/src/dm6300.c @@ -24,7 +24,7 @@ uint32_t dcoc_qh = 0x075F0000; uint8_t dm6300_init_done = 0; uint8_t dm6300_lost = 0; -#if defined HDZERO_FREESTYLE_V1 || HDZERO_FREESTYLE_V2 +#if defined HDZERO_FREESTYLE_V1 uint8_t table_power[FREQ_NUM_EXTERNAL][POWER_MAX + 1] = { // race band {0x70, 0x68, 0x5c, 0x60}, @@ -51,17 +51,44 @@ uint8_t table_power[FREQ_NUM_EXTERNAL][POWER_MAX + 1] = { {0x70, 0x68, 0x5c, 0x60}, {0x70, 0x68, 0x5c, 0x60}, }; +#elif defined HDZERO_FREESTYLE_V2 +uint8_t table_power[FREQ_NUM_EXTERNAL][POWER_MAX + 1] = { + // race band + {0x30, 0x50, 0x50, 0x58}, + {0x30, 0x50, 0x50, 0x58}, + {0x30, 0x50, 0x50, 0x58}, + {0x30, 0x50, 0x50, 0x58}, + {0x30, 0x50, 0x50, 0x58}, + {0x30, 0x50, 0x50, 0x58}, + {0x30, 0x50, 0x50, 0x58}, + {0x30, 0x50, 0x50, 0x58}, + // e band + {0x70, 0x68, 0x5c, 0x60}, // E1 + // fatshark band + {0x70, 0x68, 0x60, 0x60}, // F1 + {0x72, 0x6d, 0x60, 0x60}, // F2 + {0x74, 0x70, 0x62, 0x5c}, // F4 + // low band + {0x70, 0x68, 0x5c, 0x60}, + {0x70, 0x68, 0x5c, 0x60}, + {0x70, 0x68, 0x5c, 0x60}, + {0x70, 0x68, 0x5c, 0x60}, + {0x70, 0x68, 0x5c, 0x60}, + {0x70, 0x68, 0x5c, 0x60}, + {0x70, 0x68, 0x5c, 0x60}, + {0x70, 0x68, 0x5c, 0x60}, +}; #else uint8_t table_power[FREQ_NUM_EXTERNAL][POWER_MAX + 1] = { // race band - {0x79, 0x83}, - {0x77, 0x81}, - {0x75, 0x80}, - {0x73, 0x7E}, - {0x72, 0x7C}, - {0x70, 0x7B}, - {0x72, 0x7E}, - {0x71, 0x7C}, + {0x50, 0x60}, + {0x50, 0x60}, + {0x50, 0x60}, + {0x50, 0x60}, + {0x50, 0x60}, + {0x50, 0x60}, + {0x50, 0x60}, + {0x50, 0x60}, // e band {0x79, 0x83}, // E1 // fatshark band diff --git a/src/hardware.c b/src/hardware.c index 7b2de06..9b10b23 100644 --- a/src/hardware.c +++ b/src/hardware.c @@ -536,7 +536,6 @@ void Init_6300RF(uint8_t freq, uint8_t pwr) { } void Init_HW() { - WAIT(100); SPI_Init(); LED_Init(); #ifdef VIDEO_PAT @@ -1773,20 +1772,3 @@ uint8_t check_uart_loopback() { } } #endif - -#ifdef USE_USB_DET -typedef void (*reset_mcu_ptr)(void); -reset_mcu_ptr reset_mcu = (reset_mcu_ptr)0x0000; - -void usb_det_task() { - if (USB_DET == 1) { - LED_BLUE_OFF; - WriteReg(0, 0x8F, 0x10); // reset RF_chip - while (USB_DET == 1) { - WAIT(1); - } - // reset 5680 - reset_mcu(); - } -} -#endif \ No newline at end of file diff --git a/src/hardware.h b/src/hardware.h index 564e743..30c8e7a 100644 --- a/src/hardware.h +++ b/src/hardware.h @@ -16,17 +16,15 @@ typedef enum { BW_17M } BWType_e; -#define PWR_DEFAULT 2 -#define SPARKLE_T 20 - // eeprom parameter -#define EEP_ADDR_CAM_TYPE 0x40 -#define EEP_ADDR_CAM_PROFILE 0x41 +#define EEP_ADDR_TAB1 0x00 // 0x00 - 0x1F +#define EEP_ADDR_TAB2 0x20 // 0x20 - 0x3F +#define EEP_ADDR_CAM_TYPE 0x40 +#define EEP_ADDR_CAM_PROFILE 0x41 // profile 1: 0x42~0x51 // profile 2: 0x52~0x61 -// profile 2: 0x62~0x71 -#define EEP_ADDR_CAM_SETTING 0x42 - +// profile 3: 0x62~0x71 +#define EEP_ADDR_CAM_SETTING 0x42 #define EEP_ADDR_RF_FREQ 0x80 #define EEP_ADDR_RF_POWER 0x81 #define EEP_ADDR_LPMODE 0x82 @@ -39,11 +37,15 @@ typedef enum { #define EEP_ADDR_BAUDRATE 0x8B #define EEP_ADDR_LOWBAND_LOCK 0x8C #define EEP_ADDR_SHORTCUT 0x8D +#define EEP_ADDR_TAB3 0xA0 // 0xA0 - 0xBF +#define EEP_ADDR_DCOC1 0xC0 // 0xC0 - 0xC4 #define EEP_ADDR_DCOC_EN 0xC0 #define EEP_ADDR_DCOC_IH 0xC1 #define EEP_ADDR_DCOC_IL 0xC2 #define EEP_ADDR_DCOC_QH 0xC3 #define EEP_ADDR_DCOC_QL 0xC4 +#define EEP_ADDR_DCOC2 0xC5 // 0xC5 - 0xC9 +#define EEP_ADDR_DCOC3 0xCA // 0xCA - 0xCE #define EEP_ADDR_LIFETIME_0 0xF0 #define EEP_ADDR_LIFETIME_1 0xF1 #define EEP_ADDR_LIFETIME_2 0xF2 @@ -80,6 +82,7 @@ void GetVtxParameter(); void Setting_Save(); void Imp_RF_Param(); void CFG_Back(); +void check_eeprom(); void Set_720P50(uint8_t page); void Set_720P60(uint8_t page); diff --git a/src/i2c.c b/src/i2c.c index 2f165e5..a911cb3 100644 --- a/src/i2c.c +++ b/src/i2c.c @@ -5,6 +5,8 @@ #include "global.h" #include "print.h" +extern uint8_t I2C_EN; + #define SCL_SET(n) SCL = n #define SDA_SET(n) SDA = n @@ -29,6 +31,9 @@ void delay_10us() { #endif void I2C_start() { + if (I2C_EN != 1) + return; + SDA_SET(1); DELAY_Q; @@ -44,6 +49,9 @@ void I2C_start() { } void I2C_stop() { + if (I2C_EN != 1) + return; + SDA_SET(0); DELAY_Q; @@ -58,6 +66,9 @@ void I2C_stop() { uint8_t I2C_ack() { uint8_t ret; + if (I2C_EN != 1) + return 1; + SDA_SET(1); DELAY_Q; @@ -74,6 +85,10 @@ uint8_t I2C_ack() { uint8_t I2C_write_byte(uint8_t val) { uint8_t i; + + if (I2C_EN != 1) + return 1; + for (i = 0; i < 8; i++) { if (val >> 7) SDA_SET(1); @@ -99,7 +114,6 @@ uint8_t I2C_write_byte(uint8_t val) { uint8_t I2C_Write8(uint8_t slave_addr, uint8_t reg_addr, uint8_t val) { uint8_t slave = slave_addr << 1; uint8_t value; - I2C_start(); value = I2C_write_byte(slave); @@ -114,8 +128,7 @@ uint8_t I2C_Write8(uint8_t slave_addr, uint8_t reg_addr, uint8_t val) { I2C_write_byte(val); I2C_stop(); - - value = I2C_Read8(slave_addr, reg_addr); + // value = I2C_Read8(slave_addr, reg_addr); // debugf("\r\n0x%4x, 0x%4x", reg_addr, (uint16_t)val); return 0; } @@ -196,6 +209,9 @@ uint8_t I2C_read_byte(uint8_t no_ack) { uint8_t i; uint8_t val = 0; + if (I2C_EN != 1) + return 0; + for (i = 0; i < 8; i++) { DELAY_Q; SCL_SET(1); @@ -232,7 +248,10 @@ uint8_t I2C_Read8(uint8_t slave_addr, uint8_t reg_addr) { I2C_start(); - I2C_write_byte(slave); + if (I2C_write_byte(slave)) { // NACK + I2C_stop(); + return 0; + } I2C_write_byte(reg_addr); diff --git a/src/mcu.c b/src/mcu.c index 089bbe5..6276088 100644 --- a/src/mcu.c +++ b/src/mcu.c @@ -115,13 +115,22 @@ void version_info(void) { #endif } +uint8_t I2C_EN = 0; + void main(void) { - // init + I2C_EN = 0; + WAIT(500); + CPU_init(); WriteReg(0, 0xB0, 0x3E); WriteReg(0, 0xB2, 0x03); WriteReg(0, 0x80, 0xC8); - // WAIT(100); + + if (I2C_EN == 0) + I2C_EN = 1; + + // init + check_eeprom(); version_info(); Init_HW(); // init fc_init(); // init displayport diff --git a/src/msp_displayport.c b/src/msp_displayport.c index 645af7e..4369355 100644 --- a/src/msp_displayport.c +++ b/src/msp_displayport.c @@ -102,7 +102,7 @@ void parse_get_osd_canvas(void); void msp_tx(uint8_t c) { if (msp_tx_en || seconds > 3) - RS_tx(c); + CMS_tx(c); } uint8_t msp_cmp_fc_variant(const char *variant) {