Class: Pigpio::SPI
- Inherits:
-
Object
- Object
- Pigpio::SPI
- Defined in:
- lib/pigpio/spi.rb
Instance Attribute Summary collapse
-
#handle ⇒ Object
readonly
Returns the value of attribute handle.
-
#pi ⇒ Object
readonly
Returns the value of attribute pi.
Instance Method Summary collapse
- #close ⇒ Object
-
#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) ⇒ SPI
constructor
A new instance of SPI.
- #read(words = 1) ⇒ Object
- #write(buf) ⇒ Object
- #xfer(buf) ⇒ Object
Constructor Details
#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) ⇒ SPI
Returns a new instance of SPI.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# 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 |
Instance Attribute Details
#handle ⇒ Object (readonly)
Returns the value of attribute handle.
3 4 5 |
# File 'lib/pigpio/spi.rb', line 3 def handle @handle end |
#pi ⇒ Object (readonly)
Returns the value of attribute pi.
3 4 5 |
# File 'lib/pigpio/spi.rb', line 3 def pi @pi end |
Instance Method Details
#close ⇒ Object
21 22 23 |
# File 'lib/pigpio/spi.rb', line 21 def close IF.spi_close(@pi, @handle) end |
#read(words = 1) ⇒ Object
25 26 27 |
# File 'lib/pigpio/spi.rb', line 25 def read(words = 1) IF.spi_read(@pi, @handle, words * @byte_per_word) end |