raudi 0.0.1 → 0.0.2
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/.DS_Store +0 -0
- data/.rvmrc +1 -1
- data/bin/raudi +17 -0
- data/configuration/atmega_328.yml +69 -0
- data/configuration/avr.yml +61 -0
- data/lib/.DS_Store +0 -0
- data/lib/raudi.rb +58 -9
- data/lib/raudi/.DS_Store +0 -0
- data/lib/raudi/action_processor.rb +34 -26
- data/lib/raudi/avr.rb +4 -0
- data/lib/raudi/avr/.DS_Store +0 -0
- data/lib/raudi/avr/controller.rb +73 -0
- data/lib/raudi/avr/pin.rb +30 -0
- data/lib/raudi/avr/pin_states.rb +73 -0
- data/lib/raudi/avr/port.rb +36 -0
- data/lib/raudi/avr/timer.rb +49 -0
- data/lib/raudi/core_ext.rb +1 -0
- data/lib/raudi/core_ext/fixnum.rb +16 -0
- data/lib/raudi/info.rb +52 -0
- data/lib/raudi/processing.rb +63 -0
- data/lib/raudi/processing/gpio.rb +25 -0
- data/lib/raudi/processing/int.rb +36 -0
- data/lib/raudi/processing/pcint.rb +35 -0
- data/lib/raudi/processing/timer.rb +56 -0
- data/lib/raudi/proxy/.DS_Store +0 -0
- data/lib/raudi/proxy/controller.rb +65 -0
- data/lib/raudi/proxy/external_interrupt.rb +30 -0
- data/lib/raudi/proxy/gpio.rb +19 -0
- data/lib/raudi/proxy/headers.rb +31 -0
- data/lib/raudi/proxy/timer.rb +61 -0
- data/lib/raudi/source.rb +48 -0
- data/lib/raudi/source/action.rb +16 -0
- data/lib/raudi/source/bit_operations.rb +35 -0
- data/lib/raudi/source/block.rb +44 -0
- data/lib/raudi/source/controller.rb +56 -0
- data/lib/raudi/source/function.rb +50 -0
- data/lib/raudi/source/interrupt.rb +35 -0
- data/lib/raudi/source/variable.rb +31 -0
- data/lib/raudi/state_list.rb +17 -0
- data/raudi.gemspec +3 -0
- data/spec/.DS_Store +0 -0
- data/spec/examples/sample.raudi +5 -0
- data/spec/lib/.DS_Store +0 -0
- data/spec/lib/raudi/.DS_Store +0 -0
- data/spec/lib/raudi/action_processor_spec.rb +35 -0
- data/spec/lib/raudi/avr/controller_spec.rb +13 -0
- data/spec/lib/raudi/avr/pin_spec.rb +70 -0
- data/spec/lib/raudi/avr/timer_spec.rb +22 -0
- data/spec/lib/raudi/info_spec.rb +9 -0
- data/spec/lib/raudi/proxy/external_interrupt_spec.rb +22 -0
- data/spec/lib/raudi/proxy/gpio_spec.rb +18 -0
- data/spec/lib/raudi/proxy/headers_spec.rb +34 -0
- data/spec/lib/raudi/proxy/timer_spec.rb +67 -0
- data/spec/lib/raudi/source/external_interrupt_spec.rb +55 -0
- data/spec/lib/raudi/source/gpio_spec.rb +18 -0
- data/spec/lib/raudi/source/main_structure_spec.rb +19 -0
- data/spec/lib/raudi/source/timer_spec.rb +44 -0
- data/spec/lib/raudi_spec.rb +41 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/support/raudi_spec_helper.rb +27 -0
- metadata +106 -19
- data/examples/actions.raudi +0 -1
- data/examples/config.rb +0 -3
- data/examples/result.c +0 -10
- data/lib/raudi/avr_controller.rb +0 -23
- data/spec/raudi_spec.rb +0 -9
@@ -0,0 +1,17 @@
|
|
1
|
+
module Raudi
|
2
|
+
|
3
|
+
module StateList
|
4
|
+
|
5
|
+
Info.pin_states.each do |common_state|
|
6
|
+
define_method "#{common_state}_pins" do
|
7
|
+
pins.select { |pin| pin.send("#{common_state}?") }
|
8
|
+
end
|
9
|
+
|
10
|
+
define_method "#{common_state}_present?" do
|
11
|
+
pins.any? { |pin| pin.send("#{common_state}?") }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/raudi.gemspec
CHANGED
@@ -19,9 +19,12 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
21
|
# specify any dependencies here; for example:
|
22
|
+
# maybe in future
|
23
|
+
# s.add_dependency 'activesupport'
|
22
24
|
s.add_development_dependency "rspec", '>= 2.5'
|
23
25
|
s.add_development_dependency 'guard-rspec'
|
24
26
|
s.add_development_dependency 'fuubar'
|
25
27
|
s.add_development_dependency 'ruby_gntp'
|
28
|
+
s.add_development_dependency 'ruby-debug19'
|
26
29
|
|
27
30
|
end
|
data/spec/.DS_Store
ADDED
Binary file
|
data/spec/lib/.DS_Store
ADDED
Binary file
|
Binary file
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Raudi::ActionProcessor do
|
4
|
+
|
5
|
+
context 'processing keys' do
|
6
|
+
|
7
|
+
let(:action_text) { "Some dummy test" }
|
8
|
+
|
9
|
+
it 'string/symbol be same' do
|
10
|
+
subject['foo'] = action_text
|
11
|
+
subject[:foo].should == action_text
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'case unsensative' do
|
15
|
+
subject[:FOOBar] = action_text
|
16
|
+
subject[:foobar].should == action_text
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'allow 2 key format' do
|
20
|
+
subject[:foo, 2] = action_text
|
21
|
+
subject[:foo2].should == action_text
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'using alias key' do
|
25
|
+
|
26
|
+
it 'for interrupt action' do
|
27
|
+
subject[:interrupt] = action_text
|
28
|
+
subject[:int].should == action_text
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Raudi::AVR::Controller do
|
4
|
+
|
5
|
+
it 'should have 3 timers' do
|
6
|
+
controller.timers.should have(3).items
|
7
|
+
controller.timers[0].length.should == 8
|
8
|
+
controller.timers[1].length.should == 16
|
9
|
+
controller.timers[2].length.should == 8
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Raudi::AVR::Pin do
|
4
|
+
|
5
|
+
let(:port){ Raudi::AVR::Port.new("C", {'pins' => []}) }
|
6
|
+
|
7
|
+
context 'generate c presentation' do
|
8
|
+
|
9
|
+
context 'as gpio' do
|
10
|
+
|
11
|
+
let(:pin) { Raudi::AVR::Pin.new(port, 3, []) }
|
12
|
+
|
13
|
+
it 'input' do
|
14
|
+
pin.to_c.should == "PINC3"
|
15
|
+
pin.should be_input
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'output' do
|
19
|
+
pin.output!
|
20
|
+
pin.to_c.should == 'PINC3'
|
21
|
+
pin.should be_output
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'pullup' do
|
25
|
+
pin.pullup!
|
26
|
+
pin.to_c.should == 'PINC3'
|
27
|
+
pin.should be_pullup
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'as eint' do
|
33
|
+
pin = klass.new(port, 2, ["int_0"])
|
34
|
+
pin.int!
|
35
|
+
pin.to_c.should == "INT0"
|
36
|
+
pin.should be_int
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'state checks' do
|
42
|
+
|
43
|
+
let(:pin) { Raudi::AVR::Pin.new(port, 3, ['timer_1', 'eint_0', 'pcint_4']) }
|
44
|
+
|
45
|
+
it 'should be input by default' do
|
46
|
+
pin.should be_input
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'can be pullup by default' do
|
50
|
+
pin.can_be_pullup?.should be_true
|
51
|
+
pin.pullup!
|
52
|
+
pin.should be_pullup
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'can be output by default' do
|
56
|
+
pin.can_be_output?.should be_true
|
57
|
+
pin.output!
|
58
|
+
pin.should be_output
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'can be timer' do
|
62
|
+
pin.can_be_timer?.should be_true
|
63
|
+
pin.can_be_timer?(2).should be_false
|
64
|
+
pin.timer!
|
65
|
+
pin.should be_timer
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Raudi::AVR::Timer do
|
4
|
+
|
5
|
+
let(:timer) { klass.new('timer_0', 'length' => 8) }
|
6
|
+
|
7
|
+
specify{ timer.number.should == 0 }
|
8
|
+
|
9
|
+
specify{ timer.range.should include(23)}
|
10
|
+
specify{ timer.range.should_not include(256)}
|
11
|
+
|
12
|
+
it 'should change params when mode changed' do
|
13
|
+
timer.mode = :foo
|
14
|
+
timer.mode_params.should == {}
|
15
|
+
timer.mode_params[:a] = 34
|
16
|
+
timer.mode = :foo
|
17
|
+
timer.mode_params[:a].should == 34
|
18
|
+
timer.mode = :bar
|
19
|
+
timer.mode_params.should == {}
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Proxy for external interrupt' do
|
4
|
+
|
5
|
+
it 'external interrupt' do
|
6
|
+
config.external_interrupt :d2 => :falling, :d3 => :rising
|
7
|
+
controller.interrupt.should be_true
|
8
|
+
pin = get_pin(:d, 3)
|
9
|
+
pin.should be_int
|
10
|
+
pin.state_params.should == :rising
|
11
|
+
controller.headers.should include('avr/interrupt')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'pin change interrupt' do
|
15
|
+
config.pc_interrupt :b3, :d4
|
16
|
+
controller.interrupt.should be_true
|
17
|
+
pin = get_pin(:b, 3)
|
18
|
+
pin.should be_pcint
|
19
|
+
controller.headers.should include('avr/interrupt')
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Proxy for gpio' do
|
4
|
+
|
5
|
+
it 'output pins' do
|
6
|
+
config.output :d0, :d3
|
7
|
+
config.output :b0, :b2, :b3
|
8
|
+
controller.ports(:d).output_pins.should have(2).items
|
9
|
+
controller.ports(:b).output_pins[0].number.should == 0
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'pullup pins' do
|
13
|
+
config.pullup :c3, :c5, :b5
|
14
|
+
controller.ports(:c).should have(2).pullup_pins
|
15
|
+
controller.ports(:b).should have(1).pullup_pins
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Proxy for headers' do
|
4
|
+
|
5
|
+
it 'by default have io header' do
|
6
|
+
controller.headers.should have(1).item
|
7
|
+
controller.headers.should include('avr/io')
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'normal case' do
|
11
|
+
config.headers 'util/twi'
|
12
|
+
controller.headers.should have(2).items
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'use symbols' do
|
16
|
+
config.headers :boot
|
17
|
+
controller.headers.should have(2).items
|
18
|
+
controller.headers.should include("avr/boot")
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'remove duplication' do
|
22
|
+
config.headers :boot, 'avr/boot', "avr/boot"
|
23
|
+
controller.headers.should have(2).item
|
24
|
+
controller.headers.should include('avr/boot')
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'remove unknow header' do
|
28
|
+
config.headers :wazza, 'avr/foo', 'sample'
|
29
|
+
controller.headers.should_not include('avr/wazza')
|
30
|
+
controller.headers.should_not include('avr/foo')
|
31
|
+
controller.headers.should_not include('sample')
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Proxy for timer/counter' do
|
4
|
+
|
5
|
+
context 'define timers' do
|
6
|
+
|
7
|
+
it 'basic config' do
|
8
|
+
config.activate_timer 0
|
9
|
+
timer = controller.timers[0]
|
10
|
+
timer.active.should be_true
|
11
|
+
timer.prescale.should == 1
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'set prescale' do
|
15
|
+
config.activate_timer 1, :prescale => 8
|
16
|
+
timer = controller.timers[1]
|
17
|
+
timer.active.should be_true
|
18
|
+
timer.prescale.should == 2
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'set invalid prescale' do
|
22
|
+
config.activate_timer 2, :prescale => 5
|
23
|
+
timer = controller.timers[2]
|
24
|
+
timer.active.should be_true
|
25
|
+
timer.prescale.should == 1
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'set timer with interrupt' do
|
29
|
+
config.activate_timer 1, :interrupt => true
|
30
|
+
controller.interrupt.should be_true
|
31
|
+
timer = controller.timers[1]
|
32
|
+
controller.headers.should include('avr/interrupt')
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'ctc mode' do
|
38
|
+
|
39
|
+
it 'set to ctc a' do
|
40
|
+
config.activate_timer 2, :a => 123
|
41
|
+
timer = controller.timers[2]
|
42
|
+
timer.should be_ctc
|
43
|
+
timer.mode_params[:a].should == 123
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'set to ctc b that overflow' do
|
47
|
+
config.activate_timer 0, :b => 260
|
48
|
+
timer = controller.timers[0]
|
49
|
+
timer.should be_normal
|
50
|
+
timer.mode_params.should == {}
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'define counter' do
|
56
|
+
|
57
|
+
it 'set timer 0 to counter' do
|
58
|
+
config.activate_counter 0
|
59
|
+
controller.timers[0].counter.should be
|
60
|
+
controller.timers[0].prescale.should == 6
|
61
|
+
pin = get_pin(:d, 4)
|
62
|
+
pin.should be_timer
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Generate external interrupt code' do
|
4
|
+
|
5
|
+
context 'external interrupt' do
|
6
|
+
|
7
|
+
it 'rising' do
|
8
|
+
config.external_interrupt :d2 => :rising
|
9
|
+
Raudi.action[:interrupt, 0] = "int k; for(k = 0; k < 4; k++);"
|
10
|
+
source.should include('sei();')
|
11
|
+
source.should include('ISR(INT0_vect)')
|
12
|
+
source.should include('EIMSK |= 1 << INT0;')
|
13
|
+
source.should include('EICRA |= 1 << ISC00 | 1 << ISC01;')
|
14
|
+
source.should include('int k;')
|
15
|
+
source.should include('for(k = 0; k < 4; k++);')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'falling' do
|
19
|
+
config.external_interrupt :d3 => :falling
|
20
|
+
source.should include('EIMSK |= 1 << INT1;')
|
21
|
+
source.should include('EICRA |= 1 << ISC11;')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'define two interrupts' do
|
25
|
+
config.external_interrupt :d2 => :both, :d3 => :falling
|
26
|
+
source.should include('ISR(INT0_vect)')
|
27
|
+
source.should include('ISR(INT1_vect)')
|
28
|
+
source.should include('EIMSK |= 1 << INT0 | 1 << INT1;')
|
29
|
+
source.should include('EICRA |= 1 << ISC00 | 1 << ISC11;')
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'pin change interrupt' do
|
35
|
+
|
36
|
+
it 'for pins b1 and b5' do
|
37
|
+
config.pc_interrupt :b1, :b5
|
38
|
+
source.should include("sei();")
|
39
|
+
source.should include('PCMSK0 |= 1 << PCINT1 | 1 << PCINT5;')
|
40
|
+
source.should include('ISR(PCINT0_vect)')
|
41
|
+
source.should include('PCICR |= 1 << PCIE0;')
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'pin c3 and d5' do
|
45
|
+
config.pc_interrupt :c3, :d5
|
46
|
+
source.should include('PCMSK1 |= 1 << PCINT11;')
|
47
|
+
source.should include('PCMSK2 |= 1 << PCINT21;')
|
48
|
+
source.should include('ISR(PCINT1_vect)')
|
49
|
+
source.should include('ISR(PCINT2_vect)')
|
50
|
+
source.should include('PCICR |= 1 << PCIE1 | 1 << PCIE2;')
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Generation gpio code' do
|
4
|
+
|
5
|
+
it 'output pins' do
|
6
|
+
config.output :b2, :c3, :b5, :d2
|
7
|
+
source.should include("DDRC |= 1 << 3;")
|
8
|
+
source.should include("DDRB |= 1 << 2 | 1 << 5;")
|
9
|
+
source.should include("DDRD |= 1 << 2;")
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'pullup pins' do
|
13
|
+
config.pullup :c3, :b3, :b2, :b4
|
14
|
+
source.should include("PORTC |= 1 << 3;")
|
15
|
+
source.should include("PORTB |= 1 << 2 | 1 << 3 | 1 << 4;")
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Generation main structure' do
|
4
|
+
|
5
|
+
it 'should warp setup block' do
|
6
|
+
source.should include("int delay_time = 500;")
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should warp main block' do
|
10
|
+
source.should include("_delay_ms(delay_time);")
|
11
|
+
source.should include("toggle_pin(PIN3);")
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should allow interrupt' do
|
15
|
+
controller.interrupt = true
|
16
|
+
source.should include('sei();')
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|