gossamer 0.0.0
a very lightweight app framework for SAMD and SAML chips
Loading...
Searching...
No Matches
tc.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#include "system.h"
35
36typedef enum {
37 TC_PRESCALER_DIV1 = 0,
38 TC_PRESCALER_DIV2 = 1,
39 TC_PRESCALER_DIV4 = 2,
40 TC_PRESCALER_DIV8 = 3,
41 TC_PRESCALER_DIV16 = 4,
42 TC_PRESCALER_DIV64 = 5,
43 TC_PRESCALER_DIV256 = 6,
44 TC_PRESCALER_DIV1024 = 7
45} tc_prescaler_value_t;
46
47typedef enum {
48 TC_COUNTER_MODE_16BIT = 0,
49 TC_COUNTER_MODE_8BIT = 1,
50 TC_COUNTER_MODE_32BIT = 2,
51} tc_counter_mode_t;
52
53typedef enum {
54 TC_WAVEGEN_NORMAL_FREQUENCY = 0,
55 TC_WAVEGEN_MATCH_FREQUENCY = 1,
56 TC_WAVEGEN_NORMAL_PWM = 2,
57 TC_WAVEGEN_MATCH_PWM = 3,
58} tc_wavegen_t;
59
60typedef enum {
61 TC_CHANNEL_POLARITY_NORMAL = 0,
62 TC_CHANNEL_POLARITY_INVERTED = 1,
63} tc_channel_polarity_t;
64
86bool tc_init(uint8_t instance, generic_clock_generator_t clocksource, tc_prescaler_value_t prescaler);
87
107void tc_set_counter_mode(uint8_t instance, tc_counter_mode_t mode);
108
114void tc_set_run_in_standby(uint8_t instance, bool runStandby);
115
140void tc_set_wavegen(uint8_t instance, tc_wavegen_t mode);
141
154void tc_set_channel_polarity(uint8_t instance, uint8_t channel, tc_channel_polarity_t polarity);
155
159void tc_enable(uint8_t instance);
160
165bool tc_is_enabled(uint8_t instance);
166
173void tc_count8_set_period(uint8_t instance, uint8_t period);
174
182void tc_count8_set_cc(uint8_t instance, uint8_t channel, uint8_t value);
183
191void tc_count16_set_cc(uint8_t instance, uint8_t channel, uint16_t value);
192
199void tc_count32_set_cc(uint8_t instance, uint8_t channel, uint32_t value);
200
206void tc_count8_set_count(uint8_t instance, uint8_t value);
207
215void tc_count16_set_count(uint8_t instance, uint16_t value);
216
222void tc_count32_set_count(uint8_t instance, uint32_t value);
223
229uint8_t tc_count8_get_count(uint8_t instance);
230
238uint16_t tc_count16_get_count(uint8_t instance);
239
245uint32_t tc_count32_get_count(uint8_t instance);
246
254void tc_stop(uint8_t instance);
255
263void tc_retrigger(uint8_t instance);
264
268void tc_disable(uint8_t instance);
Gossamer system routines.
uint8_t tc_count8_get_count(uint8_t instance)
Gets the TC's current counter value in 8-bit mode.
Definition: tc.c:152
void tc_set_run_in_standby(uint8_t instance, bool runStandby)
Sets the TC's run-in-standby mode.
Definition: tc.c:74
void tc_stop(uint8_t instance)
Issues a STOP command to the TC.
Definition: tc.c:167
bool tc_is_enabled(uint8_t instance)
Checks whether the TC is enabled.
Definition: tc.c:110
bool tc_init(uint8_t instance, generic_clock_generator_t clocksource, tc_prescaler_value_t prescaler)
Enables the peripheral clock for the TC and clocks it with the selected clock source....
Definition: tc.c:36
void tc_enable(uint8_t instance)
Enables the TC. Make sure to call tc_init first to set it up.
Definition: tc.c:105
void tc_count16_set_count(uint8_t instance, uint16_t value)
Sets the TC's counter value in 16-bit mode.
Definition: tc.c:134
uint16_t tc_count16_get_count(uint8_t instance)
Gets the TC's current counter value in 16-bit mode.
Definition: tc.c:157
void tc_count16_set_cc(uint8_t instance, uint8_t channel, uint16_t value)
Sets the TC's compare channel CC0 or CC1 register in 16-bit mode.
Definition: tc.c:122
void tc_count8_set_count(uint8_t instance, uint8_t value)
Sets the TC's counter value in 8-bit mode.
Definition: tc.c:130
void tc_count32_set_count(uint8_t instance, uint32_t value)
Sets the TC's counter value in 32-bit mode.
Definition: tc.c:138
void tc_count32_set_cc(uint8_t instance, uint8_t channel, uint32_t value)
Sets the TC's compare channel CC0 or CC1 register in 32-bit mode.
Definition: tc.c:126
void tc_count8_set_cc(uint8_t instance, uint8_t channel, uint8_t value)
Sets the TC's compare channel CC0 or CC1 register in 8-bit mode.
Definition: tc.c:118
uint32_t tc_count32_get_count(uint8_t instance)
Gets the TC's current counter value in 32-bit mode.
Definition: tc.c:162
void tc_retrigger(uint8_t instance)
Issues a RETRIGGER command to the TC.
Definition: tc.c:171
void tc_count8_set_period(uint8_t instance, uint8_t period)
Sets the TC's period or PER register in 8-bit mode.
Definition: tc.c:114
void tc_set_counter_mode(uint8_t instance, tc_counter_mode_t mode)
Sets the TC's counting mode (an 8, 16 or 32-bit counter),.
Definition: tc.c:70
void tc_disable(uint8_t instance)
Disables the TC, but retains all its settings.
Definition: tc.c:175
void tc_set_channel_polarity(uint8_t instance, uint8_t channel, tc_channel_polarity_t polarity)
Sets the polarity of one of the waveform output channels.
Definition: tc.c:86
void tc_set_wavegen(uint8_t instance, tc_wavegen_t mode)
Sets the TC's waveform generation mode.
Definition: tc.c:78