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_Mono.cpp (1338B)
1 #include "../Arduino_DataBus.h" 2 #if !defined(LITTLE_FOOT_PRINT) 3 4 #include "../Arduino_GFX.h" 5 #include "Arduino_Canvas_Mono.h" 6 7 Arduino_Canvas_Mono::Arduino_Canvas_Mono(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_Mono::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 + 7) / 8 * _height; 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_Mono::writePixelPreclipped(int16_t x, int16_t y, uint16_t color) 44 { 45 int16_t w = (_width + 7) / 8; 46 int32_t pos = y * w + x / 8; 47 if (color & 0b1000010000010000) 48 { 49 _framebuffer[pos] |= 0x80 >> (x & 7); 50 } 51 else 52 { 53 _framebuffer[pos] &= ~(0x80 >> (x & 7)); 54 } 55 } 56 57 void Arduino_Canvas_Mono::flush() 58 { 59 _output->drawBitmap(_output_x, _output_y, _framebuffer, _width, _height, WHITE, BLACK); 60 } 61 62 uint8_t *Arduino_Canvas_Mono::getFramebuffer() 63 { 64 return _framebuffer; 65 } 66 67 #endif // !defined(LITTLE_FOOT_PRINT)