gossamer 0.0.0
a very lightweight app framework for SAMD and SAML chips
Loading...
Searching...
No Matches
tcc.h
Go to the documentation of this file.
1
5/*
6 * MIT License
7 *
8 * Copyright (c) 2022 Joey Castillo
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included in all
18 * copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * SOFTWARE.
27 */
28
29#pragma once
30
31#include <stdint.h>
32#include <stdbool.h>
33#include "sam.h"
34
35typedef enum {
36 TCC_PRESCALER_DIV1 = 0,
37 TCC_PRESCALER_DIV2 = 1,
38 TCC_PRESCALER_DIV4 = 2,
39 TCC_PRESCALER_DIV8 = 3,
40 TCC_PRESCALER_DIV16 = 4,
41 TCC_PRESCALER_DIV64 = 5,
42 TCC_PRESCALER_DIV256 = 6,
43 TCC_PRESCALER_DIV1024 = 7
44} tcc_prescaler_value_t;
45
46typedef enum {
47 TCC_WAVEGEN_NORMAL_FREQUENCY = 0,
48 TCC_WAVEGEN_MATCH_FREQUENCY = 1,
49 TCC_WAVEGEN_NORMAL_PWM = 2,
50// These modes may be supported in the future, but I don't have a use for them right now.
51 // TCC_WAVEGEN_DUAL_SLOPE_TOP = 7,
52 // TCC_WAVEGEN_DUAL_SLOPE_BOTTOM = 5,
53 // TCC_WAVEGEN_DUAL_SLOPE_BOTH = 6,
54 // TCC_WAVEGEN_DUAL_SLOPE_CRITICAL = 4,
55} tcc_wavegen_t;
56
57typedef enum {
58 TCC_OUTPUT_MATRIX_MODULO_4 = 0,
59 TCC_OUTPUT_MATRIX_MODULO_2 = 1,
60 TCC_OUTPUT_MATRIX_ALL_CC0 = 2,
61 TCC_OUTPUT_MATRIX_WO0_CC0_OTHERS_CC1 = 3,
62} tcc_output_matrix_t;
63
64typedef enum {
65 TCC_CHANNEL_POLARITY_NORMAL = 0,
66 TCC_CHANNEL_POLARITY_INVERTED = 1,
67} tcc_channel_polarity_t;
68
89bool tcc_init(uint8_t instance, generic_clock_generator_t clocksource, tcc_prescaler_value_t prescaler);
90
96void tcc_set_run_in_standby(uint8_t instance, bool runStandby);
97
116void tcc_set_wavegen(uint8_t instance, tcc_wavegen_t mode);
117
133void tcc_set_output_matrix(uint8_t instance, tcc_output_matrix_t mode);
134
146void tcc_set_channel_polarity(uint8_t instance, uint8_t channel, tcc_channel_polarity_t polarity);
147
151void tcc_enable(uint8_t instance);
152
157bool tcc_is_enabled(uint8_t instance);
158
166void tcc_set_period(uint8_t instance, uint32_t period);
167
175void tcc_set_cc(uint8_t instance, uint8_t channel, uint32_t value);
176
182void tcc_set_count(uint8_t instance, uint32_t value);
183
189uint32_t tcc_get_count(uint8_t instance);
190
203void tcc_stop(uint8_t instance);
204
209void tcc_retrigger(uint8_t instance);
210
215void tcc_update(uint8_t instance);
216
220void tcc_disable(uint8_t instance);
void tcc_disable(uint8_t instance)
Disables the TCC, but retains all its settings.
Definition: tcc.c:125
void tcc_set_run_in_standby(uint8_t instance, bool runStandby)
Sets whether the TCC should run in standby mode.
Definition: tcc.c:56
void tcc_set_count(uint8_t instance, uint32_t value)
Sets the value of the counter.
Definition: tcc.c:99
void tcc_set_cc(uint8_t instance, uint8_t channel, uint32_t value)
Sets the value of a compare channel.
Definition: tcc.c:94
uint32_t tcc_get_count(uint8_t instance)
Gets the current value of the counter.
Definition: tcc.c:104
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....
Definition: tcc.c:33
void tcc_set_output_matrix(uint8_t instance, tcc_output_matrix_t mode)
Sets the output matrix for the TCC.
Definition: tcc.c:64
bool tcc_is_enabled(uint8_t instance)
Checks whether the TCC is enabled.
Definition: tcc.c:85
void tcc_enable(uint8_t instance)
Enables the TCC. Make sure to call tcc_init first to set it up.
Definition: tcc.c:80
void tcc_set_wavegen(uint8_t instance, tcc_wavegen_t mode)
Sets the waveform generation mode for the TCC.
Definition: tcc.c:60
void tcc_stop(uint8_t instance)
Issues a STOP command to the TCC.
Definition: tcc.c:110
void tcc_update(uint8_t instance)
Issues an UPDATE command to the TCC.
Definition: tcc.c:120
void tcc_set_channel_polarity(uint8_t instance, uint8_t channel, tcc_channel_polarity_t polarity)
Sets the polarity of a channel.
Definition: tcc.c:68
void tcc_retrigger(uint8_t instance)
Issues a RETRIGGER command to the TCC.
Definition: tcc.c:115
void tcc_set_period(uint8_t instance, uint32_t period)
Sets the period of the TCC.
Definition: tcc.c:89