Skip to content

Commit

Permalink
Merge pull request #155 from ligenxxxx/add-target-hdzero_freestyle_v2
Browse files Browse the repository at this point in the history
Add target hdzero freestyle v2
  • Loading branch information
ligenxxxx authored Sep 25, 2023
2 parents 7528e91 + bbd27f2 commit a1822ca
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 34 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

5 changes: 5 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 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
37 changes: 23 additions & 14 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 @@ -368,7 +368,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 @@ -383,7 +384,7 @@ 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
Expand Down Expand Up @@ -437,7 +438,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 @@ -461,7 +462,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 @@ -638,6 +639,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 @@ -779,7 +783,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 @@ -823,7 +831,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 @@ -860,7 +868,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 @@ -915,6 +923,7 @@ void PwrLMT() {
*/
else if (g_IS_ARMED) { // Armed
PowerAutoSwitch();
HeatProtect();
} else { // Disarmed
if (PIT_MODE) {
/*if(cur_pwr == 0mW)
Expand All @@ -932,7 +941,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 @@ -952,7 +961,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 @@ -1107,7 +1116,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 @@ -1173,7 +1182,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 @@ -1186,7 +1195,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 @@ -53,7 +53,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 @@ -100,7 +100,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
38 changes: 30 additions & 8 deletions src/msp_displayport.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,31 @@ uint8_t get_tx_data_5680() // prepare data to VRX

// VTX temp and overhot
#ifdef USE_TEMPERATURE_SENSOR
#if defined HDZERO_FREESTYLE_V2
temp = temperature >> 2;
if (temp > 90)
temp = 8;
else if (temp > 85)
temp = 7;
else if (temp > 80)
temp = 6;
else if (temp > 75)
temp = 5;
else if (temp > 70)
temp = 4;
else if (temp > 60)
temp = 3;
else if (temp > 50)
temp = 2;
else if (temp > 40)
temp = 1;
else
temp = 0;
#else
temp = temperature_level() >> 1;
if (temp > 8)
temp = 8;
#endif
tx_buf[10] = 0x80 | (heat_protect << 6) | temp;
#else
tx_buf[10] = 0;
Expand Down Expand Up @@ -780,7 +802,7 @@ void msp_set_vtx_config(uint8_t power, uint8_t save) {
crc ^= 0x06; // band count
CMS_tx(0x08);
crc ^= 0x08; // channel count
#ifdef HDZERO_FREESTYLE
#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2
if (powerLock) {
CMS_tx(3);
crc ^= (3); // power count
Expand Down Expand Up @@ -1053,7 +1075,7 @@ void parseMspVtx_V2(uint16_t const cmd_u16) {
vtx_pit_save = PIT_MODE;
} 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 Expand Up @@ -1105,7 +1127,7 @@ void parseMspVtx_V2(uint16_t const cmd_u16) {
if (dm6300_init_done) {
if (cur_pwr != nxt_pwr) {
#ifndef VIDEO_PAT
#ifdef HDZERO_FREESTYLE
#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2
if ((nxt_pwr == 3) && (!g_IS_ARMED))
pwr_lmt_done = 0;
else
Expand Down Expand Up @@ -1424,7 +1446,7 @@ void update_cms_menu(uint16_t roll, uint16_t pitch, uint16_t yaw, uint16_t throt
;
else {
vtx_power++;
#ifdef HDZERO_FREESTYLE
#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2
if (powerLock)
vtx_power &= 0x01;
#endif
Expand All @@ -1438,7 +1460,7 @@ void update_cms_menu(uint16_t roll, uint16_t pitch, uint16_t yaw, uint16_t throt
;
else {
vtx_power--;
#ifdef HDZERO_FREESTYLE
#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2
if (powerLock)
vtx_power &= 0x01;
#endif
Expand Down Expand Up @@ -1877,7 +1899,7 @@ void set_vtx_param() {
debugf("\n\rExit PIT or LP");
#endif
#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 All @@ -1888,7 +1910,7 @@ void set_vtx_param() {
cur_pwr = RF_POWER;
}
} else if (heat_protect) {
#ifdef HDZERO_FREESTYLE
#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2
WriteReg(0, 0x8F, 0x00);
WriteReg(0, 0x8F, 0x01);
DM6300_Init(RF_FREQ, RF_BW);
Expand Down Expand Up @@ -1989,7 +2011,7 @@ void InitVtxTable() {
power_table[0] = bf_vtx_power_table[0];
power_table[1] = bf_vtx_power_table[1];

#if defined HDZERO_FREESTYLE
#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2
if (!powerLock) {
// if we dont have power lock, enable 500mw and 1W
power_table[2] = bf_vtx_power_500mW;
Expand Down
6 changes: 3 additions & 3 deletions src/rom.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ void CalibProc() {
switch (rxbuf[0]) {
case 'r':
for (cnt = 0; cnt < FREQ_NUM_INTERNAL * (POWER_MAX + 1); cnt++) {
Rom_tx(table_power[0][cnt / (POWER_MAX + 1)][cnt % (POWER_MAX + 1)]);
Rom_tx(table_power[cnt / (POWER_MAX + 1)][cnt % (POWER_MAX + 1)]);
}
break;

case 'w':
table_power[0][RF_FREQ][RF_POWER] = rxbuf[1];
table_power[RF_FREQ][RF_POWER] = rxbuf[1];

DM6300_SetPower(RF_POWER, RF_FREQ, pwr_offset);

I2C_Write8_Wait(10, ADDR_EEPROM, RF_FREQ * (POWER_MAX + 1) + RF_POWER, table_power[0][RF_FREQ][RF_POWER]);
I2C_Write8_Wait(10, ADDR_EEPROM, RF_FREQ * (POWER_MAX + 1) + RF_POWER, table_power[RF_FREQ][RF_POWER]);
break;

case 'c':
Expand Down
8 changes: 4 additions & 4 deletions src/smartaudio_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void SA_Response(uint8_t cmd) {
tbuf[7] = freq_new_h; // cur_freq_h
tbuf[8] = freq_new_l; // cur_freq_l
tbuf[9] = SA_dbm; // power dbm
#ifdef HDZERO_FREESTYLE
#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2
if (powerLock) {
tbuf[10] = 1 + 1; // amount of power level
for (i = 0; i <= 1; i++)
Expand Down Expand Up @@ -249,7 +249,7 @@ void SA_Update(uint8_t cmd) {
}
} else {
cur_pwr = dbm_to_pwr(SA_dbm);
#ifdef HDZERO_FREESTYLE
#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2
if (powerLock)
cur_pwr &= 0x01;
#endif
Expand All @@ -258,7 +258,7 @@ void SA_Update(uint8_t cmd) {
pwr_init = cur_pwr;
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 Expand Up @@ -364,7 +364,7 @@ void SA_Update(uint8_t cmd) {
temp_err = 1;
} 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;
cur_pwr = 3;
Expand Down
Loading

0 comments on commit a1822ca

Please sign in to comment.