pub trait Controller {
// Required methods
fn set_client(&self, client: Option<&'static dyn ControllerClient>);
fn enable(&self) -> Result<(), ErrorCode>;
fn disable(&self) -> Result<(), ErrorCode>;
fn get_state(&self) -> Result<State, ErrorCode>;
}Expand description
The Controller trait is used to enable and disable the CAN peripheral.
The enable process applies the settings that were previously provided
to the driver using the Configure trait.
Required Methods§
Sourcefn set_client(&self, client: Option<&'static dyn ControllerClient>)
fn set_client(&self, client: Option<&'static dyn ControllerClient>)
Set the client to be used for callbacks of the Controller implementation.
Sourcefn enable(&self) -> Result<(), ErrorCode>
fn enable(&self) -> Result<(), ErrorCode>
This function enables the CAN peripheral with the Timing, Operation and Mode
arguments that are provided to the driver before calling the
enable function.
§Return values:
Ok()- The parameters were provided and the process can begin. The driver will call thestate_changedandenabledcallbacks after the process ends. Both of the callbacks must be called and the capsule should wait for theenablecallback before transmitting or receiving frames, as enabling might fail with an error. Whilestate_changedwill report the device as being inState::Disabled, it does not report the error. A client cannot otherwise differentiate between a callback issued due to failedenableor a peripheral’s decision to enter a disabled state.Err(ErrorCode)- Indicates the error because of which the request cannot be completed.ErrorCode::BUSY- the peripheral was already enabledErrorCode::INVAL- no arguments were previously provided
Sourcefn disable(&self) -> Result<(), ErrorCode>
fn disable(&self) -> Result<(), ErrorCode>
This function disables the CAN peripheral and puts it in Sleep Mode. The peripheral must be previously enabled.
§Return values:
Ok()- The peripheral was already enabled and the process can begin. The driver will call thestate_changedanddisabledcallbacks after the process ends. Both of the callbacks must be called and the capsule should wait for thedisabledcallback before considering the peripheral disabled, as disabling might fail with an erro . Whilestate_changedwill report the device as being inState::Enabled, it does not report the error. A client cannot otherwise differentiate between a callback issued due to faileddisableor a peripheral’s decision to enter the enable state.Err(ErrorCode)- Indicates the error because of which the request cannot be completed.ErrorCode::OFF- the peripheral was not previously enabled