Skip to content

Commit

Permalink
Merge pull request #321 from ligenxxxx/low-band
Browse files Browse the repository at this point in the history
support Low band and (540P60)17Mhz
  • Loading branch information
ligenxxxx authored Aug 10, 2023
2 parents 909e54b + fd2ec34 commit 8f9d73f
Show file tree
Hide file tree
Showing 26 changed files with 757 additions and 231 deletions.
2 changes: 2 additions & 0 deletions mkapp/app/setting.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ power_ana_rx = 1

[source]
analog_format=0
hdzero_band=0
hdzero_bw=0

[record]
mode_manual=false
Expand Down
Binary file modified mkapp/hal/HDZGOGGLE_RX.bin
Binary file not shown.
Binary file modified mkapp/hal/HDZGOGGLE_VA.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion mkapp/hal/ver.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
73-184
74-186
10 changes: 5 additions & 5 deletions src/core/app_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

app_state_t g_app_state = APP_STATE_MAINMENU;

extern int valid_channel_tb[11];
extern int valid_channel_tb[10];
extern int user_select_index;

void app_state_push(app_state_t state) {
Expand Down Expand Up @@ -114,11 +114,11 @@ void app_switch_to_hdzero(bool is_default) {
ini_putl("scan", "channel", g_setting.scan.channel, SETTING_INI);
}

HDZero_open((ch >> 7) & 1);
ch &= 0xF;
HDZero_open(g_setting.source.hdzero_bw);
ch &= 0x7f;

LOGI("switch to ch:%x, CAM_MODE=%d 4:3=%d", g_setting.scan.channel, CAM_MODE, cam_4_3);
DM6302_SetChannel(ch);
LOGI("switch to bw:%d, band:%d, ch:%d, CAM_MODE=%d 4:3=%d", g_setting.source.hdzero_bw, g_setting.source.hdzero_band, g_setting.scan.channel, CAM_MODE, cam_4_3);
DM6302_SetChannel(g_setting.source.hdzero_band, ch);
DM5680_clear_vldflg();
DM5680_req_vldflg();
progress_bar.start = 0;
Expand Down
36 changes: 24 additions & 12 deletions src/core/elrs.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,18 @@ void msp_process_packet() {
if (packet.type == MSP_PACKET_COMMAND) {
switch (packet.function) {
case MSP_GET_BAND_CHAN: {
uint8_t chan, ch;
ch = g_setting.scan.channel & 0xF;
if (ch <= 8) {
chan = ch - 1 + 4 * 8; // Map R1..8
} else {
chan = (ch - 9) * 2 + 3 * 8 + 1; // Map F2/4
uint8_t chan, ch, band;
ch = g_setting.scan.channel;
band = g_setting.source.hdzero_band;

if (band == SETTING_SOURCES_HDZERO_BAND_RACEBAND) {
if (ch <= 8) {
chan = ch - 1 + (4 * 8); // Map R1..8
} else {
chan = ((ch - 9) * 2) + (3 * 8) + 1; // Map F2/4
}
} else { // if (band == SETTING_SOURCES_HDZERO_BAND_LOWBAND)
chan = ch - 1 + 5 * 8; // Map L1..8
}
msp_send_packet(MSP_GET_BAND_CHAN, MSP_PACKET_RESPONSE, 1, &chan);
} break;
Expand Down Expand Up @@ -399,15 +405,21 @@ bool elrs_headtracking_enabled() {
}

void msp_channel_update() {
// Channel 1...10 for R1...8, F2 and F4
// Channel 1...18 for R1...8, F2 and F4, L1...8
uint8_t const ch = g_setting.scan.channel;
uint8_t const band = g_setting.source.hdzero_band;
uint8_t chan;
if (ch == 0 || 10 < ch)

if (ch == 0 || ch > CHANNEL_NUM)
return; // Invalid value -> ignore
if (ch <= 8) {
chan = ch - 1 + (4 * 8); // Map R1..8
} else {
chan = ((ch - 9) * 2) + (3 * 8) + 1; // Map F2/4
if (band == SETTING_SOURCES_HDZERO_BAND_RACEBAND) {
if (ch <= 8) {
chan = ch - 1 + (4 * 8); // Map R1..8
} else {
chan = ((ch - 9) * 2) + (3 * 8) + 1; // Map F2/4
}
} else { // if (band == SETTING_SOURCES_HDZERO_BAND_LOWBAND)
chan = ch - 1 + 5 * 8; // Map L1..8
}
msp_send_packet(MSP_SET_BAND_CHAN, MSP_PACKET_COMMAND, sizeof(chan), &chan);
LOGI("MSPv2 MSP_SET_BAND_CHAN %d sent", chan);
Expand Down
10 changes: 5 additions & 5 deletions src/core/ht.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

#include "bmi270/accel_gyro.h"
#include "core/settings.h"
#include "driver/dm6302.h"
#include "driver/beep.h"
#include "driver/dm6302.h"
#include "driver/hardware.h"
#include "driver/oled.h"
#include "ui/page_common.h"
Expand Down Expand Up @@ -103,7 +103,7 @@ static void detect_motion(bool is_moving) {
beep();

OLED_ON(0); // Turn off OLED
if (g_hw_stat.source_mode == HW_SRC_MODE_HDZERO) {
if (g_hw_stat.source_mode == SOURCE_MODE_HDZERO) {
HDZero_Close(); // Turn off RF
}

Expand All @@ -125,10 +125,10 @@ static void detect_motion(bool is_moving) {
cnt++;

if (cnt == 2) {
if (g_hw_stat.source_mode == HW_SRC_MODE_HDZERO) {
if (g_hw_stat.source_mode == SOURCE_MODE_HDZERO) {
uint8_t ch = g_setting.scan.channel - 1;
HDZero_open((ch >> 7) & 1);
DM6302_SetChannel(ch & 0xF);
HDZero_open(g_setting.source.hdzero_bw);
DM6302_SetChannel(g_setting.source.hdzero_band, ch & 0x7F);
}
LOGI("OLED ON from protection.");
OLED_Brightness(g_setting.image.oled);
Expand Down
4 changes: 2 additions & 2 deletions src/core/input_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ void tune_channel(uint8_t action) {

switch (action) {
case DIAL_KEY_UP: // Tune up
if (channel == 10)
if (channel == CHANNEL_NUM)
channel = 1;
else
channel++;
break;

case DIAL_KEY_DOWN: // Tune down
if (channel == 1)
channel = 10;
channel = CHANNEL_NUM;
else
channel--;
break;
Expand Down
24 changes: 13 additions & 11 deletions src/core/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "driver/nct75.h"
#include "ui/page_common.h"
#include "ui/page_fans.h"
#include "ui/page_scannow.h"
#include "ui/ui_image_setting.h"
#include "ui/ui_porting.h"

Expand Down Expand Up @@ -210,16 +211,17 @@ void osd_vlq_show(bool bShow) {
// = 0x00 | Channel Show Time
uint8_t channel_osd_mode;

char *channel2str(uint8_t channel) // channel=1:10
char *channel2str(uint8_t band, uint8_t channel) // channel=[1:18]
{
static char *ChannelName[] = {
"R1", "R2", "R3", "R4", "R5", "R6", "R7", "R8",
"F2", "F4", ""};
static char *ChannelName[2][10] = {
{"R1", "R2", "R3", "R4", "R5", "R6", "R7", "R8", "F2", "F4"},
{"L1", "L2", "L3", "L4", "L5", "L6", "L7", "L8", " ", " "},
};

if ((channel > 0) && (channel < 11))
return ChannelName[channel - 1];
if ((channel > 0) && (channel <= CHANNEL_NUM))
return ChannelName[band][channel - 1];
else
return ChannelName[0];
return ChannelName[band][0];
}

void osd_channel_show(bool bShow) {
Expand All @@ -228,14 +230,14 @@ void osd_channel_show(bool bShow) {
char buf[32];

if (channel_osd_mode & 0x80) {
ch = channel_osd_mode & 0xF;
ch = channel_osd_mode & 0x7F;
color = lv_color_make(0xFF, 0x20, 0x20);
sprintf(buf, " To %s? ", channel2str(ch));
sprintf(buf, " To %s? ", channel2str(g_setting.source.hdzero_band, ch));
lv_obj_set_style_bg_opa(g_osd_hdzero.channel[is_fhd], LV_OPA_100, 0);
} else {
ch = g_setting.scan.channel & 0xF;
ch = g_setting.scan.channel & 0x7F;
color = lv_color_make(0xFF, 0xFF, 0xFF);
sprintf(buf, "CH:%s", channel2str(ch));
sprintf(buf, "CH:%s", channel2str(g_setting.source.hdzero_band, ch));
lv_obj_set_style_bg_opa(g_osd_hdzero.channel[is_fhd], 0, 0);
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void osd_hdzero_update(void);
void osd_rec_update(bool enable);
void osd_show(bool show);
void osd_update_element_positions();
char *channel2str(uint8_t channel);
char *channel2str(uint8_t band, uint8_t channel);
void load_fc_osd_font(uint8_t);
void *thread_osd(void *ptr);
void osd_resource_path(char *buf, const char *fmt, osd_resource_t osd_resource_type, ...);
Expand Down
7 changes: 7 additions & 0 deletions src/core/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ const setting_t g_setting_defaults = {
.logging = false,
.selftest = false,
},
.source = {
.analog_format = SETTING_SOURCES_ANALOG_FORMAT_NTSC,
.hdzero_band = SETTING_SOURCES_HDZERO_BAND_RACEBAND,
.hdzero_bw = SETTING_SOURCES_HDZERO_BW_WIDE,
},
};

int settings_put_osd_element_shown(bool show, char *config_name) {
Expand Down Expand Up @@ -296,6 +301,8 @@ void settings_load(void) {

// source
g_setting.source.analog_format = ini_getl("source", "analog_format", g_setting_defaults.source.analog_format, SETTING_INI);
g_setting.source.hdzero_band = ini_getl("source", "hdzero_band", g_setting_defaults.source.hdzero_band, SETTING_INI);
g_setting.source.hdzero_bw = ini_getl("source", "hdzero_bw", g_setting_defaults.source.hdzero_bw, SETTING_INI);

// autoscan
g_setting.autoscan.status = ini_getl("autoscan", "status", g_setting_defaults.autoscan.status, SETTING_INI);
Expand Down
10 changes: 10 additions & 0 deletions src/core/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,19 @@ typedef enum {
SETTING_SOURCES_ANALOG_FORMAT_NTSC = 0,
SETTING_SOURCES_ANALOG_FORMAT_PAL = 1
} setting_sources_analog_format_t;
typedef enum {
SETTING_SOURCES_HDZERO_BAND_RACEBAND = 0,
SETTING_SOURCES_HDZERO_BAND_LOWBAND = 1
} setting_sources_hdzero_band_t;
typedef enum {
SETTING_SOURCES_HDZERO_BW_WIDE = 0,
SETTING_SOURCES_HDZERO_BW_NARROW = 1
} setting_sources_hdzero_bw_t;

typedef struct {
setting_sources_analog_format_t analog_format; // 0=NTSC, 1= PAL
setting_sources_hdzero_band_t hdzero_band;
setting_sources_hdzero_bw_t hdzero_bw;
} setting_sources_t;

typedef struct {
Expand Down
120 changes: 106 additions & 14 deletions src/driver/dm6302.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,29 +135,117 @@ void SPI_Write(uint8_t sel, uint8_t page, uint16_t addr, uint32_t dat) {
}

// ����Ƶ��
uint32_t tab[3][FREQ_NUM] = {
{0x3741, 0x379D, 0x37FA, 0x3856, 0x38B3, 0x390F, 0x396C, 0x39C8, 0x3840, 0x38A4},
{0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x96, 0x97},
{0xB00000, 0x9D5555, 0x8AAAAB, 0x780000, 0x655555, 0x52AAAB, 0x400000, 0x2D5555, 0x000000, 0x155555}};

void DM6302_SetChannel(uint8_t ch) {
uint32_t tab[3][18] = {
{
// race band
0x3741,
0x379D,
0x37FA,
0x3856,
0x38B3,
0x390F,
0x396C,
0x39C8,
// fatshark band
0x3840,
0x38A4,
// low band
0x3574,
0x35D2,
0x3631,
0x368F,
0x36ED,
0x374C,
0x37AA,
0x3809,
},
{
// race band
0x93,
0x94,
0x95,
0x96,
0x97,
0x98,
0x99,
0x9A,
// fatshark band
0x96,
0x97,
// low band
0x8B,
0x8C,
0x8D,
0x8E,
0x8F,
0x90,
0x91,
0x92,
},
{
// race band
0xB00000,
0x9D5555,
0x8AAAAB,
0x780000,
0x655555,
0x52AAAB,
0x400000,
0x2D5555,
// fatshark band
0x000000,
0x155555,
// low band
0x1455555,
0x132AAAB,
0x1200000,
0x10D5555,
0xFAAAAB,
0xE80000,
0xD55555,
0xC2AAAB,
},
};

void DM6302_SetChannel(uint8_t band, uint8_t ch) {
if (band == 1)
ch = ch + 10;
SPI_Write(0, 0x6, 0xFF0, 0x00000018);
SPI_Write(0, 0x3, 0x130, 0x00000013);
SPI_Write(0, 0x3, 0x134, 0x00000013);
SPI_Write(0, 0x3, 0x138, 0x00000370);
SPI_Write(0, 0x3, 0x13C, 0x00000410);
SPI_Write(0, 0x3, 0x140, 0x00000000);
SPI_Write(0, 0x3, 0x144, 0x0D640735);
if (band == 1) {
SPI_Write(0, 0x3, 0x144, 0x15240735);
} else {
SPI_Write(0, 0x3, 0x144, 0x0D640735);
}

SPI_Write(0, 0x3, 0x148, 0x01017F03);
SPI_Write(0, 0x3, 0x14C, 0x022288A2);
if (band == 1) {
SPI_Write(0, 0x3, 0x14C, 0x021288A2);
} else {
SPI_Write(0, 0x3, 0x14C, 0x022288A2);
}
SPI_Write(0, 0x3, 0x150, 0x00FFCF33);
SPI_Write(0, 0x3, 0x154, 0x1F0C3440);
SPI_Write(0, 0x3, 0x128, 0x00008030);
if (band == 1) {
SPI_Write(0, 0x3, 0x154, 0x1F2C3840);
SPI_Write(0, 0x3, 0x128, 0x00008031);
} else {
SPI_Write(0, 0x3, 0x154, 0x1F0C3440);
SPI_Write(0, 0x3, 0x128, 0x00008030);
}
SPI_Write(0, 0x3, 0x120, tab[0][ch]); // ch

SPI_Write(0, 0x3, 0x11C, 0x00000002);
SPI_Write(0, 0x3, 0x118, 0x00000001);
SPI_Write(0, 0x3, 0x118, 0x00000000);
SPI_Write(0, 0x3, 0x128, 0x00008030);
if (band == 1) {
SPI_Write(0, 0x3, 0x128, 0x00008031);
} else {
SPI_Write(0, 0x3, 0x128, 0x00008030);
}
SPI_Write(0, 0x3, 0x120, tab[0][ch]); // ch
SPI_Write(0, 0x3, 0x11C, 0x00000003);
SPI_Write(0, 0x3, 0x118, 0x00000001);
Expand All @@ -168,7 +256,11 @@ void DM6302_SetChannel(uint8_t ch) {
SPI_Write(0, 0x3, 0x100, 0x00000000);
SPI_Write(0, 0x3, 0x100, 0x00000003);
SPI_Write(0, 0x3, 0x150, 0x000333B3);
SPI_Write(0, 0x3, 0x140, 0x07070000);
if (band == 1) {
SPI_Write(0, 0x3, 0x140, 0x07070002);
} else {
SPI_Write(0, 0x3, 0x140, 0x07070000);
}
SPI_Write(0, 0x3, 0x130, 0x00000010);
}

Expand Down Expand Up @@ -1080,8 +1172,8 @@ void DM6302_Init14(uint8_t sel, uint8_t bw) {
SPI_Write(sel, 0x3, 0xB4C, 0x10001000);

if (bw) {
SPI_Write(sel, 0x3, 0x90C, 0x9EA3C008);
SPI_Write(sel, 0x3, 0xB0C, 0x9EA3C008);
SPI_Write(sel, 0x3, 0x90C, 0x9EA2C008);
SPI_Write(sel, 0x3, 0xB0C, 0x9EA2C008);
} else {
SPI_Write(sel, 0x3, 0x90C, 0x9E22E0F0);
SPI_Write(sel, 0x3, 0xB0C, 0x9E22E0F0);
Expand Down
Loading

0 comments on commit 8f9d73f

Please sign in to comment.