Infrared4Arduino 1.2.3
Loading...
Searching...
No Matches
Sam.h
Go to the documentation of this file.
1/*
2Copyright (C) 2020 Bengt Martensson.
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation; either version 3 of the License, or (at
7your option) any later version.
8
9This program is distributed in the hope that it will be useful, but
10WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12General Public License for more details.
13
14You should have received a copy of the GNU General Public License along with
15this program. If not, see http://www.gnu.org/licenses/.
16 */
17
18#pragma once
19
20#include "InfraredTypes.h"
21
22#define CURRENT_CLASS Sam
23
24#define HAS_FLASH_READ 1
25#define HAS_HARDWARE_PWM 1
26#define HAS_SAMPLING 1
27#define HAS_INPUT_CAPTURE 0
28
29#define STRCPY_PF_CAST(x) static_cast<const char *>(x)
30
31// Default PWM pin
32#define PWM_PIN 3
33
34#ifdef ISR
35#undef ISR
36#endif
37#define ISR(f) void interruptServiceRoutine()
38
39class Sam : public Board {
40public:
41
42 Sam() {
43 };
44
45private:
46 pin_t pwmPin;
47 static constexpr bool invert = false;
48 uint16_t maxValue;
49 uint16_t onLength;
50 bool timerTCC0;
51 bool timerTCC1;
52 bool timerTCC2;
53 Tcc* TCCx;
54
55 void timerConfigNormal();
56
57 void timerEnableIntr();
58
59 void timerDisableIntr();
60
61 void timerConfigHz(frequency_t hz __attribute__ ((unused)), dutycycle_t dutyCycle __attribute__ ((unused))) {
62 timerConfigHz(PWM_PIN, hz, dutyCycle);
63 };
64
65 void timerConfigHz(pin_t pin, frequency_t hz, dutycycle_t dutyCycle);
66
67 void timerEnablePwm() {
68 setValue(onLength);
69 };
70
71 void timerDisablePwm() {
72 setValue(0U);
73 }
74
75 static const unsigned int TIMER_PRESCALER_DIV = 64U;
76
77 void setTimerFrequency(frequency_t hz);
78
79 void setValue(uint16_t value);
80};
This file defines some general data types that are used in the library.
int8_t dutycycle_t
Type for duty cycle in percent.
Definition: InfraredTypes.h:36
uint32_t frequency_t
Type for modulation frequency in Hz.
Definition: InfraredTypes.h:31
uint8_t pin_t
Type for GPIO pin, compatible with Arduino libs.
Definition: InfraredTypes.h:41
#define PWM_PIN
Definition: Sam.h:32
This class serves as an HAL (Hardware Abstraction Layer).
Definition: Board.h:33
Definition: Sam.h:39
Sam()
Definition: Sam.h:42