Skip to content

Commit d3b66c3

Browse files
committed
RP2040: make sure double tap utility gets called before any contructor
1 parent 0726b5f commit d3b66c3

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

Diff for: variants/RASPBERRY_PI_PICO/double_tap_usb_boot.c renamed to variants/NANO_RP2040_CONNECT/double_tap_usb_boot.cpp

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
#include "pico.h"
2-
#include "pico/time.h"
3-
#include "pico/bootrom.h"
1+
extern "C" {
2+
#include "pico.h"
3+
#include "pico/time.h"
4+
#include "pico/bootrom.h"
5+
}
46

57
// Allow user override of the LED mask
68
#ifndef USB_BOOT_LED_ACTIVITY_MASK
@@ -17,14 +19,14 @@ static const uint32_t magic_token[] = {
1719
static uint32_t __uninitialized_ram(magic_location)[count_of(magic_token)];
1820

1921
// run at initialization time
20-
static void __attribute__((constructor)) boot_double_tap_check() {
22+
static void boot_double_tap_check() {
2123
for (uint i = 0; i < count_of(magic_token); i++) {
2224
if (magic_location[i] != magic_token[i]) {
2325
// Arm for 100 ms then disarm and continue booting
2426
for (i = 0; i < count_of(magic_token); i++) {
2527
magic_location[i] = magic_token[i];
2628
}
27-
busy_wait_us(100000);
29+
busy_wait_us(500000);
2830
magic_location[0] = 0;
2931
return;
3032
}
@@ -34,4 +36,13 @@ static void __attribute__((constructor)) boot_double_tap_check() {
3436
reset_usb_boot(USB_BOOT_LED_ACTIVITY_MASK, 0);
3537
}
3638

39+
class DoubleTap {
40+
public:
41+
DoubleTap() {
42+
boot_double_tap_check();
43+
}
44+
};
45+
46+
DoubleTap dt __attribute__ ((init_priority (101)));
47+
3748
#endif

Diff for: variants/NANO_RP2040_CONNECT/double_tap_usb_boot.c renamed to variants/RASPBERRY_PI_PICO/double_tap_usb_boot.cpp

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
#include "pico.h"
2-
#include "pico/time.h"
3-
#include "pico/bootrom.h"
1+
extern "C" {
2+
#include "pico.h"
3+
#include "pico/time.h"
4+
#include "pico/bootrom.h"
5+
}
46

57
// Allow user override of the LED mask
68
#ifndef USB_BOOT_LED_ACTIVITY_MASK
@@ -17,7 +19,7 @@ static const uint32_t magic_token[] = {
1719
static uint32_t __uninitialized_ram(magic_location)[count_of(magic_token)];
1820

1921
// run at initialization time
20-
static void __attribute__((constructor)) boot_double_tap_check() {
22+
static void boot_double_tap_check() {
2123
for (uint i = 0; i < count_of(magic_token); i++) {
2224
if (magic_location[i] != magic_token[i]) {
2325
// Arm for 100 ms then disarm and continue booting
@@ -34,4 +36,13 @@ static void __attribute__((constructor)) boot_double_tap_check() {
3436
reset_usb_boot(USB_BOOT_LED_ACTIVITY_MASK, 0);
3537
}
3638

39+
class DoubleTap {
40+
public:
41+
DoubleTap() {
42+
boot_double_tap_check();
43+
}
44+
};
45+
46+
DoubleTap dt __attribute__ ((init_priority (101)));
47+
3748
#endif

0 commit comments

Comments
 (0)