pub trait Configure {
const MIN_BIT_TIMINGS: BitTiming;
const MAX_BIT_TIMINGS: BitTiming;
const SYNC_SEG: u8 = 1u8;
// Required methods
fn set_bitrate(&self, bitrate: u32) -> Result<(), ErrorCode>;
fn set_bit_timing(&self, bit_timing: BitTiming) -> Result<(), ErrorCode>;
fn set_operation_mode(&self, mode: OperationMode) -> Result<(), ErrorCode>;
fn get_bit_timing(&self) -> Result<BitTiming, ErrorCode>;
fn get_operation_mode(&self) -> Result<OperationMode, ErrorCode>;
fn set_automatic_retransmission(
&self,
automatic: bool,
) -> Result<(), ErrorCode>;
fn set_wake_up(&self, wake_up: bool) -> Result<(), ErrorCode>;
fn get_automatic_retransmission(&self) -> Result<bool, ErrorCode>;
fn get_wake_up(&self) -> Result<bool, ErrorCode>;
fn receive_fifo_count(&self) -> usize;
}
Expand description
The Configure
trait is used to configure the CAN peripheral and to prepare it for
transmission and reception of data.
The peripheral cannot transmit or receive frames if it is not previously configured and enabled.
In order to configure the peripheral, the following steps are required:
- Call
set_bitrate
orset_bit_timing
to configure the timing settings - Call
set_operation_mode
to configure the testing mode - (Optional) Call
set_automatic_retransmission
and/orset_wake_up
to configure the behaviour of the peripheral - To apply the settings and be able to use the peripheral, call
enable
(from theController
trait)
Required Associated Constants§
Sourceconst MIN_BIT_TIMINGS: BitTiming
const MIN_BIT_TIMINGS: BitTiming
Constants that define the minimum and maximum values that the timing parameters can take. They are used when calculating the optimum timing parameters for a given bitrate.
const MAX_BIT_TIMINGS: BitTiming
Provided Associated Constants§
Required Methods§
Sourcefn set_bitrate(&self, bitrate: u32) -> Result<(), ErrorCode>
fn set_bitrate(&self, bitrate: u32) -> Result<(), ErrorCode>
Configures the CAN peripheral at the given bitrate. This function is
supposed to be called before the enable
function. This function is
synchronous as the driver should only calculate the timing parameters
based on the bitrate and the frequency of the board and store them.
This function does not configure the hardware.
§Arguments:
bitrate
- A value that represents the bitrate for the CAN communication.
§Return values:
Ok()
- The timing parameters were calculated and stored.Err(ErrorCode)
- Indicates the error because of which the request cannot be completed
Sourcefn set_bit_timing(&self, bit_timing: BitTiming) -> Result<(), ErrorCode>
fn set_bit_timing(&self, bit_timing: BitTiming) -> Result<(), ErrorCode>
Configures the CAN peripheral with the given arguments. This function is
supposed to be called before the enable
function. This function is
synchronous as the driver should only store the arguments, and should not
configure the hardware.
§Arguments:
bit_timing
- A BitTiming structure to define the bit timing settings for the peripheral
§Return values:
Ok()
- The parameters were stored.Err(ErrorCode)
- Indicates the error because of which the request cannot be completed
Sourcefn set_operation_mode(&self, mode: OperationMode) -> Result<(), ErrorCode>
fn set_operation_mode(&self, mode: OperationMode) -> Result<(), ErrorCode>
Configures the CAN peripheral with the given arguments. This function is
supposed to be called before the enable
function. This function is
synchronous as the driver should only store the arguments, and should not
configure the hardware.
§Arguments:
mode
- An OperationMode structure to define the running mode of the peripheral
§Return values:
Ok()
- The parameters were stored.Err(ErrorCode)
- Indicates the error because of which the request cannot be completed
Sourcefn get_bit_timing(&self) -> Result<BitTiming, ErrorCode>
fn get_bit_timing(&self) -> Result<BitTiming, ErrorCode>
Returns the current timing parameters for the CAN peripheral.
§Return values:
Ok(BitTiming)
- The current timing parameters given to the peripheralErr(ErrorCode)
- Indicates the error because of which the request cannot be completed
Sourcefn get_operation_mode(&self) -> Result<OperationMode, ErrorCode>
fn get_operation_mode(&self) -> Result<OperationMode, ErrorCode>
Returns the current operating mode for the CAN peripheral.
§Return values:
Ok(OperationMode)
- The current operating mode parameter given to the peripheralErr(ErrorCode)
- Indicates the error because of which the request cannot be completed
Sourcefn set_automatic_retransmission(&self, automatic: bool) -> Result<(), ErrorCode>
fn set_automatic_retransmission(&self, automatic: bool) -> Result<(), ErrorCode>
Configures the CAN peripheral with the automatic retransmission setting.
This function is optional, but if used, must be called before the
enable
function. This function is synchronous as the driver should
only store the arguments, and should not configure the hardware.
§Arguments:
automatic
- Value to configure the automatic retransmission setting
§Return values:
Ok()
- The setting was stored.Err(ErrorCode)
- Indicates the error because of which the request cannot be completed
Sourcefn set_wake_up(&self, wake_up: bool) -> Result<(), ErrorCode>
fn set_wake_up(&self, wake_up: bool) -> Result<(), ErrorCode>
Configures the CAN peripheral with the automatic wake up setting.
This function is optional, but if used, must be called before the
enable
function. This function is synchronous as the driver should
only store the arguments, and should not configure the hardware.
§Arguments:
wake_up
- Value to configure the automatic wake up setting
§Return values:
Ok()
- The setting was stored.Err(ErrorCode)
- Indicates the error because of which the request cannot be completed
Sourcefn get_automatic_retransmission(&self) -> Result<bool, ErrorCode>
fn get_automatic_retransmission(&self) -> Result<bool, ErrorCode>
Returns the current automatic retransmission setting of the peripheral.
§Return values:
Ok(bool)
- The current automatic retransmission settingErr(ErrorCode)
- Indicates the error because of which the request cannot be completed
Sourcefn get_wake_up(&self) -> Result<bool, ErrorCode>
fn get_wake_up(&self) -> Result<bool, ErrorCode>
Returns the current automatic wake up setting of the peripheral.
§Return values:
Ok(bool)
- The current automatic wake up settingErr(ErrorCode)
- Indicates the error because of which the request cannot be completed
Sourcefn receive_fifo_count(&self) -> usize
fn receive_fifo_count(&self) -> usize
Returns the number of receive FIFOs the peripheral provides
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.