File tree Expand file tree Collapse file tree 3 files changed +61
-0
lines changed Expand file tree Collapse file tree 3 files changed +61
-0
lines changed Original file line number Diff line number Diff line change @@ -37,4 +37,14 @@ config SAMPLE_RUST_HOSTPROGS
37
37
38
38
If unsure, say N.
39
39
40
+ config SAMPLE_RUST_SPI_DUMMY
41
+ tristate "SPI dummy"
42
+ help
43
+ This option builds the Rust SPI dummy sample.
44
+
45
+ To compile this as a module, choose M here:
46
+ the module will be called rust_spi_dummy.
47
+
48
+ If unsure, say N.
49
+
40
50
endif # SAMPLES_RUST
Original file line number Diff line number Diff line change 2
2
3
3
obj-$(CONFIG_SAMPLE_RUST_MINIMAL) += rust_minimal.o
4
4
obj-$(CONFIG_SAMPLE_RUST_PRINT) += rust_print.o
5
+ obj-$(CONFIG_SAMPLE_RUST_SPI_DUMMY) += spi_dummy.o
5
6
6
7
subdir-$(CONFIG_SAMPLE_RUST_HOSTPROGS) += hostprogs
Original file line number Diff line number Diff line change
1
+ // SPDX-License-Identifier: GPL-2.0
2
+
3
+ use alloc:: boxed:: Box ;
4
+ use core:: pin:: Pin ;
5
+ use kernel:: prelude:: * ;
6
+ use kernel:: spi:: * ;
7
+ use kernel:: c_str;
8
+
9
+ module ! {
10
+ type : SPIDummy ,
11
+ name: "rust_spi_dummy" ,
12
+ author: "ks0n" ,
13
+ description: "SPI Dummy Driver" ,
14
+ license: "GPL" ,
15
+ }
16
+
17
+ struct SPIDummyMethods ;
18
+
19
+ #[ vtable]
20
+ impl SpiMethods for SPIDummyMethods {
21
+ fn probe ( spi_device : & mut SpiDevice ) -> Result < i32 , Error > {
22
+ pr_info ! ( "[SPI-RS] SPI Registered\n " ) ;
23
+ pr_info ! (
24
+ "[SPI-RS] SPI Registered, spi_device = {:#?}\n " ,
25
+ spi_device. to_ptr( )
26
+ ) ;
27
+
28
+ Ok ( 0 )
29
+ }
30
+ }
31
+
32
+ struct SPIDummy {
33
+ _spi : Pin < Box < DriverRegistration < SPIDummyMethods > > > ,
34
+ }
35
+
36
+ impl kernel:: Module for SPIDummy {
37
+ fn init ( module : & ' static ThisModule ) -> Result < Self > {
38
+ pr_info ! ( "[SPI-RS] Init\n " ) ;
39
+
40
+ let spi = DriverRegistration :: new_pinned ( module, c_str ! ( "SPIDummy" ) ) ?;
41
+
42
+ Ok ( SPIDummy { _spi : spi } )
43
+ }
44
+ }
45
+
46
+ impl Drop for SPIDummy {
47
+ fn drop ( & mut self ) {
48
+ pr_info ! ( "[SPI-RS] Exit\n " ) ;
49
+ }
50
+ }
You can’t perform that action at this time.
0 commit comments