i2c 0.4.0 → 0.4.2.dev
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.
- checksums.yaml +7 -0
- data/README.rdoc +16 -16
- data/lib/i2c/backends/i2c-dev.rb +64 -25
- data/lib/i2c/drivers/mcp230xx.rb +1 -1
- metadata +17 -15
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2254a2d32b8a0d9feb7e7718477e4bca157a521d
|
4
|
+
data.tar.gz: 918e34eca0c218eab8330efa1ee5b71426c91625
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 453ebbf2217f1ca9e105c95cd188b1c9d08c311d7a913927312ca7aabfaed490c0836052076e07425f5709a9409430f75626d1d064e3e40c047a0f20b8980c00
|
7
|
+
data.tar.gz: fbd3cd2ea165014d405a781591f13c88b96bc018c9a31cc223bdac2490c8859dc4a1969b2902d85a2546fe4a133b22a00280fcdd2fbe5730c25eef827b774890
|
data/README.rdoc
CHANGED
@@ -1,30 +1,30 @@
|
|
1
|
-
= I2C - Ruby I2C library
|
1
|
+
= I2C - Ruby I2C library
|
2
2
|
|
3
3
|
== About
|
4
4
|
|
5
|
-
Interface to Linux I2C (a.k.a. TWI) implementations. Right now targeted at the
|
5
|
+
Interface to Linux I2C (a.k.a. TWI) implementations. Right now targeted at the
|
6
6
|
Raspberry Pi, but should work with any linux i2c-dev I2C-hardware.
|
7
7
|
|
8
8
|
== Structure
|
9
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
|
-
|
13
|
-
* Drivers for I2C enabled ICs.
|
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
14
|
|
15
15
|
== Installation
|
16
16
|
|
17
17
|
To use the i2c-dev backend it is necessary to load the "i2c-dev" linux
|
18
18
|
kernel module. This is not done automatically even if the module for the
|
19
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
|
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
22
|
rule file is available (rules/88-i2c.rules) and can be installed to
|
23
23
|
/etc/udev/rules.d/.
|
24
24
|
|
25
25
|
== Backends
|
26
26
|
|
27
|
-
The backends are instantiated through the #I2C::create method. depending
|
27
|
+
The backends are instantiated through the #I2C::create method. depending
|
28
28
|
on the format of the passed bus descriptor the correct backend is invoked.
|
29
29
|
|
30
30
|
Right now there is only a i2c-dev backend available
|
@@ -43,21 +43,21 @@ first I2c bus on the system.
|
|
43
43
|
|
44
44
|
16 bit IO-Expander MCP23017 from Microchip. Provides a wiringpi-ruby compatible
|
45
45
|
API and may therefore be used as a drop-in replacement for IO tasks on a
|
46
|
-
Raspberry Pi.
|
46
|
+
Raspberry Pi.
|
47
47
|
Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/21952b.pdf
|
48
48
|
|
49
49
|
=== MCP23008
|
50
50
|
|
51
|
-
8 bit IO-Expander MCP23008 from Microchip. Basically a small version of the
|
52
|
-
MCP23017.
|
51
|
+
8 bit IO-Expander MCP23008 from Microchip. Basically a small version of the
|
52
|
+
MCP23017.
|
53
53
|
Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/21919e.pdf
|
54
54
|
|
55
55
|
== Acknowledgements
|
56
56
|
|
57
|
-
The low-level IO (mainly in i2c-dev.rb) was extracted from Ruby-I2C
|
58
|
-
(http://rubyforge.org/projects/i2c/) by Jonas Bähr <jonas.baehr@fs.ei.tum.de>
|
57
|
+
The low-level IO (mainly in i2c-dev.rb) was extracted from Ruby-I2C
|
58
|
+
(http://rubyforge.org/projects/i2c/) by Jonas Bähr <jonas.baehr@fs.ei.tum.de>
|
59
59
|
|
60
|
-
=== Contributions
|
60
|
+
=== Contributions
|
61
61
|
* [Gaëtan Duchaussois](https://github.com/gaetronik) I2C::Dev.read_byte.
|
62
62
|
|
63
63
|
=== Bugfixes
|
@@ -67,6 +67,6 @@ The low-level IO (mainly in i2c-dev.rb) was extracted from Ruby-I2C
|
|
67
67
|
|
68
68
|
This code may be used under the terms of the GNU General Public Licence, Version 2.
|
69
69
|
|
70
|
+
Copyright (c) 2018 David Bailey <davidbailey.2889@gmail.com>
|
70
71
|
Copyright (c) 2012 Christoph Anderegg <christoph@christoph-anderegg.ch>
|
71
72
|
Copyright (c) 2008 Jonas Bähr <jonas.baehr@fs.ei.tum.de>
|
72
|
-
|
data/lib/i2c/backends/i2c-dev.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
# I2C - Linux i2c-dev backend.
|
2
|
+
# I2C - Linux i2c-dev backend.
|
3
3
|
#
|
4
4
|
# Copyright (c) 2012 Christoph Anderegg <christoph@christoph-anderegg.ch>
|
5
|
-
# Copyright (c) 2008 Jonas Bähr, jonas.baehr@fs.ei.tum.de
|
5
|
+
# Copyright (c) 2008 Jonas Bähr, jonas.baehr@fs.ei.tum.de
|
6
6
|
# This file may be distributed under the terms of the GNU General Public
|
7
7
|
# License Version 2.
|
8
8
|
#
|
@@ -18,43 +18,82 @@ module I2C
|
|
18
18
|
@instances[device_path]
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
attr_reader :comsMutex
|
22
|
+
|
23
|
+
# this tries to lock the coms mutex, unless already held,
|
24
|
+
# then sends every param, begining with +params[0]+
|
22
25
|
# If the current param is a Fixnum, it is treated as one byte.
|
23
|
-
# If the param is a String, this string will be
|
26
|
+
# If the param is a String, this string will be sent byte by byte.
|
24
27
|
# You can use Array#pack to create a string from an array
|
25
|
-
# For Fixnum there is a
|
28
|
+
# For Fixnum there is a convenient function to_short which transforms
|
26
29
|
# the number to a string this way: 12345.to_short == [12345].pack("s")
|
27
30
|
def write(address, *params)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
if(@comsMutex.owned?)
|
32
|
+
keepLock = true;
|
33
|
+
else
|
34
|
+
@comsMutex.lock;
|
35
|
+
end
|
36
|
+
|
37
|
+
setup_device(address);
|
38
|
+
raw_write(params);
|
39
|
+
|
40
|
+
@comsMutex.unlock() unless keepLock;
|
35
41
|
end
|
36
42
|
|
37
|
-
|
43
|
+
# this tries to lock the coms mutex (unless already held),
|
44
|
+
# then sends *params, if given, and then tries to read
|
38
45
|
# +size+ bytes. The result is a String which can be treated with
|
39
46
|
# String#unpack afterwards
|
40
47
|
def read(address, size, *params)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
48
|
+
if(@comsMutex.owned?)
|
49
|
+
keepLock = true;
|
50
|
+
else
|
51
|
+
@comsMutex.lock;
|
52
|
+
end
|
53
|
+
|
54
|
+
setup_device(address);
|
55
|
+
raw_write(params) unless params.empty?
|
56
|
+
result = raw_read(size);
|
57
|
+
|
58
|
+
@comsMutex.unlock() unless keepLock;
|
59
|
+
return result;
|
45
60
|
end
|
46
|
-
|
61
|
+
|
47
62
|
# Read a byte from the current address. Return a one char String which
|
48
63
|
# can be treated with String#unpack
|
49
64
|
def read_byte(address)
|
50
|
-
|
51
|
-
@device.ioctl(I2C_SLAVE,address)
|
52
|
-
ret=@device.sysread(1)
|
53
|
-
return ret
|
65
|
+
read(address, 1);
|
54
66
|
end
|
55
|
-
|
67
|
+
|
56
68
|
private
|
69
|
+
# Set up @device for a I2C communication to address
|
70
|
+
def setup_device(address)
|
71
|
+
@device.ioctl(I2C_SLAVE, address);
|
72
|
+
end
|
73
|
+
|
74
|
+
# Read size bytes from @device, if possible. Raise an error otherwise
|
75
|
+
def raw_read(size)
|
76
|
+
return @device.sysread(size)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Write "params" to @device, unrolling them first should they be an array.
|
80
|
+
# params should be a string, formatted with Array.pack as explained for write()
|
81
|
+
def raw_write(params)
|
82
|
+
data = String.new();
|
83
|
+
data.force_encoding("US-ASCII")
|
84
|
+
|
85
|
+
if(params.is_a? Array)
|
86
|
+
params.each do |i| data << i; end
|
87
|
+
else
|
88
|
+
data << params;
|
89
|
+
end
|
90
|
+
|
91
|
+
@device.syswrite(data);
|
92
|
+
end
|
93
|
+
|
57
94
|
def initialize(device_path)
|
95
|
+
@comsMutex = Mutex.new();
|
96
|
+
|
58
97
|
@device = File.new(device_path, 'r+')
|
59
98
|
# change the sys* functions of the file object to meet our requirements
|
60
99
|
class << @device
|
@@ -62,7 +101,7 @@ module I2C
|
|
62
101
|
def syswrite(var)
|
63
102
|
begin
|
64
103
|
syswrite_orig var
|
65
|
-
rescue Errno::EREMOTEIO
|
104
|
+
rescue Errno::EREMOTEIO, Errno::EIO
|
66
105
|
raise AckError, "No acknowledge received"
|
67
106
|
end
|
68
107
|
end
|
@@ -70,7 +109,7 @@ module I2C
|
|
70
109
|
def sysread(var)
|
71
110
|
begin
|
72
111
|
sysread_orig var
|
73
|
-
rescue Errno::EREMOTEIO
|
112
|
+
rescue Errno::EREMOTEIO, Errno::EIO
|
74
113
|
raise AckError, "No acknowledge received"
|
75
114
|
end
|
76
115
|
end
|
data/lib/i2c/drivers/mcp230xx.rb
CHANGED
@@ -53,7 +53,7 @@ module I2C
|
|
53
53
|
|
54
54
|
@iodir = Array.new
|
55
55
|
max_port_no.times { @iodir << 0xFF } # Direction is input initially
|
56
|
-
@device.write(@address, port_count, iodir[0],
|
56
|
+
@device.write(@address, port_count, iodir[0], *@iodir)
|
57
57
|
|
58
58
|
@data = Array.new
|
59
59
|
max_port_no.times { @data << 0xFF }
|
metadata
CHANGED
@@ -1,53 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i2c
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
5
|
-
prerelease:
|
4
|
+
version: 0.4.2.dev
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Christoph Anderegg
|
8
|
+
- David Bailey
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2018-06-12 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Interface to I2C (aka TWI) implementations. Also provides abstractions
|
15
15
|
for some I2c-devices. Created with the Raspberry Pi in mind.
|
16
|
-
email:
|
16
|
+
email:
|
17
|
+
- davidbailey.2889@gmail.com
|
18
|
+
- christoph@christoph-anderegg.ch
|
17
19
|
executables: []
|
18
20
|
extensions: []
|
19
21
|
extra_rdoc_files:
|
20
22
|
- README.rdoc
|
21
23
|
files:
|
24
|
+
- README.rdoc
|
22
25
|
- lib/i2c.rb
|
23
|
-
- lib/i2c/i2c.rb
|
24
26
|
- lib/i2c/backends/i2c-dev.rb
|
25
27
|
- lib/i2c/drivers/mcp230xx.rb
|
26
|
-
-
|
28
|
+
- lib/i2c/i2c.rb
|
27
29
|
- rules/88-i2c.rules
|
28
|
-
-
|
30
|
+
- test//mcp230xx_spec.rb
|
29
31
|
homepage: https://github.com/andec/i2c
|
30
|
-
licenses:
|
32
|
+
licenses:
|
33
|
+
- GPL-3.0
|
34
|
+
metadata: {}
|
31
35
|
post_install_message:
|
32
36
|
rdoc_options: []
|
33
37
|
require_paths:
|
34
38
|
- lib
|
35
39
|
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
-
none: false
|
37
40
|
requirements:
|
38
|
-
- -
|
41
|
+
- - ">="
|
39
42
|
- !ruby/object:Gem::Version
|
40
43
|
version: '0'
|
41
44
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
45
|
requirements:
|
44
|
-
- -
|
46
|
+
- - ">"
|
45
47
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
48
|
+
version: 1.3.1
|
47
49
|
requirements: []
|
48
50
|
rubyforge_project:
|
49
|
-
rubygems_version:
|
51
|
+
rubygems_version: 2.6.14.1
|
50
52
|
signing_key:
|
51
|
-
specification_version:
|
53
|
+
specification_version: 4
|
52
54
|
summary: I2C access library (for Linux).
|
53
55
|
test_files: []
|