Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
* parameters.
*
* For fuller descriptions of the instructions in question see the "RP2040 Datasheet"
*
* NOTE: These are helper functions for the raw instruction encoding, and thus
* only provide support for pins numbered 0-31. You should adjust your encoding
* according to your expected GPIO_BASE (see \ref pio_set_gpio_base)
*/

// PICO_CONFIG: PARAM_ASSERTIONS_ENABLED_PIO_INSTRUCTIONS, Enable/disable assertions in the PIO instructions, type=bool, default=0, group=pio_instructions
Expand Down
7 changes: 6 additions & 1 deletion test/kitchen_sink/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//bazel:defs.bzl", "compatible_with_rp2")
load("//bazel:defs.bzl", "compatible_with_rp2", "pico_generate_pio_header")
load("//bazel/util:transition.bzl", "kitchen_sink_test_binary")

package(default_visibility = ["//visibility:public"])
Expand All @@ -21,6 +21,11 @@ cc_library(
includes = ["."],
)

pico_generate_pio_header(
name = "trivial_pio_test",
srcs = ["trivial.pio"],
)

cc_library(
name = "kitchen_sink_common",
testonly = True,
Expand Down
4 changes: 4 additions & 0 deletions test/kitchen_sink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ pico_set_program_name(kitchen_sink "Wombat tentacles")
pico_add_extra_outputs(kitchen_sink)
target_compile_definitions(kitchen_sink PRIVATE KITCHEN_SINK_ID="regular binary")

if (TARGET hardware_pio)
pico_generate_pio_header(kitchen_sink ${CMAKE_CURRENT_LIST_DIR}/trivial.pio)
endif()

add_executable(kitchen_sink_extra_stdio ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink.c)
if (COMMAND suppress_tinyusb_warnings)
# Explicitly suppress warnings in TinyUSB files which have them (this has to be done
Expand Down
3 changes: 3 additions & 0 deletions test/kitchen_sink/trivial.pio
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.program trivial

out pins, 1
1 change: 1 addition & 0 deletions tools/Findpioasm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ if (NOT TARGET pioasm)
"-DCMAKE_RULE_MESSAGES=OFF" # quieten the build
"-DCMAKE_INSTALL_MESSAGE=NEVER" # quieten the install
CMAKE_CACHE_ARGS "-DPIOASM_EXTRA_SOURCE_FILES:STRING=${PIOASM_EXTRA_SOURCE_FILES}"
"-DPIOASM_VERSION_STRING:STRING=${PICO_SDK_VERSION_STRING}"
BUILD_ALWAYS 1 # force dependency checking
EXCLUDE_FROM_ALL TRUE
)
Expand Down
12 changes: 12 additions & 0 deletions tools/pioasm/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")

package(default_visibility = ["//visibility:public"])

# TODO: No support for building the parser.
Expand All @@ -19,6 +21,7 @@ cc_library(
"pio_disassembler.h",
"pio_enums.h",
"pio_types.h",
":version",
],
copts = select({
"@rules_cc//cc/compiler:msvc-cl": ["/std:c++20"],
Expand Down Expand Up @@ -63,6 +66,15 @@ cc_library(
alwayslink = True,
)

expand_template(
name = "version",
template = "version.h.in",
substitutions = {
"${PIOASM_VERSION_STRING}": module_version() if module_version() != None else "0.0.1-WORKSPACE",
},
out = "gen/version.h",
)

cc_binary(
name = "pioasm",
deps = [
Expand Down
8 changes: 7 additions & 1 deletion tools/pioasm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND
target_compile_options(pioasm PRIVATE -Wno-psabi)
endif()

target_include_directories(pioasm PRIVATE ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}/gen)
if (NOT PIOASM_VERSION_STRING)
message(FATAL_ERROR "PIOASM_VERSION_STRING must be provided when building pioasm")
endif()

configure_file( ${CMAKE_CURRENT_LIST_DIR}/version.h.in ${CMAKE_BINARY_DIR}/version.h)

target_include_directories(pioasm PRIVATE ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}/gen ${CMAKE_BINARY_DIR})

if (MSVC OR
(WIN32 AND NOT MINGW AND (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")))
Expand Down
6 changes: 5 additions & 1 deletion tools/pioasm/ada_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@

#include <algorithm>
#include <iostream>
#include <sstream>
#include "output_format.h"
#include "pio_disassembler.h"
#include "version.h"

struct ada_output : public output_format {
struct factory {
Expand Down Expand Up @@ -97,7 +99,9 @@ struct ada_output : public output_format {
FILE *out = open_single_output(destination);
if (!out) return 1;

header(out, "This file is autogenerated by pioasm; do not edit!", 0);
std::stringstream header_string;
header_string << "This file is autogenerated by pioasm version " << PIOASM_VERSION_STRING << "; do not edit!";
header(out, header_string.str(), 0);
fprintf(out, "pragma Style_Checks (Off);\n\n");
fprintf(out, "with RP.PIO;\n\n");

Expand Down
6 changes: 5 additions & 1 deletion tools/pioasm/c_sdk_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

#include <algorithm>
#include <iostream>
#include <sstream>
#include "output_format.h"
#include "pio_disassembler.h"
#include "version.h"

struct c_sdk_output : public output_format {
struct factory {
Expand Down Expand Up @@ -66,7 +68,9 @@ struct c_sdk_output : public output_format {
FILE *out = open_single_output(destination);
if (!out) return 1;

header(out, "This file is autogenerated by pioasm; do not edit!");
std::stringstream header_string;
header_string << "This file is autogenerated by pioasm version " << PIOASM_VERSION_STRING << "; do not edit!";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it might be worth also including the filename (with any directory-parts removed) of the input PIO file? e.g.

// This file is autogenerated from ws2812.pio by pioasm version 2.1.2; do not edit!

header(out, header_string.str());

fprintf(out, "#pragma once\n");
fprintf(out, "\n");
Expand Down
8 changes: 6 additions & 2 deletions tools/pioasm/go_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@

#include <algorithm>
#include <iostream>
#include <sstream>
#include "output_format.h"
#include "pio_disassembler.h"
#include "version.h"

struct go_output : public output_format {
struct factory {
Expand Down Expand Up @@ -63,8 +65,10 @@ struct go_output : public output_format {
FILE *out = open_single_output(destination);
if (!out) return 1;

header(out, "Code generated by pioasm; DO NOT EDIT.");

std::stringstream header_string;
header_string << "This file is autogenerated by pioasm version " << PIOASM_VERSION_STRING << "; do not edit!";
header(out, header_string.str());

// First we give priority to user's code blocks since
// 1. In Go our imports always precede our code.
// 2. We give users the freedom to use their own PIO implementation.
Expand Down
5 changes: 5 additions & 0 deletions tools/pioasm/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <iostream>
#include "pio_assembler.h"
#include "version.h"

#define DEFAULT_OUTPUT_FORMAT "c-sdk"

Expand All @@ -24,6 +25,7 @@ void usage() {
}
std::cerr << " -p <output_param> add a parameter to be passed to the output format generator" << std::endl;
std::cerr << " -v <version> specify the default PIO version (0 or 1)" << std::endl;
std::cerr << " --version print pioasm version information" << std::endl;
std::cerr << " -?, --help print this help and exit\n";
}

Expand Down Expand Up @@ -66,6 +68,9 @@ int main(int argc, char *argv[]) {
} else if (argv[i] == std::string("-?") || argv[i] == std::string("--help")) {
usage();
return 1;
} else if (argv[i] == std::string("--version")) {
std::cout << "pioasm version: " << PIOASM_VERSION_STRING << std::endl;
return 0;
} else {
std::cerr << "error: unknown option " << argv[i] << std::endl;
res = 1;
Expand Down
6 changes: 4 additions & 2 deletions tools/pioasm/python_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <iostream>
#include "output_format.h"
#include "pio_disassembler.h"
#include "version.h"

struct python_output : public output_format {
struct factory {
Expand Down Expand Up @@ -61,7 +61,9 @@ struct python_output : public output_format {
FILE *out = open_single_output(destination);
if (!out) return 1;

header(out, "This file is autogenerated by pioasm; do not edit!");
std::stringstream header_string;
header_string << "This file is autogenerated by pioasm version " << PIOASM_VERSION_STRING << "; do not edit!";
header(out, header_string.str());

fprintf(out, "import rp2\n");
fprintf(out, "from machine import Pin");
Expand Down
21 changes: 20 additions & 1 deletion tools/pioasm/test/amethyst.pio
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,23 @@ wait gpio 40
wait 0 jmppin
wait 0 jmppin + 3
mov x, !x
.word 0x1234
.word 0x1234


.program prev_next
.pio_version 1
wait 0 irq prev 0 ; Wait for IRQ0
irq prev clear 0 ; Clear IRQ0
irq clear 0 ; Clear IRQ0
wait 0 irq next 0 ; Wait for IRQ0
irq next clear 0 ; Clear IRQ0

.program wee
.pio_version 1
wait 0 gpio 15
wait 0 gpio 31

.program wee2
.pio_version 1
wait 0 gpio 31
wait 0 gpio 47
16 changes: 16 additions & 0 deletions tools/pioasm/version.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (c) 2025 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

// ---------------------------------------
// THIS FILE IS AUTOGENERATED; DO NOT EDIT
// ---------------------------------------

#ifndef _PIOASM_VERSION_H
#define _PIOASM_VERSION_H

#define PIOASM_VERSION_STRING "${PIOASM_VERSION_STRING}"

#endif
Loading