Advertisement
honey_the_codewitch

Partial update waveshare4in2gsc

Mar 18th, 2022
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.47 KB | None | 0 0
  1. static void update_display_bw_part(const FrameBufferType& frame_buffer,gfx::rect16 bounds,bool dithering) {
  2.     //Serial.printf("(%d,%d)-(%d,%d)\r\n",bounds.x1,bounds.y1,bounds.x2,bounds.y2);
  3.     // i've checked these constants over and over again. they're right:
  4.     bus_driver::send_command(0x91);
  5.     bus_driver::send_command(0x90);
  6.     int x1=bounds.x1&0xF8;
  7.     int x2=bounds.x2|0x7;
  8.     bus_driver::send_data8(x1 >> 8);
  9.     bus_driver::send_data8(x1 & 0xff);     // x should be the multiple of 8, the last 3 bit will always be ignored
  10.     bus_driver::send_data8(x2 >> 8);
  11.     bus_driver::send_data8(x2 & 0xff);
  12.     bus_driver::send_data8(bounds.y1 >> 8);        
  13.     bus_driver::send_data8(bounds.y1 & 0xff);
  14.     bus_driver::send_data8(bounds.y2 >> 8);        
  15.     bus_driver::send_data8(bounds.y2 & 0xff);
  16.     bus_driver::send_data8(0x01);         // Gates scan both inside and outside of the partial window. (default)
  17.     delay(2);
  18.     bus_driver::send_command(0x13);
  19.     if(dithering) {
  20.         for(int y = bounds.y1;y<=bounds.y2;++y) {
  21.             int row = y&15;
  22.             for(int x=x1;x<=x2;x+=8) {
  23.                 uint8_t b = 0;
  24.                 for(int bx=0;bx<8;++bx) {
  25.                     int xx = (bx+x);
  26.                     int col = xx & 15;
  27.                     typename FrameBufferType::pixel_type px;
  28.                     frame_buffer.point(gfx::point16(xx,y),&px);
  29.                     b|=(1<<(7-bx))*
  30.                                 !!(255.0 * px.template channelr<
  31.                                             gfx::channel_name::L>() >
  32.                                 gfx::helpers::dither::bayer_16[col +
  33.                                                                 row * 16]);
  34.                 }
  35.                 bus_driver::send_data8(b);
  36.             }
  37.         }
  38.     } else {
  39.         // this is the one getting called
  40.         // everything about this loop has been tested
  41.         // in the update_display_bw() routine which contains
  42.         // the same code
  43.         for(int y = bounds.y1;y<=bounds.y2;++y) {
  44.             for(int x=x1;x<=x2;x+=8) {
  45.                 uint8_t b = 0;
  46.                 for(int bx=0;bx<8;++bx) {
  47.                     typename FrameBufferType::pixel_type px;
  48.                     frame_buffer.point(gfx::point16(bx+x,y),&px);
  49.                     b|=(1<<(7-bx))*!!px.native_value;
  50.                 }
  51.                 bus_driver::send_data8(b);
  52.             }
  53.         }
  54.     }
  55.  
  56.     delay(2);
  57.  
  58.     bus_driver::send_command(0x92);  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement