From 6707c4d19f7006f815032a8ab76ece4c5ab79f25 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Mon, 30 May 2022 14:10:48 +0200 Subject: [PATCH] Starting work on C++ --- .gitignore | 1 + .vscode/.cortex-debug.peripherals.state.json | 1 + .vscode/.cortex-debug.registers.state.json | 1 + .vscode/c_cpp_properties.json | 18 +++++ .vscode/extensions.json | 7 ++ .vscode/launch.json | 31 +++++++++ .vscode/settings.json | 19 +++++ CMakeLists.txt | 39 +++++++++++ README.md | 4 +- gbmanager.cpp | 14 ++++ {lib => micropython/lib}/lcd_api.py | 0 {lib => micropython/lib}/pico_i2c_lcd.py | 0 main.py => micropython/main.py | 0 pico_sdk_import.cmake | 73 ++++++++++++++++++++ 14 files changed, 206 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 .vscode/.cortex-debug.peripherals.state.json create mode 100644 .vscode/.cortex-debug.registers.state.json create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/extensions.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 CMakeLists.txt create mode 100644 gbmanager.cpp rename {lib => micropython/lib}/lcd_api.py (100%) rename {lib => micropython/lib}/pico_i2c_lcd.py (100%) rename main.py => micropython/main.py (100%) create mode 100644 pico_sdk_import.cmake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/.vscode/.cortex-debug.peripherals.state.json b/.vscode/.cortex-debug.peripherals.state.json new file mode 100644 index 0000000..0637a08 --- /dev/null +++ b/.vscode/.cortex-debug.peripherals.state.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/.vscode/.cortex-debug.registers.state.json b/.vscode/.cortex-debug.registers.state.json new file mode 100644 index 0000000..0637a08 --- /dev/null +++ b/.vscode/.cortex-debug.registers.state.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..e385a5e --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -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 +} diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..5acb283 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + "recommendations": [ + "marus25.cortex-debug", + "ms-vscode.cmake-tools", + "ms-vscode.cpptools" + ] +} diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..10509c1 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,31 @@ +{ + // 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" : "arm-none-eabi-gdb", + "device": "RP2040", + //"showDevDebugOutput": "parsed", + "configFiles": [ + "interface/picoprobe.cfg", + "target/rp2040.cfg" + ], + "svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd", + "runToEntryPoint": "main", + // Give restart the same functionality as runToMain + //"postRestartCommands": [ + // "break main", + // "continue" + //], + "searchDir": ["/home/brodbemn/src/openocd/tcl"], + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..d35102d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,19 @@ +{ + "cmake.configureOnOpen": false, + "cmake.buildBeforeRun": true, + "cmake.statusbar.advanced": { + "debug" : { + "visibility": "hidden" + }, "launch" : { + "visibility": "hidden" + }, + "build" : { + "visibility": "hidden" + }, + "buildTarget" : { + "visibility": "hidden" + }, + }, + "cortex-debug.openocdPath": "/home/brodbemn/src/openocd/src/openocd", + "cmake.generator": "Unix Makefiles", +} diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a2523f1 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,39 @@ +# Generated Cmake Pico project file + +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 "/usr/share/pico-sdk") + +# Pull in Raspberry Pi Pico SDK (must be before project) +include(pico_sdk_import.cmake) + +project(gbmanager C CXX ASM) + +# Initialise the Raspberry Pi Pico SDK +pico_sdk_init() + +# Add executable. Default name is the project name, version 0.1 + +add_executable(gbmanager gbmanager.cpp ) + +pico_set_program_name(gbmanager "gbmanager") +pico_set_program_version(gbmanager "0.1") + +pico_enable_stdio_uart(gbmanager 1) +pico_enable_stdio_usb(gbmanager 0) + +# Add the standard library to the build +target_link_libraries(gbmanager pico_stdlib) + +# Add any user requested libraries +#target_link_libraries(gbmanager +# hardware_i2c +#) + +pico_add_extra_outputs(gbmanager) + diff --git a/README.md b/README.md index be0e420..403be28 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Die Software ist derzeit noch rudimentär gehalten. Die Temperatur wird perodisc Für die Ansteuerung des LCD wird `rpi-pico-i2c-lcd` von _T-622_ ([Github](https://github.com/t-622/rpi-pico-i2c-lcd)) verwendet, das wiederum auf `python_lcd` von _dhylands_ ([Github](https://github.com/dhylands/python_lcd)) basiert. Letzteres steht unter der MIT-Lizenz. `rpi-pico-i2c-lcd` ist ohne Lizenzangabe. Die entspechenden Dateien liegen der Einfachheit halber im `lib` Unterverzeichnis. ### Installation -Am einfachsten ist es, mittels [Thonny](https://thonny.org/) die Datei `main.py` sowie den `lib`-Ordner ins Hauptverzichnis des Picos zu kopieren. Auf dem Pico muss natürlich MicroPython installiert sein. Fertig. +Am einfachsten ist es, mittels [Thonny](https://thonny.org/) den Inhalt des Unterverzeichnisses _micropython_ (also main.py sowie den libs-Ordner) ins Hauptverzichnis des Picos zu kopieren. Auf dem Pico muss natürlich MicroPython installiert sein. Fertig. # Aufbau Die zum Aufbau notwendigen Informationen bzw. Dateien befinden sich in diesem Repository. @@ -41,4 +41,4 @@ Im Verzeichnis _FreeCAD_ befindet sich das entsprechende CAD-Projekt sowie die d Das Gerät wird über ein microUSB-Kabel mit einem 5V Netzteil, wie man es zum Aufladen von Smartphones verwendet, verbunden. Der Raspberry Pi Pico benötigt sehr wenig Strom, es genügt daher ein "schwaches" Netzteil. Der Euro-Stromstecker kommt an die Steckdose. Damit ist (über ein Relais) das andere Stromkabel, das mit einer Euro-Buchse versehen ist, verbunden. An diese Buchse wiederum kommt die Heizmatte. Das letzte Kabel – in meinem Fall das hellgraue – ist der Temperaturfühler. Dieses muss über eine Bohrung o. ä. in die Gärbox eingeführt werden, so dass eine Temperaturerfassung des Innenraums möglich ist. -Mit den blauen Tasten stellt man die gewünschte Temperatur ein. Rot schaltet die Heizungssteuerung ein/aus. Ein ">H<" zeigt an, ob gerade geheizt wird. \ No newline at end of file +Mit den blauen Tasten stellt man die gewünschte Temperatur ein. Rot schaltet die Heizungssteuerung ein/aus. Ein ">H<" zeigt an, ob gerade geheizt wird. diff --git a/gbmanager.cpp b/gbmanager.cpp new file mode 100644 index 0000000..87a43a7 --- /dev/null +++ b/gbmanager.cpp @@ -0,0 +1,14 @@ +#include + +#include "pico/stdlib.h" + +int main() +{ + stdio_init_all(); + + while (true) { + std::cout << "Hello, world!" << std::endl; + //TODO: Read temperature + sleep_ms(750); + } +} \ No newline at end of file diff --git a/lib/lcd_api.py b/micropython/lib/lcd_api.py similarity index 100% rename from lib/lcd_api.py rename to micropython/lib/lcd_api.py diff --git a/lib/pico_i2c_lcd.py b/micropython/lib/pico_i2c_lcd.py similarity index 100% rename from lib/pico_i2c_lcd.py rename to micropython/lib/pico_i2c_lcd.py diff --git a/main.py b/micropython/main.py similarity index 100% rename from main.py rename to micropython/main.py diff --git a/pico_sdk_import.cmake b/pico_sdk_import.cmake new file mode 100644 index 0000000..65f8a6f --- /dev/null +++ b/pico_sdk_import.cmake @@ -0,0 +1,73 @@ +# This is a copy of /external/pico_sdk_import.cmake + +# This can be dropped into an external project to help locate this SDK +# It should be include()ed prior to project() + +if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH)) + set(PICO_SDK_PATH $ENV{PICO_SDK_PATH}) + message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')") +endif () + +if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT)) + set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT}) + message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')") +endif () + +if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH)) + set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH}) + message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')") +endif () + +set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK") +set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable") +set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK") + +if (NOT PICO_SDK_PATH) + if (PICO_SDK_FETCH_FROM_GIT) + include(FetchContent) + set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR}) + if (PICO_SDK_FETCH_FROM_GIT_PATH) + get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") + endif () + # GIT_SUBMODULES_RECURSE was added in 3.17 + if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0") + FetchContent_Declare( + pico_sdk + GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk + GIT_TAG master + GIT_SUBMODULES_RECURSE FALSE + ) + else () + FetchContent_Declare( + pico_sdk + GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk + GIT_TAG master + ) + endif () + + if (NOT pico_sdk) + message("Downloading Raspberry Pi Pico SDK") + FetchContent_Populate(pico_sdk) + set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR}) + endif () + set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE}) + else () + message(FATAL_ERROR + "SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git." + ) + endif () +endif () + +get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") +if (NOT EXISTS ${PICO_SDK_PATH}) + message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found") +endif () + +set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake) +if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE}) + message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK") +endif () + +set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE) + +include(${PICO_SDK_INIT_CMAKE_FILE})