include/gpio/gpio_mega.h File Reference

ATmega specific GPIO implementation. More...

#include <assert.h>

Go to the source code of this file.

Defines

#define CREATE_GPIO_PIN(port, pin)   (GPIO_##port * 8 + (pin))
 Create a GPIO pin number.
GPIO pin configuration flags

#define GPIO_DIR_INPUT   (0 << 0)
 Set pin as input.
#define GPIO_DIR_OUTPUT   (1 << 0)
 Set pin as output.
#define GPIO_PULL_UP   (1 << 1)
 Enable pull-up.
#define GPIO_INIT_HIGH   (1 << 1)
 Set initial pin state to high.
#define GPIO_INIT_LOW   (0 << 1)

Typedefs

typedef uint8_t gpio_pin_t
 Pin number.

Functions

static port_t gpio_pin_to_port (gpio_pin_t pin)
 Convert a pin number to a port number.
static uint8_t gpio_pin_to_mask (gpio_pin_t pin)
 Generate pin mask from pin number.
static void gpio_set_gpio_pin (gpio_pin_t pin)
 Sets a pin to high state.
static void gpio_clear_gpio_pin (gpio_pin_t pin)
 Set pin to low state.
static void gpio_set_value (gpio_pin_t pin, bool value)
 Set gpio pin value.
static bool gpio_get_value (gpio_pin_t pin)
 Read a GPIO pin value.
static __always_inline void port_select_gpio_pin (gpio_pin_t pin, uint8_t flags)
 Configures a GPIO pin.

Detailed Description

ATmega specific GPIO implementation.

Copyright (C) 2009 Atmel Corporation. All rights reserved.

Definition in file gpio_mega.h.


Define Documentation

#define CREATE_GPIO_PIN ( port,
pin   )     (GPIO_##port * 8 + (pin))

Create a GPIO pin number.

This macro generates a pin number that can be used with the GPIO functions For instance to create a pin number for pin 2 on PORTA use the macro with the following parameters: CREATE_GPIO_PIN_NUMBER(PORTA, 2)

Parameters:
port Port name, e.g. PORTB.
pin Pin number on the port. Valid values are 0 to 7.

Definition at line 88 of file gpio_mega.h.

#define GPIO_DIR_INPUT   (0 << 0)

Set pin as input.

Definition at line 92 of file gpio_mega.h.

Referenced by board_gpio_set_spi_master_mode().

#define GPIO_DIR_OUTPUT   (1 << 0)

Set pin as output.

Definition at line 93 of file gpio_mega.h.

Referenced by board_gpio_set_spi_master_mode(), board_spi_init_select(), and port_select_gpio_pin().

#define GPIO_INIT_HIGH   (1 << 1)

Set initial pin state to high.

Definition at line 95 of file gpio_mega.h.

Referenced by board_spi_init_select(), and port_select_gpio_pin().

#define GPIO_INIT_LOW   (0 << 1)

Set initial pin state to low

Definition at line 96 of file gpio_mega.h.

#define GPIO_PULL_UP   (1 << 1)

Enable pull-up.

Definition at line 94 of file gpio_mega.h.

Referenced by port_select_gpio_pin().


Typedef Documentation

Pin number.

A pin number is generated from the port and the pin on the port.

  • Each port has 8 pins even if not available in the datasheet.
  • The firs pin number is 0

Examples: The first pin on port A has the number 0. The first pin on port B has the number 8.

Definition at line 55 of file gpio_mega.h.


Function Documentation

static void gpio_clear_gpio_pin ( gpio_pin_t  pin  )  [inline, static]

Set pin to low state.

Low in the sense of Vss.

Parameters:
pin Pin number.

Definition at line 163 of file gpio_mega.h.

References gpio_pin_to_mask(), and gpio_pin_to_port().

Referenced by gpio_set_value().

static bool gpio_get_value ( gpio_pin_t  pin  )  [inline, static]

Read a GPIO pin value.

Do not attempt to read a pin directly after you have set it. To get the correct value in this case a nop() instruction needs to be added.

Parameters:
pin GPIO pin number.
Returns:
true If pin is in high state (Vdd)
false if pin is in low state (Vss)

Definition at line 240 of file gpio_mega.h.

References gpio_pin_to_mask(), gpio_pin_to_port(), and unhandled_case.

Referenced by board_gpio_is_usb_msc_mode().

static uint8_t gpio_pin_to_mask ( gpio_pin_t  pin  )  [inline, static]

Generate pin mask from pin number.

Parameters:
pin Pin number

Definition at line 73 of file gpio_mega.h.

Referenced by gpio_clear_gpio_pin(), gpio_get_value(), gpio_set_gpio_pin(), and port_select_gpio_pin().

static port_t gpio_pin_to_port ( gpio_pin_t  pin  )  [inline, static]

Convert a pin number to a port number.

Parameters:
pin Pin number

Definition at line 63 of file gpio_mega.h.

Referenced by gpio_clear_gpio_pin(), gpio_get_value(), gpio_set_gpio_pin(), and port_select_gpio_pin().

static void gpio_set_gpio_pin ( gpio_pin_t  pin  )  [inline, static]

Sets a pin to high state.

(High means drive the pin towards Vdd)

Parameters:
pin Pin number.

Definition at line 106 of file gpio_mega.h.

References gpio_pin_to_mask(), and gpio_pin_to_port().

Referenced by gpio_set_value().

static void gpio_set_value ( gpio_pin_t  pin,
bool  value 
) [inline, static]

Set gpio pin value.

Parameters:
pin GPIO pin number of the pin.
value 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 222 of file gpio_mega.h.

References gpio_clear_gpio_pin(), and gpio_set_gpio_pin().

Referenced by board_gpio_mcu_reset(), board_spi_deselect_device(), and board_spi_select_device().

static __always_inline void port_select_gpio_pin ( gpio_pin_t  pin,
uint8_t  flags 
) [static]

Configures a GPIO pin.

Parameters:
pin Pin number of the GPIO pin.
flags Configuration options.

GPIO_DIR_INPUT: Set GPIO pin as input. GPIO_DIR_OUTPUT: Set GPIO pin as output. GPIO_PULL_UP: Activate the pull up if configured as input. GPIO_INIT_HIGH: Set output initial state as high. GPIO_INIT_LOW: Set output initial state as low.

Definition at line 296 of file gpio_mega.h.

References GPIO_DIR_OUTPUT, GPIO_INIT_HIGH, gpio_pin_to_mask(), gpio_pin_to_port(), and GPIO_PULL_UP.

Referenced by board_gpio_set_spi_master_mode(), and board_spi_init_select().

Generated on Thu Apr 29 14:10:34 2010 for xplain-bc by  doxygen 1.6.3