Bidirectional RMT with open-drain

floitsch_toit
Posts: 22
Joined: Wed Jun 29, 2022 4:25 pm

Bidirectional RMT with open-drain

Postby floitsch_toit » Mon Jan 16, 2023 11:14 pm

I'm trying to clean up our code, and am now looking at our code that configures two RMT channels (one input, one output) to work on the same pin, with the output being open-drain.

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.
  1.   // This function has to be called after the pin was first
  2.   // configured as an output channel, and then as an input channel.
  3.   // We now need to reenable the output without losing the input.
  4.  
  5.   // Enable the pin. "w1ts" = "write 1 to set".
  6.   // TODO: not completely sure why this is needed, but without it
  7.   // it won't work.
  8.   if (pin < 32) {
  9.     GPIO.enable_w1ts = (0x1 << pin);
  10.   } else {
  11.     GPIO.enable1_w1ts.data = (0x1 << (pin - 32));
  12.   }
  13.  
  14.   // Reconfigure the out-channel.
  15.   FATAL_IF_NOT_ESP_OK(rmt_set_gpio(out_channel, RMT_MODE_TX, pin, false));
  16.  
  17.   // Make the pin an input again.
  18.   PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[pin]);
  19.  
  20.   // Make the pin open-drain.
  21.   GPIO.pin[pin].pad_driver = 1;
  22.  
  23.   if (enable_pullup) {
  24.     FATAL_IF_NOT_ESP_OK(gpio_pullup_en(static_cast<gpio_num_t>(pin)));
  25.   }

Who is online

Users browsing this forum: Google [Bot] and 108 guests