From 8528aca0e43d5267a070986aae8172e2c123d20d Mon Sep 17 00:00:00 2001 From: Yves BAZIN Date: Tue, 9 May 2023 09:54:43 +0200 Subject: [PATCH 1/2] hardware rotation --- library.json | 2 +- src/I2SClocklessVirtualLedDriver.h | 43 +++++++++++++++--------------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/library.json b/library.json index bfe2031..bae890c 100755 --- a/library.json +++ b/library.json @@ -8,7 +8,7 @@ "type": "git", "url": "https://github.com/hpwit/I2SClocklessVirtualLedDriver" }, - "version": "1.0.0", + "version": "1.0.X", "frameworks": "arduino", "platforms": "*" } diff --git a/src/I2SClocklessVirtualLedDriver.h b/src/I2SClocklessVirtualLedDriver.h index 26f1a05..c7f774f 100644 --- a/src/I2SClocklessVirtualLedDriver.h +++ b/src/I2SClocklessVirtualLedDriver.h @@ -360,6 +360,7 @@ class I2SClocklessVirtualLedDriver volatile xSemaphoreHandle I2SClocklessVirtualLedDriver_sem = NULL; volatile xSemaphoreHandle I2SClocklessVirtualLedDriver_semSync = NULL; volatile xSemaphoreHandle I2SClocklessVirtualLedDriver_semDisp = NULL; + volatile xSemaphoreHandle I2SClocklessVirtualLedDriver_waitDisp = NULL; frameBuffer * framebuff; bool useFrame=false; #ifdef __HARDWARE_MAP @@ -974,13 +975,13 @@ void showPixels(OffsetDisplay offdisp) { if(isDisplaying == true and __displayMode==NO_WAIT) { - ESP_LOGI(TAG, "already displaying"); - long t1=ESP.getCycleCount(); + ESP_LOGD(TAG, "already displaying"); + // long t1=ESP.getCycleCount(); wasWaitingtofinish = true; - if(I2SClocklessVirtualLedDriver_semDisp==NULL) - I2SClocklessVirtualLedDriver_semDisp = xSemaphoreCreateBinary(); - const TickType_t xDelay = 50 ; //to avoid full blocking - xSemaphoreTake(I2SClocklessVirtualLedDriver_semDisp, xDelay); + if(I2SClocklessVirtualLedDriver_waitDisp==NULL) + I2SClocklessVirtualLedDriver_waitDisp = xSemaphoreCreateCounting(10,0); + const TickType_t xDelay = 100 ; //to avoid full blocking + xSemaphoreTake(I2SClocklessVirtualLedDriver_waitDisp, xDelay); //printf("on retourne %ld\n",(ESP.getCycleCount()-t1)/240000); } @@ -1003,13 +1004,13 @@ void showPixels(OffsetDisplay offdisp) if(isDisplaying == true and __displayMode==NO_WAIT) { - ESP_LOGI(TAG, "already displaying"); - long t1=ESP.getCycleCount(); + ESP_LOGD(TAG, "already displaying"); + // long t1=ESP.getCycleCount(); wasWaitingtofinish = true; - if(I2SClocklessVirtualLedDriver_semDisp==NULL) - I2SClocklessVirtualLedDriver_semDisp = xSemaphoreCreateBinary(); - const TickType_t xDelay = 50 ; //to avoid full blocking - xSemaphoreTake(I2SClocklessVirtualLedDriver_semDisp, xDelay); + if(I2SClocklessVirtualLedDriver_waitDisp==NULL) + I2SClocklessVirtualLedDriver_waitDisp = xSemaphoreCreateCounting(10,0); + const TickType_t xDelay = 100 ; //to avoid full blocking + xSemaphoreTake(I2SClocklessVirtualLedDriver_waitDisp, xDelay); //printf("on retourne %ld\n",(ESP.getCycleCount()-t1)/240000); } @@ -1035,15 +1036,15 @@ void showPixels(OffsetDisplay offdisp) //printf("number:%d\n",NBIS2SERIALPINS); //code for the sprite //printf("core ID:%d\n",xPortGetCoreID()); - if (dispmode == NO_WAIT && isDisplaying == true) + if (__displayMode == NO_WAIT && isDisplaying == true) { - ESP_LOGI(TAG, "already displaying in show"); + ESP_LOGD(TAG, "already displaying in show"); //return; wasWaitingtofinish = true; - if(I2SClocklessVirtualLedDriver_semDisp==NULL) - I2SClocklessVirtualLedDriver_semDisp = xSemaphoreCreateBinary(); - const TickType_t xDelay = 50 ; //to avoid full blocking - xSemaphoreTake(I2SClocklessVirtualLedDriver_semDisp, xDelay); + if(I2SClocklessVirtualLedDriver_waitDisp==NULL) + I2SClocklessVirtualLedDriver_waitDisp = xSemaphoreCreateCounting(10,0); + const TickType_t xDelay = 100 ; //to avoid full blocking + xSemaphoreTake(I2SClocklessVirtualLedDriver_waitDisp, xDelay); //printf("one re\n"); } #ifdef __HARDWARE_MAP @@ -1592,7 +1593,7 @@ void calculateMapping(OffsetDisplay off) cont->i2sReset(); cont->isDisplaying = false; - cont->leds=cont->saveleds; + // cont->leds=cont->saveleds; /* We have finished to display the strips */ @@ -1600,7 +1601,7 @@ void calculateMapping(OffsetDisplay off) if(cont->__displayMode==NO_WAIT and cont->wasWaitingtofinish == true) { cont->wasWaitingtofinish=false; - xSemaphoreGive(cont->I2SClocklessVirtualLedDriver_semDisp); + xSemaphoreGive(cont->I2SClocklessVirtualLedDriver_waitDisp); } if (cont->isWaiting) { @@ -2485,4 +2486,4 @@ Lines firstPixel[nb_components]; -} +} \ No newline at end of file From bb52c35bbe88b2461f3c216aae890959b8cb84a4 Mon Sep 17 00:00:00 2001 From: Yves BAZIN Date: Wed, 10 May 2023 14:57:02 +0200 Subject: [PATCH 2/2] version 2.0 --- Releasenote.md | 5 + src/I2SClocklessVirtualLedDriver.h | 231 +++++++++++++++-------------- 2 files changed, 124 insertions(+), 112 deletions(-) create mode 100644 Releasenote.md diff --git a/Releasenote.md b/Releasenote.md new file mode 100644 index 0000000..9b02437 --- /dev/null +++ b/Releasenote.md @@ -0,0 +1,5 @@ +##Release Note 10 May 2023 v2.0.0 +* adding the scrolling,scalling, rotation +* correcting the management of the NO_WAIT +* Code simplification +* minor bug fixes diff --git a/src/I2SClocklessVirtualLedDriver.h b/src/I2SClocklessVirtualLedDriver.h index c7f774f..7e34524 100644 --- a/src/I2SClocklessVirtualLedDriver.h +++ b/src/I2SClocklessVirtualLedDriver.h @@ -364,15 +364,16 @@ class I2SClocklessVirtualLedDriver frameBuffer * framebuff; bool useFrame=false; #ifdef __HARDWARE_MAP - uint16_t * _hmap; + uint16_t * _hmap,*_defaulthmap; volatile uint16_t * _hmapoff; void setHmap( uint16_t * map) { - _hmap=map; + _defaulthmap=map; } + #ifdef _HARDWARE_SCROLL_MAP uint16_t * _hmapscroll; - uint16_t * _hmaptmp; + //uint16_t * _hmaptmp; #endif #endif @@ -871,10 +872,26 @@ class I2SClocklessVirtualLedDriver } */ + void waitDisplay() + { + if(isDisplaying == true and __displayMode==NO_WAIT) + { + wasWaitingtofinish = true; + ESP_LOGD(TAG, "already displaying... wait"); + if(I2SClocklessVirtualLedDriver_waitDisp==NULL) + { + I2SClocklessVirtualLedDriver_waitDisp = xSemaphoreCreateCounting(10,0); + } + const TickType_t xDelay = 50 ; + xSemaphoreTake(I2SClocklessVirtualLedDriver_waitDisp,xDelay); + + } + } + - void showPixels(displayMode dispmode, OffsetDisplay offdisp) - { - #ifdef __HARDWARE_MAP +void calculateOffsetDisplay(OffsetDisplay offdisp) +{ + #ifdef __HARDWARE_MAP if(offdisp.image_width==0 or offdisp.image_width==30000 ) { offdisp.image_width=offdisp.panel_width; @@ -915,10 +932,11 @@ class I2SClocklessVirtualLedDriver offdisp._scallingy= 16/ offdisp.scallingy; // Serial.println(offdisp._cos); _offsetDisplay = offdisp; + _hmap=_defaulthmap; #ifdef _HARDWARE_SCROLL_MAP calculateMapping2(offdisp); - _hmaptmp=_hmap; + _hmap= _hmapscroll; #else @@ -927,97 +945,87 @@ class I2SClocklessVirtualLedDriver #endif #endif - showPixels(dispmode); - #ifdef _HARDWARE_SCROLL_MAP - _hmap=_hmaptmp; - #endif - // calculateMapping(_defaultOffsetDisplay); - _offsetDisplay = _defaultOffsetDisplay; + #endif +} + + void showPixels(displayMode dispmode, OffsetDisplay offdisp) + { + waitDisplay(); + #ifdef __HARDWARE_MAP + calculateOffsetDisplay(offdisp); + __displayMode=dispmode; + leds=saveleds; + __showPixels(); #endif } - /* - Show pixel circular - */ - /* - void showPixels(uint8_t *new_leds,int offsett) - { - startleds=offsett; - showPixels(new_leds); - startleds=0; - } - - void showPixels(int offsett) - { - startleds=offsett; - showPixels(); - startleds=0; - } - */ - - /* - Show pixels classiques - */ void showPixels(uint8_t *newleds) { - //uint8_t *tmp_leds; - // tmp_leds = leds; + + waitDisplay(); + #ifdef __HARDWARE_MAP + _hmap=_defaulthmap; + #endif + leds = newleds; - showPixels(); - //leds = tmp_leds; + __displayMode=WAIT; + _offsetDisplay=_defaultOffsetDisplay; + __showPixels(); + } void showPixels(OffsetDisplay offdisp) { - showPixels(WAIT,offdisp); + waitDisplay(); + #ifdef __HARDWARE_MAP + calculateOffsetDisplay(offdisp); + #endif + + leds = saveleds; + __displayMode=WAIT; + _offsetDisplay=offdisp; + __showPixels(); } void showPixels(displayMode dispmode,uint8_t *newleds,OffsetDisplay offd) { - if(isDisplaying == true and __displayMode==NO_WAIT) - { - ESP_LOGD(TAG, "already displaying"); - // long t1=ESP.getCycleCount(); - wasWaitingtofinish = true; - if(I2SClocklessVirtualLedDriver_waitDisp==NULL) - I2SClocklessVirtualLedDriver_waitDisp = xSemaphoreCreateCounting(10,0); - const TickType_t xDelay = 100 ; //to avoid full blocking - xSemaphoreTake(I2SClocklessVirtualLedDriver_waitDisp, xDelay); - //printf("on retourne %ld\n",(ESP.getCycleCount()-t1)/240000); - } - - //uint8_t *tmp_leds; - //tmp_leds = leds; - // leds = newleds; - leds = newleds; - showPixels(dispmode,offd); + waitDisplay(); + #ifdef __HARDWARE_MAP + calculateOffsetDisplay(offd); + __displayMode=dispmode; + leds=newleds; + __showPixels(); + // calculateMapping(_defaultOffsetDisplay); + // _offsetDisplay = _defaultOffsetDisplay; + #endif } void showPixels(uint8_t *newleds,OffsetDisplay offd) { - leds = newleds; - showPixels(WAIT,offd); + waitDisplay(); + #ifdef __HARDWARE_MAP + calculateOffsetDisplay(offd); + __displayMode=WAIT; + leds=newleds; + __showPixels(); + // calculateMapping(_defaultOffsetDisplay); + // _offsetDisplay = _defaultOffsetDisplay; + #endif } void showPixels(displayMode dispmode,uint8_t *newleds) { //printf("je tente display\n"); - if(isDisplaying == true and __displayMode==NO_WAIT) - { - ESP_LOGD(TAG, "already displaying"); - // long t1=ESP.getCycleCount(); - wasWaitingtofinish = true; - if(I2SClocklessVirtualLedDriver_waitDisp==NULL) - I2SClocklessVirtualLedDriver_waitDisp = xSemaphoreCreateCounting(10,0); - const TickType_t xDelay = 100 ; //to avoid full blocking - xSemaphoreTake(I2SClocklessVirtualLedDriver_waitDisp, xDelay); - //printf("on retourne %ld\n",(ESP.getCycleCount()-t1)/240000); - } - + waitDisplay(); //uint8_t *tmp_leds; //tmp_leds = leds; + #ifdef __HARDWARE_MAP + _hmap=_defaulthmap; + #endif leds = newleds; - showPixels(dispmode); + __displayMode=dispmode; + _offsetDisplay=_defaultOffsetDisplay; + __showPixels(); //leds = tmp_leds; } @@ -1029,24 +1037,20 @@ void showPixels(OffsetDisplay offdisp) showPixels(NO_WAIT,framebuff->getFrametoDisplay()); } else - showPixels(WAIT); + { + waitDisplay(); + leds = saveleds; + __displayMode=WAIT; + _offsetDisplay=_defaultOffsetDisplay; + __showPixels(); + } } - void showPixels(displayMode dispmode) + + + void __showPixels() { -//printf("number:%d\n",NBIS2SERIALPINS); -//code for the sprite -//printf("core ID:%d\n",xPortGetCoreID()); - if (__displayMode == NO_WAIT && isDisplaying == true) - { - ESP_LOGD(TAG, "already displaying in show"); - //return; - wasWaitingtofinish = true; - if(I2SClocklessVirtualLedDriver_waitDisp==NULL) - I2SClocklessVirtualLedDriver_waitDisp = xSemaphoreCreateCounting(10,0); - const TickType_t xDelay = 100 ; //to avoid full blocking - xSemaphoreTake(I2SClocklessVirtualLedDriver_waitDisp, xDelay); - //printf("one re\n"); - } + + #ifdef __HARDWARE_MAP _hmapoff=_hmap; @@ -1090,11 +1094,11 @@ void showPixels(OffsetDisplay offdisp) #else loadAndTranspose2(leds, ledsstrips, (uint16_t *)DMABuffersTampon[0]->buffer, ledToDisplay, __green_map, __red_map, __blue_map, __white_map); #endif - __displayMode=dispmode; + //__displayMode=dispmode; dmaBufferActive = 1; isDisplaying = true; i2sStart(DMABuffersTampon[2]); - if (dispmode == WAIT) + if (__displayMode == WAIT) { isWaiting = true; if( I2SClocklessVirtualLedDriver_sem==NULL) @@ -1221,9 +1225,9 @@ void calculateMapping2(OffsetDisplay off) uint16_t offset2=0; for(uint16_t leddisp=0;leddispleds = leds; this->saveleds = leds; @@ -1453,8 +1458,8 @@ void calculateMapping(OffsetDisplay off) #endif #ifdef __HARDWARE_MAP - _hmap=(uint16_t *)malloc( NUM_LEDS_PER_STRIP * NBIS2SERIALPINS * 8 * 2+2); - if(!_hmap) + _defaulthmap=(uint16_t *)malloc( NUM_LEDS_PER_STRIP * NBIS2SERIALPINS * 8 * 2+2); + if(!_defaulthmap) { Serial.printf("no memory\n"); } @@ -1514,7 +1519,7 @@ void calculateMapping(OffsetDisplay off) //private: volatile int dmaBufferActive = 0; volatile bool wait; - displayMode __displayMode; + displayMode __displayMode,__defaultDisplayMode; volatile int ledToDisplay; // volatile int oo=0; uint8_t *leds,*saveleds; @@ -1705,6 +1710,8 @@ void calculateMapping(OffsetDisplay off) // static void IRAM_ATTR interruptHandler(void *arg); }; + + static void IRAM_ATTR _I2SClocklessVirtualLedDriverinterruptHandler(void *arg) {