Skip to content

Commit

Permalink
Merge branch 'fix-dm6300-variable-rf-power-when-init' into calib_hdze…
Browse files Browse the repository at this point in the history
…ro_freestyle_v2
  • Loading branch information
ligenxxxx committed Nov 17, 2023
2 parents 0516340 + 945cd00 commit f04a7be
Show file tree
Hide file tree
Showing 18 changed files with 655 additions and 531 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ The Blue LED provides these status indications:
- flicker 3x after boot indicates MSP signaling is detected.
- OFF = camera lost (check camera and cabling)
- ON/OFF @ 2hz = heat protection
- ON/OFF @ 2hz quickly = dm6300 is broken
- ON/OFF @ 8hz = 0MW pitt mode active
- ON/OFF @ 4hz = 0.1mw pitt mode active
- ON solid = VTX operation normal
Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[platformio]
extra_configs =
targets/common.ini
targets/hdzero_freestyle.ini
targets/hdzero_freestyle_v1.ini
targets/hdzero_whoop_lite.ini
targets/hdzero_whoop.ini
targets/hdzero_race_v1.ini
Expand Down
31 changes: 21 additions & 10 deletions src/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ void camera_type_detect(void) {
runcam_type_detect();
if (camera_type == CAMERA_TYPE_RUNCAM_MICRO_V1 ||
camera_type == CAMERA_TYPE_RUNCAM_MICRO_V2 ||
camera_type == CAMERA_TYPE_RUNCAM_NANO_90) {
camera_type == CAMERA_TYPE_RUNCAM_NANO_90 ||
camera_type == CAMERA_TYPE_RUNCAM_MICRO_V3) {
camera_mfr = CAMERA_MFR_RUNCAM;
#ifdef _DEBUG_CAMERA
debugf("\r\ncamera mfr : RUNCAM");
Expand All @@ -41,17 +42,21 @@ void camera_type_detect(void) {
}

void camera_ratio_detect(void) {
if (camera_type == CAMERA_TYPE_RUNCAM_MICRO_V1) {
switch (camera_type) {
case CAMERA_TYPE_RUNCAM_MICRO_V1:
camRatio = 0;
} else if (camera_type == CAMERA_TYPE_RUNCAM_MICRO_V2) {
if (camera_setting_reg_set[11] == 0)
camRatio = 1;
else
camRatio = 0;
} else if (camera_type == CAMERA_TYPE_RUNCAM_NANO_90) {
break;
case CAMERA_TYPE_RUNCAM_MICRO_V2:
case CAMERA_TYPE_RUNCAM_MICRO_V3:
camRatio = (camera_setting_reg_set[11] == 0);
break;
case CAMERA_TYPE_RUNCAM_NANO_90:
camRatio = 1;
} else
break;
default:
camRatio = 0;
break;
}
}

void camera_mode_detect(uint8_t init) {
Expand Down Expand Up @@ -84,7 +89,7 @@ void camera_mode_detect(uint8_t init) {
Init_TC3587(0);
video_format = VDO_FMT_720P60;
I2C_Write16(ADDR_TC3587, 0x0058, 0x00e0);
} else if (camera_type == CAMERA_TYPE_RUNCAM_MICRO_V2) {
} else if (camera_type == CAMERA_TYPE_RUNCAM_MICRO_V2 || camera_type == CAMERA_TYPE_RUNCAM_MICRO_V3) {
if (camera_setting_reg_set[11] == 3) {
Set_1080P30(IS_RX);
video_format = VDO_FMT_1080P30;
Expand Down Expand Up @@ -240,6 +245,9 @@ void camera_setting_read(void) {
return;

camera_type_last = camera_reg_read_eep(EEP_ADDR_CAM_TYPE);
#ifdef RESET_CONFIG
camera_type_last = CAMERA_TYPE_UNKNOW;
#endif
if (camera_type_last != camera_type) {
camera_profile_reset();
camera_profile_write();
Expand Down Expand Up @@ -346,6 +354,7 @@ void camera_menu_draw_value(void) {
const char *switch_str[] = {" OFF", " ON"};
const char *resolution_runcam_micro_v2[] = {" 4:3 ", " 16:9CROP ", " 16:9FULL ", " 1080@30 "};
const char *resolution_runcam_nano_90[] = {" 540P@90", "540@90CROP", " 540P@60", "960X720@60"};
const char *resolution_runcam_micro_v3[] = {" 4:3 ", " 16:9CROP ", " 16:9FULL ", " 1080@30 "};

uint8_t str[4];
uint8_t i;
Expand Down Expand Up @@ -426,6 +435,8 @@ void camera_menu_draw_value(void) {
strcpy(&osd_buf[i][osd_menu_offset + 19], resolution_runcam_micro_v2[camera_setting_reg_menu[i - 1]]);
} else if (camera_type == CAMERA_TYPE_RUNCAM_NANO_90) {
strcpy(&osd_buf[i][osd_menu_offset + 19], resolution_runcam_nano_90[camera_setting_reg_menu[i - 1]]);
} else if (camera_type == CAMERA_TYPE_RUNCAM_MICRO_V3) {
strcpy(&osd_buf[i][osd_menu_offset + 19], resolution_runcam_micro_v3[camera_setting_reg_menu[i - 1]]);
}
osd_buf[i][osd_menu_offset + 29] = '>';
break;
Expand Down
4 changes: 3 additions & 1 deletion src/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define RUNCAM_MICRO_V1 0x42
#define RUNCAM_MICRO_V2 0x44
#define RUNCAM_NANO_90 0x46
#define RUNCAM_MICRO_V3 0x48

#define CAMERA_SETTING_NUM 16
#define CAMERA_PROFILE_NUM 3
Expand All @@ -25,7 +26,7 @@ typedef enum {
CAMERA_MFR_UNKNOW,
CAMERA_MFR_FOXEER,
CAMERA_MFR_RUNCAM,
} camera_manufacturer_e;
} camera_manufacture_e;

typedef enum {
CAMERA_TYPE_UNKNOW,
Expand All @@ -34,6 +35,7 @@ typedef enum {
CAMERA_TYPE_RUNCAM_MICRO_V1, // include hdz nano v1
CAMERA_TYPE_RUNCAM_MICRO_V2, // include hzd nano v2 / hdz nano lite
CAMERA_TYPE_RUNCAM_NANO_90,
CAMERA_TYPE_RUNCAM_MICRO_V3,
} camera_type_e;

typedef enum {
Expand Down
15 changes: 9 additions & 6 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// #define HDZERO_WHOOP_LITE
// #define HDZERO_RACE_V1
// #define HDZERO_RACE_V2
// #define HDZERO_FREESTYLE
// #define HDZERO_FREESTYLE_V1
// #define FOXEER_VTX
// #define HDZERO_RACE_V3
// define HDZERO_FREESTYLE_V2
// #define HDZERO_FREESTYLE_V2

/* define VTX ID start */
#if defined HDZERO_WHOOP
Expand All @@ -26,7 +26,7 @@
#define VTX_ID 0x56
#elif defined HDZERO_RACE_V2
#define VTX_ID 0x57
#elif defined HDZERO_FREESTYLE
#elif defined HDZERO_FREESTYLE_V1
#define VTX_ID 0x58
#elif defined FOXEER_VTX
#define VTX_ID 0x59
Expand All @@ -47,8 +47,8 @@
#define VTX_NAME "HDZ RACE V1"
#elif defined HDZERO_RACE_V2
#define VTX_NAME "HDZ RACE V2"
#elif defined HDZERO_FREESTYLE
#define VTX_NAME "HDZ FREESTYLE"
#elif defined HDZERO_FREESTYLE_V1
#define VTX_NAME "HDZ FREESTYLE V1"
#elif defined FOXEER_VTX
#define VTX_NAME "FOX VTX"
#elif defined HDZERO_RACE_V3
Expand All @@ -71,6 +71,7 @@
#define REV_UART
#define VIDEO_PAT
// #define FIX_EEP
// #define RESET_CONFIG

#ifndef _RF_CALIB
// #define _DEBUG_MODE
Expand Down Expand Up @@ -165,13 +166,15 @@
#define Rom_ready() RS_ready()

#define FREQ_R1 (uint16_t)5658
#define FREQ_R2 (uint16_t)5696
#define FREQ_R2 (uint16_t)5695
#define FREQ_R3 (uint16_t)5732
#define FREQ_R4 (uint16_t)5769
#define FREQ_R5 (uint16_t)5806
#define FREQ_R6 (uint16_t)5843
#define FREQ_R7 (uint16_t)5880
#define FREQ_R8 (uint16_t)5917
#define FREQ_E1 (uint16_t)5705
#define FREQ_F1 (uint16_t)5740
#define FREQ_F2 (uint16_t)5760
#define FREQ_F4 (uint16_t)5800
#define FREQ_L1 (uint16_t)5362
Expand Down
93 changes: 68 additions & 25 deletions src/dm6300.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ uint32_t dcoc_ih = 0x075F0000;
uint32_t dcoc_qh = 0x075F0000;

uint8_t dm6300_init_done = 0;
#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2
uint8_t dm6300_lost = 0;
#if defined HDZERO_FREESTYLE_V1 || HDZERO_FREESTYLE_V2
uint8_t table_power[FREQ_NUM_EXTERNAL][POWER_MAX + 1] = {
// race band
{0x70, 0x68, 0x5c, 0x60},
{0x70, 0x68, 0x5c, 0x60},
{0x70, 0x68, 0x60, 0x60},
Expand All @@ -33,9 +35,12 @@ uint8_t table_power[FREQ_NUM_EXTERNAL][POWER_MAX + 1] = {
{0x78, 0x74, 0x64, 0x5b},
{0x7a, 0x77, 0x64, 0x5b},
{0x7a, 0x77, 0x64, 0x5b},
// e band
{0x70, 0x68, 0x5c, 0x60}, // E1
// fatshark band
{0x72, 0x6d, 0x60, 0x60},
{0x74, 0x70, 0x62, 0x5c},
{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},
Expand All @@ -57,9 +62,12 @@ uint8_t table_power[FREQ_NUM_EXTERNAL][POWER_MAX + 1] = {
{0x70, 0x7B},
{0x72, 0x7E},
{0x71, 0x7C},
// e band
{0x79, 0x83}, // E1
// fatshark band
{0x73, 0x7E},
{0x72, 0x7C},
{0x75, 0x80}, // F1
{0x73, 0x7E}, // F2
{0x72, 0x7C}, // F4
// low band
{0x79, 0x83},
{0x79, 0x83},
Expand All @@ -83,9 +91,15 @@ const uint32_t tab[3][FREQ_NUM_EXTERNAL] = {
0x3A3F,
0x3A9E,
0x3AFC,

// E band
0x38DF, // E1

// fatshark bank
0x3840,
0x38A4,
0x3938, // F1
0x3840, // F2
0x38A4, // F4

// low band
0x3574,
0x35D2,
Expand All @@ -106,9 +120,15 @@ const uint32_t tab[3][FREQ_NUM_EXTERNAL] = {
0x98,
0x99,
0x9a,

// E band
0x94, // E1

// fatshark bank
0x96,
0x97,
0x95, // F1
0x96, // F2
0x97, // F4

// low band
0x8B,
0x8C,
Expand All @@ -129,9 +149,14 @@ const uint32_t tab[3][FREQ_NUM_EXTERNAL] = {
0x52AAAB,
0x400000,
0x2D5555,
// E band
0x122AAAB, // E1

// fatshark bank
0x000000,
0x155555,
0xF55555, // F1
0x000000, // F2
0x155555, // F4

// low band
0x1455555,
0x132AAAB,
Expand All @@ -154,9 +179,15 @@ const uint32_t freq_tab[FREQ_NUM_EXTERNAL] = {
116780,
117560,
118280,

// e band
114100, // E1

// fatshark bank
115200,
116000,
114800, // F1
115200, // F2
116000, // F4

// low band
107240,
107980,
Expand All @@ -177,6 +208,8 @@ const uint16_t frequencies[] = {
FREQ_R6,
FREQ_R7,
FREQ_R8,
FREQ_E1,
FREQ_F1,
FREQ_F2,
FREQ_F4,
FREQ_L1,
Expand Down Expand Up @@ -240,14 +273,7 @@ void DM6300_SetChannel(uint8_t ch) {

if (ch >= FREQ_NUM)
ch = 0;
/*#ifndef _RF_CALIB
#ifndef _DEBUG_MODE
else if(ch == 5) ch = 7;
else if(ch == 6) ch = 5;
else if(ch == 7) ch = 6;
#endif
#endif
*/

dm6300_set_channel_regs[12].dat = 0x00008000 + (init6300_fcnt & 0xFF);
dm6300_set_channel_regs[13].dat = init6300_fnum[ch];

Expand Down Expand Up @@ -278,7 +304,7 @@ uint16_t DM6300_GetFreqByChannel(uint8_t const ch) {
}

void DM6300_SetPower(uint8_t pwr, uint8_t freq, uint8_t offset) {
#ifdef HDZERO_FREESTYLE
#ifdef HDZERO_FREESTYLE_V1
uint16_t a_tab[4] = {0x204, 0x11F, 0x21F, 0x31F};
#elif defined HDZERO_FREESTYLE_V2
uint16_t a_tab[4] = {0x21F, 0x21F, 0x31F, 0x31F};
Expand All @@ -289,7 +315,7 @@ void DM6300_SetPower(uint8_t pwr, uint8_t freq, uint8_t offset) {
#ifdef _DEBUG_MODE
debugf("\r\nDM6300 set power:%x, offset:%x", (uint16_t)pwr, (uint16_t)offset);
#endif
if (freq > 9)
if (freq >= FREQ_NUM)
freq = 0;
SPI_Write(0x6, 0xFF0, 0x00000018);

Expand Down Expand Up @@ -598,7 +624,7 @@ void DM6300_init3(uint8_t ch) {
CODE_SEG const dm6300_reg_value_t dm6300_init4_regs[] = {
// 04_TX_CA1_RF
{0x6, 0xFF0, 0x00000018},
{0x3, 0x31C, 0x00000000}, // 0x00000030
{0x3, 0x31C, 0x00000030}, // 0x00000030
{0x3, 0x300, 0xC000281B},
{0x3, 0x304, 0x0CC00006},
{0x3, 0x308, 0x00000000},
Expand All @@ -612,7 +638,7 @@ CODE_SEG const dm6300_reg_value_t dm6300_init4_regs[] = {
{0x3, 0x32C, 0x00000000},
{0x3, 0x330, 0x00000000}, // remove init DC high
{0x3, 0x334, 0x00000000},
{0x3, 0x31C, 0x00000011},
{0x3, 0x31C, 0x00000010},
};

void DM6300_init4() {
Expand Down Expand Up @@ -875,10 +901,27 @@ CODE_SEG const dm6300_reg_value_t dm6300_init_regs[] = {
{0x3, 0x018, 0x00000001},
{0x3, 0x018, 0x00000000}};

uint8_t DM6300_detect(void) {
uint32_t rdat = 0;
SPI_Write(0x6, 0xFF0, 0x18);
SPI_Read(0x6, 0xFF0, &rdat);

#ifdef _DEBUG_MODE
if (rdat != 0x18) {
debugf("\r\ndm6300 lost");
} else {
debugf("\r\ndm6300 alive");
}
#endif
return rdat != 0x18;
}

void DM6300_Init(uint8_t ch, BWType_e bw) {
int i;
uint32_t dat;

// dm6300 detect
dm6300_lost = DM6300_detect();
// 01_INIT
DM6300_init1();

Expand Down
3 changes: 2 additions & 1 deletion src/dm6300.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "common.h"
#include "hardware.h"

#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2
#if defined HDZERO_FREESTYLE_V1 || HDZERO_FREESTYLE_V2
#define PIT_POWER 0x18 // 2dbm
#else
#define PIT_POWER 0x26
Expand Down Expand Up @@ -37,4 +37,5 @@ extern uint8_t table_power[FREQ_NUM_EXTERNAL][POWER_MAX + 1];
extern uint32_t dcoc_ih, dcoc_qh;

extern uint8_t dm6300_init_done;
extern uint8_t dm6300_lost;
#endif /* __DM6300_H_ */
Loading

0 comments on commit f04a7be

Please sign in to comment.