arch: add __set_pin static inline

This is a low-overhead function to set/clear a GPIO pin.

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
1 files changed, 15 insertions(+), 0 deletions(-)

M arch.h
M arch.h +15 -0
@@ 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