0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-06-18 22:29:50 +03:00

Initial commit

This commit is contained in:
OneOfEleven
2023-09-09 08:03:56 +01:00
parent 92305117f1
commit 54441e27d9
3388 changed files with 582553 additions and 0 deletions

94
helper/battery.c Normal file
View File

@ -0,0 +1,94 @@
/* 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.
*/
#include "battery.h"
#include "driver/backlight.h"
#include "misc.h"
#include "ui/battery.h"
#include "ui/menu.h"
#include "ui/ui.h"
uint16_t gBatteryCalibration[6];
uint16_t gBatteryCurrentVoltage;
uint16_t gBatteryCurrent;
uint16_t gBatteryVoltages[4];
uint16_t gBatteryVoltageAverage;
uint8_t gBatteryDisplayLevel;
bool gChargingWithTypeC;
bool gLowBattery;
bool gLowBatteryBlink;
volatile uint16_t gBatterySave;
uint16_t gBatteryCheckCounter;
void BATTERY_GetReadings(bool bDisplayBatteryLevel)
{
uint8_t PreviousBatteryLevel = gBatteryDisplayLevel;
uint16_t Voltage = (gBatteryVoltages[0] + gBatteryVoltages[1] + gBatteryVoltages[2] + gBatteryVoltages[3]) / 4;
if (gBatteryCalibration[5] < Voltage)
gBatteryDisplayLevel = 6;
else
if (gBatteryCalibration[4] < Voltage)
gBatteryDisplayLevel = 5;
else
if (gBatteryCalibration[3] < Voltage)
gBatteryDisplayLevel = 4;
else
if (gBatteryCalibration[2] < Voltage)
gBatteryDisplayLevel = 3;
else
if (gBatteryCalibration[1] < Voltage)
gBatteryDisplayLevel = 2;
else
if (gBatteryCalibration[0] < Voltage)
gBatteryDisplayLevel = 1;
else
gBatteryDisplayLevel = 0;
gBatteryVoltageAverage = (Voltage * 760) / gBatteryCalibration[3];
if ((gScreenToDisplay == DISPLAY_MENU) && gMenuCursor == MENU_VOL)
gUpdateDisplay = true;
if (gBatteryCurrent < 501)
{
if (gChargingWithTypeC)
gUpdateStatus = true;
gChargingWithTypeC = 0;
}
else
{
if (!gChargingWithTypeC)
{
gUpdateStatus = true;
BACKLIGHT_TurnOn();
}
gChargingWithTypeC = 1;
}
if (PreviousBatteryLevel != gBatteryDisplayLevel)
{
if (gBatteryDisplayLevel < 2)
gLowBattery = true;
else
{
gLowBattery = false;
if (bDisplayBatteryLevel)
UI_DisplayBattery(gBatteryDisplayLevel);
}
gLowBatteryCountdown = 0;
}
}

42
helper/battery.h Normal file
View File

@ -0,0 +1,42 @@
/* 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.
*/
#ifndef BATTERY_H
#define BATTERY_H
#include <stdbool.h>
#include <stdint.h>
extern uint16_t gBatteryCalibration[6];
extern uint16_t gBatteryCurrentVoltage;
extern uint16_t gBatteryCurrent;
extern uint16_t gBatteryVoltages[4];
extern uint16_t gBatteryVoltageAverage;
extern uint8_t gBatteryDisplayLevel;
extern bool gChargingWithTypeC;
extern bool gLowBattery;
extern bool gLowBatteryBlink;
extern volatile uint16_t gBatterySave;
extern uint16_t gBatteryCheckCounter;
void BATTERY_GetReadings(bool bDisplayBatteryLevel);
#endif

115
helper/boot.c Normal file
View File

@ -0,0 +1,115 @@
/* 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.
*/
#ifndef DISABLE_AIRCOPY
#include "app/aircopy.h"
#endif
#include "bsp/dp32g030/gpio.h"
#include "driver/bk4819.h"
#include "driver/keyboard.h"
#include "driver/gpio.h"
#include "driver/system.h"
#include "helper/boot.h"
#include "misc.h"
#include "radio.h"
#include "settings.h"
#include "ui/menu.h"
#include "ui/ui.h"
BOOT_Mode_t BOOT_GetMode(void)
{
KEY_Code_t Keys[2];
unsigned int i;
for (i = 0; i < 2; i++)
{
if (GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_PTT))
return BOOT_MODE_NORMAL;
Keys[i] = KEYBOARD_Poll();
SYSTEM_DelayMs(20);
}
if (Keys[0] == Keys[1])
{
gKeyReading0 = Keys[0];
gKeyReading1 = Keys[0];
gDebounceCounter = 2;
if (Keys[0] == KEY_SIDE1)
return BOOT_MODE_F_LOCK;
#ifndef DISABLE_AIRCOPY
if (Keys[0] == KEY_SIDE2)
return BOOT_MODE_AIRCOPY;
#endif
}
return BOOT_MODE_NORMAL;
}
void BOOT_ProcessMode(BOOT_Mode_t Mode)
{
if (Mode == BOOT_MODE_F_LOCK)
{
gMenuCursor = MENU_350TX;
gSubMenuSelection = gSetting_350TX;
GUI_SelectNextDisplay(DISPLAY_MENU);
gMenuListCount = 57;
#ifdef DISABLE_VOICE
gMenuListCount--;
#endif
#ifdef DISABLE_NOAA
gMenuListCount--;
#endif
gF_LOCK = true;
}
#ifndef DISABLE_AIRCOPY
else
if (Mode == BOOT_MODE_AIRCOPY)
{
gEeprom.DUAL_WATCH = DUAL_WATCH_OFF;
gEeprom.BATTERY_SAVE = 0;
gEeprom.VOX_SWITCH = false;
gEeprom.CROSS_BAND_RX_TX = CROSS_BAND_OFF;
gEeprom.AUTO_KEYPAD_LOCK = false;
gEeprom.KEY_1_SHORT_PRESS_ACTION = 0;
gEeprom.KEY_1_LONG_PRESS_ACTION = 0;
gEeprom.KEY_2_SHORT_PRESS_ACTION = 0;
gEeprom.KEY_2_LONG_PRESS_ACTION = 0;
RADIO_InitInfo(gRxVfo, 205, 5, 41002500);
gRxVfo->CHANNEL_BANDWIDTH = BANDWIDTH_NARROW;
gRxVfo->OUTPUT_POWER = 0;
RADIO_ConfigureSquelchAndOutputPower(gRxVfo);
gCurrentVfo = gRxVfo;
RADIO_SetupRegisters(true);
BK4819_SetupAircopy();
BK4819_ResetFSK();
gAircopyState = AIRCOPY_READY;
GUI_SelectNextDisplay(DISPLAY_AIRCOPY);
}
#endif
else
GUI_SelectNextDisplay(DISPLAY_MAIN);
}

38
helper/boot.h Normal file
View File

@ -0,0 +1,38 @@
/* 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.
*/
#ifndef HELPER_BOOT_H
#define HELPER_BOOT_H
#include <stdint.h>
#include "driver/keyboard.h"
enum BOOT_Mode_t
{
BOOT_MODE_NORMAL = 0,
BOOT_MODE_F_LOCK,
#ifndef DISABLE_AIRCOPY
BOOT_MODE_AIRCOPY
#endif
};
typedef enum BOOT_Mode_t BOOT_Mode_t;
BOOT_Mode_t BOOT_GetMode(void);
void BOOT_ProcessMode(BOOT_Mode_t Mode);
#endif