Skip to content

Commit a370144

Browse files
committed
samples: rust: add i2c client driver sample
Add a basic sample for using the I2C client driver. Signed-off-by: Fabien Parent <[email protected]>
1 parent 611788a commit a370144

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

samples/rust/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ config SAMPLE_RUST_PRINT
3030

3131
If unsure, say N.
3232

33+
config SAMPLE_RUST_I2C_CLIENT
34+
tristate "I2C client device driver"
35+
help
36+
This option builds the Rust I2C client driver sample.
37+
38+
To compile this as a module, choose M here:
39+
the module will be called rust_i2c_client.
40+
41+
If unsure, say N.
42+
3343
config SAMPLE_RUST_HOSTPROGS
3444
bool "Host programs"
3545
help

samples/rust/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: GPL-2.0
22

3+
obj-$(CONFIG_SAMPLE_RUST_I2C_CLIENT) += rust_i2c_client.o
34
obj-$(CONFIG_SAMPLE_RUST_MINIMAL) += rust_minimal.o
45
obj-$(CONFIG_SAMPLE_RUST_PRINT) += rust_print.o
56

samples/rust/rust_i2c_client.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
//! Rust I2C client sample.
4+
5+
use kernel::{i2c, of, prelude::*};
6+
7+
kernel::module_i2c_driver! {
8+
type: Driver,
9+
name: "rust_i2c_client",
10+
license: "GPL",
11+
}
12+
13+
kernel::module_i2c_id_table!(I2C_MOD_TABLE, I2C_CLIENT_I2C_ID_TABLE);
14+
kernel::define_i2c_id_table! {I2C_CLIENT_I2C_ID_TABLE, (), [
15+
(i2c::DeviceId(b"rust-sample-i2c"), None),
16+
]}
17+
18+
kernel::module_of_id_table!(OF_MOD_TABLE, I2C_CLIENT_OF_ID_TABLE);
19+
kernel::define_of_id_table! {I2C_CLIENT_OF_ID_TABLE, (), [
20+
(of::DeviceId::Compatible(b"rust,rust-sample-i2c"), None),
21+
]}
22+
23+
struct Driver;
24+
impl i2c::Driver for Driver {
25+
kernel::driver_i2c_id_table!(I2C_CLIENT_I2C_ID_TABLE);
26+
kernel::driver_of_id_table!(I2C_CLIENT_OF_ID_TABLE);
27+
28+
fn probe(_client: &mut i2c::Client) -> Result {
29+
Ok(())
30+
}
31+
}

0 commit comments

Comments
 (0)