Skip to content

Commit

Permalink
Merge branch 'main' into write_eeprom
Browse files Browse the repository at this point in the history
  • Loading branch information
ligenxxxx authored Jul 29, 2024
2 parents 8a5bcc2 + 39815a6 commit ddd9d49
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 164 deletions.
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ extra_configs =
targets/hdzero_race_v3.ini
targets/hdzero_freestyle_v2.ini
targets/hdzero_eco.ini
targets/hdzero_aio.ini

15 changes: 14 additions & 1 deletion src/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void camera_ratio_detect(void) {
case CAMERA_TYPE_RUNCAM_NANO_90:
camRatio = 1;
break;
#ifdef HDZERO_ECO
#ifdef USE_TP9950
case CAMERA_TYPE_OUTDATED:
camRatio = 1;
break;
Expand All @@ -74,10 +74,23 @@ void camera_mode_detect(uint8_t init) {

init = 0;

#ifdef USE_TC3587_RSTB
TC3587_RSTB = 0;
WAIT(100);
TC3587_RSTB = 1;
WAIT(100);
#endif

Set_720P60_8bit(0);

debugf("\r\nchipID");
id = I2C_Read8(ADDR_TP9950, 0xfe);
debugf("\r\n fe:%2x", id);
id = I2C_Read8(ADDR_TP9950, 0xff);
debugf("\r\n ff:%2x\r\n", id);
WAIT(200);

debugf("\r\nCamDetect");

Set_720P60_8bit(0);

Expand Down
7 changes: 7 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// #define HDZERO_RACE_V3
// #define HDZERO_FREESTYLE_V2
// #define HDZERO_ECO
// #define HDZERO_AIO

/* define VTX ID start */
#if defined HDZERO_WHOOP
Expand All @@ -37,6 +38,8 @@
#define VTX_ID 0x5b
#elif defined HDZERO_ECO
#define VTX_ID 0x5c
#elif defined HDZERO_AIO
#define VTX_ID 0x5d
#else
#define VTX_ID 0x00
#endif
Expand All @@ -60,6 +63,8 @@
#define VTX_NAME "HDZ FREESTYLE V2"
#elif defined HDZERO_ECO
#define VTX_NAME "HDZ ECO"
#elif defined HDZERO_AIO
#define VTX_NAME "HDZ AIO"
#else
#define VTX_NAME " "
#endif
Expand Down Expand Up @@ -137,6 +142,8 @@
#define SUART_PORT P0_3
#elif defined USE_TC3587_RSTB
#define TC3587_RSTB P0_3
#elif defined USE_USB_DET
#define USB_DET P0_3
#endif
#define CAM_PWM P0_4
#define BTN_1 P0_5
Expand Down
166 changes: 4 additions & 162 deletions src/hardware.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,9 @@ void TempDetect() {
#ifdef HDZERO_ECO
if (temp_new > 10)
temp_new -= 10;
#elif defined HDZERO_AIO
if (temp_new > 15)
temp_new -= 15;
#endif

temperature = temperature - (temperature >> 2) + temp_new;
Expand Down Expand Up @@ -1722,6 +1725,7 @@ void RF_Delay_Init() {
DM6300_AUXADC_Calib();
}
}

void reset_config() {
RF_FREQ = 0;
RF_POWER = 0;
Expand Down Expand Up @@ -1768,165 +1772,3 @@ uint8_t check_uart_loopback() {
}
}
#endif

#if (0)
void _outstring(char *string) {
uint8_t i = 0;
for (i = 0; i < 128; i++) {
if (string[i] == 0)
break;
else
_outchar(string[i]);
}
}
#endif
void check_eeprom() {
const uint8_t tab_base_address[3] = {
EEP_ADDR_TAB1,
EEP_ADDR_TAB2,
EEP_ADDR_TAB3,
};
const uint8_t dcoc_base_address[3] = {
EEP_ADDR_DCOC1,
EEP_ADDR_DCOC2,
EEP_ADDR_DCOC3,
};
const uint8_t tab_range[2] = {20, 160};
const uint8_t dcoc_range[2] = {80, 180};

uint8_t tab_list[3][FREQ_NUM_INTERNAL][POWER_MAX + 1];
uint8_t dcoc_list[3][5];
uint8_t ff_cnt[3];
uint8_t i, j, k;

// read all 3 table_power partitions
for (i = 0; i < 3; i++) {
ff_cnt[i] = 0;
for (j = 0; j < FREQ_NUM_INTERNAL; j++) {
for (k = 0; k < POWER_MAX + 1; k++) {
tab_list[i][j][k] = I2C_Read8(ADDR_EEPROM, tab_base_address[i] + j * (POWER_MAX + 1) + k);
ff_cnt[i] += (tab_list[i][j][k] == 0xff);
}
}
}

#if (0)
// If eeprom is new, init partition 0 with default table_power
if (ff_cnt[0] == (FREQ_NUM_INTERNAL * (POWER_MAX + 1))) {
for (j = 0; j < FREQ_NUM_INTERNAL; j++) {
for (k = 0; k < POWER_MAX + 1; k++) {
I2C_Write8_Wait(10, ADDR_EEPROM, tab_base_address[0] + j * (POWER_MAX + 1) + k, table_power[j][k]);
}
}
_outstring("\r\nInit tab partition 0");
}
#endif

// Init partition 1/2 by copy paratition 0 if is needed (one time)
if ((ff_cnt[1] + ff_cnt[2]) > (FREQ_NUM_INTERNAL * (POWER_MAX + 1))) {
for (i = 1; i < 3; i++) {
for (j = 0; j < FREQ_NUM_INTERNAL; j++) {
for (k = 0; k < POWER_MAX + 1; k++) {
I2C_Write8_Wait(10, ADDR_EEPROM, tab_base_address[i] + j * (POWER_MAX + 1) + k, tab_list[0][j][k]);
tab_list[i][j][k] = tab_list[0][j][k];
}
}
}
//_outstring("\r\nInit tab partition 1, 2");
}

// Check the validity of each value
for (i = 0; i < FREQ_NUM_INTERNAL; i++) {
for (j = 0; j < POWER_MAX + 1; j++) {
if (tab_list[0][i][j] == tab_list[1][i][j] && tab_list[1][i][j] == tab_list[2][i][j] && tab_list[0][i][j] > tab_range[0] && tab_list[0][i][j] < tab_range[1])
// all partition are right
;
else if (tab_list[0][i][j] == tab_list[1][i][j] && tab_list[1][i][j] != tab_list[2][i][j] && tab_list[0][i][j] > tab_range[0] && tab_list[0][i][j] < tab_range[1]) {
// partition 2 value is error
I2C_Write8_Wait(10, ADDR_EEPROM, tab_base_address[2] + i * (POWER_MAX + 1) + j, tab_list[0][i][j]);
//_outstring("\r\ntab2:");
// _outchar('0' + i);
//_outchar('0' + j);
} else if (tab_list[0][i][j] == tab_list[2][i][j] && tab_list[1][i][j] != tab_list[2][i][j] && tab_list[0][i][j] > tab_range[0] && tab_list[0][i][j] < tab_range[1]) {
// partition 1 value is error
I2C_Write8_Wait(10, ADDR_EEPROM, tab_base_address[1] + i * (POWER_MAX + 1) + j, tab_list[0][i][j]);
//_outstring("\r\ntab1:");
//_outchar('0' + i);
//_outchar('0' + j);
} else if (tab_list[0][i][j] != tab_list[2][i][j] && tab_list[1][i][j] == tab_list[2][i][j] && tab_list[1][i][j] > tab_range[0] && tab_list[1][i][j] < tab_range[1]) {
// partition 0 value is error
I2C_Write8_Wait(10, ADDR_EEPROM, tab_base_address[0] + i * (POWER_MAX + 1) + j, tab_list[1][i][j]);
//_outstring("\r\ntab0:");
//_outchar('0' + i);
//_outchar('0' + j);
} else {
I2C_Write8_Wait(10, ADDR_EEPROM, tab_base_address[0] + i * (POWER_MAX + 1) + j, table_power[i][j]);
I2C_Write8_Wait(10, ADDR_EEPROM, tab_base_address[1] + i * (POWER_MAX + 1) + j, table_power[i][j]);
I2C_Write8_Wait(10, ADDR_EEPROM, tab_base_address[2] + i * (POWER_MAX + 1) + j, table_power[i][j]);
//_outstring("\r\n tab all:");
//_outchar('0' + i);
//_outchar('0' + j);
}
}
}

// read all 3 dcoc partitions
for (i = 0; i < 3; i++) {
ff_cnt[i] = 0;
for (j = 0; j < 5; j++) {
dcoc_list[i][j] = I2C_Read8(ADDR_EEPROM, dcoc_base_address[i] + j);
ff_cnt[i] += (dcoc_list[i][j] == 0xff);
}
}

if (ff_cnt[0] == 3)
return;
// Init partition 1/2 by copy paratition 0 if is needed (one time)
if ((ff_cnt[1] + ff_cnt[2]) > 5) {
for (i = 1; i < 3; i++) {
for (j = 0; j < 5; j++) {
I2C_Write8_Wait(10, ADDR_EEPROM, dcoc_base_address[i] + j, dcoc_list[0][j]);
dcoc_list[i][j] = dcoc_list[0][j];
}
}
//_outstring("\r\nInit dcoc partition 1, 2");
}

// Check the validity of each value
if (dcoc_list[0][0] == dcoc_list[1][0] && dcoc_list[1][0] == dcoc_list[2][0] && dcoc_list[0][0] == 0x00) {
;
} else {
I2C_Write8_Wait(10, ADDR_EEPROM, dcoc_base_address[0], 0);
I2C_Write8_Wait(10, ADDR_EEPROM, dcoc_base_address[1], 0);
I2C_Write8_Wait(10, ADDR_EEPROM, dcoc_base_address[2], 0);
//_outstring("\r\ndcoc en err");
}

for (i = 1; i < 5; i++) {
if (dcoc_list[0][i] == dcoc_list[1][i] && dcoc_list[1][i] == dcoc_list[2][i] && dcoc_list[0][i] > dcoc_range[0] && dcoc_list[0][i] < dcoc_range[1])
// all partition are right
;
else if (dcoc_list[0][i] == dcoc_list[1][i] && dcoc_list[1][i] != dcoc_list[2][i] && dcoc_list[0][i] > dcoc_range[0] && dcoc_list[0][i] < dcoc_range[1]) {
// partition 2 value is error
I2C_Write8_Wait(10, ADDR_EEPROM, dcoc_base_address[2] + i, dcoc_list[0][i]);
//_outstring("\r\ndcoc2:");
//_outchar('0' + i);
} else if (dcoc_list[0][i] != dcoc_list[1][i] && dcoc_list[1][i] == dcoc_list[2][i] && dcoc_list[1][i] > dcoc_range[0] && dcoc_list[1][i] < dcoc_range[1]) {
// partition 0 value is error
I2C_Write8_Wait(10, ADDR_EEPROM, dcoc_base_address[0] + i, dcoc_list[1][i]);
//_outstring("\r\ndcoc0:");
//_outchar('0' + i);
} else if (dcoc_list[0][i] != dcoc_list[1][i] && dcoc_list[0][i] == dcoc_list[2][i] && dcoc_list[0][i] > dcoc_range[0] && dcoc_list[0][i] < dcoc_range[1]) {
// partition 1 value is error
I2C_Write8_Wait(10, ADDR_EEPROM, dcoc_base_address[1] + i, dcoc_list[0][i]);
//_outstring("\r\ndcoc1:");
//_outchar('0' + i);
} else {
I2C_Write8_Wait(10, ADDR_EEPROM, dcoc_base_address[0] + i, 128);
I2C_Write8_Wait(10, ADDR_EEPROM, dcoc_base_address[1] + i, 128);
I2C_Write8_Wait(10, ADDR_EEPROM, dcoc_base_address[2] + i, 128);
//_outstring("\r\ndcoc all:");
//_outchar('0' + i);
}
}
}
4 changes: 3 additions & 1 deletion src/hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ void vtx_paralized(void);

void timer_task();
void RF_Delay_Init();

#ifdef USE_USB_DET
void usb_det_task();
#endif
#if defined HDZERO_FREESTYLE_V1 || HDZERO_FREESTYLE_V2
extern uint8_t powerLock;
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/mcu.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,9 @@ void main(void) {
runcam_shutter_fix(seconds);
}
RF_Delay_Init();

#ifdef USE_USB_DET
usb_det_task();
#endif
}
}
8 changes: 8 additions & 0 deletions targets/hdzero_aio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[env:hdzero_aio]
extends = DM5680
build_flags =
${DM5680.build_flags}
-DHDZERO_AIO
-DUSE_TP9950
-DUSE_TEMPERATURE_SENSOR
-DUSE_USB_DET

0 comments on commit ddd9d49

Please sign in to comment.