class Pigpio::SPI

Attributes

handle[R]
pi[R]

Public Class Methods

new(pi,spi_channel=0,enable_cex=1,baud=500000,bits_per_word: 8,first_MISO: false,first_MOSI: false,idol_bytes: 0,is_3wire: false,active_low_cex: 0,spi_mode: 0) click to toggle source
# File lib/pigpio/spi.rb, line 4
def initialize(pi,spi_channel=0,enable_cex=1,baud=500000,bits_per_word: 8,first_MISO: false,first_MOSI: false,idol_bytes: 0,is_3wire: false,active_low_cex: 0,spi_mode: 0)
  is_aux=(spi_channel!=0)
  flg=((spi_mode.to_i      & 0x03      ) |
     ((active_low_cex.to_i & 0x07 )<< 2) |
     ((enable_cex.to_i     & 0x07 )<< 5) |
     ((is_aux   ? 1 : 0) << 8) |
     ((is_3wire ? 1 : 0) << 9) |
     ((idol_bytes.to_i     & 0x0f )<< 10) |
     ((first_MOSI ? 1 : 0) << 14) |
     ((first_MISO ? 1 : 0) << 15) |
     ((bits_per_word.to_i  & 0x3f )<< 16)
    )
  @pi=pi
  @byte_per_word=(bits_per_word/8.0).ceil
  @handle=IF.spi_open(@pi,spi_channel,baud,flg)
end

Public Instance Methods

close() click to toggle source
# File lib/pigpio/spi.rb, line 20
def close
  IF.spi_close(@pi,@handle)
end
read(words=1) click to toggle source
# File lib/pigpio/spi.rb, line 23
def read(words=1)
  IF.spi_read(@pi,@handle,words*@byte_per_word)
end
write(buf) click to toggle source
# File lib/pigpio/spi.rb, line 26
def write(buf)
  IF.spi_write(@pi,@handle,buf)
end
xfer(buf) click to toggle source
# File lib/pigpio/spi.rb, line 29
def xfer(buf)
  IF.spi_xfer(@pi,@handle,buf)
end