Infrared4Arduino 1.2.3
Loading...
Searching...
No Matches
Esp32.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
27#pragma once
28
29#define CURRENT_CLASS Esp32
30
31#define HAS_FLASH_READ 0
32#define HAS_HARDWARE_PWM 1
33#define HAS_SAMPLING 1
34#define HAS_INPUT_CAPTURE 0
35
36#define STRCPY_PF_CAST(x) (x)
37
38#ifndef LED_BUILTIN
39#define LED_BUILTIN 2
40#endif
41
42#define LEDCHANNEL 0
43#define TIMER_SIZE 8
44
45#ifdef ISR
46#undef ISR
47#endif
48#define ISR(f) void ICACHE_RAM_ATTR IRTimer()
49
50void IRTimer(); // defined in IrReceiverSampler.cpp, masqueraded as ISR(TIMER_INTR_NAME)
51
52#define PWM_PIN 5
53
54class Esp32 : public Board {
55public:
56
58 };
59
60private:
61
62 static hw_timer_t* timer;
63 uint8_t onValue;
64
65 void timerEnableIntr() {
66 // Interrupt Service Routine - Fires every 50uS
67 // ESP32 has a proper API to setup timers, no weird chip macros needed
68 // simply call the readable API versions :)
69 // 3 timers, choose #1, 80 divider nanosecond precision, 1 to count up
70 Esp32::timer = timerBegin(1, 80, 1);
71 timerAttachInterrupt(Esp32::timer, IRTimer, true);
72 // every 50 microseconds, autoreload = true
73 timerAlarmWrite(Esp32::timer, microsPerTick, true);
74 timerAlarmEnable(Esp32::timer);
75 };
76
77 void timerDisableIntr() {
78 if (Esp32::timer != nullptr) {
79 timerEnd(Esp32::timer);
80 timerDetachInterrupt(Esp32::timer);
81 }
82 };
83
84 void timerEnablePwm() {
85 ledcWrite(LEDCHANNEL, onValue);
86 };
87
88 void timerDisablePwm() {
89 ledcWrite(LEDCHANNEL, 0);
90 };
91
92 void timerConfigHz(frequency_t frequency, dutycycle_t dutyCycle) {
93 onValue = static_cast<uint8_t>(256U * dutyCycle / 100U);
94 ledcSetup(LEDCHANNEL, frequency, TIMER_SIZE);
95 ledcAttachPin(PWM_PIN, LEDCHANNEL);
96 };
97
98 void timerConfigNormal() {
99 }
100};
void IRTimer()
#define LEDCHANNEL
Definition: Esp32.h:42
#define TIMER_SIZE
Definition: Esp32.h:43
#define PWM_PIN
Definition: Esp32.h:52
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
static const unsigned long microsPerTick
Definition: Board.h:57
Definition: Esp32.h:54
Esp32()
Definition: Esp32.h:57