Advertisement
honey_the_codewitch

batching example

Apr 24th, 2022
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.51 KB | None | 0 0
  1. #include <Arduino.h>
  2. #include <tft_io.hpp>
  3. #include <ili9341.hpp>
  4. #include <gfx_cpp14.hpp>
  5. using namespace arduino;
  6. using namespace gfx;
  7.  
  8. #define LCD_HOST    VSPI
  9. #define PIN_NUM_MISO 25
  10. #define PIN_NUM_MOSI 23
  11. #define PIN_NUM_CLK  19
  12. #define PIN_NUM_CS   22
  13.  
  14. #define PIN_NUM_DC   21
  15. #define PIN_NUM_RST  18
  16. #define PIN_NUM_BCKL 5
  17.  
  18. using bus_t = tft_spi_ex<VSPI,PIN_NUM_CS,PIN_NUM_MOSI,PIN_NUM_MISO,PIN_NUM_CLK,SPI_MODE0,false,320*240*2+8,2>;
  19. using lcd_t = ili9341<PIN_NUM_DC,PIN_NUM_RST,PIN_NUM_BCKL,bus_t,1,false,400,200>;
  20.  
  21. lcd_t lcd;
  22.  
  23. void setup() {
  24.   Serial.begin(115200);
  25.   hsv_pixel<24> px(true,0,1,1);
  26.   auto px2 = px;
  27.   // batching is the fastest way
  28.   auto b = draw::batch(lcd,lcd.bounds());
  29.   for(int y = 0;y<lcd.dimensions().height;++y) {
  30.     px2.template channelr<channel_name::S>(((double)y)/lcd.bounds().y2);
  31.     for(int x = 0;x<320;++x) {
  32.       px2.template channelr<channel_name::V>(((double)x)/lcd.bounds().x2);
  33.       b.write(px2);
  34.     }
  35.   }
  36.   // commit what we wrote
  37.   b.commit();
  38.   px2.template channelr<channel_name::H>(.5);
  39.   // batching is the fastest way
  40.   auto ba = draw::batch_async(lcd,lcd.bounds());
  41.   for(int y = 0;y<lcd.dimensions().height;++y) {
  42.     px2.template channelr<channel_name::S>(((double)y)/lcd.bounds().y2);
  43.     for(int x = 0;x<320;++x) {
  44.       px2.template channelr<channel_name::V>(((double)x)/lcd.bounds().x2);
  45.       ba.write(px2);
  46.     }
  47.   }
  48.   // commit what we wrote
  49.   ba.commit();
  50. }
  51.  
  52. void loop() {
  53.   // put your main code here, to run repeatedly:
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement