Skip to content

Commit dee231e

Browse files
committed
get image_upload work with 3.5" TFT featherwing
1 parent 5151d5f commit dee231e

File tree

2 files changed

+50
-38
lines changed
  • cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/device
  • libraries/Bluefruit52Lib/examples/Peripheral/image_upload

2 files changed

+50
-38
lines changed

cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/device/usbd.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,6 @@ TU_ATTR_WEAK bool tud_vendor_control_complete_cb(uint8_t rhport, tusb_control_re
166166

167167
// CDC Descriptor Template
168168
// Interface number, string index, EP notification address and size, EP data address (out, in) and size.
169-
// NOTE: This returns an list of byte (uint_8) values
170-
// NOTE: Unwritten & unverified assumption: _itfnum is in range [0..254] (else overflows below adding 1)
171169
#define TUD_CDC_DESCRIPTOR(_itfnum, _stridx, _ep_notif, _ep_notif_size, _epout, _epin, _epsize) \
172170
/* Interface Associate */\
173171
8, TUSB_DESC_INTERFACE_ASSOCIATION, _itfnum, 2, TUSB_CLASS_CDC, CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL, CDC_COMM_PROTOCOL_ATCOMMAND, 0,\
@@ -242,8 +240,6 @@ TU_ATTR_WEAK bool tud_vendor_control_complete_cb(uint8_t rhport, tusb_control_re
242240
// MIDI simple descriptor
243241
// - 1 Embedded Jack In connected to 1 External Jack Out
244242
// - 1 Embedded Jack out connected to 1 External Jack In
245-
// NOTE: This returns an list of byte (uint_8) values
246-
// NOTE: Unwritten & unverified assumption: _itfnum is in range [0..254] (else overflows below adding 1)
247243
#define TUD_MIDI_DESCRIPTOR(_itfnum, _stridx, _epout, _epin, _epsize) \
248244
/* Audio Control (AC) Interface */\
249245
9, TUSB_DESC_INTERFACE, _itfnum, 0, 0, TUSB_CLASS_AUDIO, AUDIO_SUBCLASS_CONTROL, AUDIO_PROTOCOL_V1, _stridx,\

libraries/Bluefruit52Lib/examples/Peripheral/image_upload/image_upload.ino

Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,45 @@
1313
*********************************************************************/
1414

1515
/* This sketch demonstrates the "Image Upload" feature of Bluefruit Mobile App.
16-
* FeatherWing OLED is used to display uploaded image
16+
* Either 2.4" or 3.5" TFT FeatherWing is used to display uploaded image
1717
* - https://www.adafruit.com/product/3315
18+
* - https://www.adafruit.com/product/3651
1819
*/
1920

21+
// if USE_35_TFT_FEATHERWING = 0 then the 2.4" TFT will be used instead
22+
#define USE_35_TFT_FEATHERWING 1
23+
2024
#include <bluefruit.h>
2125
#include <SPI.h>
2226
#include <Adafruit_GFX.h>
23-
#include <Adafruit_ILI9341.h>
27+
28+
#ifdef ARDUINO_NRF52832_FEATHER
29+
#define TFT_DC 11
30+
#define TFT_CS 31
31+
#endif
32+
33+
#ifdef ARDUINO_NRF52840_FEATHER
34+
#define TFT_DC 10
35+
#define TFT_CS 9
36+
#endif
37+
38+
#ifdef ARDUINO_NRF52840_CIRCUITPLAY
39+
#define TFT_DC A7
40+
#define TFT_CS A6
41+
#endif
42+
43+
#if USE_35_TFT_FEATHERWING
44+
#include "Adafruit_HX8357.h"
45+
Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC);
46+
#else
47+
#include <Adafruit_ILI9341.h>
48+
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
49+
#endif
50+
51+
#define COLOR_WHITE 0xFFFF
52+
#define COLOR_BLACK 0x0000
53+
#define COLOR_YELLOW 0xFFE0
54+
#define COLOR_GREEN 0x07E0
2455

2556
// Uart over BLE with large buffer to hold image data
2657
BLEUart bleuart(1024*10);
@@ -50,31 +81,14 @@ uint16_t color_buf[2048];
5081
uint32_t rxStartTime = 0;
5182
uint32_t rxLastTime = 0;
5283

53-
#ifdef ARDUINO_NRF52832_FEATHER
54-
#define TFT_DC 11
55-
#define TFT_CS 31
56-
#endif
57-
58-
#ifdef ARDUINO_NRF52840_FEATHER
59-
#define TFT_DC 10
60-
#define TFT_CS 9
61-
#endif
62-
63-
#ifdef ARDUINO_NRF52840_CIRCUITPLAY
64-
#define TFT_DC A7
65-
#define TFT_CS A6
66-
#endif
67-
68-
69-
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
7084

7185
void setup()
7286
{
7387
Serial.begin(115200);
7488

7589
tft.begin();
76-
tft.fillScreen(ILI9341_BLACK);
77-
tft.setTextColor(ILI9341_WHITE);
90+
tft.fillScreen(COLOR_BLACK);
91+
tft.setTextColor(COLOR_WHITE);
7892
tft.setTextSize(1);
7993

8094
// Config the peripheral connection with maximum bandwidth
@@ -135,7 +149,7 @@ void loop()
135149
if ( !bleuart.available() ) return;
136150

137151
// all pixel data is received
138-
if ( totalPixel == imageWidth*imageHeight )
152+
if ( (totalPixel != 0) && (totalPixel == imageWidth*imageHeight) )
139153
{
140154
uint8_t crc = bleuart.read();
141155
// do checksum later
@@ -193,37 +207,37 @@ void connect_callback(uint16_t conn_handle)
193207
conn->requestMtuExchange(247);
194208
tft.println("Exchanging MTU");
195209

196-
tft.setTextColor(ILI9341_GREEN);
210+
tft.setTextColor(COLOR_GREEN);
197211
tft.println("Ready to receive new image");
198-
tft.setTextColor(ILI9341_WHITE);
212+
tft.setTextColor(COLOR_WHITE);
199213
}
200214

201215
void print_speed(uint32_t count, uint32_t ms)
202216
{
203217
tft.setCursor(0, imageHeight+5);
204218
tft.print("Received ");
205219

206-
tft.setTextColor(ILI9341_YELLOW);
220+
tft.setTextColor(COLOR_YELLOW);
207221
tft.print(count);
208-
tft.setTextColor(ILI9341_WHITE);
222+
tft.setTextColor(COLOR_WHITE);
209223

210224
tft.print(" bytes in ");
211225

212-
tft.setTextColor(ILI9341_YELLOW);
226+
tft.setTextColor(COLOR_YELLOW);
213227
tft.print(ms / 1000.0F, 2);
214-
tft.setTextColor(ILI9341_WHITE);
228+
tft.setTextColor(COLOR_WHITE);
215229

216230
tft.println(" seconds");
217231

218232
tft.print("Speed: ");
219-
tft.setTextColor(ILI9341_YELLOW);
233+
tft.setTextColor(COLOR_YELLOW);
220234
tft.print( (count / 1000.0F) / (ms / 1000.0F), 2);
221-
tft.setTextColor(ILI9341_WHITE);
235+
tft.setTextColor(COLOR_WHITE);
222236
tft.println(" KB/s");
223237

224-
tft.setTextColor(ILI9341_GREEN);
238+
tft.setTextColor(COLOR_GREEN);
225239
tft.println("Ready to receive new image");
226-
tft.setTextColor(ILI9341_WHITE);
240+
tft.setTextColor(COLOR_WHITE);
227241
}
228242

229243
void bleuart_rx_callback(uint16_t conn_hdl)
@@ -249,7 +263,7 @@ void bleuart_rx_callback(uint16_t conn_hdl)
249263
PRINT_INT(imageWidth);
250264
PRINT_INT(imageHeight);
251265

252-
tft.fillScreen(ILI9341_BLACK);
266+
tft.fillScreen(COLOR_BLACK);
253267
tft.setCursor(0, 0);
254268
imageX = imageY = 0;
255269
}
@@ -264,9 +278,11 @@ void disconnect_callback(uint16_t conn_handle, uint8_t reason)
264278
{
265279
(void) reason;
266280

267-
tft.fillScreen(ILI9341_BLACK);
281+
tft.fillScreen(COLOR_BLACK);
268282
tft.setCursor(0, 0);
269283
tft.println("Advertising ...");
270284

271285
totalPixel = imageWidth = imageHeight = 0;
286+
287+
bleuart.flush();
272288
}

0 commit comments

Comments
 (0)