Skip to content

Commit 4d7882b

Browse files
lurchkilograham
authored andcommitted
Fix examples to build cleanly if PICO_DEFAULT_LED_PIN isn't defined
1 parent 482d965 commit 4d7882b

File tree

5 files changed

+26
-9
lines changed

5 files changed

+26
-9
lines changed

blink/blink.c

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#include "pico/stdlib.h"
88

99
int main() {
10+
#ifndef PICO_DEFAULT_LED_PIN
11+
#warning blink example requires a board with a regular LED
12+
#else
1013
const uint LED_PIN = PICO_DEFAULT_LED_PIN;
1114
gpio_init(LED_PIN);
1215
gpio_set_dir(LED_PIN, GPIO_OUT);
@@ -16,4 +19,5 @@ int main() {
1619
gpio_put(LED_PIN, 0);
1720
sleep_ms(250);
1821
}
22+
#endif
1923
}

picoboard/blinky/blinky.c

+12-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "pico/stdlib.h"
99
#include "hardware/gpio.h"
1010

11-
const uint LED_PIN = PICO_DEFAULT_LED_PIN;
1211
const uint DOT_PERIOD_MS = 100;
1312

1413
const char *morse_letters[] = {
@@ -40,36 +39,41 @@ const char *morse_letters[] = {
4039
"--.." // Z
4140
};
4241

43-
void put_morse_letter(const char *pattern) {
42+
void put_morse_letter(uint led_pin, const char *pattern) {
4443
for (; *pattern; ++pattern) {
45-
gpio_put(LED_PIN, 1);
44+
gpio_put(led_pin, 1);
4645
if (*pattern == '.')
4746
sleep_ms(DOT_PERIOD_MS);
4847
else
4948
sleep_ms(DOT_PERIOD_MS * 3);
50-
gpio_put(LED_PIN, 0);
49+
gpio_put(led_pin, 0);
5150
sleep_ms(DOT_PERIOD_MS * 1);
5251
}
5352
sleep_ms(DOT_PERIOD_MS * 2);
5453
}
5554

56-
void put_morse_str(const char *str) {
55+
void put_morse_str(uint led_pin, const char *str) {
5756
for (; *str; ++str) {
5857
if (*str >= 'A' && *str < 'Z') {
59-
put_morse_letter(morse_letters[*str - 'A']);
58+
put_morse_letter(led_pin, morse_letters[*str - 'A']);
6059
} else if (*str >= 'a' && *str < 'z') {
61-
put_morse_letter(morse_letters[*str - 'a']);
60+
put_morse_letter(led_pin, morse_letters[*str - 'a']);
6261
} else if (*str == ' ') {
6362
sleep_ms(DOT_PERIOD_MS * 4);
6463
}
6564
}
6665
}
6766

6867
int main() {
68+
#ifndef PICO_DEFAULT_LED_PIN
69+
#warning picoboard/blinky example requires a board with a regular LED
70+
#else
71+
const uint LED_PIN = PICO_DEFAULT_LED_PIN;
6972
gpio_init(LED_PIN);
7073
gpio_set_dir(LED_PIN, GPIO_OUT);
7174
while (true) {
72-
put_morse_str("Hello world");
75+
put_morse_str(LED_PIN, "Hello world");
7376
sleep_ms(1000);
7477
}
78+
#endif
7579
}

picoboard/button/button.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ bool __no_inline_not_in_flash_func(get_bootsel_button)() {
5454

5555
int main() {
5656
#ifndef PICO_DEFAULT_LED_PIN
57-
#warning picobooard/button example requires a board with a regular LED
57+
#warning picoboard/button example requires a board with a regular LED
5858
#else
5959
gpio_init(PICO_DEFAULT_LED_PIN);
6060
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);

pio/pwm/pwm.c

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ void pio_pwm_set_level(PIO pio, uint sm, uint32_t level) {
2626

2727
int main() {
2828
stdio_init_all();
29+
#ifndef PICO_DEFAULT_LED_PIN
30+
#warning pio/pwm example requires a board with a regular LED
31+
puts("Default LED pin was not defined");
32+
#else
2933

3034
// todo get free sm
3135
PIO pio = pio0;
@@ -43,4 +47,5 @@ int main() {
4347
level = (level + 1) % 256;
4448
sleep_ms(10);
4549
}
50+
#endif
4651
}

system/hello_double_tap/hello_double_tap.c

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
// `pico_bootsel_via_double_reset` library!
1414

1515
int main() {
16+
#ifndef PICO_DEFAULT_LED_PIN
17+
#warning system/hello_double_tap example requires a board with a regular LED
18+
#else
1619
const uint LED_PIN = PICO_DEFAULT_LED_PIN;
1720
gpio_init(LED_PIN);
1821
gpio_set_dir(LED_PIN, GPIO_OUT);
@@ -22,4 +25,5 @@ int main() {
2225
gpio_put(LED_PIN, 0);
2326
sleep_ms(250);
2427
}
28+
#endif
2529
}

0 commit comments

Comments
 (0)