# HG changeset patch # User Josef 'Jeff' Sipek # Date 1670791148 18000 # Sun Dec 11 15:39:08 2022 -0500 # Node ID 4b26d5c5e6432a54fed720b588d936dea19370dc # Parent ca149d313328d0a0fb7847a14440cf88caaab149 arch: add __set_pin static inline This is a low-overhead function to set/clear a GPIO pin. Signed-off-by: Josef 'Jeff' Sipek diff --git a/arch.h b/arch.h --- a/arch.h +++ b/arch.h @@ -41,6 +41,21 @@ #define mmregs ((volatile struct mmregs_layout * volatile) (void *) 0x0) /* + * GPIO pin setting helper + */ +#define PORTB (offsetof(struct mmregs_layout, portb) - 0x20) +#define PORTC (offsetof(struct mmregs_layout, portc) - 0x20) +#define PORTD (offsetof(struct mmregs_layout, portd) - 0x20) + +static inline void __set_pin(uint8_t port, uint8_t pin, bool set) +{ + if (set) + asm volatile("sbi %0, %1" :: "I" (port), "I" (pin)); + else + asm volatile("cbi %0, %1" :: "I" (port), "I" (pin)); +} + +/* * Macros to construct PORT and DDR register values */ #define PIN_INPUT_PORT_Z(bit) 0