/**************************************************************************//**
\file  gpio.h

\brief This module contains a set of functions to manipulate GPIO pins.

\author
    Atmel Corporation: http://www.atmel.com \n
    Support email: avr@atmel.com

  Copyright (c) 2008-2015, Atmel Corporation. All rights reserved.
  Licensed under Atmel's Limited License Agreement (BitCloudTM).

\internal
  History:
    17/08/07 A. Khromykh - Created
******************************************************************************/
#ifndef _GPIO_H
#define _GPIO_H

/******************************************************************************
                   Includes section
******************************************************************************/
#include <types.h>
#include <AT91SAM7X256.h>

/******************************************************************************
                   Define(s) section
******************************************************************************/
/******************************************************************************
* void gpioX_set() sets GPIOX pin to logical 1 level.
* void gpioX_clr() clears GPIOX pin to logical 0 level.
* void gpioX_make_in makes GPIOX pin as input.
* void gpioX_make_in makes GPIOX pin as output.
* uint8_t gpioX_read() returns logical level GPIOX pin.
* uint8_t gpioX_state() returns configuration of GPIOX port.
*******************************************************************************/
#define HAL_ASSIGN_PIN(name, port, bit) \
INLINE void  GPIO_##name##_set()         {AT91C_BASE_PIO##port->PIO_SODR = bit;} \
INLINE void  GPIO_##name##_clr()         {AT91C_BASE_PIO##port->PIO_CODR = bit;} \
INLINE uint8_t  GPIO_##name##_read()     {return ((AT91C_BASE_PIO##port->PIO_PDSR & bit) != 0l);} \
INLINE uint8_t  GPIO_##name##_state()    {return ((AT91C_BASE_PIO##port->PIO_OSR & bit) != 0l);} \
INLINE void  GPIO_##name##_make_out()    {AT91C_BASE_PIO##port->PIO_OER = bit;} \
INLINE void  GPIO_##name##_make_in()     {AT91C_BASE_PIO##port->PIO_ODR = bit; AT91C_BASE_PIO##port->PIO_PPUDR = bit;} \
INLINE void  GPIO_##name##_make_pullup() {AT91C_BASE_PIO##port->PIO_PPUER = bit;}\
INLINE void  GPIO_##name##_toggle()      {if (AT91C_BASE_PIO##port->PIO_ODSR & bit) \
                                            AT91C_BASE_PIO##port->PIO_CODR = bit; \
                                          else \
                                            AT91C_BASE_PIO##port->PIO_SODR = bit;}

/******************************************************************************
                   Inline static functions section
******************************************************************************/
// SPI SS manipulation macros
HAL_ASSIGN_PIN(SPI1_SS, A, AT91C_PIO_PA25);

#endif
//eof gpio.h
