Skip to content

Commit

Permalink
Merge pull request #207 from ligenxxxx/write_eeprom
Browse files Browse the repository at this point in the history
Multi-partition backup factory values
  • Loading branch information
ligenxxxx authored Jul 29, 2024
2 parents 39815a6 + ddd9d49 commit ca5fc5c
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 42 deletions.
45 changes: 36 additions & 9 deletions src/dm6300.c
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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
Expand Down
18 changes: 0 additions & 18 deletions src/hardware.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
19 changes: 11 additions & 8 deletions src/hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down
27 changes: 23 additions & 4 deletions src/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -29,6 +31,9 @@ void delay_10us() {
#endif

void I2C_start() {
if (I2C_EN != 1)
return;

SDA_SET(1);
DELAY_Q;

Expand All @@ -44,6 +49,9 @@ void I2C_start() {
}

void I2C_stop() {
if (I2C_EN != 1)
return;

SDA_SET(0);
DELAY_Q;

Expand All @@ -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;

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
13 changes: 11 additions & 2 deletions src/mcu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/msp_displayport.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ca5fc5c

Please sign in to comment.