fix(pa01): SD storage hangs after copy a large file (#6783)

Co-authored-by: 3djc <3djc@gh.com>
This commit is contained in:
richardclli
2025-12-05 11:43:51 +10:00
committed by GitHub
co-authored by 3djc
parent 12801409da
commit 86b51fdd23
14 changed files with 63 additions and 9 deletions
+14 -8
View File
@@ -68,13 +68,15 @@ enum PhysicalKeys
ENT = 16
};
extern bool suspendI2CTasks;
static bool fct_state[4] = {false, false, false, false};
static uint32_t keyState = 0;
#if !defined(BOOT)
static uint32_t nonReadCount = 0;
#endif
static uint32_t _readKeyMatrix()
void pollKeys()
{
#if !defined(BOOT)
if(!bsp_get_shouldReadKeys() && nonReadCount < 10)
@@ -83,10 +85,12 @@ static uint32_t _readKeyMatrix()
keyState |= 1<<ENT;
nonReadCount++;
return keyState;
}
nonReadCount = 0;
#endif
if (suspendI2CTasks) return;
// This function avoids concurrent matrix agitation
uint32_t result = 0;
@@ -98,13 +102,17 @@ static uint32_t _readKeyMatrix()
uint8_t ui8ReadInProgress = 0;
} syncelem;
if (syncelem.ui8ReadInProgress != 0) return syncelem.oldResult;
if (syncelem.ui8ReadInProgress != 0) {
keyState = syncelem.oldResult;
}
// ui8ReadInProgress was 0, increment it
syncelem.ui8ReadInProgress++;
// Double check before continuing, as non-atomic, non-blocking so far
// If ui8ReadInProgress is above 1, then there was concurrent task calling it, exit
if (syncelem.ui8ReadInProgress > 1) return syncelem.oldResult;
if (syncelem.ui8ReadInProgress > 1) {
keyState = syncelem.oldResult;
}
// If we land here, we have exclusive access to Matrix
bsp_output_set(BSP_KEY_OUT_MASK, ~BSP_KEY_OUT1);
@@ -170,8 +178,6 @@ static uint32_t _readKeyMatrix()
fct_state[3] = (result & 1<<KEY4)?true:false;
keyState = result;
return result;
}
void keysInit()
@@ -183,7 +189,7 @@ uint32_t readKeys()
{
uint32_t result = 0;
uint32_t mkeys = _readKeyMatrix();
uint32_t mkeys = keyState;
if (mkeys & (1 << PGUP)) result |= 1 << KEY_PAGEUP;
if (mkeys & (1 << PGDN)) result |= 1 << KEY_PAGEDN;
if (mkeys & (1 << RTN)) result |= 1 << KEY_EXIT;
@@ -195,7 +201,7 @@ uint32_t readKeys()
uint32_t readTrims()
{
uint32_t mkeys = _readKeyMatrix();
uint32_t mkeys = keyState;
return mkeys & 0xff; // Mask only the trims output
}