std1.0.0-beta-7 SafeC docs

std :: hal::gpio

Struct std::GpioPin

#include <std/hal/gpio.h> source

generic<C: GpioChip> struct GpioPin {
    &volatile unsigned int base;
    int pin;
    unsigned int pin_mask;
    int direction;
    C chip;
}

Fields

§&volatile unsigned int basesource

MMIO base address of the GPIO port

§int pinsource

pin number within the port

§unsigned int pin_masksource

1 << pin

§int directionsource

GPIO_INPUT or GPIO_OUTPUT

§C chipsource

Methods

§static struct GpioPin<C> new(&volatile unsigned int base, int pin, int direction)source · definition

Initialize a GPIO pin: base = port base, pin = pin number (0-31; 0-15 on STM32). The chip type comes from the target:

struct GpioPin<GpioGeneric> p = std::GpioPin::new(base, 3, GPIO_INPUT);
§void set_direction(int direction)source · definition

Set pin direction (GPIO_INPUT or GPIO_OUTPUT).

§void write(int value)source · definition

Write 1 (high) or 0 (low) to an output pin.

§int read() constsource · definition

Read pin state. Returns 0 or 1.

§void toggle()source · definition

Toggle output pin.

§void set_pull(int pull)source · definition

GPIO_PULL_NONE, GPIO_PULL_UP or GPIO_PULL_DOWN.