File tree 5 files changed +61
-5
lines changed
5 files changed +61
-5
lines changed Original file line number Diff line number Diff line change @@ -29,25 +29,31 @@ opt-level = "s"
29
29
30
30
31
31
[features ]
32
- default = [" lpm-asm-loop" ]
32
+ default = [" lpm-asm-loop" , " ufmt " ]
33
33
# Enables the use of the `lpm r0, Z+` in an assembly loop, instead of the plain
34
34
# `lpm` instruction with a Rust loop.
35
35
lpm-asm-loop = []
36
36
# Enables some tweak to ease debugging, should not be use in production
37
37
dev = []
38
38
39
- # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
40
-
41
39
[dependencies ]
42
40
cfg-if = " 0.1.10"
43
41
42
+ [dependencies .ufmt ]
43
+ version = " 0.1.0"
44
+ optional = true
45
+
44
46
45
47
[dev-dependencies ]
46
48
panic-halt = " 0.2.0"
47
49
ufmt = " 0.1.0"
48
50
51
+ [dev-dependencies .void ]
52
+ version = " 1.0"
53
+ default-features = false
54
+
55
+
49
56
[dev-dependencies .arduino-uno ]
50
57
# It is not yet available via crates.io
51
58
git = " https://github.com/Rahix/avr-hal.git"
52
- rev = " 0c6cf1675c2724354f1adeaeee69992acd371e80"
53
-
59
+ rev = " 0c6cf1675c2724354f1adeaeee69992acd371e80"
Original file line number Diff line number Diff line change @@ -35,3 +35,27 @@ impl Printer {
35
35
print ! ( "{}" , c) ;
36
36
}
37
37
}
38
+
39
+ impl ufmt:: uWrite for Printer {
40
+ type Error = void:: Void ;
41
+
42
+ fn write_str ( & mut self , s : & str ) -> Result < ( ) , Self :: Error > {
43
+ #[ cfg( target_arch = "avr" ) ]
44
+ ufmt:: uwrite!( & mut self . 0 , "{}" , s) . void_unwrap ( ) ;
45
+
46
+ #[ cfg( not( target_arch = "avr" ) ) ]
47
+ println ! ( "{}" , s) ;
48
+
49
+ Ok ( ( ) )
50
+ }
51
+
52
+ fn write_char ( & mut self , c : char ) -> Result < ( ) , Self :: Error > {
53
+ #[ cfg( target_arch = "avr" ) ]
54
+ ufmt:: uwrite!( & mut self . 0 , "{}" , c) . void_unwrap ( ) ;
55
+
56
+ #[ cfg( not( target_arch = "avr" ) ) ]
57
+ print ! ( "{}" , c) ;
58
+
59
+ Ok ( ( ) )
60
+ }
61
+ }
Original file line number Diff line number Diff line change @@ -94,6 +94,10 @@ fn main() -> ! {
94
94
printer. println ( avr_progmem:: progmem_str!( "Just a lone literal progmem str" ) ) ;
95
95
printer. println ( avr_progmem:: progmem_str!( "And another one" ) ) ;
96
96
97
+ // Using the ufmt impl
98
+ #[ cfg( feature = "ufmt" ) ]
99
+ ufmt:: uwriteln!( & mut printer, "{}\r " , UNICODE_TEXT . load( ) ) . unwrap ( ) ;
100
+
97
101
// Print some final lines
98
102
printer. println ( "" ) ;
99
103
printer. println ( "--------------------------" ) ;
Original file line number Diff line number Diff line change 8
8
//
9
9
// For string support, we need to convert from slice to array in const context.
10
10
#![ cfg_attr( not( doc) , feature( const_raw_ptr_deref) ) ]
11
+ //
12
+ // Allows to document required crate features on items
13
+ #![ feature( doc_cfg) ]
11
14
12
15
//!
13
16
//! Progmem utilities for the AVR architectures.
Original file line number Diff line number Diff line change
1
+ use core:: fmt;
1
2
use core:: ops:: Deref ;
2
3
3
4
@@ -84,6 +85,24 @@ impl<const N: usize> Deref for ByteString<N> {
84
85
}
85
86
}
86
87
88
+ impl < const N : usize > fmt:: Display for ByteString < N > {
89
+ fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
90
+ write ! ( fmt, "{}" , self . deref( ) )
91
+ }
92
+ }
93
+
94
+ #[ cfg( any( feature = "ufmt" , doc) ) ]
95
+ #[ doc( cfg( feature = "ufmt" ) ) ]
96
+ impl < const N : usize > ufmt:: uDisplay for ByteString < N > {
97
+ fn fmt < W : ?Sized > ( & self , fmt : & mut ufmt:: Formatter < W > ) -> Result < ( ) , W :: Error >
98
+ where
99
+ W : ufmt:: uWrite ,
100
+ {
101
+ ufmt:: uwrite!( fmt, "{}" , self . deref( ) )
102
+ }
103
+ }
104
+
105
+
87
106
/// Define a string in progmem
88
107
///
89
108
/// This is a short-cut macro to create an ad-hoc static storing the given
You can’t perform that action at this time.
0 commit comments