power up/down working for broadcast

This commit is contained in:
2025-06-25 14:49:12 -05:00
parent 2ff7291c63
commit 372e4941a2
11 changed files with 226 additions and 163 deletions

View File

@@ -71,8 +71,6 @@ static void _stateInit(ACCESSORY_t *accy)
driver_setFrequency(freq);
driver_broadcastOn(true);
ACCY_setTimeout(accy, 500);

View File

@@ -7,7 +7,7 @@
#define TX_SYS_CLK 12000000 // 12MHZ
#define DDS_CLK TX_SYS_CLK
#define RAMP_300KHZ 6710886
#define FREQ_MAX_NUM 50 //Max number of frequencies allowed
#define FREQ_MIN 0

View File

@@ -452,80 +452,29 @@ void Display_Wireless(uint8_t wireless)
GL_DrawMonoBitmap(txControl, LCD_X_MID-90, LCD_Y_MAX-22, LCD_DRAW_SET);
}
void Display_Mode(uint8_t Con_Mode1)
{
SYSTEM_DATA_t * sys = system_getSys();
ACCESSORY_t *active = sys->activeAccessory;
if (active != NULL)
{
switch (active->connected)
{
case ID_BROADCAST:
{
GL_DrawMonoBitmap(inductionIcon, LCD_X_MAX-60,LCD_Y_MIN + 2, LCD_DRAW_SET);
break;
}
case ID_TX_SINGLE_DIRECT:
{
GL_DrawMonoBitmap(directConnectIcon5, LCD_X_MAX-60,LCD_Y_MIN + 2, LCD_DRAW_SET);
sprintf(sys->tmpString, "%d", active->portId);
FL_DrawString(sys->tmpString, LCD_X_MAX-40, LCD_Y_MIN, font12Bold, LCD_DRAW_SET, FL_ALIGN_RIGHT);
break;
}
case ID_TX_DUAL_DIRECT:
{
GL_DrawMonoBitmap(directConnectIcon3, LCD_X_MAX-60,LCD_Y_MIN + 2, LCD_DRAW_SET);
break;
}
case ID_CLAMP:
{
GL_DrawMonoBitmap(clampIcon2, LCD_X_MAX-60,LCD_Y_MIN + 2, LCD_DRAW_SET);
break;
}
case ID_CLAMP2:
{
GL_DrawMonoBitmap(clampIcon2, LCD_X_MAX-60,LCD_Y_MIN + 2, LCD_DRAW_SET);
FL_DrawString("V2", LCD_X_MAX-40, LCD_Y_MIN+30, font10Bold, LCD_DRAW_SET, FL_ALIGN_CENTER);
break;
}
}
}
return;
}
void Display_Level(PWR_MODE_t Level)
//void Display_Level(PWR_MODE_t Level)
void displayLevel(void)
{
PowerLevel_t level = driver_getPowerLevel();
GL_DrawRectangle( 70, LCD_Y_MIN+15, 90, LCD_Y_MIN + 1, 2, LCD_DRAW_SET);
GL_DrawRectangle( 94, LCD_Y_MIN+15, 114, LCD_Y_MIN + 1, 2, LCD_DRAW_SET);
GL_DrawRectangle(118, LCD_Y_MIN+15, 138, LCD_Y_MIN + 1, 2, LCD_DRAW_SET);
GL_DrawRectangle(142, LCD_Y_MIN+15, 162, LCD_Y_MIN + 1, 2, LCD_DRAW_SET);
switch(Level)
switch(level)
{
case LEVEL4:
case POWER_LEVEL_4:
GL_DrawFilledRectangle(142, LCD_Y_MIN+15, 162, LCD_Y_MIN + 1, LCD_DRAW_SET);
case LEVEL3:
case POWER_LEVEL_3:
GL_DrawFilledRectangle(118, LCD_Y_MIN+15, 138, LCD_Y_MIN + 1, LCD_DRAW_SET);
case LEVEL2:
case POWER_LEVEL_2:
GL_DrawFilledRectangle( 94, LCD_Y_MIN+15, 114, LCD_Y_MIN + 1, LCD_DRAW_SET);
case LEVEL1:
case POWER_LEVEL_1:
GL_DrawFilledRectangle( 70, LCD_Y_MIN+15, 90, LCD_Y_MIN + 1, LCD_DRAW_SET);
}
@@ -816,3 +765,108 @@ void Display_OnScreen_Diagnostics(void)
// FL_DrawString(tempString, 0, 80, font10Bold, LCD_DRAW_SET, FL_ALIGN_LEFT);
}
static void displayFrequency(void)
{
FREQUENCY_t *freq = driver_getFrequency();
if (freq->ldFrequency > 0)
{
Display_CD_Symbol(); // place a CD symbol in front in correct position
}
uint32_t value = freq->frequency;
if (value < 1000)
{
sprintf(tempString,"%dHz", value);
}
else
if (value < 10000 && value >= 1000 )
{
sprintf(tempString,"%.2fkHz", (float32_t)value/1000.0 );
}
else
if (value < 100000 && value >= 10000)
{
sprintf(tempString,"%.1fkHz",(float32_t)value/1000 );
}
else
if (value > 100000)
{
sprintf(tempString,"%.0fkHz",(float32_t)value/1000 );
}
FL_DrawString(tempString, LCD_X_MAX+6, LCD_Y_MAX - 22, font18Bold, LCD_DRAW_SET, FL_ALIGN_RIGHT);
}
static void displayMode(void)
{
SYSTEM_DATA_t * sys = system_getSys();
ACCESSORY_t *active = sys->activeAccessory;
if (active != NULL)
{
switch (active->connected)
{
case ID_BROADCAST:
{
GL_DrawMonoBitmap(inductionIcon, LCD_X_MAX-60,LCD_Y_MIN + 2, LCD_DRAW_SET);
break;
}
case ID_TX_SINGLE_DIRECT:
{
GL_DrawMonoBitmap(directConnectIcon5, LCD_X_MAX-60,LCD_Y_MIN + 2, LCD_DRAW_SET);
sprintf(sys->tmpString, "%d", active->portId);
FL_DrawString(sys->tmpString, LCD_X_MAX-40, LCD_Y_MIN, font12Bold, LCD_DRAW_SET, FL_ALIGN_RIGHT);
break;
}
case ID_TX_DUAL_DIRECT:
{
GL_DrawMonoBitmap(directConnectIcon3, LCD_X_MAX-60,LCD_Y_MIN + 2, LCD_DRAW_SET);
break;
}
case ID_CLAMP:
{
GL_DrawMonoBitmap(clampIcon2, LCD_X_MAX-60,LCD_Y_MIN + 2, LCD_DRAW_SET);
break;
}
case ID_CLAMP2:
{
GL_DrawMonoBitmap(clampIcon2, LCD_X_MAX-60,LCD_Y_MIN + 2, LCD_DRAW_SET);
FL_DrawString("V2", LCD_X_MAX-40, LCD_Y_MIN+30, font10Bold, LCD_DRAW_SET, FL_ALIGN_CENTER);
break;
}
}
}
return;
}
void Display_Update(void)
{
LCD_Clear(); //clear the frameBuffer
Display_USB_Status();
// display current mode information
displayMode();
displayLevel();
displayFrequency();
LCD_Update();
}

View File

@@ -8,6 +8,11 @@
static SYSTEM_DATA_t *_sys = NULL;
static TxDriver_t _driver;
static bool powerChangeAllowed(void)
{
return ((_sys->systemTime - _driver.lastPowerChangeTime) > POWER_CHANGE_TIME);
}
TxDriver_t * driver_getDriver(void)
{
return &_driver;
@@ -80,6 +85,16 @@ void driver_init(void)
driver_setPSUVoltage(_driver.psuValueMax);
driver_enablePower(true);
fgen_init();
// HACK: pick the first frequency for now
_driver.powerLevel = POWER_LEVEL_0;
_driver.frequency = fgen_getByIndex(0);
_driver.lastPowerChangeTime = _sys->systemTime;
}
void driver_broadcastOn(bool on)
@@ -122,24 +137,23 @@ void driver_setDuty(uint32_t duty)
void driver_setFrequency(FREQUENCY_t *freq)
{
if (_sys->activeAccessory != NULL)
{
freq = _sys->activeAccessory->setFrequency(_sys->activeAccessory, freq);
if (freq != NULL)
{
// TODO: accessory may select a different frequency
// accessory may select a different frequency
_driver.frequency = freq;
driver_setPower(_driver.powerLevel);
}
}
}
void driver_setPower(PowerLevel_t powerLevel)
{
if (_sys->activeAccessory != NULL)
@@ -155,6 +169,37 @@ void driver_setPower(PowerLevel_t powerLevel)
}
}
_driver.lastPowerChangeTime = _sys->systemTime;
}
void driver_powerUp(void)
{
// limit power change rate
if (!powerChangeAllowed()) return;
PowerLevel_t level = _driver.powerLevel;
if (level < POWER_LEVEL_4)
{
level++;
}
driver_setPower(level);
}
void driver_powerDown(void)
{
if (!powerChangeAllowed()) return;
PowerLevel_t level = _driver.powerLevel;
if (level > POWER_LEVEL_0)
{
level--;
}
driver_setPower(level);
}
void driver_setSafe(bool safe)
@@ -174,11 +219,16 @@ void driver_setSafe(bool safe)
}
}
FREQUENCY_t *driver_getFrequency(void)
FREQUENCY_t* driver_getFrequency(void)
{
return _driver.frequency;
}
PowerLevel_t driver_getPowerLevel(void)
{
return _driver.powerLevel;
}
// safety monitor run from interrupt
void driver_monitor(void)
{
@@ -191,6 +241,7 @@ void driver_service(void)
{
case DRIVER_STATE_INIT:
{
break;
}

View File

@@ -21,6 +21,8 @@
#define MAX_D_PSU V_36V
#define MAX_CLAMP_PSU 255
#define POWER_CHANGE_TIME 500 //m sec
typedef enum
{
POWER_LEVEL_0 = 0,
@@ -50,6 +52,8 @@ typedef struct
FREQUENCY_t *frequency;
PowerLevel_t powerLevel;
uint32_t lastPowerChangeTime;
} TxDriver_t;
TxDriver_t * driver_getDriver(void);
@@ -66,5 +70,9 @@ void driver_setFrequency(FREQUENCY_t *freq);
void driver_setPower(PowerLevel_t powerLevel);
FREQUENCY_t *driver_getFrequency(void);
void driver_setSafe(bool safe);
PowerLevel_t driver_getPowerLevel();
void driver_powerUp(void);
void driver_powerDown(void);
#endif

View File

@@ -6,6 +6,7 @@
#include "eeprom.h"
#include "arm_math.h"
#include "soft_timer.h"
#include "utils.h"
static fgen_t _fgen;
@@ -341,6 +342,8 @@ static void loadDefaults(void)
fgen_addFrequency(32770, 1, 1, FT_ACTIVE);
fgen_addFrequency(65055, 1, 1, FT_ACTIVE);
fgen_addFrequency(88779, 1, 1, FT_ACTIVE);
EE_SaveData();
}
@@ -371,6 +374,12 @@ static bool loadFrequencies(void)
return success;
}
void fgen_setFrequency(FREQUENCY_t *freq)
{
}
void fgen_init(void)
{
uint32_t tmp;
@@ -389,7 +398,7 @@ void fgen_init(void)
resetPin.pin = PIN (PIN_RAMP_RST);
dds_init(&_fgen.dds[DDS_RAMP], RAMP, resetPin);
stimer_delay(10);
delayms(10);
// clear reset after delay
for (int i=0; i<NUM_DDS; ++i)
@@ -403,5 +412,7 @@ void fgen_init(void)
dds_sleep(&_fgen.dds[DDS_DIRECTION], true, false);
dds_setFrequency(&_fgen.dds[DDS_RAMP], RAMP_300KHZ);
}

View File

@@ -3,6 +3,9 @@
#include "dds.h"
#define RAMP_300KHZ 300000
typedef enum
{
DDS_SIGNAL = 0,

View File

@@ -198,16 +198,6 @@ void LCD_Init(void)
void Display_Update(void)
{
LCD_Clear(); //clear the frameBuffer
Display_USB_Status();
LCD_Update();
}
void LCD_PowerOff(void)

View File

@@ -152,7 +152,7 @@ static void init(void)
// Broadcast accessory is always connected
ACCY_Connect(&sys.ports[ACCY_PORT_INDUCTION], ID_BROADCAST);
// ACCY_setActive(&sys.ports[ACCY_PORT_INDUCTION], CHANNEL_A);
//ACCY_setActive(&sys.ports[ACCY_PORT_INDUCTION], CHANNEL_A);
sys.guiMode = GUI_MODE_NORMAL;
}
@@ -279,26 +279,25 @@ int main(void)
{
//mode_menu();
// test accessory state machine
//ACCY_next();
ACCY_next();
ACCY_setActive(&sys.ports[ACCY_PORT_INDUCTION], CHANNEL_A);
//ACCY_setActive(&sys.ports[ACCY_PORT_INDUCTION], CHANNEL_A);
break;
}
#if 0
case PWR_UP_KEY:
{
if(Key_Lock_Out_tmr == 0)
{
Vchktmr = LOCK_OUT_DELAY;
inc_pwr();//increment the power output
Key_Lock_Out_tmr = KEY_LOCK_TIME;
Suspend_Step_Chk = false;
step_count = 0;
}
}
driver_powerUp();
break;
}
case PWR_DN_KEY:
{
driver_powerDown();
break;
}
#if 0
case PWR_DN_KEY:
{
if(Key_Lock_Out_tmr == 0)

View File

@@ -258,12 +258,15 @@ static void handleMenuKeys(uint32_t pressed, Menu_t *menu)
}
if (pressed == KEY_ENTER)
{
if (menu->items != NULL)
{
if (menu->items[menu->selected].handler != NULL)
{
menu->items[menu->selected].handler(NULL);
}
}
}
}
static void drawScrollBar(Menu_t *menu)
@@ -585,75 +588,6 @@ static void DrawMenuScrollBar(uint32_t displayIndex, uint32_t numItems)
* Public Functions
******************************************************************************/
void MENU_Init(void)
{
//Init testMenu
TM_Init();
//Clear menu items
ClearMenuItems(mainMenu, MAIN_MENU_NUM_TX10);
ClearMenuItems(langMenu, LANG_MENU_NUM);
_menuItemsIndex = 0;
for (int i=0; i < MENU_STACK_SIZE; ++i)
{
_menuData.menuStack[i].selected = 0;
_menuData.menuStack[i].handler = NULL;
}
//main menu
uint32_t i = 0;
mainMenu[i].pMonoIcon = 0;
strcpy(mainMenu[i++].text, "System Information"); //System info screen
mainMenu[i].pMonoIcon = 0;
strcpy(mainMenu[i++].text, "Frequencies"); //Frequency Selection Menu
mainMenu[i].pMonoIcon = 0;
strcpy(mainMenu[i++].text, "Auto Shutdown"); //Auto Shutdown selection
mainMenu[i].pMonoIcon = 0;
strcpy(mainMenu[i++].text, "Language"); //Language Selection Menu
#if 0
mainMenu[i].pMonoIcon = 0;
strcpy(mainMenu[i++].text, "Link Radio"); //Link Radio Menu
//no regulatory info on the Tx10
mainMenu[i].pMonoIcon = 0;
strcpy(mainMenu[i++].text, "Regulatory Info"); //Reset - Needs a new name
#endif
//check for array over run
if(i > MAIN_MENU_NUM_TX10)
{
while(1);
}
//language menu
i = 0;
langMenu[i].pMonoIcon = 0;
strcpy(langMenu[i].text, languageNames[i++]);
langMenu[i].pMonoIcon = 0;
strcpy(langMenu[i].text, languageNames[i++]);
langMenu[i].pMonoIcon = 0;
strcpy(langMenu[i].text, languageNames[i++]);
langMenu[i].pMonoIcon = 0;
strcpy(langMenu[i].text, languageNames[i++]);
//check for array over run
if(i > LANG_MENU_NUM)
{
while(1);
}
}
void Menu_init(void)
{

View File

@@ -176,6 +176,11 @@ void ACCY_service(void)
}
}
}
else
{
// if nothing active, set broadcast
ACCY_setActive(&sys.ports[ACCY_PORT_INDUCTION], CHANNEL_A);
}
}
@@ -188,6 +193,13 @@ void ACCY_setActiveChannel(AccyChannelId_t channel)
void ACCY_next(void)
{
if (sys.activeAccessory == NULL)
{
ACCY_setActive(&sys.ports[ACCY_PORT_INDUCTION], CHANNEL_A);
return;
}
// cycle through accessories and channels to find the next available
AccessoryPortId_t currentPort = sys.activeAccessory->portId;
AccyChannelId_t currentChannel = sys.activeAccessory->activeChannel;
@@ -367,6 +379,9 @@ void ACCY_Init(void)
sys.ports[ACCY_PORT_1].idVoltage = &sys.adc.V_ID1;
sys.ports[ACCY_PORT_2].idVoltage = &sys.adc.V_ID2;
sys.activeAccessory = NULL;
sys.nextAccessory = NULL;
}
void ACCY_Update(void)