pub struct Device<Ctx: DeviceContext = Normal>(/* private fields */);Expand description
The serial device bus device representation.
This structure represents the Rust abstraction for a C struct serdev_device. The
implementation abstracts the usage of an already existing C struct serdev_device within Rust
code that we get passed from the C side.
§Invariants
A Device instance represents a valid struct serdev_device created by the C portion of
the kernel.
Implementations§
Source§impl Device<Bound>
impl Device<Bound>
Sourcepub fn set_baudrate(&self, speed: u32) -> Result<(), u32>
pub fn set_baudrate(&self, speed: u32) -> Result<(), u32>
Set the baudrate in bits per second.
Common baudrates are 115200, 9600, 19200, 57600, 4800.
Use Device::write_flush before calling this if you have written data prior to this call.
Sourcepub fn set_flow_control(&self, enable: bool)
pub fn set_flow_control(&self, enable: bool)
Set if flow control should be enabled.
Use Device::write_flush before calling this if you have written data prior to this call.
Sourcepub fn set_parity(&self, parity: Parity) -> Result
pub fn set_parity(&self, parity: Parity) -> Result
Set parity to use.
Use Device::write_flush before calling this if you have written data prior to this call.
Sourcepub fn write_all(&self, data: &[u8], timeout: Jiffies) -> Result<usize>
pub fn write_all(&self, data: &[u8], timeout: Jiffies) -> Result<usize>
Write data to the serial device until the controller has accepted all the data or has been interrupted by a timeout or signal.
Note that any accepted data has only been buffered by the controller. Use
Device::wait_until_sent to make sure the controller write buffer has actually been
emptied.
Use a timeout of 0 to wait indefinitely.
Returns the number of bytes written (less than data.len() if interrupted).
kernel::error::code::ETIMEDOUT or kernel::error::code::ERESTARTSYS if interrupted
before any bytes were written. kernel::error::code::EINVAL if data.len() > i32::MAX.
Sourcepub fn write(&self, data: &[u8]) -> Result<u32>
pub fn write(&self, data: &[u8]) -> Result<u32>
Write data to the serial device.
If you want to write until the controller has accepted all the data, use
Device::write_all.
Note that any accepted data has only been buffered by the controller. Use
Device::wait_until_sent to make sure the controller write buffer has actually been
emptied.
Returns the number of bytes written (less than data.len() if not enough room in the
write buffer).
Sourcepub fn write_flush(&self)
pub fn write_flush(&self)
Send data to the serial device immediately.
Note that this doesn’t guarantee that the data has been transmitted.
Use Device::wait_until_sent for this purpose.
Sourcepub fn wait_until_sent(&self, timeout: Jiffies)
pub fn wait_until_sent(&self, timeout: Jiffies)
Wait for the data to be sent.
After this function, the write buffer of the controller should be empty or the timeout elapsed.
Use a timeout of 0 to wait indefinitely.