Skip to content

Commit

Permalink
Merge pull request #166 from ligenxxxx/detect-dm6300
Browse files Browse the repository at this point in the history
if dm6300 lost, led will fast flash 2 times every second.
  • Loading branch information
ligenxxxx authored Oct 24, 2023
2 parents 82cee65 + eca31c7 commit e614f63
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 123 deletions.
11 changes: 11 additions & 0 deletions src/dm6300.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ uint32_t dcoc_ih = 0x075F0000;
uint32_t dcoc_qh = 0x075F0000;

uint8_t dm6300_init_done = 0;
uint8_t dm6300_lost = 0;
#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2
uint8_t table_power[FREQ_NUM_EXTERNAL][POWER_MAX + 1] = {
{0x70, 0x68, 0x5c, 0x60},
Expand Down Expand Up @@ -875,10 +876,20 @@ 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(0x3, 0xFF0, 0x18);
SPI_Read(0x3, 0x254, &rdat);

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
1 change: 1 addition & 0 deletions src/dm6300.h
Original file line number Diff line number Diff line change
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_ */
130 changes: 129 additions & 1 deletion src/hardware.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "sfr_ext.h"
#include "smartaudio_protocol.h"
#include "spi.h"
#include "tramp_protocol.h"
#include "uart.h"

uint8_t KEYBOARD_ON = 0; // avoid conflict between keyboard and cam_control
Expand Down Expand Up @@ -103,6 +104,8 @@ uint8_t dispL_cnt = 0xff;

uint8_t cameraLost = 0;

uint8_t timer_cnt = 0;

void LED_Init();

void Set_720P50(uint8_t page) {
Expand Down Expand Up @@ -1438,7 +1441,15 @@ void LED_Flip() {
}
}
void LED_Task() {
if (cameraLost) {
if (dm6300_lost) {
if (timer_cnt == 0 || timer_cnt == 4) {
LED_BLUE_ON;
led_status = ON;
} else if (timer_cnt == 2 || timer_cnt == 6) {
LED_BLUE_OFF;
led_status = OFF;
}
} else if (cameraLost) {
if (led_status == ON) {
LED_BLUE_OFF;
led_status = OFF;
Expand Down Expand Up @@ -1502,4 +1513,121 @@ void vtx_paralized(void) {
LED_Flip();
WAIT(50);
}
}

void timer_task() {
static uint16_t cur_ms10x_1sd16 = 0, last_ms10x_1sd16 = 0;
cur_ms10x_1sd16 = timer_ms10x;

if (((cur_ms10x_1sd16 - last_ms10x_1sd16) >= TIMER0_1SD16) || (cur_ms10x_1sd16 < last_ms10x_1sd16)) {
last_ms10x_1sd16 = cur_ms10x_1sd16;
timer_cnt++;
timer_cnt &= 15;
if (timer_cnt == 15) { // every second, 1Hz
btn1_tflg = 1;
pwr_tflg = 1;
cfg_tflg = 1;
seconds++;
pwr_sflg = 1;
}

timer_2hz = ((timer_cnt & 7) == 7);
timer_4hz = ((timer_cnt & 3) == 3);
timer_8hz = ((timer_cnt & 1) == 1);
timer_16hz = 1;
} else {
timer_2hz = 0;
timer_4hz = 0;
timer_8hz = 0;
timer_16hz = 0;
}
}

void RF_Delay_Init() {
static uint8_t SA_saved = 0;

#ifdef _RF_CALIB
return;
#endif

if (tramp_lock)
return;

if (SA_saved == 0) {
if (seconds >= WAIT_SA_CONFIG) {
I2C_Write8(ADDR_EEPROM, EEP_ADDR_SA_LOCK, SA_lock);
SA_saved = 1;
#ifdef _DEBUG_MODE
debugf("\r\nSave SA_lock(%x) to EEPROM", (uint16_t)SA_lock);
#endif
}
}

// init_rf
if (seconds < WAIT_SA_CONFIG) { // wait for SA config vtx
if (seconds < WAIT_SA_LOCK)
return;
else if (SA_lock)
return;
else
seconds = WAIT_SA_CONFIG;
} else if (rf_delay_init_done)
return;
else if (dm6300_init_done)
return;
else
rf_delay_init_done = 1;

if (last_SA_lock) {
#ifdef _DEBUG_MODE
debugf("\r\nRF_Delay_Init: SA");
#endif
pwr_lmt_sec = PWR_LMT_SEC;
if (SA_lock) {
if (pwr_init == POWER_MAX + 2) { // 0mW
RF_POWER = POWER_MAX + 2;
cur_pwr = POWER_MAX + 2;
} else if (PIT_MODE) {
Init_6300RF(ch_init, POWER_MAX + 1);
#ifdef _DEBUG_MODE
debugf("\r\n ch%x, pwr%x", (uint16_t)ch_init, (uint16_t)cur_pwr);
#endif
} else {
Init_6300RF(ch_init, pwr_init);
#ifdef _DEBUG_MODE
debugf("\r\n ch%x, pwr%x", (uint16_t)ch_init, (uint16_t)cur_pwr);
#endif
}
DM6300_AUXADC_Calib();
}
} else if (!mspVtxLock) {
#ifdef _DEBUG_MODE
debugf("\r\nRF_Delay_Init: None");
#endif
if (TEAM_RACE == 0x01)
vtx_paralized();
#if (0)
if (PIT_MODE == PIT_0MW) {
pwr_lmt_done = 1;
RF_POWER = POWER_MAX + 2;
cur_pwr = POWER_MAX + 2;
vtx_pit = PIT_0MW;
} else if (PIT_MODE == PIT_P1MW) {
#else
if (PIT_MODE != PIT_OFF) {
#endif
Init_6300RF(RF_FREQ, POWER_MAX + 1);
vtx_pit = PIT_P1MW;
} else {
WriteReg(0, 0x8F, 0x00);
WriteReg(0, 0x8F, 0x01);
DM6300_Init(RF_FREQ, RF_BW);
DM6300_SetChannel(RF_FREQ);
DM6300_SetPower(0, RF_FREQ, 0);
cur_pwr = RF_POWER;
WriteReg(0, 0x8F, 0x11);
rf_delay_init_done = 1;
}
DM6300_AUXADC_Calib();
}
}
4 changes: 4 additions & 0 deletions src/hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ uint8_t temperature_level(void);
void vtx_paralized(void);

void timer_task();
void RF_Delay_Init();

#if defined HDZERO_FREESTYLE || HDZERO_FREESTYLE_V2
extern uint8_t powerLock;
Expand Down Expand Up @@ -141,4 +142,7 @@ extern uint8_t temp_err;
extern uint8_t rf_delay_init_done;

extern int16_t temperature;

extern uint8_t timer_cnt;

#endif /* __HARDWARE_H_ */
122 changes: 0 additions & 122 deletions src/mcu.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
uint8_t UNUSED = 0;
uint8_t rf_delay_init_done = 0;

void timer_task();
void RF_Delay_Init();

BIT_TYPE int0_req = 0;
BIT_TYPE int1_req = 0;

Expand Down Expand Up @@ -173,125 +170,6 @@ void main(void) {
uart_baudrate_detect();
runcam_shutter_fix(seconds);
}

RF_Delay_Init();
}
}

void timer_task() {
static uint16_t cur_ms10x_1sd16 = 0, last_ms10x_1sd16 = 0;
static uint8_t timer_cnt = 0;
cur_ms10x_1sd16 = timer_ms10x;

if (((cur_ms10x_1sd16 - last_ms10x_1sd16) >= TIMER0_1SD16) || (cur_ms10x_1sd16 < last_ms10x_1sd16)) {
last_ms10x_1sd16 = cur_ms10x_1sd16;
timer_cnt++;
timer_cnt &= 15;
if (timer_cnt == 15) { // every second, 1Hz
btn1_tflg = 1;
pwr_tflg = 1;
cfg_tflg = 1;
seconds++;
pwr_sflg = 1;
}

timer_2hz = ((timer_cnt & 7) == 7);
timer_4hz = ((timer_cnt & 3) == 3);
timer_8hz = ((timer_cnt & 1) == 1);
timer_16hz = 1;
} else {
timer_2hz = 0;
timer_4hz = 0;
timer_8hz = 0;
timer_16hz = 0;
}
}

void RF_Delay_Init() {
static uint8_t SA_saved = 0;

#ifdef _RF_CALIB
return;
#endif

if (tramp_lock)
return;

if (SA_saved == 0) {
if (seconds >= WAIT_SA_CONFIG) {
I2C_Write8(ADDR_EEPROM, EEP_ADDR_SA_LOCK, SA_lock);
SA_saved = 1;
#ifdef _DEBUG_MODE
debugf("\r\nSave SA_lock(%x) to EEPROM", (uint16_t)SA_lock);
#endif
}
}

// init_rf
if (seconds < WAIT_SA_CONFIG) { // wait for SA config vtx
if (seconds < WAIT_SA_LOCK)
return;
else if (SA_lock)
return;
else
seconds = WAIT_SA_CONFIG;
} else if (rf_delay_init_done)
return;
else if (dm6300_init_done)
return;
else
rf_delay_init_done = 1;

if (last_SA_lock) {
#ifdef _DEBUG_MODE
debugf("\r\nRF_Delay_Init: SA");
#endif
pwr_lmt_sec = PWR_LMT_SEC;
if (SA_lock) {
if (pwr_init == POWER_MAX + 2) { // 0mW
RF_POWER = POWER_MAX + 2;
cur_pwr = POWER_MAX + 2;
} else if (PIT_MODE) {
Init_6300RF(ch_init, POWER_MAX + 1);
#ifdef _DEBUG_MODE
debugf("\r\n ch%x, pwr%x", (uint16_t)ch_init, (uint16_t)cur_pwr);
#endif
} else {
Init_6300RF(ch_init, pwr_init);
#ifdef _DEBUG_MODE
debugf("\r\n ch%x, pwr%x", (uint16_t)ch_init, (uint16_t)cur_pwr);
#endif
}
DM6300_AUXADC_Calib();
}
} else if (!mspVtxLock) {
#ifdef _DEBUG_MODE
debugf("\r\nRF_Delay_Init: None");
#endif
if (TEAM_RACE == 0x01)
vtx_paralized();
#if (0)
if (PIT_MODE == PIT_0MW) {
pwr_lmt_done = 1;
RF_POWER = POWER_MAX + 2;
cur_pwr = POWER_MAX + 2;
vtx_pit = PIT_0MW;
} else if (PIT_MODE == PIT_P1MW) {
#else
if (PIT_MODE != PIT_OFF) {
#endif
Init_6300RF(RF_FREQ, POWER_MAX + 1);
vtx_pit = PIT_P1MW;
} else {
WriteReg(0, 0x8F, 0x00);
WriteReg(0, 0x8F, 0x01);
DM6300_Init(RF_FREQ, RF_BW);
DM6300_SetChannel(RF_FREQ);
DM6300_SetPower(0, RF_FREQ, 0);
cur_pwr = RF_POWER;
WriteReg(0, 0x8F, 0x11);
rf_delay_init_done = 1;
}
DM6300_AUXADC_Calib();
}
}

0 comments on commit e614f63

Please sign in to comment.