started Neopixel structs
This commit is contained in:
21
hello_world/usb/wrappers/CriticalSection.cpp
Normal file
21
hello_world/usb/wrappers/CriticalSection.cpp
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#include "CriticalSection.h"
|
||||||
|
|
||||||
|
CriticalSection::CriticalSection()
|
||||||
|
{
|
||||||
|
critical_section_init(&_critical);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CriticalSection::lock()
|
||||||
|
{
|
||||||
|
critical_section_enter_blocking(&_critical);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CriticalSection::unlock()
|
||||||
|
{
|
||||||
|
critical_section_exit(&_critical);
|
||||||
|
}
|
||||||
|
|
||||||
|
CriticalSection::~CriticalSection()
|
||||||
|
{
|
||||||
|
critical_section_deinit(&_critical);
|
||||||
|
}
|
||||||
20
hello_world/usb/wrappers/CriticalSection.h
Normal file
20
hello_world/usb/wrappers/CriticalSection.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#ifndef H_10337EC23C94444EB1628220BA87E2D7
|
||||||
|
#define H_10337EC23C94444EB1628220BA87E2D7
|
||||||
|
|
||||||
|
#include "pico/sync.h"
|
||||||
|
|
||||||
|
class CriticalSection
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
critical_section_t _critical;
|
||||||
|
|
||||||
|
public:
|
||||||
|
CriticalSection();
|
||||||
|
void lock();
|
||||||
|
void unlock();
|
||||||
|
~CriticalSection();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif //H_10337EC23C94444EB1628220BA87E2D7
|
||||||
16
hello_world/usb/wrappers/Mutex.cpp
Normal file
16
hello_world/usb/wrappers/Mutex.cpp
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#include "Mutex.h"
|
||||||
|
|
||||||
|
Mutex::Mutex()
|
||||||
|
{
|
||||||
|
mutex_init(&_mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mutex::lock()
|
||||||
|
{
|
||||||
|
mutex_enter_blocking(&_mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mutex::unlock()
|
||||||
|
{
|
||||||
|
mutex_exit(&_mutex);
|
||||||
|
}
|
||||||
18
hello_world/usb/wrappers/Mutex.h
Normal file
18
hello_world/usb/wrappers/Mutex.h
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#ifndef H_A295368D75B1464CB9B5336EEFFB6239
|
||||||
|
#define H_A295368D75B1464CB9B5336EEFFB6239
|
||||||
|
|
||||||
|
#include "pico/stdlib.h"
|
||||||
|
#include "pico/mutex.h"
|
||||||
|
|
||||||
|
class Mutex
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
mutex_t _mutex;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Mutex();
|
||||||
|
void lock();
|
||||||
|
void unlock();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //H_A295368D75B1464CB9B5336EEFFB6239
|
||||||
42
hello_world/usb/wrappers/NeoPacket.cpp
Normal file
42
hello_world/usb/wrappers/NeoPacket.cpp
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
#include "NeoPacket.h"
|
||||||
|
|
||||||
|
namespace NeoPacket
|
||||||
|
{
|
||||||
|
|
||||||
|
GreenPixel& GreenPixel::operator=(GreenPixel& other)
|
||||||
|
{
|
||||||
|
this->value = other.value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
GreenPixel& GreenPixel::operator=(uint8_t val)
|
||||||
|
{
|
||||||
|
this->value = val;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
RedPixel& RedPixel::operator=(RedPixel& other)
|
||||||
|
{
|
||||||
|
this->value = other.value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
RedPixel& RedPixel::operator=(uint8_t val)
|
||||||
|
{
|
||||||
|
this->value = val;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
BluePixel& BluePixel::operator=(BluePixel& other)
|
||||||
|
{
|
||||||
|
this->value = other.value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
BluePixel& BluePixel::operator=(uint8_t val)
|
||||||
|
{
|
||||||
|
this->value = val;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
83
hello_world/usb/wrappers/NeoPacket.h
Normal file
83
hello_world/usb/wrappers/NeoPacket.h
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
#ifndef H_3FE5AF534D5E46BD9700F872DB5C50CD
|
||||||
|
#define H_3FE5AF534D5E46BD9700F872DB5C50CD
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace NeoPacket
|
||||||
|
{
|
||||||
|
|
||||||
|
class RedPixel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RedPixel& operator=(RedPixel& other);
|
||||||
|
RedPixel& operator=(uint8_t val);
|
||||||
|
uint8_t val() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint8_t padding1;
|
||||||
|
uint8_t value;
|
||||||
|
uint8_t padding2;
|
||||||
|
};
|
||||||
|
|
||||||
|
class GreenPixel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GreenPixel& operator=(GreenPixel& other);
|
||||||
|
GreenPixel& operator=(uint8_t val);
|
||||||
|
uint8_t val() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint8_t value;
|
||||||
|
uint8_t padding1;
|
||||||
|
uint8_t padding2;
|
||||||
|
};
|
||||||
|
|
||||||
|
class BluePixel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BluePixel& operator=(BluePixel& other);
|
||||||
|
BluePixel& operator=(uint8_t val);
|
||||||
|
uint8_t val() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint8_t padding1;
|
||||||
|
uint8_t padding2;
|
||||||
|
uint8_t value;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Pixel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
uint8_t green;
|
||||||
|
uint8_t red;
|
||||||
|
uint8_t blue;
|
||||||
|
void apply(GreenPixel g);
|
||||||
|
void apply(RedPixel r);
|
||||||
|
void apply(BluePixel b);
|
||||||
|
};
|
||||||
|
|
||||||
|
template <std::size_t N>
|
||||||
|
class NeoPacket
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::array<GreenPixel, N>& as_green()
|
||||||
|
{
|
||||||
|
return reinterpret_cast<std::array<GreenPixel, N>&>(*this);
|
||||||
|
}
|
||||||
|
std::array<RedPixel, N>& as_red()
|
||||||
|
{
|
||||||
|
return reinterpret_cast<std::array<RedPixel, N>&>(*this);
|
||||||
|
}
|
||||||
|
std::array<BluePixel, N>& as_blue()
|
||||||
|
{
|
||||||
|
return reinterpret_cast<std::array<BluePixel, N>&>(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::array<Pixel, N> data;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //H_3FE5AF534D5E46BD9700F872DB5C50CD
|
||||||
0
hello_world/usb/wrappers/Spi.h
Normal file
0
hello_world/usb/wrappers/Spi.h
Normal file
Reference in New Issue
Block a user