16
16
* Either 2.4" or 3.5" TFT FeatherWing is used to display uploaded image
17
17
* - https://www.adafruit.com/product/3315
18
18
* - https://www.adafruit.com/product/3651
19
+ * - https://www.adafruit.com/product/4367
19
20
*/
20
21
21
- // if USE_35_TFT_FEATHERWING = 0 then the 2.4" TFT will be used instead
22
- #define USE_35_TFT_FEATHERWING 1
22
+ #define TFT_35_FEATHERWING 1
23
+ #define TFT_24_FEATHERWING 2
24
+ #define TFT_15_GIZMO 3
25
+
26
+ // one of above supported TFT add-on
27
+ #define TFT_IN_USE TFT_35_FEATHERWING
23
28
24
29
#include < bluefruit.h>
25
30
#include < SPI.h>
40
45
#define TFT_CS A6
41
46
#endif
42
47
43
- #if USE_35_TFT_FEATHERWING
48
+ #if TFT_IN_USE == TFT_35_FEATHERWING
44
49
#include " Adafruit_HX8357.h"
45
50
Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC);
46
- #else
51
+ #elif TFT_IN_USE == TFT_24_FEATHERWING
47
52
#include < Adafruit_ILI9341.h>
48
53
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
54
+ #elif TFT_IN_USE == TFT_15_GIZMO
55
+ #error "Not supported yet"
56
+ #else
57
+ #error "TFT display is not supported"
49
58
#endif
50
59
51
60
#define COLOR_WHITE 0xFFFF
@@ -62,15 +71,17 @@ BLEUart bleuart(10*1024);
62
71
/* The Image Transfer module sends the image of your choice to Bluefruit LE over UART.
63
72
* Each image sent begins with
64
73
* - A single byte char '!' (0x21) followed by 'I' helper for image
74
+ * - Color depth: 24-bit for RGB 888, 16-bit for RGB 655
65
75
* - Image width (uint16 little endian, 2 bytes)
66
76
* - Image height (uint16 little endian, 2 bytes)
67
77
* - Pixel data encoded as RGB 24-bit and suffixed by a single byte CRC.
68
78
*
69
- * Format: [ '!' ] [ 'I' ] [ uint16 width ] [ uint16 height ] [ r g b ] [ r g b ] [ r g b ] … [ CRC ]
79
+ * Format: [ '!' ] [ 'I' ] [uint8_t color bit] [ uint16 width ] [ uint16 height ] [ r g b ] [ r g b ] [ r g b ] … [ CRC ]
70
80
*/
71
81
72
82
uint16_t imageWidth = 0 ;
73
83
uint16_t imageHeight = 0 ;
84
+ uint8_t imageColorBit = 0 ;
74
85
75
86
uint32_t totalPixel = 0 ; // received pixel
76
87
@@ -107,7 +118,21 @@ void setup()
107
118
108
119
// Configure and Start BLE Uart Service
109
120
bleuart.begin ();
110
- bleuart.setRxCallback (bleuart_rx_callback);
121
+
122
+ // Due to huge amount of image data
123
+ // NRF52832 doesn't have enough SRAM to queue up received packets using deferred callbacks.
124
+ // Therefore it must process data as soon as it comes, this can be done by
125
+ // changing the default "deferred" option to false to invoke callback immediately.
126
+ // However, the transfer speed will be affected since immediate callback will block BLE task
127
+ // to process data especially when tft.drawRGBBitmap() is calling.
128
+ #ifdef NRF52840_XXAA
129
+ // 2nd argument is true to deferred callbacks i.e queue it up in seperated callback Task
130
+ bleuart.setRxCallback (bleuart_rx_callback, true );
131
+ #else
132
+ // 2nd argument is false to invoke callbacks immediately (thus blocking other ble events)
133
+ bleuart.setRxCallback (bleuart_rx_callback, false );
134
+ #endif
135
+
111
136
bleuart.setRxOverflowCallback (bleuart_overflow_callback);
112
137
113
138
// Set up and start advertising
@@ -171,11 +196,13 @@ void bleuart_rx_callback(uint16_t conn_hdl)
171
196
172
197
if ( !bleuart.available () ) return ;
173
198
199
+ imageColorBit = bleuart.read8 ();
174
200
imageWidth = bleuart.read16 ();
175
201
imageHeight = bleuart.read16 ();
176
202
177
203
totalPixel = 0 ;
178
204
205
+ PRINT_INT (imageColorBit);
179
206
PRINT_INT (imageWidth);
180
207
PRINT_INT (imageHeight);
181
208
@@ -186,10 +213,18 @@ void bleuart_rx_callback(uint16_t conn_hdl)
186
213
// Extract pixel data to buffer and draw image line by line
187
214
while ( bleuart.available () >= 3 )
188
215
{
189
- uint8_t rgb[3 ];
190
- bleuart.read (rgb, 3 );
191
-
192
- pixel_buf[totalPixel % imageWidth] = ((rgb[0 ] & 0xF8 ) << 8 ) | ((rgb[1 ] & 0xFC ) << 3 ) | (rgb[2 ] >> 3 );
216
+ // TFT FeatherWing use 16-bit RGB 655 color, need to convert if input is 24-bit color
217
+ if ( imageColorBit == 24 )
218
+ {
219
+ uint8_t rgb[3 ];
220
+ bleuart.read (rgb, 3 );
221
+ pixel_buf[totalPixel % imageWidth] = ((rgb[0 ] & 0xF8 ) << 8 ) | ((rgb[1 ] & 0xFC ) << 3 ) | (rgb[2 ] >> 3 );
222
+ }
223
+ else if ( imageColorBit == 16 )
224
+ {
225
+ // native 16-bit 655 color
226
+ pixel_buf[totalPixel % imageWidth] = bleuart.read16 ();
227
+ }
193
228
194
229
totalPixel++;
195
230
@@ -207,10 +242,12 @@ void bleuart_rx_callback(uint16_t conn_hdl)
207
242
// do checksum later
208
243
209
244
// print speed summary
210
- print_summary (totalPixel*3 + 7 , rxLastTime-rxStartTime);
245
+ print_summary (totalPixel*(imageColorBit/ 8 ) + 8 , rxLastTime-rxStartTime);
211
246
212
247
// reset and waiting for new image
213
- totalPixel = imageWidth = imageHeight = 0 ;
248
+ imageColorBit = 0 ;
249
+ imageWidth = imageHeight = 0 ;
250
+ totalPixel = 0 ;
214
251
}
215
252
}
216
253
@@ -220,6 +257,7 @@ void connect_callback(uint16_t conn_handle)
220
257
221
258
tft.println (" Connected" );
222
259
260
+ #if 1
223
261
conn->requestPHY ();
224
262
tft.println (" Switching PHY" );
225
263
@@ -228,6 +266,7 @@ void connect_callback(uint16_t conn_handle)
228
266
229
267
conn->requestMtuExchange (247 );
230
268
tft.println (" Exchanging MTU" );
269
+ #endif
231
270
232
271
tft.setTextColor (COLOR_GREEN);
233
272
tft.println (" Ready to receive new image" );
@@ -251,14 +290,14 @@ void print_summary(uint32_t count, uint32_t ms)
251
290
252
291
tft.println (" seconds" );
253
292
254
- tft.print (" Speed " );
293
+ tft.print (" Speed: " );
255
294
tft.setTextColor (COLOR_YELLOW);
256
295
tft.print ( (count / 1000 .0F ) / (ms / 1000 .0F ), 2 );
257
296
tft.setTextColor (COLOR_WHITE);
258
- tft.print (" KB/s with " );
297
+ tft.print (" KB/s for " );
259
298
260
299
tft.setTextColor (COLOR_YELLOW);
261
- tft.print (imageWidth); tft.print (" x " ); tft.print (imageHeight);
300
+ tft.print (imageWidth); tft.print (" x " ); tft.print (imageHeight);
262
301
263
302
tft.setTextColor (COLOR_WHITE);
264
303
tft.println (" Image" );
@@ -301,7 +340,9 @@ void disconnect_callback(uint16_t conn_handle, uint8_t reason)
301
340
tft.setCursor (0 , 0 );
302
341
tft.println (" Advertising ..." );
303
342
304
- totalPixel = imageWidth = imageHeight = 0 ;
343
+ imageColorBit = 0 ;
344
+ imageWidth = imageHeight = 0 ;
345
+ totalPixel = 0 ;
305
346
bleuart_overflowed = false ;
306
347
307
348
bleuart.flush ();
0 commit comments