lovyan03 / LovyanGFX

SPI LCD graphics library for ESP32 (ESP-IDF/ArduinoESP32) / ESP8266 (ArduinoESP8266) / SAMD51(Seeed ArduinoSAMD51)
Other
1.19k stars 209 forks source link

Small Fix for latest RP2040 Core Version #613

Closed savejeff closed 2 months ago

savejeff commented 2 months ago

おはよう!

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 commented 2 months ago

hi, thanks for your feedback :+1:

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 commented 2 months ago

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