Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

portmoderegister problems #2369

Closed
tablatronix opened this issue Aug 6, 2016 · 8 comments
Closed

portmoderegister problems #2369

tablatronix opened this issue Aug 6, 2016 · 8 comments
Assignees
Labels
waiting for feedback Waiting on additional info. If it's not received, the issue may be closed.

Comments

@tablatronix
Copy link
Contributor

This is a dup but the other title is not relevant to actual issue
#1914

I have a problem setting gpio mode using
portModeRegister

@tablatronix
Copy link
Contributor Author

tablatronix commented Jan 30, 2017

port    = digitalPinToPort(PIN);    // get the pin's port
bitmask = digitalPinToBitMask(PIN); // pin bitmask
ddr     = portModeRegister(port);   // get the ddr 
*ddr |= bitmask;  // does not work

Not sure how this is supposed to toggle the correct bits when &GPE and pinmask do not align for pins above pin 3, or at least that is what it seems to me,

Maybe someone with better understanding of the registers can look at this.

demo sketch in above linked issue above pin 3 shows the issue.

@devyte
Copy link
Collaborator

devyte commented Oct 14, 2017

@tablatronix I'm not sure what can be done here, if the register bits don't align. What is your expectation?

@devyte devyte added the waiting for feedback Waiting on additional info. If it's not received, the issue may be closed. label Oct 14, 2017
@igrr
Copy link
Member

igrr commented Oct 14, 2017

Sorry, what do you mean by "GPE and pinmask do not align?" What is "pinmask"?

@tablatronix
Copy link
Contributor Author

tablatronix commented Oct 14, 2017

I think I meant GPC(p) or bitmask ( I had some tests for this, but who knows where i put them )
I noticed pinmode uses alot of voodoo, like gpiomode and GPC for setting pinmode

EIther way I had problems with the avr compat mapping, and using the above code and simple
GPE - bitmask masking alignment

Was found using code similar to the linked issue above

some notes

peri

#define GPC(p) ESP8266_REG(0x328 + ((p & 0xF) * 4))

_pinmode

      GPF(pin) = GPFFS(GPFFS_GPIO(pin));//Set mode to GPIO
      GPC(pin) = (GPC(pin) & (0xF << GPCI)); //SOURCE(GPIO) | DRIVER(NORMAL) | INT_TYPE(UNCHANGED) | WAKEUP_ENABLE(DISABLED)
      if(mode == OUTPUT_OPEN_DRAIN) GPC(pin) |= (1 << GPCD);
      GPES = (1 << pin); //Enable
    } else if(mode == INPUT || mode == INPUT_PULLUP){
      GPF(pin) = GPFFS(GPFFS_GPIO(pin));//Set mode to GPIO
      GPEC = (1 << pin); //Disable
      GPC(pin) = (GPC(pin) & (0xF << GPCI)) | (1 << GPCD); //SOURCE(GPIO) | DRIVER(OPEN_DRAIN) | INT_TYPE(UNCHANGED) | WAKEUP_ENABLE(DISABLED)
      if(mode == INPUT_PULLUP) {
          GPF(pin) |= (1 << GPFPU);  // Enable  Pullup
      }
#define digitalPinToBitMask(pin)    (1UL << (pin))
#define GPE    ESP8266_REG(0x30C) //GPIO_ENABLE R/W (Enable)
#define portModeRegister(port)      ((volatile uint32_t*) &GPE)

( again i have no idea how registers work)

@devyte devyte self-assigned this Nov 14, 2018
@earlephilhower
Copy link
Collaborator

earlephilhower commented Jan 16, 2019

The problem is that the macro used is defined on AVR to map to a specific HW register with specific bit configs. The 8266 GPIO hardware is not compatible in any way, shape, or form with the AVR, so you will need to use the appropriate high-level pinMode() calls.

@dagnall53
Copy link

@earlephilhower
Sorry to ask in a closed issue: (only just found this)
I am trying to track down some very strange behavior with PWM that I suspect is due to unexpected pinMode changes after EEPROM commit, so was wanting to see EXACTLY what each pin is set to.
I can see that the bitmask produces an apparently sensible bit mask but is there ANY way to access the ESP low level port direction registers (or equivalent).

Many thanks.. I will keep trying alternate bug finding techniques, but directly looking at the actual registers would simplify the process!.

@earlephilhower
Copy link
Collaborator

Sure, @dagnall53. Look at core/esp8266/core_esp8266_wiring.c. It's much more complicated than a simple bitmask like in AVR due to IO muxes/etc.

@dagnall53
Copy link

I think you mean 'core_esp8266_wiring_digital.c',but yes, WOW. that is truly convoluted!.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for feedback Waiting on additional info. If it's not received, the issue may be closed.
Projects
None yet
Development

No branches or pull requests

5 participants