Skip to content

Commit

Permalink
WIP I2C read - #10
Browse files Browse the repository at this point in the history
  • Loading branch information
jwhitehorn committed Sep 14, 2013
1 parent dea1b48 commit ea6a3f4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/pi_piper/bcm2835.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def self.pin_read(pin)
attach_function :i2c_write, :bcm2835_i2c_write, [:pointer, :uint], :uint8
attach_function :i2c_set_address,:bcm2835_i2c_setSlaveAddress, [:uint8], :void
attach_function :i2c_set_clock_divider, :bcm2835_i2c_setClockDivider, [:uint16], :void
attach_function :i2c_read, :bcm2835_i2c_read, [:pointer, :uint], :uint8

def self.i2c_allowed_clocks
[100.kilohertz,
Expand All @@ -84,5 +85,12 @@ def self.i2c_transfer_bytes(data)
i2c_write data_out, data.count
end

def self.i2c_read_bytes(bytes)
data_in = FFI::MemoryPointer.new(bytes)
i2c_read(data_in, bytes) #TODO reason codes

(0..bytes-1).map { |i| data_in.get_uint8(i) }
end

end
end
4 changes: 4 additions & 0 deletions lib/pi_piper/i2c.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def write(params)
Platform.driver.i2c_transfer_bytes data
end

def read(bytes)
Platform.driver.i2c_read_bytes(bytes)
end

end

end

0 comments on commit ea6a3f4

Please sign in to comment.