Subversion Repositories idreammicro-avr

Rev

Rev 2 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

/**************************************************************************//**
 * \brief Digital I/O library - API
 * \author Copyright (C) 2009  Julien Le Sech - www.idreammicro.com
 * \version 1.0
 * \date 20090314
 *
 * This file is part of the iDreamMicro library.
 *
 * This library is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any
 * later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/
 ******************************************************************************/


/**************************************************************************//**
 * \headerfile digital_io.h
 *
 * \brief
 *
 * \see
 ******************************************************************************/

 
#ifndef H__IDREAMMICRO__DIGITAL_IO__H
#define H__IDREAMMICRO__DIGITAL_IO__H

#ifdef _cplusplus
extern "C"{
#endif

/******************************************************************************
 * Header file inclusions.
 ******************************************************************************/


#include <avr/io.h>

#include <stdint.h>

/******************************************************************************
 * Public macro definitions.
 ******************************************************************************/


/**************************************************************************//**
 * \def digital_io__get_port(pin_position)
 * \brief Get port from pin position.
 ******************************************************************************/

#define digital_io__get_port(pin_position)  ((pin_position) >> 4)

/**************************************************************************//**
 * \def digital_io__get_pin(pin_position)
 * \brief Get pin form pin position.
 ******************************************************************************/

#define digital_io__get_pin(pin_position)   ((pin_position) & 0x0F)

/**************************************************************************//**
 * \def DIGITAL_IO__PORT_A
 * \brief Port A.
 ******************************************************************************/

#define DIGITAL_IO__PORT_A  0x00

/**************************************************************************//**
 * \def DIGITAL_IO__PORT_B
 * \brief Port B.
 ******************************************************************************/

#define DIGITAL_IO__PORT_B  0x10

/**************************************************************************//**
 * \def DIGITAL_IO__PORT_C
 * \brief Port C.
 ******************************************************************************/

#define DIGITAL_IO__PORT_C  0x20

/**************************************************************************//**
 * \def DIGITAL_IO__PORT_D
 * \brief Port D.
 ******************************************************************************/

#define DIGITAL_IO__PORT_D  0x30

/**************************************************************************//**
 * \def DIGITAL_IO__PORT_E
 * \brief Port E.
 ******************************************************************************/

#define DIGITAL_IO__PORT_E  0x40

/**************************************************************************//**
 * \def DIGITAL_IO__PORT_F
 * \brief Port F.
 ******************************************************************************/

#define DIGITAL_IO__PORT_F  0x50

/**************************************************************************//**
 * \def DIGITAL_IO__PORT_G
 * \brief Port G.
 ******************************************************************************/

#define DIGITAL_IO__PORT_G  0x60

/**************************************************************************//**
 * \def DIGITAL_IO__PORT_H
 * \brief port H.
 ******************************************************************************/

#define DIGITAL_IO__PORT_H  0x70

/**************************************************************************//**
 * \def DIGITAL_IO__PORT_J
 * \brief Port J.
 ******************************************************************************/

#define DIGITAL_IO__PORT_J  0x80

/**************************************************************************//**
 * \def DIGITAL_IO__PORT_K
 * \brief Port K.
 ******************************************************************************/

#define DIGITAL_IO__PORT_K  0x90

/**************************************************************************//**
 * \def DIGITAL_IO__PORT_L
 * \brief Port L.
 ******************************************************************************/

#define DIGITAL_IO__PORT_L  0xA0

/**************************************************************************//**
 * \def DIGITAL_IO__PIN_0
 * \brief Pin 0.
 ******************************************************************************/

#define DIGITAL_IO__PIN_0   0

/**************************************************************************//**
 * \def DIGITAL_IO__PIN_1
 * \brief Pin 1.
 ******************************************************************************/

#define DIGITAL_IO__PIN_1   1

/**************************************************************************//**
 * \def DIGITAL_IO__PIN_2
 * \brief Pin 2.
 ******************************************************************************/

#define DIGITAL_IO__PIN_2   2

/**************************************************************************//**
 * \def DIGITAL_IO__PIN_3
 * \brief Pin 3.
 ******************************************************************************/

#define DIGITAL_IO__PIN_3   3

/**************************************************************************//**
 * \def DIGITAL_IO__PIN_4
 * \brief Pin 4.
 ******************************************************************************/

#define DIGITAL_IO__PIN_4   4

/**************************************************************************//**
 * \def DIGITAL_IO__PIN_5
 * \brief Pin 5.
 ******************************************************************************/

#define DIGITAL_IO__PIN_5   5

/**************************************************************************//**
 * \def DIGITAL_IO__PIN_6
 * \brief Pin 6.
 ******************************************************************************/

#define DIGITAL_IO__PIN_6   6

/**************************************************************************//**
 * \def DIGITAL_IO__PIN_7
 * \brief Pin 7.
 ******************************************************************************/

#define DIGITAL_IO__PIN_7   7

/******************************************************************************
 * Public types.
 ******************************************************************************/


/**************************************************************************//**
 * \typedef digital_io__port_t
 * \brief   Represent a digital port.
 ******************************************************************************/

typedef uint8_t digital_io__port_t;

/**************************************************************************//**
 * \typedef digital_io__pin_t
 * \brief   Represent a digital pin.
 ******************************************************************************/

typedef uint8_t digital_io__pin_t;

/**************************************************************************//**
 * \typedef digital_io__pin_position_t
 * \brief Digital IO pin position.
 * High nibble is used for the port, low nibble is used for the pin.
 * digital_io__pin_position_t pin = DIGITAL_IO__PORT_B | DIGITAL_IO__PIN_5;
 ******************************************************************************/

typedef uint8_t digital_io__pin_position_t;

/**************************************************************************//**
 * \enum digital_io__directions
 * \brief Digital IO directions.
 *
 * \typedef digital_io__direction_t
 * \brief Digital IO direction.
 ******************************************************************************/

typedef enum digital_io__directions
{
    DIGITAL_IO__DIRECTION__INPUT,       /*!<  Input. */
    DIGITAL_IO__DIRECTION__OUTPUT       /*!<  Output. */
} digital_io__direction_t;

/**************************************************************************//**
 * \enum digital_io__levels
 * \brief Digital IO levels.
 *
 * \typedef digital_io__level_t
 * \brief Digital IO level.
 ******************************************************************************/

typedef enum digital_io__levels
{
    DIGITAL_IO__LEVEL__LOW, /*!<  Low level. */
    DIGITAL_IO__LEVEL__HIGH /*!<  High level. */
} digital_io__level_t;

/**************************************************************************//**
 * \typedef digital_io__port_value_t
 * \brief Port value.
 ******************************************************************************/

typedef uint8_t digital_io__port_value_t;

/******************************************************************************
 * Public function prototypes.
 ******************************************************************************/


/**************************************************************************//**
 * \fn void digital_io__configure_pin(
 * digital_io__pin_position_t   pin_position,
 * digital_io__direction_t      direction)
 *
 * \brief Configure a pin.
 *
 * \param   pin_position    pin position to configure
 * \param   direction       pin direction to set
 ******************************************************************************/

void
digital_io__configure_pin
(
    digital_io__pin_position_t  pin_position,
    digital_io__direction_t     direction
);

/**************************************************************************//**
 * \fn digital_io__level_t digital_io__get_pin_level(
 * digital_io__pin_position_t   pin_position)
 *
 * \brief Get the level of a pin.
 *
 * \param   pin_position    pin position to get level
 *
 * \return digital io level
 ******************************************************************************/

digital_io__level_t
digital_io__get_pin_level
(
    digital_io__pin_position_t  pin_position
);

/**************************************************************************//**
 * \fn void digital_io__set_pin_level(
 * digital_io__pin_position_t   pin_position,
 * digital_io__level_t          level)
 *
 * \brief Set the level of a pin.
 *
 * \param   pin_position    pin position to set level
 * \param   level           level to set
 ******************************************************************************/

void
digital_io__set_pin_level
(
    digital_io__pin_position_t  pin_position,
    digital_io__level_t         level
);

/**************************************************************************//**
 * \fn void digital_io__toggle_pin_level(
 * digital_io__pin_position_t   pin_position)
 *
 * \brief Toggle the level of a pin.
 *
 * \param   pin_position    pin position to toggle level
 ******************************************************************************/

void
digital_io__toggle_pin_level
(
    digital_io__pin_position_t  pin_position
);

/**************************************************************************//**
 * \fn void digital_io__configure_port(
 * digital_io__port_t       port,
 * digital_io__direction_t  direction)
 *
 * \brief Configure a port.
 *
 * \param   port        port to configure
 * \param   direction   port direction to configure
 ******************************************************************************/

void
digital_io__configure_port
(
    digital_io__port_t      port,
    digital_io__direction_t direction
);

/**************************************************************************//**
 * \fn uint8_t digital_io__get_port_value(digital_io__port_t port)
 *
 * \brief Get the value of a port.
 *
 * \param   port    port to get value
 *
 * \return Port value
 ******************************************************************************/

digital_io__port_value_t
digital_io__get_port_value
(
    digital_io__port_t  port
);

/**************************************************************************//**
 * \fn void digital_io__set_port_value(
 * digital_io__port_t       port,
 * digital_io__port_value_t value)
 *
 * \brief Set the value of a port.
 *
 * \param port  port to set value
 * \param value port value to set
 ******************************************************************************/

void
digital_io__set_port_value
(
    digital_io__port_t          port,
    digital_io__port_value_t    value
);

#ifdef _cplusplus
}
#endif

#endif /* H__IDREAMMICRO__DIGITAL_IO__H */