COSA
An Object-Oriented Platform for Arduino Programming
ST7735.cpp
Go to the documentation of this file.
1 
21 #include "ST7735.hh"
22 
23 const uint8_t ST7735::s_script[] __PROGMEM = {
24  // Software Reset
25  SWRESET, 0,
26  // Software Delay
27  SWDELAY, 150,
28  // Out of Sleep Mode
29  SLPOUT, 0,
30  // Software Delay
31  SWDELAY, 250,
32  // Software Delay
33  SWDELAY, 250,
34  // Frame Rate Control 1, normal mode
35  FRMCTR1, 3, 0x01, 0x2C, 0x2D,
36  // Frame Rate Control 2, idle mode
37  FRMCTR2, 3, 0x01, 0x2C, 0x2D,
38  // Frame Rate Control 2, idle mode
39  FRMCTR3, 6, 0x01, 0x2C, 0x2D, 0x01, 0x2C, 0x2D,
40  // Display Inversion Control
41  INVCTR, 1, 0x07,
42  // Power Control 1
43  // -4.6V, auto mode
44  PWCTRL1, 3, 0xA2, 0x02, 0x84,
45  // Power Control 2
46  // VGH25 = 2.4C, VGH25 = 2.4C VGSEL = -10 VGH = 3 * AVDD
47  PWCTRL2, 1, 0xC5,
48  // Power Control 3
49  // Opamp current small, Boost frequency
50  PWCTRL3, 2, 0x0A, 0x00,
51  // Power Control 4
52  // BCLK/2, Opamp current small & medium low
53  PWCTRL4, 2, 0x8A, 0x2A,
54  // Power Control 5
55  PWCTRL5, 2, 0x8A, 0xEE,
56  // EEPROM Control 1
57  VMCTRL1, 1, 0x0E,
58  // Invert Display Off
59  DINVOFF, 0,
60  // Memory Access Control
61  // row address/col address, bottom to top refresh
62  MADCTL, 1, 0xC0,
63  // Set Color Mode, 16-bit color
64  COLMOD, 1, 0x05,
65  // Set Column Address
66  // XSTART = 0, XEND = WIDTH - 1
67  CASET, 4, 0x00, 0x00, 0x00, SCREEN_WIDTH - 1,
68  // Set Row Address
69  // YSTART = 0, XEND = HEIGHT - 1
70  RASET, 4, 0x00, 0x00, 0x00, SCREEN_HEIGHT - 1,
71  // Positive Gamma Correction
72  GMCTRP1, 16,
73  0x02, 0x1c, 0x07, 0x12, 0x37, 0x32, 0x29, 0x2d,
74  0x29, 0x25, 0x2B, 0x39, 0x00, 0x01, 0x03, 0x10,
75  // Negative Gamma Correction
76  GMCTRN1, 16,
77  0x03, 0x1d, 0x07, 0x06, 0x2E, 0x2C, 0x29, 0x2D,
78  0x2E, 0x2E, 0x37, 0x3F, 0x00, 0x00, 0x02, 0x10,
79  // Normal Display On
80  NORON, 0,
81  // Software Delay
82  SWDELAY, 10,
83  // Display On
84  DISPON, 0,
85  // Software Delay
86  SWDELAY, 120,
87  // END OF SCRIPT
88  SCRIPTEND
89 };
90 
92  GDDRAM(SCREEN_WIDTH, SCREEN_HEIGHT, cs, dc)
93 {
94 }
95 
96 uint8_t
97 ST7735::set_orientation(uint8_t direction)
98 {
99  uint8_t previous = m_direction;
100  uint8_t setting = 0;
101  m_direction = direction;
102  uint16_t width = WIDTH;
103  WIDTH = HEIGHT;
104  HEIGHT = width;
105  if (direction == LANDSCAPE) {
106  setting = (MADCTL_MX | MADCTL_MV);
107  }
108  else {
109  setting = (MADCTL_MX | MADCTL_MY);
110  }
111  spi.acquire(this);
112  spi.begin();
113  write(MADCTL, setting);
114  spi.end();
115  spi.release();
116  return (previous);
117 }
void acquire(Driver *dev)
Definition: SOFT_SPI.cpp:43
static const uint8_t s_script[]
Definition: ST7735.hh:98
Definition: GDDRAM.hh:31
ST7735(Board::DigitalPin cs=Board::D10, Board::DigitalPin dc=Board::D9)
Definition: ST7735.cpp:91
void begin()
Definition: SPI.hh:216
void end()
Definition: SPI.hh:226
const uint8_t ST7735::s_script[] __PROGMEM
Definition: ST7735.cpp:23
SPI spi
Definition: SPI.cpp:29
uint16_t HEIGHT
Definition: Canvas.hh:370
void release()
Definition: SOFT_SPI.cpp:64
void write(uint16_t data)
Definition: GDDRAM.hh:241
uint16_t WIDTH
Definition: Canvas.hh:369
virtual uint8_t set_orientation(uint8_t direction)
Definition: ST7735.cpp:97
uint8_t m_direction
Definition: Canvas.hh:1015