ARMEBS4  revision-607
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Modules | Data Structures | Macros | Enumerations | Functions
GPIO (General Purpose I/O)
Collaboration diagram for GPIO (General Purpose I/O):

Modules

 GPIO Interrupts
 

Data Structures

struct  gpio_t
 GPIO control structure. More...
 

Macros

#define GPIO_NC
 Unconnected pin.
 
#define DEF_GPIOA(__PIN, __MODE)
 Helper for defining a pin. More...
 
#define DEF_GPIOB(__PIN, __MODE)
 same as DEF_GPIOA for port B
 
#define DEF_GPIOC(__PIN, __MODE)
 same as DEF_GPIOA for port C
 
#define DEF_GPIOD(__PIN, __MODE)
 same as DEF_GPIOA for port D
 
#define DEF_GPIOE(__PIN, __MODE)
 same as DEF_GPIOA for port E
 
#define DEF_GPIOF(__PIN, __MODE)
 same as DEF_GPIOA for port F
 
#define DEF_GPIOG(__PIN, __MODE)
 same as DEF_GPIOA for port G
 
#define DEF_GPIOH(__PIN, __MODE)
 same as DEF_GPIOA for port H
 
#define DEF_GPIOI(__PIN, __MODE)
 same as DEF_GPIOA for port I
 

Enumerations

enum  gpio_mode_e {
  GPIO_INPUT,
  GPIO_OUTPUT,
  GPIO_OUTPUT_0,
  GPIO_OUTPUT_1,
  GPIO_AF,
  GPIO_AN,
  GPIO_PP,
  GPIO_OD,
  GPIO_SPEED_2,
  GPIO_SPEED_25,
  GPIO_SPEED_50,
  GPIO_SPEED_100,
  GPIO_NOPULL,
  GPIO_PULLUP,
  GPIO_PULLDOWN
}
 GPIO modes, can be ORed. More...
 

Functions

status_e gpio_setup (const struct gpio_t *gpio)
 Setup a gpio. More...
 
status_e gpio_setup_list (const struct gpio_t gpio[], size_t len)
 Setup an array of gpio. More...
 
static GPIO_TypeDef_internal_gpio_get_ctrl (const struct gpio_t *gpio)
 Get the gpio controller given the gpio struct.
 
static void gpio_toggle (const struct gpio_t *gpio)
 Toggle a gpio line. More...
 
static uint32_t gpio_get (const struct gpio_t *gpio)
 Get gpio level. More...
 
static uint32_t gpio_get_internal (const struct gpio_t *gpio)
 Get gpio internal level. More...
 
static void gpio_set (const struct gpio_t *gpio, uint32_t value)
 Set a gpio. More...
 
static void gpio_set_direction (const struct gpio_t *gpio, enum gpio_mode_e dir)
 Set a gpio direction. More...
 

Detailed Description

Macro Definition Documentation

#define DEF_GPIOA (   __PIN,
  __MODE 
)

Helper for defining a pin.

Parameters
__PINthe pin number (0 for GPIOx0, ..., 3 for GPIOx3, ...)
__MODEgpio_mode_e of the pin

Example for one pin:

const gpio_t test_pin = DEF_GPIOA(3, GPIO_INPUT | GPIO_PULLUP);

Example for multiple pins:

Definition at line 358 of file stm32_gpio.h.

Enumeration Type Documentation

GPIO modes, can be ORed.

Enumerator
GPIO_INPUT 

Input.

GPIO_OUTPUT 

Output (same as GPIO_OUTPUT_0)

GPIO_OUTPUT_0 

Output (default 0)

GPIO_OUTPUT_1 

Output (default 1)

GPIO_AF 

Alternate function.

GPIO_AN 

Analog.

GPIO_PP 

Output type : Push-Pull.

GPIO_OD 

Output type : Open Drain.

GPIO_SPEED_2 

Output speed : 2 MHz.

GPIO_SPEED_25 

Output speed : 25 MHz.

GPIO_SPEED_50 

Output speed : 50 MHz.

GPIO_SPEED_100 

Output speed : 100 MHz.

GPIO_NOPULL 

No pull up or down.

GPIO_PULLUP 

Pull up.

GPIO_PULLDOWN 

pull down

Definition at line 41 of file stm32_gpio.h.

Function Documentation

status_e gpio_setup ( const struct gpio_t gpio)

Setup a gpio.

Parameters
gpioPointer on the gpio
Returns
NO_ERROR for no problem

Example configuring GPIOA3 as input with pullup:

void do_something(void)
{
const gpio_t test_pin = DEF_GPIOA(3, GPIO_INPUT | GPIO_PULLUP);
gpio_setup(&test_pin);
}

Definition at line 9 of file stm32_gpio.c.

References _internal_gpio_get_ctrl(), GPIO_TypeDef::AFR, gpio_t::ctrl, gpio_set(), gpio_t::mode, GPIO_TypeDef::MODER, NO_ERROR, gpio_t::nr, GPIO_TypeDef::OSPEEDR, GPIO_TypeDef::OTYPER, and GPIO_TypeDef::PUPDR.

Referenced by bsp_init(), camera_init(), gpio_irq_setup(), gpio_setup_list(), and workaround_reset_i2c_devices().

Here is the call graph for this function:

Here is the caller graph for this function:

status_e gpio_setup_list ( const struct gpio_t  gpio[],
size_t  len 
)

Setup an array of gpio.

Parameters
gpioPointer on the first gpio
lenThe number of gpios
Returns
NO_ERROR for no problem
void do_something(void)
{
const gpio_t test_pins[] =
{
};
gpio_setup_list(test_pins, ARRAY_SIZE(test_pins));
}

Definition at line 47 of file stm32_gpio.c.

References gpio_setup(), and NO_ERROR.

Referenced by Audio_Init(), bsp_init(), and camera_init().

Here is the call graph for this function:

Here is the caller graph for this function:

static void gpio_toggle ( const struct gpio_t gpio)
inlinestatic

Toggle a gpio line.

Parameters
gpiowhich gpio

Definition at line 185 of file stm32_gpio.h.

References _internal_gpio_get_ctrl(), GPIO_TypeDef::BSRRL, gpio_t::ctrl, gpio_t::mask, and GPIO_TypeDef::ODR.

Here is the call graph for this function:

static uint32_t gpio_get ( const struct gpio_t gpio)
inlinestatic

Get gpio level.

Parameters
gpiowhich gpio
Returns
0 for logical level 0, gpio->mask for logical level 1

The value returned is the value of the pin, outside of the chip

See Also
gpio_get_internal

Definition at line 219 of file stm32_gpio.h.

References _internal_gpio_get_ctrl(), gpio_t::ctrl, GPIO_TypeDef::IDR, and gpio_t::mask.

Referenced by bsp_button_get(), gpio_irq_restore(), and gpio_irq_setup().

Here is the call graph for this function:

Here is the caller graph for this function:

static uint32_t gpio_get_internal ( const struct gpio_t gpio)
inlinestatic

Get gpio internal level.

Parameters
gpiowhich gpio
Returns
0 for logical level 0, gpio->mask for logical level 1

The value returned is the value of the output register, not the value of the pin.

See Also
gpio_get

Definition at line 242 of file stm32_gpio.h.

References _internal_gpio_get_ctrl(), gpio_t::ctrl, gpio_t::mask, and GPIO_TypeDef::ODR.

Here is the call graph for this function:

static void gpio_set ( const struct gpio_t gpio,
uint32_t  value 
)
inlinestatic

Set a gpio.

Parameters
gpiothe gpio to set
value0 for output logical 0, anything else for logical level 1

Definition at line 260 of file stm32_gpio.h.

References _internal_gpio_get_ctrl(), GPIO_TypeDef::BSRRH, GPIO_TypeDef::BSRRL, gpio_t::ctrl, and gpio_t::mask.

Referenced by gpio_set_direction(), gpio_setup(), and workaround_reset_i2c_devices().

Here is the call graph for this function:

Here is the caller graph for this function:

static void gpio_set_direction ( const struct gpio_t gpio,
enum gpio_mode_e  dir 
)
inlinestatic

Set a gpio direction.

Parameters
gpiothe gpio to set
dirGPIO_INPUT, GPIO_OUTPUT_0 or GPIO_OUTPUT_1

Definition at line 286 of file stm32_gpio.h.

References _internal_gpio_get_ctrl(), gpio_t::ctrl, gpio_set(), GPIO_TypeDef::MODER, and gpio_t::nr.

Here is the call graph for this function: