• I am developing a module for the ST7735S display on the MStick-C and have managed to get fairly reasonable performance using only Javascript. The module supports the palletted graphics drawImage routine to avoid having to do complete screen updates - I will post how to access this soon.

    To reduce the overall storage requirement, images are unpalletted and written to the device in chunks. I want to reduce the amount of buffer allocation and use only one permanently allocated buffer which holds a chunk of 16bit pixel data to write to SPI in one operation. The problem I have is that the last chunk will in general be a fragment and so I would like to only write a part of the chunk buffer. I tried using ArrayView as follows:

     if (remnt>0){
         //remnt is the fragment size 
         var b =new Uint16Array(g.chunkbuf.buffer,0,remnt);       
         E.mapInPlace(new Uint8Array(img.buffer, chunks*CHUNKSIZE*img.bpp/8, remnt), b, img.palette, img.bpp);
         spi.write(b.buffer);
    }   
    

    This does not work as b.buffer is in fact g.chunkbuf.buffer and consequently, the spi.write sends the whole chunk buffer rather than part of it. I have had to resort to allocating a new buffer for fragments as in var b =new Uint16Array(remnt). This allocates a new buffer each time which I am concerned may lead to problems with storage allocation due to fragmentation. Have I missed something obvious as to how to solve this? Ideally, I would like spi.write() to have a size parameter.

  • This does not work as b.buffer is in fact g.chunkbuf.buffer and consequently, the spi.write sends the whole chunk buffer rather than part of it.

    Can't easily verify the spi.write since it does not return anyting but with spi.send it works as expected at least for nrf52. See this

    >var fc=new SPI();fc.setup({sck:D29,miso:D31,mosi:D3­0,mode:0});
    =undefined
    >fid=Uint8Array([0x9f,0,0,0])
    =new Uint8Array([159, 0, 0, 0])
    >fid2=Uint8Array(fid.buffer,0,2)
    =new Uint8Array([159, 0])
    >fc.send(fid,D27);
    =new Uint8Array([0, 133, 96, 21])
    >fc.send(fid2,D27);
    =new Uint8Array([0, 133])
    

    so it can be seen only two bytes are sent in second case. Maybe don't use spi.write(b.buffer); but spi.write(b); ?

About

Avatar for jeffmer @jeffmer started