mirror of https://github.com/arendst/Tasmota.git
Merge pull request #11971 from gemu2015/udisplay-update
Udisplay update
This commit is contained in:
commit
bfadd1cd4f
|
@ -29,8 +29,7 @@ github:https://github.com/lewisxhe/FT5206_Library
|
|||
/////////////////////////////////////////////////////////////////
|
||||
#include "FT5206.h"
|
||||
|
||||
int FT5206_Class::begin(TwoWire &port, uint8_t addr)
|
||||
{
|
||||
int FT5206_Class::begin(TwoWire &port, uint8_t addr) {
|
||||
_i2cPort = &port;
|
||||
_address = addr;
|
||||
uint8_t val;
|
||||
|
@ -39,9 +38,9 @@ int FT5206_Class::begin(TwoWire &port, uint8_t addr)
|
|||
if (val != FT5206_VENDID) {
|
||||
// return false;
|
||||
}
|
||||
_readByte(FT5206_CHIPID_REG, 1, &val);
|
||||
_readByte(FT5206_CHIPID_REG, 1, &chip_id);
|
||||
//Serial.printf("chip id %d\n",val );
|
||||
if ((val != FT6206_CHIPID) && (val != FT6236_CHIPID) && (val != FT6236U_CHIPID) && (val != FT5206U_CHIPID) && (val != FT5316_CHIPID) ) {
|
||||
if ((chip_id != FT6206_CHIPID) && (chip_id != FT6236_CHIPID) && (chip_id != FT6236U_CHIPID) && (chip_id != FT5206U_CHIPID) && (chip_id != FT5316_CHIPID) ) {
|
||||
return false;
|
||||
}
|
||||
_init = true;
|
||||
|
@ -49,14 +48,12 @@ int FT5206_Class::begin(TwoWire &port, uint8_t addr)
|
|||
}
|
||||
|
||||
// valid touching detect threshold.
|
||||
void FT5206_Class::adjustTheshold(uint8_t thresh)
|
||||
{
|
||||
void FT5206_Class::adjustTheshold(uint8_t thresh) {
|
||||
if (!_init)return;
|
||||
_writeByte(FT5206_THRESHHOLD_REG, 1, &thresh);
|
||||
}
|
||||
|
||||
TP_Point FT5206_Class::getPoint(uint8_t num)
|
||||
{
|
||||
TP_Point FT5206_Class::getPoint(uint8_t num) {
|
||||
if (!_init) return TP_Point(0, 0);
|
||||
_readRegister();
|
||||
if ((_touches == 0) || (num > 1)) {
|
||||
|
@ -66,30 +63,36 @@ TP_Point FT5206_Class::getPoint(uint8_t num)
|
|||
}
|
||||
}
|
||||
|
||||
uint8_t FT5206_Class::touched()
|
||||
{
|
||||
if (!_init)return 0;
|
||||
uint8_t FT5206_Class::touched() {
|
||||
if (!_init) return 0;
|
||||
uint8_t val = 0;
|
||||
_readByte(FT5206_TOUCHES_REG,1,&val);
|
||||
if (chip_id == FT5316_CHIPID) {
|
||||
_readByte(FT5206_MODE_REG, 1, &val);
|
||||
if (val) {
|
||||
// wrong mode
|
||||
val = 0;
|
||||
_writeByte(FT5206_MODE_REG, 1, &val);
|
||||
}
|
||||
}
|
||||
|
||||
_readByte(FT5206_TOUCHES_REG, 1, &val);
|
||||
//Serial.printf(">> TP: %d\n", val);
|
||||
return val > 2 ? 0: val;
|
||||
}
|
||||
|
||||
void FT5206_Class::enterSleepMode()
|
||||
{
|
||||
void FT5206_Class::enterSleepMode() {
|
||||
if (!_init)return;
|
||||
uint8_t val = FT5206_SLEEP_IN;
|
||||
_writeByte(FT5206_POWER_REG, 1, &val);
|
||||
}
|
||||
|
||||
void FT5206_Class::enterMonitorMode()
|
||||
{
|
||||
void FT5206_Class::enterMonitorMode() {
|
||||
if (!_init)return;
|
||||
uint8_t val = FT5206_MONITOR;
|
||||
_writeByte(FT5206_POWER_REG, 1, &val);
|
||||
}
|
||||
|
||||
void FT5206_Class::_readRegister()
|
||||
{
|
||||
void FT5206_Class::_readRegister() {
|
||||
_readByte(DEVIDE_MODE, 16, _data);
|
||||
_touches = _data[TD_STATUS];
|
||||
if ((_touches > 2) || (_touches == 0)) {
|
||||
|
|
|
@ -120,4 +120,5 @@ private:
|
|||
uint8_t _touches = 0;
|
||||
bool _init = false;
|
||||
TwoWire *_i2cPort;
|
||||
uint8_t chip_id;
|
||||
};
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include <Arduino.h>
|
||||
#include "uDisplay.h"
|
||||
|
||||
//#define UDSP_DEBUG
|
||||
#define UDSP_DEBUG
|
||||
|
||||
const uint16_t udisp_colors[]={UDISP_BLACK,UDISP_WHITE,UDISP_RED,UDISP_GREEN,UDISP_BLUE,UDISP_CYAN,UDISP_MAGENTA,\
|
||||
UDISP_YELLOW,UDISP_NAVY,UDISP_DARKGREEN,UDISP_DARKCYAN,UDISP_MAROON,UDISP_PURPLE,UDISP_OLIVE,\
|
||||
|
@ -1100,12 +1100,50 @@ void uDisplay::pushColors(uint16_t *data, uint16_t len, boolean not_swapped) {
|
|||
}
|
||||
#endif
|
||||
} else {
|
||||
|
||||
#ifdef ESP32
|
||||
if ( (col_mode == 18) && (spi_dc >= 0) && (spi_nr <= 2) ) {
|
||||
uint8_t *line = (uint8_t*)malloc(len * 3);
|
||||
uint8_t *lp = line;
|
||||
if (line) {
|
||||
for (uint32_t cnt = 0; cnt < len; cnt++) {
|
||||
color = *data++;
|
||||
color = (color << 8) | (color >> 8);
|
||||
uint8_t r = (color & 0xF800) >> 11;
|
||||
uint8_t g = (color & 0x07E0) >> 5;
|
||||
uint8_t b = color & 0x001F;
|
||||
r = (r * 255) / 31;
|
||||
g = (g * 255) / 63;
|
||||
b = (b * 255) / 31;
|
||||
*lp++ = r;
|
||||
*lp++ = g;
|
||||
*lp++ = b;
|
||||
}
|
||||
|
||||
if (lvgl_param.use_dma) {
|
||||
pushPixels3DMA(line, len );
|
||||
} else {
|
||||
uspi->writeBytes(line, len * 3);
|
||||
}
|
||||
free(line);
|
||||
}
|
||||
|
||||
} else {
|
||||
// 9 bit and others
|
||||
lvgl_color_swap(data, len);
|
||||
while (len--) {
|
||||
WriteColor(*data++);
|
||||
}
|
||||
}
|
||||
#endif // ESP32
|
||||
|
||||
#ifdef ESP8266
|
||||
lvgl_color_swap(data, len);
|
||||
while (len--) {
|
||||
WriteColor(*data++);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
// called from displaytext, no byte swap, currently no dma here
|
||||
if (bpp != 16) {
|
||||
|
@ -1993,6 +2031,32 @@ void uDisplay::pushPixelsDMA(uint16_t* image, uint32_t len) {
|
|||
spiBusyCheck++;
|
||||
}
|
||||
|
||||
/***************************************************************************************
|
||||
** Function name: pushPixelsDMA
|
||||
** Description: Push pixels to TFT (len must be less than 32767)
|
||||
***************************************************************************************/
|
||||
// This will byte swap the original image if setSwapBytes(true) was called by sketch.
|
||||
void uDisplay::pushPixels3DMA(uint8_t* image, uint32_t len) {
|
||||
|
||||
if ((len == 0) || (!DMA_Enabled)) return;
|
||||
|
||||
dmaWait();
|
||||
|
||||
esp_err_t ret;
|
||||
|
||||
memset(&trans, 0, sizeof(spi_transaction_t));
|
||||
|
||||
trans.user = (void *)1;
|
||||
trans.tx_buffer = image; //finally send the line data
|
||||
trans.length = len * 24; //Data length, in bits
|
||||
trans.flags = 0; //SPI_TRANS_USE_TXDATA flag
|
||||
|
||||
ret = spi_device_queue_trans(dmaHAL, &trans, portMAX_DELAY);
|
||||
assert(ret == ESP_OK);
|
||||
|
||||
spiBusyCheck++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // ESP32
|
||||
|
|
|
@ -228,6 +228,7 @@ class uDisplay : public Renderer {
|
|||
bool dmaBusy(void);
|
||||
void dmaWait(void);
|
||||
void pushPixelsDMA(uint16_t* image, uint32_t len);
|
||||
void pushPixels3DMA(uint8_t* image, uint32_t len);
|
||||
#endif // ESP32
|
||||
};
|
||||
|
||||
|
|
|
@ -939,35 +939,44 @@ void RA8876::setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
|
|||
SPI.endTransaction();
|
||||
}
|
||||
|
||||
static inline void lvgl_color_swap1(uint16_t *data, uint16_t len) { for (uint32_t i = 0; i < len; i++) (data[i] = data[i] << 8 | data[i] >> 8); }
|
||||
|
||||
// pixel color is swapped in contrast to other controllers
|
||||
void RA8876::pushColors(uint16_t *data, uint16_t len, boolean not_swapped) {
|
||||
|
||||
if (not_swapped == false) {
|
||||
lvgl_color_swap1(data, len);
|
||||
}
|
||||
|
||||
// coming from LVGL
|
||||
#ifdef ESP32
|
||||
SPI.beginTransaction(m_spiSettings);
|
||||
//RA8876_CS_LOW
|
||||
while (len--) {
|
||||
|
||||
uint16_t color = *data++;
|
||||
|
||||
#if 0
|
||||
SPI.transfer(RA8876_DATA_WRITE);
|
||||
SPI.transfer(color&0xff);
|
||||
SPI.transfer(RA8876_DATA_WRITE);
|
||||
SPI.transfer(color>>8);
|
||||
#else
|
||||
|
||||
//waitWriteFifo();
|
||||
writeData(color&0xff);
|
||||
//waitWriteFifo();
|
||||
writeData(color>>8);
|
||||
#endif
|
||||
RA8876_CS_LOW
|
||||
SPI.write(RA8876_DATA_WRITE);
|
||||
if (lvgl_param.use_dma) {
|
||||
// will need swapping !
|
||||
pushPixelsDMA(data, len);
|
||||
} else {
|
||||
SPI.writePixels(data, len * 2);
|
||||
}
|
||||
//RA8876_CS_HIGH
|
||||
RA8876_CS_HIGH
|
||||
SPI.endTransaction();
|
||||
#endif
|
||||
} else {
|
||||
// coming from displaytext
|
||||
SPI.beginTransaction(m_spiSettings);
|
||||
RA8876_CS_LOW
|
||||
SPI.transfer(RA8876_DATA_WRITE);
|
||||
|
||||
#ifdef ESP32
|
||||
SPI.writeBytes((uint8_t*)data, len * 2);
|
||||
#endif
|
||||
|
||||
#ifdef ESP8266
|
||||
while (len--) {
|
||||
uint16_t color = *data++;
|
||||
SPI.write(color&0xff);
|
||||
SPI.write(color>>8);
|
||||
}
|
||||
#endif
|
||||
RA8876_CS_HIGH
|
||||
SPI.endTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
void RA8876::drawPixel(int16_t x, int16_t y, uint16_t color) {
|
||||
|
@ -1501,7 +1510,7 @@ bool RA8876::initDMA()
|
|||
.cs_ena_posttrans = 0,
|
||||
.clock_speed_hz = RA8876_SPI_SPEED,
|
||||
.input_delay_ns = 0,
|
||||
.spics_io_num = m_csPin,
|
||||
.spics_io_num = -1,
|
||||
.flags = SPI_DEVICE_NO_DUMMY, //0,
|
||||
.queue_size = 1,
|
||||
.pre_cb = 0, //dc_callback, //Callback to handle D/C line
|
||||
|
|
|
@ -7879,6 +7879,8 @@ void start_lvgl(const char * uconfig);
|
|||
lv_event_t lvgl_last_event;
|
||||
uint8_t lvgl_last_object;
|
||||
uint8_t lvgl_last_slider;
|
||||
static lv_obj_t * kb;
|
||||
static lv_obj_t * ta;
|
||||
|
||||
void lvgl_set_last(lv_obj_t * obj, lv_event_t event);
|
||||
void lvgl_set_last(lv_obj_t * obj, lv_event_t event) {
|
||||
|
@ -7910,6 +7912,33 @@ void slider_event_cb(lv_obj_t * sld, lv_event_t event) {
|
|||
}
|
||||
}
|
||||
|
||||
static void kb_create(void);
|
||||
static void ta_event_cb(lv_obj_t * ta_local, lv_event_t e);
|
||||
static void kb_event_cb(lv_obj_t * keyboard, lv_event_t e);
|
||||
|
||||
static void kb_event_cb(lv_obj_t * keyboard, lv_event_t e) {
|
||||
lv_keyboard_def_event_cb(kb, e);
|
||||
if(e == LV_EVENT_CANCEL) {
|
||||
lv_keyboard_set_textarea(kb, NULL);
|
||||
lv_obj_del(kb);
|
||||
kb = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void kb_create(void) {
|
||||
kb = lv_keyboard_create(lv_scr_act(), NULL);
|
||||
lv_keyboard_set_cursor_manage(kb, true);
|
||||
lv_obj_set_event_cb(kb, kb_event_cb);
|
||||
lv_keyboard_set_textarea(kb, ta);
|
||||
}
|
||||
|
||||
static void ta_event_cb(lv_obj_t * ta_local, lv_event_t e) {
|
||||
if(e == LV_EVENT_CLICKED && kb == NULL) {
|
||||
kb_create();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void lvgl_StoreObj(lv_obj_t *obj);
|
||||
void lvgl_StoreObj(lv_obj_t *obj) {
|
||||
if (lvgl_numobjs < MAX_LVGL_OBJS) {
|
||||
|
@ -8039,6 +8068,18 @@ int32_t lvgl_test(char **lpp, int32_t p) {
|
|||
}
|
||||
break;
|
||||
|
||||
case 8:
|
||||
{
|
||||
ta = lv_textarea_create(lv_scr_act(), NULL);
|
||||
lv_obj_align(ta, NULL, LV_ALIGN_IN_TOP_MID, 0, LV_DPI / 16);
|
||||
lv_obj_set_event_cb(ta, ta_event_cb);
|
||||
lv_textarea_set_text(ta, "");
|
||||
lv_coord_t max_h = LV_VER_RES / 2 - LV_DPI / 8;
|
||||
if (lv_obj_get_height(ta) > max_h) lv_obj_set_height(ta, max_h);
|
||||
kb_create();
|
||||
}
|
||||
break;
|
||||
|
||||
case 50:
|
||||
res = lvgl_last_object;
|
||||
break;
|
||||
|
@ -8051,6 +8092,7 @@ int32_t lvgl_test(char **lpp, int32_t p) {
|
|||
|
||||
|
||||
default:
|
||||
start_lvgl(0);
|
||||
lvgl_setup();
|
||||
break;
|
||||
}
|
||||
|
@ -8059,6 +8101,7 @@ int32_t lvgl_test(char **lpp, int32_t p) {
|
|||
return res;
|
||||
}
|
||||
|
||||
|
||||
lv_obj_t *tabview, // LittlevGL tabview object
|
||||
*gauge, // Gauge object (on first of three tabs)
|
||||
*chart, // Chart object (second tab)
|
||||
|
|
|
@ -27,6 +27,9 @@ Renderer *renderer;
|
|||
|
||||
enum ColorType { COLOR_BW, COLOR_COLOR };
|
||||
|
||||
#ifndef DISP_BATCH_FILE
|
||||
#define DISP_BATCH_FILE "/display.bat"
|
||||
#endif
|
||||
|
||||
#ifdef USE_UFILESYS
|
||||
extern FS *ufsp;
|
||||
|
@ -1110,6 +1113,8 @@ extern FS *ffsp;
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef USE_UFILESYS
|
||||
void Display_Text_From_File(const char *file) {
|
||||
File fp;
|
||||
|
@ -1763,7 +1768,7 @@ void DisplayInitDriver(void)
|
|||
#endif
|
||||
|
||||
#ifdef USE_UFILESYS
|
||||
Display_Text_From_File("/display.ini");
|
||||
Display_Text_From_File(DISP_BATCH_FILE);
|
||||
#endif
|
||||
|
||||
#ifdef USE_GRAPH
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
|
||||
#include <renderer.h>
|
||||
#include "lvgl.h"
|
||||
#include "tasmota_lvgl_assets.h" // force compilation of assets
|
||||
|
||||
#define XDRV_54 54
|
||||
|
||||
|
@ -140,10 +139,6 @@ void lv_flush_callback(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *c
|
|||
// save pixels to file
|
||||
int32_t btw = (width * height * LV_COLOR_DEPTH + 7) / 8;
|
||||
while (btw > 0) {
|
||||
#if (LV_COLOR_DEPTH == 16) && (LV_COLOR_16_SWAP == 1)
|
||||
uint16_t * pix = (uint16_t*) color_p;
|
||||
for (uint32_t i = 0; i < btw / 2; i++) (pix[i] = pix[i] << 8 | pix[i] >> 8);
|
||||
#endif
|
||||
int32_t ret = glue->getScreenshotFile()->write((const uint8_t*) color_p, btw);
|
||||
if (ret >= 0) {
|
||||
btw -= ret;
|
||||
|
@ -314,7 +309,7 @@ void start_lvgl(const char * uconfig) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (uconfig && !renderer) {
|
||||
if (!renderer || uconfig) {
|
||||
#ifdef USE_UNIVERSAL_DISPLAY // TODO - we will probably support only UNIV_DISPLAY
|
||||
renderer = Init_uDisplay((char*)uconfig, -1);
|
||||
if (!renderer) return;
|
||||
|
@ -323,6 +318,8 @@ void start_lvgl(const char * uconfig) {
|
|||
#endif
|
||||
}
|
||||
|
||||
renderer->DisplayOnff(true);
|
||||
|
||||
// **************************************************
|
||||
// Initialize the glue between Adafruit and LVGL
|
||||
// **************************************************
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#define XDSP_17 17
|
||||
|
||||
|
||||
#include <uDisplay.h>
|
||||
|
||||
bool udisp_init_done = false;
|
||||
|
@ -52,6 +53,11 @@ void Core2DisplayDim(uint8_t dim);
|
|||
|
||||
//#define DSP_ROM_DESC
|
||||
|
||||
#ifndef DISP_DESC_FILE
|
||||
//#define DISP_DESC_FILE "/dispdesc.txt"
|
||||
#define DISP_DESC_FILE "/display.ini"
|
||||
#endif
|
||||
|
||||
/*********************************************************************************************/
|
||||
#ifdef DSP_ROM_DESC
|
||||
/* sample descriptor */
|
||||
|
@ -92,6 +98,7 @@ uDisplay *udisp;
|
|||
|
||||
Settings.display_model = XDSP_17;
|
||||
|
||||
|
||||
fbuff = (char*)calloc(DISPDESC_SIZE, 1);
|
||||
if (!fbuff) return 0;
|
||||
|
||||
|
@ -105,7 +112,7 @@ uDisplay *udisp;
|
|||
#ifdef USE_UFILESYS
|
||||
if (ffsp && !TasmotaGlobal.no_autoexec && !ddesc) {
|
||||
File fp;
|
||||
fp = ffsp->open("/dispdesc.txt", "r");
|
||||
fp = ffsp->open(DISP_DESC_FILE, "r");
|
||||
if (fp > 0) {
|
||||
uint32_t size = fp.size();
|
||||
fp.read((uint8_t*)fbuff, size);
|
||||
|
|
Loading…
Reference in New Issue