Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bigquad early access fix #1131

Merged
merged 4 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/deck/drivers/src/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,23 @@ config DECK_BIGQUAD
accessories such as external receiver (CPPM input) and GPS.
It can also monitor battery voltage and current.

config DECK_BIGQUAD_ENABLE
bool "Enable Bigquad deck capabilities"
config DECK_BIGQUAD_BAT_VOLT_MULT_MV
int "Battery voltage divider multiplier (in mV)."
depends on DECK_BIGQUAD
default n
default 7800

config DECK_BIGQUAD_BAT_AMP_PER_VOLT_MA
int "Battery ampere per volt (in mA)."
depends on DECK_BIGQUAD
default 1000

config DECK_BIGQUAD_ENABLE_OSD
depends on DECK_BIGQUAD_ENABLE
depends on DECK_BIGQUAD
bool "Enable Bigquad deck OSD"
default n

config DECK_BIGQUAD_ENABLE_PM
depends on DECK_BIGQUAD_ENABLE
depends on DECK_BIGQUAD
bool "Enable Bigquad deck PM"
default n

Expand Down
9 changes: 5 additions & 4 deletions src/deck/drivers/src/bigquad.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
#include "task.h"

#define BIGQUAD_BAT_VOLT_PIN DECK_GPIO_MISO
#define BIGQUAD_BAT_VOLT_MULT 7.8f
#define BIGQUAD_BAT_VOLT_MULT (CONFIG_DECK_BIGQUAD_BAT_VOLT_MULT_MV / 1000.0)
#define BIGQUAD_BAT_CURR_PIN DECK_GPIO_SCK
#define BIGQUAD_BAT_AMP_PER_VOLT 1.0f
#define BIGQUAD_BAT_AMP_PER_VOLT (CONFIG_DECK_BIGQUAD_BAT_AMP_PER_VOLT_MA / 1000.0)

#ifdef CONFIG_DECK_BIGQUAD_ENABLE
#ifdef CONFIG_DECK_BIGQUAD

//Hardware configuration
static bool isInit;
Expand Down Expand Up @@ -132,4 +132,5 @@ PARAM_GROUP_START(deck)
PARAM_ADD_CORE(PARAM_UINT8 | PARAM_RONLY, bcBigQuad, &isInit)

PARAM_GROUP_STOP(deck)
#endif // CONFIG_DECK_BIGQUAD_ENABLE

#endif // CONFIG_DECK_BIGQUAD
56 changes: 39 additions & 17 deletions src/hal/src/pm_stm32f4.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ typedef struct _PmSyslinkInfo
uint8_t flags;
struct
{
uint8_t chg : 1;
uint8_t pgood : 1;
uint8_t unused : 6;
uint8_t isCharging : 1;
uint8_t usbPluggedIn : 1;
uint8_t canCharge : 1;
uint8_t unused : 5;
};
};
float vBat;
Expand Down Expand Up @@ -102,6 +103,8 @@ static PmSyslinkInfo pmSyslinkInfo;

static uint8_t batteryLevel;

static bool usingBigQuadDeck;

static void pmSetBatteryVoltage(float voltage);

const static float LiPoTypicalChargeCurve[10] =
Expand Down Expand Up @@ -256,8 +259,17 @@ static void pmGracefulShutdown()
void pmSyslinkUpdate(SyslinkPacket *slp)
{
if (slp->type == SYSLINK_PM_BATTERY_STATE) {
// First byte of the packet contains some PM flags such as USB power, charging etc.
memcpy(&pmSyslinkInfo, &slp->data[0], sizeof(pmSyslinkInfo));
pmSetBatteryVoltage(pmSyslinkInfo.vBat);

// If using voltage measurements from external battery, we'll set the
// voltage to this instead of the one sent from syslink.
if (isExtBatVoltDeckPinSet) {
pmSetBatteryVoltage(extBatteryVoltage);
} else {
pmSetBatteryVoltage(pmSyslinkInfo.vBat);
}

#ifdef PM_SYSTLINK_INLCUDE_TEMP
temp = pmSyslinkInfo.temp;
#endif
Expand All @@ -273,31 +285,38 @@ void pmSetChargeState(PMChargeStates chgState)

PMStates pmUpdateState()
{
PMStates state;
bool isCharging = pmSyslinkInfo.chg;
bool isPgood = pmSyslinkInfo.pgood;
uint32_t batteryLowTime;
bool usbPluggedIn = pmSyslinkInfo.usbPluggedIn;
bool isCharging = pmSyslinkInfo.isCharging;
PMStates nextState;

batteryLowTime = xTaskGetTickCount() - batteryLowTimeStamp;
uint32_t batteryLowTime = xTaskGetTickCount() - batteryLowTimeStamp;

if (isPgood && !isCharging)
if (usingBigQuadDeck)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to remove this dependency and have the BiqQuaddeck driver call a function to enable this behavior instead. Something like pmIgnoreChargedState()

{
state = charged;
// Need special care if big quad deck is connected, because the battery voltage
// makes the usbPluggedIn high.
nextState = battery;
}
else if (isPgood && isCharging)
else if (usbPluggedIn && !isCharging)
{
state = charging;
nextState = charged;
}
else if (!isPgood && !isCharging && (batteryLowTime > PM_BAT_LOW_TIMEOUT))
else if (usbPluggedIn && isCharging)
{
state = lowPower;
nextState = charging;
}
else
{
state = battery;
nextState = battery;
}

return state;
if (nextState == battery && batteryLowTime > PM_BAT_LOW_TIMEOUT)
{
// This is to avoid setting state to lowPower when we're plugged in to USB.
nextState = lowPower;
}

return nextState;
}

void pmEnableExtBatteryCurrMeasuring(const deckPin_t pin, float ampPerVolt)
Expand Down Expand Up @@ -377,6 +396,9 @@ void pmTask(void *param)
pmSetChargeState(charge500mA);
systemWaitStart();

// Figure out if we're using the big quad deck, which is needed to estimate the correct PM state.
usingBigQuadDeck = deckFindDriverByName("bcBigQuad") != NULL;

while(1)
{
vTaskDelay(100);
Expand Down