Fix examples to build cleanly if PICO_DEFAULT_LED_PIN isn't defined
This commit is contained in:
parent
482d9657d3
commit
4d7882bc59
@ -7,6 +7,9 @@
|
|||||||
#include "pico/stdlib.h"
|
#include "pico/stdlib.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
#ifndef PICO_DEFAULT_LED_PIN
|
||||||
|
#warning blink example requires a board with a regular LED
|
||||||
|
#else
|
||||||
const uint LED_PIN = PICO_DEFAULT_LED_PIN;
|
const uint LED_PIN = PICO_DEFAULT_LED_PIN;
|
||||||
gpio_init(LED_PIN);
|
gpio_init(LED_PIN);
|
||||||
gpio_set_dir(LED_PIN, GPIO_OUT);
|
gpio_set_dir(LED_PIN, GPIO_OUT);
|
||||||
@ -16,4 +19,5 @@ int main() {
|
|||||||
gpio_put(LED_PIN, 0);
|
gpio_put(LED_PIN, 0);
|
||||||
sleep_ms(250);
|
sleep_ms(250);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,6 @@
|
|||||||
#include "pico/stdlib.h"
|
#include "pico/stdlib.h"
|
||||||
#include "hardware/gpio.h"
|
#include "hardware/gpio.h"
|
||||||
|
|
||||||
const uint LED_PIN = PICO_DEFAULT_LED_PIN;
|
|
||||||
const uint DOT_PERIOD_MS = 100;
|
const uint DOT_PERIOD_MS = 100;
|
||||||
|
|
||||||
const char *morse_letters[] = {
|
const char *morse_letters[] = {
|
||||||
@ -40,25 +39,25 @@ const char *morse_letters[] = {
|
|||||||
"--.." // Z
|
"--.." // Z
|
||||||
};
|
};
|
||||||
|
|
||||||
void put_morse_letter(const char *pattern) {
|
void put_morse_letter(uint led_pin, const char *pattern) {
|
||||||
for (; *pattern; ++pattern) {
|
for (; *pattern; ++pattern) {
|
||||||
gpio_put(LED_PIN, 1);
|
gpio_put(led_pin, 1);
|
||||||
if (*pattern == '.')
|
if (*pattern == '.')
|
||||||
sleep_ms(DOT_PERIOD_MS);
|
sleep_ms(DOT_PERIOD_MS);
|
||||||
else
|
else
|
||||||
sleep_ms(DOT_PERIOD_MS * 3);
|
sleep_ms(DOT_PERIOD_MS * 3);
|
||||||
gpio_put(LED_PIN, 0);
|
gpio_put(led_pin, 0);
|
||||||
sleep_ms(DOT_PERIOD_MS * 1);
|
sleep_ms(DOT_PERIOD_MS * 1);
|
||||||
}
|
}
|
||||||
sleep_ms(DOT_PERIOD_MS * 2);
|
sleep_ms(DOT_PERIOD_MS * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void put_morse_str(const char *str) {
|
void put_morse_str(uint led_pin, const char *str) {
|
||||||
for (; *str; ++str) {
|
for (; *str; ++str) {
|
||||||
if (*str >= 'A' && *str < 'Z') {
|
if (*str >= 'A' && *str < 'Z') {
|
||||||
put_morse_letter(morse_letters[*str - 'A']);
|
put_morse_letter(led_pin, morse_letters[*str - 'A']);
|
||||||
} else if (*str >= 'a' && *str < 'z') {
|
} else if (*str >= 'a' && *str < 'z') {
|
||||||
put_morse_letter(morse_letters[*str - 'a']);
|
put_morse_letter(led_pin, morse_letters[*str - 'a']);
|
||||||
} else if (*str == ' ') {
|
} else if (*str == ' ') {
|
||||||
sleep_ms(DOT_PERIOD_MS * 4);
|
sleep_ms(DOT_PERIOD_MS * 4);
|
||||||
}
|
}
|
||||||
@ -66,10 +65,15 @@ void put_morse_str(const char *str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
#ifndef PICO_DEFAULT_LED_PIN
|
||||||
|
#warning picoboard/blinky example requires a board with a regular LED
|
||||||
|
#else
|
||||||
|
const uint LED_PIN = PICO_DEFAULT_LED_PIN;
|
||||||
gpio_init(LED_PIN);
|
gpio_init(LED_PIN);
|
||||||
gpio_set_dir(LED_PIN, GPIO_OUT);
|
gpio_set_dir(LED_PIN, GPIO_OUT);
|
||||||
while (true) {
|
while (true) {
|
||||||
put_morse_str("Hello world");
|
put_morse_str(LED_PIN, "Hello world");
|
||||||
sleep_ms(1000);
|
sleep_ms(1000);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@ -54,7 +54,7 @@ bool __no_inline_not_in_flash_func(get_bootsel_button)() {
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
#ifndef PICO_DEFAULT_LED_PIN
|
#ifndef PICO_DEFAULT_LED_PIN
|
||||||
#warning picobooard/button example requires a board with a regular LED
|
#warning picoboard/button example requires a board with a regular LED
|
||||||
#else
|
#else
|
||||||
gpio_init(PICO_DEFAULT_LED_PIN);
|
gpio_init(PICO_DEFAULT_LED_PIN);
|
||||||
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
|
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
|
||||||
|
|||||||
@ -26,6 +26,10 @@ void pio_pwm_set_level(PIO pio, uint sm, uint32_t level) {
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
stdio_init_all();
|
stdio_init_all();
|
||||||
|
#ifndef PICO_DEFAULT_LED_PIN
|
||||||
|
#warning pio/pwm example requires a board with a regular LED
|
||||||
|
puts("Default LED pin was not defined");
|
||||||
|
#else
|
||||||
|
|
||||||
// todo get free sm
|
// todo get free sm
|
||||||
PIO pio = pio0;
|
PIO pio = pio0;
|
||||||
@ -43,4 +47,5 @@ int main() {
|
|||||||
level = (level + 1) % 256;
|
level = (level + 1) % 256;
|
||||||
sleep_ms(10);
|
sleep_ms(10);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,9 @@
|
|||||||
// `pico_bootsel_via_double_reset` library!
|
// `pico_bootsel_via_double_reset` library!
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
#ifndef PICO_DEFAULT_LED_PIN
|
||||||
|
#warning system/hello_double_tap example requires a board with a regular LED
|
||||||
|
#else
|
||||||
const uint LED_PIN = PICO_DEFAULT_LED_PIN;
|
const uint LED_PIN = PICO_DEFAULT_LED_PIN;
|
||||||
gpio_init(LED_PIN);
|
gpio_init(LED_PIN);
|
||||||
gpio_set_dir(LED_PIN, GPIO_OUT);
|
gpio_set_dir(LED_PIN, GPIO_OUT);
|
||||||
@ -22,4 +25,5 @@ int main() {
|
|||||||
gpio_put(LED_PIN, 0);
|
gpio_put(LED_PIN, 0);
|
||||||
sleep_ms(250);
|
sleep_ms(250);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user