I think I understand most of it, but I don't understand why we need to set the 'enable' bit (enable_w1ts). I would appreciate any help, or other feedback on the code.
Context: the variable pin has been used as pin for an RMT channel. First in output mode, and then in input mode.
- // This function has to be called after the pin was first
- // configured as an output channel, and then as an input channel.
- // We now need to reenable the output without losing the input.
- // Enable the pin. "w1ts" = "write 1 to set".
- // TODO: not completely sure why this is needed, but without it
- // it won't work.
- if (pin < 32) {
- GPIO.enable_w1ts = (0x1 << pin);
- } else {
- GPIO.enable1_w1ts.data = (0x1 << (pin - 32));
- }
- // Reconfigure the out-channel.
- FATAL_IF_NOT_ESP_OK(rmt_set_gpio(out_channel, RMT_MODE_TX, pin, false));
- // Make the pin an input again.
- PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[pin]);
- // Make the pin open-drain.
- GPIO.pin[pin].pad_driver = 1;
- if (enable_pullup) {
- FATAL_IF_NOT_ESP_OK(gpio_pullup_en(static_cast<gpio_num_t>(pin)));
- }