get image_upload work with 3.5" TFT featherwing

This commit is contained in:
hathach committed 2019-08-26 13:25:50 +07:00
1 parent 5151d5ff54
commit dee231e9bd
2 files changed
+50 -38

No files matched your search

@@ -166,8 +166,6 @@ TU_ATTR_WEAK bool tud_vendor_control_complete_cb(uint8_t rhport, tusb_control_re
// CDC Descriptor Template
// Interface number, string index, EP notification address and size, EP data address (out, in) and size.
// NOTE: This returns an list of byte (uint_8) values
// NOTE: Unwritten & unverified assumption: _itfnum is in range [0..254] (else overflows below adding 1)
#define TUD_CDC_DESCRIPTOR(_itfnum, _stridx, _ep_notif, _ep_notif_size, _epout, _epin, _epsize) \
/* Interface Associate */\
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
// MIDI simple descriptor
// - 1 Embedded Jack In connected to 1 External Jack Out
// - 1 Embedded Jack out connected to 1 External Jack In
// NOTE: This returns an list of byte (uint_8) values
// NOTE: Unwritten & unverified assumption: _itfnum is in range [0..254] (else overflows below adding 1)
#define TUD_MIDI_DESCRIPTOR(_itfnum, _stridx, _epout, _epin, _epsize) \
/* Audio Control (AC) Interface */\
9, TUSB_DESC_INTERFACE, _itfnum, 0, 0, TUSB_CLASS_AUDIO, AUDIO_SUBCLASS_CONTROL, AUDIO_PROTOCOL_V1, _stridx,\
@@ -13,14 +13,45 @@
*********************************************************************/
/* This sketch demonstrates the "Image Upload" feature of Bluefruit Mobile App.
* FeatherWing OLED is used to display uploaded image
* Either 2.4" or 3.5" TFT FeatherWing is used to display uploaded image
* - https://www.adafruit.com/product/3315
* - https://www.adafruit.com/product/3651
*/
// if USE_35_TFT_FEATHERWING = 0 then the 2.4" TFT will be used instead
#define USE_35_TFT_FEATHERWING 1
#include <bluefruit.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#ifdef ARDUINO_NRF52832_FEATHER
#define TFT_DC 11
#define TFT_CS 31
#endif
#ifdef ARDUINO_NRF52840_FEATHER
#define TFT_DC 10
#define TFT_CS 9
#endif
#ifdef ARDUINO_NRF52840_CIRCUITPLAY
#define TFT_DC A7
#define TFT_CS A6
#endif
#if USE_35_TFT_FEATHERWING
#include "Adafruit_HX8357.h"
Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC);
#else
#include <Adafruit_ILI9341.h>
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
#endif
#define COLOR_WHITE 0xFFFF
#define COLOR_BLACK 0x0000
#define COLOR_YELLOW 0xFFE0
#define COLOR_GREEN 0x07E0
// Uart over BLE with large buffer to hold image data
BLEUart bleuart(1024*10);
@@ -50,31 +81,14 @@ uint16_t color_buf[2048];
uint32_t rxStartTime = 0;
uint32_t rxLastTime = 0;
#ifdef ARDUINO_NRF52832_FEATHER
#define TFT_DC 11
#define TFT_CS 31
#endif
#ifdef ARDUINO_NRF52840_FEATHER
#define TFT_DC 10
#define TFT_CS 9
#endif
#ifdef ARDUINO_NRF52840_CIRCUITPLAY
#define TFT_DC A7
#define TFT_CS A6
#endif
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
void setup()
{
Serial.begin(115200);
tft.begin();
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_WHITE);
tft.fillScreen(COLOR_BLACK);
tft.setTextColor(COLOR_WHITE);
tft.setTextSize(1);
// Config the peripheral connection with maximum bandwidth
@@ -135,7 +149,7 @@ void loop()
if ( !bleuart.available() ) return;
// all pixel data is received
if ( totalPixel == imageWidth*imageHeight )
if ( (totalPixel != 0) && (totalPixel == imageWidth*imageHeight) )
{
uint8_t crc = bleuart.read();
// do checksum later
@@ -193,9 +207,9 @@ void connect_callback(uint16_t conn_handle)
conn->requestMtuExchange(247);
tft.println("Exchanging MTU");
tft.setTextColor(ILI9341_GREEN);
tft.setTextColor(COLOR_GREEN);
tft.println("Ready to receive new image");
tft.setTextColor(ILI9341_WHITE);
tft.setTextColor(COLOR_WHITE);
}
void print_speed(uint32_t count, uint32_t ms)
@@ -203,27 +217,27 @@ void print_speed(uint32_t count, uint32_t ms)
tft.setCursor(0, imageHeight+5);
tft.print("Received ");
tft.setTextColor(ILI9341_YELLOW);
tft.setTextColor(COLOR_YELLOW);
tft.print(count);
tft.setTextColor(ILI9341_WHITE);
tft.setTextColor(COLOR_WHITE);
tft.print(" bytes in ");
tft.setTextColor(ILI9341_YELLOW);
tft.setTextColor(COLOR_YELLOW);
tft.print(ms / 1000.0F, 2);
tft.setTextColor(ILI9341_WHITE);
tft.setTextColor(COLOR_WHITE);
tft.println(" seconds");
tft.print("Speed: ");
tft.setTextColor(ILI9341_YELLOW);
tft.setTextColor(COLOR_YELLOW);
tft.print( (count / 1000.0F) / (ms / 1000.0F), 2);
tft.setTextColor(ILI9341_WHITE);
tft.setTextColor(COLOR_WHITE);
tft.println(" KB/s");
tft.setTextColor(ILI9341_GREEN);
tft.setTextColor(COLOR_GREEN);
tft.println("Ready to receive new image");
tft.setTextColor(ILI9341_WHITE);
tft.setTextColor(COLOR_WHITE);
}
void bleuart_rx_callback(uint16_t conn_hdl)
@@ -249,7 +263,7 @@ void bleuart_rx_callback(uint16_t conn_hdl)
PRINT_INT(imageWidth);
PRINT_INT(imageHeight);
tft.fillScreen(ILI9341_BLACK);
tft.fillScreen(COLOR_BLACK);
tft.setCursor(0, 0);
imageX = imageY = 0;
}
@@ -264,9 +278,11 @@ void disconnect_callback(uint16_t conn_handle, uint8_t reason)
{
(void) reason;
tft.fillScreen(ILI9341_BLACK);
tft.fillScreen(COLOR_BLACK);
tft.setCursor(0, 0);
tft.println("Advertising ...");
totalPixel = imageWidth = imageHeight = 0;
bleuart.flush();
}