Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #include <tft_io.hpp>
- #include <ili9341.hpp>
- #include <gfx_cpp14.hpp>
- #include "Maziro.h"
- using namespace arduino;
- using namespace gfx;
- #define LCD_HOST VSPI
- #define PIN_NUM_MISO 25
- #define PIN_NUM_MOSI 23
- #define PIN_NUM_CLK 19
- #define PIN_NUM_CS 22
- #define LCD_WRITE_SPEED_PERCENT 400 // 40MHz
- #define LCD_READ_SPEED_PERCENT 200 // 20MHz
- #define PIN_NUM_DC 21
- #define PIN_NUM_RST 18
- #define PIN_NUM_BKL 5
- #define LCD_BKL_HIGH false
- #define LCD_WIDTH 240
- #define LCD_HEIGHT 320
- #define LCD_ROTATION 1
- using bus_type = tft_spi_ex<LCD_HOST,
- PIN_NUM_CS,
- PIN_NUM_MOSI,
- PIN_NUM_MISO,
- PIN_NUM_CLK,
- SPI_MODE0,
- PIN_NUM_MISO<0
- #ifdef OPTIMIZE_DMA
- ,(LCD_WIDTH*LCD_HEIGHT)*2+8
- #endif
- >;
- using lcd_type = ili9341<PIN_NUM_DC,
- PIN_NUM_RST,
- PIN_NUM_BKL,
- bus_type,
- LCD_ROTATION,
- LCD_BKL_HIGH,
- LCD_WRITE_SPEED_PERCENT,
- LCD_READ_SPEED_PERCENT>;
- using lcd_color = color<typename lcd_type::pixel_type>;
- lcd_type lcd;
- void draw_text(spoint16 loc, const open_font& fnt,const char* text, float scale, rgb_pixel<16> fg,rgb_pixel<16> bg) {
- size16 text_size = (size16)fnt.measure_text((ssize16)lcd.dimensions(),{0,0},text,scale);
- // just a little padding
- text_size.width+=2;
- text_size.height+=2;
- using bt = bitmap<rgb_pixel<16>>;
- uint8_t* buf = (uint8_t*)malloc(bt::sizeof_buffer(text_size));
- if(nullptr==buf) {
- return;
- }
- bt tmp(text_size,buf);
- tmp.fill(tmp.bounds(),bg);
- draw::text(tmp,(srect16)tmp.bounds(),{0,0},text,fnt,scale,fg);
- draw::bitmap(lcd,srect16(loc,(spoint16)lcd.bounds().bottom_right()),tmp,tmp.bounds());
- free(buf);
- }
- void setup() {
- // put your setup code here, to run once:
- lcd.fill(lcd.bounds(),lcd_color::white);
- draw_text({10,10},Maziro_ttf,"HELLO WORLD!",Maziro_ttf.scale(40),lcd_color::indian_red,lcd_color::white);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement