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

Small Fix for latest RP2040 Core Version #613

Closed
savejeff opened this issue Sep 6, 2024 · 2 comments
Closed

Small Fix for latest RP2040 Core Version #613

savejeff opened this issue Sep 6, 2024 · 2 comments

Comments

@savejeff
Copy link

savejeff commented Sep 6, 2024

おはよう!

I have noticed, that the latest version of the RP2040 (Version 4.X) has the latest pico-sdk (Version 2.0.0)
it changes two struct names slightly:

gpio_function -> gpio_function_t
iobank0_hw_t -> io_bank0_hw_t

when these are replaced in src\lgfx\v1\platforms\rp2040\common.cpp it complies fine again
it, unfortunately, breaks code for the older Version 3. (pico-sdk Version 1.X.X)
maybe some can be done with checking defines and doing

#if PICO_SDK_VERSION_MAJOR==1
typedef gpio_function gpio_function_t;
typedef iobank0_hw_t io_bank0_hw_t;
#endif 

in common.hpp for fallback.

and this is the change needed in common.cpp:



    bool lgfx_gpio_set_function(int_fast16_t pin, gpio_function_t fn)
    {
      if (pin < 0 || pin >= static_cast<int_fast16_t>(NUM_BANK0_GPIOS))
      {
        return false;
      }
      if ((((uint32_t)fn << IO_BANK0_GPIO0_CTRL_FUNCSEL_LSB) & ~IO_BANK0_GPIO0_CTRL_FUNCSEL_BITS) != 0)
      {
        return false;
      }
      uint32_t temp = padsbank0_hw->io[pin];
      temp &= ~(PADS_BANK0_GPIO0_IE_BITS | PADS_BANK0_GPIO0_OD_BITS);
      temp |= PADS_BANK0_GPIO0_IE_BITS;
      padsbank0_hw->io[pin] = temp;
      volatile io_bank0_hw_t *iobank0_regs = reinterpret_cast<volatile io_bank0_hw_t *>(IO_BANK0_BASE);
      iobank0_regs->io[pin].ctrl = fn << IO_BANK0_GPIO0_CTRL_FUNCSEL_LSB;
      return true;
    }

I have forked the repo and implemented the fix I you like to compare: https://github.com/savejeff/LovyanGFX

@tobozo
Copy link
Collaborator

tobozo commented Sep 6, 2024

hi, thanks for your feedback 👍

a slightly different fix was applied recently on the develop branch, I guess the effect is the same

https://github.com/lovyan03/LovyanGFX/blob/develop/src/lgfx/v1/platforms/rp2040/common.cpp#L39-L43

@savejeff
Copy link
Author

savejeff commented Sep 6, 2024

cool 👍
I'll use my fork until the changes are merged into the main branch

@savejeff savejeff closed this as completed Sep 6, 2024
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

No branches or pull requests

2 participants