Skip to content

Commit

Permalink
arm/rp2040/common: Change SPI board functions to weak
Browse files Browse the repository at this point in the history
Summary
Board logic change.
This PR adds weak_function attributes to the RP2040 common SPI board logic.
This allows board developers to override and extend the SPI board logic.

Impact
This allows board developers to add custom SPI logic such as adding additional chip select pins.
Adding new SPI devices such as displays or custom SPI devices like external boards is now possible.

External custom boards will have the biggest impact, as these are typically not pushed.

Testing
This has been tested by building the code on linux with raspberrypi-pico:nsh config.
I also tested it on a custom board and it works.
However, my knowledge is not very big about compiler compatibility when weak_function is used.
  • Loading branch information
keever50 committed Feb 24, 2025
1 parent 17a80e9 commit c094891
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions boards/arm/rp2040/common/src/rp2040_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,18 @@
****************************************************************************/

#ifdef CONFIG_RP2040_SPI0
void rp2040_spi0select(struct spi_dev_s *dev, uint32_t devid,
bool selected)
void weak_function rp2040_spi0select(struct spi_dev_s *dev,
uint32_t devid,
bool selected)
{
spiinfo("devid: %d CS: %s\n", (int)devid,
selected ? "assert" : "de-assert");

rp2040_gpio_put(CONFIG_RP2040_SPI0_CS_GPIO, !selected);
}

uint8_t rp2040_spi0status(struct spi_dev_s *dev, uint32_t devid)
uint8_t weak_function rp2040_spi0status(struct spi_dev_s *dev,
uint32_t devid)
{
uint8_t ret = 0;

Expand All @@ -90,7 +92,8 @@ uint8_t rp2040_spi0status(struct spi_dev_s *dev, uint32_t devid)
}

#ifdef CONFIG_SPI_CMDDATA
int rp2040_spi0cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd)
int weak_function rp2040_spi0cmddata(struct spi_dev_s *dev,
uint32_t devid, bool cmd)
{
#ifdef CONFIG_LCD_ST7789
if (devid == SPIDEV_DISPLAY(0))
Expand All @@ -111,16 +114,18 @@ int rp2040_spi0cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd)
#endif

#ifdef CONFIG_RP2040_SPI1
void rp2040_spi1select(struct spi_dev_s *dev, uint32_t devid,
bool selected)
void weak_function rp2040_spi1select(struct spi_dev_s *dev,
uint32_t devid,
bool selected)
{
spiinfo("devid: %d CS: %s\n", (int)devid,
selected ? "assert" : "de-assert");

rp2040_gpio_put(CONFIG_RP2040_SPI1_CS_GPIO, !selected);
}

uint8_t rp2040_spi1status(struct spi_dev_s *dev, uint32_t devid)
uint8_t weak_function rp2040_spi1status(struct spi_dev_s *dev,
uint32_t devid)
{
uint8_t ret = 0;

Expand All @@ -131,7 +136,8 @@ uint8_t rp2040_spi1status(struct spi_dev_s *dev, uint32_t devid)
}

#ifdef CONFIG_SPI_CMDDATA
int rp2040_spi1cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd)
int weak_function rp2040_spi1cmddata(struct spi_dev_s *dev,
uint32_t devid, bool cmd)
{
#if defined (CONFIG_LCD_ST7789) || defined (CONFIG_LCD_ST7735) || defined (CONFIG_LCD_GC9A01)
if (devid == SPIDEV_DISPLAY(0))
Expand Down

0 comments on commit c094891

Please sign in to comment.