Xmega Application Note


ioport.h

Go to the documentation of this file.
00001 
00038 #ifndef IOPORT_H
00039 #define IOPORT_H
00040 
00041 #include <compiler.h>
00042 
00043 
00060 typedef uint8_t pin_mask_t;
00061 
00067 typedef uint8_t port_pin_t;
00068 
00075 typedef uint16_t port_pin_flags_t;
00076 
00082 typedef uint8_t port_id_t;
00083 
00085 
00086 #define IOPORT_DIR_INPUT          (0 << 8) //!< Pin is Input
00087 #define IOPORT_DIR_OUTPUT         (1 << 8) //!< Pin is Output
00088 
00089 
00091 
00092 #define IOPORT_INIT_LOW           (0 << 9) //!< Initial Ouptput State is Low
00093 #define IOPORT_INIT_HIGH          (1 << 9) //!< Initial Ouptput State is High
00094 
00095 
00097 
00098 #define IOPORT_BOTHEDGES          (0 << 0) //!< Sense Both Edges
00099 #define IOPORT_RISING             (1 << 0) //!< Sense Risign Edge
00100 #define IOPORT_FALLING            (2 << 0) //!< Sense Falling Edge
00101 #define IOPORT_LEVEL              (3 << 0) //!< Sense Low Level
00102 #define IOPORT_INPUT_DISABLE      (7 << 0) //!< Input Buffer Disabled
00103 
00104 
00106 
00107 #define IOPORT_TOTEM              (0 << 3) //!< Normal push/pull output
00108 #define IOPORT_BUSKEEPER          (1 << 3) //!< Bus Keeper
00109 #define IOPORT_PULL_DOWN          (2 << 3) //!< Pull-Down (when input)
00110 #define IOPORT_PULL_UP            (3 << 3) //!< Pull-Up (when input)
00111 #define IOPORT_WIRED_OR           (4 << 3) //!< Wired OR
00112 #define IOPORT_WIRED_AND          (5 << 3) //!< Wired AND
00113 #define IOPORT_WIRED_OR_PULL_DOWN (6 << 3) //!< Wired OR and Pull-Down
00114 #define IOPORT_WIRED_AND_PULL_UP  (7 << 3) //!< Wired AND and Pull-Up
00115 
00116 
00118 
00119 #define IOPORT_INV_ENABLED        (1 << 6) //!< I/O is Inverted
00120 #define IOPORT_INV_DISABLE        (0 << 6) //!< I/O is Not Inverted
00121 
00122 
00124 
00125 #define IOPORT_SRL_ENABLED        (1 << 7) //!< Slew Rate Limit Enabled
00126 #define IOPORT_SRL_DISABLED       (0 << 7) //!< Slew Rate Limit Disabled
00127 
00128 
00129 
00139 #define IOPORT_CREATE_PIN(port, pin) ((PORT_##port) + (pin))
00140 
00152 static inline void *ioport_pin_to_port(port_pin_t pin)
00153 {
00154         // Each port has an offset of 0x20
00155         return (void *)((uintptr_t)&PORTA + (pin >> 3) * 0x20);
00156 }
00157 
00168 static inline void *ioport_id_pin_to_port(port_id_t port)
00169 {
00170         // Each port has an offset of 0x20
00171         return (void *)((uintptr_t)&PORTA + port * 0x20);
00172 }
00173 
00180 static inline pin_mask_t ioport_pin_to_mask(port_pin_t pin)
00181 {
00182         return 1U << (pin & 0x7);
00183 }
00184 
00193 extern void ioport_configure_port_pin(void *port, pin_mask_t pin_mask,
00194                 port_pin_flags_t flags);
00195 
00203 static inline void ioport_configure_pin(port_pin_t pin, port_pin_flags_t flags)
00204 {
00205         ioport_configure_port_pin(ioport_pin_to_port(pin), ioport_pin_to_mask(pin), flags);
00206 }
00207 
00208 
00217 static inline void ioport_configure_group(port_id_t port, pin_mask_t pin_mask, port_pin_flags_t flags)
00218 {
00219         ioport_configure_port_pin(ioport_id_pin_to_port(port), pin_mask, flags);
00220 }
00221 
00222 
00232 #define PORT_PORTA        (0 * 8)
00233 #define PORT_PORTB        (1 * 8)
00234 #define PORT_PORTC        (2 * 8)
00235 #define PORT_PORTD        (3 * 8)
00236 #define PORT_PORTE        (4 * 8)
00237 #define PORT_PORTF        (5 * 8)
00238 #define PORT_PORTG        (6 * 8)
00239 #define PORT_PORTH        (7 * 8)
00240 #define PORT_PORTJ        (8 * 8)
00241 #define PORT_PORTK        (9 * 8)
00242 #define PORT_PORTL        (10 * 8)
00243 #define PORT_PORTM        (11 * 8)
00244 #define PORT_PORTN        (12 * 8)
00245 #define PORT_PORTP        (13 * 8)
00246 #define PORT_PORTQ        (14 * 8)
00247 #define PORT_PORTR        (15 * 8)
00248 
00249 
00257 #define PORT_DIR                0x00  //!< Data Direction
00258 #define PORT_DIRSET             0x01  //!< Data Direction Set
00259 #define PORT_DIRCLR             0x02  //!< Data Direction Clear
00260 #define PORT_DIRTGL             0x03  //!< Data Direction Toggle
00261 #define PORT_OUT                0x04  //!< Data Output Value
00262 #define PORT_OUTSET             0x05  //!< Data Output Value Set
00263 #define PORT_OUTCLR             0x06  //!< Data Output Value Clear
00264 #define PORT_OUTTGL             0x07  //!< Data Output Value Toggle
00265 #define PORT_IN                 0x08  //!< Data Input Value
00266 #define PORT_INTCTRL            0x09  //!< Interrupt Control
00267 #define PORT_INT0MASK           0x0A  //!< Interrupt 0 Mask
00268 #define PORT_INT1MASK           0x0B  //!< Interrupt 1 Mask
00269 #define PORT_INTFLAGS           0x0C  //!< Interrupt Flags
00270 #define PORT_PIN0CTRL           0x10  //!< Pin 0 Configuration
00271 #define PORT_PIN1CTRL           0x11  //!< Pin 1 Configuration
00272 #define PORT_PIN2CTRL           0x12  //!< Pin 2 Configuration
00273 #define PORT_PIN3CTRL           0x13  //!< Pin 3 Configuration
00274 #define PORT_PIN4CTRL           0x14  //!< Pin 4 Configuration
00275 #define PORT_PIN5CTRL           0x15  //!< Pin 5 Configuration
00276 #define PORT_PIN6CTRL           0x16  //!< Pin 6 Configuration
00277 #define PORT_PIN7CTRL           0x17  //!< Pin 7 Configuration
00278 
00279 
00280 
00292 static inline void ioport_set_value(port_pin_t pin, bool value)
00293 {
00294         PORT_t *port = ioport_pin_to_port(pin);
00295         if (value)
00296                 port->OUTSET=ioport_pin_to_mask(pin);
00297         else
00298                 port->OUTCLR=ioport_pin_to_mask(pin);
00299 }
00300 
00309 static inline void ioport_set_pin_low(port_pin_t pin)
00310 {
00311         PORT_t *port = ioport_pin_to_port(pin);
00312         port->OUTCLR=ioport_pin_to_mask(pin);
00313 }
00314 
00323 static inline void ioport_set_pin_high(port_pin_t pin)
00324 {
00325         PORT_t *port = ioport_pin_to_port(pin);
00326         port->OUTSET=ioport_pin_to_mask(pin);
00327 }
00328 
00336 static inline bool ioport_get_value(port_pin_t pin)
00337 {
00338         PORT_t *port = ioport_pin_to_port(pin);
00339         return port->IN&ioport_pin_to_mask(pin);
00340 }
00341 
00349 static inline bool ioport_pin_is_high(port_pin_t pin)
00350 {
00351         PORT_t *port = ioport_pin_to_port(pin);
00352         return port->IN&ioport_pin_to_mask(pin);
00353 }
00354 
00362 static inline bool ioport_pin_is_low(port_pin_t pin)
00363 {
00364         PORT_t *port = ioport_pin_to_port(pin);
00365         return (~port->IN&ioport_pin_to_mask(pin));
00366 }
00372 static inline void ioport_toggle_pin(port_pin_t pin)
00373 {
00374         pin_mask_t pin_mask = ioport_pin_to_mask(pin);
00375         PORT_t *port = ioport_pin_to_port(pin);
00376         port->OUTTGL = pin_mask;
00377 }
00378 
00384 static inline void ioport_set_group_high(port_id_t port_id,pin_mask_t port_mask)
00385 {
00386         PORT_t *port  = ioport_id_pin_to_port(port_id);
00387         port->OUTSET = port_mask;
00388 }
00389 
00395 static inline void ioport_set_group_low(port_id_t port_id,pin_mask_t port_mask)
00396 {
00397         PORT_t *port  = ioport_id_pin_to_port(port_id);
00398         port->OUTCLR = port_mask;
00399 }
00400 
00406 static inline void ioport_tgl_group(port_id_t port_id,pin_mask_t port_mask)
00407 {
00408         PORT_t *port  = ioport_id_pin_to_port(port_id);
00409         port->OUTTGL = port_mask;
00410 }
00411 
00414 #endif /* IOPORT_H */
@DOC_TITLE@
Generated on Fri Oct 22 12:15:25 2010 for AVR1300 Using the Xmega ADC by doxygen 1.6.3