Skip to content

Commit

Permalink
generic fix for gpio_hold
Browse files Browse the repository at this point in the history
  • Loading branch information
markirb committed Nov 17, 2024
1 parent ab6b3fc commit 76f5dda
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
4 changes: 0 additions & 4 deletions src/ShellyMini1Gen3/shelly_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
#include "shelly_sys_led_btn.hpp"
#include "shelly_temp_sensor_ntc.hpp"

#include "driver/gpio.h"

namespace shelly {

void CreatePeripherals(std::vector<std::unique_ptr<Input>> *inputs,
Expand All @@ -32,8 +30,6 @@ void CreatePeripherals(std::vector<std::unique_ptr<Input>> *inputs,
std::unique_ptr<TempSensor> *sys_temp) {
outputs->emplace_back(new OutputPin(1, 7, 1));

gpio_hold_dis(GPIO_NUM_7);

auto *in = new InputPin(1, 10, 1, MGOS_GPIO_PULL_NONE, true);
in->AddHandler(std::bind(&HandleInputResetSequence, in, LED_GPIO, _1, _2));
in->Init();
Expand Down
4 changes: 1 addition & 3 deletions src/ShellyMini1PMGen3/shelly_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "shelly_sys_led_btn.hpp"
#include "shelly_temp_sensor_ntc.hpp"

#include "driver/gpio.h"


namespace shelly {

Expand All @@ -33,8 +33,6 @@ void CreatePeripherals(std::vector<std::unique_ptr<Input>> *inputs,
std::unique_ptr<TempSensor> *sys_temp) {
outputs->emplace_back(new OutputPin(1, 5, 1));

gpio_hold_dis(GPIO_NUM_5);

auto *in = new InputPin(1, 10, 1, MGOS_GPIO_PULL_NONE, true);
in->AddHandler(std::bind(&HandleInputResetSequence, in, LED_GPIO, _1, _2));
in->Init();
Expand Down
6 changes: 6 additions & 0 deletions src/shelly_input_pin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ void InputPin::Init() {
mgos_gpio_setup_input(cfg_.pin, cfg_.pull);
mgos_gpio_set_button_handler(cfg_.pin, cfg_.pull, MGOS_GPIO_INT_EDGE_ANY, 20,
GPIOIntHandler, this);
#if CS_PLATFORM != CS_P_ESP8266
gpio_hold_dis((gpio_num_t) cfg_.pin);
#endif
bool state = GetState();
LOG(LL_INFO, ("%s %d: pin %d, on_value %d, state %s", "InputPin", id(),
cfg_.pin, cfg_.on_value, OnOff(state)));
Expand All @@ -51,6 +54,9 @@ void InputPin::SetInvert(bool invert) {

InputPin::~InputPin() {
mgos_gpio_remove_int_handler(cfg_.pin, nullptr, nullptr);
#if CS_PLATFORM != CS_P_ESP8266
gpio_hold_en((gpio_num_t) cfg_.pin);
#endif
}

bool InputPin::ReadPin() {
Expand Down
8 changes: 8 additions & 0 deletions src/shelly_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "mgos.hpp"
#include "mgos_gpio.h"

#include "driver/gpio.h"

#ifdef MGOS_HAVE_PWM
#include "mgos_pwm.h"
#endif
Expand All @@ -42,11 +44,17 @@ OutputPin::OutputPin(int id, int pin, int on_value)
on_value_(on_value),
pulse_timer_(std::bind(&OutputPin::PulseTimerCB, this)) {
mgos_gpio_set_mode(pin_, MGOS_GPIO_MODE_OUTPUT);
#if CS_PLATFORM != CS_P_ESP8266
gpio_hold_dis((gpio_num_t) pin);
#endif
LOG(LL_INFO, ("OutputPin %d: pin %d, on_value %d, state %s", id, pin,
on_value, OnOff(GetState())));
}

OutputPin::~OutputPin() {
#if CS_PLATFORM != CS_P_ESP8266
gpio_hold_en((gpio_num_t) pin_);
#endif
}

bool OutputPin::GetState() {
Expand Down

0 comments on commit 76f5dda

Please sign in to comment.