-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBootSwitch.c
More file actions
40 lines (31 loc) · 1016 Bytes
/
Copy pathBootSwitch.c
File metadata and controls
40 lines (31 loc) · 1016 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "pico/stdlib.h"
#include "bsp/board.h"
#include "tusb.h"
// GPIO pin for the boot selector switch
// Switch open / HIGH (pull-up) → Linux (default=0)
// Switch closed / LOW → Windows (default=1)
#define SWITCH_PIN 15
// Declared in msc_disk.c
void msc_set_boot_target(bool linux_selected);
int main(void) {
board_init();
// Initialize switch GPIO with internal pull-up
gpio_init(SWITCH_PIN);
gpio_set_dir(SWITCH_PIN, GPIO_IN);
gpio_pull_up(SWITCH_PIN);
// Read initial switch position and configure virtual disk
bool linux_selected = gpio_get(SWITCH_PIN);
msc_set_boot_target(linux_selected);
// Initialize USB
tusb_init();
bool last_switch = linux_selected;
while (true) {
tud_task();
// Detect switch change and update grub.cfg on the fly
bool current = gpio_get(SWITCH_PIN);
if (current != last_switch) {
last_switch = current;
msc_set_boot_target(current);
}
}
}