aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-06-05 12:51:24 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-06-05 12:51:24 +0200
commita8b794c02574e96150d55852fa5db1ce7529503d (patch)
treecac16715745c58aa18b3c8fac8f058517ef234a9
parenta96ffb4d0fd8576d753bb975b674b2aeef617d5f (diff)
add arduino cmake toolchain + improve lazy.mk
-rw-r--r--.gitmodules6
-rw-r--r--i2ctcp/i2ctcpv1.c4
-rw-r--r--lazy.mk16
m---------lib/Arduino-CMake-Toolchain0
-rw-r--r--puzzle/dummy/CMakeLists.txt33
l---------puzzle/dummy/lib1
-rw-r--r--puzzle/dummy/main.cpp23
-rw-r--r--puzzle/dummy/makefile7
8 files changed, 86 insertions, 4 deletions
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 <mpack.h>
-#include <sys/param.h> // 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
+Subproject e745a9bed3c3fb83442d55bf05630f31574674f
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 <Arduino.h>
+#include <Wire.h>
+
+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;
+