File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,9 @@ edition = "2018"
8
8
nb = " 0.1.1"
9
9
smart-leds-trait = {git = " https://github.com/smart-leds-rs/smart-leds-trait" }
10
10
11
+ [features ]
12
+ slow = []
13
+
11
14
[dependencies .embedded-hal ]
12
15
features = [" unproven" ]
13
16
version = " 0.2.1"
Original file line number Diff line number Diff line change
1
+ # Ws2812 lib with timer based delays
2
+
3
+ If your timer/micro is to slow (e.g. all leds are white), you may wish to enable
4
+ the ` slow ` feature. It will remove any delay for the high part of the zero bits.
5
+ This may be too short for some led strips, which may display wrong data. In that
6
+ case, you might want to clock higher or use another driver.
Original file line number Diff line number Diff line change 25
25
Self { timer, pin }
26
26
}
27
27
/// Write a single color for ws2812 devices
28
+ #[ cfg( feature = "slow" ) ]
29
+ fn write_color ( & mut self , data : Color ) {
30
+ let mut serial_bits = ( data. g as u32 ) << 16 | ( data. r as u32 ) << 8 | ( data. b as u32 ) << 0 ;
31
+ for _ in 0 ..24 {
32
+ if ( serial_bits & 0x00800000 ) != 0 {
33
+ block ! ( self . timer. wait( ) ) . ok ( ) ;
34
+ self . pin . set_high ( ) ;
35
+ block ! ( self . timer. wait( ) ) . ok ( ) ;
36
+ block ! ( self . timer. wait( ) ) . ok ( ) ;
37
+ self . pin . set_low ( ) ;
38
+ } else {
39
+ block ! ( self . timer. wait( ) ) . ok ( ) ;
40
+ self . pin . set_high ( ) ;
41
+ self . pin . set_low ( ) ;
42
+ block ! ( self . timer. wait( ) ) . ok ( ) ;
43
+ block ! ( self . timer. wait( ) ) . ok ( ) ;
44
+ }
45
+ serial_bits <<= 1 ;
46
+ }
47
+ }
48
+
49
+ #[ cfg( not( feature = "slow" ) ) ]
28
50
fn write_color ( & mut self , data : Color ) {
29
51
let mut serial_bits = ( data. g as u32 ) << 16 | ( data. r as u32 ) << 8 | ( data. b as u32 ) << 0 ;
30
52
for _ in 0 ..24 {
You can’t perform that action at this time.
0 commit comments