ELEC-C7222
Libraries for ELEC C7222 Course Work
Loading...
Searching...
No Matches
c7222_pico_w_board.h File Reference

Pico W board-level GPIO layout and helpers (C API). More...

#include <stdbool.h>
#include <stdint.h>
Include dependency graph for c7222_pico_w_board.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  c7222_led_type {
  C7222_PICO_W_LED3_GREEN = 16 , C7222_PICO_W_LED3_RED = 17 , C7222_PICO_W_LED2_GREEN = 18 , C7222_PICO_W_LED2_RED = 19 ,
  C7222_PICO_W_LED1_GREEN = 20 , C7222_PICO_W_LED1_RED = 21
}
 Logical LED identifiers mapped to GPIO pins. More...
 
enum  c7222_button_type { C7222_PICO_W_BUTTON_B1 = 2 , C7222_PICO_W_BUTTON_B2 = 3 , C7222_PICO_W_BUTTON_B3 = 4 , C7222_PICO_W_BUTTON_B4 = 5 }
 Logical button identifiers mapped to GPIO pins. More...
 
enum  c7222_gpio_event_type { C7222_GPIO_EVENT_LEVEL_LOW = 0x1u , C7222_GPIO_EVENT_LEVEL_HIGH = 0x2u , C7222_GPIO_EVENT_FALL = 0x4u , C7222_GPIO_EVENT_RISE = 0x8u }
 GPIO IRQ event bits compatible with Pico SDK GPIO IRQ flags. More...
 

Functions

void c7222_pico_w_board_init_gpio (void)
 Initialize all LED and button GPIOs for the board.
 
void c7222_pico_w_board_init_led (enum c7222_led_type led)
 Initialize a single LED GPIO.
 
void c7222_pico_w_board_button_init (enum c7222_button_type button, void(*handler)(uint32_t, uint32_t), uint32_t events, bool enabled)
 Initialize a button GPIO and optionally attach an IRQ handler.
 
bool c7222_pico_w_board_button_read (enum c7222_button_type button)
 Read the current button GPIO level.
 
bool c7222_pico_w_board_led_read (enum c7222_led_type led)
 Read the current LED state.
 
void c7222_pico_w_board_led_on (enum c7222_led_type led)
 Turn an LED ON (active-low).
 
void c7222_pico_w_board_led_off (enum c7222_led_type led)
 Turn an LED OFF (active-low).
 
void c7222_pico_w_board_led_toggle (enum c7222_led_type led)
 Toggle an LED output.
 
bool c7222_pico_w_onboard_led_init (void)
 Initialize the Pico W on-board LED.
 
void c7222_pico_w_onboard_led_set (bool on)
 Set the on-board LED state.
 
void c7222_pico_w_onboard_led_on (void)
 Turn the on-board LED ON.
 
void c7222_pico_w_onboard_led_off (void)
 Turn the on-board LED OFF.
 
void c7222_pico_w_onboard_led_toggle (void)
 Toggle the on-board LED.
 
bool c7222_pico_w_onboard_led_read (void)
 Read the on-board LED state.
 

Detailed Description

Pico W board-level GPIO layout and helpers (C API).

This header defines the GPIO layout for LEDs and buttons on the C7222 Pico W board and provides C-style helper functions for initializing and accessing those pins, plus a thin C wrapper for the Pico W on-board LED. The implementation is in libs/elec_c7222/devices/platform/rpi_pico/c7222_pico_w_board.c.

Note: This header is intended for C code. For C++ projects, prefer the c7222_pico_w_board.hpp API and its associated classes (PicoWBoard, Led, and Button).

Usage assumptions (from the implementation)

  • Call c7222_pico_w_board_init_gpio() once before using any of the LED or button helpers. All other functions assert if the board has not been initialized.
  • Buttons are configured as inputs with pull-ups enabled.
  • LEDs are configured as outputs. Note: the current implementation drives LEDs as active-low (see c7222_pico_w_board_led_on/off/read).

Enumeration Type Documentation

◆ c7222_button_type

Logical button identifiers mapped to GPIO pins.

Enumerator
C7222_PICO_W_BUTTON_B1 
C7222_PICO_W_BUTTON_B2 
C7222_PICO_W_BUTTON_B3 
C7222_PICO_W_BUTTON_B4 

◆ c7222_gpio_event_type

GPIO IRQ event bits compatible with Pico SDK GPIO IRQ flags.

These values match the Pico SDK bit assignments so they can be passed directly to gpio_set_irq_enabled* after mapping.

Enumerator
C7222_GPIO_EVENT_LEVEL_LOW 
C7222_GPIO_EVENT_LEVEL_HIGH 
C7222_GPIO_EVENT_FALL 
C7222_GPIO_EVENT_RISE 

◆ c7222_led_type

Logical LED identifiers mapped to GPIO pins.

Enumerator
C7222_PICO_W_LED3_GREEN 
C7222_PICO_W_LED3_RED 
C7222_PICO_W_LED2_GREEN 
C7222_PICO_W_LED2_RED 
C7222_PICO_W_LED1_GREEN 
C7222_PICO_W_LED1_RED 

Function Documentation

◆ c7222_pico_w_board_button_init()

void c7222_pico_w_board_button_init ( enum c7222_button_type  button,
void(*)(uint32_t, uint32_t)  handler,
uint32_t  events,
bool  enabled 
)

Initialize a button GPIO and optionally attach an IRQ handler.

Parameters
buttonButton identifier.
handlerIRQ callback (may be NULL).
eventsBitmask of c7222_gpio_event_type.
enabledEnable or disable the IRQ for this button.

Implementation assumptions:

  • Configures the button as input with pull-up.
  • Uses gpio_set_irq_enabled_with_callback if a handler is provided.
  • Does not attach a global callback if handler is NULL (IRQ disabled or enabled without callback).
Here is the caller graph for this function:

◆ c7222_pico_w_board_button_read()

bool c7222_pico_w_board_button_read ( enum c7222_button_type  button)

Read the current button GPIO level.

Returns
true if the pin reads high, false otherwise.
Note
Requires c7222_pico_w_board_init_gpio() to have been called.
Here is the caller graph for this function:

◆ c7222_pico_w_board_init_gpio()

void c7222_pico_w_board_init_gpio ( void  )

Initialize all LED and button GPIOs for the board.

Implementation assumptions:

  • Configures all LED pins as outputs and drives them to the default state.
  • Configures all button pins as inputs with pull-ups.
  • Sets an internal "initialized" flag used by other functions.
Here is the caller graph for this function:

◆ c7222_pico_w_board_init_led()

void c7222_pico_w_board_init_led ( enum c7222_led_type  led)

Initialize a single LED GPIO.

Parameters
ledLED identifier to initialize.
Note
Requires c7222_pico_w_board_init_gpio() to have been called.

◆ c7222_pico_w_board_led_off()

void c7222_pico_w_board_led_off ( enum c7222_led_type  led)

Turn an LED OFF (active-low).

Here is the caller graph for this function:

◆ c7222_pico_w_board_led_on()

void c7222_pico_w_board_led_on ( enum c7222_led_type  led)

Turn an LED ON (active-low).

Here is the caller graph for this function:

◆ c7222_pico_w_board_led_read()

bool c7222_pico_w_board_led_read ( enum c7222_led_type  led)

Read the current LED state.

Returns
true if LED is ON (active-low), false otherwise.
Note
Implementation reads the GPIO and inverts it.

◆ c7222_pico_w_board_led_toggle()

void c7222_pico_w_board_led_toggle ( enum c7222_led_type  led)

Toggle an LED output.

Here is the caller graph for this function:

◆ c7222_pico_w_onboard_led_init()

bool c7222_pico_w_onboard_led_init ( void  )

Initialize the Pico W on-board LED.

Uses either PICO_DEFAULT_LED_PIN or CYW43_WL_GPIO_LED_PIN depending on build configuration. Sets an internal initialization flag.

Returns
true on success, false if no on-board LED is available.

◆ c7222_pico_w_onboard_led_off()

void c7222_pico_w_onboard_led_off ( void  )

Turn the on-board LED OFF.

◆ c7222_pico_w_onboard_led_on()

void c7222_pico_w_onboard_led_on ( void  )

Turn the on-board LED ON.

◆ c7222_pico_w_onboard_led_read()

bool c7222_pico_w_onboard_led_read ( void  )

Read the on-board LED state.

Returns
true if the GPIO reads high. For CYW43 LED, readback is not supported, so this returns false.

◆ c7222_pico_w_onboard_led_set()

void c7222_pico_w_onboard_led_set ( bool  on)

Set the on-board LED state.

Parameters
ontrue for ON, false for OFF.
Note
Requires c7222_pico_w_onboard_led_init().

◆ c7222_pico_w_onboard_led_toggle()

void c7222_pico_w_onboard_led_toggle ( void  )

Toggle the on-board LED.