Skip to content

Commit

Permalink
Merge pull request #217 from ligenxxxx/osd-freeze-after-power-on
Browse files Browse the repository at this point in the history
Osd freeze after power on
  • Loading branch information
ligenxxxx authored Aug 24, 2024
2 parents 96d2b6c + db0f045 commit e604d12
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 14 deletions.
19 changes: 6 additions & 13 deletions src/hardware.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ void Setting_Save() {
err |= I2C_Write8_Wait(10, ADDR_EEPROM, EEP_ADDR_LPMODE, LP_MODE);
err |= I2C_Write8_Wait(10, ADDR_EEPROM, EEP_ADDR_PITMODE, PIT_MODE);
err |= I2C_Write8_Wait(10, ADDR_EEPROM, EEP_ADDR_25MW, OFFSET_25MW);
err |= I2C_Write8_Wait(10, ADDR_EEPROM, EEP_ADDR_BAUDRATE, BAUDRATE);
err |= I2C_Write8_Wait(10, ADDR_EEPROM, EEP_ADDR_TEAM_RACE, TEAM_RACE);
err |= I2C_Write8_Wait(10, ADDR_EEPROM, EEP_ADDR_SHORTCUT, SHORTCUT);
#ifdef _DEBUG_MODE
Expand All @@ -365,7 +364,6 @@ void Setting_Save() {
debugf(" LP_MODE=%d\r\n", (uint16_t)LP_MODE);
debugf(" PIT_MODE=%d\r\n", (uint16_t)PIT_MODE);
debugf(" OFFSET_25MW=%d\r\n", (uint16_t)OFFSET_25MW);
debugf(" BAUDRATE=%d\r\n", (uint16_t)BAUDRATE);
debugf(" TEAM_RACE=%d\r\n", (uint16_t)TEAM_RACE);
debugf(" SHORTCUT=%d\r\n", (uint16_t)SHORTCUT);
#endif
Expand All @@ -377,7 +375,6 @@ void CFG_Back() {
LP_MODE = (LP_MODE > 2) ? 0 : LP_MODE;
PIT_MODE = (PIT_MODE > PIT_0MW) ? PIT_OFF : PIT_MODE;
OFFSET_25MW = (OFFSET_25MW > 20) ? 0 : OFFSET_25MW;
BAUDRATE = (BAUDRATE > 1) ? 0 : BAUDRATE;
TEAM_RACE = (TEAM_RACE > 2) ? 0 : TEAM_RACE;
SHORTCUT = (SHORTCUT > 1) ? 0 : SHORTCUT;
}
Expand Down Expand Up @@ -470,12 +467,6 @@ void GetVtxParameter() {
OFFSET_25MW = I2C_Read8(ADDR_EEPROM, EEP_ADDR_25MW);
TEAM_RACE = I2C_Read8(ADDR_EEPROM, EEP_ADDR_TEAM_RACE);
SHORTCUT = I2C_Read8(ADDR_EEPROM, EEP_ADDR_SHORTCUT);
#ifdef USE_TRAMP
// tramp protocol need 115200 bps.
BAUDRATE = 0;
#else
BAUDRATE = I2C_Read8(ADDR_EEPROM, EEP_ADDR_BAUDRATE);
#endif
CFG_Back();

#ifdef _DEBUG_MODE
Expand Down Expand Up @@ -567,8 +558,6 @@ void Init_HW() {
GetVtxParameter();
Get_EEP_LifeTime();
camera_init();

uart_set_baudrate(BAUDRATE);
//--------- dm6300 --------------------
// move to RF_Delay_Init()
#endif
Expand Down Expand Up @@ -1583,10 +1572,14 @@ void uart_baudrate_detect(void) {
if (!msp_tx_en) {
if (seconds - msp_lst_rcv_sec > 2) {
msp_lst_rcv_sec = seconds;

BAUDRATE++;
CFG_Back();
if (BAUDRATE > 1)
BAUDRATE = 0;

uart_set_baudrate(BAUDRATE);
Setting_Save();

I2C_Write8_Wait(10, ADDR_EEPROM, EEP_ADDR_BAUDRATE, BAUDRATE);
}
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/isr.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void CPU_init(void) {
TCON = 0x50; // [6] enable timer1
// [4] enable timer0

#if (0) // IE should be set after uart_init()
IE = 0xD2; // [7] enable global interupts 1
// [6] enable uart1 interupt 1
// [5] enable timer2 interupt 0
Expand All @@ -61,5 +62,6 @@ void CPU_init(void) {
// [2] enable INT1 interupt 0
// [1] enable timer0 interupt 0
// [0] enable INT0 interupt 0
#endif
IP = 0x10; // UART0=higher priority, Timer 0 = low
}
13 changes: 12 additions & 1 deletion src/mcu.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,18 @@ void main(void) {
if (I2C_EN == 0)
I2C_EN = 1;

// init
uart_init();

// IE should be set after uart_init()
IE = 0xD2; // [7] enable global interupts 1
// [6] enable uart1 interupt 1
// [5] enable timer2 interupt 0
// [4] enable uart0 interupt 1
// [3] enable timer1 interupt 0
// [2] enable INT1 interupt 0
// [1] enable timer0 interupt 0
// [0] enable INT0 interupt 0

check_eeprom();
version_info();
Init_HW(); // init
Expand Down
13 changes: 13 additions & 0 deletions src/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ void uart_set_baudrate(uint8_t baudIndex) {
#endif
}

void uart_init() {
#ifdef USE_TRAMP
// tramp protocol need 115200 bps.
BAUDRATE = 0;
#else
BAUDRATE = I2C_Read8(ADDR_EEPROM, EEP_ADDR_BAUDRATE);
#endif
if (BAUDRATE > 1)
BAUDRATE = 0;

uart_set_baudrate(BAUDRATE);
}

uint8_t RS_ready(void) {
if (RS_in == RS_out)
return 0;
Expand Down
1 change: 1 addition & 0 deletions src/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ uint8_t RS_rx1_len(void);
*/

void uart_set_baudrate(uint8_t baudIndex);
void uart_init();

void RS_tx1(uint8_t c);
uint8_t RS_rx1(void);
Expand Down

0 comments on commit e604d12

Please sign in to comment.