uv-k5-firmware-custom/board.c

506 lines
11 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>
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-12-02 21:41:47 +00:00
2023-09-09 07:03:56 +00:00
#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
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();
2023-09-16 06:08:18 +00:00
overlay_FLASH_MainClock = 48000000;
overlay_FLASH_ClockMultiplier = 48;
2023-09-16 06:08:18 +00:00
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();
2023-12-04 21:53:59 +00:00
ST7565_Init();
#ifdef ENABLE_FMRADIO
2023-09-14 08:56:30 +00:00
BK1080_Init(0, false);
#endif
2023-09-09 07:03:56 +00:00
#if defined(ENABLE_UART) || defined(ENABLED_AIRCOPY)
CRC_Init();
#endif
2023-09-09 07:03:56 +00:00
}