-
Notifications
You must be signed in to change notification settings - Fork 77
Use templating for generated files #39
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 all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1a67d67
Add template for main file
matiasilva f1854f9
Add Jinja as a dependency
matiasilva b4ecd11
Convert fragments to macros
matiasilva cc95747
Generate main with templates
matiasilva 4a8c10b
Add remaining templates
matiasilva 52d1280
Refactor code to use templates
matiasilva 559ea88
Move last bit of string formatting to templates
matiasilva 1bd8403
Replace mapping defaults with lists
matiasilva 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| .vscode | ||
|
|
||
| .venv |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 @@ | ||
| Jinja2 |
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,55 @@ | ||
| # CMakeLists.txt GENERATED BY PICO PROJECT GENERATOR | ||
|
|
||
| cmake_minimum_required(VERSION 3.13) | ||
|
|
||
| set(CMAKE_C_STANDARD 11) | ||
| set(CMAKE_CXX_STANDARD 17) | ||
|
|
||
| # initialise pico_sdk from installed location | ||
| # (note this can come from environment, CMake cache etc) | ||
| set(PICO_SDK_PATH "{{ sdk_path }}") | ||
|
|
||
| # pull in Raspberry Pi Pico SDK (must be before project) | ||
| include(pico_sdk_import.cmake) | ||
|
|
||
| project({{ project_name }} C CXX ASM) | ||
|
|
||
| {% if exceptions %} | ||
| set(PICO_CXX_ENABLE_EXCEPTIONS 1) | ||
| {% endif %} | ||
| {% if rtti %} | ||
| set(PICO_CXX_ENABLE_RTTI 1) | ||
| {% endif %} | ||
| {% if configs %} | ||
| # Add any PICO_CONFIG entries specified in the Advanced settings | ||
| {% for c, v in configs.items() %} | ||
| {% set v = v == "True"%} | ||
| add_compile_definitions({{c}}={{ 1 if v else 0}}) | ||
| {% endfor %} | ||
| {% endif %} | ||
| # initialise the Raspberry Pi Pico SDK | ||
| pico_sdk_init() | ||
|
|
||
| # add executable. Default name is the project name | ||
| {% set extension = ".cpp" if want_cpp else ".c" %} | ||
| add_executable({{project_name}} {{project_name}}{{extension}}) | ||
|
|
||
| pico_set_program_name({{ project_name }} "{{ project_name}}") | ||
| pico_set_program_version({{project_name}} "0.1") | ||
|
|
||
| {% if want_run_from_ram %} | ||
| # no_flash means the target is to run from RAM | ||
| pico_set_binary_type({{project_name}} no_flash) | ||
| {% endif %} | ||
| # control the console output destinations | ||
| pico_enable_stdio_uart({{project_name}} {{1 if want_uart else 0}}) | ||
| pico_enable_stdio_usb({{project_name}} {{1 if want_usb else 0}}) | ||
|
|
||
| # pull in common dependencies {% if features | length %}and additional hardware support{% endif %} | ||
| target_link_libraries({{project_name}} | ||
| pico_stdlib | ||
| {% for lib in features %} | ||
| {{ features_list[loop.index] }} | ||
| {% endfor %}) | ||
|
|
||
| pico_add_extra_outputs({{project_name}}) |
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,145 @@ | ||
| {% macro uart_define() %} | ||
| // UART defines | ||
| // By default the stdout UART is `uart0`, so we will use the second one | ||
| #define UART_ID uart1 | ||
| #define BAUD_RATE 9600 | ||
| // Use pins 4 and 5 for UART1 | ||
| // Pins can be changed, see the GPIO function select table in the datasheet for information on GPIO assignments | ||
| #define UART_TX_PIN 4 | ||
| #define UART_RX_PIN 5 | ||
| {% endmacro %} | ||
|
|
||
| {% macro uart_initialiser() %} | ||
| // Set up our UART | ||
| uart_init(UART_ID, BAUD_RATE); | ||
| // Set the TX and RX pins by using the function select on the GPIO | ||
| // Set datasheet for more information on function select | ||
| gpio_set_function(UART_TX_PIN, GPIO_FUNC_UART); | ||
| gpio_set_function(UART_RX_PIN, GPIO_FUNC_UART); | ||
| {% endmacro %} | ||
|
|
||
| {% macro spi_define() %} | ||
| // SPI Defines | ||
| // We are going to use SPI 0, and allocate it to the following GPIO pins, | ||
| // Pins can be changed, see the GPIO function select table in the datasheet for information on GPIO assignments, | ||
| #define SPI_PORT spi0 | ||
| #define PIN_MISO 16 | ||
| #define PIN_CS 17 | ||
| #define PIN_SCK 18 | ||
| #define PIN_MOSI 19 | ||
| {% endmacro %} | ||
|
|
||
| {% macro spi_initialiser() %} | ||
| // SPI initialisation. This example will use SPI at 1MHz. | ||
| spi_init(SPI_PORT, 1000*1000); | ||
| gpio_set_function(PIN_MISO, GPIO_FUNC_SPI); | ||
| gpio_set_function(PIN_CS, GPIO_FUNC_SIO); | ||
| gpio_set_function(PIN_SCK, GPIO_FUNC_SPI); | ||
| gpio_set_function(PIN_MOSI, GPIO_FUNC_SPI); | ||
| // Chip select is active-low, so we'll initialise it to a driven-high state | ||
| gpio_set_dir(PIN_CS, GPIO_OUT); | ||
| gpio_put(PIN_CS, 1); | ||
| {% endmacro %} | ||
|
|
||
| {% macro i2c_define() %} | ||
| // I2C defines | ||
| // This example will use I2C0 on GPIO8 (SDA) and GPIO9 (SCL) running at 400KHz. | ||
| // Pins can be changed, see the GPIO function select table in the datasheet for information on GPIO assignments | ||
| #define I2C_PORT i2c0 | ||
| #define I2C_SDA 8 | ||
| #define I2C_SCL 9 | ||
| {% endmacro %} | ||
|
|
||
| {% macro i2c_initialiser() %} | ||
| // I2C Initialisation. Using it at 400Khz. | ||
| i2c_init(I2C_PORT, 400*1000); | ||
| gpio_set_function(I2C_SDA, GPIO_FUNC_I2C); | ||
| gpio_set_function(I2C_SCL, GPIO_FUNC_I2C); | ||
| gpio_pull_up(I2C_SDA); | ||
| gpio_pull_up(I2C_SCL); | ||
| {% endmacro %} | ||
|
|
||
| {% macro gpio_define() %} | ||
| // GPIO defines | ||
| // Example uses GPIO 2 | ||
| #define GPIO 2 | ||
| {% endmacro %} | ||
|
|
||
| {% macro gpio_initialiser() %} | ||
| // GPIO initialisation. | ||
| // We will make this GPIO an input, and pull it up by default | ||
| gpio_init(GPIO); | ||
| gpio_set_dir(GPIO, GPIO_IN); | ||
| gpio_pull_up(GPIO); | ||
| {% endmacro %} | ||
|
|
||
| {% macro interp_define() %}{% endmacro %} | ||
|
|
||
| {% macro interp_initialiser() %} | ||
| // Interpolator example code | ||
| interp_config cfg = interp_default_config(); | ||
| // Now use the various interpolator library functions for your use case | ||
| // e.g. interp_config_clamp(&cfg, true); | ||
| // interp_config_shift(&cfg, 2); | ||
| // Then set the config | ||
| interp_set_config(interp0, 0, &cfg); | ||
| {% endmacro %} | ||
|
|
||
| {% macro timer_define() %} | ||
| int64_t alarm_callback(alarm_id_t id, void *user_data) { | ||
| // Put your timeout handler code in here | ||
| return 0; | ||
| } | ||
| {% endmacro %} | ||
|
|
||
| {% macro timer_initialiser() %} | ||
| // Timer example code - This example fires off the callback after 2000ms | ||
| add_alarm_in_ms(2000, alarm_callback, NULL, false); | ||
| {% endmacro %} | ||
|
|
||
| {% macro watchdog_define() %} | ||
| {% endmacro %} | ||
|
|
||
| {% macro watchdog_initialiser() %} | ||
| // Watchdog example code | ||
| if (watchdog_caused_reboot()) { | ||
| // Whatever action you may take if a watchdog caused a reboot | ||
| } | ||
| // Enable the watchdog, requiring the watchdog to be updated every 100ms or the chip will reboot | ||
| // second arg is pause on debug which means the watchdog will pause when stepping through code | ||
| watchdog_enable(100, 1); | ||
| // You need to call this function at least more often than the 100ms in the enable call to prevent a reboot | ||
| watchdog_update(); | ||
| {% endmacro %} | ||
|
|
||
| {% macro div_define() %} | ||
| {% endmacro %} | ||
|
|
||
| {% macro div_initialiser() %} | ||
| // Example of using the HW divider. The pico_divider library provides a more user friendly set of APIs | ||
| // over the divider (and support for 64 bit divides), and of course by default regular C language integer | ||
| // divisions are redirected thru that library, meaning you can just use C level `/` and `%` operators and | ||
| // gain the benefits of the fast hardware divider. | ||
| int32_t dividend = 123456; | ||
| int32_t divisor = -321; | ||
| // This is the recommended signed fast divider for general use. | ||
| divmod_result_t result = hw_divider_divmod_s32(dividend, divisor); | ||
| printf(\%d/%d = %d remainder %d\\n\, dividend, divisor, to_quotient_s32(result), to_remainder_s32(result)); | ||
| // This is the recommended unsigned fast divider for general use. | ||
| int32_t udividend = 123456; | ||
| int32_t udivisor = 321; | ||
| divmod_result_t uresult = hw_divider_divmod_u32(udividend, udivisor); | ||
| printf(\%d/%d = %d remainder %d\\n\, udividend, udivisor, to_quotient_u32(uresult), to_remainder_u32(uresult)); | ||
| {% endmacro %} | ||
|
|
||
| {% macro dma_define() %}{% endmacro %} | ||
|
|
||
| {% macro dma_initialiser() %}{% endmacro %} | ||
|
|
||
| {% macro pio_define() %}{% endmacro %} | ||
|
|
||
| {% macro pio_initialiser() %}{% endmacro %} | ||
|
|
||
| {% macro clocks_define() %}{% endmacro %} | ||
|
|
||
| {% macro clocks_initialiser() %}{% endmacro %} | ||
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,24 @@ | ||
| {% import "fragments.txt" as fragments %} | ||
| #include <stdio.h> | ||
| #include "pico/stdlib.h" | ||
| {% for include in includes %} | ||
| #include "{{include}}" | ||
| {% endfor %} | ||
|
|
||
| {% for lib in libraries %} | ||
| {% set def = lib | find_define %} | ||
| {% if def | length %} | ||
| {{ def }} | ||
| {% endif %} | ||
| {% endfor %} | ||
| int main() { | ||
| stdio_init_all(); | ||
| {% for lib in libraries %} | ||
| {% set ini = lib | find_initialiser %} | ||
| {% if ini | length %} | ||
| {{ ini | indent }} | ||
| {% endif %} | ||
| {% endfor %} | ||
| puts("Hello, world!"); | ||
| return 0; | ||
| } |
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,18 @@ | ||
| { | ||
| "configurations": [ | ||
| { | ||
| "name": "Linux", | ||
| "includePath": [ | ||
| "${workspaceFolder}/**", | ||
| "${env:PICO_SDK_PATH}/**" | ||
| ], | ||
| "defines": [], | ||
| "compilerPath": "/usr/bin/arm-none-eabi-gcc", | ||
| "cStandard": "gnu17", | ||
| "cppStandard": "gnu++14", | ||
| "intelliSenseMode": "linux-gcc-arm", | ||
| "configurationProvider" : "ms-vscode.cmake-tools" | ||
| } | ||
| ], | ||
| "version": 4 | ||
| } |
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 @@ | ||
| { | ||
| "recommendations": [ | ||
| "marus25.cortex-debug", | ||
| "ms-vscode.cmake-tools", | ||
| "ms-vscode.cpptools" | ||
| ] | ||
| } |
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,29 @@ | ||
| { | ||
| // Use IntelliSense to learn about possible attributes. | ||
| // Hover to view descriptions of existing attributes. | ||
| // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
| "version": "0.2.0", | ||
| "configurations": [ | ||
| { | ||
| "name": "Cortex Debug", | ||
| "cwd": "${workspaceRoot}", | ||
| "executable": "${command:cmake.launchTargetPath}", | ||
| "request": "launch", | ||
| "type": "cortex-debug", | ||
| "servertype": "openocd", | ||
| "gdbPath": "gdb-multiarch", | ||
| "device": "RP2040", | ||
| "configFiles": [ | ||
| "interface/{{deb}}", | ||
| "target/rp2040.cfg" | ||
| ], | ||
| "svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd", | ||
| "runToMain": true, | ||
| // Give restart the same functionality as runToMain | ||
| "postRestartCommands": [ | ||
| "break main", | ||
| "continue" | ||
| ] | ||
| } | ||
| ] | ||
| } |
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,17 @@ | ||
| { | ||
| "cmake.configureOnOpen": false, | ||
| "cmake.statusbar.advanced": { | ||
| "debug" : { | ||
| "visibility": "hidden" | ||
| }, | ||
| "launch" : { | ||
| "visibility": "hidden" | ||
| }, | ||
| "build" : { | ||
| "visibility": "hidden" | ||
| }, | ||
| "buildTarget" : { | ||
| "visibility": "hidden" | ||
| }, | ||
| }, | ||
| } |
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.
@kilograham I think this project-generator was created before we added the "board headers" to the Raspberry Pi Pico SDK. Should we now update the pin-numbers used here (for the various interfaces) to match up with https://github.com/raspberrypi/pico-sdk/blob/master/src/boards/include/boards/pico.h ?
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.
Needs to be a separate issue.