2023-08-09 23:00:44 +08:00
|
|
|
/* Copyright 2023 Dual Tachyon
|
|
|
|
* https://github.com/DualTachyon
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2023-08-15 00:30:30 +08:00
|
|
|
#include <string.h>
|
2023-08-28 07:40:07 +08:00
|
|
|
#include "app/app.h"
|
2023-08-31 21:22:08 +08:00
|
|
|
#include "app/dtmf.h"
|
2023-08-14 06:27:35 +08:00
|
|
|
#include "audio.h"
|
2023-08-09 23:00:44 +08:00
|
|
|
#include "bsp/dp32g030/gpio.h"
|
|
|
|
#include "bsp/dp32g030/syscon.h"
|
|
|
|
#include "board.h"
|
2023-08-13 00:40:05 +08:00
|
|
|
#include "driver/backlight.h"
|
2023-08-10 18:57:44 +08:00
|
|
|
#include "driver/bk4819.h"
|
2023-08-09 23:00:44 +08:00
|
|
|
#include "driver/gpio.h"
|
2023-08-10 18:35:02 +08:00
|
|
|
#include "driver/system.h"
|
2023-08-09 23:00:44 +08:00
|
|
|
#include "driver/systick.h"
|
2023-09-14 04:26:18 +08:00
|
|
|
#if defined(ENABLE_UART)
|
2023-08-09 23:00:44 +08:00
|
|
|
#include "driver/uart.h"
|
2023-09-14 04:26:18 +08:00
|
|
|
#endif
|
2023-08-29 03:13:33 +08:00
|
|
|
#include "helper/battery.h"
|
2023-08-29 03:45:33 +08:00
|
|
|
#include "helper/boot.h"
|
2023-08-11 00:51:57 +08:00
|
|
|
#include "misc.h"
|
2023-08-11 18:51:17 +08:00
|
|
|
#include "radio.h"
|
2023-08-14 06:27:35 +08:00
|
|
|
#include "settings.h"
|
2023-08-29 03:13:33 +08:00
|
|
|
#include "ui/lock.h"
|
|
|
|
#include "ui/welcome.h"
|
2023-08-09 23:00:44 +08:00
|
|
|
|
2023-09-14 04:26:18 +08:00
|
|
|
#if defined(ENABLE_UART)
|
2023-09-09 19:40:55 +08:00
|
|
|
static const char Version[] = "UV-K5 Firmware, Open Edition, OEFW-"GIT_HASH"\r\n";
|
2023-09-14 04:26:18 +08:00
|
|
|
#endif
|
2023-08-09 23:00:44 +08:00
|
|
|
|
2023-08-14 19:12:46 +08:00
|
|
|
void _putchar(char c)
|
|
|
|
{
|
2023-09-14 04:26:18 +08:00
|
|
|
#if defined(ENABLE_UART)
|
2023-08-14 19:12:46 +08:00
|
|
|
UART_Send((uint8_t *)&c, 1);
|
2023-09-14 04:26:18 +08:00
|
|
|
#endif
|
2023-08-14 19:12:46 +08:00
|
|
|
}
|
|
|
|
|
2023-08-09 23:00:44 +08:00
|
|
|
void Main(void)
|
|
|
|
{
|
2023-08-14 06:08:01 +08:00
|
|
|
uint8_t i;
|
|
|
|
|
2023-08-09 23:00:44 +08:00
|
|
|
// Enable clock gating of blocks we need.
|
|
|
|
SYSCON_DEV_CLK_GATE = 0
|
2023-08-10 18:05:46 +08:00
|
|
|
| SYSCON_DEV_CLK_GATE_GPIOA_BITS_ENABLE
|
|
|
|
| SYSCON_DEV_CLK_GATE_GPIOB_BITS_ENABLE
|
|
|
|
| SYSCON_DEV_CLK_GATE_GPIOC_BITS_ENABLE
|
|
|
|
| SYSCON_DEV_CLK_GATE_UART1_BITS_ENABLE
|
|
|
|
| SYSCON_DEV_CLK_GATE_SPI0_BITS_ENABLE
|
|
|
|
| SYSCON_DEV_CLK_GATE_SARADC_BITS_ENABLE
|
|
|
|
| SYSCON_DEV_CLK_GATE_CRC_BITS_ENABLE
|
|
|
|
| SYSCON_DEV_CLK_GATE_AES_BITS_ENABLE
|
2023-08-09 23:00:44 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
SYSTICK_Init();
|
|
|
|
BOARD_Init();
|
|
|
|
|
2023-09-14 04:26:18 +08:00
|
|
|
#if defined(ENABLE_UART)
|
2023-08-09 23:00:44 +08:00
|
|
|
UART_Init();
|
|
|
|
UART_Send(Version, sizeof(Version));
|
2023-09-14 04:26:18 +08:00
|
|
|
#endif
|
2023-08-09 23:00:44 +08:00
|
|
|
|
2023-08-10 18:57:44 +08:00
|
|
|
// Not implementing authentic device checks
|
|
|
|
|
2023-08-15 00:30:30 +08:00
|
|
|
memset(&gEeprom, 0, sizeof(gEeprom));
|
|
|
|
memset(gDTMF_String, '-', sizeof(gDTMF_String));
|
|
|
|
gDTMF_String[14] = 0;
|
2023-08-10 18:57:44 +08:00
|
|
|
|
|
|
|
BK4819_Init();
|
2023-08-26 18:19:20 +08:00
|
|
|
BOARD_ADC_GetBatteryInfo(&gBatteryCurrentVoltage, &gBatteryCurrent);
|
2023-08-11 00:51:57 +08:00
|
|
|
BOARD_EEPROM_Init();
|
|
|
|
BOARD_EEPROM_LoadMoreSettings();
|
2023-08-10 18:57:44 +08:00
|
|
|
|
2023-08-11 18:51:17 +08:00
|
|
|
RADIO_ConfigureChannel(0, 2);
|
|
|
|
RADIO_ConfigureChannel(1, 2);
|
2023-09-03 22:56:49 +08:00
|
|
|
RADIO_SelectVfos();
|
2023-08-11 22:41:23 +08:00
|
|
|
RADIO_SetupRegisters(true);
|
2023-08-11 18:51:17 +08:00
|
|
|
|
2023-08-14 06:08:01 +08:00
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
BOARD_ADC_GetBatteryInfo(&gBatteryVoltages[i], &gBatteryCurrent);
|
|
|
|
}
|
|
|
|
|
|
|
|
BATTERY_GetReadings(false);
|
|
|
|
if (!gChargingWithTypeC && !gBatteryDisplayLevel) {
|
2023-08-15 00:30:30 +08:00
|
|
|
FUNCTION_Select(FUNCTION_POWER_SAVE);
|
2023-08-14 06:08:01 +08:00
|
|
|
GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT);
|
2023-08-31 01:06:08 +08:00
|
|
|
gReducedService = true;
|
2023-08-14 06:08:01 +08:00
|
|
|
} else {
|
2023-08-29 03:45:33 +08:00
|
|
|
BOOT_Mode_t BootMode;
|
2023-08-14 06:27:35 +08:00
|
|
|
uint8_t Channel;
|
|
|
|
|
2023-08-29 03:13:33 +08:00
|
|
|
UI_DisplayWelcome();
|
2023-08-14 06:08:01 +08:00
|
|
|
BACKLIGHT_TurnOn();
|
|
|
|
SYSTEM_DelayMs(1000);
|
2023-09-14 18:30:08 +08:00
|
|
|
gMenuListCount = 50;
|
|
|
|
#if defined(ENABLE_NOAA)
|
|
|
|
gMenuListCount++;
|
|
|
|
#endif
|
2023-08-14 06:27:35 +08:00
|
|
|
|
2023-08-29 03:45:33 +08:00
|
|
|
BootMode = BOOT_GetMode();
|
2023-08-14 06:27:35 +08:00
|
|
|
if (gEeprom.POWER_ON_PASSWORD < 1000000) {
|
2023-09-01 06:27:02 +08:00
|
|
|
bIsInLockScreen = true;
|
2023-08-29 03:13:33 +08:00
|
|
|
UI_DisplayLock();
|
2023-09-01 06:27:02 +08:00
|
|
|
bIsInLockScreen = false;
|
2023-08-14 06:27:35 +08:00
|
|
|
}
|
|
|
|
|
2023-08-29 03:45:33 +08:00
|
|
|
BOOT_ProcessMode(BootMode);
|
2023-08-14 06:27:35 +08:00
|
|
|
|
2023-08-27 00:27:25 +08:00
|
|
|
GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_VOICE_0);
|
2023-08-30 07:19:12 +08:00
|
|
|
gUpdateStatus = true;
|
2023-08-15 18:02:03 +08:00
|
|
|
AUDIO_SetVoiceID(0, VOICE_ID_WELCOME);
|
2023-08-29 10:24:03 +08:00
|
|
|
Channel = gEeprom.ScreenChannel[gEeprom.TX_CHANNEL];
|
|
|
|
if (IS_MR_CHANNEL(Channel)) {
|
2023-08-15 18:02:03 +08:00
|
|
|
AUDIO_SetVoiceID(1, VOICE_ID_CHANNEL_MODE);
|
2023-08-29 10:24:03 +08:00
|
|
|
AUDIO_SetDigitVoice(2, Channel + 1);
|
|
|
|
} else if (IS_FREQ_CHANNEL(Channel)) {
|
2023-08-15 18:02:03 +08:00
|
|
|
AUDIO_SetVoiceID(1, VOICE_ID_FREQUENCY_MODE);
|
2023-08-14 06:27:35 +08:00
|
|
|
}
|
|
|
|
AUDIO_PlaySingleVoice(0);
|
2023-09-14 18:30:08 +08:00
|
|
|
#if defined(ENABLE_NOAA)
|
2023-08-14 07:39:49 +08:00
|
|
|
RADIO_ConfigureNOAA();
|
2023-09-14 18:30:08 +08:00
|
|
|
#endif
|
2023-08-14 06:08:01 +08:00
|
|
|
}
|
|
|
|
|
2023-08-26 09:04:16 +08:00
|
|
|
while (1) {
|
|
|
|
APP_Update();
|
|
|
|
if (gNextTimeslice) {
|
|
|
|
APP_TimeSlice10ms();
|
|
|
|
gNextTimeslice = false;
|
|
|
|
}
|
|
|
|
if (gNextTimeslice500ms) {
|
|
|
|
APP_TimeSlice500ms();
|
|
|
|
gNextTimeslice500ms = false;
|
|
|
|
}
|
|
|
|
}
|
2023-08-09 23:00:44 +08:00
|
|
|
}
|
|
|
|
|