mirror of
https://github.com/DualTachyon/uv-k5-firmware.git
synced 2024-11-27 08:59:52 +08:00
Backup of almost finished radio register setup.
This commit is contained in:
parent
615d27a625
commit
9695818121
1
Makefile
1
Makefile
@ -33,6 +33,7 @@ OBJS += driver/uart.o
|
||||
|
||||
# Main
|
||||
OBJS += board.o
|
||||
OBJS += dcs.o
|
||||
OBJS += dtmf.o
|
||||
OBJS += fm.o
|
||||
OBJS += frequencies.o
|
||||
|
91
dcs.c
Normal file
91
dcs.c
Normal file
@ -0,0 +1,91 @@
|
||||
/* 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 "dcs.h"
|
||||
|
||||
const uint16_t CTCSS_Options[50] = {
|
||||
0x029E, 0x02B5, 0x02CF, 0x02E8,
|
||||
0x0302, 0x031D, 0x0339, 0x0356,
|
||||
0x0375, 0x0393, 0x03B4, 0x03CE,
|
||||
0x03E8, 0x040B, 0x0430, 0x0455,
|
||||
0x047C, 0x04A4, 0x04CE, 0x04F9,
|
||||
0x0526, 0x0555, 0x0585, 0x05B6,
|
||||
0x05EA, 0x061F, 0x063E, 0x0656,
|
||||
0x0677, 0x068F, 0x06B1, 0x06CA,
|
||||
0x06ED, 0x0707, 0x072B, 0x0746,
|
||||
0x076B, 0x0788, 0x07AE, 0x07CB,
|
||||
0x07F3, 0x0811, 0x083B, 0x0885,
|
||||
0x08D1, 0x08F3, 0x0920, 0x0972,
|
||||
0x09C7, 0x09ED,
|
||||
};
|
||||
|
||||
const uint16_t DCS_Options[104] = {
|
||||
0x0013, 0x0015, 0x0016, 0x0019,
|
||||
0x001A, 0x001E, 0x0023, 0x0027,
|
||||
0x0029, 0x002B, 0x002C, 0x0035,
|
||||
0x0039, 0x003A, 0x003B, 0x003C,
|
||||
0x004C, 0x004D, 0x004E, 0x0052,
|
||||
0x0055, 0x0059, 0x005A, 0x005C,
|
||||
0x0063, 0x0065, 0x006A, 0x006D,
|
||||
0x006E, 0x0072, 0x0075, 0x007A,
|
||||
0x007C, 0x0085, 0x008A, 0x0093,
|
||||
0x0095, 0x0096, 0x00A3, 0x00A4,
|
||||
0x00A5, 0x00A6, 0x00A9, 0x00AA,
|
||||
0x00AD, 0x00B1, 0x00B3, 0x00B5,
|
||||
0x00B6, 0x00B9, 0x00BC, 0x00C6,
|
||||
0x00C9, 0x00CD, 0x00D5, 0x00D9,
|
||||
0x00DA, 0x00E3, 0x00E6, 0x00E9,
|
||||
0x00EE, 0x00F4, 0x00F5, 0x00F9,
|
||||
0x0109, 0x010A, 0x010B, 0x0113,
|
||||
0x0119, 0x011A, 0x0125, 0x0126,
|
||||
0x012A, 0x012C, 0x012D, 0x0132,
|
||||
0x0134, 0x0135, 0x0136, 0x0143,
|
||||
0x0146, 0x014E, 0x0153, 0x0156,
|
||||
0x015A, 0x0166, 0x0175, 0x0186,
|
||||
0x018A, 0x0194, 0x0197, 0x0199,
|
||||
0x019A, 0x01AC, 0x01B2, 0x01B4,
|
||||
0x01C3, 0x01CA, 0x01D3, 0x01D9,
|
||||
0x01DA, 0x01DC, 0x01E3, 0x01EC,
|
||||
};
|
||||
|
||||
uint32_t DCS_CalculateGolay(uint32_t CodeWord)
|
||||
{
|
||||
uint32_t Word;
|
||||
uint8_t i;
|
||||
|
||||
Word = CodeWord;
|
||||
for (i = 0; i < 12; i++) {
|
||||
Word <<= 1;
|
||||
if (Word & 0x1000) {
|
||||
Word ^= 0x08EA;
|
||||
}
|
||||
}
|
||||
return CodeWord | ((Word & 0x0FFE) << 12);
|
||||
}
|
||||
|
||||
uint32_t DCS_GetGolayCodeWord(uint8_t CodeType, uint8_t Option)
|
||||
|
||||
{
|
||||
uint32_t Code;
|
||||
|
||||
Code = DCS_CalculateGolay(DCS_Options[Option] + 0x800);
|
||||
if (CodeType == CODE_TYPE_REVERSE_DIGITAL) {
|
||||
Code ^= 0x7FFFFF;
|
||||
}
|
||||
|
||||
return Code;
|
||||
}
|
||||
|
19
dcs.h
Normal file
19
dcs.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef DCS_H
|
||||
#define DCS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
enum {
|
||||
CODE_TYPE_OFF = 0x00U,
|
||||
CODE_TYPE_CONTINUOUS_TONE = 0x01U,
|
||||
CODE_TYPE_DIGITAL = 0x02U,
|
||||
CODE_TYPE_REVERSE_DIGITAL = 0x03U,
|
||||
};
|
||||
|
||||
extern const uint16_t CTCSS_Options[50];
|
||||
extern const uint16_t DCS_Options[104];
|
||||
|
||||
uint32_t DCS_GetGolayCodeWord(uint8_t CodeType, uint8_t Option);
|
||||
|
||||
#endif
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
enum BK4819_REGISTER_t {
|
||||
BK4819_REG_00 = 0x00U,
|
||||
BK4819_REG_02 = 0x02U,
|
||||
BK4819_REG_06 = 0x06U,
|
||||
BK4819_REG_07_CTC_FREQUENCY_CDCSS_BAUD_RATE = 0x07U,
|
||||
BK4819_REG_08_CDCSS_CALL_SYMBOL_NUMBER_AND_COEFFICIENT = 0x08U,
|
||||
@ -35,6 +36,7 @@ enum BK4819_REGISTER_t {
|
||||
BK4819_REG_19 = 0x19U,
|
||||
BK4819_REG_1F = 0x1FU,
|
||||
BK4819_REG_20 = 0x20U,
|
||||
BK4819_REG_21 = 0x21U,
|
||||
BK4819_REG_24_DTMF_SELCALL_CONFIG = 0x24U,
|
||||
BK4819_REG_28_EXPANDER_CONFIG = 0x28U,
|
||||
BK4819_REG_29_COMPRESS_CONFIG = 0x29U,
|
||||
@ -44,7 +46,7 @@ enum BK4819_REGISTER_t {
|
||||
BK4819_REG_32_FREQUENCY_SCAN = 0x32U,
|
||||
BK4819_REG_33 = 0x33U,
|
||||
BK4819_REG_36_POWER_AMPLIFIER_BIAS_AND_GAIN = 0x36U,
|
||||
BK4819_REG_37_VOLTATE_LDO_AND_MISC_ENABLE = 0x37U,
|
||||
BK4819_REG_37_VOLTAGE_LDO_AND_MISC_ENABLE = 0x37U,
|
||||
BK4819_REG_38_FREQUENCY_LOW = 0x38U,
|
||||
BK4819_REG_39_FREQUENCY_HIGH = 0x39U,
|
||||
BK4819_REG_3A_RSSI_THRESHOLD_FOR_SQ1_SQ0 = 0x3AU,
|
||||
@ -54,6 +56,7 @@ enum BK4819_REGISTER_t {
|
||||
BK4819_REG_3F_INTERRUPT_ENABLE = 0x3FU,
|
||||
BK4819_REG_43_RF_AFT_LPF2_FILTER_BANDWIDTH = 0x43U,
|
||||
BK4819_REG_46_VOICE_AMPLITUDE_THRESHOLD_VOX1 = 0x46U,
|
||||
BK4819_REG_47_AF_OUTPUT_CONFIG = 0x47U,
|
||||
BK4819_REG_48_AF_RF_GAIN_DAC_GAIN = 0x48U,
|
||||
BK4819_REG_49 = 0x49U,
|
||||
BK4819_REG_4D_GLITCH_THR_SQ0 = 0x4DU,
|
||||
@ -76,6 +79,7 @@ enum BK4819_REGISTER_t {
|
||||
BK4819_REG_70_TONE1_CONFIG = 0x70U,
|
||||
BK4819_REG_71_TONE1_SCRAMBLE_FREQ_CONTROL_WORD = 0x71U,
|
||||
BK4819_REG_72_TONE2_FSK_FREQUENCY_CONTROL_WORD = 0x72U,
|
||||
BK4819_REG_78_SQUELCH_RSSI_THRESHOLD = 0x78U,
|
||||
BK4819_REG_79_VOX1_DETECTION_INTERVAL_TIME_VOICE_AMPLITUDE_THRESHOLD_VOX0 = 0x79U,
|
||||
BK4819_REG_7A_VOX0_DETECTION_DELAY = 0x7AU,
|
||||
BK4819_REG_7B = 0x7BU,
|
||||
@ -86,5 +90,17 @@ enum BK4819_REGISTER_t {
|
||||
|
||||
typedef enum BK4819_REGISTER_t BK4819_REGISTER_t;
|
||||
|
||||
enum BK4819_GPIO_PIN_t {
|
||||
BK4819_GPIO6_PIN2 = 0,
|
||||
BK4819_GPIO5_PIN1 = 1,
|
||||
BK4819_GPIO4_PIN32 = 2,
|
||||
BK4819_GPIO3_PIN31 = 3,
|
||||
BK4819_GPIO2_PIN30 = 4,
|
||||
BK4819_GPIO1_PIN29 = 5,
|
||||
BK4819_GPIO0_PIN28 = 6,
|
||||
};
|
||||
|
||||
typedef enum BK4819_GPIO_PIN_t BK4819_GPIO_PIN_t;
|
||||
|
||||
#endif
|
||||
|
||||
|
258
driver/bk4819.c
258
driver/bk4819.c
@ -16,6 +16,7 @@
|
||||
|
||||
#include "bk4819.h"
|
||||
#include "bsp/dp32g030/gpio.h"
|
||||
#include "bsp/dp32g030/portcon.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/systick.h"
|
||||
|
||||
@ -29,7 +30,7 @@ void BK4819_Init(void)
|
||||
|
||||
BK4819_WriteRegister(BK4819_REG_00, 0x8000);
|
||||
BK4819_WriteRegister(BK4819_REG_00, 0x0000);
|
||||
BK4819_WriteRegister(BK4819_REG_37_VOLTATE_LDO_AND_MISC_ENABLE, 0x1D0F);
|
||||
BK4819_WriteRegister(BK4819_REG_37_VOLTAGE_LDO_AND_MISC_ENABLE, 0x1D0F);
|
||||
BK4819_WriteRegister(BK4819_REG_36_POWER_AMPLIFIER_BIAS_AND_GAIN, 0x0022);
|
||||
BK4819_SetAGC(0);
|
||||
BK4819_WriteRegister(BK4819_REG_19, 0x1041);
|
||||
@ -58,6 +59,51 @@ void BK4819_Init(void)
|
||||
BK4819_WriteRegister(BK4819_REG_3F_INTERRUPT_ENABLE, 0);
|
||||
}
|
||||
|
||||
static uint16_t BK4819_ReadU16(void)
|
||||
{
|
||||
uint8_t i;
|
||||
uint16_t Value;
|
||||
|
||||
PORTCON_PORTC_IE = (PORTCON_PORTC_IE & ~PORTCON_PORTC_IE_C2_MASK) | PORTCON_PORTC_IE_C2_BITS_ENABLE;
|
||||
GPIOC->DIR = (GPIOC->DIR & ~GPIO_DIR_2_MASK) | GPIO_DIR_2_BITS_INPUT;
|
||||
SYSTICK_DelayUs(1);
|
||||
|
||||
Value = 0;
|
||||
for (i = 0; i < 16; i++) {
|
||||
Value <<= 1;
|
||||
Value |= GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_BK4819_2);
|
||||
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_1);
|
||||
SYSTICK_DelayUs(1);
|
||||
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_1);
|
||||
SYSTICK_DelayUs(1);
|
||||
}
|
||||
PORTCON_PORTC_IE = (PORTCON_PORTC_IE & ~PORTCON_PORTC_IE_C2_MASK) | PORTCON_PORTC_IE_C2_BITS_DISABLE;
|
||||
GPIOC->DIR = (GPIOC->DIR & ~GPIO_DIR_2_MASK) | GPIO_DIR_2_BITS_OUTPUT;
|
||||
|
||||
return Value;
|
||||
}
|
||||
|
||||
uint16_t BK4819_GetRegister(BK4819_REGISTER_t Register)
|
||||
{
|
||||
uint16_t Value;
|
||||
|
||||
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_0);
|
||||
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_1);
|
||||
SYSTICK_DelayUs(1);
|
||||
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_0);
|
||||
|
||||
BK4819_WriteU8(Register | 0x80);
|
||||
|
||||
Value = BK4819_ReadU16();
|
||||
|
||||
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_0);
|
||||
SYSTICK_DelayUs(1);
|
||||
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_1);
|
||||
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_2);
|
||||
|
||||
return Value;
|
||||
}
|
||||
|
||||
void BK4819_WriteRegister(BK4819_REGISTER_t Register, uint16_t Data)
|
||||
{
|
||||
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_0);
|
||||
@ -143,3 +189,213 @@ void BK4819_SetAGC(uint8_t Value)
|
||||
}
|
||||
}
|
||||
|
||||
void BK4819_ToggleGpioOut(BK4819_GPIO_PIN_t Pin, bool bSet)
|
||||
{
|
||||
if (bSet) {
|
||||
gBK4819_GpioOutState |= (0x40U >> Pin);
|
||||
} else {
|
||||
gBK4819_GpioOutState &= ~(0x40U >> Pin);
|
||||
}
|
||||
|
||||
BK4819_WriteRegister(BK4819_REG_33, gBK4819_GpioOutState);
|
||||
}
|
||||
|
||||
void BK4819_EnableCDCSS(uint32_t CodeWord)
|
||||
{
|
||||
// Enable CDCSS
|
||||
// Transmit positive CDCSS code
|
||||
// CDCSS Mode
|
||||
// CDCSS 23bit
|
||||
// Enable Auto CDCSS Bw Mode
|
||||
// Enable Auto CTCSS Bw Mode
|
||||
// CTCSS/CDCSS Tx Gain1 Tuning = 51
|
||||
BK4819_WriteRegister(BK4819_REG_51_CTCSS_CDCSS_CONFIG, 0x8033);
|
||||
|
||||
// CTC1 Frequency Control Word = 2775
|
||||
BK4819_WriteRegister(BK4819_REG_07_CTC_FREQUENCY_CDCSS_BAUD_RATE, (0U << 13) | 2775);
|
||||
|
||||
// Set the code word
|
||||
BK4819_WriteRegister(BK4819_REG_08_CDCSS_CALL_SYMBOL_NUMBER_AND_COEFFICIENT, 0x0000 | ((CodeWord >> 0) & 0xFFF));
|
||||
BK4819_WriteRegister(BK4819_REG_08_CDCSS_CALL_SYMBOL_NUMBER_AND_COEFFICIENT, 0x8000 | ((CodeWord >> 12) & 0xFFF));
|
||||
}
|
||||
|
||||
void BK4819_EnableCTCSS(uint32_t BaudRate)
|
||||
{
|
||||
uint16_t Config;
|
||||
|
||||
if (BaudRate == 2625) {
|
||||
// Enable TxCTCSS
|
||||
// CTCSS Mode
|
||||
// 1050/4 Detect Enable
|
||||
// Enable Auto CDCSS Bw Mode
|
||||
// Enable Auto CTCSS Bw Mode
|
||||
// CTCSS/CDCSS Tx Gain1 Tuning = 74
|
||||
Config = 0x944A;
|
||||
} else {
|
||||
// Enable TxCTCSS
|
||||
// CTCSS Mode
|
||||
// Enable Auto CDCSS Bw Mode
|
||||
// Enable Auto CTCSS Bw Mode
|
||||
// CTCSS/CDCSS Tx Gain1 Tuning = 74
|
||||
Config = 0x904A;
|
||||
}
|
||||
BK4819_WriteRegister(BK4819_REG_51_CTCSS_CDCSS_CONFIG, Config);
|
||||
// CTC1 Frequency Control Word
|
||||
BK4819_WriteRegister(BK4819_REG_07_CTC_FREQUENCY_CDCSS_BAUD_RATE, (0U << 13) | (BaudRate * 2065) / 1000);
|
||||
}
|
||||
|
||||
void BK4819_Set55HzTailDetection(void)
|
||||
{
|
||||
// CTC2 Frequency Control Word = round_nearest(25391 / 55) = 462
|
||||
BK4819_WriteRegister(BK4819_REG_07_CTC_FREQUENCY_CDCSS_BAUD_RATE, (1U << 13) | 462);
|
||||
}
|
||||
|
||||
void BK4819_EnableVox(uint16_t Vox1Threshold, uint16_t Vox0Threshold)
|
||||
{
|
||||
uint16_t Value;
|
||||
|
||||
Value = BK4819_GetRegister(BK4819_REG_31_ENABLE_COMPANDER_VOX_SCRAMBLE);
|
||||
// 0xA000 is undocumented?
|
||||
BK4819_WriteRegister(BK4819_REG_46_VOICE_AMPLITUDE_THRESHOLD_VOX1, 0xA000 | (Vox1Threshold & 0x07FF));
|
||||
// 0x1800 is undocumented?
|
||||
BK4819_WriteRegister(BK4819_REG_79_VOX1_DETECTION_INTERVAL_TIME_VOICE_AMPLITUDE_THRESHOLD_VOX0, 0x1800 | (Vox0Threshold & 0x07FF));
|
||||
// Bottom 12 bits are undocumented?
|
||||
BK4819_WriteRegister(BK4819_REG_7A_VOX0_DETECTION_DELAY, 0x289A);
|
||||
// Enable VOX
|
||||
BK4819_WriteRegister(BK4819_REG_31_ENABLE_COMPANDER_VOX_SCRAMBLE, Value | 4);
|
||||
}
|
||||
|
||||
void BK4819_SetFilterBandwidth(uint8_t Bandwidth)
|
||||
{
|
||||
if (Bandwidth == 0) {
|
||||
BK4819_WriteRegister(BK4819_REG_43_RF_AFT_LPF2_FILTER_BANDWIDTH, 0x3028);
|
||||
} else if (Bandwidth == 1) {
|
||||
BK4819_WriteRegister(BK4819_REG_43_RF_AFT_LPF2_FILTER_BANDWIDTH, 0x4048);
|
||||
}
|
||||
}
|
||||
|
||||
void BK4819_SetupPowerAmplifier(uint16_t Bias, uint32_t Frequency)
|
||||
{
|
||||
uint8_t Gain;
|
||||
|
||||
if (Bias > 255) {
|
||||
Bias = 255;
|
||||
}
|
||||
if (Frequency < 28000000) {
|
||||
// Gain 1 = 1
|
||||
// Gain 2 = 0
|
||||
Gain = 0x08U;
|
||||
} else {
|
||||
// Gain 1 = 4
|
||||
// Gain 2 = 2
|
||||
Gain = 0x22U;
|
||||
}
|
||||
// Enable PACTLoutput
|
||||
BK4819_WriteRegister(BK4819_REG_36_POWER_AMPLIFIER_BIAS_AND_GAIN, (Bias << 8) | 0x80U | Gain);
|
||||
}
|
||||
|
||||
void BK4819_SetFrequency(uint32_t Frequency)
|
||||
{
|
||||
BK4819_WriteRegister(BK4819_REG_38_FREQUENCY_LOW, (Frequency >> 0) & 0xFFFF);
|
||||
BK4819_WriteRegister(BK4819_REG_39_FREQUENCY_HIGH, (Frequency >> 16) & 0xFFFF);
|
||||
}
|
||||
|
||||
void BK4819_SetupSquelch(uint8_t SQ0, uint8_t SQ1, uint8_t SQ2, uint8_t SQ3, uint8_t SQ4, uint8_t SQ5)
|
||||
{
|
||||
BK4819_WriteRegister(BK4819_REG_70_TONE1_CONFIG, 0);
|
||||
BK4819_WriteRegister(BK4819_REG_4D_GLITCH_THR_SQ0, 0xA000 | SQ4);
|
||||
BK4819_WriteRegister(BK4819_REG_4E_SQ1_DELAY_SQ0_DELAY_GLITCH_THR_SQ1, 0x6F00 | SQ5);
|
||||
BK4819_WriteRegister(BK4819_REG_4F_EXNOISE_THR_SQ0_EXNOISE_THR_SQ1, (SQ3 << 8) | SQ2);
|
||||
BK4819_WriteRegister(BK4819_REG_78_SQUELCH_RSSI_THRESHOLD, (SQ0 << 8) | SQ1);
|
||||
BK4819_SetAF(0); // MUTE
|
||||
BK4819_RX_TurnOn();
|
||||
}
|
||||
|
||||
void BK4819_SetAF(uint8_t AF)
|
||||
{
|
||||
// AF Output Inverse Mode = Inverse
|
||||
// Undocumented bits 0x2040
|
||||
BK4819_WriteRegister(BK4819_REG_47_AF_OUTPUT_CONFIG, 0x6040 | (AF << 8));
|
||||
}
|
||||
|
||||
void BK4819_RX_TurnOn(void)
|
||||
{
|
||||
// DSP Voltage Setting = 1
|
||||
// ANA LDO = 2.7v
|
||||
// VCO LDO = 2.7v
|
||||
// RF LDO = 2.7v
|
||||
// PLL LDO = 2.7v
|
||||
// ANA LDO bypass
|
||||
// VCO LDO bypass
|
||||
// RF LDO bypass
|
||||
// PLL LDO bypass
|
||||
// Reserved bit is 1 instead of 0
|
||||
// Enable DSP
|
||||
// Enable XTAL
|
||||
// Enable Band Gap
|
||||
BK4819_WriteRegister(BK4819_REG_37_VOLTAGE_LDO_AND_MISC_ENABLE, 0x1F0F);
|
||||
|
||||
// Turn off everything
|
||||
BK4819_WriteRegister(BK4819_REG_30_VARIOUS_ENABLE_BITS, 0);
|
||||
|
||||
// Enable VCO Calibration
|
||||
// Enable RX Link
|
||||
// Enable AF DAC
|
||||
// Enable PLL/VCO
|
||||
// Disable PA Gain
|
||||
// Disable MIC ADC
|
||||
// Disable TX DSP
|
||||
// Enable RX DSP
|
||||
BK4819_WriteRegister(BK4819_REG_30_VARIOUS_ENABLE_BITS, 0xBFF1);
|
||||
}
|
||||
|
||||
void BK4819_Configure_GPIO2_PIN30_GPIO3_PIN31(uint32_t Frequency)
|
||||
{
|
||||
if (Frequency < 28000000) {
|
||||
BK4819_ToggleGpioOut(BK4819_GPIO2_PIN30, true);
|
||||
BK4819_ToggleGpioOut(BK4819_GPIO3_PIN31, false);
|
||||
} else if (Frequency == 0xFFFFFFFF) {
|
||||
BK4819_ToggleGpioOut(BK4819_GPIO2_PIN30, false);
|
||||
BK4819_ToggleGpioOut(BK4819_GPIO3_PIN31, false);
|
||||
} else {
|
||||
BK4819_ToggleGpioOut(BK4819_GPIO2_PIN30, false);
|
||||
BK4819_ToggleGpioOut(BK4819_GPIO3_PIN31, true);
|
||||
}
|
||||
}
|
||||
|
||||
void BK4819_DisableScramble(void)
|
||||
{
|
||||
uint16_t Value;
|
||||
|
||||
Value = BK4819_GetRegister(BK4819_REG_31_ENABLE_COMPANDER_VOX_SCRAMBLE);
|
||||
BK4819_WriteRegister(BK4819_REG_31_ENABLE_COMPANDER_VOX_SCRAMBLE, Value & 0xFFFD);
|
||||
}
|
||||
|
||||
void BK4819_EnableScramble(uint8_t Type)
|
||||
{
|
||||
uint16_t Value;
|
||||
|
||||
Value = BK4819_GetRegister(BK4819_REG_31_ENABLE_COMPANDER_VOX_SCRAMBLE);
|
||||
BK4819_WriteRegister(BK4819_REG_31_ENABLE_COMPANDER_VOX_SCRAMBLE, Value | 2);
|
||||
BK4819_WriteRegister(BK4819_REG_71_TONE1_SCRAMBLE_FREQ_CONTROL_WORD, (Type * 0x0408) + 0x68DC);
|
||||
}
|
||||
|
||||
void BK4819_DisableVox(void)
|
||||
{
|
||||
uint16_t Value;
|
||||
|
||||
Value = BK4819_GetRegister(BK4819_REG_31_ENABLE_COMPANDER_VOX_SCRAMBLE);
|
||||
BK4819_WriteRegister(BK4819_REG_31_ENABLE_COMPANDER_VOX_SCRAMBLE, Value & 0xFFFB);
|
||||
}
|
||||
|
||||
void BK4819_DisableDTMF_SelCall(void)
|
||||
{
|
||||
BK4819_WriteRegister(BK4819_REG_24_DTMF_SELCALL_CONFIG, 0);
|
||||
}
|
||||
|
||||
void BK4819_ConfigureDTMF_SelCall_and_UnknownRegister(void)
|
||||
{
|
||||
BK4819_WriteRegister(BK4819_REG_21, 0x06D8);
|
||||
BK4819_WriteRegister(BK4819_REG_24_DTMF_SELCALL_CONFIG, 0x8C7E);
|
||||
}
|
||||
|
||||
|
@ -17,15 +17,36 @@
|
||||
#ifndef DRIVER_BK4819_h
|
||||
#define DRIVER_BK4819_h
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "driver/bk4819-regs.h"
|
||||
|
||||
void BK4819_Init(void);
|
||||
uint16_t BK4819_GetRegister(BK4819_REGISTER_t Register);
|
||||
void BK4819_WriteRegister(BK4819_REGISTER_t Register, uint16_t Data);
|
||||
void BK4819_WriteU8(uint8_t Data);
|
||||
void BK4819_WriteU16(uint16_t Data);
|
||||
|
||||
void BK4819_SetAGC(uint8_t Value);
|
||||
|
||||
void BK4819_ToggleGpioOut(BK4819_GPIO_PIN_t Pin, bool bSet);
|
||||
|
||||
void BK4819_EnableCDCSS(uint32_t CodeWord);
|
||||
void BK4819_EnableCTCSS(uint32_t BaudRate);
|
||||
void BK4819_Set55HzTailDetection(void);
|
||||
void BK4819_EnableVox(uint16_t Vox1Threshold, uint16_t Vox0Threshold);
|
||||
void BK4819_SetFilterBandwidth(uint8_t Bandwidth);
|
||||
void BK4819_SetupPowerAmplifier(uint16_t Bias, uint32_t Frequency);
|
||||
void BK4819_SetFrequency(uint32_t Frequency);
|
||||
void BK4819_SetupSquelch(uint8_t SQ0, uint8_t SQ1, uint8_t SQ2, uint8_t SQ3, uint8_t SQ4, uint8_t SQ5);
|
||||
void BK4819_SetAF(uint8_t AF);
|
||||
void BK4819_RX_TurnOn(void);
|
||||
void BK4819_Configure_GPIO2_PIN30_GPIO3_PIN31(uint32_t Frequency);
|
||||
void BK4819_DisableScramble(void);
|
||||
void BK4819_EnableScramble(uint8_t Type);
|
||||
void BK4819_DisableVox(void);
|
||||
void BK4819_DisableDTMF_SelCall(void);
|
||||
void BK4819_ConfigureDTMF_SelCall_and_UnknownRegister(void);
|
||||
|
||||
#endif
|
||||
|
||||
|
1
fm.c
1
fm.c
@ -18,6 +18,7 @@
|
||||
#include "settings.h"
|
||||
|
||||
uint16_t gFM_Channels[20];
|
||||
bool gFmMute;
|
||||
|
||||
bool FM_CheckValidChannel(uint8_t Channel)
|
||||
{
|
||||
|
1
fm.h
1
fm.h
@ -24,6 +24,7 @@
|
||||
#define FM_CHANNEL_DOWN 0xFF
|
||||
|
||||
extern uint16_t gFM_Channels[20];
|
||||
extern bool gFmMute;
|
||||
|
||||
bool FM_CheckValidChannel(uint8_t Channel);
|
||||
uint8_t FM_FindNextChannel(uint8_t Channel, uint8_t Direction);
|
||||
|
3
main.c
3
main.c
@ -22,6 +22,7 @@
|
||||
#include "bsp/dp32g030/syscon.h"
|
||||
#include "board.h"
|
||||
#include "driver/crc.h"
|
||||
#include "driver/bk1080.h"
|
||||
#include "driver/bk4819.h"
|
||||
#include "driver/eeprom.h"
|
||||
#include "driver/flash.h"
|
||||
@ -137,8 +138,8 @@ void Main(void)
|
||||
|
||||
RADIO_ConfigureChannel(0, 2);
|
||||
RADIO_ConfigureChannel(1, 2);
|
||||
|
||||
RADIO_ConfigureTX();
|
||||
RADIO_SetupRegisters(true);
|
||||
|
||||
// Below this line is development/test area not conforming to the original firmware
|
||||
|
||||
|
8
misc.c
8
misc.c
@ -51,5 +51,13 @@ uint8_t gEEPROM_1F8E;
|
||||
|
||||
uint8_t gMR_ChannelParameters[207];
|
||||
|
||||
uint8_t g_2000036B;
|
||||
uint8_t g_2000036F;
|
||||
uint8_t g_20000381;
|
||||
|
||||
bool gIsNoaaMode;
|
||||
bool gNoaaChannel;
|
||||
|
||||
uint8_t gCodeType;
|
||||
uint8_t gCode;
|
||||
|
||||
|
8
misc.h
8
misc.h
@ -55,7 +55,15 @@ extern uint8_t gEEPROM_1F8E;
|
||||
|
||||
extern uint8_t gMR_ChannelParameters[207];
|
||||
|
||||
extern uint8_t g_2000036B;
|
||||
extern uint8_t g_2000036F;
|
||||
extern uint8_t g_20000381;
|
||||
|
||||
extern bool gIsNoaaMode;
|
||||
extern bool gNoaaChannel;
|
||||
|
||||
extern uint8_t gCodeType;
|
||||
extern uint8_t gCode;
|
||||
|
||||
#endif
|
||||
|
||||
|
140
radio.c
140
radio.c
@ -15,7 +15,13 @@
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "bsp/dp32g030/gpio.h"
|
||||
#include "dcs.h"
|
||||
#include "driver/bk4819.h"
|
||||
#include "driver/eeprom.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/system.h"
|
||||
#include "fm.h"
|
||||
#include "frequencies.h"
|
||||
#include "misc.h"
|
||||
#include "radio.h"
|
||||
@ -217,38 +223,38 @@ void RADIO_ConfigureChannel(uint8_t RadioNum, uint32_t Arg)
|
||||
|
||||
Tmp = Data[0];
|
||||
switch (gEeprom.RadioInfo[RadioNum].DCS[0].CodeType) {
|
||||
case 1: // CONTINUOUS TONE
|
||||
case CODE_TYPE_CONTINUOUS_TONE:
|
||||
if (Tmp >= 50) {
|
||||
Tmp = 0;
|
||||
}
|
||||
break;
|
||||
case 2: // DIGITAL
|
||||
case 3: // REVERSE_DIGITAL
|
||||
case CODE_TYPE_DIGITAL:
|
||||
case CODE_TYPE_REVERSE_DIGITAL:
|
||||
if (Tmp >= 104) {
|
||||
Tmp = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
gEeprom.RadioInfo[RadioNum].DCS[0].CodeType = 0;
|
||||
gEeprom.RadioInfo[RadioNum].DCS[0].CodeType = CODE_TYPE_OFF;
|
||||
break;
|
||||
}
|
||||
gEeprom.RadioInfo[RadioNum].DCS[0].RX_TX_Code = Tmp;
|
||||
|
||||
Tmp = Data[1];
|
||||
switch (gEeprom.RadioInfo[RadioNum].DCS[1].CodeType) {
|
||||
case 1: // CONTINUOUS TONE
|
||||
case CODE_TYPE_CONTINUOUS_TONE:
|
||||
if (Tmp >= 50) {
|
||||
Tmp = 0;
|
||||
}
|
||||
break;
|
||||
case 2: // DIGITAL
|
||||
case 3: // REVERSE_DIGITAL
|
||||
case CODE_TYPE_DIGITAL:
|
||||
case CODE_TYPE_REVERSE_DIGITAL:
|
||||
if (Tmp >= 104) {
|
||||
Tmp = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
gEeprom.RadioInfo[RadioNum].DCS[1].CodeType = 0;
|
||||
gEeprom.RadioInfo[RadioNum].DCS[1].CodeType = CODE_TYPE_OFF;
|
||||
break;
|
||||
}
|
||||
gEeprom.RadioInfo[RadioNum].DCS[1].RX_TX_Code = Tmp;
|
||||
@ -334,8 +340,8 @@ void RADIO_ConfigureChannel(uint8_t RadioNum, uint32_t Arg)
|
||||
gEeprom.RadioInfo[RadioNum]._0x0033 = true;
|
||||
gEeprom.RadioInfo[RadioNum].SCRAMBLING_TYPE = 0;
|
||||
gEeprom.RadioInfo[RadioNum].DTMF_DECODING_ENABLE = false;
|
||||
gEeprom.RadioInfo[RadioNum].DCS[0].CodeType = 0;
|
||||
gEeprom.RadioInfo[RadioNum].DCS[1].CodeType = 0;
|
||||
gEeprom.RadioInfo[RadioNum].DCS[0].CodeType = CODE_TYPE_OFF;
|
||||
gEeprom.RadioInfo[RadioNum].DCS[1].CodeType = CODE_TYPE_OFF;
|
||||
} else {
|
||||
gEeprom.RadioInfo[RadioNum]._0x0033 = false;
|
||||
}
|
||||
@ -452,3 +458,117 @@ void RADIO_ConfigureCrossTX(void)
|
||||
}
|
||||
}
|
||||
|
||||
void RADIO_SetupRegisters(bool bSwitchToFunction0)
|
||||
{
|
||||
uint8_t Bandwidth;
|
||||
uint16_t Status;
|
||||
uint16_t InterruptMask;
|
||||
uint32_t Frequency;
|
||||
|
||||
GPIO_ClearBit(&GPIOC->DATA, 4);
|
||||
g_2000036B = 0;
|
||||
BK4819_ToggleGpioOut(BK4819_GPIO0_PIN28, false);
|
||||
|
||||
Bandwidth = gRxRadioInfo->CHANNEL_BANDWIDTH;
|
||||
if (Bandwidth != 0) { // != WIDE
|
||||
Bandwidth = 1; // NARROW
|
||||
}
|
||||
BK4819_SetFilterBandwidth(Bandwidth);
|
||||
|
||||
BK4819_ToggleGpioOut(BK4819_GPIO1_PIN29, false);
|
||||
BK4819_SetupPowerAmplifier(0, 0);
|
||||
BK4819_ToggleGpioOut(BK4819_GPIO5_PIN1, false);
|
||||
|
||||
while (1) {
|
||||
Status = BK4819_GetRegister(BK4819_REG_0C_CDCSS_CTCSS_STATUS_VOX_SQ_INTR_INDICATOR);
|
||||
if ((Status & 1U) == 0) { // INTERRUPT REQUEST
|
||||
break;
|
||||
}
|
||||
BK4819_WriteRegister(BK4819_REG_02, 0);
|
||||
SYSTEM_DelayMs(1);
|
||||
}
|
||||
BK4819_WriteRegister(BK4819_REG_3F_INTERRUPT_ENABLE, 0);
|
||||
BK4819_WriteRegister(BK4819_REG_7D_MIC_SENSITIVITY_TUNING, gEeprom.MIC_SENSITIVITY_TUNING | 0xE940);
|
||||
if (gRxRadioInfo->CHANNEL_SAVE < 207 || gIsNoaaMode != false) {
|
||||
Frequency = gRxRadioInfo->pNext->DCS[0].Frequency;
|
||||
} else {
|
||||
Frequency = NoaaFrequencyTable[gNoaaChannel];
|
||||
}
|
||||
BK4819_SetFrequency(Frequency);
|
||||
BK4819_SetupSquelch(gRxRadioInfo->SQ0, gRxRadioInfo->SQ1, gRxRadioInfo->SQ2, gRxRadioInfo->SQ3, gRxRadioInfo->SQ4, gRxRadioInfo->SQ5);
|
||||
BK4819_Configure_GPIO2_PIN30_GPIO3_PIN31(Frequency);
|
||||
BK4819_ToggleGpioOut(BK4819_GPIO6_PIN2, true);
|
||||
BK4819_WriteRegister(BK4819_REG_48_AF_RF_GAIN_DAC_GAIN, 0xB3A8);
|
||||
|
||||
// SQUELCH_LOST SQUELCH_FOUND
|
||||
InterruptMask = 0x000C;
|
||||
|
||||
if (gRxRadioInfo->CHANNEL_SAVE < 207) {
|
||||
if (gRxRadioInfo->_0x0033 != true) {
|
||||
uint8_t CodeType;
|
||||
uint8_t CodeWord;
|
||||
|
||||
CodeType = gCodeType;
|
||||
CodeWord = gCode;
|
||||
if (g_20000381 == 0) {
|
||||
CodeType = gRxRadioInfo->pNext->DCS[0].CodeType;
|
||||
CodeWord = gRxRadioInfo->pNext->DCS[0].RX_TX_Code;
|
||||
}
|
||||
switch (CodeType) {
|
||||
case CODE_TYPE_DIGITAL:
|
||||
case CODE_TYPE_REVERSE_DIGITAL:
|
||||
BK4819_EnableCDCSS(DCS_GetGolayCodeWord(CodeType, CodeWord));
|
||||
// SQUELCH_LOST SQUELCH_FOUND CDCSS_LOST CDCSS_FOUND CTCSS/CDCSS_TAIL_FOUND
|
||||
InterruptMask = 0x070C;
|
||||
break;
|
||||
case CODE_TYPE_CONTINUOUS_TONE:
|
||||
BK4819_EnableCTCSS(CTCSS_Options[CodeWord]);
|
||||
BK4819_Set55HzTailDetection();
|
||||
// SQUELCH_LOST SQUELCH_FOUND CTCSS_LOST CTCSS_FOUND CTCSS/CDCSS_TAIL_FOUND
|
||||
InterruptMask = 0x04CC;
|
||||
break;
|
||||
default:
|
||||
BK4819_EnableCTCSS(670);
|
||||
BK4819_Set55HzTailDetection();
|
||||
// SQUELCH_LOST SQUELCH_FOUND CTCSS/CDCSS_TAIL_FOUND
|
||||
InterruptMask = 0x040C;
|
||||
break;
|
||||
}
|
||||
if (gRxRadioInfo->SCRAMBLING_TYPE == 0 || gSetting_ScrambleEnable == false) {
|
||||
BK4819_DisableScramble();
|
||||
} else {
|
||||
BK4819_EnableScramble(gRxRadioInfo->SCRAMBLING_TYPE - 1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
BK4819_EnableCTCSS(2625);
|
||||
// SQUELCH_LOST SQUELCH_FOUND CTCSS_LOST CTCSS_FOUND
|
||||
InterruptMask = 0x00CC;
|
||||
}
|
||||
|
||||
if (gEeprom.VOX_SWITCH == true && gFmMute != true && gCrossTxRadioInfo->CHANNEL_SAVE < 207 && gCrossTxRadioInfo->_0x0033 != true) {
|
||||
BK4819_EnableVox(gEeprom.VOX1_THRESHOLD, gEeprom.VOX0_THRESHOLD);
|
||||
// VOX_LOST VOX_FOUND
|
||||
InterruptMask |= 0x0030;
|
||||
} else {
|
||||
BK4819_DisableVox();
|
||||
}
|
||||
if ((gRxRadioInfo->_0x0033 == true) || ((gRxRadioInfo->DTMF_DECODING_ENABLE != true && (gSetting_KILLED != true)))) {
|
||||
BK4819_DisableDTMF_SelCall();
|
||||
} else {
|
||||
BK4819_ConfigureDTMF_SelCall_and_UnknownRegister();
|
||||
// DTMF/5TONE_FOUND
|
||||
InterruptMask |= 0x0800;
|
||||
}
|
||||
BK4819_WriteRegister(BK4819_REG_3F_INTERRUPT_ENABLE, InterruptMask);
|
||||
|
||||
// TODO: below only writes values to unknown variables
|
||||
// FUN_0000692c();
|
||||
|
||||
if (bSwitchToFunction0 == 1) {
|
||||
// TODO
|
||||
#if 0
|
||||
SetFunctionSelector(0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
5
radio.h
5
radio.h
@ -27,8 +27,8 @@ enum {
|
||||
};
|
||||
|
||||
enum {
|
||||
RADIO_CHANNEL_UP = 0x01,
|
||||
RADIO_CHANNEL_DOWN = 0xFF,
|
||||
RADIO_CHANNEL_UP = 0x01U,
|
||||
RADIO_CHANNEL_DOWN = 0xFFU,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
@ -81,6 +81,7 @@ void RADIO_ConfigureSquelchAndOutputPower(RADIO_Info_t *pInfo);
|
||||
void RADIO_ApplyDeviation(RADIO_Info_t *pInfo);
|
||||
void RADIO_ConfigureTX(void);
|
||||
void RADIO_ConfigureCrossTX(void);
|
||||
void RADIO_SetupRegisters(bool bSwitchToFunction0);
|
||||
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user