diff --git a/CMakeLists.txt b/CMakeLists.txt index 521dd99..24ed01a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.20) include(pico_sdk_import.cmake) @@ -14,10 +14,11 @@ pico_sdk_init() pico_generate_pio_header(threeam ${CMAKE_CURRENT_LIST_DIR}/Neopixel.pio) -target_sources(threeam PRIVATE +target_sources(threeam PRIVATE main.cpp colors.hpp - Neopixel.pio.h) +# Neopixel.pio.h + ) target_link_libraries(threeam PRIVATE pico_stdlib diff --git a/colors.hpp b/colors.hpp index 5bbac6a..6ce48ae 100644 --- a/colors.hpp +++ b/colors.hpp @@ -1,6 +1,9 @@ +#ifndef H_29BB41A351824C13AA4B9673DCEC215D +#define H_29BB41A351824C13AA4B9673DCEC215D + #include -struct pixel +struct Pixel { uint8_t green; uint8_t red; @@ -21,8 +24,33 @@ struct pixel } }; +struct BigPixel +{ + uint32_t value; + //should check for endianness I think + //but there is no fully compliant way to test at compile time + #if defined(__BYTE_ORDER__)&&(__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) + uint8_t& green() { return *(reinterpret_cast(value)+0); } + uint8_t& red() { return *(reinterpret_cast(value)+1); } + uint8_t& blue() { return *(reinterpret_cast(value)+2); } + uint8_t& white() { return *(reinterpret_cast(value)+3); } + #else + uint8_t& green() { return *(reinterpret_cast(value)+3); } + uint8_t& red() { return *(reinterpret_cast(value)+2); } + uint8_t& blue() { return *(reinterpret_cast(value)+1); } + uint8_t& white() { return *(reinterpret_cast(value)+0); } + #endif +}; + // GRB color -const pixel Callie = { 0xD0, 0xA0, 0xC8 }; -const pixel Coqui = { 0xF4, 0xFF, 0x91 }; -const pixel Meat = { 0xEA, 0xCD, 0xBF }; -const pixel Olivia = { 0xCC, 0xFF, 0xE7 }; +const Pixel Callie = { 0xD0, 0xA0, 0xC8 }; +const Pixel Coqui = { 0xF4, 0xFF, 0x91 }; +const Pixel Meat = { 0xEA, 0xCD, 0xBF }; +const Pixel Olivia = { 0xCC, 0xFF, 0xE7 }; + +const BigPixel bCallie = { 0xD0A0C800 }; +const BigPixel bCoqui = { 0xF4FF9100 }; +const BigPixel bMeat = { 0xEACDBF00 }; +const BigPixel bOlivia = { 0xCCFFE700 }; + +#endif //H_29BB41A351824C13AA4B9673DCEC215D diff --git a/grid.hpp b/grid.hpp new file mode 100644 index 0000000..78269c7 --- /dev/null +++ b/grid.hpp @@ -0,0 +1,59 @@ +#ifndef H_89BCEB17FBD94DE38B501C2F028FDF35 +#define H_89BCEB17FBD94DE38B501C2F028FDF35 + +#include "colors.hpp" + +template +class Grid +{ + static_assert(Size % 2 == 0); + static constexpr int pixels = Size*Size; + std::array data; + public: + static constexpr std::array quad1() + { + std::array q; + for (int i = 0; i < Size/2; i++) + for (int j = 0; j < Size/2; j++) + { + const int count = i * Size/2 + j; + q[count] = i * Size + j; + } + return q; + } + static constexpr std::array quad2() + { + std::array q; + for (int i = 0; i < Size/2; i++) + for (int j = 0; j < Size/2; j++) + { + const int count = i * Size/2 + j; + q[count] = (Size - i - 1) * Size + j; + } + return q; + } + static constexpr std::array quad3() + { + std::array q; + for (int i = 0; i < Size/2; i++) + for (int j = 0; j < Size/2; j++) + { + const int count = i * Size/2 + j; + q[count] = i * Size + j; + } + return q; + } + static constexpr std::array quad4() + { + std::array q; + for (int i = 0; i < Size/2; i++) + for (int j = 0; j < Size/2; j++) + { + const int count = i * Size/2 + j; + q[count] = (Size - i - 1) * Size + (Size - j - 1); + } + return q; + } +}; + +#endif //H_89BCEB17FBD94DE38B501C2F028FDF35 diff --git a/main.cpp b/main.cpp index 269ecef..e7d527d 100644 --- a/main.cpp +++ b/main.cpp @@ -4,30 +4,32 @@ #include "Neopixel.pio.h" #include #include "colors.hpp" +#include "grid.hpp" #include "hardware/pio.h" #include "hardware/clocks.h" #include constexpr uint8_t WS2812_PIN = 22; -std::array data; +std::array data; +Grid<8> grid; extern "C" int main() { stdio_init_all(); - data[0] = Coqui; - data[1] = Olivia; - data[2] = Meat; - data[3] = Callie; - memcpy(data.data()+4, data.data(), 4*sizeof(pixel)); - memcpy(data.data()+8, data.data(), 8*sizeof(pixel)); - memcpy(data.data()+16, data.data(), 16*sizeof(pixel)); + // data[0] = bCoqui; + // data[1] = bOlivia; + // data[2] = bMeat; + // data[3] = bCallie; + // memcpy(data.data()+4, data.data(), 4*sizeof(pixel)); + // memcpy(data.data()+8, data.data(), 8*sizeof(pixel)); + // memcpy(data.data()+16, data.data(), 16*sizeof(pixel)); // for (auto x : data) // printf("%d ", x); auto pio = pio0; auto offset = pio_add_program(pio, &ws2812_program); ws2812_program_init(pio, 0, offset, WS2812_PIN, 800000, false); - for (auto p : data) - pio_sm_put_blocking(pio, 0, p.get()); + // for (auto p : data) + // pio_sm_put_blocking(pio, 0, p.value); while (1); }