Skip to content

File syn_gpio.h

File List > drivers > syn_gpio.h

Go to the documentation of this file

#ifndef SYN_GPIO_H
#define SYN_GPIO_H

#include "../common/syn_defs.h"
#include "../port/syn_port_gpio.h"

#ifdef __cplusplus
extern "C" {
#endif

#ifndef SYN_GPIO_PIN
#define SYN_GPIO_PIN(port_idx, pin_num) (((uint16_t)(port_idx) << 4) | ((pin_num) & 0x0F))
#endif

#ifndef SYN_GPIO_PIN_PORT
#define SYN_GPIO_PIN_PORT(pin) ((uint8_t)(((uint16_t)(pin) >> 4) & 0x0F))
#endif

#ifndef SYN_GPIO_PIN_NUM
#define SYN_GPIO_PIN_NUM(pin) ((uint8_t)((uint16_t)(pin) & 0x0F))
#endif

/* ── Convenience wrappers (inline pass-through to port layer) ─────────── */

static inline SYN_Status syn_gpio_init(SYN_GPIO_Pin pin, SYN_GPIO_Mode mode)
{
    return syn_port_gpio_init(pin, mode);
}

static inline SYN_Status syn_gpio_write(SYN_GPIO_Pin pin, SYN_GPIO_State state)
{
    return syn_port_gpio_write(pin, state);
}

static inline SYN_GPIO_State syn_gpio_read(SYN_GPIO_Pin pin)
{
    return syn_port_gpio_read(pin);
}

static inline SYN_Status syn_gpio_toggle(SYN_GPIO_Pin pin)
{
    return syn_port_gpio_toggle(pin);
}

/* ── Extended API (implemented in syn_gpio.c) ────────────────────────── */

SYN_Status syn_gpio_init_multiple(const SYN_GPIO_Pin *pins, size_t count, SYN_GPIO_Mode mode);

SYN_Status syn_gpio_write_multiple(const SYN_GPIO_Pin *pins, size_t count, SYN_GPIO_State state);

#ifdef __cplusplus
}
#endif

#endif /* SYN_GPIO_H */