arm/rp2040: Add rp2040_gpio_init/put/get/setdir()

This commit is contained in:
Yuichi Nakamura 2021-03-05 23:11:38 +09:00 committed by Masayuki Ishikawa
parent 40217e644f
commit a8d269df98
2 changed files with 63 additions and 5 deletions

View File

@ -35,13 +35,8 @@
#include "arm_arch.h"
#include "chip.h"
#include "rp2040_gpio.h"
#include "hardware/rp2040_pads_bank0.h"
#include "hardware/rp2040_io_bank0.h"
#include "hardware/rp2040_sio.h"
/****************************************************************************
* Private Functions
****************************************************************************/
@ -67,3 +62,10 @@ void rp2040_gpio_set_pulls(uint32_t gpio, int up, int down)
RP2040_PADS_BANK0_GPIO_PUE | RP2040_PADS_BANK0_GPIO_PDE,
RP2040_PADS_BANK0_GPIO(gpio));
}
void rp2040_gpio_init(uint32_t gpio)
{
rp2040_gpio_setdir(gpio, false);
rp2040_gpio_put(gpio, false);
rp2040_gpio_set_function(gpio, RP2040_GPIO_FUNC_SIO);
}

View File

@ -27,10 +27,26 @@
#include <nuttx/config.h>
#include "hardware/rp2040_sio.h"
#include "hardware/rp2040_io_bank0.h"
#include "hardware/rp2040_pads_bank0.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define RP2040_GPIO_FUNC_JTAG RP2040_IO_BANK0_GPIO_CTRL_FUNCSEL_JTAG
#define RP2040_GPIO_FUNC_SPI RP2040_IO_BANK0_GPIO_CTRL_FUNCSEL_SPI
#define RP2040_GPIO_FUNC_UART RP2040_IO_BANK0_GPIO_CTRL_FUNCSEL_UART
#define RP2040_GPIO_FUNC_I2C RP2040_IO_BANK0_GPIO_CTRL_FUNCSEL_I2C
#define RP2040_GPIO_FUNC_PWM RP2040_IO_BANK0_GPIO_CTRL_FUNCSEL_PWM
#define RP2040_GPIO_FUNC_SIO RP2040_IO_BANK0_GPIO_CTRL_FUNCSEL_SIO
#define RP2040_GPIO_FUNC_PIO0 RP2040_IO_BANK0_GPIO_CTRL_FUNCSEL_PIO0
#define RP2040_GPIO_FUNC_PIO1 RP2040_IO_BANK0_GPIO_CTRL_FUNCSEL_PIO1
#define RP2040_GPIO_FUNC_CLOCKS RP2040_IO_BANK0_GPIO_CTRL_FUNCSEL_CLOCKS
#define RP2040_GPIO_FUNC_USB RP2040_IO_BANK0_GPIO_CTRL_FUNCSEL_USB
#define RP2040_GPIO_FUNC_NULL RP2040_IO_BANK0_GPIO_CTRL_FUNCSEL_NULL
/****************************************************************************
* Public Types
****************************************************************************/
@ -50,12 +66,52 @@ extern "C"
#define EXTERN extern
#endif
/****************************************************************************
* Inline Functions
****************************************************************************/
static inline void rp2040_gpio_put(uint32_t gpio, int set)
{
uint32_t value = 1 << gpio;
if (set)
{
putreg32(value, RP2040_SIO_GPIO_OUT_SET);
}
else
{
putreg32(value, RP2040_SIO_GPIO_OUT_CLR);
}
}
static inline bool rp2040_gpio_get(uint32_t gpio)
{
uint32_t value = 1 << gpio;
return (getreg32(RP2040_SIO_GPIO_IN) & value) != 0;
}
static inline void rp2040_gpio_setdir(uint32_t gpio, int out)
{
uint32_t value = 1 << gpio;
if (out)
{
putreg32(value, RP2040_SIO_GPIO_OE_SET);
}
else
{
putreg32(value, RP2040_SIO_GPIO_OE_CLR);
}
}
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
void rp2040_gpio_set_function(uint32_t gpio, uint32_t func);
void rp2040_gpio_set_pulls(uint32_t gpio, int up, int down);
void rp2040_gpio_init(uint32_t gpio);
#undef EXTERN
#if defined(__cplusplus)