gossamer 0.0.1
a very lightweight app framework for SAMD and SAML chips
|
Functions for configuring and using the TCC peripheral, a more advanced timer/counter. More...
Functions | |
bool | tcc_init (uint8_t instance, generic_clock_generator_t clocksource, tcc_prescaler_value_t prescaler) |
Enables the peripheral clock for the TCC and clocks it with the selected clock source. Also resets the TCC to its starting configuration. | |
void | tcc_set_run_in_standby (uint8_t instance, bool runStandby) |
Sets whether the TCC should run in standby mode. | |
void | tcc_set_wavegen (uint8_t instance, tcc_wavegen_t mode) |
Sets the waveform generation mode for the TCC. | |
void | tcc_set_output_matrix (uint8_t instance, tcc_output_matrix_t mode) |
Sets the output matrix for the TCC. | |
void | tcc_set_channel_polarity (uint8_t instance, uint8_t channel, tcc_channel_polarity_t polarity) |
Sets the polarity of a channel. | |
void | tcc_enable (uint8_t instance) |
Enables the TCC. Make sure to call tcc_init first to set it up. | |
bool | tcc_is_enabled (uint8_t instance) |
Checks whether the TCC is enabled. | |
void | tcc_set_period (uint8_t instance, uint32_t period, bool buffered) |
Sets the period of the TCC. | |
uint32_t | tcc_get_period (uint8_t instance) |
Gets the period of the TCC. | |
void | tcc_set_cc (uint8_t instance, uint8_t channel, uint32_t value, bool buffered) |
Sets the value of a compare channel. | |
void | tcc_set_count (uint8_t instance, uint32_t value) |
Sets the value of the counter. | |
uint32_t | tcc_get_count (uint8_t instance) |
Gets the current value of the counter. | |
void | tcc_stop (uint8_t instance) |
Issues a STOP command to the TCC. | |
void | tcc_retrigger (uint8_t instance) |
Issues a RETRIGGER command to the TCC. | |
void | tcc_update (uint8_t instance) |
Issues an UPDATE command to the TCC. | |
void | tcc_disable (uint8_t instance) |
Disables the TCC, but retains all its settings. | |
Functions for configuring and using the TCC peripheral, a more advanced timer/counter.
void tcc_disable | ( | uint8_t | instance | ) |
Disables the TCC, but retains all its settings.
instance | The TCC peripheral instance as numbered in the data sheet, or 0. |
void tcc_enable | ( | uint8_t | instance | ) |
Enables the TCC. Make sure to call tcc_init first to set it up.
instance | The TCC peripheral instance as numbered in the data sheet, or 0. |
uint32_t tcc_get_count | ( | uint8_t | instance | ) |
Gets the current value of the counter.
instance | The TCC peripheral instance as numbered in the data sheet, or 0. |
uint32_t tcc_get_period | ( | uint8_t | instance | ) |
Gets the period of the TCC.
instance | The TCC peripheral instance as numbered in the data sheet, or 0. |
bool tcc_init | ( | uint8_t | instance, |
generic_clock_generator_t | clocksource, | ||
tcc_prescaler_value_t | prescaler | ||
) |
Enables the peripheral clock for the TCC and clocks it with the selected clock source. Also resets the TCC to its starting configuration.
This just sets up the TCC in its reset state. You are still responsible for configuring it with the options you need for waveform output.
instance | The TCC peripheral instance as numbered in the data sheet, or 0. |
clocksource | The clock source to use for the TCC. |
prescaler | The prescaler factor, which divides the clock source by a factor:
|
bool tcc_is_enabled | ( | uint8_t | instance | ) |
Checks whether the TCC is enabled.
instance | The TCC peripheral instance as numbered in the data sheet, or 0. |
void tcc_retrigger | ( | uint8_t | instance | ) |
Issues a RETRIGGER command to the TCC.
instance | The TCC peripheral instance as numbered in the data sheet, or 0. |
void tcc_set_cc | ( | uint8_t | instance, |
uint8_t | channel, | ||
uint32_t | value, | ||
bool | buffered | ||
) |
Sets the value of a compare channel.
instance | The TCC peripheral instance as numbered in the data sheet, or 0. |
channel | The compare channel to set, from 0 to 3 (or 0-1 on some TCCs; check the data sheet) |
buffered | If true, sets the CC value in the buffered register, which will be loaded at the next UPDATE condition. If false, sets the period directly. Note that double buffering is not available on the SAM D11 and SAM D21, and a value of true on those platforms will be ignored. |
value | The value to set the compare channel to. Max 24 bits (16,777,215). |
void tcc_set_channel_polarity | ( | uint8_t | instance, |
uint8_t | channel, | ||
tcc_channel_polarity_t | polarity | ||
) |
Sets the polarity of a channel.
instance | The TCC peripheral instance as numbered in the data sheet, or 0. |
channel | The waveform output channel from 0 to 7. |
polarity | The polarity to set. One of:
|
void tcc_set_count | ( | uint8_t | instance, |
uint32_t | value | ||
) |
Sets the value of the counter.
instance | The TCC peripheral instance as numbered in the data sheet, or 0. |
value | The value to set the counter to. Max 24 bits (16,777,215). |
void tcc_set_output_matrix | ( | uint8_t | instance, |
tcc_output_matrix_t | mode | ||
) |
Sets the output matrix for the TCC.
instance | The TCC peripheral instance as numbered in the data sheet, or 0. |
mode | The output matrix mode to use. One of:
|
void tcc_set_period | ( | uint8_t | instance, |
uint32_t | period, | ||
bool | buffered | ||
) |
Sets the period of the TCC.
instance | The TCC peripheral instance as numbered in the data sheet, or 0. |
period | The period to set. |
buffered | If true, sets the period in the buffered register, which will be loaded at the next UPDATE condition. If false, sets the period directly. Note that double buffering is not available on the SAM D11 and SAM D21, and a value of true on those platforms will be ignored. |
The period is the value that the counter counts up to before resetting. The frequency of the timer is determined by the period and the prescaler value.
void tcc_set_run_in_standby | ( | uint8_t | instance, |
bool | runStandby | ||
) |
Sets whether the TCC should run in standby mode.
instance | The TCC peripheral instance as numbered in the data sheet, or 0. |
runStandby | true if the TCC should run in standby mode, false otherwise. |
void tcc_set_wavegen | ( | uint8_t | instance, |
tcc_wavegen_t | mode | ||
) |
Sets the waveform generation mode for the TCC.
instance | The TCC peripheral instance as numbered in the data sheet, or 0. |
mode | The waveform generation mode to use. One of:
|
tcc_set_output_matrix
for other options). This mode results in a square wave with a frequency dependent on the PER register, and a duty cycle that depends on the CCn register.tcc_set_output_matrix
for other options). This mode results in a square wave with a frequency defined by the PER register, and a duty cycle defined by the CCn register. void tcc_stop | ( | uint8_t | instance | ) |
Issues a STOP command to the TCC.
instance | The TCC peripheral instance as numbered in the data sheet, or 0. |
When a stop is detected while the counter is running, the counter will maintain its current value, and the Stop bit in the Status register will be set (STATUS.STOP).
void tcc_update | ( | uint8_t | instance | ) |
Issues an UPDATE command to the TCC.
instance | The TCC peripheral instance as numbered in the data sheet, or 0. |