diff --git a/hello_world/usb/wrappers/CriticalSection.cpp b/hello_world/usb/wrappers/CriticalSection.cpp new file mode 100644 index 0000000..bf12503 --- /dev/null +++ b/hello_world/usb/wrappers/CriticalSection.cpp @@ -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); +} \ No newline at end of file diff --git a/hello_world/usb/wrappers/CriticalSection.h b/hello_world/usb/wrappers/CriticalSection.h new file mode 100644 index 0000000..262801e --- /dev/null +++ b/hello_world/usb/wrappers/CriticalSection.h @@ -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 diff --git a/hello_world/usb/wrappers/Mutex.cpp b/hello_world/usb/wrappers/Mutex.cpp new file mode 100644 index 0000000..703ed2c --- /dev/null +++ b/hello_world/usb/wrappers/Mutex.cpp @@ -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); +} diff --git a/hello_world/usb/wrappers/Mutex.h b/hello_world/usb/wrappers/Mutex.h new file mode 100644 index 0000000..0e3ca24 --- /dev/null +++ b/hello_world/usb/wrappers/Mutex.h @@ -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 \ No newline at end of file diff --git a/hello_world/usb/wrappers/NeoPacket.cpp b/hello_world/usb/wrappers/NeoPacket.cpp new file mode 100644 index 0000000..9a4ad41 --- /dev/null +++ b/hello_world/usb/wrappers/NeoPacket.cpp @@ -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; +} + +} \ No newline at end of file diff --git a/hello_world/usb/wrappers/NeoPacket.h b/hello_world/usb/wrappers/NeoPacket.h new file mode 100644 index 0000000..27a0ed3 --- /dev/null +++ b/hello_world/usb/wrappers/NeoPacket.h @@ -0,0 +1,83 @@ +#ifndef H_3FE5AF534D5E46BD9700F872DB5C50CD +#define H_3FE5AF534D5E46BD9700F872DB5C50CD + +#include +#include + +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 +class NeoPacket +{ + public: + std::array& as_green() + { + return reinterpret_cast&>(*this); + } + std::array& as_red() + { + return reinterpret_cast&>(*this); + } + std::array& as_blue() + { + return reinterpret_cast&>(*this); + } + + private: + std::array data; +}; + +} + +#endif //H_3FE5AF534D5E46BD9700F872DB5C50CD diff --git a/hello_world/usb/wrappers/Spi.h b/hello_world/usb/wrappers/Spi.h new file mode 100644 index 0000000..e69de29