• Ooops, missed the SPI part, sorry.
    If you search for SPI in the docs, you get all the modules that use SPI, and you can look at the code.

    For example from the LIS2DH12 that has SPI interface as well (at the bottom of the file):

    exports.connectSPI = function(spi,cs,options) {
      if ("function"==typeof options)
        throw new Error("Use require(LIS2DH12).connectSPI(..., {callback:function() { ... }} instead");
      return new LIS2DH12(function(reg,len) { // read
        return spi.send([reg|0xC0,new Uint8Array(len)], cs).slice(1);
      }, function(reg,data) { // write
        return spi.write(reg, data, cs);
      },options);
    };
    

    The interesting part:

    // reg - the register address
    // len - how many bytes to read
    function read(reg,len) {
        return spi.send([reg|0xC0,new Uint8Array(len)], cs).slice(1);
     }
    
    // reg - the register address
    // data - the data you want to send
    function write(reg,data) {
        return spi.write(reg, data, cs);
      }
    
About

Avatar for AkosLukacs @AkosLukacs started