SSD1351 OLED Driver inconsistent color mask

I noticed something strange with the SetColorFG and SetColorBG functions - for some reason red and blue range is set to 32, while green’s range is set to 64. Is this on purpose or a bug?

  void SetColorFG(uint8_t red, uint8_t green, uint8_t blue)
    {
        uint16_t t1, t2;

        fg_color_ = (red & 0x1f) << 11 | (green & 0x3f) << 5 | (blue & 0x1f);
        t1        = (fg_color_ >> 8) & 0xff;
        t2        = (fg_color_ & 0xff);
        fg_color_ = t2 << 8 | t1;
    };

    void SetColorBG(uint8_t red, uint8_t green, uint8_t blue)
    {
        uint16_t t1, t2;

        bg_color_ = (red & 0x1f) << 11 | (green & 0x3f) << 5 | (blue & 0x1f);
        t1        = (bg_color_ >> 8) & 0xff;
        t2        = (bg_color_ & 0xff);
        bg_color_ = t2 << 8 | t1;
    };

It’s correct. SSD1351 uses 16bit color. Human eyes are better at shades of green, so it gets the extra bit.

1 Like