Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions esp32-cam-webserver.ino
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <dummy.h>

#include "src/app_config.h" // global definitions
#include "src/storage.h" // Filesystem
Expand All @@ -6,6 +7,10 @@
#include "src/app_httpd.h" // Web server
#include "src/camera_pins.h" // Pin Mappings

#include "esp_task_wdt.h"
#include "soc/periph_defs.h"
#include "esp_private/periph_ctrl.h"
#include "freertos/timers.h"
/*
* This sketch is a extension/expansion/rework of the ESP32 Camera webserer example.
*
Expand Down Expand Up @@ -177,7 +182,11 @@ void flashLED(int flashtime) {
}

void scheduleReboot(int delay) {
esp_task_wdt_init(delay,true);
esp_task_wdt_config_t wdt_config = {
.timeout_ms = delay, // Timeout in milliseconds
.trigger_panic = true, // Trigger a panic when the timeout is reached
};
esp_task_wdt_init(&wdt_config); // schedule a a watchdog panic event for 3 seconds in the future
esp_task_wdt_add(NULL);
}

Expand All @@ -188,4 +197,3 @@ void resetI2CBus() {
periph_module_reset(PERIPH_I2C0_MODULE);
periph_module_reset(PERIPH_I2C1_MODULE);
}

6 changes: 3 additions & 3 deletions src/app_cam.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#define CAM_DUMP_BUFFER_SIZE 1024

#include <esp_camera.h>
#include <esp_int_wdt.h>
#include <esp_task_wdt.h>
#include <esp_private/esp_int_wdt.h>
#include <esp_private/esp_task_wdt.h>

#include "app_component.h"
#include "camera_pins.h"
Expand Down Expand Up @@ -85,4 +85,4 @@ class CLAppCam : public CLAppComponent {

extern CLAppCam AppCam;

#endif
#endif
12 changes: 11 additions & 1 deletion src/app_httpd.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#include "freertos/FreeRTOS.h"
#include "app_httpd.h"

#include "soc/periph_defs.h"
#include "soc/periph_defs.h"
#include "esp_private/periph_ctrl.h"
#include "esp_private/esp_int_wdt.h"
#include "esp_task_wdt.h"
CLAppHttpd::CLAppHttpd() {
// Gather static values used when dumping status; these are slow functions, so just do them once during startup
sketchSize = ESP.getSketchSize();;
Expand Down Expand Up @@ -373,7 +379,11 @@ void onControl(AsyncWebServerRequest *request) {
request->send(200);
if (AppHttpd.getLamp() != -1) AppHttpd.setLamp(0); // kill the lamp; otherwise it can remain on during the soft-reboot
Storage.getFS().end(); // close file storage
esp_task_wdt_init(3,true); // schedule a a watchdog panic event for 3 seconds in the future
esp_task_wdt_config_t wdt_config = {
.timeout_ms = 3000, // Timeout in milliseconds
.trigger_panic = true, // Trigger a panic when the timeout is reached
};
esp_task_wdt_init(&wdt_config); // schedule a a watchdog panic event for 3 seconds in the future
esp_task_wdt_add(NULL);
periph_module_disable(PERIPH_I2C0_MODULE); // try to shut I2C down properly
periph_module_disable(PERIPH_I2C1_MODULE);
Expand Down
6 changes: 3 additions & 3 deletions src/app_httpd.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef app_httpd_h
#define app_httpd_h

#include <esp_int_wdt.h>
#include <esp_task_wdt.h>
#include <esp_private/esp_int_wdt.h>
#include <esp_private/esp_task_wdt.h>
#include <freertos/timers.h>

#include "esp32pwm.h"
Expand Down Expand Up @@ -198,4 +198,4 @@ class CLAppHttpd : public CLAppComponent {

extern CLAppHttpd AppHttpd;

#endif
#endif
23 changes: 11 additions & 12 deletions src/esp32pwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ ESP32PWM::ESP32PWM() {

ESP32PWM::~ESP32PWM() {
if (attached()) {
ledcDetachPin(pin);
ledcDetach(pin);
}
deallocate();
}

double ESP32PWM::_ledcSetupTimerFreq(uint8_t chan, double freq, uint8_t bit_num) {
return ledcSetup(chan, freq, bit_num);
return ledcAttach(chan, freq, bit_num);
}

int ESP32PWM::timerAndIndexToChannel(int timerNum, int index) {
Expand Down Expand Up @@ -142,12 +142,11 @@ double ESP32PWM::setup(double freq, uint8_t resolution_bits) {

resolutionBits = resolution_bits;
if (attached()) {
ledcDetachPin(pin);
double val = ledcSetup(getChannel(), freq, resolution_bits);
attachPin(pin);
ledcDetach(pin);
double val = ledcAttach(pin, freq, resolution_bits);
return val;
}
return ledcSetup(getChannel(), freq, resolution_bits);
return ledcAttach(pin, freq, resolution_bits);
}
double ESP32PWM::getDutyScaled() {
return mapf((double) myDuty, 0, (double) ((1 << resolutionBits) - 1), 0.0,
Expand All @@ -171,13 +170,13 @@ void ESP32PWM::adjustFrequencyLocal(double freq, double dutyScaled) {
timerFreqSet[getTimer()] = (long) freq;
myFreq = freq;
if (attached()) {
ledcDetachPin(pin);
ledcDetach(pin);
// Remove the PWM during frequency adjust
_ledcSetupTimerFreq(getChannel(), freq, resolutionBits);
ledcAttach(getChannel(), freq, resolutionBits);
writeScaled(dutyScaled);
ledcAttachPin(pin, getChannel()); // re-attach the pin after frequency adjust
//ledcAttach(pin, getChannel()); // re-attach the pin after frequency adjust
} else {
_ledcSetupTimerFreq(getChannel(), freq, resolutionBits);
ledcAttach(getChannel(), freq, resolutionBits);
writeScaled(dutyScaled);
}
}
Expand Down Expand Up @@ -209,7 +208,7 @@ void ESP32PWM::attachPin(uint8_t pin) {

if (hasPwm(pin)) {
attach(pin);
ledcAttachPin(pin, getChannel());
//ledcAttach(pin, getChannel());
} else {
Serial.println(
"ERROR PWM channel unavailable on pin requested! " + String(pin)
Expand All @@ -230,7 +229,7 @@ void ESP32PWM::attachPin(uint8_t pin, double freq, uint8_t resolution_bits) {
attachPin(pin);
}
void ESP32PWM::detachPin(int pin) {
ledcDetachPin(pin);
ledcDetach(pin);
deallocate();
}
/* Side effects of frequency changes happen because of shared timers
Expand Down