updates
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
cmake_minimum_required(VERSION 3.12)
|
cmake_minimum_required(VERSION 3.20)
|
||||||
|
|
||||||
include(pico_sdk_import.cmake)
|
include(pico_sdk_import.cmake)
|
||||||
|
|
||||||
@@ -14,10 +14,11 @@ pico_sdk_init()
|
|||||||
|
|
||||||
pico_generate_pio_header(threeam ${CMAKE_CURRENT_LIST_DIR}/Neopixel.pio)
|
pico_generate_pio_header(threeam ${CMAKE_CURRENT_LIST_DIR}/Neopixel.pio)
|
||||||
|
|
||||||
target_sources(threeam PRIVATE
|
target_sources(threeam PRIVATE
|
||||||
main.cpp
|
main.cpp
|
||||||
colors.hpp
|
colors.hpp
|
||||||
Neopixel.pio.h)
|
# Neopixel.pio.h
|
||||||
|
)
|
||||||
|
|
||||||
target_link_libraries(threeam PRIVATE
|
target_link_libraries(threeam PRIVATE
|
||||||
pico_stdlib
|
pico_stdlib
|
||||||
|
|||||||
38
colors.hpp
38
colors.hpp
@@ -1,6 +1,9 @@
|
|||||||
|
#ifndef H_29BB41A351824C13AA4B9673DCEC215D
|
||||||
|
#define H_29BB41A351824C13AA4B9673DCEC215D
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
struct pixel
|
struct Pixel
|
||||||
{
|
{
|
||||||
uint8_t green;
|
uint8_t green;
|
||||||
uint8_t red;
|
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<uint8_t*>(value)+0); }
|
||||||
|
uint8_t& red() { return *(reinterpret_cast<uint8_t*>(value)+1); }
|
||||||
|
uint8_t& blue() { return *(reinterpret_cast<uint8_t*>(value)+2); }
|
||||||
|
uint8_t& white() { return *(reinterpret_cast<uint8_t*>(value)+3); }
|
||||||
|
#else
|
||||||
|
uint8_t& green() { return *(reinterpret_cast<uint8_t*>(value)+3); }
|
||||||
|
uint8_t& red() { return *(reinterpret_cast<uint8_t*>(value)+2); }
|
||||||
|
uint8_t& blue() { return *(reinterpret_cast<uint8_t*>(value)+1); }
|
||||||
|
uint8_t& white() { return *(reinterpret_cast<uint8_t*>(value)+0); }
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
// GRB color
|
// GRB color
|
||||||
const pixel Callie = { 0xD0, 0xA0, 0xC8 };
|
const Pixel Callie = { 0xD0, 0xA0, 0xC8 };
|
||||||
const pixel Coqui = { 0xF4, 0xFF, 0x91 };
|
const Pixel Coqui = { 0xF4, 0xFF, 0x91 };
|
||||||
const pixel Meat = { 0xEA, 0xCD, 0xBF };
|
const Pixel Meat = { 0xEA, 0xCD, 0xBF };
|
||||||
const pixel Olivia = { 0xCC, 0xFF, 0xE7 };
|
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
|
||||||
|
|||||||
59
grid.hpp
Normal file
59
grid.hpp
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
#ifndef H_89BCEB17FBD94DE38B501C2F028FDF35
|
||||||
|
#define H_89BCEB17FBD94DE38B501C2F028FDF35
|
||||||
|
|
||||||
|
#include "colors.hpp"
|
||||||
|
|
||||||
|
template <int Size>
|
||||||
|
class Grid
|
||||||
|
{
|
||||||
|
static_assert(Size % 2 == 0);
|
||||||
|
static constexpr int pixels = Size*Size;
|
||||||
|
std::array<BigPixel, pixels> data;
|
||||||
|
public:
|
||||||
|
static constexpr std::array<int, pixels/4> quad1()
|
||||||
|
{
|
||||||
|
std::array<int, pixels/4> 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<int, pixels/4> quad2()
|
||||||
|
{
|
||||||
|
std::array<int, pixels/4> 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<int, pixels/4> quad3()
|
||||||
|
{
|
||||||
|
std::array<int, pixels/4> 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<int, pixels/4> quad4()
|
||||||
|
{
|
||||||
|
std::array<int, pixels/4> 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
|
||||||
22
main.cpp
22
main.cpp
@@ -4,30 +4,32 @@
|
|||||||
#include "Neopixel.pio.h"
|
#include "Neopixel.pio.h"
|
||||||
#include <array>
|
#include <array>
|
||||||
#include "colors.hpp"
|
#include "colors.hpp"
|
||||||
|
#include "grid.hpp"
|
||||||
#include "hardware/pio.h"
|
#include "hardware/pio.h"
|
||||||
#include "hardware/clocks.h"
|
#include "hardware/clocks.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
constexpr uint8_t WS2812_PIN = 22;
|
constexpr uint8_t WS2812_PIN = 22;
|
||||||
|
|
||||||
std::array<pixel, 32> data;
|
std::array<BigPixel, 32> data;
|
||||||
|
Grid<8> grid;
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
int main() {
|
int main() {
|
||||||
stdio_init_all();
|
stdio_init_all();
|
||||||
data[0] = Coqui;
|
// data[0] = bCoqui;
|
||||||
data[1] = Olivia;
|
// data[1] = bOlivia;
|
||||||
data[2] = Meat;
|
// data[2] = bMeat;
|
||||||
data[3] = Callie;
|
// data[3] = bCallie;
|
||||||
memcpy(data.data()+4, data.data(), 4*sizeof(pixel));
|
// memcpy(data.data()+4, data.data(), 4*sizeof(pixel));
|
||||||
memcpy(data.data()+8, data.data(), 8*sizeof(pixel));
|
// memcpy(data.data()+8, data.data(), 8*sizeof(pixel));
|
||||||
memcpy(data.data()+16, data.data(), 16*sizeof(pixel));
|
// memcpy(data.data()+16, data.data(), 16*sizeof(pixel));
|
||||||
// for (auto x : data)
|
// for (auto x : data)
|
||||||
// printf("%d ", x);
|
// printf("%d ", x);
|
||||||
auto pio = pio0;
|
auto pio = pio0;
|
||||||
auto offset = pio_add_program(pio, &ws2812_program);
|
auto offset = pio_add_program(pio, &ws2812_program);
|
||||||
ws2812_program_init(pio, 0, offset, WS2812_PIN, 800000, false);
|
ws2812_program_init(pio, 0, offset, WS2812_PIN, 800000, false);
|
||||||
for (auto p : data)
|
// for (auto p : data)
|
||||||
pio_sm_put_blocking(pio, 0, p.get());
|
// pio_sm_put_blocking(pio, 0, p.value);
|
||||||
while (1);
|
while (1);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user