8#if defined(USE_BK72XX) || (defined(USE_RTL87XX) && !defined(CLANG_TIDY))
9#include <wiring_data.h>
26 return INPUT_PULLDOWN;
28 return OUTPUT_OPEN_DRAIN;
40#if defined(USE_LIBRETINY_VARIANT_RTL8710B) && !defined(CLANG_TIDY)
44static void IRAM_ATTR rtl8710b_arm_next_edge(gpio_irq_t *irq) {
45 uint32_t level = GPIO_ReadDataBit(irq->pin);
46 for (
int i = 0; i < 4; i++) {
48 GPIO_INTMode(irq->pin, ENABLE, GPIO_INT_Trigger_EDGE,
49 level ? GPIO_INT_POLARITY_ACTIVE_LOW : GPIO_INT_POLARITY_ACTIVE_HIGH, GPIO_INT_DEBOUNCE_ENABLE);
50 const uint32_t now = GPIO_ReadDataBit(irq->pin);
57static void IRAM_ATTR rtl8710b_change_handler(
uint32_t id, gpio_irq_event event) {
58 auto *data =
reinterpret_cast<PinData *
>(
id);
60 if (data->irqMode == CHANGE)
61 rtl8710b_arm_next_edge(data->irq);
62 if (data->irqHandler !=
nullptr)
63 reinterpret_cast<void (*)(
void *)
>(data->irqHandler)(data->irqParam);
68 PinStatus arduino_mode = (PinStatus) 255;
71 arduino_mode =
inverted_ ? FALLING : RISING;
74 arduino_mode =
inverted_ ? RISING : FALLING;
77 arduino_mode = CHANGE;
87 attachInterruptParam(
pin_, func, arduino_mode, arg);
88#if defined(USE_LIBRETINY_VARIANT_RTL8710B) && !defined(CLANG_TIDY)
89 if (arduino_mode == CHANGE) {
90 PinInfo *info = pinInfo(this->
pin_);
91 PinData *data = info !=
nullptr ? info->data :
nullptr;
92 if (data !=
nullptr && data->irq !=
nullptr) {
94 const uint32_t primask = __get_PRIMASK();
96 GPIO_UserRegIrq(data->irq->pin,
reinterpret_cast<void *
>(rtl8710b_change_handler), data);
97 rtl8710b_arm_next_edge(data->irq);
98 __set_PRIMASK(primask);
106static constexpr uintptr_t BK_GPIO_CFG_BASE = 0x00802800;
107static constexpr uint32_t BK_GPIO_OUTPUT_BIT = 1 << 1;
111static bool bk_enter_output(uint8_t pin,
bool level) {
112 PinInfo *info = pinInfo(pin);
113 if (info ==
nullptr || info->gpio > 31)
115 PinData *data = pinData(info);
116 if (pinEnabled(info, PIN_GPIO) && data->gpioMode == OUTPUT)
118 pinRemoveMode(info, PIN_PWM);
120 reinterpret_cast<volatile uint32_t *
>(BK_GPIO_CFG_BASE + info->gpio * 4);
121 *cfg = level ? BK_GPIO_OUTPUT_BIT : 0;
122 pinEnable(info, PIN_GPIO);
123 data->gpioMode = OUTPUT;
128#if defined(USE_RTL87XX) && !defined(CLANG_TIDY)
130static void rtl_preset_level(uint8_t pin,
bool level) {
131 PinInfo *info = pinInfo(pin);
134 if (info->data ==
nullptr || info->data->gpio ==
nullptr)
136 if (info->data !=
nullptr && info->data->gpio !=
nullptr)
137 gpio_write(info->data->gpio, level);
148#if defined(USE_RTL87XX) && !defined(CLANG_TIDY)
154 pinMode(this->
pin_, mode);
164#if defined(USE_LIBRETINY_VARIANT_RTL8720C) && !defined(CLANG_TIDY)
167 PinInfo *info = pinInfo(this->
pin_);
168 if (info !=
nullptr && (info->enabled & PIN_IRQ))
169 return bool(gpio_irq_read(info->data->irq)) ^ this->
inverted_;
179 detachInterrupt(
pin_);
186using namespace libretiny;
195 detachInterrupt(
reinterpret_cast<ArduinoInternalGPIOPin *
>(this->
arg_)->get_pin());
198 reinterpret_cast<ArduinoInternalGPIOPin *
>(this->
arg_)->
pin_mode(flags);
BedjetMode mode
BedJet operating mode.
Copy of GPIOPin that is safe to use from ISRs (with no virtual functions)
void digital_write(bool value)
void pin_mode(gpio::Flags flags)
void pin_mode(gpio::Flags flags) override
void attach_interrupt_(void(*func)(void *), void *arg, gpio::InterruptType type) const
size_t dump_summary(char *buffer, size_t len) const override
bool digital_read() override
void detach_interrupt() const
ISRInternalGPIOPin to_isr() const
void digital_write(bool value) override
ESPHOME_LOG_TAG(TAG, "libretiny.crash")