Avatar for JumJum

JumJum

Member since Oct 2013 • Last active Dec 2018
  • 116 conversations
  • 584 comments

Most recent activity

  • in ESP32
    Avatar for JumJum

    Sorry, no bell is ringing on that.
    Could be in there from beginning by nkolban ?

  • in JavaScript
    Avatar for JumJum

    Last not least, flickering is gone.
    Surrounded jsvIterateCallback with rtos commands to switch taskhandling off

    vTaskSuspendAll();
      jsvIterateCallback(data, allFast ? jswrap_io_shiftOutCallbackFast : jswrap_io_shiftOutCallback, &d);
    xTaskResumeAll();
    

    Actual status, compared to direct_io branch is:

    • switched fast io off (return false in jshGetPinAddress)
    • switched task handling off during jsvIterateCallback
    • moved en.set() and en.reset() from js(g.scan) to be set in arr

    Latest next week, I'll send a request with all changes to direct_io branch.
    Open questions:

    • how do we call task relevant RTOS function ? We could use #ifdef ESP32 or #ifdef RTOS. I would prefer the 2nd one.
    • do we need jshIsPinValid(d->pins[n]) in jswrap_io_shiftOutCallback ? Isn't this already done in jswrap_io_shiftOut ?
  • in JavaScript
    Avatar for JumJum

    Success, but once again I've only an idea of an idea why, but it works.
    Removed en.reset() and en.set() from g.scan
    Pushed {callback:en.reset.bind(en)} as first entry into arr,
    Pushed {callback:en.set.bind(en)} as last entry into arr
    Due to this, lines 15 and 31 have same brightness as all others.

  • in JavaScript
    Avatar for JumJum

    arr.push({callback:en.set.bind(en)});
    fixes in the wrong direction, we get dark line 15/31
    Timing is a very special for the P3 board

  • in JavaScript
    Avatar for JumJum

    I use the direct_io branch, and love the changes.
    In my local copy, I changed the fast function to use jsh_PinSetValue instead of using GPIO-Register.
    Flickering could be because of task management in RTOS
    Agree to slowness of a JS-Solution, and will take a closer look to g.flip

  • in JavaScript
    Avatar for JumJum

    Believe me, the world is absolutely crazy.
    First of all, its much faster, I've been down close to 10 ms.
    Bad news, upper 16 rows are always green and lower 16 rows are white.
    Whatever I tried, there was no way to get this running. Even hardcode the colour did not help.

    After a lot of frustration, I went back to setting pins with jshPinSetValue, and surprise surprise, now it works.
    Looks to me like having a timing problem.
    Good news is, time for scan is 13 ms now, which is still really fast.
    What we don't have is brightness. Line 16 and 32 are much brighter than others.
    And brightness is flickering.
    This also looks like a timing problem.

    Anyway, my next step will be to create a graphics driver, using Graphics.createCallback to get rid of prep step.

  • in JavaScript
    Avatar for JumJum

    I tested with latest direct_io branch, see my code
    First checked speed, which is really fast, came down to 18msec/scan :-)
    Up to this everything was fine

    var led;
    connect2 = function(R1,R2,B1,B2,G1,G2,A,B,C,D,Latch­,Clock,Enable) {
      var sfnc = shiftOut.bind(null,[R1,G1,B1,R2,G2,B2],{­clk:Clock});
      var dfnc = digitalWrite.bind(null,[Enable,Latch,Lat­ch,D,C,B,A,Enable]);
    
      var en = Enable;
      var g = Graphics.createArrayBuffer(64,32,4);
      var buf = g.buffer;
      var ledBuf = new Uint8Array(64 * 32 / 2);//converted graphics.buffer to data for LED
      var arr = [];
      g.prep = function() {
        var bufpnt1,bufpnt2,ledpnt;
        bufpnt1 = 0; bufpnt2 = 512; ledpnt = 0;
        var pane = false,i,j;
        for(i = 0; i < 16; i++){
          for(j = 0; j < 64;j +=2){
            ledBuf[ledpnt] = (buf[bufpnt2] & 7) + ((buf[bufpnt1] & 7)<<3);
            ledpnt++;
            ledBuf[ledpnt] = ((buf[bufpnt2] & 0xf0) >>4) + ((buf[bufpnt1] & 0xf0)>>1);
            ledpnt++;
            bufpnt1++;
            bufpnt2++;
          }
        }
        arr = [];
        for(var y=0; y < 16;y++){
          arr.push(new Uint8Array(ledBuf.buffer,y*64,64));
          arr.push({callback:dfnc.bind(null,33|y<<­1)});
        }
      };
      g.scan = function() {
        en.reset();
        sfnc(arr);
        en.set();
      };
      g.setBgColor(1);
      g.clear();
      g.setColor(2);
      g.fillRect(5,12,50,25);
      g.setColor(4);
      g.fillRect(10,14,40,20);
      g.fillRect(10,0,40,0);
      return g;
    };
    function tst(){
      led = connect2(D2,D16,D4,D17,D15,D27, D5,D18,D19,D21, D26,D22,D25);
      if(led.prep) led.prep();
      var t=getTime();
      led.scan();
      print((getTime()-t) * 1000);
    }
    

    Next tried to work with graphics and whatever I did, panel displays something different. :-(
    During testing I added some printf's here and there
    First confusing was how often jswrap_io_shiftOutCallbackFast was called. My expectation was 1024, but the counter I added returns 8704
    Counter was added like this

    int xx = 0;
    void jswrap_io_shiftOutCallbackFast(int val, void *data) {
    xx++;
      jswrap_io_shiftOutData *d = (jswrap_io_shiftOutData*)data;
      int n, i;
      for (i=0;i<d->repeat;i++) {
    .....
    void jswrap_io_shiftOut(JsVar *pins, JsVar *options, JsVar *data) {
    xx = 0;
      jswrap_io_shiftOutData d;
      d.cnt = 0;
      d.clk = PIN_UNDEFINED;
    .......
      // Now run through the data, pushing it out
      jsvIterateCallback(data, allFast ? jswrap_io_shiftOutCallbackFast : jswrap_io_shiftOutCallback, &d);
    printf("xx:%d\n",xx);
    }
    

    Checking jsvIterateCallback was next step, some more printf like this in
    BTW, this is the short version of a long story, ....

      // Handle the data being an array buffer
      else if (jsvIsArrayBuffer(data)) {
    jsWarn("ArrayBuffer:%j\n",data);
        JsvArrayBufferIterator it;
        jsvArrayBufferIteratorNew(&it, data, 0);
    jsWarn("byteLength:%d\n",it.byteLength);­
        if (JSV_ARRAYBUFFER_GET_SIZE(it.type) == 1 && !JSV_ARRAYBUFFER_IS_SIGNED(it.type)) {
          JsvStringIterator *sit = &it.it;
    
    

    See log, Sum of all byteLength gives exactly 8704, which is the number how often callbackFast is called.
    Here we reach the point where the story is beyond my knowledge. Hope you can help.

    tst()
    WARNING: ArrayBuffer:new Uint8Array([9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9])
    WARNING: byteLength:64
    WARNING: ArrayBuffer:new Uint8Array([9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9])
    WARNING: byteLength:128
    WARNING: ArrayBuffer:new Uint8Array([9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9])
    WARNING: byteLength:192
    WARNING: ArrayBuffer:new Uint8Array([9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9])
    WARNING: byteLength:256
    WARNING: ArrayBuffer:new Uint8Array([9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9])
    WARNING: byteLength:320
    WARNING: ArrayBuffer:new Uint8Array([9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9])
    WARNING: byteLength:384
    WARNING: ArrayBuffer:new Uint8Array([9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9])
    WARNING: byteLength:448
    WARNING: ArrayBuffer:new Uint8Array([9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9])
    WARNING: byteLength:512
    WARNING: ArrayBuffer:new Uint8Array([9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9])
    WARNING: byteLength:576
    WARNING: ArrayBuffer:new Uint8Array([9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9])
    WARNING: byteLength:640
    WARNING: ArrayBuffer:new Uint8Array([9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9])
    WARNING: byteLength:704
    WARNING: ArrayBuffer:new Uint8Array([9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9])
    WARNING: byteLength:768
    WARNING: ArrayBuffer:new Uint8Array([9, 9, 9, 9, 9, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9])
    WARNING: byteLength:832
    WARNING: ArrayBuffer:new Uint8Array([9, 9, 9, 9, 9, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9])
    WARNING: byteLength:896
    WARNING: ArrayBuffer:new Uint8Array([9, 9, 9, 9, 9, 17, 17, 17, 17, 17, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9])
    WARNING: byteLength:960
    WARNING: ArrayBuffer:new Uint8Array([9, 9, 9, 9, 9, 17, 17, 17, 17, 17, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9])
    WARNING: byteLength:1024
    xx:8704

  • in JavaScript
    Avatar for JumJum

    push data out is jsvIterateCallback(data, allFast.....

    I'll check it soon.

    even in BytePort you had to grab the binary data out of a variable each call
    Thats correct, but no need to grab pins, set them to output, calculate mask, ... on each call
    Just tinking, binary data, couldn't this be added to initialization, and we only have to set a pointer ? Or would this cause problems if jsvars are restructured ?, hmmm
    Anyway, we got some speed in a lot of places (I2C, SPI, ....)
    And the way you use an array to avoid executing JS, very interesting.

  • in JavaScript
    Avatar for JumJum

    First of all, duplicating a function under a different name was not my intention.
    The idea was, on a long term, to mark shiftOut and digitalWrite as deprecated and replace it with something like bytePort. The example for bytePort includes an option to have default handling and familiy specific handling. At least, this is the idea. And it is faster in sending data.
    To get a better understanding of where time is going, I tested duration of the scan loop, and switched off one part after the other in source from the branch Gordon posted.
    This is the result, looks like shifting out data is fast, but preparing options and GPIOs takes a lot of time. At least for ESP32.

    scan loop XXXXXXXX
      shiftout Data(sfnc) XXXXXXX
          set options for internal use XXXXXX
      set array of pins XXXXX
      assign output, and pin mask XXXX
      set clock XXX
      push data out XX
     set row address(dfnc) X
    duration(msec) 25,300 18,160 14,350 13,820 11,090 9,290 6,780 3,810
Actions