Skip to content

Commit d2cdf6c

Browse files
add pioasm --version, and print version number in generated files (#2554)
* add pioasm --version, and print version number in generated files * Hook up pio version string in Bazel build --------- Co-authored-by: Armando Montanez <[email protected]>
1 parent 19904be commit d2cdf6c

File tree

14 files changed

+98
-9
lines changed

14 files changed

+98
-9
lines changed

src/rp2_common/hardware_pio/include/hardware/pio_instructions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
* parameters.
1919
*
2020
* For fuller descriptions of the instructions in question see the "RP2040 Datasheet"
21+
*
22+
* NOTE: These are helper functions for the raw instruction encoding, and thus
23+
* only provide support for pins numbered 0-31. You should adjust your encoding
24+
* according to your expected GPIO_BASE (see \ref pio_set_gpio_base)
2125
*/
2226

2327
// PICO_CONFIG: PARAM_ASSERTIONS_ENABLED_PIO_INSTRUCTIONS, Enable/disable assertions in the PIO instructions, type=bool, default=0, group=pio_instructions

test/kitchen_sink/BUILD.bazel

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("//bazel:defs.bzl", "compatible_with_rp2")
1+
load("//bazel:defs.bzl", "compatible_with_rp2", "pico_generate_pio_header")
22
load("//bazel/util:transition.bzl", "kitchen_sink_test_binary")
33

44
package(default_visibility = ["//visibility:public"])
@@ -21,6 +21,11 @@ cc_library(
2121
includes = ["."],
2222
)
2323

24+
pico_generate_pio_header(
25+
name = "trivial_pio_test",
26+
srcs = ["trivial.pio"],
27+
)
28+
2429
cc_library(
2530
name = "kitchen_sink_common",
2631
testonly = True,

test/kitchen_sink/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ pico_set_program_name(kitchen_sink "Wombat tentacles")
105105
pico_add_extra_outputs(kitchen_sink)
106106
target_compile_definitions(kitchen_sink PRIVATE KITCHEN_SINK_ID="regular binary")
107107

108+
if (TARGET hardware_pio)
109+
pico_generate_pio_header(kitchen_sink ${CMAKE_CURRENT_LIST_DIR}/trivial.pio)
110+
endif()
111+
108112
add_executable(kitchen_sink_extra_stdio ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink.c)
109113
if (COMMAND suppress_tinyusb_warnings)
110114
# Explicitly suppress warnings in TinyUSB files which have them (this has to be done

test/kitchen_sink/trivial.pio

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.program trivial
2+
3+
out pins, 1

tools/Findpioasm.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ if (NOT TARGET pioasm)
3434
"-DCMAKE_RULE_MESSAGES=OFF" # quieten the build
3535
"-DCMAKE_INSTALL_MESSAGE=NEVER" # quieten the install
3636
CMAKE_CACHE_ARGS "-DPIOASM_EXTRA_SOURCE_FILES:STRING=${PIOASM_EXTRA_SOURCE_FILES}"
37+
"-DPIOASM_VERSION_STRING:STRING=${PICO_SDK_VERSION_STRING}"
3738
BUILD_ALWAYS 1 # force dependency checking
3839
EXCLUDE_FROM_ALL TRUE
3940
)

tools/pioasm/BUILD.bazel

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
2+
13
package(default_visibility = ["//visibility:public"])
24

35
# TODO: No support for building the parser.
@@ -19,6 +21,7 @@ cc_library(
1921
"pio_disassembler.h",
2022
"pio_enums.h",
2123
"pio_types.h",
24+
":version",
2225
],
2326
copts = select({
2427
"@rules_cc//cc/compiler:msvc-cl": ["/std:c++20"],
@@ -63,6 +66,15 @@ cc_library(
6366
alwayslink = True,
6467
)
6568

69+
expand_template(
70+
name = "version",
71+
template = "version.h.in",
72+
substitutions = {
73+
"${PIOASM_VERSION_STRING}": module_version() if module_version() != None else "0.0.1-WORKSPACE",
74+
},
75+
out = "gen/version.h",
76+
)
77+
6678
cc_binary(
6779
name = "pioasm",
6880
deps = [

tools/pioasm/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND
4141
target_compile_options(pioasm PRIVATE -Wno-psabi)
4242
endif()
4343

44-
target_include_directories(pioasm PRIVATE ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}/gen)
44+
if (NOT PIOASM_VERSION_STRING)
45+
message(FATAL_ERROR "PIOASM_VERSION_STRING must be provided when building pioasm")
46+
endif()
47+
48+
configure_file( ${CMAKE_CURRENT_LIST_DIR}/version.h.in ${CMAKE_BINARY_DIR}/version.h)
49+
50+
target_include_directories(pioasm PRIVATE ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}/gen ${CMAKE_BINARY_DIR})
4551

4652
if (MSVC OR
4753
(WIN32 AND NOT MINGW AND (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")))

tools/pioasm/ada_output.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313

1414
#include <algorithm>
1515
#include <iostream>
16+
#include <sstream>
1617
#include "output_format.h"
1718
#include "pio_disassembler.h"
19+
#include "version.h"
1820

1921
struct ada_output : public output_format {
2022
struct factory {
@@ -97,7 +99,9 @@ struct ada_output : public output_format {
9799
FILE *out = open_single_output(destination);
98100
if (!out) return 1;
99101

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

tools/pioasm/c_sdk_output.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77
#include <algorithm>
88
#include <iostream>
9+
#include <sstream>
910
#include "output_format.h"
1011
#include "pio_disassembler.h"
12+
#include "version.h"
1113

1214
struct c_sdk_output : public output_format {
1315
struct factory {
@@ -66,7 +68,9 @@ struct c_sdk_output : public output_format {
6668
FILE *out = open_single_output(destination);
6769
if (!out) return 1;
6870

69-
header(out, "This file is autogenerated by pioasm; do not edit!");
71+
std::stringstream header_string;
72+
header_string << "This file is autogenerated by pioasm version " << PIOASM_VERSION_STRING << "; do not edit!";
73+
header(out, header_string.str());
7074

7175
fprintf(out, "#pragma once\n");
7276
fprintf(out, "\n");

tools/pioasm/go_output.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414

1515
#include <algorithm>
1616
#include <iostream>
17+
#include <sstream>
1718
#include "output_format.h"
1819
#include "pio_disassembler.h"
20+
#include "version.h"
1921

2022
struct go_output : public output_format {
2123
struct factory {
@@ -63,8 +65,10 @@ struct go_output : public output_format {
6365
FILE *out = open_single_output(destination);
6466
if (!out) return 1;
6567

66-
header(out, "Code generated by pioasm; DO NOT EDIT.");
67-
68+
std::stringstream header_string;
69+
header_string << "This file is autogenerated by pioasm version " << PIOASM_VERSION_STRING << "; do not edit!";
70+
header(out, header_string.str());
71+
6872
// First we give priority to user's code blocks since
6973
// 1. In Go our imports always precede our code.
7074
// 2. We give users the freedom to use their own PIO implementation.

0 commit comments

Comments
 (0)