-
Notifications
You must be signed in to change notification settings - Fork 18
Add some examples, improve the assembler #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3a64ca7
hello pio example
jepler 72c2324
Adapt first example from the Micropython book
jepler ebdf4e3
assemble: Diagnose duplicate labels
jepler 3ad9fae
assemble: better diagnose jump to undefined label
jepler 0d56e19
run black
jepler 0635463
disable a pylint diagnostic
jepler 9cf38eb
Pylint changes
jepler 8db157b
Explain where these examples come from
jepler b8e8c92
Remove unneeded 'set pindirs', fix minimum frequency
jepler d727e55
Explain why a needless jmp is here
jepler b5b8e35
add blink example
jepler 9399b44
pylint
jepler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<!-- | ||
SPDX-FileCopyrightText: 2020 Jeff Epler, written for Adafruit Industries | ||
|
||
SPDX-License-Identifier: MIT | ||
--> | ||
|
||
These examples are adapted from [Getting started with MicroPython on the Raspberry Pi Pico](https://www.adafruit.com/product/4898). You can also get an [electonic copy](https://hackspace.raspberrypi.org/books/micropython-pico/). PIO is covered in Appendix C. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# SPDX-FileCopyrightText: 2021 Jeff Epler, written for Adafruit Industries | ||
# | ||
# SPDX-License-Identifier: MIT | ||
# | ||
# Adapted from the an example in Appendix C of RPi_PiPico_Digital_v10.pdf | ||
|
||
import time | ||
import board | ||
import rp2pio | ||
import adafruit_pioasm | ||
|
||
led_quarter_brightness = adafruit_pioasm.assemble( | ||
""" | ||
set pins, 0 [2] | ||
set pins, 1 | ||
""" | ||
) | ||
|
||
led_half_brightness = adafruit_pioasm.assemble( | ||
""" | ||
set pins, 0 | ||
set pins, 1 | ||
""" | ||
) | ||
|
||
led_full_brightness = adafruit_pioasm.assemble( | ||
""" | ||
set pins, 1 | ||
""" | ||
) | ||
|
||
while True: | ||
sm = rp2pio.StateMachine( | ||
led_quarter_brightness, frequency=10000, first_set_pin=board.LED | ||
) | ||
time.sleep(1) | ||
sm.deinit() | ||
|
||
sm = rp2pio.StateMachine( | ||
led_half_brightness, frequency=10000, first_set_pin=board.LED | ||
) | ||
time.sleep(1) | ||
sm.deinit() | ||
|
||
sm = rp2pio.StateMachine( | ||
led_full_brightness, frequency=10000, first_set_pin=board.LED | ||
) | ||
time.sleep(1) | ||
sm.deinit() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<!-- | ||
SPDX-FileCopyrightText: 2020 Jeff Epler, written for Adafruit Industries | ||
|
||
SPDX-License-Identifier: MIT | ||
--> | ||
|
||
These examples are adapted from the pio folder of the [Raspberry Pi Pico SDK Examples](https://github.com/raspberrypi/pico-examples). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# SPDX-FileCopyrightText: 2021 Jeff Epler, written for Adafruit Industries | ||
# | ||
# SPDX-License-Identifier: MIT | ||
# | ||
# Adapted from the example https://github.com/raspberrypi/pico-examples/tree/master/pio/hello_pio | ||
|
||
import time | ||
import board | ||
import rp2pio | ||
import adafruit_pioasm | ||
|
||
hello = """ | ||
.program hello | ||
loop: | ||
pull | ||
out pins, 1 | ||
; This program uses a 'jmp' at the end to follow the example. However, | ||
; in a many cases (including this one!) there is no jmp needed at the end | ||
; and the default "wrap" behavior will automatically return to the "pull" | ||
; instruction at the beginning. | ||
jmp loop | ||
tannewt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
|
||
assembled = adafruit_pioasm.assemble(hello) | ||
|
||
sm = rp2pio.StateMachine( | ||
assembled, | ||
frequency=2000, | ||
first_out_pin=board.LED, | ||
) | ||
print("real frequency", sm.frequency) | ||
|
||
while True: | ||
sm.write(bytes((1,))) | ||
time.sleep(0.5) | ||
sm.write(bytes((0,))) | ||
time.sleep(0.5) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check will only work for single digit targets but it could be up to 32. Instead, you could try and
int(target)
and then catch the error.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite, but maybe the code is too clever as written. It looks whether the first character (if present) in target is a digit.