samples/rust/rust_i2c_client.rs
Source file repositories/reference/linux-study-clean/samples/rust/rust_i2c_client.rs
File Facts
- System
- Linux kernel
- Corpus path
samples/rust/rust_i2c_client.rs- Extension
.rs- Size
- 4016 bytes
- Lines
- 151
- Domain
- Support Tooling And Documentation
- Bucket
- samples
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
struct SampleDriver
Annotated Snippet
struct SampleDriver {
parent_dev: ARef<platform::Device>,
#[pin]
_reg: Devres<i2c::Registration>,
}
kernel::of_device_table!(
OF_TABLE,
MODULE_OF_TABLE,
<SampleDriver as platform::Driver>::IdInfo,
[(of::DeviceId::new(c"test,rust-device"), ())]
);
kernel::acpi_device_table!(
ACPI_TABLE,
MODULE_ACPI_TABLE,
<SampleDriver as platform::Driver>::IdInfo,
[(acpi::DeviceId::new(c"LNUXBEEF"), ())]
);
const SAMPLE_I2C_CLIENT_ADDR: u16 = 0x30;
const SAMPLE_I2C_ADAPTER_INDEX: i32 = 0;
const BOARD_INFO: i2c::I2cBoardInfo =
i2c::I2cBoardInfo::new(c"rust_driver_i2c", SAMPLE_I2C_CLIENT_ADDR);
impl platform::Driver for SampleDriver {
type IdInfo = ();
type Data<'bound> = Self;
const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = Some(&OF_TABLE);
const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE);
fn probe<'bound>(
pdev: &'bound platform::Device<device::Core<'_>>,
_info: Option<&'bound Self::IdInfo>,
) -> impl PinInit<Self, Error> + 'bound {
dev_info!(
pdev.as_ref(),
"Probe Rust I2C Client registration sample.\n"
);
kernel::try_pin_init!( Self {
parent_dev: pdev.into(),
_reg <- {
let adapter = i2c::I2cAdapter::get(SAMPLE_I2C_ADAPTER_INDEX)?;
i2c::Registration::new(&adapter, &BOARD_INFO, pdev.as_ref())
}
})
}
fn unbind<'bound>(
pdev: &'bound platform::Device<device::Core<'_>>,
_this: Pin<&Self::Data<'bound>>,
) {
dev_info!(
pdev.as_ref(),
"Unbind Rust I2C Client registration sample.\n"
);
}
}
kernel::module_platform_driver! {
type: SampleDriver,
name: "rust_device_i2c",
authors: ["Danilo Krummrich", "Igor Korotin"],
description: "Rust I2C client registration",
license: "GPL v2",
}
Annotation
- Detected declarations: `struct SampleDriver`.
- Atlas domain: Support Tooling And Documentation / samples.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.