mirror of
https://github.com/OneOfEleven/uv-k5-firmware-custom.git
synced 2025-04-29 14:51:26 +03:00
updates
This commit is contained in:
parent
78da1d5610
commit
ab0c37290f
2
Makefile
2
Makefile
@ -14,7 +14,7 @@ ENABLE_LTO := 1
|
|||||||
ENABLE_UART := 1
|
ENABLE_UART := 1
|
||||||
ENABLE_UART_DEBUG := 1
|
ENABLE_UART_DEBUG := 1
|
||||||
# AirCopy 2.5 kB
|
# AirCopy 2.5 kB
|
||||||
ENABLE_AIRCOPY := 1
|
ENABLE_AIRCOPY := 0
|
||||||
ENABLE_AIRCOPY_REMEMBER_FREQ := 1
|
ENABLE_AIRCOPY_REMEMBER_FREQ := 1
|
||||||
ENABLE_AIRCOPY_RX_REBOOT := 0
|
ENABLE_AIRCOPY_RX_REBOOT := 0
|
||||||
# FM Radio 4.2 kB
|
# FM Radio 4.2 kB
|
||||||
|
@ -30,7 +30,9 @@
|
|||||||
#endif
|
#endif
|
||||||
#include "driver/bk4819.h"
|
#include "driver/bk4819.h"
|
||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
|
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
||||||
#include "driver/uart.h"
|
#include "driver/uart.h"
|
||||||
|
#endif
|
||||||
#include "functions.h"
|
#include "functions.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
@ -28,7 +28,9 @@
|
|||||||
#include "driver/eeprom.h"
|
#include "driver/eeprom.h"
|
||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
#include "driver/system.h"
|
#include "driver/system.h"
|
||||||
|
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
||||||
#include "driver/uart.h"
|
#include "driver/uart.h"
|
||||||
|
#endif
|
||||||
#include "frequencies.h"
|
#include "frequencies.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "radio.h"
|
#include "radio.h"
|
||||||
|
108
app/app.c
108
app/app.c
@ -44,7 +44,9 @@
|
|||||||
#include "driver/keyboard.h"
|
#include "driver/keyboard.h"
|
||||||
#include "driver/st7565.h"
|
#include "driver/st7565.h"
|
||||||
#include "driver/system.h"
|
#include "driver/system.h"
|
||||||
|
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
||||||
#include "driver/uart.h"
|
#include "driver/uart.h"
|
||||||
|
#endif
|
||||||
#include "am_fix.h"
|
#include "am_fix.h"
|
||||||
#include "dtmf.h"
|
#include "dtmf.h"
|
||||||
#include "external/printf/printf.h"
|
#include "external/printf/printf.h"
|
||||||
@ -492,7 +494,7 @@ bool APP_start_listening(function_type_t Function, const bool reset_am_fix)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_MDC1200
|
#ifdef ENABLE_MDC1200
|
||||||
MDC1200_reset_rx();
|
// MDC1200_reset_rx();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// clear the other vfo's rssi level (to hide the antenna symbol)
|
// clear the other vfo's rssi level (to hide the antenna symbol)
|
||||||
@ -920,8 +922,10 @@ void APP_process_radio_interrupts(void)
|
|||||||
while (BK4819_ReadRegister(0x0C) & (1u << 0))
|
while (BK4819_ReadRegister(0x0C) & (1u << 0))
|
||||||
{ // BK chip interrupt request
|
{ // BK chip interrupt request
|
||||||
|
|
||||||
|
uint16_t interrupt_bits;
|
||||||
|
|
||||||
BK4819_WriteRegister(0x02, 0);
|
BK4819_WriteRegister(0x02, 0);
|
||||||
const uint16_t interrupt_bits = BK4819_ReadRegister(0x02);
|
interrupt_bits = BK4819_ReadRegister(0x02);
|
||||||
|
|
||||||
if (interrupt_bits & BK4819_REG_02_DTMF_5TONE_FOUND)
|
if (interrupt_bits & BK4819_REG_02_DTMF_5TONE_FOUND)
|
||||||
{ // save the RX'ed DTMF character
|
{ // save the RX'ed DTMF character
|
||||||
@ -1016,8 +1020,8 @@ void APP_process_radio_interrupts(void)
|
|||||||
|
|
||||||
if (interrupt_bits & BK4819_REG_02_SQUELCH_CLOSED)
|
if (interrupt_bits & BK4819_REG_02_SQUELCH_CLOSED)
|
||||||
{
|
{
|
||||||
BK4819_set_GPIO_pin(BK4819_GPIO6_PIN2_GREEN, false); // LED off
|
|
||||||
g_squelch_open = false;
|
g_squelch_open = false;
|
||||||
|
BK4819_set_GPIO_pin(BK4819_GPIO6_PIN2_GREEN, false); // LED off
|
||||||
|
|
||||||
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
||||||
UART_printf("squelch closed\r\n");
|
UART_printf("squelch closed\r\n");
|
||||||
@ -1026,7 +1030,6 @@ void APP_process_radio_interrupts(void)
|
|||||||
|
|
||||||
if (interrupt_bits & BK4819_REG_02_SQUELCH_OPENED)
|
if (interrupt_bits & BK4819_REG_02_SQUELCH_OPENED)
|
||||||
{
|
{
|
||||||
// BK4819_set_GPIO_pin(BK4819_GPIO6_PIN2_GREEN, true); // LED on
|
|
||||||
g_squelch_open = true;
|
g_squelch_open = true;
|
||||||
|
|
||||||
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
||||||
@ -1036,48 +1039,119 @@ void APP_process_radio_interrupts(void)
|
|||||||
|
|
||||||
#ifdef ENABLE_MDC1200
|
#ifdef ENABLE_MDC1200
|
||||||
{
|
{
|
||||||
const uint16_t sync_flags = BK4819_ReadRegister(0x0B);
|
const uint16_t rx_sync_flags = BK4819_ReadRegister(0x0B);
|
||||||
|
const bool rx_sync_neg = (rx_sync_flags & (1u << 7)) ? true : false;
|
||||||
|
const bool rx_sync_pos = (rx_sync_flags & (1u << 6)) ? true : false;
|
||||||
|
const bool rx_sync = (interrupt_bits & BK4819_REG_02_FSK_RX_SYNC) ? true : false;
|
||||||
|
const bool rx_finished = (interrupt_bits & BK4819_REG_02_FSK_RX_FINISHED) ? true : false;
|
||||||
|
const bool rx_fifo_almost_full = (interrupt_bits & BK4819_REG_02_FSK_FIFO_ALMOST_FULL) ? true : false;
|
||||||
|
|
||||||
// if (sync_flags & ((1u << 7) | (1u << 6)))
|
BK4819_set_GPIO_pin(BK4819_GPIO6_PIN2_GREEN, true); // LED on
|
||||||
// { // RX sync found (pos or neg version)
|
|
||||||
// #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
|
||||||
// UART_printf("fsk rx sync\r\n");
|
|
||||||
// #endif
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (sync_flags & (1u << 7))
|
if (rx_sync_neg)
|
||||||
{ // RX sync neg found
|
{ // RX sync neg found
|
||||||
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
||||||
UART_printf("fsk rx sync neg\r\n");
|
UART_printf("fsk rx sync neg\r\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sync_flags & (1u << 6))
|
if (rx_sync_pos)
|
||||||
{ // RX sync pos found
|
{ // RX sync pos found
|
||||||
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
||||||
UART_printf("fsk rx sync pos\r\n");
|
UART_printf("fsk rx sync pos\r\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (interrupt_bits & BK4819_REG_02_FSK_RX_SYNC)
|
if (rx_sync)
|
||||||
{
|
{
|
||||||
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
||||||
UART_printf("fsk rx sync\r\n");
|
UART_printf("fsk rx sync\r\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (interrupt_bits & BK4819_REG_02_FSK_RX_FINISHED)
|
if (rx_fifo_almost_full)
|
||||||
|
{
|
||||||
|
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
||||||
|
UART_printf("fsk rx almost full\r\n");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rx_finished)
|
||||||
{
|
{
|
||||||
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
||||||
UART_printf("fsk rx finished\r\n");
|
UART_printf("fsk rx finished\r\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (interrupt_bits & BK4819_REG_02_FSK_FIFO_ALMOST_FULL)
|
if (rx_fifo_almost_full)
|
||||||
{
|
{
|
||||||
|
uint8_t buffer[sizeof(mdc1200_sync_suc_xor) + 14];
|
||||||
|
unsigned int i;
|
||||||
|
uint8_t op;
|
||||||
|
uint8_t arg;
|
||||||
|
uint16_t unit_id;
|
||||||
|
const uint16_t fsk_reg59 = BK4819_ReadRegister(0x59) & ~((1u << 15) | (1u << 14) | (1u << 12) | (1u << 11));
|
||||||
|
const unsigned int sync_size = (fsk_reg59 & (1u << 3)) ? 4 : 2;
|
||||||
|
// const unsigned int size = 1 + ((BK4819_ReadRegister(0x5D) >> 8) & 0xffff);
|
||||||
|
const unsigned int size = sizeof(buffer) - sync_size;
|
||||||
|
|
||||||
|
// 40 C4 B0 32 BA F9 33 18 35 08 83 F6 0C C9
|
||||||
|
// 0100000011000100101100000011001010111010111110010011001100011000001101010000100010000011111101100000110011001001
|
||||||
|
|
||||||
|
// 0100000011000100101100000011001010111010111110010011001100011000001101010000100010000011111101100000000011110101
|
||||||
|
// 1011111100111011010011111100110101000101000001101100110011100111110010101111011101111100000010011111111100001010
|
||||||
|
|
||||||
|
// BF 3B 4F CD 45 06 CC E7 CA F7 7C 09 FF 0A
|
||||||
|
|
||||||
|
{ // fetch RX'ed data .. 16-bits at a time
|
||||||
|
|
||||||
|
unsigned int k = 0;
|
||||||
|
|
||||||
|
// precede the data with the missing sync pattern
|
||||||
|
for (i = 0; i < sync_size; i++)
|
||||||
|
buffer[k++] = mdc1200_sync_suc_xor[i] ^ (rx_sync_neg ? 0xff : 0);
|
||||||
|
|
||||||
|
for (i = 0; i < (size / 2); i++)
|
||||||
|
{
|
||||||
|
const uint16_t word = BK4819_ReadRegister(0x5F);
|
||||||
|
buffer[k++] = (word >> 8) & 0xff;
|
||||||
|
buffer[k++] = (word >> 0) & 0xff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// clear FIFO's then enable RX
|
||||||
|
BK4819_WriteRegister(0x59, (1u << 15) | (1u << 14) | fsk_reg59);
|
||||||
|
BK4819_WriteRegister(0x59, (1u << 12) | fsk_reg59);
|
||||||
|
|
||||||
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
||||||
UART_printf("fsk rx almost full\r\n");
|
UART_SendText("fsk rx ");
|
||||||
|
for (i = 0; i < sizeof(buffer); i++)
|
||||||
|
UART_printf(" %02X", buffer[i]);
|
||||||
|
UART_SendText("\r\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (!g_squelch_open)
|
||||||
|
BK4819_set_GPIO_pin(BK4819_GPIO6_PIN2_GREEN, false); // LED off
|
||||||
|
|
||||||
|
if (MDC1200_process_rx(
|
||||||
|
buffer,
|
||||||
|
sizeof(buffer),
|
||||||
|
// (sync_flags & (1u << 7)) ? true : false, // true if the sync pattern is bit inverted
|
||||||
|
&op,
|
||||||
|
&arg,
|
||||||
|
&unit_id))
|
||||||
|
{
|
||||||
|
g_beep_to_play = BEEP_880HZ_60MS_TRIPLE_BEEP;
|
||||||
|
|
||||||
|
// TODO: display the packet
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
||||||
|
UART_printf("MDC1200 op %02X arg %02X id %04X\r\n", op, arg, unit_id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
2
app/fm.c
2
app/fm.c
@ -24,7 +24,9 @@
|
|||||||
#include "driver/bk1080.h"
|
#include "driver/bk1080.h"
|
||||||
#include "driver/eeprom.h"
|
#include "driver/eeprom.h"
|
||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
|
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
||||||
#include "driver/uart.h"
|
#include "driver/uart.h"
|
||||||
|
#endif
|
||||||
#include "frequencies.h"
|
#include "frequencies.h"
|
||||||
#include "functions.h"
|
#include "functions.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
@ -25,7 +25,9 @@
|
|||||||
#include "app/search.h"
|
#include "app/search.h"
|
||||||
#include "audio.h"
|
#include "audio.h"
|
||||||
#include "driver/keyboard.h"
|
#include "driver/keyboard.h"
|
||||||
|
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
||||||
#include "driver/uart.h"
|
#include "driver/uart.h"
|
||||||
|
#endif
|
||||||
#include "dtmf.h"
|
#include "dtmf.h"
|
||||||
#include "external/printf/printf.h"
|
#include "external/printf/printf.h"
|
||||||
#include "functions.h"
|
#include "functions.h"
|
||||||
|
@ -32,7 +32,9 @@
|
|||||||
#include "bsp/dp32g030/gpio.h"
|
#include "bsp/dp32g030/gpio.h"
|
||||||
#include "driver/bk4819.h"
|
#include "driver/bk4819.h"
|
||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
|
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
||||||
#include "driver/uart.h"
|
#include "driver/uart.h"
|
||||||
|
#endif
|
||||||
#include "dtmf.h"
|
#include "dtmf.h"
|
||||||
#include "frequencies.h"
|
#include "frequencies.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
@ -32,7 +32,9 @@
|
|||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
#include "driver/keyboard.h"
|
#include "driver/keyboard.h"
|
||||||
#include "driver/st7565.h"
|
#include "driver/st7565.h"
|
||||||
|
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
||||||
#include "driver/uart.h"
|
#include "driver/uart.h"
|
||||||
|
#endif
|
||||||
#include "frequencies.h"
|
#include "frequencies.h"
|
||||||
#include "helper/battery.h"
|
#include "helper/battery.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
@ -20,7 +20,9 @@
|
|||||||
#include "audio.h"
|
#include "audio.h"
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
#include "driver/bk4819.h"
|
#include "driver/bk4819.h"
|
||||||
|
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
||||||
#include "driver/uart.h"
|
#include "driver/uart.h"
|
||||||
|
#endif
|
||||||
#include "frequencies.h"
|
#include "frequencies.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "radio.h"
|
#include "radio.h"
|
||||||
|
@ -33,7 +33,9 @@
|
|||||||
#include "driver/crc.h"
|
#include "driver/crc.h"
|
||||||
#include "driver/eeprom.h"
|
#include "driver/eeprom.h"
|
||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
|
#if defined(ENABLE_UART)
|
||||||
#include "driver/uart.h"
|
#include "driver/uart.h"
|
||||||
|
#endif
|
||||||
#include "functions.h"
|
#include "functions.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
2
audio.c
2
audio.c
@ -29,7 +29,9 @@
|
|||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
#include "driver/system.h"
|
#include "driver/system.h"
|
||||||
#include "driver/systick.h"
|
#include "driver/systick.h"
|
||||||
|
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
||||||
#include "driver/uart.h"
|
#include "driver/uart.h"
|
||||||
|
#endif
|
||||||
#include "functions.h"
|
#include "functions.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
@ -356,13 +356,13 @@ void BK4819_EnableAGC(void)
|
|||||||
BK4819_WriteRegister(0x11, 0x027B);
|
BK4819_WriteRegister(0x11, 0x027B);
|
||||||
BK4819_WriteRegister(0x10, 0x007A);
|
BK4819_WriteRegister(0x10, 0x007A);
|
||||||
BK4819_WriteRegister(0x14, 0x0018);
|
BK4819_WriteRegister(0x14, 0x0018);
|
||||||
|
/*
|
||||||
// undocumented ?
|
// undocumented ?
|
||||||
BK4819_WriteRegister(0x49, 0x2A38);
|
BK4819_WriteRegister(0x49, 0x2A38);
|
||||||
BK4819_WriteRegister(0x7B, 0x318C);
|
BK4819_WriteRegister(0x7B, 0x318C);
|
||||||
BK4819_WriteRegister(0x7C, 0x595E);
|
BK4819_WriteRegister(0x7C, 0x595E);
|
||||||
BK4819_WriteRegister(0x20, 0x8DEF);
|
BK4819_WriteRegister(0x20, 0x8DEF);
|
||||||
|
*/
|
||||||
// fagci had the answer to why we weren't as sensitive!
|
// fagci had the answer to why we weren't as sensitive!
|
||||||
for (unsigned int i = 0; i < 8; i++)
|
for (unsigned int i = 0; i < 8; i++)
|
||||||
BK4819_WriteRegister(0x06, ((i & 7u) << 13) | (0x4A << 7) | (0x36 << 0));
|
BK4819_WriteRegister(0x06, ((i & 7u) << 13) | (0x4A << 7) | (0x36 << 0));
|
||||||
@ -1149,7 +1149,7 @@ void BK4819_Idle(void)
|
|||||||
{
|
{
|
||||||
BK4819_WriteRegister(0x30, 0);
|
BK4819_WriteRegister(0x30, 0);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
void BK4819_ExitBypass(void)
|
void BK4819_ExitBypass(void)
|
||||||
{
|
{
|
||||||
BK4819_SetAF(BK4819_AF_MUTE);
|
BK4819_SetAF(BK4819_AF_MUTE);
|
||||||
@ -1186,10 +1186,10 @@ void BK4819_ExitBypass(void)
|
|||||||
(5u << 3) | // 5 DC Filter band width for Tx (MIC In)
|
(5u << 3) | // 5 DC Filter band width for Tx (MIC In)
|
||||||
(6u << 0)); // 6 DC Filter band width for Rx (I.F In)
|
(6u << 0)); // 6 DC Filter band width for Rx (I.F In)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
void BK4819_PrepareTransmit(void)
|
void BK4819_PrepareTransmit(void)
|
||||||
{
|
{
|
||||||
BK4819_ExitBypass();
|
// BK4819_ExitBypass();
|
||||||
BK4819_ExitTxMute();
|
BK4819_ExitTxMute();
|
||||||
BK4819_TxOn_Beep();
|
BK4819_TxOn_Beep();
|
||||||
}
|
}
|
||||||
@ -2155,23 +2155,23 @@ void BK4819_reset_fsk(void)
|
|||||||
// 0 = disable
|
// 0 = disable
|
||||||
// 1 = enable
|
// 1 = enable
|
||||||
|
|
||||||
// 0000 0100 1000 1101 1011 1111 0110 0110 0101 1000
|
// REG_5A .. bytes 0 & 1 sync pattern
|
||||||
// 0 4 8 D B F 6 6 5 8
|
|
||||||
//
|
|
||||||
// REG_5A
|
|
||||||
//
|
//
|
||||||
// <15:8> sync byte 0
|
// <15:8> sync byte 0
|
||||||
// < 7:0> sync byte 1
|
// < 7:0> sync byte 1
|
||||||
BK4819_WriteRegister(0x5A, 0x8DBF);
|
BK4819_WriteRegister(0x5A, ((uint16_t)mdc1200_sync_suc_xor[0] << 8) | (mdc1200_sync_suc_xor[1] << 0));
|
||||||
|
|
||||||
|
// REG_5B .. bytes 2 & 3 sync pattern
|
||||||
|
//
|
||||||
// <15:8> sync byte 2
|
// <15:8> sync byte 2
|
||||||
// < 7:0> sync byte 3
|
// < 7:0> sync byte 3
|
||||||
BK4819_WriteRegister(0x5B, 0x6658);
|
BK4819_WriteRegister(0x5B, ((uint16_t)mdc1200_sync_suc_xor[2] << 8) | (mdc1200_sync_suc_xor[3] << 0));
|
||||||
|
|
||||||
// disable CRC
|
// disable CRC
|
||||||
BK4819_WriteRegister(0x5C, 0x5625 | (0u << 6));
|
BK4819_WriteRegister(0x5C, 0x5625 | (0u << 6));
|
||||||
|
|
||||||
// packet size (14 bytes)
|
// packet size .. 14 bytes - size of a single mdc1200 packet
|
||||||
BK4819_WriteRegister(0x5D, ((14u - 1) << 8));
|
BK4819_WriteRegister(0x5D, (((sizeof(mdc1200_sync_suc_xor) - 4 + 14) - 1) << 8));
|
||||||
|
|
||||||
// clear FIFO's then enable RX
|
// clear FIFO's then enable RX
|
||||||
BK4819_WriteRegister(0x59, (1u << 15) | (1u << 14) | fsk_reg59);
|
BK4819_WriteRegister(0x59, (1u << 15) | (1u << 14) | fsk_reg59);
|
||||||
|
@ -118,7 +118,7 @@ void BK4819_TurnsOffTones_TurnsOnRX(void);
|
|||||||
|
|
||||||
void BK4819_reset_fsk(void);
|
void BK4819_reset_fsk(void);
|
||||||
void BK4819_Idle(void);
|
void BK4819_Idle(void);
|
||||||
void BK4819_ExitBypass(void);
|
//void BK4819_ExitBypass(void);
|
||||||
void BK4819_PrepareTransmit(void);
|
void BK4819_PrepareTransmit(void);
|
||||||
void BK4819_TxOn_Beep(void);
|
void BK4819_TxOn_Beep(void);
|
||||||
void BK4819_ExitSubAu(void);
|
void BK4819_ExitSubAu(void);
|
||||||
|
BIN
firmware.bin
BIN
firmware.bin
Binary file not shown.
Binary file not shown.
@ -14,7 +14,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
||||||
#include "driver/uart.h"
|
#include "driver/uart.h"
|
||||||
|
#endif
|
||||||
#include "frequencies.h"
|
#include "frequencies.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
@ -29,7 +29,9 @@
|
|||||||
#include "driver/bk4819.h"
|
#include "driver/bk4819.h"
|
||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
#include "driver/system.h"
|
#include "driver/system.h"
|
||||||
|
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
||||||
#include "driver/uart.h"
|
#include "driver/uart.h"
|
||||||
|
#endif
|
||||||
#include "frequencies.h"
|
#include "frequencies.h"
|
||||||
#include "functions.h"
|
#include "functions.h"
|
||||||
#include "helper/battery.h"
|
#include "helper/battery.h"
|
||||||
|
9
main.c
9
main.c
@ -32,9 +32,14 @@
|
|||||||
#include "driver/st7565.h"
|
#include "driver/st7565.h"
|
||||||
#include "driver/system.h"
|
#include "driver/system.h"
|
||||||
#include "driver/systick.h"
|
#include "driver/systick.h"
|
||||||
|
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
||||||
#include "driver/uart.h"
|
#include "driver/uart.h"
|
||||||
|
#endif
|
||||||
#include "helper/battery.h"
|
#include "helper/battery.h"
|
||||||
#include "helper/boot.h"
|
#include "helper/boot.h"
|
||||||
|
#ifdef ENABLE_MDC1200
|
||||||
|
#include "mdc1200.h"
|
||||||
|
#endif
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "radio.h"
|
#include "radio.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
@ -90,6 +95,10 @@ void Main(void)
|
|||||||
|
|
||||||
BK4819_Init();
|
BK4819_Init();
|
||||||
|
|
||||||
|
#ifdef ENABLE_MDC1200
|
||||||
|
mdc1200_init();
|
||||||
|
#endif
|
||||||
|
|
||||||
BOARD_ADC_GetBatteryInfo(&g_usb_current_voltage, &g_usb_current);
|
BOARD_ADC_GetBatteryInfo(&g_usb_current_voltage, &g_usb_current);
|
||||||
|
|
||||||
BOARD_EEPROM_load();
|
BOARD_EEPROM_load();
|
||||||
|
140
mdc1200.c
140
mdc1200.c
@ -2,7 +2,9 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "driver/crc.h"
|
#include "driver/crc.h"
|
||||||
|
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
||||||
#include "driver/uart.h"
|
#include "driver/uart.h"
|
||||||
|
#endif
|
||||||
#include "mdc1200.h"
|
#include "mdc1200.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
|
||||||
@ -15,9 +17,18 @@
|
|||||||
// >= 24-bit pre-amble
|
// >= 24-bit pre-amble
|
||||||
// 40-bit sync
|
// 40-bit sync
|
||||||
//
|
//
|
||||||
//static const uint8_t pre_amble[] = {0x00, 0x00, 0x00, 0xCC}; / add some bit reversals just before the sync pattern
|
const uint8_t mdc1200_pre_amble[] = {0x00, 0x00, 0x00};
|
||||||
static const uint8_t pre_amble[] = {0x00, 0x00, 0x00};
|
const uint8_t mdc1200_sync[5] = {0x07, 0x09, 0x2a, 0x44, 0x6f};
|
||||||
static const uint8_t sync[] = {0x07, 0x09, 0x2a, 0x44, 0x6f};
|
//
|
||||||
|
// before successive bit xorring:
|
||||||
|
// 0x07092A446F
|
||||||
|
// 0000 0111 0000 1001 0010 1010 0100 0100 0110 1111
|
||||||
|
//
|
||||||
|
// after successive bit xorring:
|
||||||
|
// 0000 0100 1000 1101 1011 1111 0110 0110 0101 1000
|
||||||
|
// 0x048DBF6658
|
||||||
|
//
|
||||||
|
uint8_t mdc1200_sync_suc_xor[sizeof(mdc1200_sync)];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
uint8_t bit_reverse_8(uint8_t n)
|
uint8_t bit_reverse_8(uint8_t n)
|
||||||
@ -52,7 +63,7 @@ uint32_t bit_reverse_32(uint32_t n)
|
|||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
|
|
||||||
uint16_t compute_crc(const uint8_t *data, const unsigned int data_len)
|
uint16_t compute_crc(const void *data, const unsigned int data_len)
|
||||||
{ // let the CPU's hardware do some work :)
|
{ // let the CPU's hardware do some work :)
|
||||||
uint16_t crc;
|
uint16_t crc;
|
||||||
CRC_InitReverse();
|
CRC_InitReverse();
|
||||||
@ -63,14 +74,15 @@ uint32_t bit_reverse_32(uint32_t n)
|
|||||||
|
|
||||||
#elif 1
|
#elif 1
|
||||||
|
|
||||||
uint16_t compute_crc(const uint8_t *data, const unsigned int data_len)
|
uint16_t compute_crc(const void *data, const unsigned int data_len)
|
||||||
{ // using the reverse computation and polynominal avoids having to reverse the bit order during and after
|
{ // using the reverse computation and polynominal avoids having to reverse the bit order during and after
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
const uint8_t *data8 = (const uint8_t *)data;
|
||||||
uint16_t crc = 0;
|
uint16_t crc = 0;
|
||||||
for (i = 0; i < data_len; i++)
|
for (i = 0; i < data_len; i++)
|
||||||
{
|
{
|
||||||
unsigned int k;
|
unsigned int k;
|
||||||
crc ^= data[i];
|
crc ^= data8[i];
|
||||||
for (k = 8; k > 0; k--)
|
for (k = 8; k > 0; k--)
|
||||||
crc = (crc & 1u) ? (crc >> 1) ^ 0x8408 : crc >> 1;
|
crc = (crc & 1u) ? (crc >> 1) ^ 0x8408 : crc >> 1;
|
||||||
}
|
}
|
||||||
@ -79,9 +91,10 @@ uint32_t bit_reverse_32(uint32_t n)
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
uint16_t compute_crc(const uint8_t *data, const unsigned int data_len)
|
uint16_t compute_crc(const void *data, const unsigned int data_len)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
const uint8_t *data8 = (const uint8_t *)data;
|
||||||
uint16_t crc = 0;
|
uint16_t crc = 0;
|
||||||
|
|
||||||
for (i = 0; i < data_len; i++)
|
for (i = 0; i < data_len; i++)
|
||||||
@ -89,7 +102,7 @@ uint32_t bit_reverse_32(uint32_t n)
|
|||||||
uint8_t mask;
|
uint8_t mask;
|
||||||
|
|
||||||
// bit reverse each data byte
|
// bit reverse each data byte
|
||||||
const uint8_t bits = bit_reverse_8(*data++);
|
const uint8_t bits = bit_reverse_8(*data8++);
|
||||||
|
|
||||||
for (mask = 0x0080; mask != 0; mask >>= 1)
|
for (mask = 0x0080; mask != 0; mask >>= 1)
|
||||||
{
|
{
|
||||||
@ -111,16 +124,17 @@ uint32_t bit_reverse_32(uint32_t n)
|
|||||||
// ************************************
|
// ************************************
|
||||||
// RX
|
// RX
|
||||||
|
|
||||||
void error_correction(uint8_t *data)
|
void error_correction(void *data)
|
||||||
{ // can correct up to 3 or 4 corrupted bits (I think)
|
{ // can correct up to 3 or 4 corrupted bits (I think)
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
uint8_t shift_reg;
|
uint8_t shift_reg;
|
||||||
uint8_t syn;
|
uint8_t syn;
|
||||||
|
uint8_t *data8 = (uint8_t *)data;
|
||||||
|
|
||||||
for (i = 0, shift_reg = 0, syn = 0; i < FEC_K; i++)
|
for (i = 0, shift_reg = 0, syn = 0; i < FEC_K; i++)
|
||||||
{
|
{
|
||||||
const uint8_t bi = data[i];
|
const uint8_t bi = data8[i];
|
||||||
int bit_num;
|
int bit_num;
|
||||||
for (bit_num = 0; bit_num < 8; bit_num++)
|
for (bit_num = 0; bit_num < 8; bit_num++)
|
||||||
{
|
{
|
||||||
@ -129,7 +143,7 @@ void error_correction(uint8_t *data)
|
|||||||
|
|
||||||
shift_reg = (shift_reg << 1) | ((bi >> bit_num) & 1u);
|
shift_reg = (shift_reg << 1) | ((bi >> bit_num) & 1u);
|
||||||
b = ((shift_reg >> 6) ^ (shift_reg >> 5) ^ (shift_reg >> 2) ^ (shift_reg >> 0)) & 1u;
|
b = ((shift_reg >> 6) ^ (shift_reg >> 5) ^ (shift_reg >> 2) ^ (shift_reg >> 0)) & 1u;
|
||||||
syn = (syn << 1) | (((b ^ (data[i + FEC_K] >> bit_num)) & 1u) ? 1u : 0u);
|
syn = (syn << 1) | (((b ^ (data8[i + FEC_K] >> bit_num)) & 1u) ? 1u : 0u);
|
||||||
|
|
||||||
if (syn & 0x80) k++;
|
if (syn & 0x80) k++;
|
||||||
if (syn & 0x20) k++;
|
if (syn & 0x20) k++;
|
||||||
@ -146,21 +160,22 @@ void error_correction(uint8_t *data)
|
|||||||
ii--;
|
ii--;
|
||||||
}
|
}
|
||||||
if (ii >= 0)
|
if (ii >= 0)
|
||||||
data[ii] ^= 1u << bn; // fix a bit
|
data8[ii] ^= 1u << bn; // fix a bit
|
||||||
syn ^= 0xA6; // 10100110
|
syn ^= 0xA6; // 10100110
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
void xor_demodulation(uint8_t *data, const unsigned int size, const bool sync_inverted)
|
void xor_demodulation(void *data, const unsigned int size, const bool sync_inverted)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
uint8_t *data8 = (uint8_t *)data;
|
||||||
uint8_t prev_bit = 0;
|
uint8_t prev_bit = 0;
|
||||||
for (i = 0; i < size; i++)
|
for (i = 0; i < size; i++)
|
||||||
{
|
{
|
||||||
int bit_num;
|
int bit_num;
|
||||||
uint8_t in = data[i];
|
uint8_t in = data8[i];
|
||||||
uint8_t out = 0;
|
uint8_t out = 0;
|
||||||
for (bit_num = 7; bit_num >= 0; bit_num--)
|
for (bit_num = 7; bit_num >= 0; bit_num--)
|
||||||
{
|
{
|
||||||
@ -171,14 +186,15 @@ void xor_demodulation(uint8_t *data, const unsigned int size, const bool sync_in
|
|||||||
prev_bit = new_bit;
|
prev_bit = new_bit;
|
||||||
out |= bit << bit_num;
|
out |= bit << bit_num;
|
||||||
}
|
}
|
||||||
data[i] = out;
|
data8[i] = out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
bool decode_data(uint8_t *data)
|
bool decode_data(void *data)
|
||||||
{
|
{
|
||||||
uint16_t crc1;
|
uint16_t crc1;
|
||||||
uint16_t crc2;
|
uint16_t crc2;
|
||||||
|
uint8_t *data8 = (uint8_t *)data;
|
||||||
|
|
||||||
{ // de-interleave
|
{ // de-interleave
|
||||||
|
|
||||||
@ -211,7 +227,7 @@ bool decode_data(uint8_t *data)
|
|||||||
for (m = 0; m < FEC_K; m++)
|
for (m = 0; m < FEC_K; m++)
|
||||||
{
|
{
|
||||||
const unsigned int n = (m * 16) + i;
|
const unsigned int n = (m * 16) + i;
|
||||||
deinterleaved[k++] = (data[n >> 3] >> ((7 - n) & 7u)) & 1u;
|
deinterleaved[k++] = (data8[n >> 3] >> ((7 - n) & 7u)) & 1u;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,7 +239,7 @@ bool decode_data(uint8_t *data)
|
|||||||
for (k = 0; k < 8; k++)
|
for (k = 0; k < 8; k++)
|
||||||
if (deinterleaved[m++])
|
if (deinterleaved[m++])
|
||||||
b |= 1u << k;
|
b |= 1u << k;
|
||||||
data[i] = b;
|
data8[i] = b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,7 +252,7 @@ bool decode_data(uint8_t *data)
|
|||||||
// 01 80 1234 2E3E 00 6580A862DD8808
|
// 01 80 1234 2E3E 00 6580A862DD8808
|
||||||
|
|
||||||
crc1 = compute_crc(data, 4);
|
crc1 = compute_crc(data, 4);
|
||||||
crc2 = ((uint16_t)data[5] << 8) | (data[4] << 0);
|
crc2 = ((uint16_t)data8[5] << 8) | (data8[4] << 0);
|
||||||
|
|
||||||
return (crc1 == crc2) ? true : false;
|
return (crc1 == crc2) ? true : false;
|
||||||
}
|
}
|
||||||
@ -244,14 +260,15 @@ bool decode_data(uint8_t *data)
|
|||||||
// **********************************************************
|
// **********************************************************
|
||||||
// TX
|
// TX
|
||||||
|
|
||||||
void xor_modulation(uint8_t *data, const unsigned int size)
|
void xor_modulation(void *data, const unsigned int size)
|
||||||
{ // exclusive-or succesive bits - the entire packet
|
{ // exclusive-or succesive bits - the entire packet
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
uint8_t *data8 = (uint8_t *)data;
|
||||||
uint8_t prev_bit = 0;
|
uint8_t prev_bit = 0;
|
||||||
for (i = 0; i < size; i++)
|
for (i = 0; i < size; i++)
|
||||||
{
|
{
|
||||||
int bit_num;
|
int bit_num;
|
||||||
uint8_t in = data[i];
|
uint8_t in = data8[i];
|
||||||
uint8_t out = 0;
|
uint8_t out = 0;
|
||||||
for (bit_num = 7; bit_num >= 0; bit_num--)
|
for (bit_num = 7; bit_num >= 0; bit_num--)
|
||||||
{
|
{
|
||||||
@ -260,11 +277,11 @@ void xor_modulation(uint8_t *data, const unsigned int size)
|
|||||||
out |= 1u << bit_num; // previous bit and new bit are different - send a '1'
|
out |= 1u << bit_num; // previous bit and new bit are different - send a '1'
|
||||||
prev_bit = new_bit;
|
prev_bit = new_bit;
|
||||||
}
|
}
|
||||||
data[i] = out ^ 0xff;
|
data8[i] = out ^ 0xff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t * encode_data(uint8_t *data)
|
uint8_t * encode_data(void *data)
|
||||||
{
|
{
|
||||||
// R=1/2 K=7 convolutional coder
|
// R=1/2 K=7 convolutional coder
|
||||||
//
|
//
|
||||||
@ -276,20 +293,22 @@ uint8_t * encode_data(uint8_t *data)
|
|||||||
// 3. for each bit, calculate the modulo-2 sum: bit(n-0) + bit(n-2) + bit(n-5) + bit(n-6)
|
// 3. for each bit, calculate the modulo-2 sum: bit(n-0) + bit(n-2) + bit(n-5) + bit(n-6)
|
||||||
// 4. then for each byte of resulting output, again reverse those bits to generate the values shown above
|
// 4. then for each byte of resulting output, again reverse those bits to generate the values shown above
|
||||||
|
|
||||||
|
uint8_t *data8 = (uint8_t *)data;
|
||||||
|
|
||||||
{ // add the FEC bits to the end of the data
|
{ // add the FEC bits to the end of the data
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
uint8_t shift_reg = 0;
|
uint8_t shift_reg = 0;
|
||||||
for (i = 0; i < FEC_K; i++)
|
for (i = 0; i < FEC_K; i++)
|
||||||
{
|
{
|
||||||
unsigned int bit_num;
|
unsigned int bit_num;
|
||||||
const uint8_t bi = data[i];
|
const uint8_t bi = data8[i];
|
||||||
uint8_t bo = 0;
|
uint8_t bo = 0;
|
||||||
for (bit_num = 0; bit_num < 8; bit_num++)
|
for (bit_num = 0; bit_num < 8; bit_num++)
|
||||||
{
|
{
|
||||||
shift_reg = (shift_reg << 1) | ((bi >> bit_num) & 1u);
|
shift_reg = (shift_reg << 1) | ((bi >> bit_num) & 1u);
|
||||||
bo |= (((shift_reg >> 6) ^ (shift_reg >> 5) ^ (shift_reg >> 2) ^ (shift_reg >> 0)) & 1u) << bit_num;
|
bo |= (((shift_reg >> 6) ^ (shift_reg >> 5) ^ (shift_reg >> 2) ^ (shift_reg >> 0)) & 1u) << bit_num;
|
||||||
}
|
}
|
||||||
data[FEC_K + i] = bo;
|
data8[FEC_K + i] = bo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,7 +320,7 @@ uint8_t * encode_data(uint8_t *data)
|
|||||||
unsigned int i;
|
unsigned int i;
|
||||||
UART_printf("mdc1200 tx1 %u ", size);
|
UART_printf("mdc1200 tx1 %u ", size);
|
||||||
for (i = 0; i < size; i++)
|
for (i = 0; i < size; i++)
|
||||||
UART_printf(" %02X", data[i]);
|
UART_printf(" %02X", data8[i]);
|
||||||
UART_SendText("\r\n");
|
UART_SendText("\r\n");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -310,7 +329,7 @@ uint8_t * encode_data(uint8_t *data)
|
|||||||
|
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
unsigned int k;
|
unsigned int k;
|
||||||
uint8_t interleaved[(FEC_K * 2) * 8];
|
uint8_t interleaved[(FEC_K * 2) * 8]; // temp individual bit storage
|
||||||
|
|
||||||
// interleave order
|
// interleave order
|
||||||
// 0, 16, 32, 48, 64, 80, 96,
|
// 0, 16, 32, 48, 64, 80, 96,
|
||||||
@ -334,7 +353,7 @@ uint8_t * encode_data(uint8_t *data)
|
|||||||
for (i = 0, k = 0; i < (FEC_K * 2); i++)
|
for (i = 0, k = 0; i < (FEC_K * 2); i++)
|
||||||
{
|
{
|
||||||
unsigned int bit_num;
|
unsigned int bit_num;
|
||||||
const uint8_t b = data[i];
|
const uint8_t b = data8[i];
|
||||||
for (bit_num = 0; bit_num < 8; bit_num++)
|
for (bit_num = 0; bit_num < 8; bit_num++)
|
||||||
{
|
{
|
||||||
interleaved[k] = (b >> bit_num) & 1u;
|
interleaved[k] = (b >> bit_num) & 1u;
|
||||||
@ -352,23 +371,23 @@ uint8_t * encode_data(uint8_t *data)
|
|||||||
for (bit_num = 7; bit_num >= 0; bit_num--)
|
for (bit_num = 7; bit_num >= 0; bit_num--)
|
||||||
if (interleaved[k++])
|
if (interleaved[k++])
|
||||||
b |= 1u << bit_num;
|
b |= 1u << bit_num;
|
||||||
data[i] = b;
|
data8[i] = b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return data + (FEC_K * 2);
|
return data8 + (FEC_K * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int MDC1200_encode_single_packet(uint8_t *data, const uint8_t op, const uint8_t arg, const uint16_t unit_id)
|
unsigned int MDC1200_encode_single_packet(void *data, const uint8_t op, const uint8_t arg, const uint16_t unit_id)
|
||||||
{
|
{
|
||||||
unsigned int size;
|
unsigned int size;
|
||||||
uint16_t crc;
|
uint16_t crc;
|
||||||
uint8_t *p = data;
|
uint8_t *p = (uint8_t *)data;
|
||||||
|
|
||||||
memcpy(p, pre_amble, sizeof(pre_amble));
|
memcpy(p, mdc1200_pre_amble, sizeof(mdc1200_pre_amble));
|
||||||
p += sizeof(pre_amble);
|
p += sizeof(mdc1200_pre_amble);
|
||||||
memcpy(p, sync, sizeof(sync));
|
memcpy(p, mdc1200_sync, sizeof(mdc1200_sync));
|
||||||
p += sizeof(sync);
|
p += sizeof(mdc1200_sync);
|
||||||
|
|
||||||
p[0] = op;
|
p[0] = op;
|
||||||
p[1] = arg;
|
p[1] = arg;
|
||||||
@ -381,14 +400,15 @@ unsigned int MDC1200_encode_single_packet(uint8_t *data, const uint8_t op, const
|
|||||||
|
|
||||||
p = encode_data(p);
|
p = encode_data(p);
|
||||||
|
|
||||||
size = (unsigned int)(p - data);
|
size = (unsigned int)(p - (uint8_t *)data);
|
||||||
/*
|
/*
|
||||||
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
const uint8_t *data8 = (const uint8_t *)data;
|
||||||
UART_printf("mdc1200 tx2 %u ", size);
|
UART_printf("mdc1200 tx2 %u ", size);
|
||||||
for (i = 0; i < size; i++)
|
for (i = 0; i < size; i++)
|
||||||
UART_printf(" %02X", data[i]);
|
UART_printf(" %02X", data8[i]);
|
||||||
UART_SendText("\r\n");
|
UART_SendText("\r\n");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -398,16 +418,16 @@ unsigned int MDC1200_encode_single_packet(uint8_t *data, const uint8_t op, const
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
unsigned int MDC1200_encode_double_packet(uint8_t *data, const uint8_t op, const uint8_t arg, const uint16_t unit_id, const uint8_t b0, const uint8_t b1, const uint8_t b2, const uint8_t b3)
|
unsigned int MDC1200_encode_double_packet(void *data, const uint8_t op, const uint8_t arg, const uint16_t unit_id, const uint8_t b0, const uint8_t b1, const uint8_t b2, const uint8_t b3)
|
||||||
{
|
{
|
||||||
unsigned int size;
|
unsigned int size;
|
||||||
uint16_t crc;
|
uint16_t crc;
|
||||||
uint8_t *p = data;
|
uint8_t *p = (uint8_t *)data;
|
||||||
|
|
||||||
memcpy(p, pre_amble, sizeof(pre_amble));
|
memcpy(p, mdc1200_pre_amble, sizeof(mdc1200_pre_amble));
|
||||||
p += sizeof(pre_amble);
|
p += sizeof(mdc1200_pre_amble);
|
||||||
memcpy(p, sync, sizeof(sync));
|
memcpy(p, mdc1200_sync, sizeof(mdc1200_sync));
|
||||||
p += sizeof(sync);
|
p += sizeof(mdc1200_sync);
|
||||||
|
|
||||||
p[0] = op;
|
p[0] = op;
|
||||||
p[1] = arg;
|
p[1] = arg;
|
||||||
@ -431,7 +451,7 @@ unsigned int MDC1200_encode_double_packet(uint8_t *data, const uint8_t op, const
|
|||||||
|
|
||||||
p = encode_data(p);
|
p = encode_data(p);
|
||||||
|
|
||||||
size = (unsigned int)(p - data);
|
size = (unsigned int)(p - (uint8_t *)data);
|
||||||
|
|
||||||
xor_modulation(data, size);
|
xor_modulation(data, size);
|
||||||
|
|
||||||
@ -459,16 +479,31 @@ void MDC1200_reset_rx(void)
|
|||||||
memset(&rx, 0, sizeof(rx));
|
memset(&rx, 0, sizeof(rx));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MDC1200_process_rx(const uint8_t rx_byte, uint8_t *op, uint8_t *arg, uint16_t *unit_id)
|
bool MDC1200_process_rx(
|
||||||
|
const void *buffer,
|
||||||
|
const unsigned int size,
|
||||||
|
//const bool inverted,
|
||||||
|
uint8_t *op,
|
||||||
|
uint8_t *arg,
|
||||||
|
uint16_t *unit_id)
|
||||||
|
{
|
||||||
|
const uint8_t *buffer8 = (const uint8_t *)buffer;
|
||||||
|
unsigned int index;
|
||||||
|
|
||||||
|
memset(&rx, 0, sizeof(rx));
|
||||||
|
|
||||||
|
for (index = 0; index < size; index++)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
int k;
|
int bit;
|
||||||
|
|
||||||
for (k = 7; k >= 0; k--)
|
const uint8_t rx_byte = buffer8[index];
|
||||||
|
|
||||||
|
for (bit = 7; bit >= 0; bit--)
|
||||||
{
|
{
|
||||||
rx.prev_bit = rx.bit;
|
rx.prev_bit = rx.bit;
|
||||||
|
|
||||||
rx.bit = (rx_byte >> k) & 1u;
|
rx.bit = (rx_byte >> bit) & 1u;
|
||||||
|
|
||||||
if (rx.stage == 0)
|
if (rx.stage == 0)
|
||||||
{ // scanning for the pre-amble
|
{ // scanning for the pre-amble
|
||||||
@ -624,6 +659,7 @@ bool MDC1200_process_rx(const uint8_t rx_byte, uint8_t *op, uint8_t *arg, uint16
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -638,3 +674,9 @@ void test(void)
|
|||||||
// const int size = MDC1200_encode_double_packet(data, 0x55, 0x34, 0x5678, 0x0a, 0x0b, 0x0c, 0x0d);
|
// const int size = MDC1200_encode_double_packet(data, 0x55, 0x34, 0x5678, 0x0a, 0x0b, 0x0c, 0x0d);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
void mdc1200_init(void)
|
||||||
|
{
|
||||||
|
memcpy(mdc1200_sync_suc_xor, mdc1200_sync, sizeof(mdc1200_sync));
|
||||||
|
xor_modulation(mdc1200_sync_suc_xor, sizeof(mdc1200_sync_suc_xor));
|
||||||
|
}
|
||||||
|
18
mdc1200.h
18
mdc1200.h
@ -85,11 +85,23 @@ enum mdc1200_op_code_e {
|
|||||||
MDC1200_OP_CODE_MSG_XX = 0x47,
|
MDC1200_OP_CODE_MSG_XX = 0x47,
|
||||||
MDC1200_OP_CODE_RADIO_CHECK = 0x63
|
MDC1200_OP_CODE_RADIO_CHECK = 0x63
|
||||||
};
|
};
|
||||||
|
typedef enum mdc1200_op_code_e mdc1200_op_code_t;
|
||||||
|
|
||||||
unsigned int MDC1200_encode_single_packet(uint8_t *data, const uint8_t op, const uint8_t arg, const uint16_t unit_id);
|
extern const uint8_t mdc1200_sync[5];
|
||||||
//unsigned int MDC1200_encode_double_packet(uint8_t *data, const uint8_t op, const uint8_t arg, const uint16_t unit_id, const uint8_t b0, const uint8_t b1, const uint8_t b2, const uint8_t b3);
|
extern uint8_t mdc1200_sync_suc_xor[sizeof(mdc1200_sync)];
|
||||||
|
|
||||||
|
unsigned int MDC1200_encode_single_packet(void *data, const uint8_t op, const uint8_t arg, const uint16_t unit_id);
|
||||||
|
//unsigned int MDC1200_encode_double_packet(void *data, const uint8_t op, const uint8_t arg, const uint16_t unit_id, const uint8_t b0, const uint8_t b1, const uint8_t b2, const uint8_t b3);
|
||||||
|
|
||||||
void MDC1200_reset_rx(void);
|
void MDC1200_reset_rx(void);
|
||||||
bool MDC1200_process_rx(const uint8_t rx_byte, uint8_t *op, uint8_t *arg, uint16_t *unit_id);
|
bool MDC1200_process_rx(
|
||||||
|
const void *buffer,
|
||||||
|
const unsigned int size,
|
||||||
|
//const bool inverted,
|
||||||
|
uint8_t *op,
|
||||||
|
uint8_t *arg,
|
||||||
|
uint16_t *unit_id);
|
||||||
|
|
||||||
|
void mdc1200_init(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -20,7 +20,9 @@
|
|||||||
#include "app/fm.h"
|
#include "app/fm.h"
|
||||||
#endif
|
#endif
|
||||||
#include "driver/eeprom.h"
|
#include "driver/eeprom.h"
|
||||||
|
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
||||||
#include "driver/uart.h"
|
#include "driver/uart.h"
|
||||||
|
#endif
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
|
@ -26,7 +26,9 @@
|
|||||||
#include "driver/bk4819.h"
|
#include "driver/bk4819.h"
|
||||||
#include "driver/eeprom.h" // EEPROM_ReadBuffer()
|
#include "driver/eeprom.h" // EEPROM_ReadBuffer()
|
||||||
#include "driver/st7565.h"
|
#include "driver/st7565.h"
|
||||||
|
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
||||||
#include "driver/uart.h"
|
#include "driver/uart.h"
|
||||||
|
#endif
|
||||||
#include "external/printf/printf.h"
|
#include "external/printf/printf.h"
|
||||||
#include "frequencies.h"
|
#include "frequencies.h"
|
||||||
#include "helper/battery.h"
|
#include "helper/battery.h"
|
||||||
|
@ -99,11 +99,10 @@ void UI_DisplayStatus(const bool test_display)
|
|||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
// SCAN indicator
|
// SCAN indicator
|
||||||
if (g_scan_state_dir != SCAN_STATE_DIR_OFF ||
|
if (g_scan_state_dir != SCAN_STATE_DIR_OFF || test_display)
|
||||||
g_screen_to_display == DISPLAY_SEARCH ||
|
|
||||||
test_display)
|
|
||||||
{
|
{
|
||||||
if (g_search_css_state == SEARCH_CSS_STATE_OFF) // don't display this if in search mode
|
// don't display this if in search mode
|
||||||
|
if (g_screen_to_display != DISPLAY_SEARCH)
|
||||||
{
|
{
|
||||||
if (g_scan_next_channel <= USER_CHANNEL_LAST)
|
if (g_scan_next_channel <= USER_CHANNEL_LAST)
|
||||||
{ // channel mode
|
{ // channel mode
|
||||||
|
Loading…
x
Reference in New Issue
Block a user