From a322c400f09aa350e05cd0565f9d7b08f7bf3fc6 Mon Sep 17 00:00:00 2001 From: jon Date: Tue, 26 Jul 2022 05:31:33 +0100 Subject: [PATCH] Added support for new RGB888 pen type --- examples/galactic_unicorn/feature_test.cpp | 5 +-- .../galactic_unicorn/galactic_unicorn.cpp | 34 +++++++++++++++---- .../galactic_unicorn/galactic_unicorn.hpp | 5 +-- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/examples/galactic_unicorn/feature_test.cpp b/examples/galactic_unicorn/feature_test.cpp index 66361158..c2016afb 100644 --- a/examples/galactic_unicorn/feature_test.cpp +++ b/examples/galactic_unicorn/feature_test.cpp @@ -21,7 +21,8 @@ extern uint32_t right_channel_bin_len; void gradient(uint8_t r, uint8_t g, uint8_t b) { for(int y = 0; y < 12; y++) { for(int x = 0; x < 53; x++) { - graphics.set_pen((r * x) / 52, (g * x) / 52, (b * x) / 52); +// graphics.set_pen((r * x) / 52, (g * x) / 52, (b * x) / 52); + graphics.set_pen(x, x, x); graphics.pixel(Point(x, y)); } } @@ -72,7 +73,7 @@ int main() { galactic_unicorn.init(); - galactic_unicorn.set_brightness(0.5f); + //galactic_unicorn.set_brightness(0.5f); while(true) { if(galactic_unicorn.is_pressed(galactic_unicorn.SWITCH_BRIGHTNESS_UP)) { diff --git a/libraries/galactic_unicorn/galactic_unicorn.cpp b/libraries/galactic_unicorn/galactic_unicorn.cpp index 9dda38b1..0f2718f5 100644 --- a/libraries/galactic_unicorn/galactic_unicorn.cpp +++ b/libraries/galactic_unicorn/galactic_unicorn.cpp @@ -39,7 +39,7 @@ // .. and back to the start constexpr uint32_t ROW_COUNT = 11; -constexpr uint32_t BCD_FRAME_COUNT = 12; +constexpr uint32_t BCD_FRAME_COUNT = 14; constexpr uint32_t BCD_FRAME_BYTES = 60; constexpr uint32_t ROW_BYTES = BCD_FRAME_COUNT * BCD_FRAME_BYTES; constexpr uint32_t BITSTREAM_LENGTH = (ROW_COUNT * ROW_BYTES); @@ -98,7 +98,7 @@ namespace pimoroni { // 0-65535 range for the pwm counter float r_gamma = 1.8f; r_gamma_lut[v] = (uint16_t)(powf((float)(v) / 255.0f, r_gamma) * (float(1U << (BCD_FRAME_COUNT)) - 1.0f) + 0.5f); - float g_gamma = 2.0f; + float g_gamma = 1.8f; g_gamma_lut[v] = (uint16_t)(powf((float)(v) / 255.0f, g_gamma) * (float(1U << (BCD_FRAME_COUNT)) - 1.0f) + 0.5f); float b_gamma = 1.8f; b_gamma_lut[v] = (uint16_t)(powf((float)(v) / 255.0f, b_gamma) * (float(1U << (BCD_FRAME_COUNT)) - 1.0f) + 0.5f); @@ -356,7 +356,7 @@ namespace pimoroni { void GalacticUnicorn::set_brightness(float value) { value = value < 0.0f ? 0.0f : value; value = value > 1.0f ? 1.0f : value; - this->brightness = floor(value * 255.0f); + this->brightness = floor(value * 256.0f); } float GalacticUnicorn::get_brightness() { @@ -382,16 +382,16 @@ namespace pimoroni { } - void GalacticUnicorn::update(PicoGraphics_PenRGB888 &graphics) { + void GalacticUnicorn::update(PicoGraphics_PenRGB565 &graphics) { uint16_t *p = (uint16_t *)graphics.frame_buffer; for(size_t j = 0; j < 53 * 11; j++) { int x = j % 53; int y = j / 53; uint16_t col = __builtin_bswap16(*p); - uint8_t r = (col & 0xff0000) >> 16; - uint8_t g = (col & 0x00ff00) >> 8; - uint8_t b = (col & 0x0000ff) >> 0; + uint8_t r = (col & 0b1111100000000000) >> 8; + uint8_t g = (col & 0b0000011111100000) >> 3; + uint8_t b = (col & 0b0000000000011111) << 3; p++; r = (r * this->brightness) >> 8; @@ -402,6 +402,26 @@ namespace pimoroni { } } + void GalacticUnicorn::update(PicoGraphics_PenRGB888 &graphics) { + uint32_t *p = (uint32_t *)graphics.frame_buffer; + for(size_t j = 0; j < 53 * 11; j++) { + int x = j % 53; + int y = j / 53; + + uint32_t col = *p; + uint8_t r = (col & 0xff0000) >> 16; + uint8_t g = (col & 0x00ff00) >> 8; + uint8_t b = (col & 0x0000ff) >> 0; + p++; + + r = (r * this->brightness) >> 8; + g = (g * this->brightness) >> 8; + b = (b * this->brightness) >> 8; + + set_pixel(x, y, b, g, r); + } + } + bool GalacticUnicorn::is_pressed(uint8_t button) { return !gpio_get(button); } diff --git a/libraries/galactic_unicorn/galactic_unicorn.hpp b/libraries/galactic_unicorn/galactic_unicorn.hpp index d4499cb0..340e767f 100644 --- a/libraries/galactic_unicorn/galactic_unicorn.hpp +++ b/libraries/galactic_unicorn/galactic_unicorn.hpp @@ -53,8 +53,8 @@ namespace pimoroni { uint audio_sm = 0; uint audio_sm_offset = 0; - uint8_t brightness = 255; - uint8_t volume = 127; + uint16_t brightness = 256; + uint16_t volume = 127; public: ~GalacticUnicorn(); @@ -64,6 +64,7 @@ namespace pimoroni { void clear(); + void update(PicoGraphics_PenRGB565 &graphics); void update(PicoGraphics_PenRGB888 &graphics); void set_brightness(float value);