pub struct Gclk<G, I>where
    G: GclkId,
    I: GclkSourceId,
{ /* private fields */ }
Expand description

Generic clock generator used to distribute clocks to various peripherals

A generic clock generator acts as a branch in the clock tree. It can connect a root or branch clock to other branch or leaf clocks. In particular, all peripheral Pclks must be derived from a Gclk.

The type parameter G is a GclkId that determines which of the 12 generators this Gclk represents (Gclk0 - Gclk11). The type parameter I represents the Id type for the clock Source driving this Gclk. It must be one of the valid GclkSourceIds. Alternatively, if the Gclk is driven by a GPIO Pin, then I is a PinId implementing GclkIo. See the clock module documentation for more detail on Id types.

On its own, an instance of Gclk does not represent an enabled clock generator. Instead, it must first be wrapped with Enabled, which implements compile-time safety of the clock tree.

Because the terminal call to enable consumes the Gclk and returns an EnabledGclk, the remaining API uses the builder pattern, where each method takes and returns self by value, allowing them to be easily chained.

See the module-level documentation for an example of creating, configuring and using a Gclk.

Implementations

Create a new Gclk from a GPIO Pin

Creating a Gclk does not modify any of the hardware registers. It only serves to consume the Pin and create a struct to track the GCLK configuration.

The configuration data is stored until the user calls enable. At that point, all of the registers are written according to the initialization procedures specified in the datasheet, and an EnabledGclk is returned. The Gclk is not active or useful until that point.

Consume the Gclk and free its corresponding resources

Freeing a Gclk returns the corresponding GclkToken and GPIO Pin.

Create a new Gclk from a clock Source

Creating a Gclk does not modify any of the hardware registers. It only serves to Increment the Source’s Enabled counter and create a struct to track the GCLK configuration.

The configuration data is stored until the user calls enable. At that point, all of the registers are written according to the initialization procedures specified in the datasheet, and an EnabledGclk is returned. The Gclk is not active or useful until that point.

Consume the Gclk and free its corresponding resources

Freeing a Gclk returns the corresponding GclkToken and Decrements the Source’s Enabled counter.

Set the GclkDivider value

Set the clock division factor from input to output. This takes either a GclkDiv8 or GclkDiv16 enum, restricting the possible division factors to only the valid ones for the given Gclk. See the GclkDivider trait for more details.

Output a 50-50 duty cycle clock when using an odd GclkDivider

Return the Gclk ouput frequency

This is the input frequency divided by the GclkDivider.

Set the state of GclkOut pins when GclkIo output is disabled

The output off value (OOV) determines the logic level of a GPIO Pin (configured as a GclkIo output) when the Gclk is disabled OR the GclkOut is disabled.

As mentioned in the Gclk documentation, configuration options are not usually applied until the call to Gclk::enable. However, because the OOV is relevant when the Gclk is disabled, we make an exception. When calling this function, the new OOV will take effect immediately.

However, remember that the Pin is not controlled by the Gclk unless the Pin is configured in AlternateM mode. Pins are automatically set to AlternateM mode when calling enable_gclk_out, but by that point, the OOV is irrelevant. If you need the Pin to be set to its OOV, you must manually set it to AlternateM mode before constructing the GclkOut.

Enable the Gclk, so that it can be used as a clock Source

As mentioned in the Gclk documentation, no hardware registers are actually modified until this call. Rather, the desired configuration is stored internally, and the Gclk is initialized and configured here according to the datasheet.

The returned value is an EnabledGclk that can be used as a clock Source for other clocks.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.