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

Avoid fast pins IO on RTOS based boards #136

Merged
merged 2 commits into from
Jan 8, 2025

Conversation

facchinm
Copy link
Contributor

Better fix than arduino/ArduinoCore-zephyr@80943e6

@KurtE

Once we are touching this file, I'd also take a look at why UNO R4 is not in the FAST_IO path (see d5aa1a3#r150329231 )

@KurtE
Copy link
Contributor

KurtE commented Dec 13, 2024

@facchinm - Would be good if it could be in the fast io...

At one point I was going to do so. I do have for example my own digitalWriteFast and the like calls, As do several others up on the forum, which work a lot faster than standard ones.

Would be reasonably easy to setup something within BUSIO... Which either uses the similar table that is I believe marked private or like I did:

static R_PORT0_Type * const port_table[] = { R_PORT0, R_PORT1, R_PORT2, R_PORT3, R_PORT4, R_PORT5, R_PORT6, R_PORT7 };
static const uint16_t mask_table[] = { 1 << 0, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5, 1 << 6, 1 << 7,
                                       1 << 8, 1 << 9, 1 << 10, 1 << 11, 1 << 12, 1 << 13, 1 << 14, 1 << 15 };
// quick and dirty digitalWriteFast
static inline void digitalWriteFast(pin_size_t pin, PinStatus val) {
  uint16_t hardware_port_pin = g_pin_cfg[pin].pin;
  //uint16_t mask = 1 << (hardware_port_pin & 0xf);
  uint16_t pin_mask = mask_table[hardware_port_pin & 0xf];
  R_PORT0_Type * const portX = port_table[hardware_port_pin >> 8];

  if (val) portX->POSR = pin_mask;
  else portX->PORR = pin_mask;
}

Obviously, one could then have the BUSIO code either hold onto the Port or the SET and Clear registers
and the mask... Which is probably similar to what we did for Teensy 4.x which likewise have the Set and Clear
registers... On T3.x we used the BIT band address, which I found out was optional on M4 boards and not on the R4...

I took the easy route to get these boards working on the libraries that used BUSIO as there was pushback on forum about
adding things like this....

But I hope you do!

@ladyada ladyada merged commit 1750617 into adafruit:master Jan 8, 2025
1 check passed
@ladyada
Copy link
Member

ladyada commented Jan 8, 2025

thanks for the fix, apologies for the delay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants