beagleboard 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9de4fc9c2d33be9532d660d9c80e2866c37932490cf3ab4aff86faa5274de3d1
4
+ data.tar.gz: 57bdfe384676500035013e28b99de9301a149098b5bc3f7140c569311916fb91
5
+ SHA512:
6
+ metadata.gz: 306269e3089ef8752a1a3e31dac6134fae4515fbc0099b53ff5f57077ccb20e782d0c32905e81497a87b0995747d3c1144ce342758e49133e6d7c74bad12bee2
7
+ data.tar.gz: c0de1e483011775a1d113d2d76ee33e80c8abde5e10b234aca0640e7ef83785fa58a8b0c1809fa0c3864f5e1de23c8f33776384374d6377d36061c89a5412c40
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.rspec_status
3
+ /.yardoc
4
+ /_yardoc/
5
+ /Gemfile.lock
6
+ /coverage/
7
+ /doc/
8
+ /dts/*.dtbo
9
+ /pkg/
10
+ /spec/reports/
11
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,9 @@
1
+ Style/Documentation:
2
+ Enabled: false
3
+
4
+ Metrics/LineLength:
5
+ Enabled: false
6
+
7
+ Metrics/BlockLength:
8
+ Exclude:
9
+ - spec/**/*_spec.rb
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ language: ruby
3
+ script: bundle exec rake spec
4
+ rvm:
5
+ - 2.3
6
+ - 2.4
7
+ - 2.5
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at contact@atome.io. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in beagleboard.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 atome
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # beagleboard
2
+
3
+ [![Build Status](https://travis-ci.org/atome-fr/beagleboard.svg?branch=master)](https://travis-ci.org/atome-fr/beagleboard)
4
+
5
+ A Ruby gem to manipulate the BeagleBone and BeagleBone Black ADC and GPIOs
6
+
7
+ ## usage
8
+
9
+ ```ruby
10
+ require 'beagleboard'
11
+
12
+ device = BeagleBone::BeagleBoneBlack.new
13
+
14
+ # ADCs access
15
+ device.p9_39.scale = 100
16
+ device.p9_39.raw_value #=> 2559
17
+ device.p9_39.value #=> 62
18
+ device.p9_39.scale = 1.0
19
+ device.p9_39.value #=> 0.624755859375
20
+
21
+ # GPIO access
22
+ device.p8_20.direction = :in
23
+ device.p8_20.value #=> 0 or 1
24
+ device.p8_21.direction = :out
25
+ device.p8_21.value = 0
26
+
27
+ # Helpers for setting direction and value
28
+ device.p8_22.direction = :low
29
+ device.p8_22.direction = :high
30
+
31
+ # USR LEDs access (they are GPIO)
32
+ 10.times do
33
+ device.usr0.value = 1
34
+ sleep 0.1
35
+ device.usr0.value = 0
36
+ sleep 0.1
37
+ end
38
+ ```
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ require 'rubocop/rake_task'
7
+ RuboCop::RakeTask.new
8
+
9
+ task default: :spec
@@ -0,0 +1,27 @@
1
+
2
+ lib = File.expand_path('lib', __dir__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'beagleboard/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'beagleboard'
8
+ spec.version = Beagleboard::VERSION
9
+ spec.authors = ['atome']
10
+ spec.email = ['contact@atome.io']
11
+
12
+ spec.summary = 'Library to manipulate beagleBoard devices.'
13
+ spec.homepage = 'https://github.com/atome-fr/beagleboard'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'ffi'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.16'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.0'
26
+ spec.add_development_dependency 'rubocop'
27
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'beagleboard'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/dts/BSDmakefile ADDED
@@ -0,0 +1,9 @@
1
+ .SUFFIXES: .dts .dtbo
2
+
3
+ all: am335x-beaglebone-tscadc.dtbo test.dtbo
4
+
5
+ clean:
6
+ rm -f am335x-beaglebone-tscadc.dtbo
7
+
8
+ .dts.dtbo:
9
+ dtc -I dts -O dtb -o ${.TARGET} ${.IMPSRC}
@@ -0,0 +1,16 @@
1
+ /dts-v1/;
2
+ /plugin/;
3
+
4
+ / {
5
+ compatible = "ti,am335x-bone-green", "ti,am335x-bone-black", "ti,am335x-bone", "ti,am33xx";
6
+
7
+ fragment@0 {
8
+ target = <&tscadc>;
9
+ __overlay__ {
10
+ status = "okay";
11
+ adc {
12
+ ti,adc-channels = <0 1 2 3 4 5 6>;
13
+ };
14
+ };
15
+ };
16
+ };
@@ -0,0 +1,68 @@
1
+ require 'ffi'
2
+
3
+ require "beagleboard/#{FFI::Platform::OS}/adc"
4
+ require "beagleboard/#{FFI::Platform::OS}/gpio"
5
+
6
+ module BeagleBoard
7
+ class AM335x
8
+ def initialize
9
+ @plateform = case FFI::Platform::OS
10
+ when 'linux' then 'Linux'
11
+ when 'freebsd' then 'FreeBSD'
12
+ end
13
+ end
14
+
15
+ def respond_to_missing?(name, *args)
16
+ return true if valid_ain_name(name)
17
+ return true if valid_gpio_name(name)
18
+ super
19
+ end
20
+
21
+ def method_missing(name, *args)
22
+ if valid_ain_name(name)
23
+ attach_object(name, ain_factory(name))
24
+ elsif valid_gpio_name(name)
25
+ attach_object(name, gpio_factory(name))
26
+ else
27
+ super
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def attach_object(name, obj)
34
+ instance_variable_set("@#{name}", obj)
35
+
36
+ define_singleton_method(name) do
37
+ instance_variable_get("@#{name}")
38
+ end
39
+
40
+ obj
41
+ end
42
+
43
+ def valid_ain_name(name)
44
+ return nil unless (captures = name.to_s.match(/\Aain(\d)\z/))
45
+ return nil unless (0...7).cover?(captures[1].to_i)
46
+ captures[1].to_i
47
+ end
48
+
49
+ def ain_factory(name)
50
+ ain = valid_ain_name(name)
51
+
52
+ Object.const_get("BeagleBoard::#{@plateform}::Adc").new(ain)
53
+ end
54
+
55
+ def valid_gpio_name(name)
56
+ return nil unless (captures = name.to_s.match(/\Agpio(\d)_(\d|[1-9]\d+)\z/))
57
+ return nil unless (0..3).cover?(captures[1].to_i)
58
+ return nil unless (0...32).cover?(captures[2].to_i)
59
+ [captures[1].to_i, captures[2].to_i]
60
+ end
61
+
62
+ def gpio_factory(name)
63
+ bank, gpio = valid_gpio_name(name)
64
+
65
+ Object.const_get("BeagleBoard::#{@plateform}::Gpio").new(bank, gpio)
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,34 @@
1
+ module BeagleBoard
2
+ module Base
3
+ class Adc
4
+ attr_accessor :scale
5
+
6
+ def initialize(_adc, scale = 2**12)
7
+ @scale = scale
8
+
9
+ enable
10
+ end
11
+
12
+ def enable
13
+ raise StandardError, 'Not supported'
14
+ end
15
+
16
+ def disable
17
+ raise StandardError, 'Not supported'
18
+ end
19
+
20
+ def raw_value
21
+ raise StandardError, 'Not supported'
22
+ end
23
+
24
+ def value
25
+ res = (raw_value.to_f * @scale / 2**12)
26
+ case @scale
27
+ when Integer then res.to_i
28
+ when Float then res
29
+ else raise("Unexpected type: #{@scale.class}")
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,33 @@
1
+ module BeagleBoard
2
+ module Base
3
+ class Gpio
4
+ def initialize(bank, gpio)
5
+ @bank = bank
6
+ @gpio = gpio
7
+ open
8
+ end
9
+
10
+ def open; end
11
+
12
+ def close; end
13
+
14
+ def direction
15
+ raise StandardError, 'Not supported'
16
+ end
17
+
18
+ def direction=(value)
19
+ raise StandardError, 'Invalid direction' unless %i[in out low high].include?(value)
20
+
21
+ value.to_s
22
+ end
23
+
24
+ def value
25
+ raise StandardError, 'Not supported'
26
+ end
27
+
28
+ def value=(_value)
29
+ raise StandardError, 'Not supported'
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,90 @@
1
+ require 'beagleboard/am335x'
2
+
3
+ module BeagleBoard
4
+ class BeagleBone < AM335x
5
+ {
6
+ # P8
7
+ 'p8_03' => 'gpio1_6',
8
+ 'p8_04' => 'gpio1_7',
9
+ 'p8_05' => 'gpio1_2',
10
+ 'p8_06' => 'gpio1_3',
11
+ 'p8_07' => 'gpio2_2',
12
+ 'p8_08' => 'gpio2_3',
13
+ 'p8_09' => 'gpio2_5',
14
+ 'p8_10' => 'gpio2_4',
15
+ 'p8_11' => 'gpio1_13',
16
+ 'p8_12' => 'gpio1_12',
17
+ 'p8_13' => 'gpio0_23',
18
+ 'p8_14' => 'gpio0_26',
19
+ 'p8_15' => 'gpio1_15',
20
+ 'p8_16' => 'gpio1_14',
21
+ 'p8_17' => 'gpio0_27',
22
+ 'p8_18' => 'gpio2_1',
23
+ 'p8_19' => 'gpio0_22',
24
+ 'p8_20' => 'gpio1_31',
25
+ 'p8_21' => 'gpio1_30',
26
+ 'p8_22' => 'gpio1_5',
27
+ 'p8_23' => 'gpio1_4',
28
+ 'p8_24' => 'gpio1_1',
29
+ 'p8_25' => 'gpio1_0',
30
+ 'p8_26' => 'gpio1_29',
31
+ 'p8_27' => 'gpio2_22',
32
+ 'p8_28' => 'gpio2_24',
33
+ 'p8_29' => 'gpio2_23',
34
+ 'p8_30' => 'gpio2_25',
35
+ 'p8_31' => 'gpio0_10',
36
+ 'p8_32' => 'gpio0_11',
37
+ 'p8_33' => 'gpio0_9',
38
+ 'p8_35' => 'gpio0_8',
39
+ 'p8_37' => 'gpio2_14',
40
+ 'p8_39' => 'gpio2_12',
41
+ 'p8_40' => 'gpio2_13',
42
+ 'p8_41' => 'gpio2_10',
43
+ 'p8_42' => 'gpio2_11',
44
+ 'p8_43' => 'gpio2_8',
45
+ 'p8_44' => 'gpio2_9',
46
+ 'p8_45' => 'gpio2_6',
47
+ 'p8_46' => 'gpio2_7',
48
+
49
+ # P9
50
+ 'p9_11' => 'gpio0_30',
51
+ 'p9_12' => 'gpio1_28',
52
+ 'p9_13' => 'gpio0_31',
53
+ 'p9_14' => 'gpio1_18',
54
+ 'p9_15' => 'gpio1_16',
55
+ 'p9_16' => 'gpio1_19',
56
+ 'p9_17' => 'gpio0_5',
57
+ 'p9_18' => 'gpio0_4',
58
+ 'p9_19' => 'gpio0_13',
59
+ 'p9_20' => 'gpio0_12',
60
+ 'p9_21' => 'gpio0_3',
61
+ 'p9_22' => 'gpio0_2',
62
+ 'p9_23' => 'gpio1_17',
63
+ 'p9_24' => 'gpio0_15',
64
+ 'p9_25' => 'gpio3_21',
65
+ 'p9_26' => 'gpio0_14',
66
+ 'p9_27' => 'gpio3_19',
67
+ 'p9_28' => 'gpio3_17',
68
+ 'p9_29' => 'gpio3_15',
69
+ 'p9_30' => 'gpio3_16',
70
+ 'p9_31' => 'gpio3_14',
71
+ 'p9_33' => 'ain4',
72
+ 'p9_35' => 'ain6',
73
+ 'p9_36' => 'ain5',
74
+ 'p9_37' => 'ain2',
75
+ 'p9_38' => 'ain3',
76
+ 'p9_39' => 'ain0',
77
+ 'p9_40' => 'ain1',
78
+ 'p9_42' => 'gpio0_7',
79
+
80
+ 'usr0' => 'gpio1_21',
81
+ 'usr1' => 'gpio1_22',
82
+ 'usr2' => 'gpio1_23',
83
+ 'usr3' => 'gpio1_24'
84
+ }.each do |name, function|
85
+ define_method(name) do
86
+ send(function)
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,63 @@
1
+ require 'beagleboard/beaglebone'
2
+
3
+ module BeagleBoard
4
+ module Cape
5
+ module Emmc
6
+ [(3..6).to_a, (20..25).to_a].flatten.each do |pin|
7
+ define_method("p8_#{pin}") do
8
+ raise StandardError, 'Pin disabled (MMC)'
9
+ end
10
+ end
11
+ end
12
+
13
+ module Hdmi
14
+ [28, 29, 31].each do |pin|
15
+ define_method("p9_#{pin}") do
16
+ raise StandardError, 'Pin disabled (HDMI)'
17
+ end
18
+ end
19
+ (27..46).each do |pin|
20
+ define_method("p8_#{pin}") do
21
+ raise StandardError, 'Pin disabled (HDMI)'
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ class BeagleBoneBlack < BeagleBone
28
+ {
29
+ 'p9_41a' => 'gpio0_20',
30
+ 'p9_41b' => 'gpio3_20',
31
+ 'p9_42a' => 'gpio0_7',
32
+ 'p9_42b' => 'gpio3_18'
33
+ }.each do |name, function|
34
+ define_method(name) do
35
+ send(function)
36
+ end
37
+ end
38
+
39
+ def initialize(options = {})
40
+ default_options = {
41
+ capes: %i[emmc hdmi]
42
+ }
43
+ options = default_options.merge(options)
44
+
45
+ super()
46
+
47
+ extend Cape::Hdmi if options[:capes].include? :hdmi
48
+ extend Cape::Emmc if options[:capes].include? :emmc
49
+ end
50
+
51
+ def p9_41
52
+ return @p9_41 if instance_variable_defined?(:@p9_41)
53
+ p9_41a.direction = :in
54
+ @p9_41 = p9_41b # rubocop:disable Naming/VariableNumber
55
+ end
56
+
57
+ def p9_42
58
+ return @p9_42 if instance_variable_defined?(:@p9_42)
59
+ p9_42a.direction = :in
60
+ @p9_42 = p9_42b # rubocop:disable Naming/VariableNumber
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,62 @@
1
+ require 'ffi'
2
+
3
+ require 'beagleboard/base/adc'
4
+
5
+ FFI.typedef(:uint32, :size_t)
6
+
7
+ module BeagleBoard
8
+ module FreeBSD
9
+ class Adc < BeagleBoard::Base::Adc
10
+ extend FFI::Library
11
+ ffi_lib 'c'
12
+ attach_function :sysctl, %i[pointer uint pointer pointer pointer size_t], :int
13
+ attach_function :sysctlbyname, %i[string pointer pointer pointer size_t], :int
14
+ attach_function :sysctlnametomib, %i[string pointer pointer], :int
15
+
16
+ def self.enable(mib)
17
+ buf = FFI::MemoryPointer.new(:int).write_int(1)
18
+ res = sysctl(mib, 6, nil, nil, buf, buf.size)
19
+ raise StandardError, 'Write error' if res < 0
20
+ end
21
+
22
+ def self.disable(mib)
23
+ buf = FFI::MemoryPointer.new(:int).write_int(0)
24
+ res = sysctl(mib, 6, nil, nil, buf, buf.size)
25
+ raise StandardError, 'Write error' if res < 0
26
+ end
27
+
28
+ def self.input(mib)
29
+ buf = FFI::MemoryPointer.new(:int)
30
+ bufsiz = FFI::MemoryPointer.new(:int).write_int(buf.size)
31
+ res = sysctl(mib, 6, buf, bufsiz, nil, 0)
32
+ raise StandardError, 'Read error' if res < 0
33
+ buf.read_int
34
+ end
35
+
36
+ def initialize(adc)
37
+ @enable_mib = FFI::MemoryPointer.new(:int, 6)
38
+ @input_mib = FFI::MemoryPointer.new(:int, 6)
39
+
40
+ size = FFI::MemoryPointer.new(:int).write_int(6)
41
+ Adc.sysctlnametomib("dev.ti_adc.0.ain.#{adc}.enable", @enable_mib, size)
42
+ Adc.sysctlnametomib("dev.ti_adc.0.ain.#{adc}.input", @input_mib, size)
43
+
44
+ super
45
+ end
46
+
47
+ def enable
48
+ Adc.enable(@enable_mib)
49
+ end
50
+
51
+ def disable
52
+ Adc.disable(@enable_mib)
53
+ end
54
+
55
+ def raw_value
56
+ Adc.input(@input_mib)
57
+ end
58
+
59
+ attr_accessor :scale
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,121 @@
1
+ require 'ffi'
2
+
3
+ require 'beagleboard/base/gpio'
4
+
5
+ module BeagleBoard
6
+ module FreeBSD
7
+ class Gpio < BeagleBoard::Base::Gpio
8
+ extend FFI::Library
9
+
10
+ GPIO_PIN_LOW = 0x00
11
+ GPIO_PIN_HIGH = 0x01
12
+
13
+ GPIO_PIN_INPUT = 0x001
14
+ GPIO_PIN_OUTPUT = 0x002
15
+ GPIO_PIN_OPENDRAIN = 0x004
16
+ GPIO_PIN_PUSHPULL = 0x008
17
+ GPIO_PIN_TRISTATE = 0x010
18
+ GPIO_PIN_PULLUP = 0x020
19
+ GPIO_PIN_PULLDOWN = 0x040
20
+ GPIO_PIN_INVIN = 0x080
21
+ GPIO_PIN_INVOUT = 0x100
22
+
23
+ GPIO_VALUE_INVALID = -1
24
+ GPIO_VALUE_LOW = GPIO_PIN_LOW
25
+ GPIO_VALUE_HIGH = GPIO_PIN_HIGH
26
+
27
+ ffi_lib 'gpio'
28
+ attach_function :gpio_open, [:int], :int
29
+ attach_function :gpio_open_device, [:string], :int
30
+ attach_function :gpio_close, [:int], :void
31
+ # gpio_pin_list
32
+ # gpio_pin_config
33
+ # gpio_pin_set_name
34
+ attach_function :gpio_pin_get, %i[int uint32], :int
35
+ attach_function :gpio_pin_set, %i[int uint32 int], :int
36
+ attach_function :gpio_pin_toggle, %i[int uint32], :int
37
+ attach_function :gpio_pin_low, %i[int uint32], :int
38
+ attach_function :gpio_pin_high, %i[int uint32], :int
39
+ attach_function :gpio_pin_input, %i[int uint32], :int
40
+ attach_function :gpio_pin_output, %i[int uint32], :int
41
+ attach_function :gpio_pin_opendrain, %i[int uint32], :int
42
+ attach_function :gpio_pin_pushpull, %i[int uint32], :int
43
+ attach_function :gpio_pin_tristate, %i[int uint32], :int
44
+ attach_function :gpio_pin_pullup, %i[int uint32], :int
45
+ attach_function :gpio_pin_pulldown, %i[int uint32], :int
46
+ attach_function :gpio_pin_invin, %i[int uint32], :int
47
+ attach_function :gpio_pin_invout, %i[int uint32], :int
48
+ attach_function :gpio_pin_pulsate, %i[int uint32], :int
49
+
50
+ def initialize(bank, gpio)
51
+ super
52
+ end
53
+
54
+ def open
55
+ @bank_fd = gpio_open(@bank)
56
+ end
57
+
58
+ def close
59
+ gpio_close(@bank_fd)
60
+ end
61
+
62
+ def toggle
63
+ gpio_pin_toggle(@bank_fd, @gpio)
64
+ end
65
+
66
+ def direction
67
+ case gpio_pin_config(@bank_fd, @gpio)
68
+ when GPIO_PIN_INPUT then :in
69
+ when GPIO_PIN_OUTPUT then :out
70
+ end
71
+ end
72
+
73
+ def direction=(direction)
74
+ send(direction_function(direction), @bank_fd, @gpio)
75
+ self.value = direction_value(direction)
76
+ end
77
+
78
+ def value
79
+ res = Gpio.gpio_pin_get(@bank_fd, @gpio)
80
+
81
+ raise 'Read error' if res < 0
82
+
83
+ res
84
+ end
85
+
86
+ def value=(value)
87
+ return unless value
88
+ res = send(value_function(value), @bank_fd, @gpio)
89
+ raise StandardError, 'Write error' if res < 0
90
+ end
91
+
92
+ private
93
+
94
+ def direction_function(direction)
95
+ {
96
+ in: :gpio_pin_input,
97
+ out: :gpio_pin_output,
98
+ low: :gpio_pin_output,
99
+ high: :gpio_pin_output
100
+ }[direction]
101
+ end
102
+
103
+ def direction_value(direction)
104
+ {
105
+ in: nil,
106
+ out: nil,
107
+ low: 0,
108
+ high: 1
109
+ }[direction]
110
+ end
111
+
112
+ def value_function(value)
113
+ {
114
+ 0 => :gpio_pin_low,
115
+ 1 => :gpio_pin_high,
116
+ nil => nil
117
+ }[value]
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,21 @@
1
+ require 'beagleboard/base/adc'
2
+
3
+ module BeagleBoard
4
+ module Linux
5
+ class Adc < BeagleBoard::Base::Adc
6
+ def initialize(ain)
7
+ @ain_number = ain
8
+
9
+ super
10
+ end
11
+
12
+ def enable; end
13
+
14
+ def disable; end
15
+
16
+ def raw_value
17
+ File.read("/sys/bus/iio/devices/iio:device0/in_voltage#{@ain_number}_raw")
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,39 @@
1
+ require 'beagleboard/base/gpio'
2
+
3
+ module BeagleBoard
4
+ module Linux
5
+ class Gpio < BeagleBoard::Base::Gpio
6
+ def initialize(bank, gpio)
7
+ @gpio_number = bank * 32 + gpio
8
+ @gpio_directory = "/sys/class/gpio/gpio#{@gpio_number}"
9
+ super
10
+ end
11
+
12
+ def open
13
+ File.write('/sys/class/gpio/export', @gpio_number.to_s)
14
+ end
15
+
16
+ def close
17
+ File.write('/sys/class/gpio/unexport', @gpio_number.to_s)
18
+ end
19
+
20
+ def direction
21
+ File.read("#{@gpio_directory}/direction").to_sym
22
+ end
23
+
24
+ def direction=(value)
25
+ raise StandardError, 'Invalid direction' unless %i[in out low high].include?(value)
26
+
27
+ File.write("#{@gpio_directory}/direction", value.to_s)
28
+ end
29
+
30
+ def value
31
+ File.read("#{@gpio_directory}/value").to_i
32
+ end
33
+
34
+ def value=(value)
35
+ File.write("#{@gpio_directory}/value", value.to_s)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module Beagleboard
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,6 @@
1
+ require 'beagleboard/beaglebone'
2
+ require 'beagleboard/beagleboneblack'
3
+ require 'beagleboard/version'
4
+
5
+ module Beagleboard
6
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: beagleboard
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - atome
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-06-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ffi
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - contact@atome.io
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".rubocop.yml"
93
+ - ".travis.yml"
94
+ - CODE_OF_CONDUCT.md
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - beagleboard.gemspec
100
+ - bin/console
101
+ - bin/setup
102
+ - dts/BSDmakefile
103
+ - dts/am335x-beaglebone-tscadc.dts
104
+ - lib/beagleboard.rb
105
+ - lib/beagleboard/am335x.rb
106
+ - lib/beagleboard/base/adc.rb
107
+ - lib/beagleboard/base/gpio.rb
108
+ - lib/beagleboard/beaglebone.rb
109
+ - lib/beagleboard/beagleboneblack.rb
110
+ - lib/beagleboard/freebsd/adc.rb
111
+ - lib/beagleboard/freebsd/gpio.rb
112
+ - lib/beagleboard/linux/adc.rb
113
+ - lib/beagleboard/linux/gpio.rb
114
+ - lib/beagleboard/version.rb
115
+ homepage: https://github.com/atome-fr/beagleboard
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.7.6
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: Library to manipulate beagleBoard devices.
139
+ test_files: []