Source

vectorscope / bits.c

Diff from to
 #include <avr/pgmspace.h>
 #include "bits.h"
 
-#define set_bit(PORT, PIN, VALUE) do { \
-		if (VALUE) \
-			sbi(PORT, PIN); \
-		else \
-			cbi(PORT, PIN); \
-	} while (0)
-
-#define get_bit(PORT, PIN) \
-	((PORT) & (1 << PIN))
-
-
 void
-ddr(
+__bits_ddr(
 	const uint8_t id,
 	const uint8_t value
 )
 {
-	const uint8_t port = (id >> 4) & 0xF;
-	const uint8_t pin = (id >> 0) & 0xF;
-
-	switch (port)
-	{
-#if defined(__AVR_AT90USB162__)
-	case 0xA:
-		set_bit(DDRA, pin, value);
-		return;
-#endif
-	case 0xB:
-		set_bit(DDRB, pin, value);
-		return;
-	case 0xC:
-		set_bit(DDRC, pin, value);
-		return;
-	case 0xD:
-		set_bit(DDRD, pin, value);
-		return;
-	case 0xE:
-		set_bit(DDRE, pin, value);
-		return;
-	case 0xF:
-		set_bit(DDRF, pin, value);
-		return;
-	}
+	__inline_ddr(id, value);
 }
 
 
 void
-out(
+__bits_out(
 	const uint8_t id,
 	const uint8_t value
 )
 {
-	const uint8_t port = (id >> 4) & 0xF;
-	const uint8_t pin = (id >> 0) & 0xF;
-
-	switch (port)
-	{
-#if defined(__AVR_AT90USB162__)
-	case 0xA:
-		set_bit(PORTA, pin, value);
-		return;
-#endif
-	case 0xB:
-		set_bit(PORTB, pin, value);
-		return;
-	case 0xC:
-		set_bit(PORTC, pin, value);
-		return;
-	case 0xD:
-		set_bit(PORTD, pin, value);
-		return;
-	case 0xE:
-		set_bit(PORTE, pin, value);
-		return;
-	case 0xF:
-		set_bit(PORTF, pin, value);
-		return;
-	}
-
-	send_str(PSTR("bad\r\n"));
+	__inline_out(id, value);
 }
 
 
 uint8_t
-in(
+__bits_in(
 	const uint8_t id
 )
 {
-	const uint8_t port = (id >> 4) & 0xF;
-	const uint8_t pin = (id >> 0) & 0xF;
-
-	switch (port)
-	{
-#if defined(__AVR_AT90USB162__)
-	case 0xA:
-		return get_bit(PINA, pin);
-#endif
-	case 0xB:
-		return get_bit(PINB, pin);
-	case 0xC:
-		return get_bit(PINC, pin);
-	case 0xD:
-		return get_bit(PIND, pin);
-	case 0xE:
-		return get_bit(PINE, pin);
-	case 0xF:
-		return get_bit(PINF, pin);
-	}
-
-	return 0;
+	return __inline_in(id);
 }