pub trait Configure {
    const MIN_BIT_TIMINGS: BitTiming;
    const MAX_BIT_TIMINGS: BitTiming;
    const SYNC_SEG: u8 = 1u8;

    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 or set_bit_timing to configure the timing settings
  • Call set_operation_mode to configure the testing mode
  • (Optional) Call set_automatic_retransmission and/or set_wake_up to configure the behaviour of the peripheral
  • To apply the settings and be able to use the peripheral, call enable (from the Controller trait)

Required Associated Constants

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.

Provided Associated Constants

This constant represents the synchronization segment. Most CAN devices seems to have define this in hardware to 1 quantum long. 1 quantum long. It is used for the synchronization of the clocks.

Required Methods

Configures the CAN peripheral at the given bitrate. This function is supposed to be caled before the enable function. This function is synchronous as the driver should only calculate the timing parameters based on the bitrate and the frequenct 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

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

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

Returns the current timing parameters for the CAN peripheral.

Return values:
  • Ok(BitTiming) - The current timing parameters given to the peripheral
  • Err(ErrorCode) - Indicates the error because of which the request cannot be completed

Returns the current operating mode for the CAN peripheral.

Return values:
  • Ok(OperationMode) - The current operating mode parameter given to the peripheral
  • Err(ErrorCode) - Indicates the error because of which the request cannot be completed

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

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

Returns the current automatic retransmission setting of the peripheral.

Return values:
  • Ok(bool) - The current automatic retransmission setting
  • Err(ErrorCode) - Indicates the error because of which the request cannot be completed

Returns the current automatic wake up setting of the peripheral.

Return values:
  • Ok(bool) - The current automatic wake up setting
  • Err(ErrorCode) - Indicates the error because of which the request cannot be completed

Returns the number of receive FIFOs the peripheral provides

Implementors