diff --git a/Makefile b/Makefile index 47410d4..c02331f 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ ENABLE_OVERLAY := 0 ENABLE_LTO := 1 # UART Programming 2.9 kB ENABLE_UART := 1 -ENABLE_UART_DEBUG := 1 +ENABLE_UART_DEBUG := 0 # AirCopy 2.5 kB ENABLE_AIRCOPY := 1 ENABLE_AIRCOPY_REMEMBER_FREQ := 1 @@ -37,7 +37,7 @@ ENABLE_MDC1200 := 1 ENABLE_PWRON_PASSWORD := 0 ENABLE_RESET_AES_KEY := 1 ENABLE_BIG_FREQ := 0 -ENABLE_SMALL_BOLD := 0 +ENABLE_SMALL_BOLD := 1 ENABLE_TRIM_TRAILING_ZEROS := 1 ENABLE_KEEP_MEM_NAME := 1 ENABLE_WIDE_RX := 1 diff --git a/app/main.c b/app/main.c index 104f540..1fb1541 100644 --- a/app/main.c +++ b/app/main.c @@ -525,9 +525,7 @@ void MAIN_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held) // clamp the frequency entered to some valid value if (Frequency < FREQ_BAND_TABLE[0].lower) - { Frequency = FREQ_BAND_TABLE[0].lower; - } else if (Frequency >= BX4819_BAND1.upper && Frequency < BX4819_BAND2.lower) { @@ -536,9 +534,7 @@ void MAIN_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held) } else if (Frequency > FREQ_BAND_TABLE[ARRAY_SIZE(FREQ_BAND_TABLE) - 1].upper) - { Frequency = FREQ_BAND_TABLE[ARRAY_SIZE(FREQ_BAND_TABLE) - 1].upper; - } { const frequency_band_t band = FREQUENCY_GetBand(Frequency); @@ -559,7 +555,6 @@ void MAIN_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held) } Frequency += g_tx_vfo->step_freq / 2; // for rounding to nearest step size - Frequency = FREQUENCY_floor_to_step(Frequency, g_tx_vfo->step_freq, FREQ_BAND_TABLE[g_tx_vfo->band].lower, FREQ_BAND_TABLE[g_tx_vfo->band].upper); if (Frequency >= BX4819_BAND1.upper && Frequency < BX4819_BAND2.lower) @@ -569,18 +564,13 @@ void MAIN_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held) } g_tx_vfo->freq_config_rx.frequency = Frequency; + g_tx_vfo->freq_config_tx.frequency = Frequency; // find the first channel that contains this frequency g_tx_vfo->freq_in_channel = BOARD_find_channel(Frequency); - // 1of11 .. test to prevent monitor mode being turned off - #if 0 - // this currently also turns monitor mode off :( - g_request_save_channel = 1; - #else - SETTINGS_save_channel(g_tx_vfo->channel_save, g_eeprom.tx_vfo, g_tx_vfo, 1); - RADIO_setup_registers(true); - #endif + g_request_save_channel = 1; + g_vfo_configure_mode = VFO_CONFIGURE; return; } diff --git a/driver/bk4819.c b/driver/bk4819.c index fbd46b7..fc963ba 100644 --- a/driver/bk4819.c +++ b/driver/bk4819.c @@ -195,22 +195,13 @@ void BK4819_WriteRegister(bk4819_register_t Register, uint16_t Data) { GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCN); GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL); - SYSTICK_DelayUs(1); - GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCN); BK4819_WriteU8(Register); - - SYSTICK_DelayUs(1); - BK4819_WriteU16(Data); - SYSTICK_DelayUs(1); - GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCN); - SYSTICK_DelayUs(1); - GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL); GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SDA); } diff --git a/firmware.bin b/firmware.bin index fb5fe82..42c6df8 100644 Binary files a/firmware.bin and b/firmware.bin differ diff --git a/firmware.packed.bin b/firmware.packed.bin index 0284bcd..8076513 100644 Binary files a/firmware.packed.bin and b/firmware.packed.bin differ diff --git a/mdc1200.c b/mdc1200.c index 8264670..0a203b8 100644 --- a/mdc1200.c +++ b/mdc1200.c @@ -8,10 +8,11 @@ // MDC1200 sync bit reversals and packet sync // -// 24-bit pre-amble +// >= 24-bit pre-amble // 40-bit sync // -static const uint8_t header[] = {0x55, 0x55, 0x55, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x07, 0x09, 0x2a, 0x44, 0x6f}; +static const uint8_t pre_amble[] = {0x55, 0x55, 0x55, 0x00, 0x00, 0x00, 0x00, 0x0A}; +static const uint8_t sync[] = {0x07, 0x09, 0x2a, 0x44, 0x6f}; uint8_t bit_reverse_8(uint8_t n) { @@ -170,13 +171,11 @@ void error_correction(uint8_t *data) } } -uint8_t * decode_data(uint8_t *data) +bool MDC1200_decode_data(uint8_t *data) { uint16_t crc1; uint16_t crc2; -// (void)data; - { // de-interleave unsigned int i; @@ -184,6 +183,24 @@ uint8_t * decode_data(uint8_t *data) unsigned int m; uint8_t deinterleaved[(FEC_K * 2) * 8]; + // interleave order + // 0, 16, 32, 48, 64, 80, 96, + // 1, 17, 33, 49, 65, 81, 97, + // 2, 18, 34, 50, 66, 82, 98, + // 3, 19, 35, 51, 67, 83, 99, + // 4, 20, 36, 52, 68, 84, 100, + // 5, 21, 37, 53, 69, 85, 101, + // 6, 22, 38, 54, 70, 86, 102, + // 7, 23, 39, 55, 71, 87, 103, + // 8, 24, 40, 56, 72, 88, 104, + // 9, 25, 41, 57, 73, 89, 105, + // 10, 26, 42, 58, 74, 90, 106, + // 11, 27, 43, 59, 75, 91, 107, + // 12, 28, 44, 60, 76, 92, 108, + // 13, 29, 45, 61, 77, 93, 109, + // 14, 30, 46, 62, 78, 94, 110, + // 15, 31, 47, 63, 79, 95, 111 + // de-interleave the received bits for (i = 0, k = 0; i < 16; i++) { @@ -212,9 +229,9 @@ uint8_t * decode_data(uint8_t *data) crc2 = (data[5] << 8) | (data[4] << 0); if (crc1 != crc2) - return NULL; + return false; - // appears to be a valid packet + // valid packet @@ -223,7 +240,7 @@ uint8_t * decode_data(uint8_t *data) - return NULL; + return true; } uint8_t * encode_data(uint8_t *data) @@ -276,11 +293,28 @@ uint8_t * encode_data(uint8_t *data) unsigned int i; unsigned int k; - unsigned int m; uint8_t interleaved[(FEC_K * 2) * 8]; + // interleave order + // 0, 16, 32, 48, 64, 80, 96, + // 1, 17, 33, 49, 65, 81, 97, + // 2, 18, 34, 50, 66, 82, 98, + // 3, 19, 35, 51, 67, 83, 99, + // 4, 20, 36, 52, 68, 84, 100, + // 5, 21, 37, 53, 69, 85, 101, + // 6, 22, 38, 54, 70, 86, 102, + // 7, 23, 39, 55, 71, 87, 103, + // 8, 24, 40, 56, 72, 88, 104, + // 9, 25, 41, 57, 73, 89, 105, + // 10, 26, 42, 58, 74, 90, 106, + // 11, 27, 43, 59, 75, 91, 107, + // 12, 28, 44, 60, 76, 92, 108, + // 13, 29, 45, 61, 77, 93, 109, + // 14, 30, 46, 62, 78, 94, 110, + // 15, 31, 47, 63, 79, 95, 111 + // bit interleaver - for (i = 0, k = 0, m = 0; i < (FEC_K * 2); i++) + for (i = 0, k = 0; i < (FEC_K * 2); i++) { unsigned int bit_num; const uint8_t b = data[i]; @@ -289,7 +323,7 @@ uint8_t * encode_data(uint8_t *data) interleaved[k] = (b >> bit_num) & 1u; k += 16; if (k >= sizeof(interleaved)) - k = ++m; + k -= sizeof(interleaved) - 1; } } @@ -334,8 +368,10 @@ unsigned int MDC1200_encode_single_packet(uint8_t *data, const uint8_t op, const uint16_t crc; uint8_t *p = data; - memcpy(p, header, sizeof(header)); - p += sizeof(header); + memcpy(p, pre_amble, sizeof(pre_amble)); + p += sizeof(pre_amble); + memcpy(p, sync, sizeof(sync)); + p += sizeof(sync); p[0] = op; p[1] = arg; @@ -363,17 +399,18 @@ unsigned int MDC1200_encode_single_packet(uint8_t *data, const uint8_t op, const delta_modulation(data, size); return size; -// return 26; } - +/* 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 size; uint16_t crc; uint8_t *p = data; - memcpy(p, header, sizeof(header)); - p += sizeof(header); + memcpy(p, pre_amble, sizeof(pre_amble)); + p += sizeof(pre_amble); + memcpy(p, sync, sizeof(sync)); + p += sizeof(sync); p[0] = op; p[1] = arg; @@ -402,15 +439,13 @@ unsigned int MDC1200_encode_double_packet(uint8_t *data, const uint8_t op, const delta_modulation(data, size); return size; -// return 40; } +*/ /* void test(void) { - uint8_t data[14 + 14 + 5 + 7]; - + uint8_t data[42]; const int size = MDC1200_encode_single_packet(data, 0x12, 0x34, 0x5678); - // const int size = MDC1200_encode_double_packet(data, 0x55, 0x34, 0x5678, 0x0a, 0x0b, 0x0c, 0x0d); } */ \ No newline at end of file diff --git a/mdc1200.h b/mdc1200.h index f0d8c5a..321bfac 100644 --- a/mdc1200.h +++ b/mdc1200.h @@ -3,6 +3,7 @@ #define MDC1200H #include +#include // 0x00 (0x81) emergency alarm // 0x20 (0x00) emergency alarm ack @@ -85,6 +86,7 @@ enum mdc1200_op_code_e { MDC1200_OP_CODE_RADIO_CHECK = 0x63 }; +bool MDC1200_decode_data(uint8_t *data); 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_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);