Skip to content

Commit

Permalink
compat witch stock: use gpio_hold on in/out pins
Browse files Browse the repository at this point in the history
fixup for gpio_hold
  • Loading branch information
markirb authored and root committed Nov 30, 2024
1 parent db28dcb commit a81bab9
Show file tree
Hide file tree
Showing 4 changed files with 22 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 @@ -22,7 +22,7 @@
#include "shelly_sys_led_btn.hpp"
#include "shelly_temp_sensor_ntc.hpp"

#include "driver/gpio.h"


namespace shelly {

Expand All @@ -32,8 +32,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
10 changes: 10 additions & 0 deletions src/shelly_input_pin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

#include "mgos.hpp"

#if CS_PLATFORM != CS_P_ESP8266
#include "driver/gpio.h"
#endif

namespace shelly {

InputPin::InputPin(int id, int pin, int on_value, enum mgos_gpio_pull_type pull,
Expand All @@ -39,6 +43,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 +58,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
11 changes: 11 additions & 0 deletions src/shelly_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
#include "mgos.hpp"
#include "mgos_gpio.h"

#if CS_PLATFORM != CS_P_ESP8266
#include "driver/gpio.h"
#endif


#ifdef MGOS_HAVE_PWM
#include "mgos_pwm.h"
#endif
Expand All @@ -42,11 +47,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 a81bab9

Please sign in to comment.