IS31FL3733 Async Driver 1.0.0
Asynchronous DMA-driven IS31FL3733 LED driver for Arduino SAMD
Loading...
Searching...
No Matches
is31fl3733_rgb_matrix.hpp
1/*---------------------------------------------------------------------------------------------
2 * Copyright (c) Cal Abel. All rights reserved.
3 * Licensed under the MIT License. See LICENSE in the project root for license information.
4 *
5 * Based on the original IS31FL3733 C++ library by Neil Enns
6 * (https://github.com/neilenns/is31fl3733).
7 * RGB matrix helper - part of async DMA rewrite for Arduino SAMD.
8 *
9 * IS31FL3733 RGB matrix helper utilities.
10 *--------------------------------------------------------------------------------------------*/
11#pragma once
12
13#include "is31fl3733.hpp"
14#include "is31fl3733_color_utils.hpp"
15
16namespace IS31FL3733 {
22 public:
26 static constexpr uint8_t kRows = 4;
28 static constexpr uint8_t kCols = 16;
39 IS31FL3733RgbMatrix(TwoWire *wire, uint8_t addr = 0x50, uint8_t sdbPin = 0xFF,
40 uint8_t irqPin = 0xFF, ColorOrder order = ColorOrder::GRB)
41 : IS31FL3733(wire, addr, sdbPin, irqPin) {
42 SetColorOrder(order);
43 }
48
54 static bool IsValidRow(uint8_t row) {
55 return row >= 1 && row <= kRows;
56 }
57
61 static bool IsValidCol(uint8_t col) {
62 return col >= 1 && col <= kCols;
63 }
73 void SetPixelColor32(uint8_t row, uint8_t col, uint32_t packedRgb, bool gamma = false) {
74 if (!IsValidRow(row) || !IsValidCol(col)) {
75 return;
76 }
77
78 uint32_t color = gamma ? ColorUtils::Gamma32(packedRgb) : packedRgb;
79
80 const uint8_t r = static_cast<uint8_t>((color >> 16) & 0xFF);
81 const uint8_t g = static_cast<uint8_t>((color >> 8) & 0xFF);
82 const uint8_t b = static_cast<uint8_t>(color & 0xFF);
83
84 IS31FL3733::SetPixelColor(row, col, r, g, b);
85 }
86
94 void SetPixelHSV(uint8_t row, uint8_t col, uint16_t hue, uint8_t sat = 255, uint8_t val = 255,
95 bool gamma = true) {
96 uint32_t color = ColorUtils::ColorHSV(hue, sat, val);
97 SetPixelColor32(row, col, color, gamma);
98 }
99
103 void FillColor32(uint32_t packedRgb, bool gamma = false) {
104 for (uint8_t row = 1; row <= kRows; row++) {
105 for (uint8_t col = 1; col <= kCols; col++) {
106 SetPixelColor32(row, col, packedRgb, gamma);
107 }
108 }
109 }
110
116 void FillHSV(uint16_t hue, uint8_t sat = 255, uint8_t val = 255, bool gamma = true) {
117 const uint32_t color = ColorUtils::ColorHSV(hue, sat, val);
118 FillColor32(color, gamma);
119 }
121};
122} // namespace IS31FL3733
Convenience RGB matrix API built on top of the core async driver.
static constexpr uint8_t kRows
Logical RGB matrix row count.
void SetPixelColor32(uint8_t row, uint8_t col, uint32_t packedRgb, bool gamma=false)
Set a logical RGB pixel from packed 0xRRGGBB value.
void FillHSV(uint16_t hue, uint8_t sat=255, uint8_t val=255, bool gamma=true)
Fill logical matrix with HSV color.
void FillColor32(uint32_t packedRgb, bool gamma=false)
Fill logical matrix with packed RGB color.
IS31FL3733RgbMatrix(TwoWire *wire, uint8_t addr=0x50, uint8_t sdbPin=0xFF, uint8_t irqPin=0xFF, ColorOrder order=ColorOrder::GRB)
Construct RGB matrix helper with same arguments as base driver.
static constexpr uint8_t kCols
Logical RGB matrix column count.
void SetPixelHSV(uint8_t row, uint8_t col, uint16_t hue, uint8_t sat=255, uint8_t val=255, bool gamma=true)
Set a logical RGB pixel from HSV.
static bool IsValidCol(uint8_t col)
Validate a logical RGB column index.
void SetColorOrder(ColorOrder order)
Set the color order for RGB pixel mapping.
static bool IsValidRow(uint8_t row)
Validate a logical RGB row index.
Asynchronous DMA-driven IS31FL3733 LED driver for SAMD SERCOM I2C.
ColorOrder GetColorOrder() const
Get the current color order.
void SetPixelColor(uint8_t row, uint8_t col, uint8_t r, uint8_t g, uint8_t b)
Set RGB color for a logical pixel (with color order mapping).
void SetColorOrder(ColorOrder order)
Set the color order for RGB pixel mapping.