libftdi-ruby 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
+ ## Description
2
+
1
3
  Ruby bindings for [libftdi](http://www.intra2net.com/en/developer/libftdi/index.php) - an open source library to talk to [FTDI](http://www.ftdichip.com/) chips.
2
4
 
3
- You must install libftdi itself in addition to this gem.
5
+ ## Prerequisites
6
+
7
+ You must install `libftdi` itself in addition to this gem.
4
8
 
5
9
  ## Synopsys
6
10
 
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'ftdi'
4
+
5
+ ctx = Ftdi::Context.new
6
+
7
+ begin
8
+ ctx.usb_open(0x0403, 0x6001)
9
+
10
+ begin
11
+ ctx.set_bitmode(0x00, :bitbang)
12
+ #ctx.baudrate = 250000
13
+
14
+ 100.times do
15
+ p ctx.read_pins
16
+ sleep 0.5
17
+ end
18
+ ensure
19
+ ctx.set_bitmode(0x00, :reset)
20
+ ctx.usb_close
21
+ end
22
+ rescue Ftdi::Error => e
23
+ $stderr.puts e.to_s
24
+ end
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'ftdi'
4
+
5
+ ctx = Ftdi::Context.new
6
+
7
+ begin
8
+ ctx.usb_open(0x0403, 0x6001)
9
+
10
+ begin
11
+ ctx.set_bitmode(0xff, :bitbang)
12
+ #ctx.baudrate = 250000
13
+
14
+ 10.times do
15
+ ctx.write_data [0xff]
16
+ sleep 0.5
17
+ ctx.write_data [0x00]
18
+ sleep 0.5
19
+ end
20
+ ensure
21
+ ctx.set_bitmode(0xff, :reset)
22
+ ctx.usb_close
23
+ end
24
+ rescue Ftdi::Error => e
25
+ $stderr.puts e.to_s
26
+ end
@@ -37,6 +37,9 @@ module Ftdi
37
37
  # @see Ftdi::Context#interface=
38
38
  Interface = enum(:interface_any, :interface_a, :interface_b, :interface_c, :interface_d)
39
39
 
40
+ # Bitbang mode for {Ftdi::Context#set_bitmode}.
41
+ BitbangMode = enum(:reset, :bitbang, :mpsse, :syncbb, :mcu, :opto, :cbus, :syncff)
42
+
40
43
  # Flow control: disable
41
44
  # @see Ftdi::Context#flowctrl=
42
45
  SIO_DISABLE_FLOW_CTRL = 0x0
@@ -267,6 +270,15 @@ module Ftdi
267
270
  new_flowctrl
268
271
  end
269
272
 
273
+ # Set Bitbang mode for ftdi chip.
274
+ # @param [Fixnum] bitmask to configure lines. HIGH/ON value configures a line as output.
275
+ # @param [BitbangMode] mode Bitbang mode: use the values defined in {Ftdi::Context#BitbangMode}
276
+ # @return [NilClass] nil
277
+ # @see BitbangMode
278
+ def set_bitmode(bitmask, mode)
279
+ check_result(Ftdi.ftdi_set_bitmode(ctx, bitmask, mode))
280
+ end
281
+
270
282
  # Gets write buffer chunk size.
271
283
  # @return [Fixnum] Write buffer chunk size.
272
284
  # @raise [StatusCodeError] libftdi reports error.
@@ -339,6 +351,16 @@ module Ftdi
339
351
  r
340
352
  end
341
353
 
354
+ # Directly read pin state, circumventing the read buffer. Useful for bitbang mode.
355
+ # @return [Fixnum] Pins state
356
+ # @raise [StatusCodeError] libftdi reports error.
357
+ # @see #set_bitmode
358
+ def read_pins
359
+ p = FFI::MemoryPointer.new(:uchar, 1)
360
+ check_result(Ftdi.ftdi_read_pins(ctx, p))
361
+ p.read_uchar
362
+ end
363
+
342
364
  # Gets used interface of the device.
343
365
  # @return [Interface] Used interface of the device.
344
366
  def interface
@@ -385,5 +407,7 @@ module Ftdi
385
407
  attach_function :ftdi_read_data_set_chunksize, [ :pointer, :uint ], :int
386
408
  attach_function :ftdi_read_data_get_chunksize, [ :pointer, :pointer ], :int
387
409
  attach_function :ftdi_set_interface, [ :pointer, Interface ], :int
410
+ attach_function :ftdi_set_bitmode, [ :pointer, :int, :int ], :int
411
+ attach_function :ftdi_read_pins, [ :pointer, :pointer ], :int
388
412
  end
389
413
 
@@ -1,5 +1,5 @@
1
1
  module Ftdi
2
2
  # Gem version.
3
- VERSION = "0.0.3".freeze
3
+ VERSION = "0.0.4".freeze
4
4
  end
5
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libftdi-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-12 00:00:00.000000000 Z
12
+ date: 2012-11-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
16
- requirement: &2153402300 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '1.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2153402300
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: yard
27
- requirement: &2153401800 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: 0.7.5
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *2153401800
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.7.5
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: redcarpet
38
- requirement: &2153401340 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ~>
@@ -43,7 +53,12 @@ dependencies:
43
53
  version: 1.17.2
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *2153401340
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.17.2
47
62
  description: libftdi library bindings to talk to FTDI chips
48
63
  email:
49
64
  - akzhan.abdulin@gmail.com
@@ -57,6 +72,8 @@ files:
57
72
  - LICENSE
58
73
  - README.md
59
74
  - Rakefile
75
+ - example/bitread.rb
76
+ - example/blink.rb
60
77
  - lib/ftdi.rb
61
78
  - lib/ftdi/version.rb
62
79
  - libftdi-ruby.gemspec
@@ -81,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
98
  version: '0'
82
99
  requirements: []
83
100
  rubyforge_project: libftdi-ruby
84
- rubygems_version: 1.8.15
101
+ rubygems_version: 1.8.24
85
102
  signing_key:
86
103
  specification_version: 3
87
104
  summary: libftdi library bindings