Infrared4Arduino 1.2.3
Loading...
Searching...
No Matches
Teensy3x.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
26#pragma once
27
28#define CURRENT_CLASS Teensy3x
29
30// https://www.pjrc.com/teensy/troubleshoot.html says:
31// Teensy LC, 3.0, 3.1 do not have this problem.
32// Variables defined with "const" are placed only in flash memory, but can be accessed normally.
33// Only the older 8 bit AVR-based boards require these special steps to prevent strings
34// and read-only variables from consuming limited RAM.
35#define HAS_FLASH_READ 0
36#define HAS_HARDWARE_PWM 1
37#define HAS_SAMPLING 1
38#define HAS_INPUT_CAPTURE 0
39
40#define TIMER_INTR_NAME cmt_isr
41#ifndef LED_BUILTIN
42#define LED_BUILTIN 13
43#endif
44
45#ifdef ISR
46#undef ISR
47#endif
48#define ISR(f) void f(void)
49
50#if F_BUS < 8000000
51#error IRremote requires at least 8 MHz on Teensy 3.x
52#endif
53
54class Teensy3x : public Board {
55public:
56
58 };
59
60 // not tested yet
61 void reset() {
62 // https://forum.pjrc.com/threads/52512-External-RESET-button-Teensy-3-2?p=180363&viewfull=1#post180363
63 SCB_AIRCR = 0x05FA0004;
64 }
65
66private:
67
68 void timerReset() {
69 uint8_t tmp __attribute__((unused)) = CMT_MSC;
70 CMT_CMD2 = 30U;
71 };
72
73 void timerEnablePwm() {
74 CORE_PIN5_CONFIG = PORT_PCR_MUX(2) | PORT_PCR_DSE | PORT_PCR_SRE;
75 };
76
77 void timerDisablePwm() {
78 CORE_PIN5_CONFIG = PORT_PCR_MUX(1) | PORT_PCR_DSE | PORT_PCR_SRE;
79 };
80
81 void timerEnableIntr() {
82 NVIC_ENABLE_IRQ(IRQ_CMT);
83 };
84
85 void timerDisableIntr() {
86 NVIC_DISABLE_IRQ(IRQ_CMT);
87 };
88
89 static const uint32_t CMT_PPS_DIV = (F_BUS + 7999999U) / 8000000U; // = 5
90
91 void timerConfigHz(frequency_t frequency, dutycycle_t dutyCycle) {
92 SIM_SCGC4 |= SIM_SCGC4_CMT;
93 SIM_SOPT2 |= SIM_SOPT2_PTD7PAD;
94
95 CMT_PPS = CMT_PPS_DIV - 1U;
96 CMT_CGH1 = F_BUS / CMT_PPS_DIV / frequency * dutyCycle / 100U;
97 CMT_CGL1 = F_BUS / CMT_PPS_DIV / frequency * (100 - dutyCycle) / 100U;
98 CMT_CMD1 = 0U;
99 CMT_CMD2 = 30U;
100 CMT_CMD3 = 0U;
101 CMT_CMD4 = 0U;
102 CMT_OC = 0x60U;
103 CMT_MSC = 0x01U;
104 };
105
106 void timerConfigNormal() {
107 SIM_SCGC4 |= SIM_SCGC4_CMT;
108 CMT_PPS = CMT_PPS_DIV - 1U;
109 CMT_CGH1 = 1U;
110 CMT_CGL1 = 1U;
111 CMT_CMD1 = 0U;
112 CMT_CMD2 = 30U;
113 CMT_CMD3 = 0U;
114 CMT_CMD4 = (F_BUS / 160000U + CMT_PPS_DIV / 2U) / CMT_PPS_DIV - 31U;
115 CMT_OC = 0U;
116 CMT_MSC = 0x03U;
117 };
118
119#define PWM_PIN 5
120};
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
This class serves as an HAL (Hardware Abstraction Layer).
Definition: Board.h:33
void reset()
Definition: Teensy3x.h:61
Teensy3x()
Definition: Teensy3x.h:57