Initial Release
This commit is contained in:
4
picoboard/CMakeLists.txt
Normal file
4
picoboard/CMakeLists.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
if (NOT PICO_NO_HARDWARE)
|
||||
add_subdirectory(blinky)
|
||||
add_subdirectory(button)
|
||||
endif ()
|
||||
12
picoboard/blinky/CMakeLists.txt
Normal file
12
picoboard/blinky/CMakeLists.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
add_executable(picoboard_blinky
|
||||
blinky.c
|
||||
)
|
||||
|
||||
# Pull in our pico_stdlib which pulls in commonly used features
|
||||
target_link_libraries(picoboard_blinky pico_stdlib)
|
||||
|
||||
# create map/bin/hex file etc.
|
||||
pico_add_extra_outputs(picoboard_blinky)
|
||||
|
||||
# add url via pico_set_program_url
|
||||
example_auto_set_url(picoboard_blinky)
|
||||
75
picoboard/blinky/blinky.c
Normal file
75
picoboard/blinky/blinky.c
Normal file
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "pico/stdlib.h"
|
||||
#include "hardware/gpio.h"
|
||||
|
||||
const uint LED_PIN = 25;
|
||||
const uint DOT_PERIOD_MS = 100;
|
||||
|
||||
const char *morse_letters[] = {
|
||||
".-", // A
|
||||
"-...", // B
|
||||
"-.-.", // C
|
||||
"-..", // D
|
||||
".", // E
|
||||
"..-.", // F
|
||||
"--.", // G
|
||||
"....", // H
|
||||
"..", // I
|
||||
".---", // J
|
||||
"-.-", // K
|
||||
".-..", // L
|
||||
"--", // M
|
||||
"-.", // N
|
||||
"---", // O
|
||||
".--.", // P
|
||||
"--.-", // Q
|
||||
".-.", // R
|
||||
"...", // S
|
||||
"-", // T
|
||||
"..-", // U
|
||||
"...-", // V
|
||||
".--", // W
|
||||
"-..-", // X
|
||||
"-.--", // Y
|
||||
"--.." // Z
|
||||
};
|
||||
|
||||
void put_morse_letter(const char *pattern) {
|
||||
for (; *pattern; ++pattern) {
|
||||
gpio_put(LED_PIN, 1);
|
||||
if (*pattern == '.')
|
||||
sleep_ms(DOT_PERIOD_MS);
|
||||
else
|
||||
sleep_ms(DOT_PERIOD_MS * 3);
|
||||
gpio_put(LED_PIN, 0);
|
||||
sleep_ms(DOT_PERIOD_MS * 1);
|
||||
}
|
||||
sleep_ms(DOT_PERIOD_MS * 2);
|
||||
}
|
||||
|
||||
void put_morse_str(const char *str) {
|
||||
for (; *str; ++str) {
|
||||
if (*str >= 'A' && *str < 'Z') {
|
||||
put_morse_letter(morse_letters[*str - 'A']);
|
||||
} else if (*str >= 'a' && *str < 'z') {
|
||||
put_morse_letter(morse_letters[*str - 'a']);
|
||||
} else if (*str == ' ') {
|
||||
sleep_ms(DOT_PERIOD_MS * 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
gpio_init(LED_PIN);
|
||||
gpio_set_dir(LED_PIN, GPIO_OUT);
|
||||
while (true) {
|
||||
put_morse_str("Hello world");
|
||||
sleep_ms(1000);
|
||||
}
|
||||
}
|
||||
12
picoboard/button/CMakeLists.txt
Normal file
12
picoboard/button/CMakeLists.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
add_executable(picoboard_button
|
||||
button.c
|
||||
)
|
||||
|
||||
# Pull in our pico_stdlib which pulls in commonly used features
|
||||
target_link_libraries(picoboard_button pico_stdlib)
|
||||
|
||||
# create map/bin/hex file etc.
|
||||
pico_add_extra_outputs(picoboard_button)
|
||||
|
||||
# add url via pico_set_program_url
|
||||
example_auto_set_url(picoboard_button)
|
||||
62
picoboard/button/button.c
Normal file
62
picoboard/button/button.c
Normal file
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "pico/stdlib.h"
|
||||
#include "hardware/gpio.h"
|
||||
#include "hardware/sync.h"
|
||||
#include "hardware/structs/ioqspi.h"
|
||||
#include "hardware/structs/sio.h"
|
||||
|
||||
// This example blinks the Picoboard LED when the BOOTSEL button is pressed.
|
||||
//
|
||||
// Picoboard has a button attached to the flash CS pin, which the bootrom
|
||||
// checks, and jumps straight to the USB bootcode if the button is pressed
|
||||
// (pulling flash CS low). We can check this pin in by jumping to some code in
|
||||
// SRAM (so that the XIP interface is not required), floating the flash CS
|
||||
// pin, and observing whether it is pulled low.
|
||||
//
|
||||
// This doesn't work if others are trying to access flash at the same time,
|
||||
// e.g. XIP streamer, or the other core.
|
||||
|
||||
bool __no_inline_not_in_flash_func(get_bootsel_button)() {
|
||||
const uint CS_PIN_INDEX = 1;
|
||||
|
||||
// Must disable interrupts, as interrupt handlers may be in flash, and we
|
||||
// are about to temporarily disable flash access!
|
||||
uint32_t flags = save_and_disable_interrupts();
|
||||
|
||||
// Set chip select to Hi-Z
|
||||
hw_write_masked(&ioqspi_hw->io[CS_PIN_INDEX].ctrl,
|
||||
GPIO_OVERRIDE_LOW << IO_QSPI_GPIO_QSPI_SS_CTRL_OEOVER_LSB,
|
||||
IO_QSPI_GPIO_QSPI_SS_CTRL_OEOVER_BITS);
|
||||
|
||||
// Note we can't call into any sleep functions in flash right now
|
||||
for (volatile int i = 0; i < 1000; ++i);
|
||||
|
||||
// The HI GPIO registers in SIO can observe and control the 6 QSPI pins.
|
||||
// Note the button pulls the pin *low* when pressed.
|
||||
bool button_state = !(sio_hw->gpio_hi_in & (1u << CS_PIN_INDEX));
|
||||
|
||||
// Need to restore the state of chip select, else we are going to have a
|
||||
// bad time when we return to code in flash!
|
||||
hw_write_masked(&ioqspi_hw->io[CS_PIN_INDEX].ctrl,
|
||||
GPIO_OVERRIDE_NORMAL << IO_QSPI_GPIO_QSPI_SS_CTRL_OEOVER_LSB,
|
||||
IO_QSPI_GPIO_QSPI_SS_CTRL_OEOVER_BITS);
|
||||
|
||||
restore_interrupts(flags);
|
||||
|
||||
return button_state;
|
||||
}
|
||||
|
||||
int main() {
|
||||
gpio_init(PICO_DEFAULT_LED_PIN);
|
||||
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
|
||||
while (true) {
|
||||
gpio_put(PICO_DEFAULT_LED_PIN, get_bootsel_button());
|
||||
sleep_ms(10);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user