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

Update main.c -reduce chance of becoming stuck in bootloader #28

Merged
merged 2 commits into from
Dec 7, 2024
Merged
Changes from all 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
11 changes: 7 additions & 4 deletions bootloader/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -748,20 +748,23 @@ static void update_EEPROM()
}
#endif // UPDATE_EEPROM_ENABLE

#define low_pin_count_threshold 450 // count signal pin is low before determining jump to main firmware
#define pull_down_pin_count_interations 4000 // greater interations extend grace period for input devices booting with signal pin high
static void checkForSignal()
{
gpio_mode_set_input(input_pin, GPIO_PULL_DOWN);

delayMicroseconds(500);

for(int i = 0 ; i < 500; i ++){
for(int i = 0 ; i < pull_down_pin_count_interations ; i ++){
if(!gpio_read(input_pin)){
low_pin_count++;
}

delayMicroseconds(10);
if (low_pin_count > low_pin_count_threshold) i = pull_down_pin_count_interations ; // end for loop if low_pin_count_threshold has already been exceeded
}
if (low_pin_count > 450) {
if (low_pin_count > low_pin_count_threshold) { // pulled low & majority stayed low - jump to application
#if CHECK_SOFTWARE_RESET
if (!bl_was_software_reset()) {
jump();
Expand All @@ -784,7 +787,7 @@ static void checkForSignal()
delayMicroseconds(10);
}
if (low_pin_count == 0) {
return; // all high while pin is pulled low, bootloader signal
return; // pulled high & never low in history - stay in bootloader only
}

low_pin_count = 0;
Expand All @@ -802,7 +805,7 @@ static void checkForSignal()
}

if (low_pin_count > 0) {
jump();
jump(); // floating & low at least once - jump to application
}
}

Expand Down