Midnight Sun Firmware
Loading...
Searching...
No Matches
GPIO

GPIO library. More...

Classes

struct  GpioAddress
 Port and pin data. More...
 
struct  GpioInterrupt
 Storage class for GPIO interrupts. More...
 

Macros

#define GPIO_PINS_PER_PORT   16U
 16 Pins per port
 
#define GPIO_ADDRESS_OFFSET   0x400U
 Each GPIO Port is seperated in the MMIO by 1024 bytes.
 
#define GPIO_TOTAL_PINS   ((GPIO_PINS_PER_PORT) * (NUM_GPIO_PORTS))
 

Typedefs

typedef struct GpioAddress GpioAddress
 Port and pin data.
 
typedef struct GpioInterrupt GpioInterrupt
 Storage class for GPIO interrupts.
 

Enumerations

enum  GpioState { GPIO_STATE_LOW = 0 , GPIO_STATE_HIGH , NUM_GPIO_STATES }
 High or low GPIO state. More...
 
enum  GpioMode {
  GPIO_ANALOG = 0 , GPIO_INPUT_FLOATING , GPIO_INPUT_PULL_DOWN , GPIO_INPUT_PULL_UP ,
  GPIO_OUTPUT_OPEN_DRAIN , GPIO_OUTPUT_PUSH_PULL , GPIO_ALTFN_OPEN_DRAIN , GPIO_ALTFN_PUSH_PULL ,
  NUM_GPIO_MODES
}
 Available modes for the GPIO pins. More...
 
enum  GpioAlternateFunctions {
  GPIO_ALT_NONE = 0x00U , GPIO_ALT0_SWDIO = 0x00U , GPIO_ALT0_SWCLK = 0x00U , GPIO_ALT1_TIM1 = 0x01U ,
  GPIO_ALT1_TIM2 = 0x01U , GPIO_ALT4_I2C1 = 0x04U , GPIO_ALT4_I2C2 = 0x04U , GPIO_ALT4_I2C3 = 0x04U ,
  GPIO_ALT5_SPI1 = 0x05U , GPIO_ALT5_SPI2 = 0x05U , GPIO_ALT6_SPI3 = 0x06U , GPIO_ALT7_USART1 = 0x07U ,
  GPIO_ALT7_USART2 = 0x07U , GPIO_ALT7_USART3 = 0x07U , GPIO_ALT9_CAN1 = 0x09U , GPIO_ALT14_TIM15 = 0x0EU ,
  GPIO_ALT14_TIM16 = 0x0EU
}
 Alternate function mapping. Read STM32L433 datasheet page 75. More...
 
enum  GpioPort {
  GPIO_PORT_A = 0 , GPIO_PORT_B , GPIO_PORT_C , GPIO_PORT_D ,
  GPIO_PORT_E , GPIO_PORT_H , NUM_GPIO_PORTS
}
 Available GPIO ports. More...
 

Functions

StatusCode gpio_init (void)
 Initializes GPIO globally by disabling JTAG and enabling all GPIO clocks. More...
 
StatusCode gpio_init_pin (const GpioAddress *address, const GpioMode pin_mode, GpioState init_state)
 Initializes a GPIO pin by address. More...
 
StatusCode gpio_init_pin_af (const GpioAddress *address, const GpioMode pin_mode, GpioAlternateFunctions alt_func)
 Initializes an alternate function for a GPIO pin by address. More...
 
StatusCode gpio_set_state (const GpioAddress *address, GpioState state)
 Sets the GPIO pin to a valid state. More...
 
StatusCode gpio_toggle_state (const GpioAddress *address)
 Toggles the GPIO. More...
 
GpioState gpio_get_state (const GpioAddress *address)
 Gets the GPIO state. More...
 
StatusCode gpio_register_interrupt (const GpioAddress *address, const InterruptSettings *settings, const Event event, const Task *task)
 Register a GPIO interrupt by passing in the pin address and task to notify. More...
 
InterruptEdge gpio_it_get_edge (const GpioAddress *address)
 Gets the GPIO interrupt edge. More...
 
InterruptPriority gpio_it_get_priority (const GpioAddress *address)
 Gets the GPIO interrupt priority. More...
 
InterruptClass gpio_it_get_class (const GpioAddress *address)
 Gets the GPIO interrupt class. More...
 
Taskgpio_it_get_target_task (const GpioAddress *address)
 Gets the GPIO interrupt task. More...
 
StatusCode gpio_it_mask_interrupt (const GpioAddress *address, bool masked)
 Masks the GPIO interrupt. More...
 
StatusCode gpio_trigger_interrupt (const GpioAddress *address)
 Software generated GPIO interrupt. More...
 

Detailed Description

GPIO library.

Enumeration Type Documentation

◆ GpioAlternateFunctions

Alternate function mapping. Read STM32L433 datasheet page 75.

Enumerator
GPIO_ALT_NONE 

No alternate function

GPIO_ALT0_SWDIO 

Serial wire debug I/O

GPIO_ALT0_SWCLK 

Serial wire clock

GPIO_ALT1_TIM1 

Timer 1

GPIO_ALT1_TIM2 

Timer 2

GPIO_ALT4_I2C1 

I2C Hardware block 1

GPIO_ALT4_I2C2 

I2C Hardware block 2

GPIO_ALT4_I2C3 

I2C Hardware block 3

GPIO_ALT5_SPI1 

SPI Hardware block 1

GPIO_ALT5_SPI2 

SPI Hardware block 2

GPIO_ALT6_SPI3 

SPI Hardware block 3

GPIO_ALT7_USART1 

UART Hardware block 1

GPIO_ALT7_USART2 

UART Hardware block 2

GPIO_ALT7_USART3 

UART Hardware block 3

GPIO_ALT9_CAN1 

CAN Hardware block 1

GPIO_ALT14_TIM15 

Timer 15

GPIO_ALT14_TIM16 

Timer 16

◆ GpioMode

enum GpioMode

Available modes for the GPIO pins.

Enumerator
GPIO_ANALOG 

Analog input pin

GPIO_INPUT_FLOATING 

Floating input pin

GPIO_INPUT_PULL_DOWN 

Pulled-down input pin

GPIO_INPUT_PULL_UP 

Pulled-up input pin

GPIO_OUTPUT_OPEN_DRAIN 

Open drain output pin

GPIO_OUTPUT_PUSH_PULL 

Push pull output pin

GPIO_ALTFN_OPEN_DRAIN 

Alternate function Open drain pin

GPIO_ALTFN_PUSH_PULL 

Alternate functino Push pull pin

NUM_GPIO_MODES 

Number of GPIO Modes

◆ GpioPort

enum GpioPort

Available GPIO ports.

Enumerator
GPIO_PORT_A 

GPIO Port A

GPIO_PORT_B 

GPIO Port B

GPIO_PORT_C 

GPIO Port C

GPIO_PORT_D 

GPIO Port D

GPIO_PORT_E 

GPIO Port E

GPIO_PORT_H 

GPIO Port H

NUM_GPIO_PORTS 

Number of GPIO Ports

◆ GpioState

enum GpioState

High or low GPIO state.

Enumerator
GPIO_STATE_LOW 

GPIO output voltage is 0V

GPIO_STATE_HIGH 

GPIO output voltage is 3.3V

NUM_GPIO_STATES 

Number of GPIO states

Function Documentation

◆ gpio_get_state()

GpioState gpio_get_state ( const GpioAddress address)

Gets the GPIO state.

Parameters
addressto the GPIO address
Returns
STATUS_CODE_OK if pin reading succeeded STATUS_CODE_INVALID_ARGS if one of the parameters are incorrect

◆ gpio_init()

StatusCode gpio_init ( void  )

Initializes GPIO globally by disabling JTAG and enabling all GPIO clocks.

ONLY CALL ONCE or it will deinit all current settings. Change pin setting by calling gpio_init_pin

Returns
STATUS_CODE_OK if intialization succeeded.

◆ gpio_init_pin()

StatusCode gpio_init_pin ( const GpioAddress address,
const GpioMode  pin_mode,
GpioState  init_state 
)

Initializes a GPIO pin by address.

GPIOs are configured to a specified mode, at the max refresh speed

Parameters
addressPointer to the GPIO address
pin_modePin configuration mode
init_stateInitial GPIO state for output pins
Returns
STATUS_CODE_OK if pin initialization succeeded STATUS_CODE_INVALID_ARGS if one of the parameters are incorrect

◆ gpio_init_pin_af()

StatusCode gpio_init_pin_af ( const GpioAddress address,
const GpioMode  pin_mode,
GpioAlternateFunctions  alt_func 
)

Initializes an alternate function for a GPIO pin by address.

This initialization should be used I2C, SPI, UART and timers

Parameters
addressPointer to the GPIO address
pin_modePin configuration mode
alt_funcAlternate function of the GPIO
Returns
STATUS_CODE_OK if pin initialization succeeded STATUS_CODE_INVALID_ARGS if one of the parameters are incorrect

◆ gpio_it_get_class()

InterruptClass gpio_it_get_class ( const GpioAddress address)

Gets the GPIO interrupt class.

Parameters
addressPointer to the GPIO address
Returns
The corresponding GPIO's interrupt class NUM_INTERRUPT_CLASSES if the interrupt has not been registered

◆ gpio_it_get_edge()

InterruptEdge gpio_it_get_edge ( const GpioAddress address)

Gets the GPIO interrupt edge.

Parameters
addressPointer to the GPIO address
Returns
The corresponding GPIO's interrupt edge NUM_INTERRUPT_EDGES if the interrupt has not been registered

◆ gpio_it_get_priority()

InterruptPriority gpio_it_get_priority ( const GpioAddress address)

Gets the GPIO interrupt priority.

Parameters
addressPointer to the GPIO address
Returns
The corresponding GPIO's interrupt priority NUM_INTERRUPT_PRIORITIES if the interrupt has not been registered

◆ gpio_it_get_target_task()

Task * gpio_it_get_target_task ( const GpioAddress address)

Gets the GPIO interrupt task.

Parameters
addressPointer to the GPIO address
Returns
The corresponding GPIO's interrupt task NULL if the interrupt has not been registered

◆ gpio_it_mask_interrupt()

StatusCode gpio_it_mask_interrupt ( const GpioAddress address,
bool  masked 
)

Masks the GPIO interrupt.

Parameters
addressPointer to the GPIO address
masked0: Enables the GPIO interrupt 1: Mask the GPIO interrupt
Returns
STATUS_CODE_OK if interrupt masking succeeded STATUS_CODE_INVALID_ARGS if one of the parameters are incorrect

◆ gpio_register_interrupt()

StatusCode gpio_register_interrupt ( const GpioAddress address,
const InterruptSettings settings,
const Event  event,
const Task task 
)

Register a GPIO interrupt by passing in the pin address and task to notify.

Parameters
addressPointer to the GPIO address
settingsPointer to the interrupt settings
eventEvent notification
taskTask to notify when interrupt fires
Returns
STATUS_CODE_OK if interrupt initialization succeeded STATUS_CODE_INVALID_ARGS if one of the parameters are incorrect STATUS_CODE_RESOURCE_EXHAUSTED if the pin is already being used

◆ gpio_set_state()

StatusCode gpio_set_state ( const GpioAddress address,
GpioState  state 
)

Sets the GPIO pin to a valid state.

Parameters
addressto the GPIO address
stateGPIO state can either be HIGH/LOW
Returns
STATUS_CODE_OK if pin writing succeeded STATUS_CODE_INVALID_ARGS if one of the parameters are incorrect

◆ gpio_toggle_state()

StatusCode gpio_toggle_state ( const GpioAddress address)

Toggles the GPIO.

Parameters
addressto the GPIO address
Returns
STATUS_CODE_OK if pin toggling succeeded STATUS_CODE_INVALID_ARGS if one of the parameters are incorrect

◆ gpio_trigger_interrupt()

StatusCode gpio_trigger_interrupt ( const GpioAddress address)

Software generated GPIO interrupt.

Parameters
addressPointer to the GPIO address
Returns
STATUS_CODE_OK if interrupt triggering succeeded STATUS_CODE_INVALID_ARGS if one of the parameters are incorrect