0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-06-20 15:08:37 +03:00

Fix serial comms mishap, fix dual-watch not starting at power-on

This commit is contained in:
OneOfEleven
2023-10-11 16:02:45 +01:00
parent 5942582da4
commit 46a082ef05
23 changed files with 612 additions and 506 deletions

249
audio.c
View File

@ -44,7 +44,7 @@
0x5A, 0x4B, 0x4B, 0x46, 0x46, 0x69, 0x64, 0x6E,
0x5A, 0x64,
};
static const uint8_t VoiceClipLengthEnglish[76] =
{
0x50, 0x32, 0x2D, 0x2D, 0x2D, 0x37, 0x37, 0x37,
@ -58,14 +58,14 @@
0x55, 0x4B, 0x4B, 0x32, 0x32, 0x32, 0x32, 0x37,
0x41, 0x32, 0x3C, 0x37,
};
voice_id_t g_voice_id[8];
uint8_t g_voice_read_index;
uint8_t g_voice_write_index;
volatile uint16_t g_count_down_to_play_next_voice_10ms;
volatile bool g_flag_play_queued_voice;
voice_id_t g_another_voice_id = VOICE_ID_INVALID;
#endif
beep_type_t g_beep_to_play = BEEP_NONE;
@ -88,7 +88,7 @@ void AUDIO_PlayBeep(beep_type_t Beep)
if (g_screen_to_display == DISPLAY_AIRCOPY)
return;
#endif
if (g_current_function == FUNCTION_RECEIVE)
return;
@ -103,10 +103,12 @@ void AUDIO_PlayBeep(beep_type_t Beep)
BK4819_RX_TurnOn();
#ifdef ENABLE_FMRADIO
if (g_fm_radio_mode)
BK1080_Mute(true);
#ifdef MUTE_AUDIO_FOR_VOICE
if (g_fm_radio_mode)
BK1080_Mute(true);
#endif
#endif
SYSTEM_DelayMs(20);
switch (Beep)
@ -133,7 +135,7 @@ void AUDIO_PlayBeep(beep_type_t Beep)
ToneFrequency = 880;
break;
}
BK4819_PlayTone(ToneFrequency, true);
SYSTEM_DelayMs(2);
@ -152,7 +154,7 @@ void AUDIO_PlayBeep(beep_type_t Beep)
SYSTEM_DelayMs(60);
BK4819_EnterTxMute();
SYSTEM_DelayMs(20);
case BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL:
case BEEP_500HZ_60MS_DOUBLE_BEEP:
BK4819_ExitTxMute();
@ -170,7 +172,7 @@ void AUDIO_PlayBeep(beep_type_t Beep)
BK4819_ExitTxMute();
Duration = 40;
break;
case BEEP_880HZ_200MS:
BK4819_ExitTxMute();
Duration = 200;
@ -208,7 +210,7 @@ void AUDIO_PlayBeep(beep_type_t Beep)
if (g_fm_radio_mode)
BK1080_Mute(false);
#endif
if (g_current_function == FUNCTION_POWER_SAVE && g_rx_idle_mode)
BK4819_Sleep();
}
@ -218,18 +220,20 @@ void AUDIO_PlayBeep(beep_type_t Beep)
void AUDIO_PlayVoice(uint8_t VoiceID)
{
unsigned int i;
if (g_eeprom.voice_prompt == VOICE_PROMPT_OFF)
return;
GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_VOICE_0);
SYSTEM_DelayMs(20);
GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_VOICE_0);
for (i = 0; i < 8; i++)
{
if ((VoiceID & 0x80U) == 0)
GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_VOICE_1);
else
GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_VOICE_1);
SYSTICK_DelayUs(1000);
GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_VOICE_0);
SYSTICK_DelayUs(1200);
@ -238,122 +242,123 @@ void AUDIO_PlayBeep(beep_type_t Beep)
SYSTICK_DelayUs(200);
}
}
void AUDIO_PlaySingleVoice(bool flag)
{
uint8_t VoiceID;
uint8_t Delay;
VoiceID = g_voice_id[0];
if (g_eeprom.voice_prompt != VOICE_PROMPT_OFF && g_voice_write_index > 0)
{
if (g_eeprom.voice_prompt == VOICE_PROMPT_CHINESE)
{ // Chinese
if (VoiceID >= ARRAY_SIZE(VoiceClipLengthChinese))
goto Bailout;
Delay = VoiceClipLengthChinese[VoiceID];
VoiceID += VOICE_ID_CHI_BASE;
}
else
{ // English
if (VoiceID >= ARRAY_SIZE(VoiceClipLengthEnglish))
goto Bailout;
Delay = VoiceClipLengthEnglish[VoiceID];
VoiceID += VOICE_ID_ENG_BASE;
}
if (g_current_function == FUNCTION_RECEIVE ||
g_current_function == FUNCTION_MONITOR ||
g_current_function == FUNCTION_INCOMING) // 1of11
uint8_t VoiceID = g_voice_id[0];
if (g_eeprom.voice_prompt == VOICE_PROMPT_OFF || g_voice_write_index == 0)
goto Bailout;
if (g_eeprom.voice_prompt == VOICE_PROMPT_CHINESE)
{ // Chinese
if (VoiceID >= ARRAY_SIZE(VoiceClipLengthChinese))
goto Bailout;
Delay = VoiceClipLengthChinese[VoiceID];
VoiceID += VOICE_ID_CHI_BASE;
}
else
{ // English
if (VoiceID >= ARRAY_SIZE(VoiceClipLengthEnglish))
goto Bailout;
Delay = VoiceClipLengthEnglish[VoiceID];
VoiceID += VOICE_ID_ENG_BASE;
}
#ifdef MUTE_AUDIO_FOR_VOICE
if (g_current_function == FUNCTION_RECEIVE || g_current_function == FUNCTION_MONITOR)
BK4819_SetAF(BK4819_AF_MUTE);
#ifdef ENABLE_FMRADIO
#endif
#ifdef ENABLE_FMRADIO
#ifdef MUTE_AUDIO_FOR_VOICE
if (g_fm_radio_mode)
BK1080_Mute(true);
#endif
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
#endif
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
#ifdef ENABLE_VOX
g_vox_resume_count_down = 2000;
#endif
SYSTEM_DelayMs(5);
AUDIO_PlayVoice(VoiceID);
if (g_voice_write_index == 1)
Delay += 3;
if (flag)
{
SYSTEM_DelayMs(Delay * 10);
if (g_current_function == FUNCTION_RECEIVE || g_current_function == FUNCTION_MONITOR)
BK4819_SetAF(g_rx_vfo->am_mode ? BK4819_AF_AM : BK4819_AF_FM);
#ifdef ENABLE_FMRADIO
if (g_fm_radio_mode)
BK1080_Mute(false);
#endif
if (!g_enable_speaker)
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
g_voice_write_index = 0;
g_voice_read_index = 0;
#ifdef ENABLE_VOX
g_vox_resume_count_down = 2000;
g_vox_resume_count_down = 80;
#endif
SYSTEM_DelayMs(5);
AUDIO_PlayVoice(VoiceID);
if (g_voice_write_index == 1)
Delay += 3;
if (flag)
{
SYSTEM_DelayMs(Delay * 10);
if (g_current_function == FUNCTION_RECEIVE ||
g_current_function == FUNCTION_MONITOR ||
g_current_function == FUNCTION_INCOMING) // 1of11
BK4819_SetAF(g_rx_vfo->am_mode ? BK4819_AF_AM : BK4819_AF_FM);
#ifdef ENABLE_FMRADIO
if (g_fm_radio_mode)
BK1080_Mute(false);
#endif
if (!g_enable_speaker)
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
g_voice_write_index = 0;
g_voice_read_index = 0;
#ifdef ENABLE_VOX
g_vox_resume_count_down = 80;
#endif
return;
}
g_voice_read_index = 1;
g_count_down_to_play_next_voice_10ms = Delay;
g_flag_play_queued_voice = false;
return;
}
g_voice_read_index = 1;
g_count_down_to_play_next_voice_10ms = Delay;
g_flag_play_queued_voice = false;
return;
Bailout:
g_voice_read_index = 0;
g_voice_write_index = 0;
}
void AUDIO_SetVoiceID(uint8_t Index, voice_id_t VoiceID)
{
if (Index >= ARRAY_SIZE(g_voice_id))
return;
if (Index == 0)
if (g_eeprom.voice_prompt == VOICE_PROMPT_OFF || Index == 0)
{
g_voice_write_index = 0;
g_voice_read_index = 0;
}
g_voice_id[Index] = VoiceID;
g_voice_write_index++;
if (g_eeprom.voice_prompt != VOICE_PROMPT_OFF && Index < ARRAY_SIZE(g_voice_id))
{
g_voice_id[Index] = VoiceID;
g_voice_write_index++;
}
}
uint8_t AUDIO_SetDigitVoice(uint8_t Index, uint16_t Value)
{
uint16_t Remainder;
uint8_t Result;
uint8_t Count;
if (Index == 0)
if (g_eeprom.voice_prompt == VOICE_PROMPT_OFF || Index == 0)
{
g_voice_write_index = 0;
g_voice_read_index = 0;
}
if (g_eeprom.voice_prompt == VOICE_PROMPT_OFF)
return 0;
Count = 0;
Result = Value / 1000U;
Remainder = Value % 1000U;
@ -373,21 +378,26 @@ void AUDIO_PlayBeep(beep_type_t Beep)
g_voice_id[g_voice_write_index++] = (voice_id_t)Result;
Count++;
Remainder -= Result * 10U;
Skip:
g_voice_id[g_voice_write_index++] = (voice_id_t)Remainder;
return Count + 1U;
}
void AUDIO_PlayQueuedVoice(void)
{
uint8_t VoiceID;
uint8_t Delay;
bool Skip;
Skip = false;
bool Skip = false;
if (g_eeprom.voice_prompt == VOICE_PROMPT_OFF)
{
g_voice_write_index = 0;
g_voice_read_index = 0;
return;
}
if (g_voice_read_index != g_voice_write_index && g_eeprom.voice_prompt != VOICE_PROMPT_OFF)
{
VoiceID = g_voice_id[g_voice_read_index];
@ -411,44 +421,47 @@ void AUDIO_PlayBeep(beep_type_t Beep)
else
Skip = true;
}
g_voice_read_index++;
if (!Skip)
{
if (g_voice_read_index == g_voice_write_index)
Delay += 3;
AUDIO_PlayVoice(VoiceID);
g_count_down_to_play_next_voice_10ms = Delay;
g_flag_play_queued_voice = false;
#ifdef ENABLE_VOX
g_vox_resume_count_down = 2000;
#endif
return;
}
}
if (g_current_function == FUNCTION_RECEIVE ||
g_current_function == FUNCTION_MONITOR ||
g_current_function == FUNCTION_INCOMING) // 1of11
// ***********************
// unmute the radios audio
if (g_current_function == FUNCTION_RECEIVE || g_current_function == FUNCTION_MONITOR)
BK4819_SetAF(g_rx_vfo->am_mode ? BK4819_AF_AM : BK4819_AF_FM);
#ifdef ENABLE_FMRADIO
if (g_fm_radio_mode)
BK1080_Mute(false);
#endif
if (!g_enable_speaker)
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
// **********************
#ifdef ENABLE_VOX
g_vox_resume_count_down = 80;
#endif
g_voice_write_index = 0;
g_voice_read_index = 0;
}