Skip to content

Commit

Permalink
Fix TX power setting (I broke it previous commit)
Browse files Browse the repository at this point in the history
  • Loading branch information
OneOfEleven committed Oct 8, 2023
1 parent 0bb34d2 commit 16d5130
Show file tree
Hide file tree
Showing 18 changed files with 214 additions and 156 deletions.
18 changes: 13 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ ENABLE_SWD := 0
ENABLE_OVERLAY := 0
ENABLE_LTO := 1
ENABLE_UART := 1
ENABLE_AIRCOPY := 0
ENABLE_UART_DEBUG := 0
ENABLE_AIRCOPY := 1
ENABLE_FMRADIO := 1
ENABLE_NOAA := 1
ENABLE_VOICE := 1
ENABLE_VOICE := 0
ENABLE_VOX := 1
ENABLE_ALARM := 1
ENABLE_TX1750 := 1
ENABLE_PWRON_PASSWORD := 1
ENABLE_PWRON_PASSWORD := 0
ENABLE_BIG_FREQ := 0
ENABLE_SMALL_BOLD := 1
ENABLE_KEEP_MEM_NAME := 1
Expand All @@ -36,8 +37,8 @@ ENABLE_RSSI_BAR := 1
ENABLE_SHOW_TX_TIMEOUT := 1
ENABLE_AUDIO_BAR := 0
ENABLE_COPY_CHAN_TO_VFO := 1
#ENABLE_PANADAPTER := 1
#ENABLE_SINGLE_VFO_CHAN := 1
#ENABLE_PANADAPTER := 0
#ENABLE_SINGLE_VFO_CHAN := 0

#############################################################

Expand All @@ -58,6 +59,10 @@ ifeq ($(ENABLE_SHOW_TX_TIMEOUT),1)
ENABLE_AUDIO_BAR := 0
endif

ifeq ($(ENABLE_UART_DEBUG),1)
ENABLE_UART := 1
endif

BSP_DEFINITIONS := $(wildcard hardware/*/*.def)
BSP_HEADERS := $(patsubst hardware/%,bsp/%,$(BSP_DEFINITIONS))
BSP_HEADERS := $(patsubst %.def,%.h,$(BSP_HEADERS))
Expand Down Expand Up @@ -234,6 +239,9 @@ endif
ifeq ($(ENABLE_UART),1)
CFLAGS += -DENABLE_UART
endif
ifeq ($(ENABLE_UART_DEBUG),1)
CFLAGS += -DENABLE_UART_DEBUG
endif
ifeq ($(ENABLE_BIG_FREQ),1)
CFLAGS += -DENABLE_BIG_FREQ
endif
Expand Down
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ ENABLE_CLANG := 0 **experimental, builds with clang instead
ENABLE_SWD := 0 only needed if using CPU's SWD port (debugging/programming)
ENABLE_OVERLAY := 0 cpu FLASH stuff, not needed
ENABLE_LTO := 0 **experimental, reduces size of compiled firmware but might break EEPROM reads (OVERLAY will be disabled if you enable this)
ENABLE_UART := 1 without this you can't configure radio via PC !
ENABLE_UART := 1 without this you can't configure radio via PC
ENABLE_UART_DEBUG := 0 just for code debugging, it sends debug info along the USB serial connection (programming lead)
ENABLE_AIRCOPY := 0 easier to just enter frequency with butts
ENABLE_FMRADIO := 0 WBFM VHF broadcast band receiver
ENABLE_NOAA := 0 everything NOAA (only of any use in the USA)
ENABLE_FMRADIO := 1 WBFM VHF broadcast band receiver
ENABLE_NOAA := 1 everything NOAA (only of any use in the USA)
ENABLE_VOICE := 0 want to hear voices ?
ENABLE_VOX := 0
ENABLE_ALARM := 0 TX alarms
ENABLE_1750HZ := 0 side key 1750Hz TX tone (older style repeater access)
ENABLE_VOX := 1 voice operated transmission
ENABLE_ALARM := 1 TX alarms
ENABLE_1750HZ := 1 side key 1750Hz TX tone (older style repeater access)
ENABLE_PWRON_PASSWORD := 1 power-on password stuff
ENABLE_BIG_FREQ := 0 big font frequencies (like original QS firmware)
ENABLE_SMALL_BOLD := 1 bold channel name/no. (when name + freq channel display mode)
Expand All @@ -58,13 +59,13 @@ ENABLE_CODE_SCAN_TIMEOUT := 0 enable/disable 32-sec CTCSS/DCS scan ti
ENABLE_AM_FIX := 1 dynamically adjust the front end gains when in AM mode to helo prevent AM demodulator saturation, ignore the on-screen RSSI level (for now)
ENABLE_AM_FIX_SHOW_DATA := 1 show debug data for the AM fix (still tweaking it)
ENABLE_SQUELCH_MORE_SENSITIVE := 1 make squelch levels a little bit more sensitive - I plan to let user adjust the values themselves
ENABLE_FASTER_CHANNEL_SCAN := 0 increases the channel scan speed, but the squelch is also made more twitchy
ENABLE_FASTER_CHANNEL_SCAN := 1 increases the channel scan speed, but the squelch is also made more twitchy
ENABLE_RSSI_BAR := 1 enable a dBm/Sn RSSI bar graph level inplace of the little antenna symbols
ENABLE_AUDIO_BAR := 0 experimental, display an audo bar level when TX'ing
ENABLE_SHOW_TX_TIMEOUT := 1 show the TX time left (TX timeout)
ENABLE_SHOW_TX_TIMEOUT := 1 show the TX time left when transmitting
ENABLE_COPY_CHAN_TO_VFO := 1 copy current channel into the other VFO. Long press Menu key ('M')
#ENABLE_SINGLE_VFO_CHAN := 1 not yet implemented - single VFO on display when possible
#ENABLE_BAND_SCOPE := 1 not yet implemented - spectrum/pan-adapter
#ENABLE_BAND_SCOPE := 0 not yet implemented - spectrum/pan-adapter
#ENABLE_SINGLE_VFO_CHAN := 0 not yet implemented - single VFO on display when possible
```

# New/modified function keys
Expand Down
8 changes: 6 additions & 2 deletions app/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#endif
#include "driver/bk4819.h"
#include "driver/gpio.h"
#include "driver/uart.h"
#include "functions.h"
#include "misc.h"
#include "settings.h"
Expand Down Expand Up @@ -58,11 +59,14 @@ void ACTION_Power(void)
if (++g_tx_vfo->output_power > OUTPUT_POWER_HIGH)
g_tx_vfo->output_power = OUTPUT_POWER_LOW;

#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
// UART_printf("act_pwr %u\r\n", g_tx_vfo->output_power);
#endif

g_request_save_channel = 1;
//g_request_save_channel = 2; // auto save the channel

#ifdef ENABLE_VOICE
g_another_voice_id = VOICE_ID_POWER;
g_another_voice_id = VOICE_ID_POWER;
#endif

g_request_display_screen = g_screen_to_display;
Expand Down
20 changes: 11 additions & 9 deletions app/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "driver/keyboard.h"
#include "driver/st7565.h"
#include "driver/system.h"
#include "driver/uart.h"
#include "am_fix.h"
#include "dtmf.h"
#include "external/printf/printf.h"
Expand Down Expand Up @@ -1301,7 +1302,7 @@ void APP_CheckKeys(void)

if (g_ptt_is_pressed)
{
if (GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_PTT) || g_serial_config_count_down_500ms > 0)
if (GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_PTT) || g_serial_config_count_down_500ms > 0 || !g_setting_tx_enable)
{ // PTT released or serial comms config in progress
if (++g_ptt_debounce_counter >= 3 || g_serial_config_count_down_500ms > 0) // 30ms
{ // stop transmitting
Expand All @@ -1315,11 +1316,11 @@ void APP_CheckKeys(void)
g_ptt_debounce_counter = 0;
}
else
if (!GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_PTT) && g_serial_config_count_down_500ms == 0)
if (!GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_PTT) && g_serial_config_count_down_500ms == 0 && g_setting_tx_enable)
{ // PTT pressed
if (++g_ptt_debounce_counter >= 3) // 30ms
{ // start transmitting
g_boot_counter_10ms = 0; // cancel the boot-up screen
g_boot_counter_10ms = 0; // cancel the boot-up screen
g_ptt_debounce_counter = 0;
g_ptt_is_pressed = true;
APP_ProcessKey(KEY_PTT, true, false);
Expand Down Expand Up @@ -1350,7 +1351,7 @@ void APP_CheckKeys(void)
if (g_key_reading_0 != KEY_INVALID && Key != KEY_INVALID)
APP_ProcessKey(g_key_reading_1, false, g_key_being_held); // key pressed without releasing previous key

g_key_reading_0 = Key;
g_key_reading_0 = Key;
g_debounce_counter = 0;
return;
}
Expand Down Expand Up @@ -2108,8 +2109,9 @@ static void APP_ProcessKey(const key_code_t Key, const bool key_pressed, const b
// if (Key == KEY_INVALID)
// return;

// reset the state so as to remove it from the screen
if (Key != KEY_INVALID && Key != KEY_PTT)
RADIO_Setg_vfo_state(VFO_STATE_NORMAL); // reset the state
RADIO_Setg_vfo_state(VFO_STATE_NORMAL);

const bool backlight_was_on = GPIO_CheckBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT);

Expand Down Expand Up @@ -2150,10 +2152,10 @@ static void APP_ProcessKey(const key_code_t Key, const bool key_pressed, const b
}
#endif

if (g_flag_SaveChannel)
if (g_flag_save_channel)
{
SETTINGS_SaveChannel(g_tx_vfo->channel_save, g_eeprom.tx_vfo, g_tx_vfo, g_flag_SaveChannel);
g_flag_SaveChannel = false;
SETTINGS_SaveChannel(g_tx_vfo->channel_save, g_eeprom.tx_vfo, g_tx_vfo, g_flag_save_channel);
g_flag_save_channel = false;

RADIO_ConfigureChannel(g_eeprom.tx_vfo, VFO_CONFIGURE);
RADIO_SetupRegisters(true);
Expand Down Expand Up @@ -2464,7 +2466,7 @@ static void APP_ProcessKey(const key_code_t Key, const bool key_pressed, const b
}
else
{
g_flag_SaveChannel = g_request_save_channel;
g_flag_save_channel = g_request_save_channel;

if (g_request_display_screen == DISPLAY_INVALID)
g_request_display_screen = DISPLAY_MAIN;
Expand Down
4 changes: 2 additions & 2 deletions app/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ void MENU_AcceptSetting(void)
break;

case MENU_TX_EN:
g_Setting_tx_enable = g_sub_menu_selection;
g_setting_tx_enable = g_sub_menu_selection;
break;

#ifdef ENABLE_F_CAL_MENU
Expand Down Expand Up @@ -1208,7 +1208,7 @@ void MENU_ShowCurrentSetting(void)
break;

case MENU_TX_EN:
g_sub_menu_selection = g_Setting_tx_enable;
g_sub_menu_selection = g_setting_tx_enable;
break;

#ifdef ENABLE_F_CAL_MENU
Expand Down
4 changes: 2 additions & 2 deletions app/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ static void SCANNER_Key_MENU(bool key_pressed, bool key_held)
g_eeprom.freq_channel[g_eeprom.tx_vfo] = Channel;
}

g_tx_vfo->channel_save = Channel;
g_tx_vfo->channel_save = Channel;
g_eeprom.screen_channel[g_eeprom.tx_vfo] = Channel;
g_request_save_channel = 2;
g_request_save_channel = 2;

#ifdef ENABLE_VOICE
g_another_voice_id = VOICE_ID_CONFIRM;
Expand Down
28 changes: 14 additions & 14 deletions board.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ static const uint32_t gDefaultFrequencyTable[] =
FLASH_Init(FLASH_READ_MODE_1_CYCLE);
FLASH_ConfigureTrimValues();
SYSTEM_ConfigureClocks();

overlay_FLASH_MainClock = 48000000;
overlay_FLASH_ClockMultiplier = 48;

FLASH_Init(FLASH_READ_MODE_2_CYCLE);
}
#endif
Expand Down Expand Up @@ -644,7 +644,7 @@ void BOARD_EEPROM_Init(void)
memset(g_eeprom.ani_dtmf_id, 0, sizeof(g_eeprom.ani_dtmf_id));
strcpy(g_eeprom.ani_dtmf_id, "123");
}

// 0EE8..0EEF
EEPROM_ReadBuffer(0x0EE8, Data, 8);
if (DTMF_ValidateCodes((char *)Data, 8))
Expand All @@ -654,7 +654,7 @@ void BOARD_EEPROM_Init(void)
memset(g_eeprom.kill_code, 0, sizeof(g_eeprom.kill_code));
strcpy(g_eeprom.kill_code, "ABCD9");
}

// 0EF0..0EF7
EEPROM_ReadBuffer(0x0EF0, Data, 8);
if (DTMF_ValidateCodes((char *)Data, 8))
Expand All @@ -664,7 +664,7 @@ void BOARD_EEPROM_Init(void)
memset(g_eeprom.revive_code, 0, sizeof(g_eeprom.revive_code));
strcpy(g_eeprom.revive_code, "9DCBA");
}

// 0EF8..0F07
EEPROM_ReadBuffer(0x0EF8, Data, 16);
if (DTMF_ValidateCodes((char *)Data, 16))
Expand All @@ -674,7 +674,7 @@ void BOARD_EEPROM_Init(void)
memset(g_eeprom.dtmf_up_code, 0, sizeof(g_eeprom.dtmf_up_code));
strcpy(g_eeprom.dtmf_up_code, "12345");
}

// 0F08..0F17
EEPROM_ReadBuffer(0x0F08, Data, 16);
if (DTMF_ValidateCodes((char *)Data, 16))
Expand All @@ -684,7 +684,7 @@ void BOARD_EEPROM_Init(void)
memset(g_eeprom.dtmf_down_code, 0, sizeof(g_eeprom.dtmf_down_code));
strcpy(g_eeprom.dtmf_down_code, "54321");
}

// 0F18..0F1F
EEPROM_ReadBuffer(0x0F18, Data, 8);
// g_eeprom.scan_list_default = (Data[0] < 2) ? Data[0] : false;
Expand All @@ -706,7 +706,7 @@ void BOARD_EEPROM_Init(void)
g_setting_500_tx_enable = (Data[4] < 2) ? Data[4] : false;
g_setting_350_enable = (Data[5] < 2) ? Data[5] : true;
g_setting_scramble_enable = (Data[6] < 2) ? Data[6] : true;
g_Setting_tx_enable = (Data[7] & (1u << 0)) ? true : false;
g_setting_tx_enable = (Data[7] & (1u << 0)) ? true : false;
g_setting_live_dtmf_decoder = (Data[7] & (1u << 1)) ? true : false;
g_setting_battery_text = (((Data[7] >> 2) & 3u) <= 2) ? (Data[7] >> 2) & 3 : 2;
#ifdef ENABLE_AUDIO_BAR
Expand Down Expand Up @@ -764,7 +764,7 @@ void BOARD_EEPROM_LoadMoreSettings(void)
EEPROM_ReadBuffer(0x1F50 + (g_eeprom.vox_level * 2), &g_eeprom.vox1_threshold, 2);
EEPROM_ReadBuffer(0x1F68 + (g_eeprom.vox_level * 2), &g_eeprom.vox0_threshold, 2);
#endif

//EEPROM_ReadBuffer(0x1F80 + g_eeprom.mic_sensitivity, &Mic, 1);
//g_eeprom.mic_sensitivity_tuning = (Mic < 32) ? Mic : 15;
g_eeprom.mic_sensitivity_tuning = g_mic_gain_dB_2[g_eeprom.mic_sensitivity];
Expand Down Expand Up @@ -803,7 +803,7 @@ uint32_t BOARD_fetchChannelFrequency(const int channel)
} __attribute__((packed)) info;

EEPROM_ReadBuffer(channel * 16, &info, sizeof(info));

return info.frequency;
}

Expand All @@ -813,9 +813,9 @@ void BOARD_fetchChannelName(char *s, const int channel)

if (s == NULL)
return;

memset(s, 0, 11); // 's' had better be large enough !

if (channel < 0)
return;

Expand Down Expand Up @@ -872,10 +872,10 @@ void BOARD_FactoryReset(bool bIsAll)
// set the first few memory channels
for (i = 0; i < ARRAY_SIZE(gDefaultFrequencyTable); i++)
{
const uint32_t Frequency = gDefaultFrequencyTable[i];
const uint32_t Frequency = gDefaultFrequencyTable[i];
g_rx_vfo->freq_config_rx.frequency = Frequency;
g_rx_vfo->freq_config_tx.frequency = Frequency;
g_rx_vfo->band = FREQUENCY_GetBand(Frequency);
g_rx_vfo->band = FREQUENCY_GetBand(Frequency);
SETTINGS_SaveChannel(USER_CHANNEL_FIRST + i, 0, g_rx_vfo, 2);
}
}
Expand Down
31 changes: 31 additions & 0 deletions driver/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
* limitations under the License.
*/

#include <string.h>
#include <stdbool.h>

#include "bsp/dp32g030/dma.h"
#include "bsp/dp32g030/syscon.h"
#include "bsp/dp32g030/uart.h"
#include "driver/uart.h"
#include "external/printf/printf.h"

static bool UART_IsLogEnabled;
uint8_t UART_DMA_Buffer[256];
Expand Down Expand Up @@ -92,8 +95,36 @@ void UART_Send(const void *pBuffer, uint32_t Size)
}
}

void UART_SendText(const void *str)
{
if (str)
UART_Send(str, strlen(str));
}

void UART_LogSend(const void *pBuffer, uint32_t Size)
{
if (UART_IsLogEnabled)
UART_Send(pBuffer, Size);
}

void UART_LogSendText(const void *str)
{
if (UART_IsLogEnabled && str)
UART_Send(str, strlen(str));
}

#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
void UART_printf(const char *str, ...)
{
char text[256];
int len;

va_list va;
va_start(va, str);
len = vsnprintf(text, sizeof(text), str, va);
va_end(va);

UART_Send(text, len);
//UART_Send(text, strlen(text));
}
#endif
5 changes: 5 additions & 0 deletions driver/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ extern uint8_t UART_DMA_Buffer[256];

void UART_Init(void);
void UART_Send(const void *pBuffer, uint32_t Size);
void UART_SendText(const void *str);
void UART_LogSend(const void *pBuffer, uint32_t Size);
void UART_LogSendText(const void *str);
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
void UART_printf(const char *str, ...);
#endif

#endif

Binary file modified firmware.bin
Binary file not shown.
Binary file modified firmware.packed.bin
Binary file not shown.
Loading

0 comments on commit 16d5130

Please sign in to comment.