Xmega Application Note | |||||
Defines | |
#define | IOPORT_CREATE_PIN(port, pin) ((PORT_##port) + (pin)) |
Create a PORT pin number. | |
Typedefs | |
typedef uint8_t | pin_mask_t |
A bitmask representing a set of pins on a port. | |
typedef uint8_t | port_id_t |
A port id. | |
typedef uint16_t | port_pin_flags_t |
Pin configuration flags. | |
typedef uint8_t | port_pin_t |
A PORT pin. | |
Functions | |
static void | ioport_configure_group (port_id_t port, pin_mask_t pin_mask, port_pin_flags_t flags) |
Configure a group of I/O pins on a specified port number. | |
static void | ioport_configure_pin (port_pin_t pin, port_pin_flags_t flags) |
Select the port function for a single pin. | |
void | ioport_configure_port_pin (void *port, pin_mask_t pin_mask, port_pin_flags_t flags) |
Configure the IO PORT pin function for a set of pins on a port. | |
static bool | ioport_get_value (port_pin_t pin) |
Read the current state of a PORT pin. | |
static void * | ioport_id_pin_to_port (port_id_t port) |
Create a pointer to a port from a PORT id number. | |
static bool | ioport_pin_is_high (port_pin_t pin) |
Read the current state of a PORT pin and test high level. | |
static bool | ioport_pin_is_low (port_pin_t pin) |
Read the current state of a PORT pin and test high level. | |
static pin_mask_t | ioport_pin_to_mask (port_pin_t pin) |
Generate port pin mask form PORT pin number. | |
static void * | ioport_pin_to_port (port_pin_t pin) |
Create a pointer to a port from a PORT pin number. | |
static void | ioport_set_group_high (port_id_t port_id, pin_mask_t port_mask) |
Drives a group of I/O pin of a port to high level. | |
static void | ioport_set_group_low (port_id_t port_id, pin_mask_t port_mask) |
Drives a group of I/O pin of a port to low level. | |
static void | ioport_set_pin_high (port_pin_t pin) |
Drive a PORT pin to a high level. | |
static void | ioport_set_pin_low (port_pin_t pin) |
Drive a PORT pin to a low level. | |
static void | ioport_set_value (port_pin_t pin, bool value) |
Drive a PORT pin to a given state. | |
static void | ioport_tgl_group (port_id_t port_id, pin_mask_t port_mask) |
Toggles a group of I/O pin of a port. | |
static void | ioport_toggle_pin (port_pin_t pin) |
Toggle the current state of a PORT pin. | |
Input/Sense Configuration Flags | |
| |
#define | IOPORT_BOTHEDGES (0 << 0) |
Sense Both Edges. | |
#define | IOPORT_FALLING (2 << 0) |
Sense Falling Edge. | |
#define | IOPORT_INPUT_DISABLE (7 << 0) |
Input Buffer Disabled. | |
#define | IOPORT_LEVEL (3 << 0) |
Sense Low Level. | |
#define | IOPORT_RISING (1 << 0) |
Sense Risign Edge. | |
Output and Pull Configuration Flags | |
| |
#define | IOPORT_BUSKEEPER (1 << 3) |
Bus Keeper. | |
#define | IOPORT_PULL_DOWN (2 << 3) |
Pull-Down (when input). | |
#define | IOPORT_PULL_UP (3 << 3) |
Pull-Up (when input). | |
#define | IOPORT_TOTEM (0 << 3) |
Normal push/pull output. | |
#define | IOPORT_WIRED_AND (5 << 3) |
Wired AND. | |
#define | IOPORT_WIRED_AND_PULL_UP (7 << 3) |
Wired AND and Pull-Up. | |
#define | IOPORT_WIRED_OR (4 << 3) |
Wired OR. | |
#define | IOPORT_WIRED_OR_PULL_DOWN (6 << 3) |
Wired OR and Pull-Down. | |
Input/Output Configuration Flags | |
| |
#define | IOPORT_DIR_INPUT (0 << 8) |
Pin is Input. | |
#define | IOPORT_DIR_OUTPUT (1 << 8) |
Pin is Output. | |
Initial Output State Flags | |
| |
#define | IOPORT_INIT_HIGH (1 << 9) |
Initial Ouptput State is High. | |
#define | IOPORT_INIT_LOW (0 << 9) |
Initial Ouptput State is Low. | |
Inverted I/O Configuration Flags | |
| |
#define | IOPORT_INV_DISABLE (0 << 6) |
I/O is Not Inverted. | |
#define | IOPORT_INV_ENABLED (1 << 6) |
I/O is Inverted. | |
Slew Rate Limit Configuration Flags | |
| |
#define | IOPORT_SRL_DISABLED (0 << 7) |
Slew Rate Limit Disabled. | |
#define | IOPORT_SRL_ENABLED (1 << 7) |
Slew Rate Limit Enabled. | |
PORT fields struture offset | |
For internal use only. These macros are used to compute the field offset nummber with the PORT_t struture. | |
#define | PORT_DIR 0x00 |
Data Direction. | |
#define | PORT_DIRCLR 0x02 |
Data Direction Clear. | |
#define | PORT_DIRSET 0x01 |
Data Direction Set. | |
#define | PORT_DIRTGL 0x03 |
Data Direction Toggle. | |
#define | PORT_IN 0x08 |
Data Input Value. | |
#define | PORT_INT0MASK 0x0A |
Interrupt 0 Mask. | |
#define | PORT_INT1MASK 0x0B |
Interrupt 1 Mask. | |
#define | PORT_INTCTRL 0x09 |
Interrupt Control. | |
#define | PORT_INTFLAGS 0x0C |
Interrupt Flags. | |
#define | PORT_OUT 0x04 |
Data Output Value. | |
#define | PORT_OUTCLR 0x06 |
Data Output Value Clear. | |
#define | PORT_OUTSET 0x05 |
Data Output Value Set. | |
#define | PORT_OUTTGL 0x07 |
Data Output Value Toggle. | |
#define | PORT_PIN0CTRL 0x10 |
Pin 0 Configuration. | |
#define | PORT_PIN1CTRL 0x11 |
Pin 1 Configuration. | |
#define | PORT_PIN2CTRL 0x12 |
Pin 2 Configuration. | |
#define | PORT_PIN3CTRL 0x13 |
Pin 3 Configuration. | |
#define | PORT_PIN4CTRL 0x14 |
Pin 4 Configuration. | |
#define | PORT_PIN5CTRL 0x15 |
Pin 5 Configuration. | |
#define | PORT_PIN6CTRL 0x16 |
Pin 6 Configuration. | |
#define | PORT_PIN7CTRL 0x17 |
Pin 7 Configuration. | |
PORT Pin Numbering | |
For internal use only. These macros are used to generate PORT pin numbers for each port with the CREATE_PORT_PIN macro. Each port has 8 pins so e.g. the first pin on PORTB gets number 8, first pin on PORTC gets 16 ... | |
#define | PORT_PORTA (0 * 8) |
#define | PORT_PORTB (1 * 8) |
#define | PORT_PORTC (2 * 8) |
#define | PORT_PORTD (3 * 8) |
#define | PORT_PORTE (4 * 8) |
#define | PORT_PORTF (5 * 8) |
#define | PORT_PORTG (6 * 8) |
#define | PORT_PORTH (7 * 8) |
#define | PORT_PORTJ (8 * 8) |
#define | PORT_PORTK (9 * 8) |
#define | PORT_PORTL (10 * 8) |
#define | PORT_PORTM (11 * 8) |
#define | PORT_PORTN (12 * 8) |
#define | PORT_PORTP (13 * 8) |
#define | PORT_PORTQ (14 * 8) |
#define | PORT_PORTR (15 * 8) |
This is a driver implementation for the I/O ports peripheral. The I/O ports peripheral can be found on XMEGA devices and it controls and configures the I/O pins.
#define IOPORT_CREATE_PIN | ( | port, | |||
pin | ) | ((PORT_##port) + (pin)) |
Create a PORT pin number.
This macro creates a PORT pin number from a pin on a port. The PORT pin number can be used with the functions provided from this driver.
port | Port name e.g. PORTA. | |
pin | Pin number on the port, valid values are 0 to 7. |
Definition at line 139 of file ioport.h.
Referenced by board_init().
#define IOPORT_DIR_INPUT (0 << 8) |
#define IOPORT_DIR_OUTPUT (1 << 8) |
Pin is Output.
Definition at line 87 of file ioport.h.
Referenced by board_init(), and ioport_configure_port_pin().
#define IOPORT_INIT_HIGH (1 << 9) |
Initial Ouptput State is High.
Definition at line 93 of file ioport.h.
Referenced by board_init(), and ioport_configure_port_pin().
#define IOPORT_INIT_LOW (0 << 9) |
#define IOPORT_INPUT_DISABLE (7 << 0) |
#define IOPORT_PULL_UP (3 << 3) |
#define IOPORT_SRL_DISABLED (0 << 7) |
#define IOPORT_SRL_ENABLED (1 << 7) |
#define IOPORT_WIRED_AND_PULL_UP (7 << 3) |
#define IOPORT_WIRED_OR_PULL_DOWN (6 << 3) |
#define PORT_DIRCLR 0x02 |
Data Direction Clear.
Definition at line 259 of file ioport.h.
Referenced by ioport_configure_port_pin().
#define PORT_DIRSET 0x01 |
Data Direction Set.
Definition at line 258 of file ioport.h.
Referenced by ioport_configure_port_pin().
#define PORT_OUTCLR 0x06 |
Data Output Value Clear.
Definition at line 263 of file ioport.h.
Referenced by ioport_configure_port_pin().
#define PORT_OUTSET 0x05 |
Data Output Value Set.
Definition at line 262 of file ioport.h.
Referenced by ioport_configure_port_pin().
#define PORT_PIN0CTRL 0x10 |
Pin 0 Configuration.
Definition at line 270 of file ioport.h.
Referenced by ioport_configure_port_pin().
typedef uint8_t pin_mask_t |
typedef uint8_t port_id_t |
typedef uint16_t port_pin_flags_t |
typedef uint8_t port_pin_t |
static void ioport_configure_group | ( | port_id_t | port, | |
pin_mask_t | pin_mask, | |||
port_pin_flags_t | flags | |||
) | [inline, static] |
Configure a group of I/O pins on a specified port number.
port | The port number | |
pin_mask | The pin mask to configure | |
flags | Bitmask of flags specifying additional configuration parameters. |
Definition at line 217 of file ioport.h.
References ioport_configure_port_pin(), and ioport_id_pin_to_port().
00218 { 00219 ioport_configure_port_pin(ioport_id_pin_to_port(port), pin_mask, flags); 00220 }
static void ioport_configure_pin | ( | port_pin_t | pin, | |
port_pin_flags_t | flags | |||
) | [inline, static] |
Select the port function for a single pin.
pin | The pin to configure | |
flags | Bitmask of flags specifying additional configuration parameters. |
Definition at line 203 of file ioport.h.
References ioport_configure_port_pin(), ioport_pin_to_mask(), and ioport_pin_to_port().
Referenced by board_init().
00204 { 00205 ioport_configure_port_pin(ioport_pin_to_port(pin), ioport_pin_to_mask(pin), flags); 00206 }
void ioport_configure_port_pin | ( | void * | port, | |
pin_mask_t | pin_mask, | |||
port_pin_flags_t | flags | |||
) |
Configure the IO PORT pin function for a set of pins on a port.
port | Pointer to the port | |
pin_mask | Mask containing the pins that should be configured | |
flags | Bitmask of flags specifying additional configuration parameters. |
Definition at line 40 of file ioport.c.
References IOPORT_DIR_OUTPUT, IOPORT_INIT_HIGH, PORT_DIRCLR, PORT_DIRSET, PORT_OUTCLR, PORT_OUTSET, and PORT_PIN0CTRL.
Referenced by ioport_configure_group(), and ioport_configure_pin().
00041 { 00042 uint8_t pin; 00043 00044 for (pin = 0; pin < 8; pin++) { 00045 if (pin_mask & (1 << pin)) { 00046 *((uint8_t*)port+PORT_PIN0CTRL+pin)=flags; 00047 } 00048 } 00049 /* Select direction and initial pin state */ 00050 if (flags & IOPORT_DIR_OUTPUT) { 00051 if (flags & IOPORT_INIT_HIGH) { 00052 *((uint8_t*)port+PORT_OUTSET)=pin_mask; 00053 } 00054 else { 00055 *((uint8_t*)port+PORT_OUTCLR)=pin_mask; 00056 } 00057 *((uint8_t*)port+PORT_DIRSET)=pin_mask; 00058 } 00059 else { 00060 *((uint8_t*)port+PORT_DIRCLR)=pin_mask; 00061 } 00062 }
static bool ioport_get_value | ( | port_pin_t | pin | ) | [inline, static] |
Read the current state of a PORT pin.
pin | A number identifying the pin to read. |
true | The pin is currently high (close to Vdd) | |
false | The pin is currently low (close to Vss) |
Definition at line 336 of file ioport.h.
References ioport_pin_to_mask(), and ioport_pin_to_port().
00337 { 00338 PORT_t *port = ioport_pin_to_port(pin); 00339 return port->IN&ioport_pin_to_mask(pin); 00340 }
static void* ioport_id_pin_to_port | ( | port_id_t | port | ) | [inline, static] |
Create a pointer to a port from a PORT id number.
It is assumed that all ports are lined up after PORTA in the memory map like it is described in the XMEGA A manual. Otherwise we have to do a switch case here.
port | PORT id number. (PORTA is 0, PORTB is 1 ...) |
Definition at line 168 of file ioport.h.
Referenced by ioport_configure_group(), ioport_set_group_high(), ioport_set_group_low(), and ioport_tgl_group().
static bool ioport_pin_is_high | ( | port_pin_t | pin | ) | [inline, static] |
Read the current state of a PORT pin and test high level.
pin | A number identifying the pin to read. |
true | The pin is currently high (close to Vdd) | |
false | The pin is currently low (close to Vss) |
Definition at line 349 of file ioport.h.
References ioport_pin_to_mask(), and ioport_pin_to_port().
00350 { 00351 PORT_t *port = ioport_pin_to_port(pin); 00352 return port->IN&ioport_pin_to_mask(pin); 00353 }
static bool ioport_pin_is_low | ( | port_pin_t | pin | ) | [inline, static] |
Read the current state of a PORT pin and test high level.
pin | A number identifying the pin to read. |
true | The pin is currently high (close to Vdd) | |
false | The pin is currently low (close to Vss) |
Definition at line 362 of file ioport.h.
References ioport_pin_to_mask(), and ioport_pin_to_port().
00363 { 00364 PORT_t *port = ioport_pin_to_port(pin); 00365 return (~port->IN&ioport_pin_to_mask(pin)); 00366 }
static pin_mask_t ioport_pin_to_mask | ( | port_pin_t | pin | ) | [inline, static] |
Generate port pin mask form PORT pin number.
pin | PORT pin number. |
Definition at line 180 of file ioport.h.
Referenced by ioport_configure_pin(), ioport_get_value(), ioport_pin_is_high(), ioport_pin_is_low(), ioport_set_pin_high(), ioport_set_pin_low(), ioport_set_value(), and ioport_toggle_pin().
static void* ioport_pin_to_port | ( | port_pin_t | pin | ) | [inline, static] |
Create a pointer to a port from a PORT pin number.
It is assumed that all ports are lined up after PORTA in the memory map like it is described in the XMEGA A manual. Otherwise we have to do a switch case here.
pin | PORT pin number. This number can be generated by the macro CREATE_PORT_PIN. |
Definition at line 152 of file ioport.h.
Referenced by ioport_configure_pin(), ioport_get_value(), ioport_pin_is_high(), ioport_pin_is_low(), ioport_set_pin_high(), ioport_set_pin_low(), ioport_set_value(), and ioport_toggle_pin().
static void ioport_set_group_high | ( | port_id_t | port_id, | |
pin_mask_t | port_mask | |||
) | [inline, static] |
Drives a group of I/O pin of a port to high level.
port_id | The port number. | |
port_mask | The mask. |
Definition at line 384 of file ioport.h.
References ioport_id_pin_to_port().
00385 { 00386 PORT_t *port = ioport_id_pin_to_port(port_id); 00387 port->OUTSET = port_mask; 00388 }
static void ioport_set_group_low | ( | port_id_t | port_id, | |
pin_mask_t | port_mask | |||
) | [inline, static] |
Drives a group of I/O pin of a port to low level.
port_id | The port number. | |
port_mask | The mask. |
Definition at line 395 of file ioport.h.
References ioport_id_pin_to_port().
00396 { 00397 PORT_t *port = ioport_id_pin_to_port(port_id); 00398 port->OUTCLR = port_mask; 00399 }
static void ioport_set_pin_high | ( | port_pin_t | pin | ) | [inline, static] |
Drive a PORT pin to a high level.
This function will only have an effect if pin is configured as an output.
pin | A number identifying the pin to act on. |
Definition at line 323 of file ioport.h.
References ioport_pin_to_mask(), and ioport_pin_to_port().
00324 { 00325 PORT_t *port = ioport_pin_to_port(pin); 00326 port->OUTSET=ioport_pin_to_mask(pin); 00327 }
static void ioport_set_pin_low | ( | port_pin_t | pin | ) | [inline, static] |
Drive a PORT pin to a low level.
This function will only have an effect if pin is configured as an output.
pin | A number identifying the pin to act on. |
Definition at line 309 of file ioport.h.
References ioport_pin_to_mask(), and ioport_pin_to_port().
00310 { 00311 PORT_t *port = ioport_pin_to_port(pin); 00312 port->OUTCLR=ioport_pin_to_mask(pin); 00313 }
static void ioport_set_value | ( | port_pin_t | pin, | |
bool | value | |||
) | [inline, static] |
Drive a PORT pin to a given state.
This function will only have an effect if pin is configured as an output.
pin | A number identifying the pin to act on. | |
value | The desired state of the pin. true means drive the pin high (towards Vdd), while false means drive the pin low (towards Vss). |
Definition at line 292 of file ioport.h.
References ioport_pin_to_mask(), and ioport_pin_to_port().
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 }
static void ioport_tgl_group | ( | port_id_t | port_id, | |
pin_mask_t | port_mask | |||
) | [inline, static] |
Toggles a group of I/O pin of a port.
port_id | The port number. | |
port_mask | The mask. |
Definition at line 406 of file ioport.h.
References ioport_id_pin_to_port().
00407 { 00408 PORT_t *port = ioport_id_pin_to_port(port_id); 00409 port->OUTTGL = port_mask; 00410 }
static void ioport_toggle_pin | ( | port_pin_t | pin | ) | [inline, static] |
Toggle the current state of a PORT pin.
pin | A number identifying the pin to act on. |
Definition at line 372 of file ioport.h.
References ioport_pin_to_mask(), and ioport_pin_to_port().
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 }
Generated on Fri Oct 22 12:15:26 2010 for AVR1300 Using the Xmega ADC by ![]() |