COSA
An Object-Oriented Platform for Arduino Programming
ILI9163.cpp
Go to the documentation of this file.
1 
21 #include "ILI9163.hh"
22 
23 const uint8_t ILI9163::s_script[] __PROGMEM = {
24  // Software Reset
25  SWRESET, 0,
26  // Out of Sleep Mode
27  SLPOUT, 0,
28  SWDELAY, 120,
29  // Set Color Mode, 16-bit color
30  COLMOD, 1, 0x05,
31  // Gamma set
32  GAMSET, 1, 0x04,
33  // Enable Gamma adjustment
34  EN3GAM, 1, 0x01,
35  // Display Normal Mode
36  NORON, 0,
37  // Display functions
38  DISCTRL, 2, 0xff, 0x06,
39  // Positive Gamma Correction
40  GMCTRP1, 15,
41  0x36, 0x29, 0x12, 0x22, 0x1C,
42  0x15, 0x42, 0xB7, 0x2F, 0x13,
43  0x12, 0x0A, 0x11, 0x0B, 0x06,
44  // Negative Gamma Correction
45  GMCTRN1, 15,
46  0x09, 0x16, 0x2D, 0x0D, 0x13,
47  0x15, 0x40, 0x48, 0x53, 0x0C,
48  0x1D, 0x25, 0x2E, 0x34, 0x39,
49  // Frame Rate Control 1, normal mode
50  FRMCTR1, 2, 0x08, 0x02,
51  // Display Inversion Control
52  INVCTR, 1, 0x07,
53  // Power Control 1
54  PWCTRL1, 2, 0x0A, 0x02,
55  // Power Control 2
56  PWCTRL2, 1, 0x02,
57  // VCOM Control 1
58  VMCTRL1, 2, 0x50, 0x63,
59  // VCOM Control 2
60  VMCTRL2, 1, 0,
61  // Set Column Address
62  // XSTART = 0, XEND = WIDTH - 1
63  CASET, 4, 0x00, 0x00, 0x00, SCREEN_WIDTH - 1,
64  // Set Row Address
65  // YSTART = 0, XEND = HEIGHT - 1
66  RASET, 4, 0x00, 0x00, 0x00, SCREEN_HEIGHT - 1,
67  // Memory Access Control
68  // row address/col address, bottom to top refresh
69  MADCTL, 1, MADCTL_MX | MADCTL_MY | MADCTL_BGR,
70  // Display On
71  DISPON, 0,
72  // Software Delay
73  SWDELAY, 1,
74  // END OF SCRIPT
75  SCRIPTEND
76 };
77 
79  GDDRAM(SCREEN_WIDTH, SCREEN_HEIGHT, cs, dc)
80 {
81 }
82 
83 uint8_t
84 ILI9163::set_orientation(uint8_t direction)
85 {
86  uint8_t previous = m_direction;
87  uint8_t setting = 0;
88  m_direction = direction;
89  uint16_t width = WIDTH;
90  WIDTH = HEIGHT;
91  HEIGHT = width;
92  if (direction == LANDSCAPE) {
93  setting = MADCTL_MY | MADCTL_MV | MADCTL_BGR;
94  }
95  else {
96  setting = MADCTL_MX | MADCTL_MY | MADCTL_BGR;
97  }
98  spi.acquire(this);
99  spi.begin();
100  write(MADCTL, setting);
101  spi.end();
102  spi.release();
103  return (previous);
104 }
void acquire(Driver *dev)
Definition: SOFT_SPI.cpp:43
Definition: GDDRAM.hh:31
ILI9163(Board::DigitalPin cs=Board::D10, Board::DigitalPin dc=Board::D9)
Definition: ILI9163.cpp:78
void begin()
Definition: SPI.hh:216
void end()
Definition: SPI.hh:226
virtual uint8_t set_orientation(uint8_t direction)
Definition: ILI9163.cpp:84
const uint8_t ILI9163::s_script[] __PROGMEM
Definition: ILI9163.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
uint8_t m_direction
Definition: Canvas.hh:1015
static const uint8_t s_script[]
Definition: ILI9163.hh:101