/**
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "pico/stdlib.h"
#include "pico/binary_info.h"
#ifdef CYW43_WL_GPIO_LED_PIN
#include "pico/cyw43_arch.h"
#endif
// Set an LED_TYPE variable - 0 is default, 1 is connected to WIFI chip
// Note that LED_TYPE == 1 is only supported when initially compiled for
// a board with PICO_CYW43_SUPPORTED (eg pico_w), else the required
// libraries won't be present
bi_decl(bi_program_feature_group(0x1111, 0, "LED Configuration"));
#if defined(PICO_DEFAULT_LED_PIN)
// the tag and id are not important as picotool filters based on the
// variable name, so just set them to 0
bi_decl(bi_ptr_int32(0x1111, 0, LED_TYPE, 0));
bi_decl(bi_ptr_int32(0x1111, 0, LED_PIN, PICO_DEFAULT_LED_PIN));
#elif defined(CYW43_WL_GPIO_LED_PIN)
bi_decl(bi_ptr_int32(0x1111, 0, LED_TYPE, 1));
bi_decl(bi_ptr_int32(0x1111, 0, LED_PIN, CYW43_WL_GPIO_LED_PIN));
#else
bi_decl(bi_ptr_int32(0x1111, 0, LED_TYPE, 0));
bi_decl(bi_ptr_int32(0x1111, 0, LED_PIN, 25));
#endif
#ifndef LED_DELAY_MS
#define LED_DELAY_MS 250
#endif
// Perform initialisation
int pico_led_init(void) {
if (LED_TYPE == 0) {
// A device like Pico that uses a GPIO for the LED so we can
// use normal GPIO functionality to turn the led on and off
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
return PICO_OK;
#ifdef CYW43_WL_GPIO_LED_PIN
} else if (LED_TYPE == 1) {
// For Pico W devices we need to initialise the driver etc
return cyw43_arch_init();
#endif
} else {
return PICO_ERROR_INVALID_DATA;
}
}
// Turn the led on or off
void pico_set_led(bool led_on) {
if (LED_TYPE == 0) {
// Just set the GPIO on or off
gpio_put(LED_PIN, led_on);
#ifdef CYW43_WL_GPIO_LED_PIN
} else if (LED_TYPE == 1) {
// Ask the wifi "driver" to set the GPIO on or off
cyw43_arch_gpio_put(LED_PIN, led_on);
#endif
}
}
int main() {
int rc = pico_led_init();
hard_assert(rc == PICO_OK);
while (true) {
pico_set_led(true);
sleep_ms(LED_DELAY_MS);
pico_set_led(false);
sleep_ms(LED_DELAY_MS);
}
}
This firmware image was imported from the pico-examples repository.
Copyright 2020 (c) 2020 Raspberry Pi (Trading) Ltd.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Before flashing, please put your Raspberry Pi Pico™ chip in the bootloader mode by keeping the BOOTSEL button pressed while powering up. For more information, please take a look at your board's datasheet.
If you find yourself unable to perform any of the operations, please navigate to the troubleshooting, and the Q&A pages.
The "π Check installed version" button doesn't send your firmware to the Internet. Instead, its algorithm compares the firmware builds' UF2 block hashes safely in your web browser.
The installed firmware version is compared only with all the different versions (builds) of the same project.
Exercise caution while exploring projects of unknown origin. In principle, anyone can publish their firmware here. Projects endorsed by this website will always come with the "submitted by flashmypico" text written just below their title.
A part of your chip's unique RANDID number may be sent to the server if this project's author has enabled the installed version tracking feature. This number will only be logged if the project's author already has it, and has used it to enable this feature for this particular board.