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

cpu/rpx0xx: initial PIO support #17425

Merged
merged 12 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions boards/rpi-pico/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ config BOARD_RPI_PICO
default y
select CPU_MODEL_RP2040
select HAS_PERIPH_ADC
select HAS_PERIPH_I2C
select HAS_PERIPH_UART
select HAS_PERIPH_SPI

Expand Down
1 change: 1 addition & 0 deletions boards/rpi-pico/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ CPU := rpx0xx

# Put defined MCU peripherals here (in alphabetical order)
FEATURES_PROVIDED += periph_adc
FEATURES_PROVIDED += periph_i2c
FEATURES_PROVIDED += periph_spi
FEATURES_PROVIDED += periph_timer
FEATURES_PROVIDED += periph_uart
66 changes: 66 additions & 0 deletions boards/rpi-pico/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@
extern "C" {
#endif

/**
* @brief Silences the warning when an unsigned value is compared to 0
*
* This can be deleted when I2C is properly implemented.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still dreaming of a proper low-level I2C driver interface so multiple backends are possible without hacks like this.

I think it can even be done without changing the API and maybe even a fast path if only a single backend is selected.

*/
static inline unsigned _periph_numof_is_unsigned_0(void)
{
return 0;
}

static const uart_conf_t uart_config[] = {
{
.dev = UART0,
Expand Down Expand Up @@ -110,6 +120,62 @@ static const adc_conf_t adc_config[] = {
#define ADC_NUMOF ARRAY_SIZE(adc_config)
/** @} */

/**
* @name I2C configuration
* @{
*/
/**
* @brief Number of I2C interfaces
*/
#define I2C_NUMOF _periph_numof_is_unsigned_0()
/** @} */

/**
* @name PIO configuration
* @{
*/
/**
* @brief Array of PIO configurations
*/
static const pio_conf_t pio_config[] = {
{
.dev = PIO0,
.irqn0 = PIO0_IRQ_0_IRQn,
.irqn1 = PIO0_IRQ_1_IRQn
},
{
.dev = PIO1,
.irqn0 = PIO1_IRQ_0_IRQn,
.irqn1 = PIO1_IRQ_1_IRQn
}
};

#define PIO_0_ISR0 isr_pio00 /**< ISR name of PIO 0 IRQ 0 */
#define PIO_0_ISR1 isr_pio01 /**< ISR name of PIO 0 IRQ 1 */
#define PIO_1_ISR0 isr_pio10 /**< ISR name of PIO 1 IRQ 0 */
#define PIO_1_ISR1 isr_pio11 /**< ISR name of PIO 1 IRQ 1 */

#define PIO_NUMOF ARRAY_SIZE(pio_config) /**< Number of PIOs */

#if defined(PIO_I2C_CONFIG) || defined(DOXYGEN)
/**
* @brief PIO I2C configuration
*
* PIO_I2C_CONFIG should be defined during the build process to fit
* the users pin selection.
*/
static const pio_i2c_conf_t pio_i2c_config[] = {
PIO_I2C_CONFIG
};
/**
* @brief Number of PIO I2C configurations
*/
#define PIO_I2C_NUMOF ARRAY_SIZE(pio_i2c_config)
#else
#define pio_i2c_config ((pio_i2c_conf_t *)NULL)
#endif
/** @} */

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions cpu/rpx0xx/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ config CPU_FAM_RPX0XX
select HAS_CPU_RPX0XX
select HAS_PERIPH_GPIO
select HAS_PERIPH_GPIO_IRQ
select HAS_PERIPH_PIO
select HAS_PERIPH_TIMER
select HAS_PERIPH_TIMER_PERIODIC
select HAS_PERIPH_UART_MODECFG
select HAS_PERIPH_UART_RECONFIGURE
select HAS_PIO_I2C

config CPU_FAM
default "RPX0XX" if CPU_FAM_RPX0XX
Expand Down
4 changes: 4 additions & 0 deletions cpu/rpx0xx/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ MODULE = cpu

DIRS = $(RIOTCPU)/cortexm_common periph

ifneq (,$(filter pio_i2c,$(USEMODULE)))
DIRS += pio/i2c
endif

include $(RIOTBASE)/Makefile.base
9 changes: 9 additions & 0 deletions cpu/rpx0xx/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
ifneq (,$(filter pio_%,$(USEMODULE)))
USEMODULE += periph_pio
endif

ifneq (,$(filter pio_i2c periph_i2c,$(FEATURES_USED)))
DEFAULT_MODULE += pio_autostart_i2c
USEMODULE += pio_i2c
endif

include $(RIOTCPU)/cortexm_common/Makefile.dep
2 changes: 2 additions & 0 deletions cpu/rpx0xx/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ include $(RIOTCPU)/cortexm_common/Makefile.features

FEATURES_PROVIDED += periph_gpio
FEATURES_PROVIDED += periph_gpio_irq
FEATURES_PROVIDED += periph_pio
FEATURES_PROVIDED += periph_timer_periodic
FEATURES_PROVIDED += periph_uart_reconfigure
FEATURES_PROVIDED += periph_uart_modecfg
FEATURES_PROVIDED += pio_i2c
4 changes: 4 additions & 0 deletions cpu/rpx0xx/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ PROGRAMMER ?= elf2uf2
OPENOCD_DEBUG_ADAPTER ?= dap

include $(RIOTMAKE)/arch/cortexm.inc.mk

ifneq (,$(filter periph_pio pio_%,$(USEMODULE)))
include $(RIOTMAKE)/tools/pioasm.inc.mk
endif
20 changes: 20 additions & 0 deletions cpu/rpx0xx/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "vendor/RP2040.h"
#include "io_reg.h"
#include "macros/units.h"
#include "periph/pio.h" /* pio_t */

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -431,6 +432,25 @@ typedef struct {
uint8_t ch_numof; /**< number of timer channels */
} timer_conf_t;

/**
* @brief PIO configuration type
*/
typedef struct {
PIO0_Type *dev; /**< PIO device */
IRQn_Type irqn0; /**< PIO IRQ0 interrupt number */
IRQn_Type irqn1; /**< PIO IRQ1 interrupt number */
} pio_conf_t;

/**
* @brief PIO I2C configuration type
*/
typedef struct {
pio_t pio; /**< PIO number of the PIO to run this configuration */
gpio_t sda; /**< Pin to use as SDA pin */
gpio_t scl; /**< Pin to use as SCL pin */
unsigned irq; /**< PIO IRQ line to use */
} pio_i2c_conf_t;

/**
* @brief Get the PAD control register for the given GPIO pin as word
*
Expand Down
Loading