File tree 4 files changed +34
-26
lines changed
4 files changed +34
-26
lines changed Original file line number Diff line number Diff line change @@ -52,8 +52,18 @@ ufmt = "0.1.0"
52
52
version = " 1.0"
53
53
default-features = false
54
54
55
+ [dev-dependencies .avr-device ]
56
+ version = " 0.3"
57
+ features = [" atmega328p" , " rt" ]
55
58
56
- [dev-dependencies .arduino-uno ]
59
+ [dev-dependencies .arduino-hal ]
57
60
# It is not yet available via crates.io
58
61
git = " https://github.com/Rahix/avr-hal.git"
59
- rev = " 0c6cf1675c2724354f1adeaeee69992acd371e80"
62
+ rev = " e897783816437a677aa577ddfdaa34e9a1e86d96"
63
+ features = [" arduino-uno" ]
64
+
65
+ [dev-dependencies .atmega-hal ]
66
+ # It is not yet available via crates.io
67
+ git = " https://github.com/Rahix/avr-hal.git"
68
+ rev = " e897783816437a677aa577ddfdaa34e9a1e86d96"
69
+
Original file line number Diff line number Diff line change 10
10
11
11
// Import the Arduino libraries, interestingly they don't cause problems perse
12
12
// on other architectures. Through, we will not use there.
13
- use arduino_uno:: prelude:: * ;
13
+ use arduino_hal:: port:: mode:: AnyInput ;
14
+ use arduino_hal:: port:: mode:: Input ;
15
+ use arduino_hal:: port:: mode:: Output ;
16
+ use arduino_hal:: port:: Pin ;
17
+ use arduino_hal:: prelude:: * ;
14
18
15
19
16
20
#[ cfg( target_arch = "avr" ) ]
17
- pub struct Printer ( pub arduino_uno:: Serial < arduino_uno:: hal:: port:: mode:: Floating > ) ;
21
+ pub struct Printer (
22
+ pub arduino_hal:: usart:: Usart <
23
+ avr_device:: atmega328p:: USART0 ,
24
+ Pin < Input < AnyInput > , atmega_hal:: port:: PD0 > ,
25
+ Pin < Output , atmega_hal:: port:: PD1 > ,
26
+ > ,
27
+ ) ;
18
28
#[ cfg( not( target_arch = "avr" ) ) ]
19
29
pub struct Printer ;
20
30
Original file line number Diff line number Diff line change 33
33
34
34
// Define no_std only for AVR
35
35
#![ cfg_attr( target_arch = "avr" , no_std) ]
36
- #![ no_main]
36
+ #![ cfg_attr ( target_arch = "avr" , no_main) ]
37
37
38
38
39
39
use avr_progmem:: progmem;
@@ -55,23 +55,17 @@ progmem! {
55
55
mod printer;
56
56
use printer:: Printer ;
57
57
58
- #[ no_mangle ]
58
+ #[ cfg_attr ( target_arch = "avr" , arduino_hal :: entry ) ]
59
59
fn main ( ) -> ! {
60
60
let mut printer = {
61
61
#[ cfg( target_arch = "avr" ) ]
62
62
{
63
63
// Initialize the USB-Serial output on the Arduino Uno
64
64
65
- let dp = arduino_uno:: Peripherals :: take ( ) . unwrap ( ) ;
65
+ let dp = arduino_hal:: Peripherals :: take ( ) . unwrap ( ) ;
66
+ let pins = arduino_hal:: pins!( dp) ;
67
+ let serial = arduino_hal:: default_serial!( dp, pins, 9600 ) ;
66
68
67
- let mut pins = arduino_uno:: Pins :: new ( dp. PORTB , dp. PORTC , dp. PORTD ) ;
68
-
69
- let serial = arduino_uno:: Serial :: new (
70
- dp. USART0 ,
71
- pins. d0 ,
72
- pins. d1 . into_output ( & mut pins. ddr ) ,
73
- 9600 ,
74
- ) ;
75
69
Printer ( serial)
76
70
}
77
71
#[ cfg( not( target_arch = "avr" ) ) ]
Original file line number Diff line number Diff line change 5
5
6
6
// Define no_std only for AVR
7
7
#![ cfg_attr( target_arch = "avr" , no_std) ]
8
- #![ no_main]
8
+ #![ cfg_attr ( target_arch = "avr" , no_main) ]
9
9
//
10
10
// To unwrap the Option in const context
11
11
#![ feature( const_option) ]
@@ -46,23 +46,17 @@ temporary DRAM necessary.
46
46
mod printer;
47
47
use printer:: Printer ;
48
48
49
- #[ no_mangle ]
49
+ #[ cfg_attr ( target_arch = "avr" , arduino_hal :: entry ) ]
50
50
fn main ( ) -> ! {
51
51
let mut printer = {
52
52
#[ cfg( target_arch = "avr" ) ]
53
53
{
54
54
// Initialize the USB-Serial output on the Arduino Uno
55
55
56
- let dp = arduino_uno:: Peripherals :: take ( ) . unwrap ( ) ;
56
+ let dp = arduino_hal:: Peripherals :: take ( ) . unwrap ( ) ;
57
+ let pins = arduino_hal:: pins!( dp) ;
58
+ let serial = arduino_hal:: default_serial!( dp, pins, 9600 ) ;
57
59
58
- let mut pins = arduino_uno:: Pins :: new ( dp. PORTB , dp. PORTC , dp. PORTD ) ;
59
-
60
- let serial = arduino_uno:: Serial :: new (
61
- dp. USART0 ,
62
- pins. d0 ,
63
- pins. d1 . into_output ( & mut pins. ddr ) ,
64
- 9600 ,
65
- ) ;
66
60
Printer ( serial)
67
61
}
68
62
#[ cfg( not( target_arch = "avr" ) ) ]
You can’t perform that action at this time.
0 commit comments