Refactor dds into dds and fgen
driver module started
This commit is contained in:
143
source/ports.c
143
source/ports.c
@@ -31,13 +31,12 @@
|
||||
#include "pwr_level.h"
|
||||
#include "System/system.h"
|
||||
#include "usbComms.h"
|
||||
#include "driver.h"
|
||||
|
||||
ACCESSORY_t accy1;
|
||||
ACCESSORY_t accy2;
|
||||
uint16_t Port_timer;
|
||||
uint16_t Taps_adjust_timer;
|
||||
extern uint8_t Port_changed_flag,Init_Done;
|
||||
extern uint8_t Port_State[],Cur_Mode,old_freq,Bcast_Pwr_Level,Bcast_LF_Value[],Bcast_HF_Value[],Power_Level;
|
||||
extern uint8_t Port_State[],Cur_Mode,old_freq,Bcast_Pwr_Level,Power_Level;
|
||||
extern MODE_REC_t mode_Array[MODE_MAX_NUM];
|
||||
extern uint8_t frequency,Over_Voltage_Flag;
|
||||
extern FREQUENCY_t freqArray[FREQ_MAX_NUM];
|
||||
@@ -50,6 +49,9 @@ extern SYSTEM_DATA_t sys;
|
||||
|
||||
uint8_t whatever;
|
||||
|
||||
static uint8_t Bcast_LF_Value[5] = {0,5,10,15,20};
|
||||
static uint8_t Bcast_HF_Value[5] = {0,12,25,37,50};
|
||||
|
||||
static int handleBroadcast(ACCESSORY_t *accy)
|
||||
{
|
||||
switch (accy->state)
|
||||
@@ -58,8 +60,21 @@ static int handleBroadcast(ACCESSORY_t *accy)
|
||||
{
|
||||
if (accy->initState)
|
||||
{
|
||||
USB_SendString("Broadcast initializing...");
|
||||
accy->stateTimer = sys.systemTime + 2000;
|
||||
// use the current frequency if it is valid, otherwise, set to the lowest valid for broadcast
|
||||
sys.frequency = 3140;
|
||||
|
||||
if(sys.frequency <= 8010)
|
||||
BC_Duty_Cycle = Bcast_LF_Value[0];
|
||||
else
|
||||
BC_Duty_Cycle = Bcast_HF_Value[0];
|
||||
|
||||
|
||||
PWM_Setup(sys.frequency, BC_Duty_Cycle);//freqArray[frequency].frequency1
|
||||
|
||||
driver_broadcastOn(true);
|
||||
|
||||
|
||||
accy->stateTimer = sys.systemTime + 500;
|
||||
}
|
||||
|
||||
if (sys.systemTime >= accy->stateTimer)
|
||||
@@ -73,14 +88,25 @@ static int handleBroadcast(ACCESSORY_t *accy)
|
||||
{
|
||||
if (accy->initState)
|
||||
{
|
||||
USB_SendString("Broadcast deinitializing...");
|
||||
accy->stateTimer = sys.systemTime + 2000;
|
||||
//USB_SendString("Broadcast deinitializing...");
|
||||
|
||||
// turn off the amp and antenna
|
||||
driver_broadcastOn(false);
|
||||
delayms(50);
|
||||
|
||||
// turn off PWM
|
||||
driver_setDuty(0);
|
||||
|
||||
// set PSU to minimum
|
||||
driver_setPSUVoltage(V_24V);
|
||||
|
||||
accy->stateTimer = sys.systemTime + 500;
|
||||
}
|
||||
|
||||
if (sys.systemTime >= accy->stateTimer)
|
||||
{
|
||||
accy->state = PORT_STATE_STANDBY;
|
||||
USB_SendString("Broadcast in standby!");
|
||||
//USB_SendString("Broadcast in standby!");
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -90,7 +116,7 @@ static int handleBroadcast(ACCESSORY_t *accy)
|
||||
{
|
||||
if (accy->initState)
|
||||
{
|
||||
USB_SendString("Broadcast running!");
|
||||
//USB_SendString("Broadcast running!");
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -223,6 +249,12 @@ void ACCY_service(void)
|
||||
|
||||
}
|
||||
|
||||
void ACCY_setActiveChannel(AccyChannelId_t channel)
|
||||
{
|
||||
// TODO: handle anything needed for switching here
|
||||
sys.activeAccessory->activeChannel = channel;
|
||||
}
|
||||
|
||||
void ACCY_next(void)
|
||||
{
|
||||
// cycle through accessories and channels to find the next available
|
||||
@@ -260,13 +292,20 @@ void ACCY_next(void)
|
||||
channel++;
|
||||
|
||||
} while ((port != currentPort) || (channel != currentChannel));
|
||||
|
||||
|
||||
}
|
||||
|
||||
void ACCY_setActive(ACCESSORY_t *accy, AccyChannelId_t channel)
|
||||
{
|
||||
accy->activeChannel = channel;
|
||||
|
||||
// if just changing channels on the active accessory, don't deinit/init
|
||||
// assume accessory's function will detect the channel change and respond
|
||||
if (accy == sys.activeAccessory)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// deinitialize current accessory
|
||||
if (sys.activeAccessory != NULL)
|
||||
{
|
||||
@@ -382,76 +421,6 @@ static ACCY_ID_t ReadAccessory(uint8_t port)
|
||||
return (ACCY_ID_t)idNumber;
|
||||
}
|
||||
|
||||
void Disconnect(uint8_t port) // called when you disconnect
|
||||
{
|
||||
if (port == ACCY_PORT_1)
|
||||
{
|
||||
accy1.connected = ID_NONE;
|
||||
accy1.consecutiveScans = 0;
|
||||
accy1.isConnected = false;
|
||||
|
||||
//Change Mode if this accessory was selected
|
||||
if(mode_Array[PORT1_A].Selected || mode_Array[PORT1_B].Selected)
|
||||
{
|
||||
//disconnect port 1 from keith's struct
|
||||
mode_Array[PORT1_A].Selected = 0;
|
||||
mode_Array[PORT1_B].Selected = 0;
|
||||
|
||||
if ((Cur_Mode > BROADCAST) && (Cur_Mode ==PORT1_A) || (Cur_Mode == PORT1_B) ) //and change mode
|
||||
Cur_Mode = Next_Available_Mode(Cur_Mode); // find next Mode available
|
||||
}
|
||||
else
|
||||
{
|
||||
//disconnect port 1 from keith's struct
|
||||
mode_Array[PORT1_A].Selected = 0;
|
||||
mode_Array[PORT1_B].Selected = 0;
|
||||
}
|
||||
}
|
||||
else //port 2
|
||||
{
|
||||
accy2.connected = ID_NONE;
|
||||
accy2.consecutiveScans = 0;
|
||||
accy2.isConnected = false;
|
||||
|
||||
//Change Mode if this accessory was selected
|
||||
if(mode_Array[PORT2_A].Selected || mode_Array[PORT2_B].Selected)
|
||||
{
|
||||
//disconnect port 2 from keith's struct
|
||||
mode_Array[PORT2_A].Selected = 0;
|
||||
mode_Array[PORT2_B].Selected = 0;
|
||||
|
||||
if ((Cur_Mode > BROADCAST) && (Cur_Mode == PORT2_A) || (Cur_Mode == PORT2_B) ) //and change mode
|
||||
// Cur_Mode = Next_Available_Mode(Cur_Mode); // find next Mode available
|
||||
{
|
||||
if (mode_Array[PORT1_A].Selected || mode_Array[PORT1_B].Selected) //and change mode
|
||||
Cur_Mode = PORT1_A;
|
||||
else
|
||||
Cur_Mode = Next_Available_Mode(Cur_Mode); // find next Mode available
|
||||
}
|
||||
//
|
||||
// else
|
||||
// Cur_Mode = 1;
|
||||
// if (Cur_Mode > 0)
|
||||
// {
|
||||
// if (mode_Array[1].Selected || mode_Array[2].Selected) //and change mode
|
||||
// Cur_Mode = 1;
|
||||
// else
|
||||
// Cur_Mode = Next_Available_Mode(Cur_Mode); // find next Mode available
|
||||
// }
|
||||
}
|
||||
else
|
||||
{
|
||||
//disconnect port 1 from keith's struct
|
||||
mode_Array[PORT2_A].Selected = 0;
|
||||
mode_Array[PORT2_B].Selected = 0;
|
||||
}
|
||||
}
|
||||
Port_changed_flag = true; // added 10/2/23
|
||||
Init_Done = false; // 3/20/24 Force a Power Level One change
|
||||
|
||||
//Configure frequency to make sure things are setup correctly
|
||||
// Tx_ConfigureFrequency();
|
||||
}
|
||||
void ACCY_Init(void)
|
||||
{
|
||||
|
||||
@@ -467,20 +436,8 @@ void ACCY_Init(void)
|
||||
sys.ports[ACCY_PORT_1].idVoltage = &sys.adc.V_ID1;
|
||||
sys.ports[ACCY_PORT_2].idVoltage = &sys.adc.V_ID2;
|
||||
|
||||
accy1.connected = ID_NONE;
|
||||
accy1.consecutiveScans = 0;
|
||||
accy1.isConnected = false;
|
||||
|
||||
accy2.connected = ID_NONE;
|
||||
accy2.consecutiveScans = 0;
|
||||
accy2.isConnected = false;
|
||||
|
||||
Port_timer = DELAY_100MS;
|
||||
Port_changed_flag = false;
|
||||
|
||||
//Setup accessory for GPIO gain control
|
||||
// InitAccessoryGainGPIO();
|
||||
}
|
||||
|
||||
void ACCY_Update(void)
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user