Initial Release
This commit is contained in:
14
pio/pio_blink/CMakeLists.txt
Normal file
14
pio/pio_blink/CMakeLists.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
add_executable(pio_blink)
|
||||
|
||||
# by default the header is generated into the build dir
|
||||
pico_generate_pio_header(pio_blink ${CMAKE_CURRENT_LIST_DIR}/blink.pio)
|
||||
# however, alternatively you can choose to generate it somewhere else (in this case in the source tree for check in)
|
||||
#pico_generate_pio_header(pio_blink ${CMAKE_CURRENT_LIST_DIR}/blink.pio OUTPUT_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
target_sources(pio_blink PRIVATE blink.c)
|
||||
|
||||
target_link_libraries(pio_blink PRIVATE pico_stdlib hardware_pio)
|
||||
pico_add_extra_outputs(pio_blink)
|
||||
|
||||
# add url via pico_set_program_url
|
||||
example_auto_set_url(pio_blink)
|
||||
34
pio/pio_blink/blink.c
Normal file
34
pio/pio_blink/blink.c
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "pico/stdlib.h"
|
||||
#include "hardware/pio.h"
|
||||
#include "blink.pio.h"
|
||||
|
||||
void blink_pin_forever(PIO pio, uint sm, uint offset, uint pin, uint freq);
|
||||
|
||||
int main() {
|
||||
setup_default_uart();
|
||||
|
||||
// todo get free sm
|
||||
PIO pio = pio0;
|
||||
uint offset = pio_add_program(pio, &blink_program);
|
||||
printf("Loaded program at %d\n", offset);
|
||||
|
||||
blink_pin_forever(pio, 0, offset, 0, 3);
|
||||
blink_pin_forever(pio, 1, offset, 6, 4);
|
||||
blink_pin_forever(pio, 2, offset, 11, 1);
|
||||
}
|
||||
|
||||
void blink_pin_forever(PIO pio, uint sm, uint offset, uint pin, uint freq) {
|
||||
blink_program_init(pio, sm, offset, pin);
|
||||
pio_sm_set_enabled(pio, sm, true);
|
||||
|
||||
printf("Blinking pin %d at freq %d\n", pin, freq);
|
||||
pio->txf[sm] = 24000000 / freq;
|
||||
}
|
||||
34
pio/pio_blink/blink.pio
Normal file
34
pio/pio_blink/blink.pio
Normal file
@@ -0,0 +1,34 @@
|
||||
;
|
||||
; Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
|
||||
;
|
||||
; SPDX-License-Identifier: BSD-3-Clause
|
||||
;
|
||||
|
||||
; SET pin 0 should be mapped to your LED GPIO
|
||||
|
||||
.program blink
|
||||
pull block
|
||||
out y, 32
|
||||
.wrap_target
|
||||
mov x, y
|
||||
set pins, 1 ; Turn LED on
|
||||
lp1:
|
||||
jmp x-- lp1 ; Delay for (x + 1) cycles, x is a 32 bit number
|
||||
mov x, y
|
||||
set pins, 0 ; Turn LED off
|
||||
lp2:
|
||||
jmp x-- lp2 ; Delay for the same number of cycles again
|
||||
.wrap ; Blink forever!
|
||||
|
||||
|
||||
% c-sdk {
|
||||
// this is a raw helper function for use by the user which sets up the GPIO output, and configures the SM to output on a particular pin
|
||||
|
||||
void blink_program_init(PIO pio, uint sm, uint offset, uint pin) {
|
||||
pio_gpio_init(pio, pin);
|
||||
pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true);
|
||||
pio_sm_config c = blink_program_get_default_config(offset);
|
||||
sm_config_set_set_pins(&c, pin, 1);
|
||||
pio_sm_init(pio, sm, offset, &c);
|
||||
}
|
||||
%}
|
||||
Reference in New Issue
Block a user