pub struct Peripherals {Show 32 fields
pub pins: Pins,
pub ADC: ADC<Disabled>,
pub CTIMER0: CTIMER<Disabled, Detached, Detached, Detached>,
pub DMA: DMA<Disabled>,
pub GPIO: GPIO<Disabled>,
pub I2C0: I2C<I2C0, Disabled, Disabled, Disabled>,
pub I2C1: I2C<I2C1, Disabled, Disabled, Disabled>,
pub I2C2: I2C<I2C2, Disabled, Disabled, Disabled>,
pub I2C3: I2C<I2C3, Disabled, Disabled, Disabled>,
pub MRT0: MRT,
pub PININT: PININT<Disabled>,
pub PMU: PMU,
pub SPI0: SPI<SPI0, Disabled>,
pub SPI1: SPI<SPI1, Disabled>,
pub SWM: SWM<Disabled>,
pub SYSCON: SYSCON,
pub USART0: USART<USART0, Disabled>,
pub USART1: USART<USART1, Disabled>,
pub USART2: USART<USART2, Disabled>,
pub USART3: USART<USART3, Disabled>,
pub USART4: USART<USART4, Disabled>,
pub WKT: WKT<Disabled>,
pub ACOMP: ACOMP,
pub CAPT: CAPT,
pub CRC: CRC,
pub DAC0: DAC0,
pub DAC1: DAC1,
pub FLASH_CTRL: FLASH_CTRL,
pub INPUTMUX: INPUTMUX,
pub IOCON: IOCON,
pub SCT0: SCT0,
pub WWDT: WWDT,
}Expand description
Provides access to all peripherals
This is the entry point to the HAL API. Before you can do anything else, you
need to get an instance of this struct via Peripherals::take or
Peripherals::steal.
The HAL API tracks the state of peripherals at compile-time, to prevent potential bugs before the program can even run. Many parts of this documentation call this “type state”. The peripherals available in this struct are set to their initial state (i.e. their state after a system reset). See user manual, section 5.6.14.
§Safe Use of the API
Since it should be impossible (outside of unsafe code) to access the peripherals before this struct is initialized, you can rely on the peripheral states being correct, as long as there’s no bug in the API, and you’re not using unsafe code to do anything that the HAL API can’t account for.
If you directly use unsafe code to access peripherals or manipulate this API, this will be really obvious from the code. But please note that if you’re using other APIs to access the hardware, such conflicting hardware access might not be obvious, as the other API might use unsafe code under the hood to access the hardware (just like this API does).
If you do access the peripherals in any way not intended by this API, please make sure you know what you’re doing. In specific terms, this means you should be fully aware of what your code does, and whether that is a valid use of the hardware.
Fields§
§pins: PinsPins that can be used for GPIO or other functions
ADC: ADC<Disabled>Analog-to-Digital Converter (ADC)
CTIMER0: CTIMER<Disabled, Detached, Detached, Detached>Standard counter/timer (CTIMER)
DMA: DMA<Disabled>DMA controller
GPIO: GPIO<Disabled>General-purpose I/O (GPIO)
By default, the GPIO peripheral is enabled on the LPC82x and disabled on the LPC845.
I2C0: I2C<I2C0, Disabled, Disabled, Disabled>I2C0
I2C1: I2C<I2C1, Disabled, Disabled, Disabled>I2C1
I2C2: I2C<I2C2, Disabled, Disabled, Disabled>I2C2
I2C3: I2C<I2C3, Disabled, Disabled, Disabled>I2C3
MRT0: MRTMulti-Rate Timer (MRT)
PININT: PININT<Disabled>Pin interrupt and pattern match engine
PMU: PMUPower Management Unit
SPI0: SPI<SPI0, Disabled>SPI0
SPI1: SPI<SPI1, Disabled>SPI1
SWM: SWM<Disabled>Switch matrix
By default, the switch matrix is enabled on the LPC82x and disabled on the LPC845.
The reference manual for the LPC845 suggests otherwise, but it seems to be wrong.
SYSCON: SYSCONSystem configuration
USART0: USART<USART0, Disabled>USART0
USART1: USART<USART1, Disabled>USART1
USART2: USART<USART2, Disabled>USART2
USART3: USART<USART3, Disabled>USART3
USART3 and PIN_INT6 share an interrupt, this may cause difficulties when trying to use both at the same time
USART4: USART<USART4, Disabled>USART4
USART4 and PIN_INT7 share an interrupt, this may cause difficulties when trying to use both at the same time
WKT: WKT<Disabled>Self-wake-up timer (WKT)
ACOMP: ACOMPAnalog comparator
A HAL API for this peripheral has not been implemented yet. In the meantime, this field provides you with the raw register mappings, which allow you full, unprotected access to the peripheral.
CAPT: CAPTCapacitive Touch (CAPT)
A HAL API for this peripheral has not been implemented yet. In the meantime, this field provides you with the raw register mappings, which allow you full, unprotected access to the peripheral.
CRC: CRCCRC engine
A HAL API for this peripheral has not been implemented yet. In the meantime, this field provides you with the raw register mappings, which allow you full, unprotected access to the peripheral.
DAC0: DAC0Digital-to-Analog Converter 0 (DAC0)
A HAL API for this peripheral has not been implemented yet. In the meantime, this field provides you with the raw register mappings, which allow you full, unprotected access to the peripheral.
DAC1: DAC1Digital-to-Analog Converter 1 (DAC1)
A HAL API for this peripheral has not been implemented yet. In the meantime, this field provides you with the raw register mappings, which allow you full, unprotected access to the peripheral.
FLASH_CTRL: FLASH_CTRLFlash controller
A HAL API for this peripheral has not been implemented yet. In the meantime, this field provides you with the raw register mappings, which allow you full, unprotected access to the peripheral.
INPUTMUX: INPUTMUXInput multiplexing
A HAL API for this peripheral has not been implemented yet. In the meantime, this field provides you with the raw register mappings, which allow you full, unprotected access to the peripheral.
IOCON: IOCONI/O configuration
A HAL API for this peripheral has not been implemented yet. In the meantime, this field provides you with the raw register mappings, which allow you full, unprotected access to the peripheral.
SCT0: SCT0State Configurable Timer (SCT)
A HAL API for this peripheral has not been implemented yet. In the meantime, this field provides you with the raw register mappings, which allow you full, unprotected access to the peripheral.
WWDT: WWDTWindowed Watchdog Timer (WWDT)
A HAL API for this peripheral has not been implemented yet. In the meantime, this field provides you with the raw register mappings, which allow you full, unprotected access to the peripheral.
Implementations§
Source§impl Peripherals
impl Peripherals
Sourcepub fn take() -> Option<Self>
pub fn take() -> Option<Self>
Take the peripherals safely
This method can only be called one time to access the peripherals. It
will return Some(Peripherals) when called for the first time, then
None on any subsequent calls.
Applications should call this method once, at the beginning of their main method, to get access to the full API. Any other parts of the program should just expect to be passed whatever parts of the HAL API they need.
Calling this method from a library is considered an anti-pattern. Libraries should just require whatever they need to be passed as arguments and leave the initialization to the application that calls them.
For an alternative way to gain access to the hardware, please take a
look at Peripherals::steal.
§Example
use lpc8xx_hal::Peripherals;
// This code should be at the beginning of your program. As long as this
// is the only place that calls `take`, the following should never
// panic.
let p = Peripherals::take().unwrap();Sourcepub unsafe fn steal() -> Self
pub unsafe fn steal() -> Self
Steal the peripherals
This function returns an instance of Peripherals, whether or not such
an instance exists somewhere else. This is highly unsafe, as it can lead
to conflicting access of the hardware, mismatch between actual hardware
state and peripheral state as tracked by this API at compile-time, and
in general a full nullification of all safety guarantees that this API
would normally make.
If at all possible, you should always prefer Peripherals::take to this
method. The only legitimate use of this API is code that can’t access
Peripherals the usual way, like a panic handler, or maybe temporary
debug code in an interrupt handler.
§Safety
This method returns an instance of Peripherals that might conflict
with either other instances of Peripherals that exist in the program,
or other means of accessing the hardware. This is only sure, if you make
sure of the following:
- No other code can access the hardware at the same time.
- You don’t change the hardware state in any way that could invalidate
the type state of other
Peripheralsinstances. - The type state in your
Peripheralsinstance matches the actual state of the hardware.
Items 1. and 2. are really tricky, so it is recommended to avoid any situations where they apply, and restrict the use of this method to situations where the program has effectively ended and the hardware will be reset right after (like a panic handler).
Item 3. applies to all uses of this method, and is generally very tricky to get right. The best way to achieve that is probably to force the API into a type state that allows you to execute operations that are known to put the hardware in a safe state. Like forcing the type state for a peripheral API to the “disabled” state, then enabling it, to make sure it is enabled, regardless of whether it was enabled before.
Since there are no means within this API to forcibly change type state,
you will need to resort to something like core::mem::transmute.