aboutsummaryrefslogtreecommitdiff
path: root/puzzle
diff options
context:
space:
mode:
Diffstat (limited to 'puzzle')
-rw-r--r--puzzle/neo/CMakeLists.txt44
-rw-r--r--puzzle/neo/FreeRTOSConfig.h52
-rw-r--r--puzzle/neo/console-neopuzzle/neo.cpp100
-rw-r--r--puzzle/neo/index.dox8
l---------puzzle/neo/lib1
-rw-r--r--puzzle/neo/main.cpp (renamed from puzzle/neo/arduino-neopuzzle/arduino-neopuzzle.ino)79
-rw-r--r--puzzle/neo/makefile8
-rw-r--r--puzzle/neo/mod.c6
-rw-r--r--puzzle/readme.md15
-rw-r--r--puzzle/vault/CMakeLists.txt12
-rw-r--r--puzzle/vault/index.dox5
-rw-r--r--puzzle/vault/makefile12
-rw-r--r--puzzle/vault/mod.c4
13 files changed, 176 insertions, 170 deletions
diff --git a/puzzle/neo/CMakeLists.txt b/puzzle/neo/CMakeLists.txt
new file mode 100644
index 0000000..6c45f13
--- /dev/null
+++ b/puzzle/neo/CMakeLists.txt
@@ -0,0 +1,44 @@
+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 Mega or Mega 2560 [avr.mega]")
+
+# freertos
+add_library(freertos_config INTERFACE)
+target_include_directories(freertos_config SYSTEM INTERFACE .)
+set(FREERTOS_PORT GCC_ATMEGA)
+set(FREERTOS_HEAP 4)
+
+project(pb_mod_neo C CXX)
+
+add_subdirectory(lib/pbdrv)
+add_subdirectory(lib/FreeRTOS-Kernel)
+
+add_executable(main
+ main.cpp
+ mod.c
+ )
+
+target_link_libraries(main PUBLIC
+ pbdrv-mod
+ )
+target_link_arduino_libraries(main PUBLIC
+ core
+ Wire
+ Adafruit_seesaw
+ )
+
+# fugly workaround
+target_link_arduino_libraries(_arduino_lib_Adafruit_seesaw_Library PUBLIC "Adafruit BusIO")
+
+target_enable_arduino_upload(main)
+
diff --git a/puzzle/neo/FreeRTOSConfig.h b/puzzle/neo/FreeRTOSConfig.h
new file mode 100644
index 0000000..c0acc49
--- /dev/null
+++ b/puzzle/neo/FreeRTOSConfig.h
@@ -0,0 +1,52 @@
+#pragma once
+
+#define configUSE_PREEMPTION 1
+#define configUSE_IDLE_HOOK 0
+#define configUSE_TICK_HOOK 0
+#define configMAX_PRIORITIES 32
+#define configMINIMAL_STACK_SIZE ((configSTACK_DEPTH_TYPE) 192)
+#define configUSE_16_BIT_TICKS 1
+#define configIDLE_SHOULD_YIELD 1
+#define configUSE_MUTEXES 1
+#define configUSE_RECURSIVE_MUTEXES 1
+#define configUSE_APPLICATION_TASK_TAG 0
+#define configUSE_COUNTING_SEMAPHORES 1
+#define configQUEUE_REGISTRY_SIZE 8
+#define configUSE_QUEUE_SETS 0
+#define configUSE_TIME_SLICING 1
+#define configSTACK_DEPTH_TYPE uint16_t
+#define configSUPPORT_STATIC_ALLOCATION 0
+#define configSUPPORT_DYNAMIC_ALLOCATION 1
+// #define configTOTAL_HEAP_SIZE (1024)
+#define configTOTAL_HEAP_SIZE (5 * 1024)
+#define configCHECK_FOR_STACK_OVERFLOW 0
+#define configUSE_MALLOC_FAILED_HOOK 0
+#define configUSE_DAEMON_TASK_STARTUP_HOOK 0
+#define configGENERATE_RUN_TIME_STATS 0
+#define configUSE_TRACE_FACILITY 0
+#define configUSE_STATS_FORMATTING_FUNCTIONS 0
+#define configUSE_TIMERS 1
+#define configTIMER_TASK_PRIORITY (configMAX_PRIORITIES - 1)
+#define configTIMER_QUEUE_LENGTH 10
+#define configTIMER_TASK_STACK_DEPTH 92
+
+#include <assert.h>
+#define configASSERT(x) assert(x)
+
+#define INCLUDE_vTaskPrioritySet 1
+#define INCLUDE_uxTaskPriorityGet 1
+#define INCLUDE_vTaskDelete 1
+#define INCLUDE_vTaskSuspend 1
+#define INCLUDE_vTaskDelayUntil 1
+#define INCLUDE_vTaskDelay 1
+#define INCLUDE_xTaskGetSchedulerState 1
+#define INCLUDE_xTaskGetCurrentTaskHandle 1
+#define INCLUDE_uxTaskGetStackHighWaterMark 1
+#define INCLUDE_xTaskGetIdleTaskHandle 1
+#define INCLUDE_eTaskGetState 1
+#define INCLUDE_xTimerPendFunctionCall 1
+#define INCLUDE_xTaskAbortDelay 1
+#define INCLUDE_xTaskGetHandle 1
+#define INCLUDE_xTaskResumeFromISR 1
+#define INCLUDE_xQueueGetMutexHolder 1
+
diff --git a/puzzle/neo/console-neopuzzle/neo.cpp b/puzzle/neo/console-neopuzzle/neo.cpp
deleted file mode 100644
index 56d90f7..0000000
--- a/puzzle/neo/console-neopuzzle/neo.cpp
+++ /dev/null
@@ -1,100 +0,0 @@
-#include <iostream>
-#include <array>
-
-#define MATRIX_SIZE 8
-
-enum NeoState {
- NEO_UNINITIALIZED,
- NEO_PLAYING,
- NEO_SOLVED
-};
-
-// Simulate the 8x8 LED matrix with a 2D array
-std::array<std::array<bool, MATRIX_SIZE>, MATRIX_SIZE> neoMatrix;
-
-NeoState neoState = NEO_UNINITIALIZED;
-
-// Helper function to toggle LEDs if within bounds
-void toggleIfValid(int x, int y) {
- if (x >= 0 && x < MATRIX_SIZE && y >= 0 && y < MATRIX_SIZE) {
- neoMatrix[x][y] = !neoMatrix[x][y];
- }
-}
-
-void initializeNeoMatrix() {
- // The initial pattern from the Appendix A example (assuming red is 'true'/on and white is 'false'/off)
- std::array<std::array<bool, MATRIX_SIZE>, MATRIX_SIZE> initialPattern = {{
- {false, true, false, true, false, true, false, true},
- {true, false, true, false, true, false, true, false},
- {false, true, false, true, false, true, false, true},
- {true, false, true, false, true, false, true, false},
- {false, true, false, true, false, true, false, true},
- {true, false, true, false, true, false, true, false},
- {false, true, false, true, false, true, false, true},
- {true, false, true, false, true, false, true, false}
- }};
-
- for (int i = 0; i < MATRIX_SIZE; i++) {
- for (int j = 0; j < MATRIX_SIZE; j++) {
- neoMatrix[i][j] = initialPattern[i][j];
- }
- }
-
- neoState = NEO_PLAYING;
-}
-
-
-void printNeoMatrix() {
- // Print the matrix state to the console
- for (int i = 0; i < MATRIX_SIZE; i++) {
- for (int j = 0; j < MATRIX_SIZE; j++) {
- std::cout << (neoMatrix[i][j] ? 1 : 0) << " ";
- }
- std::cout << std::endl;
- }
-}
-
-void toggleAdjacentLEDs(int x, int y) {
- // Toggle the LED at (x, y) and adjacent LEDs
- toggleIfValid(x, y); // Center
- toggleIfValid(x - 1, y); // Up
- toggleIfValid(x + 1, y); // Down
- toggleIfValid(x, y - 1); // Left
- toggleIfValid(x, y + 1); // Right
-}
-
-
-bool isNeoPuzzleSolved() {
- for (int i = 0; i < MATRIX_SIZE; i++) {
- for (int j = 0; j < MATRIX_SIZE; j++) {
- if (neoMatrix[i][j]) return false; // If any LED is on, puzzle is not solved
- }
- }
- return true;
-}
-
-/// Integration needed
-int main() {
- initializeNeoMatrix();
- printNeoMatrix();
-
- while (neoState != NEO_SOLVED) {
- int x, y;
- std::cout << "Enter the coordinates of the button pressed (x y): ";
- std::cin >> x >> y;
-
- if (x >= 0 && x < MATRIX_SIZE && y >= 0 && y < MATRIX_SIZE) {
- toggleAdjacentLEDs(x, y);
- printNeoMatrix();
-
- if (isNeoPuzzleSolved()) {
- neoState = NEO_SOLVED;
- std::cout << "The NeoTrellis puzzle is solved!\n";
- }
- } else {
- std::cout << "Invalid coordinates. Please enter values between 0 and " << MATRIX_SIZE - 1 << ".\n";
- }
- }
-
- return 0;
-}
diff --git a/puzzle/neo/index.dox b/puzzle/neo/index.dox
index 14cefdc..87822e0 100644
--- a/puzzle/neo/index.dox
+++ b/puzzle/neo/index.dox
@@ -3,4 +3,12 @@
\ingroup puz
\defgroup puz_neo Neo
\brief NeoTrellis puzzle module
+
+\par Setup
+- Use the Arduino IDE library manager to install the "Adafruit seesaw Library"
+ library and its dependencies
+
+\warning There is another library named "Adafruit NeoTrellis M4 Library", this
+is not the right library.
+
*/
diff --git a/puzzle/neo/lib b/puzzle/neo/lib
new file mode 120000
index 0000000..58677dd
--- /dev/null
+++ b/puzzle/neo/lib
@@ -0,0 +1 @@
+../../lib \ No newline at end of file
diff --git a/puzzle/neo/arduino-neopuzzle/arduino-neopuzzle.ino b/puzzle/neo/main.cpp
index b334677..13a6859 100644
--- a/puzzle/neo/arduino-neopuzzle/arduino-neopuzzle.ino
+++ b/puzzle/neo/main.cpp
@@ -1,3 +1,4 @@
+#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_NeoTrellis.h>
@@ -22,6 +23,45 @@ enum NeoState {
NeoState neoState = NEO_UNINITIALIZED;
+void toggleAdjacentLEDs(int x, int y) {
+ for (int dx = -1; dx <= 1; ++dx) {
+ for (int dy = -1; dy <= 1; ++dy) {
+ if (dx == 0 && dy == 0) continue; // Skip the center button itself
+ int nx = x + dx, ny = y + dy;
+ if (nx >= 0 && nx < MATRIX_SIZE && ny >= 0 && ny < MATRIX_SIZE) {
+ neoMatrix[nx][ny] = !neoMatrix[nx][ny];
+ trellis.setPixelColor(nx * MATRIX_SIZE + ny, neoMatrix[nx][ny] ? LED_COLOR_ON : LED_COLOR_OFF);
+ }
+ }
+ }
+}
+
+
+bool isNeoPuzzleSolved() {
+ for (int i = 0; i < MATRIX_SIZE; i++) {
+ for (int j = 0; j < MATRIX_SIZE; j++) {
+ if (neoMatrix[i][j]) return false; // If any LED is on, puzzle is not solved
+ }
+ }
+ return true;
+}
+
+TrellisCallback buttonCallback(keyEvent evt) {
+ int x = evt.bit.NUM / MATRIX_SIZE;
+ int y = evt.bit.NUM % MATRIX_SIZE;
+
+ if (evt.bit.EDGE == SEESAW_KEYPAD_EDGE_RISING) {
+ toggleAdjacentLEDs(x, y);
+ trellis.show();
+ if (isNeoPuzzleSolved()) {
+ neoState = NEO_SOLVED;
+ Serial.println("The NeoTrellis puzzle is solved!");
+ }
+ }
+ return 0;
+}
+
+
void setup() {
Serial.begin(115200);
while (!Serial); // Wait for Serial to be ready
@@ -55,41 +95,4 @@ void setup() {
void loop() {
trellis.read(); // Process button events
delay(20);
-}
-
-TrellisCallback buttonCallback(keyEvent evt) {
- int x = evt.bit.NUM / MATRIX_SIZE;
- int y = evt.bit.NUM % MATRIX_SIZE;
-
- if (evt.bit.EDGE == SEESAW_KEYPAD_EDGE_RISING) {
- toggleAdjacentLEDs(x, y);
- trellis.show();
- if (isNeoPuzzleSolved()) {
- neoState = NEO_SOLVED;
- Serial.println("The NeoTrellis puzzle is solved!");
- }
- }
- return 0;
-}
-
-void toggleAdjacentLEDs(int x, int y) {
- for (int dx = -1; dx <= 1; ++dx) {
- for (int dy = -1; dy <= 1; ++dy) {
- if (dx == 0 && dy == 0) continue; // Skip the center button itself
- int nx = x + dx, ny = y + dy;
- if (nx >= 0 && nx < MATRIX_SIZE && ny >= 0 && ny < MATRIX_SIZE) {
- neoMatrix[nx][ny] = !neoMatrix[nx][ny];
- trellis.setPixelColor(nx * MATRIX_SIZE + ny, neoMatrix[nx][ny] ? LED_COLOR_ON : LED_COLOR_OFF);
- }
- }
- }
-}
-
-bool isNeoPuzzleSolved() {
- for (int i = 0; i < MATRIX_SIZE; i++) {
- for (int j = 0; j < MATRIX_SIZE; j++) {
- if (neoMatrix[i][j]) return false; // If any LED is on, puzzle is not solved
- }
- }
- return true;
-}
+} \ No newline at end of file
diff --git a/puzzle/neo/makefile b/puzzle/neo/makefile
new file mode 100644
index 0000000..26e9157
--- /dev/null
+++ b/puzzle/neo/makefile
@@ -0,0 +1,8 @@
+TARGET = $(BUILD_DIR)/main.elf
+
+include ../../lazy.mk
+
+export SERIAL_PORT ?= /dev/ttyACM0
+flash: upload-main;
+upload-main: $(TARGET)
+
diff --git a/puzzle/neo/mod.c b/puzzle/neo/mod.c
new file mode 100644
index 0000000..7157d22
--- /dev/null
+++ b/puzzle/neo/mod.c
@@ -0,0 +1,6 @@
+#include "pb.h"
+#include "pb-mod.h"
+
+const char * PB_MOD_NAME = "neotrellis";
+const i2c_addr_t PB_MOD_ADDR = PB_ADDR_MOD_NEOTRELLIS;
+
diff --git a/puzzle/readme.md b/puzzle/readme.md
index 959c506..1b572ba 100644
--- a/puzzle/readme.md
+++ b/puzzle/readme.md
@@ -1,20 +1,15 @@
\defgroup puz puzzle
\brief Puzzle modules
-# puzzles
-
-This folder contains the source code for all puzzle modules.
-
## Arduino-based puzzle modules
> [!NOTE]
> Because of the poorly designed hardware (21-22) used during development
> (23-24), all puzzle modules ended up being developed using Arduino boards.
-All libraries in this repository use CMake for building (for consistency),
-which also means the Arduino based puzzle modules use CMake. The CMakeLists.txt
-of some puzzles uses the [Arduino-CMake-Toolchain][arduino-cmake]. To build any
-of these subfolders, make sure you have done the following:
+The Arduino based puzzle modules also use CMake with the
+[Arduino-CMake-Toolchain][arduino-cmake]. To build any of these puzzles, make
+sure you have done the following:
- Install the official Arduino IDE
- Open "Tools" > "Board" > "Board manager"
@@ -22,6 +17,8 @@ of these subfolders, make sure you have done the following:
[arduino-cmake]: https://github.com/a9183756-gh/Arduino-CMake-Toolchain
+<!--
+
## ESP-based puzzle modules
### ESP-IDF SDK Setup instructions
@@ -34,3 +31,5 @@ of these subfolders, make sure you have done the following:
- [For windows](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/get-started/windows-setup.html#get-started-windows-first-steps)
- [For Linux](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/get-started/linux-macos-setup.html#get-started-linux-macos-first-steps)
+-->
+
diff --git a/puzzle/vault/CMakeLists.txt b/puzzle/vault/CMakeLists.txt
index b0f05f2..bc13c8c 100644
--- a/puzzle/vault/CMakeLists.txt
+++ b/puzzle/vault/CMakeLists.txt
@@ -7,26 +7,18 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
# enable debug features
set(CMAKE_BUILD_TYPE Debug)
add_compile_definitions(DEBUG)
-# add_compile_options(-O0) # no optimizations
# arduino
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/lib/Arduino-CMake-Toolchain/Arduino-toolchain.cmake)
-# set(ARDUINO_BOARD "Arduino Uno [avr.uno]")
set(ARDUINO_BOARD "Arduino Mega or Mega 2560 [avr.mega]")
# freertos
add_library(freertos_config INTERFACE)
target_include_directories(freertos_config SYSTEM INTERFACE .)
-# set(FREERTOS_PORT GCC_ATMEGA) # Arduino Uno
-set(FREERTOS_PORT GCC_ATMEGA) # Arduino Uno
+set(FREERTOS_PORT GCC_ATMEGA)
set(FREERTOS_HEAP 4)
-# used for testing
-# set(ARDUINO_BOARD "Raspberry Pi Pico W [rp2040.rpipicow]")
-# add_compile_definitions(USE_TINYUSB)
-# include_directories(/home/loek/.arduino15/packages/rp2040/hardware/rp2040/3.9.2/libraries/Adafruit_TinyUSB_Arduino/src/arduino)
-
-project(pb_mod_dummy C CXX)
+project(pb_mod_vault C CXX)
add_subdirectory(lib/pbdrv)
add_subdirectory(lib/FreeRTOS-Kernel)
diff --git a/puzzle/vault/index.dox b/puzzle/vault/index.dox
index b14e616..15eae1f 100644
--- a/puzzle/vault/index.dox
+++ b/puzzle/vault/index.dox
@@ -3,4 +3,9 @@
\ingroup puz
\defgroup puz_vault Vault
\brief Vault puzzle module
+
+\par Setup
+- Use the Arduino IDE library manager to install the "TM1637" library (by
+ Avishay Orpaz) and its dependencies
+
*/
diff --git a/puzzle/vault/makefile b/puzzle/vault/makefile
index 509d8e3..26e9157 100644
--- a/puzzle/vault/makefile
+++ b/puzzle/vault/makefile
@@ -6,15 +6,3 @@ export SERIAL_PORT ?= /dev/ttyACM0
flash: upload-main;
upload-main: $(TARGET)
-test: test_a test_b;
-
-test_a:
- $(MAKE) -C . clean
- $(MAKE) -E CMFLAGS+=-D\ CMAKE_CXX_FLAGS=-DTEST_A -C .
- $(MAKE) -E SERIAL_PORT=/dev/ttyACM0 -C . flash
-
-test_b:
- $(MAKE) -C . clean
- $(MAKE) -E CMFLAGS+=-D\ CMAKE_CXX_FLAGS=-DTEST_B -C .
- $(MAKE) -E SERIAL_PORT=/dev/ttyACM1 -C . flash
-
diff --git a/puzzle/vault/mod.c b/puzzle/vault/mod.c
index 058a585..bae8a3d 100644
--- a/puzzle/vault/mod.c
+++ b/puzzle/vault/mod.c
@@ -1,6 +1,6 @@
#include "pb.h"
#include "pb-mod.h"
-const char * PB_MOD_NAME = "dummy";
-const i2c_addr_t PB_MOD_ADDR = PB_ADDR_MOD_DUMMY;
+const char * PB_MOD_NAME = "vault";
+const i2c_addr_t PB_MOD_ADDR = PB_ADDR_MOD_VAULT;