Use cunning enumeration scheme for PIOs

main
Michael Hayes 14 years ago
parent e346ab13b0
commit f0670cba4e

@ -41,44 +41,11 @@
/** Define port names, note not all the ports are available on some AVRs. */ /** Define port names, note not all the ports are available on some AVRs. */
#ifdef PORTA enum {PORT_A, PORT_B, PORT_C, PORT_D, PORT_E, PORT_F, PORT_G};
#define PORT_A &PORTA
#endif
#ifdef PORTB
#define PORT_B &PORTB
#endif
#ifdef PORTC
#define PORT_C &PORTC
#endif
#ifdef PORTD
#define PORT_D &PORTD
#endif
#ifdef PORTE
#define PORT_E &PORTE
#endif
#ifdef PORTF
#define PORT_F &PORTF
#endif
#ifdef PORTG
#define PORT_G &PORTG
#endif
typedef volatile uint8_t *pio_port_t; typedef volatile uint8_t *pio_port_t;
typedef uint8_t pio_mask_t; typedef uint8_t pio_mask_t;
typedef uint16_t pio_t;
typedef struct
{
pio_port_t port;
pio_mask_t bitmask;
} pio_t;
/** Define PIO pin types. The two flavours of PIO_OUTPUT are to /** Define PIO pin types. The two flavours of PIO_OUTPUT are to
@ -101,17 +68,19 @@ typedef enum pio_config_enum
*/ */
/** Define a PIO as a compound literal structure in terms of a port and /** Define a PIO as a unique 16 bit number encoding the low part of
a bitmask. */ the PORT address in the low byte and the bit mask in the high
#define PIO_DEFINE(PORT, PORTBIT) (pio_t){.port = PORT, .bitmask = BIT (PORTBIT)} byte. PORTB is used for the pattern since PORTA is not always
defined for some AVRs. */
#define PIO_DEFINE(PORT, PORTBIT) (((((PORT) - PORT_B) * 3 + (uint16_t) (&PORTB)) & 0xff) + (BIT(PORTBIT) << 8))
/** Private macro to lookup bitmask. */ /** Private macro to lookup bitmask. */
#define PIO_BITMASK_(pio) (pio.bitmask) #define PIO_BITMASK_(pio) (pio >> 8)
/** Private macro to lookup port register. */ /** Private macro to lookup port register. */
#define PIO_PORT_(pio) (pio.port) #define PIO_PORT_(pio) ((pio_port_t)(pio & 0xff))
/** Private macro to map a pio to its corresponding data direction /** Private macro to map a pio to its corresponding data direction

Loading…
Cancel
Save