From a8b794c02574e96150d55852fa5db1ce7529503d Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Wed, 5 Jun 2024 12:51:24 +0200 Subject: add arduino cmake toolchain + improve lazy.mk --- .gitmodules | 6 ++++++ i2ctcp/i2ctcpv1.c | 4 +++- lazy.mk | 16 +++++++++++++--- lib/Arduino-CMake-Toolchain | 1 + puzzle/dummy/CMakeLists.txt | 33 +++++++++++++++++++++++++++++++++ puzzle/dummy/lib | 1 + puzzle/dummy/main.cpp | 23 +++++++++++++++++++++++ puzzle/dummy/makefile | 7 +++++++ 8 files changed, 87 insertions(+), 4 deletions(-) create mode 160000 lib/Arduino-CMake-Toolchain create mode 100644 puzzle/dummy/CMakeLists.txt create mode 120000 puzzle/dummy/lib create mode 100644 puzzle/dummy/main.cpp create mode 100644 puzzle/dummy/makefile diff --git a/.gitmodules b/.gitmodules index 1a813e0..6313925 100644 --- a/.gitmodules +++ b/.gitmodules @@ -18,3 +18,9 @@ url = https://github.com/ludocode/mpack branch = v1.1.1 shallow = true +[submodule "lib/Arduino-CMake-Toolchain"] + path = lib/Arduino-CMake-Toolchain + url = https://github.com/a9183756-gh/Arduino-CMake-Toolchain + branch = e745a9bed3c3fb83442d55bf05630f31574674f2 + shallow = true + diff --git a/i2ctcp/i2ctcpv1.c b/i2ctcp/i2ctcpv1.c index 1ae1da0..944df3a 100644 --- a/i2ctcp/i2ctcpv1.c +++ b/i2ctcp/i2ctcpv1.c @@ -1,5 +1,7 @@ #include -#include // MIN() macro +#ifndef MIN +#define MIN(a,b) (((a) < (b)) ? (a) : (b)) +#endif #include "i2ctcpv1.h" diff --git a/lazy.mk b/lazy.mk index 2620961..3b9813a 100644 --- a/lazy.mk +++ b/lazy.mk @@ -3,18 +3,28 @@ BUILD_DIR ?= build TARGET ?= $(BUILD_DIR)/main +CMFLAGS += --fresh +CMFLAGS += --log-level WARNING +CMFLAGS += -Wno-deprecated + .PHONY: FORCE all: FORCE $(TARGET) $(BUILD_DIR)/build.ninja: CMakeLists.txt - mkdir -p $(BUILD_DIR) - cmake -B $(BUILD_DIR) -G Ninja --fresh --log-level WARNING + @mkdir -p $(BUILD_DIR) + @cmake -B $(BUILD_DIR) -G Ninja $(CMFLAGS) $(TARGET): $(BUILD_DIR)/build.ninja FORCE - ninja -C $(BUILD_DIR) + @ninja -C $(BUILD_DIR) # ninja automatically builds in parallel, so is preferred clean: FORCE $(RM) -r $(BUILD_DIR) +# forward other targets to cmake +ifneq ($(MAKECMDGOALS),) +%:: + @ninja -C $(BUILD_DIR) $@ +endif + diff --git a/lib/Arduino-CMake-Toolchain b/lib/Arduino-CMake-Toolchain new file mode 160000 index 0000000..e745a9b --- /dev/null +++ b/lib/Arduino-CMake-Toolchain @@ -0,0 +1 @@ +Subproject commit e745a9bed3c3fb83442d55bf05630f31574674f2 diff --git a/puzzle/dummy/CMakeLists.txt b/puzzle/dummy/CMakeLists.txt new file mode 100644 index 0000000..026864b --- /dev/null +++ b/puzzle/dummy/CMakeLists.txt @@ -0,0 +1,33 @@ +cmake_minimum_required(VERSION 3.29) + +set(CMAKE_C_STANDARD 11) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_EXPORT_COMPILE_COMMANDS 1) + +# enable debug features +set(CMAKE_BUILD_TYPE Debug) +add_compile_definitions(DEBUG) + +# arduino +set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/lib/Arduino-CMake-Toolchain/Arduino-toolchain.cmake) +set(ARDUINO_BOARD "Arduino Uno [avr.uno]") + +project(pb_mod_dummy C CXX) + +include(../../shared/include.cmake) + +add_executable(main + main.cpp + ) + +# target_link_libraries(main +# puzbus +# # pbdrv-mod-arduino +# ) +target_link_arduino_libraries(main + core + Wire + ) + +target_enable_arduino_upload(main) + diff --git a/puzzle/dummy/lib b/puzzle/dummy/lib new file mode 120000 index 0000000..58677dd --- /dev/null +++ b/puzzle/dummy/lib @@ -0,0 +1 @@ +../../lib \ No newline at end of file diff --git a/puzzle/dummy/main.cpp b/puzzle/dummy/main.cpp new file mode 100644 index 0000000..4374066 --- /dev/null +++ b/puzzle/dummy/main.cpp @@ -0,0 +1,23 @@ +#include +#include + +void receiveEvent(int howMany){ + while (Wire.available()){ + char c = Wire.read(); + Serial.print(c, HEX); + } + Serial.println(); +} + +void setup() { + Wire.begin(0x00); + Wire.onReceive(receiveEvent); +} + +void loop() { + const uint8_t data[] = {0xff, 0x00, 0xde, 0xad, 0xbe, 0xef}; + Wire.beginTransmission(0x69); + Wire.write(data, sizeof(data)); + Wire.endTransmission(); +} + diff --git a/puzzle/dummy/makefile b/puzzle/dummy/makefile new file mode 100644 index 0000000..a971dfb --- /dev/null +++ b/puzzle/dummy/makefile @@ -0,0 +1,7 @@ +TARGET = $(BUILD_DIR)/main.elf + +include ../../lazy.mk + +export SERIAL_PORT = /dev/ttyACM0 +flash: upload-main; + -- cgit v1.2.3