File tree 6 files changed +78
-1
lines changed
6 files changed +78
-1
lines changed Original file line number Diff line number Diff line change 97
97
device : " crate::device::uart::Uart"
98
98
kconfig : CONFIG_SERIAL
99
99
100
+ - name : led-strip
101
+ rules :
102
+ - type : or
103
+ value :
104
+ - type : compatible
105
+ value :
106
+ names :
107
+ - " worldsemi,wd2812-spi"
108
+ level : 0
109
+ - type : compatible
110
+ value :
111
+ names :
112
+ - " worldsemi,ws2812-rpi_pico-pio"
113
+ level : 1
114
+ actions :
115
+ - type : instance
116
+ value :
117
+ raw :
118
+ type : myself
119
+ device : " crate::device::led_strip::LedStrip"
120
+ kconfig : CONFIG_LED_STRIP
121
+
100
122
# Generate a pseudo node that matches all of the labels across the tree with their nodes.
101
123
- name : labels
102
124
rules :
Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ fn main() -> Result<()> {
67
67
// one from the minimal libc.
68
68
. clang_arg ( "-DRUST_BINDGEN" )
69
69
. clang_arg ( format ! ( "-I{}/lib/libc/minimal/include" , zephyr_base) )
70
- . derive_copy ( false )
70
+ . derive_copy ( true )
71
71
. allowlist_function ( "k_.*" )
72
72
. allowlist_function ( "gpio_.*" )
73
73
. allowlist_function ( "flash_.*" )
@@ -82,6 +82,7 @@ fn main() -> Result<()> {
82
82
// Each DT node has a device entry that is a static.
83
83
. allowlist_item ( "__device_dts_ord.*" )
84
84
. allowlist_function ( "device_.*" )
85
+ . allowlist_function ( "led_strip.*" )
85
86
. allowlist_function ( "sys_.*" )
86
87
. allowlist_function ( "uart_.*" )
87
88
. allowlist_item ( "E.*" )
Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ extern int errno;
41
41
#include <zephyr/drivers/gpio.h>
42
42
#include <zephyr/drivers/flash.h>
43
43
#include <zephyr/drivers/uart.h>
44
+ #include <zephyr/drivers/led_strip.h>
44
45
45
46
/*
46
47
* bindgen will only output #defined constants that resolve to simple numbers. These are some
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ use crate::sync::atomic::{AtomicUsize, Ordering};
10
10
pub mod gpio;
11
11
pub mod flash;
12
12
pub mod uart;
13
+ pub mod led_strip;
13
14
14
15
// Allow dead code, because it isn't required for a given build to have any devices.
15
16
/// Device uniqueness.
Original file line number Diff line number Diff line change
1
+ //! Simple led strip driver
2
+
3
+ use crate :: raw;
4
+ use crate :: error:: { Result , to_result_void} ;
5
+
6
+ use super :: Unique ;
7
+
8
+ /// A simple led strip wrapper.
9
+ pub struct LedStrip {
10
+ /// The underlying device itself.
11
+ #[ allow( dead_code) ]
12
+ pub ( crate ) device : * const raw:: device ,
13
+ }
14
+
15
+ // This is send, safe with Zephyr.
16
+ unsafe impl Send for LedStrip { }
17
+
18
+ impl LedStrip {
19
+ /// Constructor, used by the devicetree generated code.
20
+ #[ allow( dead_code) ]
21
+ pub ( crate ) unsafe fn new ( unique : & Unique , device : * const raw:: device ) -> Option < LedStrip > {
22
+ if !unique. once ( ) {
23
+ return None ;
24
+ }
25
+
26
+ Some ( LedStrip { device } )
27
+ }
28
+
29
+ /// Return the number of LEDS in the chain.
30
+ pub fn chain_len ( & self ) -> usize {
31
+ unsafe { raw:: led_strip_length ( self . device ) as usize }
32
+ }
33
+
34
+ /// Update the state of the LEDs.
35
+ ///
36
+ /// It is unclear from the API docs whether this is supposed to be an array of rgb_led
37
+ /// (which is what the samples assume), or packed rgb data.
38
+ pub unsafe fn update ( & mut self , channels : & [ raw:: led_rgb ] ) -> Result < ( ) > {
39
+ to_result_void ( unsafe {
40
+ raw:: led_strip_update_rgb ( self . device ,
41
+ channels. as_ptr ( ) as * mut _ ,
42
+ channels. len ( ) )
43
+ } )
44
+ }
45
+ }
Original file line number Diff line number Diff line change @@ -41,6 +41,13 @@ pub fn uptime_get() -> i64 {
41
41
}
42
42
}
43
43
44
+ /// Busy wait.
45
+ ///
46
+ /// Busy wait for a give number of microseconds. This directly calls `zephyr_sys::k_busy_wait`.
47
+ ///
48
+ /// Zephyr has numerous caveats on configurations where this function doesn't work.
49
+ pub use zephyr_sys:: k_busy_wait as busy_wait;
50
+
44
51
pub mod critical {
45
52
//! Zephyr implementation of critical sections.
46
53
//!
You can’t perform that action at this time.
0 commit comments