Skip to content

Commit

Permalink
Merge branch 'main' into vtx-menu-add-shortcut-mode-item
Browse files Browse the repository at this point in the history
  • Loading branch information
ligenxxxx committed Sep 27, 2023
2 parents 4e80550 + 55f0faa commit 8461434
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 56 deletions.
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ extra_configs =
targets/hdzero_race_v2.ini
targets/foxeer_vtx.ini
targets/hdzero_race_v3.ini
targets/hdzero_freestyle_v2.ini

3 changes: 3 additions & 0 deletions src/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,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
6 changes: 6 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// #define HDZERO_FREESTYLE
// #define FOXEER_VTX
// #define HDZERO_RACE_V3
// define HDZERO_FREESTYLE_V2

/* define VTX ID start */
#if defined HDZERO_WHOOP
Expand All @@ -31,6 +32,8 @@
#define VTX_ID 0x59
#elif defined HDZERO_RACE_V3
#define VTX_ID 0x5a
#elif defined HDZERO_FREESTYLE_V2
#define VTX_ID 0x5b
#else
#define VTX_ID 0x00
#endif
Expand All @@ -50,6 +53,8 @@
#define VTX_NAME "FOX VTX"
#elif defined HDZERO_RACE_V3
#define VTX_NAME "HDZ RACE V3"
#elif defined HDZERO_FREESTYLE_V2
#define VTX_NAME "HDZ FREESTYLE V2"
#else
#define VTX_NAME " "
#endif
Expand All @@ -66,6 +71,7 @@
// #define REV_UART
// #define VIDEO_PAT
// #define FIX_EEP
// #define RESET_CONFIG

#ifndef _RF_CALIB
// #define _DEBUG_MODE
Expand Down
5 changes: 3 additions & 2 deletions src/dm6300.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ uint32_t dcoc_ih = 0x075F0000;
uint32_t dcoc_qh = 0x075F0000;

uint8_t dm6300_init_done = 0;
#ifdef HDZERO_FREESTYLE
#if defined HDZERO_FREESTYLE || 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 Down Expand Up @@ -281,6 +280,8 @@ uint16_t DM6300_GetFreqByChannel(uint8_t const ch) {
void DM6300_SetPower(uint8_t pwr, uint8_t freq, uint8_t offset) {
#ifdef HDZERO_FREESTYLE
uint16_t a_tab[4] = {0x204, 0x11F, 0x21F, 0x31F};
#elif defined HDZERO_FREESTYLE_V2
uint16_t a_tab[4] = {0x21F, 0x21F, 0x31F, 0x31F};
#else
uint16_t a_tab[2] = {0x21F, 0x41F};
#endif
Expand Down
2 changes: 1 addition & 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"

#ifdef HDZERO_FREESTYLE
#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2
#define PIT_POWER 0x18 // 2dbm
#else
#define PIT_POWER 0x26
Expand Down
55 changes: 40 additions & 15 deletions src/hardware.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ uint8_t KEYBOARD_ON = 0; // avoid conflict between keyboard and cam_control
uint8_t EE_VALID = 0;
uint8_t lowband_lock = 1;

#ifdef HDZERO_FREESTYLE
#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2
uint8_t powerLock = 1;
#endif

/**********************************
//
// POWER MODE
//
// HDZERO_FREESTYLE
// HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2
// 0------------25mW (14dBm)
// 1------------200mW (23dBm)
// 2------------500mW (27dBm)
Expand Down Expand Up @@ -372,7 +372,8 @@ void GetVtxParameter() {
for (j = 0; j <= POWER_MAX; j++) {
table_power[i][j] = tab[i][j];
#ifndef _RF_CALIB
#ifndef HDZERO_FREESTYLE
#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2
#else
if (j == 0) // 25mw +3dbm
table_power[i][j] += 0xC;
#endif
Expand All @@ -387,14 +388,14 @@ void GetVtxParameter() {
#ifdef _RF_CALIB
for (i = 0; i < FREQ_NUM_INTERNAL; i++) {
for (j = 0; j <= POWER_MAX; j++) {
I2C_Write8_Wait(10, ADDR_EEPROM, i * (POWER_MAX + 1) + j, table_power[0][i][j]);
I2C_Write8_Wait(10, ADDR_EEPROM, i * (POWER_MAX + 1) + j, table_power[i][j]);
}
}
#endif
}

// VTX Setting
lowband_lock = 0x01 & I2C_Read8_Wait(10, ADDR_EEPROM, EEP_ADDR_LOWBAND_LOCK);
lowband_lock = I2C_Read8_Wait(10, ADDR_EEPROM, EEP_ADDR_LOWBAND_LOCK);
RF_FREQ = I2C_Read8(ADDR_EEPROM, EEP_ADDR_RF_FREQ);
RF_POWER = I2C_Read8(ADDR_EEPROM, EEP_ADDR_RF_POWER);
LP_MODE = I2C_Read8(ADDR_EEPROM, EEP_ADDR_LPMODE);
Expand All @@ -409,6 +410,22 @@ void GetVtxParameter() {
BAUDRATE = I2C_Read8(ADDR_EEPROM, EEP_ADDR_BAUDRATE);
#endif
CFG_Back();
#ifdef RESET_CONFIG
RF_FREQ = 0;
RF_POWER = 0;
LP_MODE = 0;
PIT_MODE = 0;
OFFSET_25MW = 0;
TEAM_RACE = 0;
BAUDRATE = 0;
I2C_Write8_Wait(10, ADDR_EEPROM, EEP_ADDR_RF_FREQ, RF_FREQ);
I2C_Write8_Wait(10, ADDR_EEPROM, EEP_ADDR_RF_POWER, RF_POWER);
I2C_Write8_Wait(10, ADDR_EEPROM, EEP_ADDR_LPMODE, LP_MODE);
I2C_Write8_Wait(10, ADDR_EEPROM, EEP_ADDR_PITMODE, PIT_MODE);
I2C_Write8_Wait(10, ADDR_EEPROM, EEP_ADDR_25MW, OFFSET_25MW);
I2C_Write8_Wait(10, ADDR_EEPROM, EEP_ADDR_TEAM_RACE, TEAM_RACE);
I2C_Write8_Wait(10, ADDR_EEPROM, EEP_ADDR_BAUDRATE, BAUDRATE);
#endif
#ifdef _DEBUG_MODE
debugf("\r\nUSE EEPROM for VTX setting:RF_FREQ=%d, RF_POWER=%d, LPMODE=%d PIT_MODE=%d", (uint16_t)RF_FREQ, (uint16_t)RF_POWER, (uint16_t)LP_MODE, (uint16_t)PIT_MODE);
#endif
Expand All @@ -426,7 +443,7 @@ void GetVtxParameter() {
#endif
#endif

#ifdef HDZERO_FREESTYLE
#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2
// powerLock
powerLock = 0x01 & I2C_Read8_Wait(10, ADDR_EEPROM, EEP_ADDR_POWER_LOCK);
#endif
Expand All @@ -450,7 +467,7 @@ void Init_6300RF(uint8_t freq, uint8_t pwr) {
DM6300_Init(freq, RF_BW);
DM6300_SetChannel(freq);
#ifndef VIDEO_PAT
#ifdef HDZERO_FREESTYLE
#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2
if ((pwr == 3) && (!g_IS_ARMED))
pwr_lmt_done = 0;
else
Expand Down Expand Up @@ -627,6 +644,9 @@ void PowerAutoSwitch() {

#ifdef HDZERO_WHOOP_LITE
pwr_offset >>= 1;
#elif defined HDZERO_FREESTYLE_V2
if (pwr_offset > 16)
pwr_offset = 16;
#endif

if ((!g_IS_ARMED) && (last_ofs == pwr_offset))
Expand Down Expand Up @@ -768,7 +788,11 @@ void HeatProtect() {
int16_t temp;

#ifdef USE_TEMPERATURE_SENSOR
int16_t temp_max = 0x5A;
#ifdef HDZERO_FREESTYLE_V2
int16_t temp_max = 95;
#else
int16_t temp_max = 90;
#endif
#else
int16_t temp_max = 0x5C0;
int16_t temp_err_data = 0x700;
Expand Down Expand Up @@ -812,7 +836,7 @@ void HeatProtect() {
debugf("\r\nHeat Protect.");
#endif
heat_protect = 1;
#ifdef HDZERO_FREESTYLE
#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2
WriteReg(0, 0x8F, 0x00);
msp_set_vtx_config(POWER_MAX + 1, 0);
#else
Expand Down Expand Up @@ -849,7 +873,7 @@ void PwrLMT() {
pwr_tflg = 0;
pwr_lmt_sec++;

#ifdef HDZERO_FREESTYLE
#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2
// test: power plus every sec
if (pwr_lmt_sec >= 3) {
if (RF_POWER == 3) {
Expand Down Expand Up @@ -904,6 +928,7 @@ void PwrLMT() {
*/
else if (g_IS_ARMED) { // Armed
PowerAutoSwitch();
HeatProtect();
} else { // Disarmed
if (PIT_MODE) {
/*if(cur_pwr == 0mW)
Expand All @@ -921,7 +946,7 @@ void PwrLMT() {
pwr_tflg = 0;
pwr_lmt_sec++;

#ifdef HDZERO_FREESTYLE
#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2
// test: power plus every sec
if (pwr_lmt_sec >= 3) {
if (RF_POWER == 3) {
Expand All @@ -941,7 +966,7 @@ void PwrLMT() {
SPI_Write(0x3, 0x330, 0x31F); // analog offset 1W
}
}
#endif // HDZERO_FREESTYLE
#endif // HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2

#ifdef _DEBUG_MODE
debugf("\r\npwr_lmt_sec %x", (uint16_t)pwr_lmt_sec);
Expand Down Expand Up @@ -1096,7 +1121,7 @@ void Imp_RF_Param() {
if (LP_MODE && !g_IS_ARMED)
return;
#ifndef VIDEO_PAT
#ifdef HDZERO_FREESTYLE
#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2
if (RF_POWER == 3 && !g_IS_ARMED)
pwr_lmt_done = 0;
else
Expand Down Expand Up @@ -1162,7 +1187,7 @@ void Button1_SP() {
RF_POWER = 0;
else
RF_POWER++;
#ifdef HDZERO_FREESTYLE
#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2
if (powerLock)
RF_POWER &= 0x01;
#endif
Expand All @@ -1175,7 +1200,7 @@ void Button1_SP() {
cur_pwr = 0;
} else {
#ifndef VIDEO_PAT
#ifdef HDZERO_FREESTYLE
#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2
if (RF_POWER == 3 && !g_IS_ARMED)
pwr_lmt_done = 0;
else
Expand Down
4 changes: 2 additions & 2 deletions src/hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ typedef enum {
#define FREQ_NUM_EXTERNAL 18
extern uint8_t lowband_lock;
#define FREQ_NUM (lowband_lock ? 10 : 18)
#if defined HDZERO_FREESTYLE
#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2
#define POWER_MAX 3
#else
#define POWER_MAX 1
Expand Down Expand Up @@ -101,7 +101,7 @@ void vtx_paralized(void);

void timer_task();

#ifdef HDZERO_FREESTYLE
#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2
extern uint8_t powerLock;
#endif
extern uint8_t RF_FREQ;
Expand Down
4 changes: 4 additions & 0 deletions src/mcu.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ void timer_task() {
void RF_Delay_Init() {
static uint8_t SA_saved = 0;

#ifdef _RF_CALIB
return;
#endif

if (tramp_lock)
return;

Expand Down
Loading

0 comments on commit 8461434

Please sign in to comment.