i2c 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc ADDED
@@ -0,0 +1,59 @@
1
+ = I2C - Ruby I2C library
2
+
3
+ == About
4
+
5
+ Interface to Linux I2C (a.k.a. TWI) implementations. Right now targeted at the
6
+ Raspberry Pi, but should work with any linux i2c-dev I2C-hardware.
7
+
8
+ == Structure
9
+
10
+ The library is split into two parts:
11
+ - A backend for accessing the I2C bus (right now only through the i2c-dev
12
+ in Linux, other impementations are possible).
13
+ - Drivers for I2C enabled ICs.
14
+
15
+ == Installation
16
+
17
+ To use the i2c-dev backend it is necessary to load the "i2c-dev" linux
18
+ kernel module. This is not done automatically even if the module for the
19
+ underlying I2C-hardware is. To automatically load the i2c-dev driver on startup
20
+ add it to /etc/modules. Also the device file (usually /dev/i2c-0) must be
21
+ user accessible. A working (at least on a RaspberryPi running Raspbian) udev
22
+ rule file is available (rules/88-i2c.rules) and can be installed to
23
+ /etc/udev/rules.d/.
24
+
25
+ == Backends
26
+
27
+ The backends are instantiated through the #I2C::create method. depending
28
+ on the format of the passed bus descriptor the correct backend is invoked.
29
+
30
+ Right now there is only a i2c-dev backend available
31
+
32
+ === i2c-dev Backend
33
+
34
+ Backend for the Linux I2C implementation. Accepts device file names as
35
+ bus descriptors. E.g.
36
+
37
+ I2C.create("/dev/i2c-0") returns an instance of I2C::Dev attached to the
38
+ first I2c bus on the system.
39
+
40
+ == Drivers
41
+
42
+ === MCP23017
43
+
44
+ 16bit IO-Expander MCP23017 from Microchip. Provides a wiringpi-ruby compatible
45
+ API and may therefore be used as a drop-in replacement for IO tasks on a
46
+ Raspberry Pi. Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/21952b.pdf
47
+
48
+ == Acknowledgements
49
+
50
+ The low-level IO (mainly in i2c-dev.rb) was extracted from Ruby-I2C
51
+ (http://rubyforge.org/projects/i2c/) by Jonas Bähr <jonas.baehr@fs.ei.tum.de>
52
+
53
+ == Legal stuff
54
+
55
+ This code may be used under the terms of the GNU General Public Licence, Version 2.
56
+
57
+ Copyright (c) 2012 Christoph Anderegg <christoph@christoph-anderegg.ch>
58
+ Copyright (c) 2008 Jonas Bähr, jonas.baehr@fs.ei.tum.de
59
+
data/lib/i2c.rb CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  require 'i2c/i2c.rb'
10
10
  require 'i2c/backends/i2c-dev.rb'
11
- require 'i2c/drivers/mcp17026.rb'
11
+ require 'i2c/drivers/mcp23017.rb'
12
12
 
13
13
 
14
14
 
@@ -22,7 +22,7 @@ LOW = 0
22
22
 
23
23
  module I2C
24
24
  module Drivers
25
- class MCP17026
25
+ class MCP23017
26
26
  # Registers
27
27
  IODIRA = 0x00
28
28
  IODIRB = 0x01
@@ -30,7 +30,7 @@ module I2C
30
30
  GPIOB = 0x13
31
31
 
32
32
  # Creates an instance representing exactly one
33
- # MCP17026 on one I2C-bus.
33
+ # MCP23017 on one I2C-bus.
34
34
  #
35
35
  # device: I2C-device file (usually /dev/i2c-0).
36
36
  # Or an intantiated io class that supports
@@ -1,8 +1,6 @@
1
1
  require 'i2c'
2
- #require 'mock/mock_i2c_io.rb'
3
2
 
4
3
  class MockI2CIO
5
-
6
4
  attr_reader :registers
7
5
  attr_reader :last_address
8
6
 
@@ -43,48 +41,48 @@ class MockI2CIO
43
41
  end
44
42
  end
45
43
 
46
- describe I2C::Drivers::MCP17026, "#mode?" do
44
+ describe I2C::Drivers::MCP23017, "#mode?" do
47
45
  it "initially returns 1 for all pin modes" do
48
46
  io = MockI2CIO.new
49
- mcp17026 = I2C::Drivers::MCP17026.new(io, 0x20)
47
+ mcp17026 = I2C::Drivers::MCP23017.new(io, 0x20)
50
48
  (0..15).each do |pin|
51
49
  mcp17026.mode?(pin).should eq(1)
52
50
  end
53
51
  end
54
52
  end
55
53
 
56
- describe I2C::Drivers::MCP17026, "#mode?" do
54
+ describe I2C::Drivers::MCP23017, "#mode?" do
57
55
  it "returns what has been set through #mode" do
58
56
  io = MockI2CIO.new
59
- mcp17026 = I2C::Drivers::MCP17026.new(io, 0x20)
57
+ mcp23017 = I2C::Drivers::MCP23017.new(io, 0x20)
60
58
  (0..500).each do |pin|
61
59
  pin = rand(16)
62
60
  mode = rand(2)
63
- mcp17026.mode(pin, mode)
64
- mcp17026.mode?(pin).should eq(mode)
61
+ mcp23017.mode(pin, mode)
62
+ mcp23017.mode?(pin).should eq(mode)
65
63
  end
66
64
  end
67
65
  end
68
66
 
69
- describe I2C::Drivers::MCP17026, "#[]" do
67
+ describe I2C::Drivers::MCP23017, "#[]" do
70
68
  it "initially returns 0 for all I/O pins" do
71
69
  io = MockI2CIO.new
72
- mcp17026 = I2C::Drivers::MCP17026.new(io, 0x20)
70
+ mcp23017 = I2C::Drivers::MCP23017.new(io, 0x20)
73
71
  (0..15).each do |pin|
74
- mcp17026[pin].should eq(0)
72
+ mcp23017[pin].should eq(0)
75
73
  end
76
74
  end
77
75
  end
78
76
 
79
- describe I2C::Drivers::MCP17026, "#[]" do
77
+ describe I2C::Drivers::MCP23017, "#[]" do
80
78
  it "returns what has been set through #[]=" do
81
79
  io = MockI2CIO.new
82
- mcp17026 = I2C::Drivers::MCP17026.new(io, 0x20)
80
+ mcp23017 = I2C::Drivers::MCP23017.new(io, 0x20)
83
81
  (0..500).each do |pin|
84
82
  pin = rand(16)
85
83
  value = rand(2)
86
- mcp17026[pin] = value
87
- mcp17026[pin].should eq(value)
84
+ mcp23017[pin] = value
85
+ mcp23017[pin].should eq(value)
88
86
  end
89
87
  end
90
88
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i2c
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,18 +11,21 @@ bindir: bin
11
11
  cert_chain: []
12
12
  date: 2012-08-03 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: Interface to Linux I2C (a.k.a. TWI) implementations.
14
+ description: Interface to I2C (aka TWI) implementations. Also provides abstractions
15
+ for some I2c-devices. Created with the Raspberry Pi in mind.
15
16
  email: christoph@christoph-anderegg.ch
16
17
  executables: []
17
18
  extensions: []
18
- extra_rdoc_files: []
19
+ extra_rdoc_files:
20
+ - README.rdoc
19
21
  files:
20
22
  - lib/i2c.rb
21
23
  - lib/i2c/i2c.rb
22
24
  - lib/i2c/backends/i2c-dev.rb
23
- - lib/i2c/drivers/mcp17026.rb
24
- - test//mcp17026_spec.rb
25
+ - lib/i2c/drivers/mcp23017.rb
26
+ - test//mcp23017_spec.rb
25
27
  - rules/88-i2c.rules
28
+ - README.rdoc
26
29
  homepage: https://github.com/andec/i2c
27
30
  licenses: []
28
31
  post_install_message:
@@ -46,5 +49,5 @@ rubyforge_project:
46
49
  rubygems_version: 1.8.24
47
50
  signing_key:
48
51
  specification_version: 3
49
- summary: I2C access library.
52
+ summary: I2C access library (for Linux).
50
53
  test_files: []