summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--CMakeLists.txt36
-rw-r--r--led_cube.c117
-rw-r--r--pico_sdk_import.cmake73
4 files changed, 228 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..d9d8bd8
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+build/*
+compile_commands.json
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..c05c0c6
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,36 @@
+cmake_minimum_required(VERSION 3.12)
+
+# Pull in Pico SDK (must be before project)
+include(pico_sdk_import.cmake)
+
+project(led_cube C CXX ASM)
+set(CMAKE_C_STANDARD 11)
+set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
+
+set(PICO_EXAMPLES_PATH $(PROJECT_SOURCE_DIR))
+
+# Initalise the SDK
+pico_sdk_init()
+
+if (TARGET tinyusb_device)
+ add_executable(led_cube
+ led_cube.c
+ )
+
+ # pull in common dependencies
+ target_link_libraries(led_cube
+ pico_stdlib
+ pico_multicore
+ )
+
+ # enable usb output, disable uart output
+ pico_enable_stdio_usb(led_cube 1)
+ pico_enable_stdio_uart(led_cube 0)
+
+ # create map/bin/hex file etc.
+ pico_add_extra_outputs(led_cube)
+
+ elseif(PICO_ON_DEVICE)
+ message(WARNING "not building hello_usb because TinyUSB submodule is not initialized in the SDK")
+endif()
diff --git a/led_cube.c b/led_cube.c
new file mode 100644
index 0000000..0d4d255
--- /dev/null
+++ b/led_cube.c
@@ -0,0 +1,117 @@
+#include "pico/stdlib.h"
+#include <stdio.h>
+#include <stdint.h>
+
+// define the pins used controlling 74HC595
+#define DATA_PIN 2
+#define CLOCK_PIN 3
+#define LATCH_PIN 4
+
+void init_pins(void)
+{
+ gpio_init(DATA_PIN);
+ gpio_init(CLOCK_PIN);
+ gpio_init(LATCH_PIN);
+ gpio_set_dir(DATA_PIN, GPIO_OUT);
+ gpio_set_dir(CLOCK_PIN, GPIO_OUT);
+ gpio_set_dir(LATCH_PIN, GPIO_OUT);
+ printf("pin initialization successful!\n");
+}
+
+uint8_t map[9];
+
+// define the order of 74HC595 chain
+#define MINUS 0
+#define FIRST_PLUS 1
+#define SECOND_PLUS 2
+#define THIRD_PLUS 3
+#define FOURTH_PLUS 4
+#define FIFTH_PLUS 5
+#define SIXTH_PLUS 6
+#define SEVENTH_PLUS 7
+#define EIGHTH_PLUS 8
+
+void init_map(void)
+{
+ map[0] = MINUS;
+ map[1] = FIRST_PLUS;
+ map[2] = SECOND_PLUS;
+ map[3] = THIRD_PLUS;
+ map[4] = FOURTH_PLUS;
+ map[5] = FIFTH_PLUS;
+ map[6] = SIXTH_PLUS;
+ map[7] = SEVENTH_PLUS;
+ map[8] = EIGHTH_PLUS;
+
+}
+
+void send_raw_data(uint8_t data[9])
+{
+ gpio_put(LATCH_PIN, 0);
+ for (size_t i = 0; i < 9; i++) {
+ for (size_t j = 0; j < 8; j++)
+ {
+ gpio_put(DATA_PIN, data[map[i]] & (1 << j));
+ gpio_put(CLOCK_PIN, 0);
+ gpio_put(CLOCK_PIN, 1);
+ }
+ }
+ gpio_put(LATCH_PIN, 1);
+}
+
+void send_data(uint8_t floor, uint64_t on_floor)
+{
+ uint8_t data[9];
+
+ data[0] = floor;
+ for (size_t i = 0; i < 8; i++) {
+ data[i] = (on_floor >> (8 * i)) & 0xFF;
+ }
+
+ send_raw_data(data);
+}
+
+void draw(uint64_t data[8])
+{
+ for (size_t i = 0; i < 8; i++) {
+ send_data((1 << i), data[i]);
+ }
+}
+
+
+void test(void)
+{
+ for (size_t i = 0; i < 8; i++) {
+ send_data((1 << i), 0xFFFFFFFFFFFFFFFF);
+ sleep_ms(200);
+ }
+}
+
+void test_every_pin(void)
+{
+ uint64_t data[8];
+ for (size_t x = 0; x < 8; x++) {
+ for (size_t y = 0; y < 8; y++) {
+ for (size_t z = 0; z < 8; z++) {
+ data[z] = 1 << (y * 8 + x);
+ draw(data);
+ data[z] = 0;
+ sleep_ms(20);
+ }
+ }
+ }
+}
+
+
+int main()
+{
+ init_pins();
+ init_map();
+
+ while(1) {
+ test();
+ test_every_pin();
+ }
+
+ return 0;
+}
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 <PICO_SDK_PATH>/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})