Kaynağa Gözat

st7735: Added text feature and documentation with license

Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
Kiveisha Yevgeniy 10 yıl önce
ebeveyn
işleme
8fe679494c
6 değiştirilmiş dosya ile 617 ekleme ve 162 silme
  1. 22
    7
      examples/st7735.cxx
  2. 91
    12
      src/st7735/gfx.cxx
  3. 128
    28
      src/st7735/gfx.h
  4. 24
    0
      src/st7735/license.txt
  5. 34
    70
      src/st7735/st7735.cxx
  6. 318
    45
      src/st7735/st7735.h

+ 22
- 7
examples/st7735.cxx Dosyayı Görüntüle

@@ -35,27 +35,42 @@ main(int argc, char **argv)
35 35
     upm::ST7735 * lcd = new upm::ST7735(7, 4, 9, 8);
36 36
     lcd->fillScreen (ST7735_RED);
37 37
     lcd->refresh ();
38
-    
38
+
39 39
     lcd->fillScreen (ST7735_CYAN);
40 40
     lcd->refresh ();
41
-    
41
+
42 42
     lcd->fillScreen (ST7735_BLACK);
43 43
     lcd->refresh ();
44
-    
44
+
45 45
     lcd->drawLine(10, 10, 10, 100, ST7735_MAGENTA);
46 46
     lcd->drawLine(20, 20, 10, 100, ST7735_YELLOW);
47 47
     lcd->drawLine(30, 30, 50, 100, ST7735_WHITE);
48 48
     lcd->refresh ();
49
-    
49
+
50 50
     lcd->drawPixel (20, 20, ST7735_GREEN);
51 51
     lcd->refresh ();
52
-    
52
+
53 53
     lcd->drawTriangle (50, 50, 80, 80, 60, 90, ST7735_GREEN);
54 54
     lcd->refresh ();
55
-    
55
+
56 56
     lcd->drawCircle (100, 110, 10, ST7735_BLUE);
57 57
     lcd->refresh ();
58
-    
58
+
59
+
60
+    lcd->setTextWrap(0x0);
61
+
62
+    lcd->setCursor(0, 30);
63
+    lcd->setTextColor(ST7735_RED, ST7735_RED);
64
+    lcd->setTextSize(1);
65
+    lcd->print("Hello World!");
66
+
67
+    lcd->setCursor(10, 50);
68
+    lcd->setTextColor(ST7735_RED, ST7735_YELLOW);
69
+    lcd->setTextSize(2);
70
+    lcd->print("BIG");
71
+
72
+    lcd->refresh ();
73
+
59 74
     std::cout << "exiting application" << std::endl;
60 75
 
61 76
     delete lcd;

+ 91
- 12
src/st7735/gfx.cxx Dosyayı Görüntüle

@@ -30,48 +30,50 @@
30 30
 
31 31
 using namespace upm;
32 32
 
33
-GFX::GFX (int width, int height) {
33
+GFX::GFX (int width, int height, uint8_t * screenBuffer, const unsigned char * font) : WIDTH(width), HEIGHT(height) {
34 34
     m_height = height;
35 35
     m_width  = width;
36
+    m_font   = font;
37
+    m_map    = screenBuffer;
36 38
 }
37 39
 
38 40
 GFX::~GFX () {
39 41
 }
40 42
 
41
-maa_result_t 
43
+maa_result_t
42 44
 GFX::setPixel (int x, int y, uint16_t color) {
43 45
     if((x < 0) ||(x >= m_width) || (y < 0) || (y >= m_height)) {
44 46
         return MAA_ERROR_UNSPECIFIED;
45 47
     }
46
-    
48
+
47 49
     int index = ((y * m_width) + x) * sizeof(uint16_t);
48 50
     m_map[index] = (uint8_t) (color >> 8);
49 51
     m_map[++index] = (uint8_t)(color);
50
-    
52
+
51 53
     return MAA_SUCCESS;
52 54
 }
53 55
 
54
-void 
56
+void
55 57
 GFX::fillScreen (uint16_t color) {
56 58
     fillRect(0, 0, m_width, m_height, color);
57 59
 }
58 60
 
59
-void 
61
+void
60 62
 GFX::fillRect (int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) {
61 63
     for (int16_t i=x; i<x+w; i++) {
62 64
         drawFastVLine(i, y, h, color);
63 65
     }
64 66
 }
65 67
 
66
-void 
68
+void
67 69
 GFX::drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) {
68 70
     drawLine(x, y, x, y+h-1, color);
69 71
 }
70 72
 
71
-void 
73
+void
72 74
 GFX::drawLine (int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color) {
73 75
     int16_t steep = abs(y1 - y0) > abs(x1 - x0);
74
-    
76
+
75 77
     if (steep) {
76 78
         swap(x0, y0);
77 79
         swap(x1, y1);
@@ -109,14 +111,14 @@ GFX::drawLine (int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color) {
109 111
     }
110 112
 }
111 113
 
112
-void 
114
+void
113 115
 GFX::drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color) {
114 116
     drawLine(x0, y0, x1, y1, color);
115 117
     drawLine(x1, y1, x2, y2, color);
116 118
     drawLine(x2, y2, x0, y0, color);
117 119
 }
118 120
 
119
-void 
121
+void
120 122
 GFX::drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color) {
121 123
     int16_t f = 1 - r;
122 124
     int16_t ddF_x = 1;
@@ -136,7 +138,7 @@ GFX::drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color) {
136 138
             f += ddF_y;
137 139
         }
138 140
         x++;
139
-        
141
+
140 142
         ddF_x += 2;
141 143
         f += ddF_x;
142 144
 
@@ -150,3 +152,80 @@ GFX::drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color) {
150 152
         setPixel(x0 - y, y0 - x, color);
151 153
     }
152 154
 }
155
+
156
+void
157
+GFX::setCursor (int16_t x, int16_t y) {
158
+    m_cursorX = x;
159
+    m_cursorY = y;
160
+}
161
+
162
+void
163
+GFX::setTextColor (uint16_t textColor, uint16_t textBGColor) {
164
+    m_textColor   = textColor;
165
+    m_textBGColor = textBGColor;
166
+}
167
+
168
+void
169
+GFX::setTextSize (uint8_t size) {
170
+    m_textSize = (size > 0) ? size : 1;
171
+}
172
+
173
+void
174
+GFX::setTextWrap (uint8_t wrap) {
175
+    m_wrap = wrap;
176
+}
177
+
178
+void
179
+GFX::drawChar (int16_t x, int16_t y, uint8_t data, uint16_t color, uint16_t bg, uint8_t size) {
180
+    if( (x >= m_width)            || // Clip right
181
+        (y >= m_height)           || // Clip bottom
182
+        ((x + 6 * size - 1) < 0)  || // Clip left
183
+        ((y + 8 * size - 1) < 0))    // Clip top
184
+    return;
185
+
186
+    for (int8_t i=0; i<6; i++ ) {
187
+        uint8_t line;
188
+        if (i == 5) {
189
+            line = 0x0;
190
+        } else {
191
+            line = *(m_font+(data * 5)+i);
192
+            for (int8_t j = 0; j<8; j++) {
193
+                if (line & 0x1) {
194
+                    if (size == 1) // default size
195
+                        setPixel (x+i, y+j, color);
196
+                    else {  // big size
197
+                        fillRect (x+(i*size), y+(j*size), size, size, color);
198
+                    }
199
+                } else if (bg != color) {
200
+                    if (size == 1) // default size
201
+                        setPixel (x+i, y+j, bg);
202
+                    else {  // big size
203
+                        fillRect (x+i*size, y+j*size, size, size, bg);
204
+                    }
205
+                }
206
+                line >>= 1;
207
+            }
208
+        }
209
+    }
210
+}
211
+
212
+void
213
+GFX::print (std::string msg) {
214
+    int len = msg.length();
215
+
216
+    for (int idx = 0; idx < len; idx++) {
217
+        if (msg[idx] == '\n') {
218
+            m_cursorY += m_textSize * 8;
219
+            m_cursorX  = 0;
220
+        } else if (msg[idx] == '\r') {
221
+            // skip em
222
+        } else {
223
+            drawChar(m_cursorX, m_cursorY, msg[idx], m_textColor, m_textBGColor, m_textSize);
224
+            m_cursorX += m_textSize * 6;
225
+            if (m_wrap && (m_textColor > (m_width - m_textSize * 6))) {
226
+                m_cursorY += m_textSize * 8;
227
+                m_cursorX = 0;
228
+            }
229
+        }
230
+    }
231
+}

+ 128
- 28
src/st7735/gfx.h Dosyayı Görüntüle

@@ -32,7 +32,7 @@
32 32
 #define swap(a, b) { int16_t t = a; a = b; b = t; }
33 33
 
34 34
 namespace upm {
35
-    
35
+
36 36
 /**
37 37
  * @brief GFX helper class
38 38
  *
@@ -43,10 +43,12 @@ class GFX {
43 43
         /**
44 44
          * Instanciates a GFX object
45 45
          *
46
-         * @param width 
47
-         * @param height
46
+         * @param width screen width
47
+         * @param height screen height
48
+         * @param screenBuffer pointer to screen buffer
49
+         * @param font pointer to font map
48 50
          */
49
-        GFX (int width, int height);
51
+        GFX (int width, int height, uint8_t * screenBuffer, const unsigned char * font);
50 52
 
51 53
         /**
52 54
          * GFX object destructor
@@ -62,55 +64,153 @@ class GFX {
62 64
          * @param y1 second coordinate
63 65
          */
64 66
         virtual void setAddrWindow (uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1) = 0;
65
-        
67
+
66 68
         /**
67
-         * 
69
+         * Send pixel collor (RGB) to the chip. Must be implemented by
70
+         * inherited class.
71
+         *
72
+         * @param x axis on horizontal scale
73
+         * @param y axis on vertical scale
74
+         * @param color rgb value
68 75
          */
69 76
         virtual void drawPixel (int16_t x, int16_t y, uint16_t color) = 0;
70
-        
77
+
71 78
         /**
72
-         * 
79
+         * Copy the buffer to the chip via SPI interface.
73 80
          */
74 81
         virtual void refresh () = 0;
75
-        
82
+
83
+        /**
84
+         *
85
+         *
86
+         * @param x axis on horizontal scale
87
+         * @param y axis on vertical scale
88
+         * @param data character to write
89
+         * @param color character's color
90
+         * @param bg character's background color
91
+         * @param size size of the font
92
+         */
93
+        void drawChar (int16_t x, int16_t y, uint8_t data, uint16_t color, uint16_t bg, uint8_t size);
94
+
76 95
         /**
77
-         * 
96
+         * Print the message to the screen
97
+         *
98
+         * @param msg message which will be printed
99
+         */
100
+        void print (std::string msg);
101
+
102
+        /**
103
+         * Print the message to the screen
104
+         *
105
+         * @param x axis on horizontal scale
106
+         * @param y axis on vertical scale
107
+         * @param color pixel's color
78 108
          */
79 109
         maa_result_t setPixel (int x, int y, uint16_t color);
80
-        
110
+
81 111
         /**
82
-         * 
112
+         * Fill screen with selected color
113
+         *
114
+         * @param color selected's color
83 115
          */
84 116
         void fillScreen (uint16_t color);
85
-        
117
+
86 118
         /**
87
-         * 
119
+         * Fill rectangle with selected color
120
+         *
121
+         * @param x axis on horizontal scale (top left corner)
122
+         * @param y axis on vertical scale (top left corner)
123
+         * @param w distanse from x
124
+         * @param h distanse from y
125
+         * @param color selected color
88 126
          */
89 127
         void fillRect (int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
90
-        
128
+
91 129
         /**
92
-         * 
130
+         * Draw line in vertical scale.
131
+         *
132
+         * @param x axis on horizontal scale
133
+         * @param y axis on vertical scale
134
+         * @param h distanse from y
135
+         * @param color selected color
93 136
          */
94 137
         void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
95
-        
138
+
96 139
         /**
97
-         * 
140
+         * Draw line from coordinate C0 to coordinate C1
141
+         *
142
+         * @param x0 first coordinate
143
+         * @param y0 first coordinate
144
+         * @param x1 second coordinate
145
+         * @param y1 second coordinate
146
+         * @param color selected color
98 147
          */
99 148
         void drawLine (int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
100
-        
149
+
101 150
         /**
102
-         * 
151
+         * Draw a triangle
152
+         *
153
+         * @param x0 first coordinate
154
+         * @param y0 first coordinate
155
+         * @param x1 second coordinate
156
+         * @param y1 second coordinate
157
+         * @param x2 third coordinate
158
+         * @param y2 third coordinate
159
+         * @param color selected color
103 160
          */
104 161
         void drawTriangle (int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
105
-        
162
+
106 163
         /**
107
-         * 
164
+         * Draw a circle
165
+         *
166
+         * @param x center of circule on X scale
167
+         * @param y center of circule on Y scale
108 168
          */
109
-        void drawCircle (int16_t x0, int16_t y0, int16_t r, uint16_t color);
110
-        
111
-        int m_height;
112
-        int m_width;
113
-        
114
-        uint8_t m_map[160 * 128 * 2];
169
+        void drawCircle (int16_t x, int16_t y, int16_t r, uint16_t color);
170
+
171
+        /**
172
+         * Set cursor for text message
173
+         *
174
+         * @param x axis on horizontal scale
175
+         * @param y axis on vertical scale
176
+         */
177
+        void setCursor (int16_t x, int16_t y);
178
+
179
+        /**
180
+         * Set text color for the message
181
+         *
182
+         * @param textColor font color
183
+         * @param textBGColor background color
184
+         */
185
+        void setTextColor (uint16_t textColor, uint16_t textBGColor);
186
+
187
+        /**
188
+         * Set the size of the font
189
+         *
190
+         * @param size font size
191
+         */
192
+        void setTextSize (uint8_t size);
193
+
194
+        /**
195
+         * Wrap printed message.
196
+         *
197
+         * @param wrap true (0x1) or false (0x0)
198
+         */
199
+        void setTextWrap (uint8_t wrap);
200
+
201
+        int m_height; /**< Screen height */
202
+        int m_width; /**< Screen width */
203
+        int m_textSize; /**< Printed text size */
204
+        int m_textColor; /**< Printed text color */
205
+        int m_textBGColor; /**< Printed text background color */
206
+        int m_cursorX; /**< Cursor X coordinate */
207
+        int m_cursorY; /**< Cursor Y coordinate */
208
+        int m_wrap; /**< Wrapper flag (true or false) */
209
+
210
+        uint8_t * m_map; /**< Screens buffer */
211
+
212
+    protected:
213
+        const int16_t   WIDTH, HEIGHT;
214
+        const unsigned char * m_font;
115 215
     };
116 216
 }

+ 24
- 0
src/st7735/license.txt Dosyayı Görüntüle

@@ -0,0 +1,24 @@
1
+Software License Agreement (BSD License)
2
+
3
+Copyright (c) 2012 Adafruit Industries.  All rights reserved.
4
+
5
+Redistribution and use in source and binary forms, with or without
6
+modification, are permitted provided that the following conditions are met:
7
+
8
+- Redistributions of source code must retain the above copyright notice,
9
+  this list of conditions and the following disclaimer.
10
+- Redistributions in binary form must reproduce the above copyright notice,
11
+  this list of conditions and the following disclaimer in the documentation
12
+  and/or other materials provided with the distribution.
13
+
14
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24
+POSSIBILITY OF SUCH DAMAGE.

+ 34
- 70
src/st7735/st7735.cxx Dosyayı Görüntüle

@@ -32,14 +32,14 @@
32 32
 
33 33
 using namespace upm;
34 34
 
35
-ST7735::ST7735 (uint8_t csLCD, uint8_t cSD, uint8_t rs, uint8_t rst) : GFX (160, 128) {
35
+ST7735::ST7735 (uint8_t csLCD, uint8_t cSD, uint8_t rs, uint8_t rst) : GFX (160, 128, m_map, font) {
36 36
     maa_init();
37
-    
37
+
38 38
     m_csLCD = csLCD;
39 39
     m_cSD   = cSD;
40 40
     m_rST   = rst;
41 41
     m_rS    = rs;
42
-    
42
+
43 43
     initModule ();
44 44
     configModule ();
45 45
 }
@@ -71,7 +71,7 @@ ST7735::~ST7735 () {
71 71
 void
72 72
 ST7735::initModule () {
73 73
     maa_result_t error = MAA_SUCCESS;
74
-    
74
+
75 75
     m_height = 160;
76 76
     m_width  = 128;
77 77
 
@@ -86,13 +86,13 @@ ST7735::initModule () {
86 86
         fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_cSD);
87 87
         exit (1);
88 88
     }
89
-    
89
+
90 90
     m_rSTPinCtx = maa_gpio_init (m_rST);
91 91
     if (m_rSTPinCtx == NULL) {
92 92
         fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_rST);
93 93
         exit (1);
94 94
     }
95
-    
95
+
96 96
     m_rSPinCtx = maa_gpio_init (m_rS);
97 97
     if (m_rSPinCtx == NULL) {
98 98
         fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_rS);
@@ -108,12 +108,12 @@ ST7735::initModule () {
108 108
     if (error != MAA_SUCCESS) {
109 109
         maa_result_print (error);
110 110
     }
111
-    
111
+
112 112
     error = maa_gpio_dir (m_rSTPinCtx, MAA_GPIO_OUT);
113 113
     if (error != MAA_SUCCESS) {
114 114
         maa_result_print (error);
115 115
     }
116
-    
116
+
117 117
     error = maa_gpio_dir (m_rSPinCtx, MAA_GPIO_OUT);
118 118
     if (error != MAA_SUCCESS) {
119 119
         maa_result_print (error);
@@ -124,7 +124,7 @@ ST7735::initModule () {
124 124
     if (error != MAA_SUCCESS) {
125 125
         maa_result_print (error);
126 126
     }
127
-    
127
+
128 128
     lcdCSOn ();
129 129
 }
130 130
 
@@ -140,7 +140,7 @@ ST7735::data (uint8_t value) {
140 140
     maa_spi_write (m_spi, value);
141 141
 }
142 142
 
143
-void 
143
+void
144 144
 ST7735::executeCMDList(const uint8_t *addr) {
145 145
     uint8_t  numCommands, numArgs;
146 146
     uint16_t ms;
@@ -165,45 +165,45 @@ ST7735::executeCMDList(const uint8_t *addr) {
165 165
     }
166 166
 }
167 167
 
168
-void 
168
+void
169 169
 ST7735::setAddrWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1) {
170 170
     uint8_t colstart, rowstart;
171 171
     colstart  = rowstart = 0;
172 172
 
173 173
     write (ST7735_CASET);                       // Column addr set
174
-    
174
+
175 175
     rsHIGH ();
176
-    m_spiBuffer[0] = 0x00;              
176
+    m_spiBuffer[0] = 0x00;
177 177
     m_spiBuffer[1] = x0 + colstart;             // XSTART
178 178
     m_spiBuffer[2] = 0x00;
179 179
     m_spiBuffer[3] = x1 + colstart;             // XEND
180 180
     maa_spi_write_buf(m_spi, m_spiBuffer, 4);
181
-    
181
+
182 182
     write (ST7735_RASET);                       // Row addr set
183
-    
183
+
184 184
     rsHIGH ();
185
-    m_spiBuffer[0] = 0x00;              
185
+    m_spiBuffer[0] = 0x00;
186 186
     m_spiBuffer[1] = y0 + rowstart;             // YSTART
187 187
     m_spiBuffer[2] = 0x00;
188 188
     m_spiBuffer[3] = y1 + rowstart;             // YEND
189 189
     maa_spi_write_buf(m_spi, m_spiBuffer, 4);
190
-    
190
+
191 191
     write (ST7735_RAMWR);                       // write to RAM
192 192
 }
193 193
 
194
-void 
194
+void
195 195
 ST7735::drawPixel(int16_t x, int16_t y, uint16_t color) {
196 196
     if (MAA_SUCCESS != setPixel (x, y, color)) {
197 197
         return;
198 198
     }
199
-    
199
+
200 200
     refresh ();
201 201
 }
202 202
 
203
-void 
203
+void
204 204
 ST7735::refresh () {
205 205
     rsHIGH ();
206
-    
206
+
207 207
     int fragmentSize = m_height * m_width * 2 / 20;
208 208
     for (int fragment = 0; fragment < 20; fragment++) {
209 209
         maa_spi_write_buf(m_spi, &m_map[fragment * fragmentSize], fragmentSize);
@@ -215,72 +215,36 @@ ST7735::configModule() {
215 215
     rsHIGH ();
216 216
     lcdCSOff ();
217 217
     lcdCSOn ();
218
-    
218
+
219 219
     maa_gpio_write (m_rSTPinCtx, HIGH);
220 220
     usleep (500000);
221 221
     maa_gpio_write (m_rSTPinCtx, LOW);
222 222
     usleep (500000);
223 223
     maa_gpio_write (m_rSTPinCtx, HIGH);
224 224
     usleep (500000);
225
-    
225
+
226 226
     executeCMDList (Rcmd1);
227 227
     executeCMDList (Rcmd2red);
228 228
     executeCMDList (Rcmd3);
229
-    
229
+
230 230
     write (ST7735_MADCTL);
231 231
     data (0xC0);
232
-        
232
+
233 233
     setAddrWindow (0, 0, m_width - 1, m_height - 1);
234
-    
234
+
235 235
     fillScreen (ST7735_BLACK);
236 236
     refresh ();
237 237
 }
238 238
 
239
-void 
240
-ST7735::fill (int col, uint16_t* buff, int len) {
241
-    uint8_t colstart, rowstart;
242
-    uint8_t buf[len * 2];
243
-    
244
-    colstart = 0;
245
-
246
-    write (ST7735_CASET);                       // Column addr set
247
-    
248
-    rsHIGH ();
249
-    m_spiBuffer[0] = 0x00;              
250
-    m_spiBuffer[1] = col + 1;             // XSTART
251
-    m_spiBuffer[2] = 0x00;
252
-    m_spiBuffer[3] = col + 1;             // XEND
253
-    maa_spi_write_buf(m_spi, m_spiBuffer, 4);
254
-    
255
-    write (ST7735_RASET);                       // Row addr set
256
-    
257
-    rsHIGH ();
258
-    m_spiBuffer[0] = 0x00;              
259
-    m_spiBuffer[1] = 0x01;             // YSTART
260
-    m_spiBuffer[2] = 0x00;
261
-    m_spiBuffer[3] = 0x9F;             // YEND
262
-    maa_spi_write_buf(m_spi, m_spiBuffer, 4);
263
-    
264
-    write (ST7735_RAMWR);                       // write to RAM
265
-    
266
-    /*for (int idx = 0; idx < len; idx++) {
267
-        buf[idx*2] = buff[idx] >> 8;
268
-        buf[(idx*2)+1] = buff[idx];
269
-    }*/
270
-    
271
-    rsHIGH ();
272
-    maa_spi_write_buf(m_spi, (uint8_t *)buff, len * 2);
273
-}
274
-
275 239
 maa_result_t
276 240
 ST7735::lcdCSOn () {
277 241
     maa_result_t error = MAA_SUCCESS;
278
-    
242
+
279 243
     error = maa_gpio_write (m_csLCDPinCtx, LOW);
280 244
     if (error != MAA_SUCCESS) {
281 245
         maa_result_print (error);
282 246
     }
283
-    
247
+
284 248
     error = maa_gpio_write (m_cSDPinCtx, HIGH);
285 249
     if (error != MAA_SUCCESS) {
286 250
         maa_result_print (error);
@@ -292,7 +256,7 @@ ST7735::lcdCSOn () {
292 256
 maa_result_t
293 257
 ST7735::lcdCSOff () {
294 258
     maa_result_t error = MAA_SUCCESS;
295
-    
259
+
296 260
     error = maa_gpio_write (m_csLCDPinCtx, HIGH);
297 261
     if (error != MAA_SUCCESS) {
298 262
         maa_result_print (error);
@@ -304,12 +268,12 @@ ST7735::lcdCSOff () {
304 268
 maa_result_t
305 269
 ST7735::sdCSOn () {
306 270
     maa_result_t error = MAA_SUCCESS;
307
-    
271
+
308 272
     error = maa_gpio_write (m_cSDPinCtx, LOW);
309 273
     if (error != MAA_SUCCESS) {
310 274
         maa_result_print (error);
311 275
     }
312
-    
276
+
313 277
     error = maa_gpio_write (m_csLCDPinCtx, HIGH);
314 278
     if (error != MAA_SUCCESS) {
315 279
         maa_result_print (error);
@@ -321,7 +285,7 @@ ST7735::sdCSOn () {
321 285
 maa_result_t
322 286
 ST7735::sdCSOff () {
323 287
     maa_result_t error = MAA_SUCCESS;
324
-    
288
+
325 289
     error = maa_gpio_write (m_cSDPinCtx, HIGH);
326 290
     if (error != MAA_SUCCESS) {
327 291
         maa_result_print (error);
@@ -333,7 +297,7 @@ ST7735::sdCSOff () {
333 297
 maa_result_t
334 298
 ST7735::rsHIGH () {
335 299
     maa_result_t error = MAA_SUCCESS;
336
-    
300
+
337 301
     error = maa_gpio_write (m_rSPinCtx, HIGH);
338 302
     if (error != MAA_SUCCESS) {
339 303
         maa_result_print (error);
@@ -345,7 +309,7 @@ ST7735::rsHIGH () {
345 309
 maa_result_t
346 310
 ST7735::rsLOW () {
347 311
     maa_result_t error = MAA_SUCCESS;
348
-    
312
+
349 313
     error = maa_gpio_write (m_rSPinCtx, LOW);
350 314
     if (error != MAA_SUCCESS) {
351 315
         maa_result_print (error);

+ 318
- 45
src/st7735/st7735.h Dosyayı Görüntüle

@@ -2,10 +2,9 @@
2 2
  * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3 3
  * Copyright (c) 2014 Intel Corporation.
4 4
  *
5
- * Credits to Adafrut.com
6
- * {Based on,Inspired from} original <libname> from <author>. See original license in <filepath>.
7
-
8
- * 
5
+ * Credits to Adafruit.
6
+ * Based on Adafruit ST7735 library, see original license in license.txt file.
7
+ *
9 8
  * Permission is hereby granted, free of charge, to any person obtaining
10 9
  * a copy of this software and associated documentation files (the
11 10
  * "Software"), to deal in the Software without restriction, including
@@ -87,13 +86,13 @@
87 86
 #define ST7735_GMCTRN1      0xE1
88 87
 
89 88
 // Color definitions
90
-#define	ST7735_BLACK        0x0000
91
-#define	ST7735_BLUE         0x001F
92
-#define	ST7735_RED          0xF800
93
-#define	ST7735_GREEN        0x07E0
89
+#define ST7735_BLACK        0x0000
90
+#define ST7735_BLUE         0x001F
91
+#define ST7735_RED          0xF800
92
+#define ST7735_GREEN        0x07E0
94 93
 #define ST7735_CYAN         0x07FF
95 94
 #define ST7735_MAGENTA      0xF81F
96
-#define ST7735_YELLOW       0xFFE0  
95
+#define ST7735_YELLOW       0xFFE0
97 96
 #define ST7735_WHITE        0xFFFF
98 97
 
99 98
 #define HIGH                1
@@ -103,7 +102,7 @@
103 102
 
104 103
 namespace upm {
105 104
 
106
-static const uint8_t Bcmd[] = {                  
105
+static const uint8_t Bcmd[] = {
107 106
     // Initialization commands for 7735B screens
108 107
       18,                     // 18 commands in list:
109 108
     ST7735_SWRESET,   DELAY,  //  1: Software reset, no args, w/delay
@@ -189,7 +188,7 @@ static const uint8_t Bcmd[] = {
189 188
       0x00,                   //     Boost frequency
190 189
     ST7735_PWCTR4 , 2      ,  // 10: Power control, 2 args, no delay:
191 190
       0x8A,                   //     BCLK/2, Opamp current small & Medium low
192
-      0x2A,  
191
+      0x2A,
193 192
     ST7735_PWCTR5 , 2      ,  // 11: Power control, 2 args, no delay:
194 193
       0x8A, 0xEE,
195 194
     ST7735_VMCTR1 , 1      ,  // 12: Power control, 1 arg, no delay:
@@ -236,27 +235,285 @@ static const uint8_t Bcmd[] = {
236 235
 
237 236
 #define swap(a, b) { int16_t t = a; a = b; b = t; }
238 237
 
239
-
238
+const unsigned char font[] = {
239
+    0x00, 0x00, 0x00, 0x00, 0x00,
240
+    0x3E, 0x5B, 0x4F, 0x5B, 0x3E,
241
+    0x3E, 0x6B, 0x4F, 0x6B, 0x3E,
242
+    0x1C, 0x3E, 0x7C, 0x3E, 0x1C,
243
+    0x18, 0x3C, 0x7E, 0x3C, 0x18,
244
+    0x1C, 0x57, 0x7D, 0x57, 0x1C,
245
+    0x1C, 0x5E, 0x7F, 0x5E, 0x1C,
246
+    0x00, 0x18, 0x3C, 0x18, 0x00,
247
+    0xFF, 0xE7, 0xC3, 0xE7, 0xFF,
248
+    0x00, 0x18, 0x24, 0x18, 0x00,
249
+    0xFF, 0xE7, 0xDB, 0xE7, 0xFF,
250
+    0x30, 0x48, 0x3A, 0x06, 0x0E,
251
+    0x26, 0x29, 0x79, 0x29, 0x26,
252
+    0x40, 0x7F, 0x05, 0x05, 0x07,
253
+    0x40, 0x7F, 0x05, 0x25, 0x3F,
254
+    0x5A, 0x3C, 0xE7, 0x3C, 0x5A,
255
+    0x7F, 0x3E, 0x1C, 0x1C, 0x08,
256
+    0x08, 0x1C, 0x1C, 0x3E, 0x7F,
257
+    0x14, 0x22, 0x7F, 0x22, 0x14,
258
+    0x5F, 0x5F, 0x00, 0x5F, 0x5F,
259
+    0x06, 0x09, 0x7F, 0x01, 0x7F,
260
+    0x00, 0x66, 0x89, 0x95, 0x6A,
261
+    0x60, 0x60, 0x60, 0x60, 0x60,
262
+    0x94, 0xA2, 0xFF, 0xA2, 0x94,
263
+    0x08, 0x04, 0x7E, 0x04, 0x08,
264
+    0x10, 0x20, 0x7E, 0x20, 0x10,
265
+    0x08, 0x08, 0x2A, 0x1C, 0x08,
266
+    0x08, 0x1C, 0x2A, 0x08, 0x08,
267
+    0x1E, 0x10, 0x10, 0x10, 0x10,
268
+    0x0C, 0x1E, 0x0C, 0x1E, 0x0C,
269
+    0x30, 0x38, 0x3E, 0x38, 0x30,
270
+    0x06, 0x0E, 0x3E, 0x0E, 0x06,
271
+    0x00, 0x00, 0x00, 0x00, 0x00,
272
+    0x00, 0x00, 0x5F, 0x00, 0x00,
273
+    0x00, 0x07, 0x00, 0x07, 0x00,
274
+    0x14, 0x7F, 0x14, 0x7F, 0x14,
275
+    0x24, 0x2A, 0x7F, 0x2A, 0x12,
276
+    0x23, 0x13, 0x08, 0x64, 0x62,
277
+    0x36, 0x49, 0x56, 0x20, 0x50,
278
+    0x00, 0x08, 0x07, 0x03, 0x00,
279
+    0x00, 0x1C, 0x22, 0x41, 0x00,
280
+    0x00, 0x41, 0x22, 0x1C, 0x00,
281
+    0x2A, 0x1C, 0x7F, 0x1C, 0x2A,
282
+    0x08, 0x08, 0x3E, 0x08, 0x08,
283
+    0x00, 0x80, 0x70, 0x30, 0x00,
284
+    0x08, 0x08, 0x08, 0x08, 0x08,
285
+    0x00, 0x00, 0x60, 0x60, 0x00,
286
+    0x20, 0x10, 0x08, 0x04, 0x02,
287
+    0x3E, 0x51, 0x49, 0x45, 0x3E,
288
+    0x00, 0x42, 0x7F, 0x40, 0x00,
289
+    0x72, 0x49, 0x49, 0x49, 0x46,
290
+    0x21, 0x41, 0x49, 0x4D, 0x33,
291
+    0x18, 0x14, 0x12, 0x7F, 0x10,
292
+    0x27, 0x45, 0x45, 0x45, 0x39,
293
+    0x3C, 0x4A, 0x49, 0x49, 0x31,
294
+    0x41, 0x21, 0x11, 0x09, 0x07,
295
+    0x36, 0x49, 0x49, 0x49, 0x36,
296
+    0x46, 0x49, 0x49, 0x29, 0x1E,
297
+    0x00, 0x00, 0x14, 0x00, 0x00,
298
+    0x00, 0x40, 0x34, 0x00, 0x00,
299
+    0x00, 0x08, 0x14, 0x22, 0x41,
300
+    0x14, 0x14, 0x14, 0x14, 0x14,
301
+    0x00, 0x41, 0x22, 0x14, 0x08,
302
+    0x02, 0x01, 0x59, 0x09, 0x06,
303
+    0x3E, 0x41, 0x5D, 0x59, 0x4E,
304
+    0x7C, 0x12, 0x11, 0x12, 0x7C,
305
+    0x7F, 0x49, 0x49, 0x49, 0x36,
306
+    0x3E, 0x41, 0x41, 0x41, 0x22,
307
+    0x7F, 0x41, 0x41, 0x41, 0x3E,
308
+    0x7F, 0x49, 0x49, 0x49, 0x41,
309
+    0x7F, 0x09, 0x09, 0x09, 0x01,
310
+    0x3E, 0x41, 0x41, 0x51, 0x73,
311
+    0x7F, 0x08, 0x08, 0x08, 0x7F,
312
+    0x00, 0x41, 0x7F, 0x41, 0x00,
313
+    0x20, 0x40, 0x41, 0x3F, 0x01,
314
+    0x7F, 0x08, 0x14, 0x22, 0x41,
315
+    0x7F, 0x40, 0x40, 0x40, 0x40,
316
+    0x7F, 0x02, 0x1C, 0x02, 0x7F,
317
+    0x7F, 0x04, 0x08, 0x10, 0x7F,
318
+    0x3E, 0x41, 0x41, 0x41, 0x3E,
319
+    0x7F, 0x09, 0x09, 0x09, 0x06,
320
+    0x3E, 0x41, 0x51, 0x21, 0x5E,
321
+    0x7F, 0x09, 0x19, 0x29, 0x46,
322
+    0x26, 0x49, 0x49, 0x49, 0x32,
323
+    0x03, 0x01, 0x7F, 0x01, 0x03,
324
+    0x3F, 0x40, 0x40, 0x40, 0x3F,
325
+    0x1F, 0x20, 0x40, 0x20, 0x1F,
326
+    0x3F, 0x40, 0x38, 0x40, 0x3F,
327
+    0x63, 0x14, 0x08, 0x14, 0x63,
328
+    0x03, 0x04, 0x78, 0x04, 0x03,
329
+    0x61, 0x59, 0x49, 0x4D, 0x43,
330
+    0x00, 0x7F, 0x41, 0x41, 0x41,
331
+    0x02, 0x04, 0x08, 0x10, 0x20,
332
+    0x00, 0x41, 0x41, 0x41, 0x7F,
333
+    0x04, 0x02, 0x01, 0x02, 0x04,
334
+    0x40, 0x40, 0x40, 0x40, 0x40,
335
+    0x00, 0x03, 0x07, 0x08, 0x00,
336
+    0x20, 0x54, 0x54, 0x78, 0x40,
337
+    0x7F, 0x28, 0x44, 0x44, 0x38,
338
+    0x38, 0x44, 0x44, 0x44, 0x28,
339
+    0x38, 0x44, 0x44, 0x28, 0x7F,
340
+    0x38, 0x54, 0x54, 0x54, 0x18,
341
+    0x00, 0x08, 0x7E, 0x09, 0x02,
342
+    0x18, 0xA4, 0xA4, 0x9C, 0x78,
343
+    0x7F, 0x08, 0x04, 0x04, 0x78,
344
+    0x00, 0x44, 0x7D, 0x40, 0x00,
345
+    0x20, 0x40, 0x40, 0x3D, 0x00,
346
+    0x7F, 0x10, 0x28, 0x44, 0x00,
347
+    0x00, 0x41, 0x7F, 0x40, 0x00,
348
+    0x7C, 0x04, 0x78, 0x04, 0x78,
349
+    0x7C, 0x08, 0x04, 0x04, 0x78,
350
+    0x38, 0x44, 0x44, 0x44, 0x38,
351
+    0xFC, 0x18, 0x24, 0x24, 0x18,
352
+    0x18, 0x24, 0x24, 0x18, 0xFC,
353
+    0x7C, 0x08, 0x04, 0x04, 0x08,
354
+    0x48, 0x54, 0x54, 0x54, 0x24,
355
+    0x04, 0x04, 0x3F, 0x44, 0x24,
356
+    0x3C, 0x40, 0x40, 0x20, 0x7C,
357
+    0x1C, 0x20, 0x40, 0x20, 0x1C,
358
+    0x3C, 0x40, 0x30, 0x40, 0x3C,
359
+    0x44, 0x28, 0x10, 0x28, 0x44,
360
+    0x4C, 0x90, 0x90, 0x90, 0x7C,
361
+    0x44, 0x64, 0x54, 0x4C, 0x44,
362
+    0x00, 0x08, 0x36, 0x41, 0x00,
363
+    0x00, 0x00, 0x77, 0x00, 0x00,
364
+    0x00, 0x41, 0x36, 0x08, 0x00,
365
+    0x02, 0x01, 0x02, 0x04, 0x02,
366
+    0x3C, 0x26, 0x23, 0x26, 0x3C,
367
+    0x1E, 0xA1, 0xA1, 0x61, 0x12,
368
+    0x3A, 0x40, 0x40, 0x20, 0x7A,
369
+    0x38, 0x54, 0x54, 0x55, 0x59,
370
+    0x21, 0x55, 0x55, 0x79, 0x41,
371
+    0x21, 0x54, 0x54, 0x78, 0x41,
372
+    0x21, 0x55, 0x54, 0x78, 0x40,
373
+    0x20, 0x54, 0x55, 0x79, 0x40,
374
+    0x0C, 0x1E, 0x52, 0x72, 0x12,
375
+    0x39, 0x55, 0x55, 0x55, 0x59,
376
+    0x39, 0x54, 0x54, 0x54, 0x59,
377
+    0x39, 0x55, 0x54, 0x54, 0x58,
378
+    0x00, 0x00, 0x45, 0x7C, 0x41,
379
+    0x00, 0x02, 0x45, 0x7D, 0x42,
380
+    0x00, 0x01, 0x45, 0x7C, 0x40,
381
+    0xF0, 0x29, 0x24, 0x29, 0xF0,
382
+    0xF0, 0x28, 0x25, 0x28, 0xF0,
383
+    0x7C, 0x54, 0x55, 0x45, 0x00,
384
+    0x20, 0x54, 0x54, 0x7C, 0x54,
385
+    0x7C, 0x0A, 0x09, 0x7F, 0x49,
386
+    0x32, 0x49, 0x49, 0x49, 0x32,
387
+    0x32, 0x48, 0x48, 0x48, 0x32,
388
+    0x32, 0x4A, 0x48, 0x48, 0x30,
389
+    0x3A, 0x41, 0x41, 0x21, 0x7A,
390
+    0x3A, 0x42, 0x40, 0x20, 0x78,
391
+    0x00, 0x9D, 0xA0, 0xA0, 0x7D,
392
+    0x39, 0x44, 0x44, 0x44, 0x39,
393
+    0x3D, 0x40, 0x40, 0x40, 0x3D,
394
+    0x3C, 0x24, 0xFF, 0x24, 0x24,
395
+    0x48, 0x7E, 0x49, 0x43, 0x66,
396
+    0x2B, 0x2F, 0xFC, 0x2F, 0x2B,
397
+    0xFF, 0x09, 0x29, 0xF6, 0x20,
398
+    0xC0, 0x88, 0x7E, 0x09, 0x03,
399
+    0x20, 0x54, 0x54, 0x79, 0x41,
400
+    0x00, 0x00, 0x44, 0x7D, 0x41,
401
+    0x30, 0x48, 0x48, 0x4A, 0x32,
402
+    0x38, 0x40, 0x40, 0x22, 0x7A,
403
+    0x00, 0x7A, 0x0A, 0x0A, 0x72,
404
+    0x7D, 0x0D, 0x19, 0x31, 0x7D,
405
+    0x26, 0x29, 0x29, 0x2F, 0x28,
406
+    0x26, 0x29, 0x29, 0x29, 0x26,
407
+    0x30, 0x48, 0x4D, 0x40, 0x20,
408
+    0x38, 0x08, 0x08, 0x08, 0x08,
409
+    0x08, 0x08, 0x08, 0x08, 0x38,
410
+    0x2F, 0x10, 0xC8, 0xAC, 0xBA,
411
+    0x2F, 0x10, 0x28, 0x34, 0xFA,
412
+    0x00, 0x00, 0x7B, 0x00, 0x00,
413
+    0x08, 0x14, 0x2A, 0x14, 0x22,
414
+    0x22, 0x14, 0x2A, 0x14, 0x08,
415
+    0xAA, 0x00, 0x55, 0x00, 0xAA,
416
+    0xAA, 0x55, 0xAA, 0x55, 0xAA,
417
+    0x00, 0x00, 0x00, 0xFF, 0x00,
418
+    0x10, 0x10, 0x10, 0xFF, 0x00,
419
+    0x14, 0x14, 0x14, 0xFF, 0x00,
420
+    0x10, 0x10, 0xFF, 0x00, 0xFF,
421
+    0x10, 0x10, 0xF0, 0x10, 0xF0,
422
+    0x14, 0x14, 0x14, 0xFC, 0x00,
423
+    0x14, 0x14, 0xF7, 0x00, 0xFF,
424
+    0x00, 0x00, 0xFF, 0x00, 0xFF,
425
+    0x14, 0x14, 0xF4, 0x04, 0xFC,
426
+    0x14, 0x14, 0x17, 0x10, 0x1F,
427
+    0x10, 0x10, 0x1F, 0x10, 0x1F,
428
+    0x14, 0x14, 0x14, 0x1F, 0x00,
429
+    0x10, 0x10, 0x10, 0xF0, 0x00,
430
+    0x00, 0x00, 0x00, 0x1F, 0x10,
431
+    0x10, 0x10, 0x10, 0x1F, 0x10,
432
+    0x10, 0x10, 0x10, 0xF0, 0x10,
433
+    0x00, 0x00, 0x00, 0xFF, 0x10,
434
+    0x10, 0x10, 0x10, 0x10, 0x10,
435
+    0x10, 0x10, 0x10, 0xFF, 0x10,
436
+    0x00, 0x00, 0x00, 0xFF, 0x14,
437
+    0x00, 0x00, 0xFF, 0x00, 0xFF,
438
+    0x00, 0x00, 0x1F, 0x10, 0x17,
439
+    0x00, 0x00, 0xFC, 0x04, 0xF4,
440
+    0x14, 0x14, 0x17, 0x10, 0x17,
441
+    0x14, 0x14, 0xF4, 0x04, 0xF4,
442
+    0x00, 0x00, 0xFF, 0x00, 0xF7,
443
+    0x14, 0x14, 0x14, 0x14, 0x14,
444
+    0x14, 0x14, 0xF7, 0x00, 0xF7,
445
+    0x14, 0x14, 0x14, 0x17, 0x14,
446
+    0x10, 0x10, 0x1F, 0x10, 0x1F,
447
+    0x14, 0x14, 0x14, 0xF4, 0x14,
448
+    0x10, 0x10, 0xF0, 0x10, 0xF0,
449
+    0x00, 0x00, 0x1F, 0x10, 0x1F,
450
+    0x00, 0x00, 0x00, 0x1F, 0x14,
451
+    0x00, 0x00, 0x00, 0xFC, 0x14,
452
+    0x00, 0x00, 0xF0, 0x10, 0xF0,
453
+    0x10, 0x10, 0xFF, 0x10, 0xFF,
454
+    0x14, 0x14, 0x14, 0xFF, 0x14,
455
+    0x10, 0x10, 0x10, 0x1F, 0x00,
456
+    0x00, 0x00, 0x00, 0xF0, 0x10,
457
+    0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
458
+    0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
459
+    0xFF, 0xFF, 0xFF, 0x00, 0x00,
460
+    0x00, 0x00, 0x00, 0xFF, 0xFF,
461
+    0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
462
+    0x38, 0x44, 0x44, 0x38, 0x44,
463
+    0x7C, 0x2A, 0x2A, 0x3E, 0x14,
464
+    0x7E, 0x02, 0x02, 0x06, 0x06,
465
+    0x02, 0x7E, 0x02, 0x7E, 0x02,
466
+    0x63, 0x55, 0x49, 0x41, 0x63,
467
+    0x38, 0x44, 0x44, 0x3C, 0x04,
468
+    0x40, 0x7E, 0x20, 0x1E, 0x20,
469
+    0x06, 0x02, 0x7E, 0x02, 0x02,
470
+    0x99, 0xA5, 0xE7, 0xA5, 0x99,
471
+    0x1C, 0x2A, 0x49, 0x2A, 0x1C,
472
+    0x4C, 0x72, 0x01, 0x72, 0x4C,
473
+    0x30, 0x4A, 0x4D, 0x4D, 0x30,
474
+    0x30, 0x48, 0x78, 0x48, 0x30,
475
+    0xBC, 0x62, 0x5A, 0x46, 0x3D,
476
+    0x3E, 0x49, 0x49, 0x49, 0x00,
477
+    0x7E, 0x01, 0x01, 0x01, 0x7E,
478
+    0x2A, 0x2A, 0x2A, 0x2A, 0x2A,
479
+    0x44, 0x44, 0x5F, 0x44, 0x44,
480
+    0x40, 0x51, 0x4A, 0x44, 0x40,
481
+    0x40, 0x44, 0x4A, 0x51, 0x40,
482
+    0x00, 0x00, 0xFF, 0x01, 0x03,
483
+    0xE0, 0x80, 0xFF, 0x00, 0x00,
484
+    0x08, 0x08, 0x6B, 0x6B, 0x08,
485
+    0x36, 0x12, 0x36, 0x24, 0x36,
486
+    0x06, 0x0F, 0x09, 0x0F, 0x06,
487
+    0x00, 0x00, 0x18, 0x18, 0x00,
488
+    0x00, 0x00, 0x10, 0x10, 0x00,
489
+    0x30, 0x40, 0xFF, 0x01, 0x01,
490
+    0x00, 0x1F, 0x01, 0x01, 0x1E,
491
+    0x00, 0x19, 0x1D, 0x17, 0x12,
492
+    0x00, 0x3C, 0x3C, 0x3C, 0x3C,
493
+    0x00, 0x00, 0x00, 0x00, 0x00
494
+};
240 495
 
241 496
 /**
242
- * @brief C++ API for NRF24l01 transceiver module
497
+ * @brief C++ API for ST7735 SPI LCD module
243 498
  *
244
- * This file defines the NRF24l01 C++ interface for libnrf24l01
499
+ * This file defines the ST7735 C++ interface for libst7735
245 500
  *
246
- * @snippet nrf_receiver.cxx Interesting
247
- * @snippet nrf_transmitter.cxx Interesting
501
+ * @snippet st7735.cxx Interesting
248 502
  */
249 503
 class ST7735 : public GFX {
250 504
     public:
251 505
         /**
252
-         * Instanciates a NRF24l01 object
506
+         * Instanciates a ST7735 object
253 507
          *
254
-         * @param cs chip select pin
508
+         * @param csLCD LCD chip select pin
509
+         * @param cSD SD card chip select pin
510
+         * @param rs data/command pin
511
+         * @param rst reset pin
255 512
          */
256 513
         ST7735 (uint8_t csLCD, uint8_t cSD, uint8_t rs, uint8_t rst);
257 514
 
258 515
         /**
259
-         * NRF24l01 object destructor
516
+         * ST7735 object destructor
260 517
          */
261 518
         ~ST7735 ();
262 519
 
@@ -269,76 +526,92 @@ class ST7735 : public GFX {
269 526
         }
270 527
 
271 528
         /**
272
-         * 
529
+         * Initialize the modules GPIOs
273 530
          */
274 531
         void initModule ();
275 532
 
276 533
         /**
277
-         * 
534
+         * Configure the chip via SPI interface
278 535
          */
279 536
         void configModule ();
280
-        
537
+
281 538
         /**
282
-         * 
539
+         * Send command to SPI bus (rs must be LOW)
540
+         *
541
+         * @param value command number
283 542
          */
284 543
         void write (uint8_t value);
285
-        
544
+
286 545
         /**
287
-         * 
546
+         * Send data to SPI bus (rs must be HIGH)
547
+         *
548
+         * @param value command number
288 549
          */
289 550
         void data (uint8_t value);
290
-        
551
+
291 552
         /**
292
-         * 
553
+         * Execute set of commands and data
554
+         *
555
+         * @param *addr pointer to start of the commands/data section
293 556
          */
294 557
         void executeCMDList (const uint8_t *addr);
295
-        
558
+
296 559
         /**
297
-         * 
560
+         * Set the window size inside the screen where the pixels data
561
+         * will be written.
562
+         *
563
+         * @param x0 first coordinate
564
+         * @param y0 first coordinate
565
+         * @param x1 second coordinate
566
+         * @param y1 second coordinate
298 567
          */
299 568
         void setAddrWindow (uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1);
300
-        
569
+
301 570
         /**
302
-         * 
571
+         * Send pixel collor (RGB) to the chip.
572
+         *
573
+         * @param x axis on horizontal scale
574
+         * @param y axis on vertical scale
575
+         * @param color rgb (16bit) color (R[0-4], G[5-10], B[11-15])
303 576
          */
304 577
         void drawPixel (int16_t x, int16_t y, uint16_t color);
305
-        
578
+
306 579
         /**
307
-         * 
580
+         * Copy the buffer to the chip via SPI interface.
308 581
          */
309 582
         void refresh ();
310
-        
583
+
311 584
         /**
312
-         * 
585
+         * LCD chip select LOW.
313 586
          */
314 587
         maa_result_t lcdCSOn ();
315 588
 
316 589
         /**
317
-         * 
590
+         * LCD chip select HIGH.
318 591
          */
319 592
         maa_result_t lcdCSOff ();
320 593
 
321 594
         /**
322
-         * 
595
+         * CD card chip select LOW.
323 596
          */
324 597
         maa_result_t sdCSOn ();
325 598
 
326 599
         /**
327
-         * 
600
+         * CD card select HIGH.
328 601
          */
329 602
         maa_result_t sdCSOff ();
330
-        
603
+
331 604
         /**
332
-         * 
605
+         * Data select HIGH.
333 606
          */
334 607
         maa_result_t rsHIGH ();
335 608
 
336 609
         /**
337
-         * 
610
+         * Data select LOW.
338 611
          */
339 612
         maa_result_t rsLOW ();
340
-        
341
-        void fill (int col, uint16_t* buff, int len);
613
+
614
+        uint8_t m_map[160 * 128 * 2]; /**< Screens buffer */
342 615
     private:
343 616
         maa_spi_context      m_spi;
344 617
         uint8_t              m_csLCD;
@@ -350,8 +623,8 @@ class ST7735 : public GFX {
350 623
         maa_gpio_context     m_cSDPinCtx;
351 624
         maa_gpio_context     m_rSTPinCtx;
352 625
         maa_gpio_context     m_rSPinCtx;
353
-                
354
-        uint8_t              m_spiBuffer[128];
626
+
627
+        uint8_t              m_spiBuffer[32];
355 628
 
356 629
         std::string          m_name;
357 630
 };