kamilsss655/board.c

885 lines
24 KiB
C
Raw Normal View History

2023-09-09 07:03:56 +00: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.
*/
#include <string.h>
#include "app/dtmf.h"
2023-09-14 08:56:30 +00:00
#ifdef ENABLE_FMRADIO
#include "app/fm.h"
#endif
2023-09-09 07:03:56 +00:00
#include "board.h"
#include "bsp/dp32g030/gpio.h"
#include "bsp/dp32g030/portcon.h"
#include "bsp/dp32g030/saradc.h"
#include "bsp/dp32g030/syscon.h"
#include "driver/adc.h"
2023-10-28 13:35:27 +00:00
#include "driver/backlight.h"
2023-09-14 08:56:30 +00:00
#ifdef ENABLE_FMRADIO
#include "driver/bk1080.h"
#endif
2023-09-09 07:03:56 +00:00
#include "driver/bk4819.h"
#include "driver/crc.h"
#include "driver/eeprom.h"
#include "driver/flash.h"
#include "driver/gpio.h"
#include "driver/system.h"
#include "driver/st7565.h"
#include "frequencies.h"
#include "helper/battery.h"
#include "misc.h"
#include "settings.h"
2023-09-16 06:08:18 +00:00
#if defined(ENABLE_OVERLAY)
#include "sram-overlay.h"
#endif
#include "ui/menu.h"
2023-09-15 11:31:30 +00:00
2023-09-13 01:01:35 +00:00
static const uint32_t gDefaultFrequencyTable[] =
{
2023-09-15 11:31:30 +00:00
14500000, //
14550000, //
43300000, //
43320000, //
43350000 //
2023-09-13 01:01:35 +00:00
};
2023-09-16 06:08:18 +00:00
#if defined(ENABLE_OVERLAY)
void BOARD_FLASH_Init(void)
{
FLASH_Init(FLASH_READ_MODE_1_CYCLE);
FLASH_ConfigureTrimValues();
SYSTEM_ConfigureClocks();
overlay_FLASH_MainClock = 48000000;
overlay_FLASH_ClockMultiplier = 48;
FLASH_Init(FLASH_READ_MODE_2_CYCLE);
}
#endif
2023-09-09 07:03:56 +00:00
void BOARD_GPIO_Init(void)
{
GPIOA->DIR |= 0
2023-09-16 06:08:18 +00:00
// A7 = UART1 TX default as OUTPUT from bootloader!
// A8 = UART1 RX default as INPUT from bootloader!
// Key pad + I2C
2023-09-09 07:03:56 +00:00
| GPIO_DIR_10_BITS_OUTPUT
2023-09-16 06:08:18 +00:00
// Key pad + I2C
2023-09-09 07:03:56 +00:00
| GPIO_DIR_11_BITS_OUTPUT
2023-09-16 06:08:18 +00:00
// Key pad + Voice chip
2023-09-09 07:03:56 +00:00
| GPIO_DIR_12_BITS_OUTPUT
2023-09-16 06:08:18 +00:00
// Key pad + Voice chip
| GPIO_DIR_13_BITS_OUTPUT
;
2023-09-09 07:03:56 +00:00
GPIOA->DIR &= ~(0
2023-09-16 06:08:18 +00:00
// Key pad
| GPIO_DIR_3_MASK // INPUT
// Key pad
| GPIO_DIR_4_MASK // INPUT
// Key pad
| GPIO_DIR_5_MASK // INPUT
// Key pad
| GPIO_DIR_6_MASK // INPUT
);
2023-09-09 07:03:56 +00:00
GPIOB->DIR |= 0
2023-09-16 06:08:18 +00:00
// ST7565
2023-09-09 07:03:56 +00:00
| GPIO_DIR_9_BITS_OUTPUT
2023-09-16 06:08:18 +00:00
// ST7565 + SWD IO
2023-09-09 07:03:56 +00:00
| GPIO_DIR_11_BITS_OUTPUT
2023-09-16 06:08:18 +00:00
// B14 = SWD_CLK assumed INPUT by default
// BK1080
| GPIO_DIR_15_BITS_OUTPUT
;
2023-09-09 07:03:56 +00:00
GPIOC->DIR |= 0
2023-09-16 06:08:18 +00:00
// BK4819 SCN
2023-09-09 07:03:56 +00:00
| GPIO_DIR_0_BITS_OUTPUT
2023-09-16 06:08:18 +00:00
// BK4819 SCL
2023-09-09 07:03:56 +00:00
| GPIO_DIR_1_BITS_OUTPUT
2023-09-16 06:08:18 +00:00
// BK4819 SDA
2023-09-09 07:03:56 +00:00
| GPIO_DIR_2_BITS_OUTPUT
2023-09-16 06:08:18 +00:00
// Flash light
2023-09-09 07:03:56 +00:00
| GPIO_DIR_3_BITS_OUTPUT
2023-09-16 06:08:18 +00:00
// Speaker
| GPIO_DIR_4_BITS_OUTPUT
;
GPIOC->DIR &= ~(0
// PTT button
| GPIO_DIR_5_MASK // INPUT
);
#if defined(ENABLE_FMRADIO)
GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_BK1080);
#endif
2023-09-09 07:03:56 +00:00
}
void BOARD_PORTCON_Init(void)
{
// PORT A pin selection
2023-09-16 06:08:18 +00:00
PORTCON_PORTA_SEL0 &= ~(0
// Key pad
| PORTCON_PORTA_SEL0_A3_MASK
// Key pad
| PORTCON_PORTA_SEL0_A4_MASK
// Key pad
| PORTCON_PORTA_SEL0_A5_MASK
// Key pad
| PORTCON_PORTA_SEL0_A6_MASK
);
2023-09-09 07:03:56 +00:00
PORTCON_PORTA_SEL0 |= 0
2023-09-16 06:08:18 +00:00
// Key pad
| PORTCON_PORTA_SEL0_A3_BITS_GPIOA3
// Key pad
| PORTCON_PORTA_SEL0_A4_BITS_GPIOA4
// Key pad
| PORTCON_PORTA_SEL0_A5_BITS_GPIOA5
// Key pad
| PORTCON_PORTA_SEL0_A6_BITS_GPIOA6
// UART1 TX, wasn't cleared in previous step / relying on default value!
| PORTCON_PORTA_SEL0_A7_BITS_UART1_TX
;
PORTCON_PORTA_SEL1 &= ~(0
// Key pad + I2C
| PORTCON_PORTA_SEL1_A10_MASK
// Key pad + I2C
| PORTCON_PORTA_SEL1_A11_MASK
// Key pad + Voice chip
| PORTCON_PORTA_SEL1_A12_MASK
// Key pad + Voice chip
| PORTCON_PORTA_SEL1_A13_MASK
);
2023-09-09 07:03:56 +00:00
PORTCON_PORTA_SEL1 |= 0
2023-09-16 06:08:18 +00:00
// UART1 RX, wasn't cleared in previous step / relying on default value!
2023-09-09 07:03:56 +00:00
| PORTCON_PORTA_SEL1_A8_BITS_UART1_RX
2023-09-16 06:08:18 +00:00
// Battery voltage, wasn't cleared in previous step / relying on default value!
2023-09-09 07:03:56 +00:00
| PORTCON_PORTA_SEL1_A9_BITS_SARADC_CH4
2023-09-16 06:08:18 +00:00
// Key pad + I2C
| PORTCON_PORTA_SEL1_A10_BITS_GPIOA10
// Key pad + I2C
| PORTCON_PORTA_SEL1_A11_BITS_GPIOA11
// Key pad + Voice chip
| PORTCON_PORTA_SEL1_A12_BITS_GPIOA12
// Key pad + Voice chip
| PORTCON_PORTA_SEL1_A13_BITS_GPIOA13
// Battery Current, wasn't cleared in previous step / relying on default value!
2023-09-09 07:03:56 +00:00
| PORTCON_PORTA_SEL1_A14_BITS_SARADC_CH9
2023-09-16 06:08:18 +00:00
;
2023-09-09 07:03:56 +00:00
// PORT B pin selection
2023-09-16 06:08:18 +00:00
PORTCON_PORTB_SEL0 &= ~(0
// SPI0 SSN
| PORTCON_PORTB_SEL0_B7_MASK
);
2023-09-09 07:03:56 +00:00
PORTCON_PORTB_SEL0 |= 0
2023-09-16 06:08:18 +00:00
// SPI0 SSN
| PORTCON_PORTB_SEL0_B7_BITS_SPI0_SSN
;
PORTCON_PORTB_SEL1 &= ~(0
// ST7565
| PORTCON_PORTB_SEL1_B9_MASK
// ST7565 + SWD IO
| PORTCON_PORTB_SEL1_B11_MASK
// SWD CLK
| PORTCON_PORTB_SEL1_B14_MASK
// BK1080
| PORTCON_PORTB_SEL1_B15_MASK
);
2023-09-09 07:03:56 +00:00
PORTCON_PORTB_SEL1 |= 0
2023-09-16 06:08:18 +00:00
// SPI0 CLK, wasn't cleared in previous step / relying on default value!
2023-09-09 07:03:56 +00:00
| PORTCON_PORTB_SEL1_B8_BITS_SPI0_CLK
2023-09-16 06:08:18 +00:00
// ST7565
| PORTCON_PORTB_SEL1_B9_BITS_GPIOB9
// SPI0 MOSI, wasn't cleared in previous step / relying on default value!
2023-09-09 07:03:56 +00:00
| PORTCON_PORTB_SEL1_B10_BITS_SPI0_MOSI
2023-09-16 06:08:18 +00:00
#if defined(ENABLE_SWD)
// SWD IO
2023-09-09 07:03:56 +00:00
| PORTCON_PORTB_SEL1_B11_BITS_SWDIO
2023-09-16 06:08:18 +00:00
// SWD CLK
| PORTCON_PORTB_SEL1_B14_BITS_SWCLK
#else
// ST7565
| PORTCON_PORTB_SEL1_B11_BITS_GPIOB11
#endif
;
2023-09-09 07:03:56 +00:00
// PORT C pin selection
2023-09-16 06:08:18 +00:00
PORTCON_PORTC_SEL0 &= ~(0
// BK4819 SCN
| PORTCON_PORTC_SEL0_C0_MASK
// BK4819 SCL
| PORTCON_PORTC_SEL0_C1_MASK
// BK4819 SDA
| PORTCON_PORTC_SEL0_C2_MASK
// Flash light
| PORTCON_PORTC_SEL0_C3_MASK
// Speaker
| PORTCON_PORTC_SEL0_C4_MASK
// PTT button
| PORTCON_PORTC_SEL0_C5_MASK
);
2023-09-09 07:03:56 +00:00
// PORT A pin configuration
PORTCON_PORTA_IE |= 0
2023-09-16 06:08:18 +00:00
// Keypad
2023-09-09 07:03:56 +00:00
| PORTCON_PORTA_IE_A3_BITS_ENABLE
2023-09-16 06:08:18 +00:00
// Keypad
2023-09-09 07:03:56 +00:00
| PORTCON_PORTA_IE_A4_BITS_ENABLE
2023-09-16 06:08:18 +00:00
// Keypad
2023-09-09 07:03:56 +00:00
| PORTCON_PORTA_IE_A5_BITS_ENABLE
2023-09-16 06:08:18 +00:00
// Keypad
2023-09-09 07:03:56 +00:00
| PORTCON_PORTA_IE_A6_BITS_ENABLE
2023-09-16 06:08:18 +00:00
// A7 = UART1 TX disabled by default
// UART1 RX
| PORTCON_PORTA_IE_A8_BITS_ENABLE
;
2023-09-09 07:03:56 +00:00
PORTCON_PORTA_IE &= ~(0
2023-09-16 06:08:18 +00:00
// Keypad + I2C
2023-09-09 07:03:56 +00:00
| PORTCON_PORTA_IE_A10_MASK
2023-09-16 06:08:18 +00:00
// Keypad + I2C
2023-09-09 07:03:56 +00:00
| PORTCON_PORTA_IE_A11_MASK
2023-09-16 06:08:18 +00:00
// Keypad + Voice chip
2023-09-09 07:03:56 +00:00
| PORTCON_PORTA_IE_A12_MASK
2023-09-16 06:08:18 +00:00
// Keypad + Voice chip
| PORTCON_PORTA_IE_A13_MASK
);
2023-09-09 07:03:56 +00:00
PORTCON_PORTA_PU |= 0
2023-09-16 06:08:18 +00:00
// Keypad
2023-09-09 07:03:56 +00:00
| PORTCON_PORTA_PU_A3_BITS_ENABLE
2023-09-16 06:08:18 +00:00
// Keypad
2023-09-09 07:03:56 +00:00
| PORTCON_PORTA_PU_A4_BITS_ENABLE
2023-09-16 06:08:18 +00:00
// Keypad
2023-09-09 07:03:56 +00:00
| PORTCON_PORTA_PU_A5_BITS_ENABLE
2023-09-16 06:08:18 +00:00
// Keypad
| PORTCON_PORTA_PU_A6_BITS_ENABLE
;
2023-09-09 07:03:56 +00:00
PORTCON_PORTA_PU &= ~(0
2023-09-16 06:08:18 +00:00
// Keypad + I2C
2023-09-09 07:03:56 +00:00
| PORTCON_PORTA_PU_A10_MASK
2023-09-16 06:08:18 +00:00
// Keypad + I2C
2023-09-09 07:03:56 +00:00
| PORTCON_PORTA_PU_A11_MASK
2023-09-16 06:08:18 +00:00
// Keypad + Voice chip
2023-09-09 07:03:56 +00:00
| PORTCON_PORTA_PU_A12_MASK
2023-09-16 06:08:18 +00:00
// Keypad + Voice chip
| PORTCON_PORTA_PU_A13_MASK
);
2023-09-09 07:03:56 +00:00
PORTCON_PORTA_PD &= ~(0
2023-09-16 06:08:18 +00:00
// Keypad
2023-09-09 07:03:56 +00:00
| PORTCON_PORTA_PD_A3_MASK
2023-09-16 06:08:18 +00:00
// Keypad
2023-09-09 07:03:56 +00:00
| PORTCON_PORTA_PD_A4_MASK
2023-09-16 06:08:18 +00:00
// Keypad
2023-09-09 07:03:56 +00:00
| PORTCON_PORTA_PD_A5_MASK
2023-09-16 06:08:18 +00:00
// Keypad
2023-09-09 07:03:56 +00:00
| PORTCON_PORTA_PD_A6_MASK
2023-09-16 06:08:18 +00:00
// Keypad + I2C
2023-09-09 07:03:56 +00:00
| PORTCON_PORTA_PD_A10_MASK
2023-09-16 06:08:18 +00:00
// Keypad + I2C
2023-09-09 07:03:56 +00:00
| PORTCON_PORTA_PD_A11_MASK
2023-09-16 06:08:18 +00:00
// Keypad + Voice chip
2023-09-09 07:03:56 +00:00
| PORTCON_PORTA_PD_A12_MASK
2023-09-16 06:08:18 +00:00
// Keypad + Voice chip
| PORTCON_PORTA_PD_A13_MASK
);
2023-09-09 07:03:56 +00:00
PORTCON_PORTA_OD |= 0
2023-09-16 06:08:18 +00:00
// Keypad
2023-09-09 07:03:56 +00:00
| PORTCON_PORTA_OD_A3_BITS_ENABLE
2023-09-16 06:08:18 +00:00
// Keypad
2023-09-09 07:03:56 +00:00
| PORTCON_PORTA_OD_A4_BITS_ENABLE
2023-09-16 06:08:18 +00:00
// Keypad
2023-09-09 07:03:56 +00:00
| PORTCON_PORTA_OD_A5_BITS_ENABLE
2023-09-16 06:08:18 +00:00
// Keypad
| PORTCON_PORTA_OD_A6_BITS_ENABLE
;
2023-09-09 07:03:56 +00:00
PORTCON_PORTA_OD &= ~(0
2023-09-16 06:08:18 +00:00
// Keypad + I2C
2023-09-09 07:03:56 +00:00
| PORTCON_PORTA_OD_A10_MASK
2023-09-16 06:08:18 +00:00
// Keypad + I2C
2023-09-09 07:03:56 +00:00
| PORTCON_PORTA_OD_A11_MASK
2023-09-16 06:08:18 +00:00
// Keypad + Voice chip
2023-09-09 07:03:56 +00:00
| PORTCON_PORTA_OD_A12_MASK
2023-09-16 06:08:18 +00:00
// Keypad + Voice chip
| PORTCON_PORTA_OD_A13_MASK
);
2023-09-09 07:03:56 +00:00
// PORT B pin configuration
PORTCON_PORTB_IE |= 0
2023-09-16 06:08:18 +00:00
| PORTCON_PORTB_IE_B14_BITS_ENABLE
;
2023-09-09 07:03:56 +00:00
PORTCON_PORTB_IE &= ~(0
2023-09-16 06:08:18 +00:00
// Back light
2023-09-09 07:03:56 +00:00
| PORTCON_PORTB_IE_B6_MASK
2023-09-16 06:08:18 +00:00
// UART1
2023-09-09 07:03:56 +00:00
| PORTCON_PORTB_IE_B7_MASK
| PORTCON_PORTB_IE_B8_MASK
2023-09-16 06:08:18 +00:00
// ST7565
2023-09-09 07:03:56 +00:00
| PORTCON_PORTB_IE_B9_MASK
2023-09-16 06:08:18 +00:00
// SPI0 MOSI
2023-09-09 07:03:56 +00:00
| PORTCON_PORTB_IE_B10_MASK
2023-09-16 06:08:18 +00:00
#if !defined(ENABLE_SWD)
// ST7565
| PORTCON_PORTB_IE_B11_MASK
#endif
// BK1080
| PORTCON_PORTB_IE_B15_MASK
);
2023-09-09 07:03:56 +00:00
PORTCON_PORTB_PU &= ~(0
2023-09-16 06:08:18 +00:00
// Back light
2023-09-09 07:03:56 +00:00
| PORTCON_PORTB_PU_B6_MASK
2023-09-16 06:08:18 +00:00
// ST7565
2023-09-09 07:03:56 +00:00
| PORTCON_PORTB_PU_B9_MASK
2023-09-16 06:08:18 +00:00
// ST7565 + SWD IO
2023-09-09 07:03:56 +00:00
| PORTCON_PORTB_PU_B11_MASK
2023-09-16 06:08:18 +00:00
// SWD CLK
2023-09-09 07:03:56 +00:00
| PORTCON_PORTB_PU_B14_MASK
2023-09-16 06:08:18 +00:00
// BK1080
| PORTCON_PORTB_PU_B15_MASK
);
2023-09-09 07:03:56 +00:00
PORTCON_PORTB_PD &= ~(0
2023-09-16 06:08:18 +00:00
// Back light
2023-09-09 07:03:56 +00:00
| PORTCON_PORTB_PD_B6_MASK
2023-09-16 06:08:18 +00:00
// ST7565
2023-09-09 07:03:56 +00:00
| PORTCON_PORTB_PD_B9_MASK
2023-09-16 06:08:18 +00:00
// ST7565 + SWD IO
2023-09-09 07:03:56 +00:00
| PORTCON_PORTB_PD_B11_MASK
2023-09-16 06:08:18 +00:00
// SWD CLK
2023-09-09 07:03:56 +00:00
| PORTCON_PORTB_PD_B14_MASK
2023-09-16 06:08:18 +00:00
// BK1080
| PORTCON_PORTB_PD_B15_MASK
);
2023-09-09 07:03:56 +00:00
PORTCON_PORTB_OD &= ~(0
2023-09-16 06:08:18 +00:00
// Back light
2023-09-09 07:03:56 +00:00
| PORTCON_PORTB_OD_B6_MASK
2023-09-16 06:08:18 +00:00
// ST7565
2023-09-09 07:03:56 +00:00
| PORTCON_PORTB_OD_B9_MASK
2023-09-16 06:08:18 +00:00
// ST7565 + SWD IO
2023-09-09 07:03:56 +00:00
| PORTCON_PORTB_OD_B11_MASK
2023-09-16 06:08:18 +00:00
// BK1080
| PORTCON_PORTB_OD_B15_MASK
);
2023-09-09 07:03:56 +00:00
PORTCON_PORTB_OD |= 0
2023-09-16 06:08:18 +00:00
// SWD CLK
| PORTCON_PORTB_OD_B14_BITS_ENABLE
;
2023-09-09 07:03:56 +00:00
// PORT C pin configuration
PORTCON_PORTC_IE |= 0
2023-09-16 06:08:18 +00:00
// PTT button
| PORTCON_PORTC_IE_C5_BITS_ENABLE
;
2023-09-09 07:03:56 +00:00
PORTCON_PORTC_IE &= ~(0
2023-09-16 06:08:18 +00:00
// BK4819 SCN
2023-09-09 07:03:56 +00:00
| PORTCON_PORTC_IE_C0_MASK
2023-09-16 06:08:18 +00:00
// BK4819 SCL
2023-09-09 07:03:56 +00:00
| PORTCON_PORTC_IE_C1_MASK
2023-09-16 06:08:18 +00:00
// BK4819 SDA
2023-09-09 07:03:56 +00:00
| PORTCON_PORTC_IE_C2_MASK
2023-09-16 06:08:18 +00:00
// Flash Light
2023-09-09 07:03:56 +00:00
| PORTCON_PORTC_IE_C3_MASK
2023-09-16 06:08:18 +00:00
// Speaker
| PORTCON_PORTC_IE_C4_MASK
);
2023-09-09 07:03:56 +00:00
PORTCON_PORTC_PU |= 0
2023-09-16 06:08:18 +00:00
// PTT button
| PORTCON_PORTC_PU_C5_BITS_ENABLE
;
2023-09-09 07:03:56 +00:00
PORTCON_PORTC_PU &= ~(0
2023-09-16 06:08:18 +00:00
// BK4819 SCN
2023-09-09 07:03:56 +00:00
| PORTCON_PORTC_PU_C0_MASK
2023-09-16 06:08:18 +00:00
// BK4819 SCL
2023-09-09 07:03:56 +00:00
| PORTCON_PORTC_PU_C1_MASK
2023-09-16 06:08:18 +00:00
// BK4819 SDA
2023-09-09 07:03:56 +00:00
| PORTCON_PORTC_PU_C2_MASK
2023-09-16 06:08:18 +00:00
// Flash Light
2023-09-09 07:03:56 +00:00
| PORTCON_PORTC_PU_C3_MASK
2023-09-16 06:08:18 +00:00
// Speaker
| PORTCON_PORTC_PU_C4_MASK
);
2023-09-09 07:03:56 +00:00
PORTCON_PORTC_PD &= ~(0
2023-09-16 06:08:18 +00:00
// BK4819 SCN
2023-09-09 07:03:56 +00:00
| PORTCON_PORTC_PD_C0_MASK
2023-09-16 06:08:18 +00:00
// BK4819 SCL
2023-09-09 07:03:56 +00:00
| PORTCON_PORTC_PD_C1_MASK
2023-09-16 06:08:18 +00:00
// BK4819 SDA
2023-09-09 07:03:56 +00:00
| PORTCON_PORTC_PD_C2_MASK
2023-09-16 06:08:18 +00:00
// Flash Light
2023-09-09 07:03:56 +00:00
| PORTCON_PORTC_PD_C3_MASK
2023-09-16 06:08:18 +00:00
// Speaker
2023-09-09 07:03:56 +00:00
| PORTCON_PORTC_PD_C4_MASK
2023-09-16 06:08:18 +00:00
// PTT Button
| PORTCON_PORTC_PD_C5_MASK
);
2023-09-09 07:03:56 +00:00
PORTCON_PORTC_OD &= ~(0
2023-09-16 06:08:18 +00:00
// BK4819 SCN
2023-09-09 07:03:56 +00:00
| PORTCON_PORTC_OD_C0_MASK
2023-09-16 06:08:18 +00:00
// BK4819 SCL
2023-09-09 07:03:56 +00:00
| PORTCON_PORTC_OD_C1_MASK
2023-09-16 06:08:18 +00:00
// BK4819 SDA
2023-09-09 07:03:56 +00:00
| PORTCON_PORTC_OD_C2_MASK
2023-09-16 06:08:18 +00:00
// Flash Light
2023-09-09 07:03:56 +00:00
| PORTCON_PORTC_OD_C3_MASK
2023-09-16 06:08:18 +00:00
// Speaker
| PORTCON_PORTC_OD_C4_MASK
);
2023-09-09 07:03:56 +00:00
PORTCON_PORTC_OD |= 0
2023-09-16 06:08:18 +00:00
// BK4819 SCN
| PORTCON_PORTC_OD_C0_BITS_DISABLE
// BK4819 SCL
| PORTCON_PORTC_OD_C1_BITS_DISABLE
// BK4819 SDA
| PORTCON_PORTC_OD_C2_BITS_DISABLE
// Flash Light
| PORTCON_PORTC_OD_C3_BITS_DISABLE
// Speaker
| PORTCON_PORTC_OD_C4_BITS_DISABLE
// PTT button
| PORTCON_PORTC_OD_C5_BITS_ENABLE
;
2023-09-09 07:03:56 +00:00
}
void BOARD_ADC_Init(void)
{
ADC_Config_t Config;
Config.CLK_SEL = SYSCON_CLK_SEL_W_SARADC_SMPL_VALUE_DIV2;
Config.CH_SEL = ADC_CH4 | ADC_CH9;
Config.AVG = SARADC_CFG_AVG_VALUE_8_SAMPLE;
Config.CONT = SARADC_CFG_CONT_VALUE_SINGLE;
Config.MEM_MODE = SARADC_CFG_MEM_MODE_VALUE_CHANNEL;
Config.SMPL_CLK = SARADC_CFG_SMPL_CLK_VALUE_INTERNAL;
Config.SMPL_WIN = SARADC_CFG_SMPL_WIN_VALUE_15_CYCLE;
Config.SMPL_SETUP = SARADC_CFG_SMPL_SETUP_VALUE_1_CYCLE;
Config.ADC_TRIG = SARADC_CFG_ADC_TRIG_VALUE_CPU;
Config.CALIB_KD_VALID = SARADC_CALIB_KD_VALID_VALUE_YES;
Config.CALIB_OFFSET_VALID = SARADC_CALIB_OFFSET_VALID_VALUE_YES;
Config.DMA_EN = SARADC_CFG_DMA_EN_VALUE_DISABLE;
Config.IE_CHx_EOC = SARADC_IE_CHx_EOC_VALUE_NONE;
Config.IE_FIFO_FULL = SARADC_IE_FIFO_FULL_VALUE_DISABLE;
Config.IE_FIFO_HFULL = SARADC_IE_FIFO_HFULL_VALUE_DISABLE;
ADC_Configure(&Config);
ADC_Enable();
ADC_SoftReset();
}
void BOARD_ADC_GetBatteryInfo(uint16_t *pVoltage, uint16_t *pCurrent)
{
ADC_Start();
while (!ADC_CheckEndOfConversion(ADC_CH9)) {}
*pVoltage = ADC_GetValue(ADC_CH4);
*pCurrent = ADC_GetValue(ADC_CH9);
}
void BOARD_Init(void)
{
BOARD_PORTCON_Init();
BOARD_GPIO_Init();
2023-10-28 13:35:27 +00:00
BACKLIGHT_InitHardware();
2023-09-09 07:03:56 +00:00
BOARD_ADC_Init();
ST7565_Init(true);
2023-09-14 08:56:30 +00:00
#ifdef ENABLE_FMRADIO
BK1080_Init(0, false);
#endif
2023-09-09 07:03:56 +00:00
CRC_Init();
}
void BOARD_EEPROM_Init(void)
{
unsigned int i;
uint8_t Data[16];
memset(Data, 0, sizeof(Data));
// 0E70..0E77
EEPROM_ReadBuffer(0x0E70, Data, 8);
2023-09-15 11:31:30 +00:00
gEeprom.CHAN_1_CALL = IS_MR_CHANNEL(Data[0]) ? Data[0] : MR_CHANNEL_FIRST;
gEeprom.SQUELCH_LEVEL = (Data[1] < 10) ? Data[1] : 1;
gEeprom.TX_TIMEOUT_TIMER = (Data[2] < 11) ? Data[2] : 1;
2023-09-14 08:56:30 +00:00
#ifdef ENABLE_NOAA
2023-09-12 10:01:34 +00:00
gEeprom.NOAA_AUTO_SCAN = (Data[3] < 2) ? Data[3] : false;
2023-09-09 07:03:56 +00:00
#endif
2023-09-15 11:31:30 +00:00
gEeprom.KEY_LOCK = (Data[4] < 2) ? Data[4] : false;
#ifdef ENABLE_VOX
gEeprom.VOX_SWITCH = (Data[5] < 2) ? Data[5] : false;
gEeprom.VOX_LEVEL = (Data[6] < 10) ? Data[6] : 1;
#endif
2023-09-15 11:31:30 +00:00
gEeprom.MIC_SENSITIVITY = (Data[7] < 5) ? Data[7] : 4;
2023-09-09 07:03:56 +00:00
// 0E78..0E7F
EEPROM_ReadBuffer(0x0E78, Data, 8);
2023-10-25 18:47:14 +00:00
gEeprom.BACKLIGHT_MAX = (Data[0] & 0xF) <= 10 ? (Data[0] & 0xF) : 10;
gEeprom.BACKLIGHT_MIN = (Data[0] >> 4) < gEeprom.BACKLIGHT_MAX ? (Data[0] >> 4) : 0;
#ifdef ENABLE_BLMIN_TMP_OFF
gEeprom.BACKLIGHT_MIN_STAT = BLMIN_STAT_ON;
#endif
gEeprom.CHANNEL_DISPLAY_MODE = (Data[1] < 4) ? Data[1] : MDF_FREQUENCY; // 4 instead of 3 - extra display mode
gEeprom.CROSS_BAND_RX_TX = (Data[2] < 3) ? Data[2] : CROSS_BAND_OFF;
gEeprom.BATTERY_SAVE = (Data[3] < 5) ? Data[3] : 4;
gEeprom.DUAL_WATCH = (Data[4] < 3) ? Data[4] : DUAL_WATCH_CHAN_A;
2023-10-25 18:47:14 +00:00
gEeprom.BACKLIGHT_TIME = (Data[5] < ARRAY_SIZE(gSubMenu_BACKLIGHT)) ? Data[5] : 3;
2023-10-27 18:11:22 +00:00
gEeprom.TAIL_TONE_ELIMINATION = (Data[6] < 2) ? Data[6] : false;
gEeprom.VFO_OPEN = (Data[7] < 2) ? Data[7] : true;
2023-09-09 07:03:56 +00:00
// 0E80..0E87
EEPROM_ReadBuffer(0x0E80, Data, 8);
2023-09-14 08:56:30 +00:00
gEeprom.ScreenChannel[0] = IS_VALID_CHANNEL(Data[0]) ? Data[0] : (FREQ_CHANNEL_FIRST + BAND6_400MHz);
gEeprom.ScreenChannel[1] = IS_VALID_CHANNEL(Data[3]) ? Data[3] : (FREQ_CHANNEL_FIRST + BAND6_400MHz);
2023-09-09 07:03:56 +00:00
gEeprom.MrChannel[0] = IS_MR_CHANNEL(Data[1]) ? Data[1] : MR_CHANNEL_FIRST;
gEeprom.MrChannel[1] = IS_MR_CHANNEL(Data[4]) ? Data[4] : MR_CHANNEL_FIRST;
2023-09-14 08:56:30 +00:00
gEeprom.FreqChannel[0] = IS_FREQ_CHANNEL(Data[2]) ? Data[2] : (FREQ_CHANNEL_FIRST + BAND6_400MHz);
gEeprom.FreqChannel[1] = IS_FREQ_CHANNEL(Data[5]) ? Data[5] : (FREQ_CHANNEL_FIRST + BAND6_400MHz);
#ifdef ENABLE_NOAA
2023-09-09 07:03:56 +00:00
gEeprom.NoaaChannel[0] = IS_NOAA_CHANNEL(Data[6]) ? Data[6] : NOAA_CHANNEL_FIRST;
gEeprom.NoaaChannel[1] = IS_NOAA_CHANNEL(Data[7]) ? Data[7] : NOAA_CHANNEL_FIRST;
#endif
2023-09-14 08:56:30 +00:00
#ifdef ENABLE_FMRADIO
2023-09-12 10:01:34 +00:00
{ // 0E88..0E8F
struct
{
uint16_t SelectedFrequency;
uint8_t SelectedChannel;
uint8_t IsMrMode;
uint8_t Padding[8];
} __attribute__((packed)) FM;
2023-09-12 10:01:34 +00:00
EEPROM_ReadBuffer(0x0E88, &FM, 8);
gEeprom.FM_LowerLimit = 760;
gEeprom.FM_UpperLimit = 1080;
if (FM.SelectedFrequency < gEeprom.FM_LowerLimit || FM.SelectedFrequency > gEeprom.FM_UpperLimit)
gEeprom.FM_SelectedFrequency = 960;
else
gEeprom.FM_SelectedFrequency = FM.SelectedFrequency;
gEeprom.FM_SelectedChannel = FM.SelectedChannel;
gEeprom.FM_IsMrMode = (FM.IsMrMode < 2) ? FM.IsMrMode : false;
}
2023-09-09 07:03:56 +00:00
// 0E40..0E67
EEPROM_ReadBuffer(0x0E40, gFM_Channels, sizeof(gFM_Channels));
FM_ConfigureChannelState();
2023-09-14 08:56:30 +00:00
#endif
2023-09-09 07:03:56 +00:00
// 0E90..0E97
EEPROM_ReadBuffer(0x0E90, Data, 8);
gEeprom.BEEP_CONTROL = Data[0] & 1;
gEeprom.KEY_M_LONG_PRESS_ACTION = ((Data[0] >> 1) < ACTION_OPT_LEN) ? (Data[0] >> 1) : ACTION_OPT_NONE;
2023-09-14 08:56:30 +00:00
gEeprom.KEY_1_SHORT_PRESS_ACTION = (Data[1] < ACTION_OPT_LEN) ? Data[1] : ACTION_OPT_MONITOR;
gEeprom.KEY_1_LONG_PRESS_ACTION = (Data[2] < ACTION_OPT_LEN) ? Data[2] : ACTION_OPT_FLASHLIGHT;
gEeprom.KEY_2_SHORT_PRESS_ACTION = (Data[3] < ACTION_OPT_LEN) ? Data[3] : ACTION_OPT_SCAN;
gEeprom.KEY_2_LONG_PRESS_ACTION = (Data[4] < ACTION_OPT_LEN) ? Data[4] : ACTION_OPT_NONE;
gEeprom.SCAN_RESUME_MODE = (Data[5] < 3) ? Data[5] : SCAN_RESUME_CO;
2023-09-14 08:56:30 +00:00
gEeprom.AUTO_KEYPAD_LOCK = (Data[6] < 2) ? Data[6] : false;
gEeprom.POWER_ON_DISPLAY_MODE = (Data[7] < 4) ? Data[7] : POWER_ON_DISPLAY_MODE_VOLTAGE;
2023-09-09 07:03:56 +00:00
// 0E98..0E9F
EEPROM_ReadBuffer(0x0E98, Data, 8);
2023-09-17 08:54:24 +00:00
memmove(&gEeprom.POWER_ON_PASSWORD, Data, 4);
2023-09-09 07:03:56 +00:00
// 0EA0..0EA7
2023-09-14 08:56:30 +00:00
#ifdef ENABLE_VOICE
2023-09-09 07:03:56 +00:00
EEPROM_ReadBuffer(0x0EA0, Data, 8);
gEeprom.VOICE_PROMPT = (Data[0] < 3) ? Data[0] : VOICE_PROMPT_ENGLISH;
#endif
2023-09-09 07:03:56 +00:00
// 0EA8..0EAF
EEPROM_ReadBuffer(0x0EA8, Data, 8);
2023-09-14 08:56:30 +00:00
#ifdef ENABLE_ALARM
2023-09-09 08:01:52 +00:00
gEeprom.ALARM_MODE = (Data[0] < 2) ? Data[0] : true;
#endif
2023-09-09 07:03:56 +00:00
gEeprom.ROGER = (Data[1] < 3) ? Data[1] : ROGER_MODE_OFF;
gEeprom.REPEATER_TAIL_TONE_ELIMINATION = (Data[2] < 11) ? Data[2] : 0;
gEeprom.TX_VFO = (Data[3] < 2) ? Data[3] : 0;
gEeprom.BATTERY_TYPE = (Data[4] < BATTERY_TYPE_UNKNOWN) ? Data[4] : BATTERY_TYPE_1600_MAH;
2023-09-09 07:03:56 +00:00
// 0ED0..0ED7
EEPROM_ReadBuffer(0x0ED0, Data, 8);
gEeprom.DTMF_SIDE_TONE = (Data[0] < 2) ? Data[0] : true;
gEeprom.DTMF_SEPARATE_CODE = DTMF_ValidateCodes((char *)(Data + 1), 1) ? Data[1] : '*';
gEeprom.DTMF_GROUP_CALL_CODE = DTMF_ValidateCodes((char *)(Data + 2), 1) ? Data[2] : '#';
gEeprom.DTMF_DECODE_RESPONSE = (Data[3] < 4) ? Data[3] : 0;
2023-10-04 21:08:13 +00:00
gEeprom.DTMF_auto_reset_time = (Data[4] < 61) ? Data[4] : (Data[4] >= 5) ? Data[4] : 10;
2023-09-09 07:03:56 +00:00
gEeprom.DTMF_PRELOAD_TIME = (Data[5] < 101) ? Data[5] * 10 : 300;
gEeprom.DTMF_FIRST_CODE_PERSIST_TIME = (Data[6] < 101) ? Data[6] * 10 : 100;
gEeprom.DTMF_HASH_CODE_PERSIST_TIME = (Data[7] < 101) ? Data[7] * 10 : 100;
// 0ED8..0EDF
EEPROM_ReadBuffer(0x0ED8, Data, 8);
gEeprom.DTMF_CODE_PERSIST_TIME = (Data[0] < 101) ? Data[0] * 10 : 100;
gEeprom.DTMF_CODE_INTERVAL_TIME = (Data[1] < 101) ? Data[1] * 10 : 100;
gEeprom.PERMIT_REMOTE_KILL = (Data[2] < 2) ? Data[2] : true;
// 0EE0..0EE7
EEPROM_ReadBuffer(0x0EE0, Data, 8);
if (DTMF_ValidateCodes((char *)Data, 8))
2023-09-17 08:54:24 +00:00
memmove(gEeprom.ANI_DTMF_ID, Data, 8);
2023-09-09 07:03:56 +00:00
else
{
memset(gEeprom.ANI_DTMF_ID, 0, sizeof(gEeprom.ANI_DTMF_ID));
strcpy(gEeprom.ANI_DTMF_ID, "123");
}
2023-09-09 07:03:56 +00:00
// 0EE8..0EEF
EEPROM_ReadBuffer(0x0EE8, Data, 8);
if (DTMF_ValidateCodes((char *)Data, 8))
2023-09-17 08:54:24 +00:00
memmove(gEeprom.KILL_CODE, Data, 8);
2023-09-09 07:03:56 +00:00
else
{
memset(gEeprom.KILL_CODE, 0, sizeof(gEeprom.KILL_CODE));
strcpy(gEeprom.KILL_CODE, "ABCD9");
}
2023-09-09 07:03:56 +00:00
// 0EF0..0EF7
EEPROM_ReadBuffer(0x0EF0, Data, 8);
if (DTMF_ValidateCodes((char *)Data, 8))
2023-09-17 08:54:24 +00:00
memmove(gEeprom.REVIVE_CODE, Data, 8);
2023-09-09 07:03:56 +00:00
else
{
memset(gEeprom.REVIVE_CODE, 0, sizeof(gEeprom.REVIVE_CODE));
strcpy(gEeprom.REVIVE_CODE, "9DCBA");
}
2023-09-09 07:03:56 +00:00
// 0EF8..0F07
EEPROM_ReadBuffer(0x0EF8, Data, 16);
if (DTMF_ValidateCodes((char *)Data, 16))
2023-09-17 08:54:24 +00:00
memmove(gEeprom.DTMF_UP_CODE, Data, 16);
2023-09-09 07:03:56 +00:00
else
{
memset(gEeprom.DTMF_UP_CODE, 0, sizeof(gEeprom.DTMF_UP_CODE));
strcpy(gEeprom.DTMF_UP_CODE, "12345");
}
2023-09-09 07:03:56 +00:00
// 0F08..0F17
EEPROM_ReadBuffer(0x0F08, Data, 16);
if (DTMF_ValidateCodes((char *)Data, 16))
2023-09-17 08:54:24 +00:00
memmove(gEeprom.DTMF_DOWN_CODE, Data, 16);
2023-09-09 07:03:56 +00:00
else
{
memset(gEeprom.DTMF_DOWN_CODE, 0, sizeof(gEeprom.DTMF_DOWN_CODE));
strcpy(gEeprom.DTMF_DOWN_CODE, "54321");
}
2023-09-09 07:03:56 +00:00
// 0F18..0F1F
EEPROM_ReadBuffer(0x0F18, Data, 8);
// gEeprom.SCAN_LIST_DEFAULT = (Data[0] < 2) ? Data[0] : false;
gEeprom.SCAN_LIST_DEFAULT = (Data[0] < 3) ? Data[0] : false; // we now have 'all' channel scan option
2023-09-09 07:03:56 +00:00
for (i = 0; i < 2; i++)
{
const unsigned int j = 1 + (i * 3);
gEeprom.SCAN_LIST_ENABLED[i] = (Data[j + 0] < 2) ? Data[j] : false;
gEeprom.SCANLIST_PRIORITY_CH1[i] = Data[j + 1];
gEeprom.SCANLIST_PRIORITY_CH2[i] = Data[j + 2];
}
// 0F40..0F47
EEPROM_ReadBuffer(0x0F40, Data, 8);
2023-11-08 00:43:06 +00:00
gSetting_F_LOCK = (Data[0] < F_LOCK_LEN) ? Data[0] : F_LOCK_DEF;
gSetting_350TX = (Data[1] < 2) ? Data[1] : false; // was true
gSetting_KILLED = (Data[2] < 2) ? Data[2] : false;
gSetting_200TX = (Data[3] < 2) ? Data[3] : false;
gSetting_500TX = (Data[4] < 2) ? Data[4] : false;
gSetting_350EN = (Data[5] < 2) ? Data[5] : true;
gSetting_ScrambleEnable = (Data[6] < 2) ? Data[6] : true;
2023-11-08 00:43:06 +00:00
//gSetting_TX_EN = (Data[7] & (1u << 0)) ? true : false;
gSetting_live_DTMF_decoder = (Data[7] & (1u << 1)) ? true : false;
2023-10-04 15:37:11 +00:00
gSetting_battery_text = (((Data[7] >> 2) & 3u) <= 2) ? (Data[7] >> 2) & 3 : 2;
#ifdef ENABLE_AUDIO_BAR
gSetting_mic_bar = (Data[7] & (1u << 4)) ? true : false;
#endif
2023-09-21 23:03:53 +00:00
#ifdef ENABLE_AM_FIX
2023-09-21 22:06:47 +00:00
gSetting_AM_fix = (Data[7] & (1u << 5)) ? true : false;
#endif
2023-10-04 15:37:11 +00:00
gSetting_backlight_on_tx_rx = (Data[7] >> 6) & 3u;
2023-09-09 07:03:56 +00:00
if (!gEeprom.VFO_OPEN)
{
gEeprom.ScreenChannel[0] = gEeprom.MrChannel[0];
gEeprom.ScreenChannel[1] = gEeprom.MrChannel[1];
}
// 0D60..0E27
EEPROM_ReadBuffer(0x0D60, gMR_ChannelAttributes, sizeof(gMR_ChannelAttributes));
// 0F30..0F3F
EEPROM_ReadBuffer(0x0F30, gCustomAesKey, sizeof(gCustomAesKey));
bHasCustomAesKey = false;
2023-09-15 11:31:30 +00:00
for (i = 0; i < ARRAY_SIZE(gCustomAesKey); i++)
2023-09-09 07:03:56 +00:00
{
if (gCustomAesKey[i] != 0xFFFFFFFFu)
{
bHasCustomAesKey = true;
return;
}
}
}
2023-10-16 10:22:56 +00:00
void BOARD_EEPROM_LoadCalibration(void)
2023-09-09 07:03:56 +00:00
{
// uint8_t Mic;
2023-10-16 10:22:56 +00:00
EEPROM_ReadBuffer(0x1EC0, gEEPROM_RSSI_CALIB[3], 8);
memcpy(gEEPROM_RSSI_CALIB[4], gEEPROM_RSSI_CALIB[3], 8);
memcpy(gEEPROM_RSSI_CALIB[5], gEEPROM_RSSI_CALIB[3], 8);
memcpy(gEEPROM_RSSI_CALIB[6], gEEPROM_RSSI_CALIB[3], 8);
2023-09-09 07:03:56 +00:00
2023-10-18 14:59:30 +00:00
EEPROM_ReadBuffer(0x1EC8, gEEPROM_RSSI_CALIB[0], 8);
memcpy(gEEPROM_RSSI_CALIB[1], gEEPROM_RSSI_CALIB[0], 8);
memcpy(gEEPROM_RSSI_CALIB[2], gEEPROM_RSSI_CALIB[0], 8);
2023-09-09 07:03:56 +00:00
EEPROM_ReadBuffer(0x1F40, gBatteryCalibration, 12);
if (gBatteryCalibration[0] >= 5000)
{
gBatteryCalibration[0] = 1900;
gBatteryCalibration[1] = 2000;
}
gBatteryCalibration[5] = 2300;
#ifdef ENABLE_VOX
EEPROM_ReadBuffer(0x1F50 + (gEeprom.VOX_LEVEL * 2), &gEeprom.VOX1_THRESHOLD, 2);
EEPROM_ReadBuffer(0x1F68 + (gEeprom.VOX_LEVEL * 2), &gEeprom.VOX0_THRESHOLD, 2);
#endif
2023-09-09 07:03:56 +00:00
//EEPROM_ReadBuffer(0x1F80 + gEeprom.MIC_SENSITIVITY, &Mic, 1);
//gEeprom.MIC_SENSITIVITY_TUNING = (Mic < 32) ? Mic : 15;
gEeprom.MIC_SENSITIVITY_TUNING = gMicGain_dB2[gEeprom.MIC_SENSITIVITY];
{
struct
{
int16_t BK4819_XtalFreqLow;
uint16_t EEPROM_1F8A;
uint16_t EEPROM_1F8C;
uint8_t VOLUME_GAIN;
uint8_t DAC_GAIN;
} __attribute__((packed)) Misc;
// radio 1 .. 04 00 46 00 50 00 2C 0E
// radio 2 .. 05 00 46 00 50 00 2C 0E
EEPROM_ReadBuffer(0x1F88, &Misc, 8);
gEeprom.BK4819_XTAL_FREQ_LOW = (Misc.BK4819_XtalFreqLow >= -1000 && Misc.BK4819_XtalFreqLow <= 1000) ? Misc.BK4819_XtalFreqLow : 0;
gEEPROM_1F8A = Misc.EEPROM_1F8A & 0x01FF;
gEEPROM_1F8C = Misc.EEPROM_1F8C & 0x01FF;
gEeprom.VOLUME_GAIN = (Misc.VOLUME_GAIN < 64) ? Misc.VOLUME_GAIN : 58;
gEeprom.DAC_GAIN = (Misc.DAC_GAIN < 16) ? Misc.DAC_GAIN : 8;
BK4819_WriteRegister(BK4819_REG_3B, 22656 + gEeprom.BK4819_XTAL_FREQ_LOW);
// BK4819_WriteRegister(BK4819_REG_3C, gEeprom.BK4819_XTAL_FREQ_HIGH);
}
2023-09-09 07:03:56 +00:00
}
uint32_t BOARD_fetchChannelFrequency(const int channel)
{
struct
{
uint32_t frequency;
uint32_t offset;
} __attribute__((packed)) info;
EEPROM_ReadBuffer(channel * 16, &info, sizeof(info));
return info.frequency;
}
void BOARD_fetchChannelName(char *s, const int channel)
{
int i;
if (s == NULL)
return;
memset(s, 0, 11); // 's' had better be large enough !
if (channel < 0)
return;
if (!RADIO_CheckValidChannel(channel, false, 0))
return;
EEPROM_ReadBuffer(0x0F50 + (channel * 16), s + 0, 8);
EEPROM_ReadBuffer(0x0F58 + (channel * 16), s + 8, 2);
for (i = 0; i < 10; i++)
if (s[i] < 32 || s[i] > 127)
break; // invalid char
s[i--] = 0; // null term
while (i >= 0 && s[i] == 32) // trim trailing spaces
s[i--] = 0; // null term
}
2023-09-09 07:03:56 +00:00
void BOARD_FactoryReset(bool bIsAll)
{
uint16_t i;
2023-09-15 11:31:30 +00:00
uint8_t Template[8];
2023-09-09 07:03:56 +00:00
memset(Template, 0xFF, sizeof(Template));
2023-09-15 11:31:30 +00:00
2023-09-09 07:03:56 +00:00
for (i = 0x0C80; i < 0x1E00; i += 8)
{
if (
!(i >= 0x0EE0 && i < 0x0F18) && // ANI ID + DTMF codes
!(i >= 0x0F30 && i < 0x0F50) && // AES KEY + F LOCK + Scramble Enable
!(i >= 0x1C00 && i < 0x1E00) && // DTMF contacts
!(i >= 0x0EB0 && i < 0x0ED0) && // Welcome strings
!(i >= 0x0EA0 && i < 0x0EA8) && // Voice Prompt
(bIsAll ||
(
!(i >= 0x0D60 && i < 0x0E28) && // MR Channel Attributes
!(i >= 0x0F18 && i < 0x0F30) && // Scan List
!(i >= 0x0F50 && i < 0x1C00) && // MR Channel Names
!(i >= 0x0E40 && i < 0x0E70) && // FM Channels
2023-09-14 08:56:30 +00:00
!(i >= 0x0E88 && i < 0x0E90) // FM settings
))
2023-09-15 11:31:30 +00:00
)
{
2023-09-09 07:03:56 +00:00
EEPROM_WriteBuffer(i, Template);
}
}
2023-09-13 01:01:35 +00:00
if (bIsAll)
{
RADIO_InitInfo(gRxVfo, FREQ_CHANNEL_FIRST + BAND6_400MHz, 43350000);
2023-09-15 11:31:30 +00:00
// set the first few memory channels
for (i = 0; i < ARRAY_SIZE(gDefaultFrequencyTable); i++)
2023-09-13 01:01:35 +00:00
{
const uint32_t Frequency = gDefaultFrequencyTable[i];
2023-09-25 17:08:21 +00:00
gRxVfo->freq_config_RX.Frequency = Frequency;
gRxVfo->freq_config_TX.Frequency = Frequency;
2023-09-13 01:01:35 +00:00
gRxVfo->Band = FREQUENCY_GetBand(Frequency);
SETTINGS_SaveChannel(MR_CHANNEL_FIRST + i, 0, gRxVfo, 2);
}
}
2023-09-09 07:03:56 +00:00
}