acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

Arduino_Canvas_3bit.cpp (1533B)

      1 #include "../Arduino_DataBus.h"
      2 #if !defined(LITTLE_FOOT_PRINT)
      3 
      4 #include "../Arduino_GFX.h"
      5 #include "Arduino_Canvas_3bit.h"
      6 
      7 Arduino_Canvas_3bit::Arduino_Canvas_3bit(int16_t w, int16_t h, Arduino_G *output, int16_t output_x, int16_t output_y)
      8     : Arduino_GFX(w, h), _output(output), _output_x(output_x), _output_y(output_y)
      9 {
     10 }
     11 
     12 bool Arduino_Canvas_3bit::begin(int32_t speed)
     13 {
     14   if (speed != GFX_SKIP_OUTPUT_BEGIN)
     15   {
     16     if (!_output->begin(speed))
     17     {
     18       return false;
     19     }
     20   }
     21 
     22   size_t s = (_width * _height + 1) / 2;
     23 #if defined(ESP32)
     24   if (psramFound())
     25   {
     26     _framebuffer = (uint8_t *)ps_malloc(s);
     27   }
     28   else
     29   {
     30     _framebuffer = (uint8_t *)malloc(s);
     31   }
     32 #else
     33   _framebuffer = (uint8_t *)malloc(s);
     34 #endif
     35   if (!_framebuffer)
     36   {
     37     return false;
     38   }
     39 
     40   return true;
     41 }
     42 
     43 void Arduino_Canvas_3bit::writePixelPreclipped(int16_t x, int16_t y, uint16_t color)
     44 {
     45   int32_t pos = x + (y * _width);
     46   int32_t idx = pos >> 1;
     47   uint8_t c = (((color & 0b1000000000000000) ? 0b100 : 0) |
     48                ((color & 0b0000010000000000) ? 0b010 : 0) |
     49                ((color & 0b0000000000010000) ? 0b001 : 0));
     50   if (pos & 1)
     51   {
     52     _framebuffer[idx] = (_framebuffer[idx] & 0b00111000) | c;
     53   }
     54   else
     55   {
     56     _framebuffer[idx] = (_framebuffer[idx] & 0b00000111) | (c << 3);
     57   }
     58 }
     59 
     60 void Arduino_Canvas_3bit::flush()
     61 {
     62   _output->draw3bitRGBBitmap(_output_x, _output_y, _framebuffer, _width, _height);
     63 }
     64 
     65 uint8_t *Arduino_Canvas_3bit::getFramebuffer()
     66 {
     67   return _framebuffer;
     68 }
     69 
     70 #endif // !defined(LITTLE_FOOT_PRINT)