Skip to content

Commit

Permalink
new target: HDZero ECO VTX (#195)
Browse files Browse the repository at this point in the history
* add tp9950 driver

* LED_BLUE_OFF if no ahd camera is detected

* Update common.h

* do not detect camera resolution

* add new vtx hdzero_pico

* optimized pico vtx _RF_CALIB

* add HDZero ECO VTX

* set eco camera ratio to 4:3

* Update hardware.c

* clean debugf

* Calibrate eco vtx temperature value
  • Loading branch information
ligenxxxx committed Mar 25, 2024
1 parent a6f027e commit 0258086
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 5 deletions.
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ extra_configs =
targets/foxeer_vtx.ini
targets/hdzero_race_v3.ini
targets/hdzero_freestyle_v2.ini
targets/hdzero_eco.ini

106 changes: 106 additions & 0 deletions src/camera.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "camera.h"
#include "common.h"
#include "dm6300.h"
#include "global.h"
#include "hardware.h"
Expand Down Expand Up @@ -53,12 +54,116 @@ void camera_ratio_detect(void) {
case CAMERA_TYPE_RUNCAM_NANO_90:
camRatio = 1;
break;
#ifdef HDZERO_ECO
case CAMERA_TYPE_OUTDATED:
camRatio = 1;
break;
#endif
default:
camRatio = 0;
break;
}
}

#ifdef USE_TP9950
void camera_mode_detect(uint8_t init) {

uint32_t frame = 0;
uint32_t agc_en = 0;
uint8_t id = 0;

init = 0;

TC3587_RSTB = 0;
WAIT(100);
TC3587_RSTB = 1;
WAIT(100);

Set_720P60_8bit(0);

#ifdef _DEBUG_MODE
debugf("\r\nchipID");
#endif
id = I2C_Read8(ADDR_TP9950, 0xfe);
#ifdef _DEBUG_MODE
debugf("\r\n fe:%2x", id);
#endif

id = I2C_Read8(ADDR_TP9950, 0xff);
#ifdef _DEBUG_MODE
debugf("\r\n ff:%2x\r\n", id);
#endif
WAIT(200);

I2C_Write8(ADDR_TP9950, 0x26, 0x01);
I2C_Write8(ADDR_TP9950, 0x07, 0xC0);
I2C_Write8(ADDR_TP9950, 0x0B, 0xC0);
I2C_Write8(ADDR_TP9950, 0x22, 0x35);
agc_en = I2C_Read8(ADDR_TP9950, 0x06);
agc_en &= 0xFB;
I2C_Write8(ADDR_TP9950, 0x06, agc_en);

I2C_Write8(ADDR_TP9950, 0x02, 0xca);
I2C_Write8(ADDR_TP9950, 0x0b, 0xc0);
I2C_Write8(ADDR_TP9950, 0x0c, 0x03);
I2C_Write8(ADDR_TP9950, 0x0d, 0x50);
I2C_Write8(ADDR_TP9950, 0x15, 0x13);
I2C_Write8(ADDR_TP9950, 0x16, 0x16);
I2C_Write8(ADDR_TP9950, 0x17, 0x00);
I2C_Write8(ADDR_TP9950, 0x18, 0x19);
I2C_Write8(ADDR_TP9950, 0x19, 0xD0);
I2C_Write8(ADDR_TP9950, 0x1a, 0x25);
I2C_Write8(ADDR_TP9950, 0x20, 0x30);
I2C_Write8(ADDR_TP9950, 0x21, 0x84);
I2C_Write8(ADDR_TP9950, 0x22, 0x36);
I2C_Write8(ADDR_TP9950, 0x23, 0x3c);
I2C_Write8(ADDR_TP9950, 0x26, 0x05);
I2C_Write8(ADDR_TP9950, 0x2b, 0x60);
I2C_Write8(ADDR_TP9950, 0x2c, 0x0a);
I2C_Write8(ADDR_TP9950, 0x2d, 0x30);
I2C_Write8(ADDR_TP9950, 0x2e, 0x70);
I2C_Write8(ADDR_TP9950, 0x30, 0x48);
I2C_Write8(ADDR_TP9950, 0x31, 0xbb);
I2C_Write8(ADDR_TP9950, 0x32, 0x2e);
I2C_Write8(ADDR_TP9950, 0x33, 0x90);
I2C_Write8(ADDR_TP9950, 0x39, 0x1c);
I2C_Write8(ADDR_TP9950, 0x3B, 0x26);
I2C_Write8(ADDR_TP9950, 0x18, 0x19);
I2C_Write8(ADDR_TP9950, 0x40, 0x08);
I2C_Write8(ADDR_TP9950, 0x13, 0x04);
I2C_Write8(ADDR_TP9950, 0x14, 0x04);
I2C_Write8(ADDR_TP9950, 0x40, 0x00);
I2C_Write8(ADDR_TP9950, 0x35, 0x05);
I2C_Write8(ADDR_TP9950, 0xfa, 0x08);
I2C_Write8(ADDR_TP9950, 0x4C, 0x40);
I2C_Write8(ADDR_TP9950, 0x4e, 0x05);

I2C_Write8(ADDR_TP9950, 0x1c, 0x06);
I2C_Write8(ADDR_TP9950, 0x1d, 0x72);
// **** soft reset **** //
I2C_Write8(ADDR_TP9950, 0x06, 0xb2);

video_format = VDO_FMT_720P60;
camera_type = CAMERA_TYPE_OUTDATED;
camera_ratio_detect();
LED_BLUE_ON;
led_status = ON;

RF_BW = BW_27M;
RF_BW_last = RF_BW;

#ifdef _RF_CALIB
WAIT(1000);
if (I2C_Read8(ADDR_TP9950, 0x01) != 0x7E) { // if camera lost
WriteReg(0, 0x50, 0x01); // set to video pattern
}
RF_POWER = 0;
RF_FREQ = 0;
Init_6300RF(RF_FREQ, RF_POWER);
DM6300_AUXADC_Calib();
#endif
}
#else
void camera_mode_detect(uint8_t init) {
uint8_t cycles = 4;
uint8_t loss = 0;
Expand Down Expand Up @@ -162,6 +267,7 @@ void camera_mode_detect(uint8_t init) {
debugf("27M");
#endif
}
#endif

void camera_button_init() {
WriteReg(0, 0x17, 0xC0);
Expand Down
10 changes: 7 additions & 3 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// #define FOXEER_VTX
// #define HDZERO_RACE_V3
// #define HDZERO_FREESTYLE_V2
// #define HDZERO_ECO

/* define VTX ID start */
#if defined HDZERO_WHOOP
Expand All @@ -34,6 +35,8 @@
#define VTX_ID 0x5a
#elif defined HDZERO_FREESTYLE_V2
#define VTX_ID 0x5b
#elif defined HDZERO_ECO
#define VTX_ID 0x5c
#else
#define VTX_ID 0x00
#endif
Expand All @@ -55,6 +58,8 @@
#define VTX_NAME "HDZ RACE V3"
#elif defined HDZERO_FREESTYLE_V2
#define VTX_NAME "HDZ FREESTYLE V2"
#elif defined HDZERO_ECO
#define VTX_NAME "HDZ ECO"
#else
#define VTX_NAME " "
#endif
Expand Down Expand Up @@ -114,9 +119,8 @@
#define WAIT_SA_CONFIG 3
#endif

#define CFG_TO_SEC 10
#define CAM_DET_DLY 1000
#define DISP_TIME 3 // 3/8s
#define CFG_TO_SEC 10
#define DISP_TIME 3 // 3/8s

// gpio
#define SCL P0_0
Expand Down
38 changes: 37 additions & 1 deletion src/hardware.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,26 @@ void Set_720P60(uint8_t page) {
WriteReg(page, 0x06, 0x01);
}

void Set_720P60_8bit(uint8_t page) {
WriteReg(page, 0x21, 0x1F);

WriteReg(page, 0x40, 0x00);
WriteReg(page, 0x41, 0x2A);
WriteReg(page, 0x42, 0xD0);
WriteReg(page, 0x43, 0xE4);
WriteReg(page, 0x44, 0x4C);
WriteReg(page, 0x45, 0xEE);
WriteReg(page, 0x49, 0x04);
WriteReg(page, 0x4c, 0x19);
WriteReg(page, 0x4f, 0x86);
WriteReg(page, 0x52, 0x04);
WriteReg(page, 0x53, 0x00);
WriteReg(page, 0x54, 0x3C);
WriteReg(0, 0x8e, 0x04);

WriteReg(page, 0x06, 0x01);
}

void Set_960x720P60(uint8_t page) {
WriteReg(page, 0x21, 0x1C);

Expand Down Expand Up @@ -518,7 +538,11 @@ void Init_HW() {
SPI_Init();
LED_Init();
#ifdef VIDEO_PAT
#ifdef USE_TP9950
Set_720P60_8bit(0);
#else
Set_720P60(0);
#endif
WriteReg(0, 0x50, 0x01);
RF_FREQ = 0;
GetVtxParameter();
Expand Down Expand Up @@ -574,7 +598,12 @@ void TempDetect() {
temp_new = I2C_Read8(ADDR_TEMPADC, 0);
if (temp_new >= 0x7D) // MAX +125
temp_new = 0x7D;
// temp_new >>= 5; //LM75AD
// temp_new >>= 5; //LM75AD

#ifdef HDZERO_ECO
if (temp_new > 10)
temp_new -= 10;
#endif

temperature = temperature - (temperature >> 2) + temp_new;

Expand Down Expand Up @@ -1133,10 +1162,17 @@ void video_detect(void) {
}

cameraLost = (ReadReg(0, 0x02) >> 4) & 1;
if (camera_type == CAMERA_TYPE_OUTDATED) {
cameraLost |= (I2C_Read8(ADDR_TP9950, 0x01) != 0x7E);
return;
}

if (sec == 3) {
sec = 0;
if (cameraLost) { // video loss
#ifdef _DEBUG_CAMERA
debugf("r\ncamera lost");
#endif
if (video_format == VDO_FMT_720P50) {
Set_720P60(IS_RX);
video_format = VDO_FMT_720P60;
Expand Down
1 change: 1 addition & 0 deletions src/hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ void Set_960x720P60(uint8_t page);
void Set_720P30(uint8_t page, uint8_t is_43);
void Set_540P60(uint8_t page);
void Set_1080P30(uint8_t page);
void Set_720P60_8bit(uint8_t page);

void Flicker_LED(uint8_t n);
void LED_Flip();
Expand Down
2 changes: 1 addition & 1 deletion src/i2c_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define ADDR_MAX7315 0x20 // Rev1 Rev3
#define ADDR_PCA9554 0x38 // Rev2

#define ADDR_TP2825 0x44
#define ADDR_TP9950 0x44
#define ADDR_TC3587 0x0E
#define ADDR_EEPROM 0x50
#define ADDR_TEMPADC 0x48
Expand Down
8 changes: 8 additions & 0 deletions targets/hdzero_eco.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[env:hdzero_eco]
extends = DM5680
build_flags =
${DM5680.build_flags}
-DHDZERO_ECO
-DUSE_TC3587_RSTB
-DUSE_TP9950
-DUSE_TEMPERATURE_SENSOR

0 comments on commit 0258086

Please sign in to comment.