PS_Fgen_FW  4da88f4073c1cc65ea45c3a652a2751e495e50db
Firmware for an Power Supply and Function Generator build from an ATX power supply
Loading...
Searching...
No Matches
ILI9341_Fast.h
1// Fast ILI9341 240x320 2.2" display library
2// (c) 2019-20 by Pawel A. Hernik
3
4/*
5 ILI9341 240x320 2.2" LCD pinout (header at the top, from left):
6 #1 MISO -> NC
7 #2 LED -> 3.3V
8 #3 SCK -> SCL/D13/PA5
9 #4 SDI -> MOSI/D11/PA7
10 #5 DC -> D8/PA1 or any digital
11 #6 RESET -> D9/PA0 or any digital
12 #7 CS -> D10/PA2 or any digital
13 #8 GND -> GND
14 #9 VCC -> 3.3V
15*/
16
17#ifndef _ILI9341_FAST_H_
18#define _ILI9341_FAST_H_
19
20// ------------------------------
21// remove "define COMPATIBILITY_MODE" for best performance on 16MHz AVR Arduinos
22// if defined - the library should work on all Arduino compatible boards
23//#define COMPATIBILITY_MODE
24
25// define when CS pin is always connected to the ground
26//#define CS_ALWAYS_LOW
27// ------------------------------
28
29#include "Arduino.h"
30#include "Print.h"
31#include <Adafruit_GFX.h>
32#include <avr/pgmspace.h>
33
34#define ILI9341_TFTWIDTH 240
35#define ILI9341_TFTHEIGHT 320
36
37// Color definitions
38
39#define RGBto565(r,g,b) ((((r) & 0xF8) << 8) | (((g) & 0xFC) << 3) | ((b) >> 3))
40#define RGBIto565(r,g,b,i) ((((((r)*(i))/255) & 0xF8) << 8) | ((((g)*(i)/255) & 0xFC) << 3) | ((((b)*(i)/255) & 0xFC) >> 3))
41
42#define BLACK 0x0000
43#define BLUE 0x001F
44#define RED 0xF800
45#define GREEN 0x07E0
46#define CYAN 0x07FF
47#define MAGENTA 0xF81F
48#define YELLOW 0xFFE0
49#define WHITE 0xFFFF
50
51#define GREY RGBto565(128,128,128)
52#define LGREY RGBto565(160,160,160)
53#define DGREY RGBto565( 80, 80, 80)
54
55#define LBLUE RGBto565(100,100,255)
56#define DBLUE RGBto565( 0, 0,128)
57
58class ILI9341 : public Adafruit_GFX {
59
60 public:
61 ILI9341(int8_t DC, int8_t RST, int8_t CS = -1);
62
63 void init();
64 void begin() { init(); }
65 void setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
66 void pushColor(uint16_t color);
67 void fillScreen(uint16_t color=BLACK);
68 void clearScreen() { fillScreen(BLACK); }
69 void drawPixel(int16_t x, int16_t y, uint16_t color);
70 void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
71 void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
72 void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
73 void drawImage(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t *img);
74 void drawImageF(int16_t x, int16_t y, int16_t w, int16_t h, const uint16_t *img16);
75 void drawImageF(int16_t x, int16_t y, const uint16_t *img16) { drawImageF(x,y,pgm_read_word(img16),pgm_read_word(img16+1),img16+3); }
76 void setRotation(uint8_t r);
77 void invertDisplay(boolean mode);
78 void partialDisplay(boolean mode);
79 void sleepDisplay(boolean mode);
80 void enableDisplay(boolean mode);
81 void idleDisplay(boolean mode);
82 void resetDisplay();
83 void setScrollArea(uint16_t tfa, uint16_t bfa);
84 void setScroll(uint16_t vsp);
85 void setPartArea(uint16_t sr, uint16_t er);
86
87 uint16_t Color565(uint8_t r, uint8_t g, uint8_t b);
88 uint16_t color565(uint8_t r, uint8_t g, uint8_t b) { return Color565(r, g, b); }
89 void rgbWheel(int idx, uint8_t *_r, uint8_t *_g, uint8_t *_b);
90 uint16_t rgbWheel(int idx);
91
92 protected:
93 void displayInit(const uint8_t *addr);
94 void writeSPI(uint8_t);
95 void writeMulti(uint16_t color, uint16_t num);
96 void writeCmd(uint8_t c);
97 void writeData(uint8_t d8);
98 void writeData16(uint16_t d16);
99 void copyMulti(uint8_t *img, uint16_t num);
100
101 private:
102 int8_t csPin, dcPin, rstPin;
103 uint8_t csMask, dcMask;
104 volatile uint8_t *csPort, *dcPort;
105
106};
107
108#endif