Function

Struct Function 

Source
pub struct Function<T, S> { /* private fields */ }
Expand description

A fixed or movable function that can be assigned to a pin

The type parameter T identifies the fixed or movable function that an instance of Function controls. The other type paramter, State, tracks whether this function is assigned to a pin, and which pin it is assigned to.

You can gain access to the instances of this struct that represent fixed functions through FixedFunctions, to those that represent movable functions through MovableFunctions.

Implementations§

Source§

impl<T> Function<T, Unassigned>

Source

pub fn assign<P, S>( self, pin: Pin<P, S>, swm: &mut Handle, ) -> (Function<T, Assigned<P>>, <Pin<P, S> as AssignFunction<T, T::Kind>>::Assigned)
where T: FunctionTrait<P>, P: Trait, S: State, Pin<P, S>: AssignFunction<T, T::Kind>,

Assign this function to a pin

This method is only available if a number of requirements are met:

  • Function must be in the Unassigned state, as a function can only be assigned to one pin.
  • The Pin must be in the SWM state (pins::state::Swm). See documentation on Pin for information on pin state management.
  • The function must be assignable to the pin. Movable functions can be assigned to any pin, but fixed functions can be assigned to only one specific pin.
  • The state of the pin must allow another function of this type to be assigned. Input functions can always be assigned, but only one output or bidirectional function can be assigned to a given pin at any time.

Code attempting to call this method while these requirement are not met, will not compile.

Consumes this instance of Function, as well as the provided Pin, and returns new instances. The returned Function instance will have its state set to indicate that it has been assigned to the pin. The returned Pin will have its state updated to indicate that a function of this Function’s type has been assigned.

§Examples

Assign one output and one input function to the same pin:

use lpc8xx_hal::Peripherals;

let p = Peripherals::take().unwrap();

let mut syscon = p.SYSCON.split();
let mut swm = p.SWM.split();

#[cfg(feature = "82x")]
let mut swm_handle = swm.handle;
#[cfg(feature = "845")]
let mut swm_handle = swm.handle.enable(&mut syscon.handle);

// Assign output function to a pin
let (u0_txd, pio0_0) = swm.movable_functions.u0_txd.assign(
    p.pins.pio0_0.into_swm_pin(),
    &mut swm_handle,
);

// Assign input function to the same pin
let (u1_rxd, pio0_0) = swm.movable_functions.u1_rxd.assign(
    pio0_0,
    &mut swm_handle,
);
Source§

impl<T, P> Function<T, Assigned<P>>

Source

pub fn unassign<S>( self, pin: Pin<P, S>, swm: &mut Handle, ) -> (Function<T, Unassigned>, <Pin<P, S> as UnassignFunction<T, T::Kind>>::Unassigned)
where T: FunctionTrait<P>, P: Trait, S: State, Pin<P, S>: UnassignFunction<T, T::Kind>,

Unassign this function from a pin

This method is only available if a number of requirements are met:

  • The function must be assigned to the provided pin. This means Function must be in the Assigned state, and the type parameter of Assigned must indicate that the function is assigned to the same pin that is provided as an argument.
  • The Pin must be in the SWM state (pins::state::Swm), and the state must indicate that a function of this Function’s type is currently assigned. This should always be the case, if the previous condition is met, as it should be impossible to create inconsistent states between Functions and Pins without using unsafe.

Code attempting to call this method while these requirement are not met, will not compile.

Consumes this instance of Function, as well as the provided Pin, and returns new instances. The returned Function instance will have its state set to indicate that it is no longer assigned to a pin. The returned Pin will have its state updated to indicate that one fewer function of this type is now assigned.

§Examples

Unassign a function that has been previously assigned to a pin:

// U0_TXD must have been previously assigned to the pin, or the
// following code will not compile. See documentation of
// `Function::assign`.
let (u0_txd, pio0_0) = u0_txd.unassign(pio0_0, &mut swm_handle);

Trait Implementations§

Source§

impl<PIN> Channel<ADC> for Function<ADC_0, Assigned<PIN>>

Source§

type ID = u8

Channel ID type Read more
Source§

fn channel() -> Self::ID

Get the specific ID that identifies this channel, for example 0_u8 for the first ADC channel, if Self::ID is u8.
Source§

impl<PIN> Channel<ADC> for Function<ADC_1, Assigned<PIN>>

Source§

type ID = u8

Channel ID type Read more
Source§

fn channel() -> Self::ID

Get the specific ID that identifies this channel, for example 0_u8 for the first ADC channel, if Self::ID is u8.
Source§

impl<PIN> Channel<ADC> for Function<ADC_10, Assigned<PIN>>

Source§

type ID = u8

Channel ID type Read more
Source§

fn channel() -> Self::ID

Get the specific ID that identifies this channel, for example 0_u8 for the first ADC channel, if Self::ID is u8.
Source§

impl<PIN> Channel<ADC> for Function<ADC_11, Assigned<PIN>>

Source§

type ID = u8

Channel ID type Read more
Source§

fn channel() -> Self::ID

Get the specific ID that identifies this channel, for example 0_u8 for the first ADC channel, if Self::ID is u8.
Source§

impl<PIN> Channel<ADC> for Function<ADC_2, Assigned<PIN>>

Source§

type ID = u8

Channel ID type Read more
Source§

fn channel() -> Self::ID

Get the specific ID that identifies this channel, for example 0_u8 for the first ADC channel, if Self::ID is u8.
Source§

impl<PIN> Channel<ADC> for Function<ADC_3, Assigned<PIN>>

Source§

type ID = u8

Channel ID type Read more
Source§

fn channel() -> Self::ID

Get the specific ID that identifies this channel, for example 0_u8 for the first ADC channel, if Self::ID is u8.
Source§

impl<PIN> Channel<ADC> for Function<ADC_4, Assigned<PIN>>

Source§

type ID = u8

Channel ID type Read more
Source§

fn channel() -> Self::ID

Get the specific ID that identifies this channel, for example 0_u8 for the first ADC channel, if Self::ID is u8.
Source§

impl<PIN> Channel<ADC> for Function<ADC_5, Assigned<PIN>>

Source§

type ID = u8

Channel ID type Read more
Source§

fn channel() -> Self::ID

Get the specific ID that identifies this channel, for example 0_u8 for the first ADC channel, if Self::ID is u8.
Source§

impl<PIN> Channel<ADC> for Function<ADC_6, Assigned<PIN>>

Source§

type ID = u8

Channel ID type Read more
Source§

fn channel() -> Self::ID

Get the specific ID that identifies this channel, for example 0_u8 for the first ADC channel, if Self::ID is u8.
Source§

impl<PIN> Channel<ADC> for Function<ADC_7, Assigned<PIN>>

Source§

type ID = u8

Channel ID type Read more
Source§

fn channel() -> Self::ID

Get the specific ID that identifies this channel, for example 0_u8 for the first ADC channel, if Self::ID is u8.
Source§

impl<PIN> Channel<ADC> for Function<ADC_8, Assigned<PIN>>

Source§

type ID = u8

Channel ID type Read more
Source§

fn channel() -> Self::ID

Get the specific ID that identifies this channel, for example 0_u8 for the first ADC channel, if Self::ID is u8.
Source§

impl<PIN> Channel<ADC> for Function<ADC_9, Assigned<PIN>>

Source§

type ID = u8

Channel ID type Read more
Source§

fn channel() -> Self::ID

Get the specific ID that identifies this channel, for example 0_u8 for the first ADC channel, if Self::ID is u8.

Auto Trait Implementations§

§

impl<T, S> Freeze for Function<T, S>
where T: Freeze, S: Freeze,

§

impl<T, S> RefUnwindSafe for Function<T, S>

§

impl<T, S> Send for Function<T, S>
where T: Send, S: Send,

§

impl<T, S> Sync for Function<T, S>
where T: Sync, S: Sync,

§

impl<T, S> Unpin for Function<T, S>
where T: Unpin, S: Unpin,

§

impl<T, S> UnwindSafe for Function<T, S>
where T: UnwindSafe, S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.