Skip to content

Commit 14896b6

Browse files
committed
add pioasm --version, and print version number in generated files
1 parent 214c243 commit 14896b6

File tree

12 files changed

+80
-8
lines changed

12 files changed

+80
-8
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/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/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.

tools/pioasm/main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <iostream>
88
#include "pio_assembler.h"
9+
#include "version.h"
910

1011
#define DEFAULT_OUTPUT_FORMAT "c-sdk"
1112

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

@@ -66,6 +68,9 @@ int main(int argc, char *argv[]) {
6668
} else if (argv[i] == std::string("-?") || argv[i] == std::string("--help")) {
6769
usage();
6870
return 1;
71+
} else if (argv[i] == std::string("--version")) {
72+
std::cout << "pioasm version: " << PIOASM_VERSION_STRING << std::endl;
73+
return 0;
6974
} else {
7075
std::cerr << "error: unknown option " << argv[i] << std::endl;
7176
res = 1;

tools/pioasm/python_output.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
#include <algorithm>
99
#include <sstream>
1010
#include <iomanip>
11-
#include <iostream>
1211
#include "output_format.h"
1312
#include "pio_disassembler.h"
13+
#include "version.h"
1414

1515
struct python_output : public output_format {
1616
struct factory {
@@ -61,7 +61,9 @@ struct python_output : public output_format {
6161
FILE *out = open_single_output(destination);
6262
if (!out) return 1;
6363

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

6668
fprintf(out, "import rp2\n");
6769
fprintf(out, "from machine import Pin");

0 commit comments

Comments
 (0)