Shrink flash usage _just_ enough
This commit is contained in:
@@ -33,7 +33,7 @@ public:
|
||||
private:
|
||||
static void Thread(const void *arg);
|
||||
static osThreadId TaskHandle;
|
||||
static const size_t TaskStackSize = 1536 / 2;
|
||||
static const size_t TaskStackSize = 1536 / 3;
|
||||
static uint32_t TaskBuffer[TaskStackSize];
|
||||
static osStaticThreadDef_t TaskControlBlock;
|
||||
static uint32_t waitForEvent(uint32_t mask, uint32_t ticksToWait =
|
||||
|
||||
@@ -46,9 +46,7 @@ void InterruptHandler::Thread(const void *arg) {
|
||||
while (true) {
|
||||
/* If the INT_N line is low */
|
||||
if (!notifSent) {
|
||||
if (xTaskNotifyWait(0x00, 0x0F, NULL, 25) == pdPASS) {
|
||||
osDelay(1);
|
||||
}
|
||||
xTaskNotifyWait(0x00, 0x0F, NULL, 25);
|
||||
}
|
||||
notifSent = false;
|
||||
/* Read the FUSB302B status and interrupt registers */
|
||||
@@ -96,9 +94,7 @@ void InterruptHandler::Thread(const void *arg) {
|
||||
}
|
||||
}
|
||||
}
|
||||
volatile uint8_t irqs = 0;
|
||||
void InterruptHandler::irqCallback() {
|
||||
irqs++;
|
||||
BaseType_t taskWoke = pdFALSE;
|
||||
xTaskNotifyFromISR(TaskHandle, 0x01, eNotifyAction::eSetBits, &taskWoke);
|
||||
portYIELD_FROM_ISR(taskWoke);
|
||||
|
||||
@@ -23,14 +23,12 @@
|
||||
#include "hard_reset.h"
|
||||
#include "fusb302b.h"
|
||||
bool PolicyEngine::pdNegotiationComplete;
|
||||
bool PolicyEngine::pdHasEnteredLowPower;
|
||||
int PolicyEngine::current_voltage_mv;
|
||||
int PolicyEngine::_requested_voltage;
|
||||
bool PolicyEngine::_unconstrained_power;
|
||||
union pd_msg PolicyEngine::currentMessage;
|
||||
uint16_t PolicyEngine::hdr_template;
|
||||
bool PolicyEngine::_explicit_contract;
|
||||
bool PolicyEngine::_min_power;
|
||||
int8_t PolicyEngine::_hard_reset_counter;
|
||||
int8_t PolicyEngine::_old_tcc_match;
|
||||
uint8_t PolicyEngine::_pps_index;
|
||||
@@ -58,17 +56,7 @@ void PolicyEngine::init() {
|
||||
}
|
||||
|
||||
void PolicyEngine::notify(uint32_t notification) {
|
||||
notification = notification
|
||||
& (
|
||||
PDB_EVT_PE_RESET | PDB_EVT_PE_MSG_RX | PDB_EVT_PE_TX_DONE
|
||||
| PDB_EVT_PE_TX_ERR | PDB_EVT_PE_HARD_SENT
|
||||
| PDB_EVT_PE_I_OVRTEMP | PDB_EVT_PE_PPS_REQUEST);
|
||||
if (notification) {
|
||||
xEventGroupSetBits(xEventGroupHandle, notification);
|
||||
} else {
|
||||
asm("bkpt");
|
||||
}
|
||||
|
||||
xEventGroupSetBits(xEventGroupHandle, notification);
|
||||
}
|
||||
|
||||
void PolicyEngine::pe_task(const void *arg) {
|
||||
@@ -310,7 +298,6 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_select_cap() {
|
||||
pdbs_dpm_transition_standby();
|
||||
}
|
||||
|
||||
_min_power = false;
|
||||
return PESinkTransitionSink;
|
||||
/* If the message was a Soft_Reset, do the soft reset procedure */
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET
|
||||
@@ -325,10 +312,6 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_select_cap() {
|
||||
return PESinkWaitCap;
|
||||
/* If we do have an explicit contract, go to the ready state */
|
||||
} else {
|
||||
/* If we got here from a Wait message, we Should run
|
||||
* SinkRequestTimer in the Ready state. */
|
||||
_min_power = (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_WAIT);
|
||||
|
||||
return PESinkReady;
|
||||
}
|
||||
} else {
|
||||
@@ -361,9 +344,7 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_transition_sink() {
|
||||
_explicit_contract = true;
|
||||
|
||||
/* Set the output appropriately */
|
||||
if (!_min_power) {
|
||||
pdbs_dpm_transition_requested();
|
||||
}
|
||||
pdbs_dpm_transition_requested();
|
||||
|
||||
return PESinkReady;
|
||||
/* If there was a protocol error, send a hard reset */
|
||||
@@ -384,18 +365,9 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_ready() {
|
||||
eventmask_t evt;
|
||||
|
||||
/* Wait for an event */
|
||||
if (_min_power) {
|
||||
evt = waitForEvent(
|
||||
PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET | PDB_EVT_PE_I_OVRTEMP
|
||||
| PDB_EVT_PE_GET_SOURCE_CAP | PDB_EVT_PE_NEW_POWER
|
||||
| PDB_EVT_PE_PPS_REQUEST,
|
||||
PD_T_SINK_REQUEST);
|
||||
} else {
|
||||
evt = waitForEvent(
|
||||
PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET | PDB_EVT_PE_I_OVRTEMP
|
||||
| PDB_EVT_PE_GET_SOURCE_CAP | PDB_EVT_PE_NEW_POWER
|
||||
| PDB_EVT_PE_PPS_REQUEST);
|
||||
}
|
||||
evt = waitForEvent(
|
||||
PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET | PDB_EVT_PE_I_OVRTEMP
|
||||
| PDB_EVT_PE_PPS_REQUEST);
|
||||
|
||||
/* If we got reset signaling, transition to default */
|
||||
if (evt & PDB_EVT_PE_RESET) {
|
||||
@@ -407,25 +379,6 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_ready() {
|
||||
return PESinkHardReset;
|
||||
}
|
||||
|
||||
/* If the DPM wants us to, send a Get_Source_Cap message */
|
||||
if (evt & PDB_EVT_PE_GET_SOURCE_CAP) {
|
||||
/* Tell the protocol layer we're starting an AMS */
|
||||
ProtocolTransmit::notify(
|
||||
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_START_AMS);
|
||||
return PESinkGetSourceCap;
|
||||
}
|
||||
|
||||
/* If the DPM wants new power, let it figure out what power it wants
|
||||
* exactly. This isn't exactly the transition from the spec (that would be
|
||||
* SelectCap, not EvalCap), but this works better with the particular
|
||||
* design of this firmware. */
|
||||
if (evt & PDB_EVT_PE_NEW_POWER) {
|
||||
/* Tell the protocol layer we're starting an AMS */
|
||||
ProtocolTransmit::notify(
|
||||
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_START_AMS);
|
||||
return PESinkEvalCap;
|
||||
}
|
||||
|
||||
/* If SinkPPSPeriodicTimer ran out, send a new request */
|
||||
if (evt & PDB_EVT_PE_PPS_REQUEST) {
|
||||
/* Tell the protocol layer we're starting an AMS */
|
||||
@@ -434,12 +387,6 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_ready() {
|
||||
return PESinkSelectCap;
|
||||
}
|
||||
|
||||
/* If no event was received, the timer ran out. */
|
||||
if (evt == 0) {
|
||||
/* Repeat our Request message */
|
||||
return PESinkSelectCap;
|
||||
}
|
||||
|
||||
/* If we received a message */
|
||||
if (evt & PDB_EVT_PE_MSG_RX) {
|
||||
if (messageWaiting()) {
|
||||
@@ -488,16 +435,9 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_ready() {
|
||||
/* Handle GotoMin messages */
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GOTOMIN
|
||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
if (pdbs_dpm_giveback_enabled()) {
|
||||
/* Transition to the minimum current level */
|
||||
pdbs_dpm_transition_min();
|
||||
_min_power = true;
|
||||
return PESinkTransitionSink;
|
||||
} else {
|
||||
/* GiveBack is not supported */
|
||||
/* GiveBack is not supported */
|
||||
return PESinkSendNotSupported;
|
||||
|
||||
return PESinkSendNotSupported;
|
||||
}
|
||||
/* Evaluate new Source_Capabilities */
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage)
|
||||
== PD_MSGTYPE_SOURCE_CAPABILITIES
|
||||
@@ -770,22 +710,7 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_not_supported_received()
|
||||
}
|
||||
|
||||
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_source_unresponsive() {
|
||||
/* If the DPM can evaluate the Type-C Current advertisement */
|
||||
//TS80P doesnt
|
||||
// if (cfg->dpm.evaluate_typec_current != NULL) {
|
||||
// /* Make the DPM evaluate the Type-C Current advertisement */
|
||||
// int tcc_match = cfg->dpm.evaluate_typec_current(cfg,
|
||||
// fusb_get_typec_current(&cfg->fusb));
|
||||
//
|
||||
// /* If the last two readings are the same, set the output */
|
||||
// if (_old_tcc_match == tcc_match) {
|
||||
// cfg->dpm.transition_typec(cfg);
|
||||
// }
|
||||
//
|
||||
// /* Remember whether or not the last measurement succeeded */
|
||||
// _old_tcc_match = tcc_match;
|
||||
// }
|
||||
/* Wait tPDDebounce between measurements */
|
||||
//Sit and chill, as PD is not working
|
||||
osDelay(PD_T_PD_DEBOUNCE);
|
||||
|
||||
return PESinkSourceUnresponsive;
|
||||
@@ -799,13 +724,6 @@ bool PolicyEngine::pdHasNegotiated() {
|
||||
return pdNegotiationComplete;
|
||||
}
|
||||
|
||||
bool PolicyEngine::heatingAllowed() {
|
||||
if (pdHasNegotiated())
|
||||
return !pdHasEnteredLowPower;
|
||||
//Not pd -- pass through
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t PolicyEngine::waitForEvent(uint32_t mask, uint32_t ticksToWait) {
|
||||
return xEventGroupWaitBits(xEventGroupHandle, mask, mask, pdFALSE,
|
||||
ticksToWait);
|
||||
|
||||
@@ -24,10 +24,6 @@
|
||||
* Events for the Policy Engine thread, used internally + sent by user code
|
||||
*
|
||||
*/
|
||||
/* Tell the PE to send a Get_Source_Cap message */
|
||||
#define PDB_EVT_PE_GET_SOURCE_CAP EVENT_MASK(7)
|
||||
/* Tell the PE that new power is required */
|
||||
#define PDB_EVT_PE_NEW_POWER EVENT_MASK(8)
|
||||
|
||||
#define PDB_EVT_PE_RESET EVENT_MASK(0)
|
||||
#define PDB_EVT_PE_MSG_RX EVENT_MASK(1)
|
||||
@@ -51,11 +47,8 @@ public:
|
||||
static void PPSTimerCallBack();
|
||||
//Has pd negotiation completed
|
||||
static bool pdHasNegotiated();
|
||||
//Used in case the USB-C PD source requests minimum power
|
||||
static bool heatingAllowed();
|
||||
private:
|
||||
static bool pdNegotiationComplete;
|
||||
static bool pdHasEnteredLowPower;
|
||||
static int current_voltage_mv; //The current voltage PD is expecting
|
||||
static int _requested_voltage; //The voltage the unit wanted to requests
|
||||
static bool _unconstrained_power; // If the source is unconstrained
|
||||
@@ -65,8 +58,6 @@ private:
|
||||
static uint16_t hdr_template;
|
||||
/* Whether or not we have an explicit contract */
|
||||
static bool _explicit_contract;
|
||||
/* Whether or not we're receiving minimum power */
|
||||
static bool _min_power;
|
||||
/* The number of hard resets we've sent */
|
||||
static int8_t _hard_reset_counter;
|
||||
/* The result of the last Type-C Current match comparison */
|
||||
|
||||
@@ -253,17 +253,12 @@ void PolicyEngine::pdbs_dpm_get_sink_capability(union pd_msg *cap) {
|
||||
cap->hdr = hdr_template | PD_MSGTYPE_SINK_CAPABILITIES | PD_NUMOBJ(numobj);
|
||||
}
|
||||
|
||||
bool PolicyEngine::pdbs_dpm_giveback_enabled() {
|
||||
return false;
|
||||
//We do not support giveback
|
||||
}
|
||||
|
||||
bool PolicyEngine::pdbs_dpm_evaluate_typec_current(
|
||||
enum fusb_typec_current tcc) {
|
||||
//This is for evaluating 5V static current advertised by resistors
|
||||
//This is for evaluating 5V static current advertised by resistors
|
||||
/* We don't control the voltage anymore; it will always be 5 V. */
|
||||
current_voltage_mv = _requested_voltage = 5000;
|
||||
//For the soldering iron we accept this as a fallback, but it sucks
|
||||
//For the soldering iron we accept this as a fallback, but it sucks
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -278,27 +273,19 @@ void PolicyEngine::pdbs_dpm_transition_default() {
|
||||
current_voltage_mv = 5000;
|
||||
/* Turn the output off */
|
||||
pdNegotiationComplete = false;
|
||||
pdHasEnteredLowPower = true;
|
||||
}
|
||||
|
||||
void PolicyEngine::pdbs_dpm_transition_min() {
|
||||
pdHasEnteredLowPower = true;
|
||||
}
|
||||
|
||||
void PolicyEngine::pdbs_dpm_transition_standby() {
|
||||
/* If the voltage is changing, enter Sink Standby */
|
||||
if (_requested_voltage != current_voltage_mv) {
|
||||
/* For the PD Buddy Sink, entering Sink Standby is equivalent to
|
||||
* turning the output off. However, we don't want to change the LED
|
||||
* state for standby mode. */
|
||||
pdHasEnteredLowPower = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PolicyEngine::pdbs_dpm_transition_requested() {
|
||||
/* Cast the dpm_data to the right type */
|
||||
pdNegotiationComplete = true;
|
||||
pdHasEnteredLowPower = false;
|
||||
}
|
||||
|
||||
void PolicyEngine::handleMessage(union pd_msg *msg) {
|
||||
@@ -314,8 +301,7 @@ void PolicyEngine::readMessage() {
|
||||
}
|
||||
|
||||
void PolicyEngine::pdbs_dpm_transition_typec() {
|
||||
//This means PD failed, so we either have a dump 5V only type C or a QC charger
|
||||
//This means PD failed, so we either have a dumb 5V only type C or a QC charger
|
||||
//For now; treat this as failed neg
|
||||
pdNegotiationComplete = false;
|
||||
pdHasEnteredLowPower = false;
|
||||
}
|
||||
|
||||
@@ -126,18 +126,6 @@ const uint8_t idleScreenBG[] = {
|
||||
0x8A,0x84,0x82,0x81,0x80,0x80,0x80,0x40,0x40,0x20,0x18,0x07
|
||||
};
|
||||
|
||||
const uint8_t idleScreenBGF[] = {
|
||||
//width = 84
|
||||
//height = 16
|
||||
0xE0,0x18,0x04,0x02,0x02,0x01,0x41,0x81,0x01,0x01,0x65,0x99,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
|
||||
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x02,0x02,0x04,0x18,0xE0,0x00,0x00,0xE0,0x18,0x04,0x02,0x02,
|
||||
0x01,0x01,0x41,0x61,0x61,0x61,0xE1,0xC1,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0xC1,
|
||||
0xE1,0x61,0x61,0x61,0x41,0x01,0x02,0x02,0x04,0x18,0xE0,0x00,
|
||||
0x07,0x18,0x20,0x40,0x40,0x80,0x80,0x80,0x81,0x82,0x84,0x8A,0x92,0x82,0x82,0x82,0x80,0x82,0x80,0x82,0x82,0x82,0x87,0x87,
|
||||
0x85,0x87,0x85,0x87,0x87,0x85,0x85,0x85,0x85,0x87,0x82,0x80,0x40,0x40,0x20,0x18,0x07,0x00,0x00,0x07,0x18,0x20,0x40,0x40,
|
||||
0x80,0x80,0x82,0x86,0x86,0x86,0x87,0x83,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x83,
|
||||
0x87,0x86,0x86,0x86,0x82,0x80,0x40,0x40,0x20,0x18,0x07,0x00
|
||||
};
|
||||
|
||||
/*
|
||||
* 16x16 icons
|
||||
|
||||
Reference in New Issue
Block a user