GPIO pin operating mode.
typedef enum
{
dmgpio_mode_input = 0, // Digital input
dmgpio_mode_output_pp, // Output push-pull
dmgpio_mode_output_od, // Output open-drain
dmgpio_mode_af_pp, // Alternate function push-pull
dmgpio_mode_af_od, // Alternate function open-drain
dmgpio_mode_analog, // Analog mode (ADC/DAC)
} dmgpio_mode_t;Internal pull resistor configuration.
typedef enum
{
dmgpio_pull_none = 0, // No pull resistor
dmgpio_pull_up, // Pull-up resistor
dmgpio_pull_down, // Pull-down resistor
} dmgpio_pull_t;GPIO output slew rate.
typedef enum
{
dmgpio_speed_low = 0, // Low speed (~2 MHz)
dmgpio_speed_medium, // Medium speed (~25 MHz)
dmgpio_speed_high, // High speed (~50 MHz)
dmgpio_speed_very_high, // Very high speed (~100 MHz)
} dmgpio_speed_t;GPIO pin logic level.
typedef enum
{
dmgpio_pin_reset = 0, // Logic low (0)
dmgpio_pin_set, // Logic high (1)
} dmgpio_pin_state_t;IOCTL command codes for dmgpio_dmdrvi_ioctl, numbered from
DMDRVI_IOCTL_CUSTOM_BASE (0x1000, dmdrvi 2.0) - the range dmdrvi reserves
for driver-specific commands. Everything below it is a standard dmdrvi
command (network, block, monitor) that dmgpio does not implement.
Up to dmgpio 1.0 the commands were numbered from 0. Modules that send dmgpio ioctls must be rebuilt against dmgpio 1.1 or later.
typedef enum
{
dmgpio_ioctl_cmd_toggle_pins = DMDRVI_IOCTL_CUSTOM_BASE, // Toggle pins state (arg = NULL)
dmgpio_ioctl_cmd_set_pins_state, // arg = const dmgpio_pins_state_t*
dmgpio_ioctl_cmd_get_high_pins_state, // arg = dmgpio_pins_mask_t* - pins in high state
dmgpio_ioctl_cmd_get_low_pins_state, // arg = dmgpio_pins_mask_t* - pins in low state
dmgpio_ioctl_cmd_set_interrupt_handler // arg = dmgpio_interrupt_handler_t*
} dmgpio_ioctl_cmd_t;Create a new GPIO device context by reading configuration from an INI file.
dmdrvi_context_t dmgpio_dmdrvi_create(dmini_context_t config, dmdrvi_dev_num_t* dev_num);Parameters:
config– INI configuration context (see Configuration Guide)dev_num– Device number output
Returns: New context on success, NULL on failure.
Free the GPIO device context and deinitialize the pin.
void dmgpio_dmdrvi_free(dmdrvi_context_t context);Open a handle to the GPIO device.
void* dmgpio_dmdrvi_open(dmdrvi_context_t context, int flags);Parameters:
context– DMDRVI contextflags– Open flags (e.g.,DMDRVI_O_RDWR)
Returns: Device handle on success, NULL on failure.
Close the device handle.
void dmgpio_dmdrvi_close(dmdrvi_context_t context, void* handle);Read the current high-state pin bitmask as a hex string, with pread-style byte offset support.
size_t dmgpio_dmdrvi_read(dmdrvi_context_t context, void* handle, void* buffer, size_t size, uint32_t offset);The device is modelled as a 6-byte virtual file whose content is always the current high-state bitmask formatted as "0x%04X" (e.g. "0x000A"). offset is a byte offset into that content, enabling standard pread()-style access. An offset at or beyond 6 returns 0 bytes (EOF).
Example:
// offset=0, size=16 → "0x000A" (6 bytes, pin 1 and 3 are high)
// offset=6, size=16 → "" (0 bytes, EOF)
// offset=2, size=2 → "00" (mid-string slice)
Returns: Number of bytes copied into buffer, or 0 at EOF.
Write the desired high-state pin bitmask to the device.
size_t dmgpio_dmdrvi_write(dmdrvi_context_t context, void* handle, const void* buffer, size_t size, uint32_t offset);Accepts a decimal ("10") or hex ("0x000A") string. Trailing whitespace and newlines (e.g. appended by the shell's echo) are automatically stripped. Each bit in the value corresponds to a pin within the configured pins mask: a 1 sets the pin high, a 0 sets it low.
offset is not meaningful for GPIO (the state is a single atomic value) and is ignored.
Perform control and query operations on the GPIO device.
int dmgpio_dmdrvi_ioctl(dmdrvi_context_t context, void* handle, int command, void* arg);Parameters:
command– IOCTL command fromdmgpio_ioctl_cmd_targ– Command-specific argument (see command descriptions above)
Returns: 0 on success, -EINVAL for a missing arg, -ENOTTY for any
command that is not a dmgpio_ioctl_cmd_t - for example the dmdrvi class
probes (DMDRVI_IOCTL_BLOCK_GET_INFO, DMDRVI_IOCTL_MONITOR_GET_POLICY)
dmdevfs sends to every node, so GPIO nodes are never reported as block or
monitor devices. Unknown commands are not logged.
Get device statistics.
int dmgpio_dmdrvi_stat(dmdrvi_context_t context, void* handle, dmdrvi_stat_t* stat);The port layer defines hardware-specific functions. See include/dmgpio_port.h.
Initialize a GPIO pin.
int dmgpio_port_init(dmgpio_port_t port, dmgpio_pin_t pin,
dmgpio_mode_t mode, dmgpio_pull_t pull,
dmgpio_speed_t speed, uint8_t alternate);Deinitialize (reset) a GPIO pin.
int dmgpio_port_deinit(dmgpio_port_t port, dmgpio_pin_t pin);Read the current logical state of a GPIO pin.
dmgpio_pin_state_t dmgpio_port_read_pin(dmgpio_port_t port, dmgpio_pin_t pin);Set the logical state of a GPIO output pin.
void dmgpio_port_write_pin(dmgpio_port_t port, dmgpio_pin_t pin, dmgpio_pin_state_t state);Toggle the logical state of a GPIO output pin.
void dmgpio_port_toggle_pin(dmgpio_port_t port, dmgpio_pin_t pin);