Subversion Repositories idreammicro-avr

Compare Revisions

Ignore whitespace Rev 1 → Rev 2

/trunk/build_system/env_arduino_uno.py
0,0 → 1,19
# Import environment set for AVR-GCC.
Import('env_avr')
 
# Create target environment by cloning AVR environment.
env_target = env_avr.Clone()
 
# Declare some variables about microcontroller.
# Microcontroller type.
DEVICE = 'atmega328p'
# Microcontroller frequency.
CPU_FREQUENCY = '16000000UL' # Hz
 
# Set environment for an Atmel AVR ATmega328p microcontroller.
env_target.Append(CCFLAGS = '-mmcu=' + DEVICE)
env_target.Append(LINKFLAGS = '-mmcu=' + DEVICE)
env_target.Append(CPPDEFINES = 'F_CPU=' + CPU_FREQUENCY)
 
# Export environment set for target.
Export('env_target', 'DEVICE')
/trunk/build_system/env_arduino_mega2560.py
0,0 → 1,19
# Import environment set for AVR-GCC.
Import('env_avr')
 
# Create target environment by cloning AVR environment.
env_target = env_avr.Clone()
 
# Declare some variables about microcontroller.
# Microcontroller type.
DEVICE = 'atmega2560'
# Microcontroller frequency.
CPU_FREQUENCY = '16000000UL' # Hz
 
# Set environment for an Atmel AVR Atmega 2560 microcontroller.
env_target.Append(CCFLAGS = '-mmcu=' + DEVICE)
env_target.Append(LINKFLAGS = '-mmcu=' + DEVICE)
env_target.Append(CPPDEFINES = 'F_CPU=' + CPU_FREQUENCY)
 
# Export environment set for target.
Export('env_target', 'DEVICE')
/trunk/build_system/env_avr.py
0,0 → 1,14
# Create and initialize the environment.
env_avr = Environment()
 
# Set environment for AVR-GCC.
env_avr['CC'] = 'avr-gcc'
env_avr['CPPPATH'] = '/usr/lib/avr/include'
env_avr['OBJCOPY'] = 'avr-objcopy'
env_avr['SIZE'] = 'avr-size'
env_avr['AR'] = 'avr-ar'
env_avr['RANLIB'] = 'avr-ranlib'
env_avr.Append(CCFLAGS = '-Os')
 
# Export environment set for AVR-GCC.
Export('env_avr')
/trunk/SConscript
0,0 → 1,39
# Import environment set for target.
Import('env_target', 'env_name', 'DEVICE')
 
# Set target name.
TARGET = 'helloworld'
 
# Set libraries to use.
libraries = [
'digital_io'
]
 
# Build libraries.
for library in libraries:
SConscript(
'#libraries/' + library + '/SConscript',
exports = { 'env_target' : env_target, 'env_name' : env_name },
duplicate = 0
)
 
# Set source file.
sources = 'helloworld.c'
 
# Build program.
env_target.Program(target = TARGET + '.elf', source = sources)
 
# Create hex binary file.
env_target.Command(
TARGET + '.hex',
TARGET + '.elf',
env_target['OBJCOPY'] + ' -O ihex $SOURCE $TARGET'
)
 
# Compute memory usage.
env_target.Command(
None,
TARGET + '.elf',
env_target['SIZE'] + ' -C --mcu=' + DEVICE + ' $SOURCE'
)
 
/trunk/SConstruct
0,0 → 1,32
# Set environment for AVR-GCC.
SConscript('#build_system/env_avr.py')
 
# Import environment set for AVR-GCC.
Import('env_avr')
 
# Append CPPPATH with the root path of libraries.
env_avr.Append(CPPPATH = [ '#libraries/' ])
 
# Define environments to use (one environment per target).
environments = [
'env_arduino_uno',
'env_arduino_mega2560'
]
 
# Browse environments.
for environment in environments:
# Set environment for target.
SConscript(
'#build_system/' + environment + '.py',
exports = 'env_avr'
)
# Import environment set for target.
Import('env_target')
# Build program.
SConscript(
'SConscript',
variant_dir = '#build/' + environment,
exports = { 'env_target' : env_target, 'env_name' : environment },
duplicate = 0
)
 
/trunk/libraries/useful/bits.h
0,0 → 1,67
/**************************************************************************//**
* \brief Bit manipulation library - API
* \author Copyright (C) 2011 Julien Le Sech - www.idreammicro.com
* \version 1.0
* \date 20110823
*
* 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 bits.h
******************************************************************************/
 
#ifndef H__IDREAMMICRO__USEFUL__BITS__H
#define H__IDREAMMICRO__USEFUL__BITS__H
 
#ifdef _cplusplus
extern "C"{
#endif
 
/******************************************************************************
* Public macro definitions.
******************************************************************************/
 
/**************************************************************************//**
* \def BIT__SET
* \brief Set a bit in a byte.
******************************************************************************/
#define BIT__SET(variable, bit) (variable |= (1 << bit))
 
/**************************************************************************//**
* \def BIT__RST
* \brief Reset a bit in a byte.
******************************************************************************/
#define BIT__RST(variable, bit) (variable &= ~(1 << bit))
 
/**************************************************************************//**
* \def BIT__TGL
* \brief Toggle a bit in a byte.
******************************************************************************/
#define BIT__TGL(variable, bit) (variable ^= (1 << bit))
 
/**************************************************************************//**
* \def BIT__TST
* \brief Test a bit in a byte.
******************************************************************************/
#define BIT__TST(variable, bit) (variable & (1 << bit))
 
#ifdef _cplusplus
}
#endif
 
#endif /* H__IDREAMMICRO__USEFUL__BITS__H */
 
/trunk/libraries/digital_io/test/digital_io__test.c
0,0 → 1,68
/**************************************************************************//**
* \brief Digital I/O library - Test program
* \author Copyright (C) 2011 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/
******************************************************************************/
 
/**************************************************************************//**
* \file digital_io__test.c
******************************************************************************/
 
/******************************************************************************
* Header file inclusions.
******************************************************************************/
 
#include "../digital_io.h"
 
#include <avr/io.h>
#include <util/delay.h>
 
/******************************************************************************
* Main function.
******************************************************************************/
 
/**************************************************************************//**
* \fn int main(void)
*
* \brief Main function.
******************************************************************************/
int
main
(
void
){
// Declare pin.
digital_io__pin_position_t pin = DIGITAL_IO__PORT_B | DIGITAL_IO__PIN_5;
// Configure pin as output.
digital_io__configure_pin(pin, DIGITAL_IO__DIRECTION__OUTPUT);
 
while (1)
{
// Set pin level.
digital_io__set_pin_level(pin, DIGITAL_IO__LEVEL__HIGH);
_delay_ms(1000);
 
// Reset pin level.
digital_io__set_pin_level(pin, DIGITAL_IO__LEVEL__LOW);
_delay_ms(1000);
}
 
return 0;
}
/trunk/libraries/digital_io/test/SConscript
0,0 → 1,28
# Import environment set for target.
Import('env_target', 'env_name', 'DEVICE')
 
# Set target name.
TARGET = 'digital_io__test'
 
# Set source file.
sources = [
'digital_io__test.c'
]
 
# Build program.
env_target.Program(target = TARGET + '.elf', source = sources)
 
# Create hex binary file.
env_target.Command(
TARGET + '.hex',
TARGET + '.elf',
env_target['OBJCOPY'] + ' -O ihex $SOURCE $TARGET'
)
 
# Compute memory usage.
env_target.Command(
None,
TARGET + '.elf',
env_target['SIZE'] + ' -C --mcu=' + DEVICE + ' $SOURCE'
)
 
/trunk/libraries/digital_io/.sconsign.dblite
/trunk/libraries/digital_io/.sconsign.dblite
Modification de propriétés sur libraries/digital_io/.sconsign.dblite
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
/trunk/libraries/digital_io/demo/.sconsign.dblite
/trunk/libraries/digital_io/demo/.sconsign.dblite
Modification de propriétés sur libraries/digital_io/demo/.sconsign.dblite
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
/trunk/libraries/digital_io/demo/SConscript
0,0 → 1,28
# Import environment set for target.
Import('env_target', 'env_name', 'DEVICE')
 
# Set target name.
TARGET = 'digital_io__demo'
 
# Set source file.
sources = [
'digital_io__demo.c'
]
 
# Build program.
env_target.Program(target = TARGET + '.elf', source = sources)
 
# Create hex binary file.
env_target.Command(
TARGET + '.hex',
TARGET + '.elf',
env_target['OBJCOPY'] + ' -O ihex $SOURCE $TARGET'
)
 
# Compute memory usage.
env_target.Command(
None,
TARGET + '.elf',
env_target['SIZE'] + ' -C --mcu=' + DEVICE + ' $SOURCE'
)
 
/trunk/libraries/digital_io/demo/digital_io__demo.c
0,0 → 1,68
/**************************************************************************//**
* \brief Digital I/O library - Demonstration program
* \author Copyright (C) 2011 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/
******************************************************************************/
 
/**************************************************************************//**
* \file digital_io__demo.c
******************************************************************************/
 
/******************************************************************************
* Header file inclusions.
******************************************************************************/
 
#include "../digital_io.h"
 
#include <avr/io.h>
#include <util/delay.h>
 
/******************************************************************************
* Main function.
******************************************************************************/
 
/**************************************************************************//**
* \fn int main(void)
*
* \brief Main function.
******************************************************************************/
int
main
(
void
){
// Declare pin.
digital_io__pin_position_t pin = DIGITAL_IO__PORT_B | DIGITAL_IO__PIN_5;
// Configure pin as output.
digital_io__configure_pin(pin, DIGITAL_IO__DIRECTION__OUTPUT);
 
while (1)
{
// Set pin level.
digital_io__set_pin_level(pin, DIGITAL_IO__LEVEL__HIGH);
_delay_ms(1000);
 
// Reset pin level.
digital_io__set_pin_level(pin, DIGITAL_IO__LEVEL__LOW);
_delay_ms(1000);
}
 
return 0;
}
/trunk/libraries/digital_io/src/digital_io.c
0,0 → 1,355
/**************************************************************************//**
* \brief Digital I/O library - Implementation
* \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/
******************************************************************************/
 
/**************************************************************************//**
* \file digital_io.c
******************************************************************************/
 
/******************************************************************************
* Header file inclusions.
******************************************************************************/
 
#include <digital_io/digital_io.h>
#include <useful/bits.h>
 
#include <avr/io.h>
 
#include <stdint.h>
 
/******************************************************************************
* Private macro definitions.
******************************************************************************/
 
/**************************************************************************//**
* \def DIGITAL_IO__PORT_DIRECTION__INPUT
* \brief
******************************************************************************/
#define DIGITAL_IO__PORT_DIRECTION__INPUT 0x00
 
/**************************************************************************//**
* \def DIGITAL_IO__PORT_DIRECTION__OUTPUT
* \brief
******************************************************************************/
#define DIGITAL_IO__PORT_DIRECTION__OUTPUT 0xFF
 
/**************************************************************************//**
* \def digital_io__get_index(port)
* \brief
******************************************************************************/
#define digital_io__get_index(port) ((port) >> 4)
/******************************************************************************
* Private types.
******************************************************************************/
 
/**************************************************************************//**
* \typedef digital_io__register_t
* \brief Digital IO registers (input, output, direction).
******************************************************************************/
typedef struct digital_io__register
{
const uint8_t volatile * const p_input;
uint8_t volatile * const p_output;
uint8_t volatile * const p_direction;
} digital_io__register_t;
 
/******************************************************************************
* Private variable definitions.
******************************************************************************/
 
static const digital_io__register_t ports[] =
{
#ifdef PORTA
[digital_io__get_index(DIGITAL_IO__PORT_A)]
{ // PORT A.
.p_input = &PINA,
.p_output = &PORTA,
.p_direction = &DDRA
},
#endif
#ifdef PORTB
[digital_io__get_index(DIGITAL_IO__PORT_B)]
{ // PORT B.
.p_input = &PINB,
.p_output = &PORTB,
.p_direction = &DDRB
},
#endif
#ifdef PORTC
[digital_io__get_index(DIGITAL_IO__PORT_C)]
{ // PORT C.
.p_input = &PINC,
.p_output = &PORTC,
.p_direction = &DDRC
},
#endif
#ifdef PORTD
[digital_io__get_index(DIGITAL_IO__PORT_D)]
{ // PORT D.
.p_input = &PIND,
.p_output = &PORTD,
.p_direction = &DDRD
},
#endif
#ifdef PORTE
[digital_io__get_index(DIGITAL_IO__PORT_E)]
{ // PORT E.
.p_input = &PINE,
.p_output = &PORTE,
.p_direction = &DDRE
},
#endif
#ifdef PORTF
[digital_io__get_index(DIGITAL_IO__PORT_F)]
{ // PORT F.
.p_input = &PINF,
.p_output = &PORTF,
.p_direction = &DDRF
},
#endif
#ifdef PORTG
[digital_io__get_index(DIGITAL_IO__PORT_G)]
{ // PORT G.
.p_input = &PING,
.p_output = &PORTG,
.p_direction = &DDRG
},
#endif
#ifdef PORTH
[digital_io__get_index(DIGITAL_IO__PORT_H)]
{ // PORT H.
.p_input = &PINH,
.p_output = &PORTH,
.p_direction = &DDRH
},
#endif
#ifdef PORTJ
[digital_io__get_index(DIGITAL_IO__PORT_J)]
{ // PORT J.
.p_input = &PINJ,
.p_output = &PORTJ,
.p_direction = &DDRJ
},
#endif
#ifdef PORTK
[digital_io__get_index(DIGITAL_IO__PORT_K)] =
{ // PORT K.
.p_input = &PINK,
.p_output = &PORTK,
.p_direction = &DDRK
},
#endif
#ifdef PORTL
[digital_io__get_index(DIGITAL_IO__PORT_L)]
{ // PORT L.
.p_input = &PINL,
.p_output = &PORTL,
.p_direction = &DDRL
}
#endif
};
 
/******************************************************************************
* Public function definitions.
******************************************************************************/
 
/**************************************************************************//**
* \fn void digital_io__configure_pin(
* digital_io__pin_position_t pin_position,
* digital_io__direction_t direction)
*
* \brief Configure a pin.
*
* \param[in] pin_position pin position to configure
* \param direction pin direction
******************************************************************************/
void
digital_io__configure_pin
(
digital_io__pin_position_t pin_position,
digital_io__direction_t direction
){
// Alias.
digital_io__register_t const* p_register =
&(ports[digital_io__get_port(pin_position)]);
 
if (DIGITAL_IO__DIRECTION__INPUT == direction)
{
BIT__RST(*(p_register->p_direction), digital_io__get_pin(pin_position));
}
else
{
BIT__SET(*(p_register->p_direction), digital_io__get_pin(pin_position));
}
}
 
/**************************************************************************//**
* \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
){
// Alias.
digital_io__register_t const* p_register =
&(ports[digital_io__get_port(pin_position)]);
 
digital_io__level_t level =
BIT__TST(*(p_register->p_input), digital_io__get_pin(pin_position)) ?
DIGITAL_IO__LEVEL__HIGH : DIGITAL_IO__LEVEL__LOW;
 
return level;
}
 
/**************************************************************************//**
* \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[in] 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
){
// Alias.
digital_io__register_t const* p_register =
&(ports[digital_io__get_port(pin_position)]);
 
if (DIGITAL_IO__LEVEL__LOW == level)
{
BIT__RST(*(p_register->p_output), digital_io__get_pin(pin_position));
}
else
{
BIT__SET(*(p_register->p_output), digital_io__get_pin(pin_position));
}
}
 
/**************************************************************************//**
* \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
){
// Alias.
digital_io__register_t const* p_register =
&(ports[digital_io__get_port(pin_position)]);
 
BIT__TGL(*(p_register->p_output), digital_io__get_pin(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
){
// Alias.
digital_io__register_t const* p_register =
&(ports[digital_io__get_port(port)]);
 
if (DIGITAL_IO__DIRECTION__INPUT == direction)
{
*(p_register->p_direction) = DIGITAL_IO__PORT_DIRECTION__INPUT;
}
else
{
*(p_register->p_direction) = DIGITAL_IO__PORT_DIRECTION__OUTPUT;
}
}
 
/**************************************************************************//**
* \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
){
// Alias.
digital_io__register_t const* p_register =
&(ports[digital_io__get_port(port)]);
 
uint8_t value = *(p_register->p_input);
 
return value;
}
 
/**************************************************************************//**
* \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
){
// Alias.
digital_io__register_t const* p_register =
&(ports[digital_io__get_port(port)]);
 
*(p_register->p_output) = value;
}
/trunk/libraries/digital_io/src/SConscript
0,0 → 1,18
# Import environment set for target.
Import('env_target', 'env_name', 'DEVICE')
 
# Define target name.
TARGET = 'digital_io'
 
# Define source files.
sources = [
'digital_io.c'
]
 
# Build static library.
env_target.StaticLibrary(target = TARGET, source = sources)
 
# Append LIBPATH and LIBS.
env_target.Append(LIBPATH = [ '#build/' + env_name + '/libraries/' + TARGET + '/src'])
env_target.Append(LIBS = [ TARGET ])
 
/trunk/libraries/digital_io/SConstruct
0,0 → 1,54
# Create and initialize the environment.
env = Environment()
 
# Set environment for AVR-GCC.
env['CC'] = 'avr-gcc'
env['CPPPATH'] = '/usr/lib/avr/include'
env['OBJCOPY'] = 'avr-objcopy'
env['SIZE'] = 'avr-size'
env['AR'] = 'avr-ar'
env['RANLIB'] = 'avr-ranlib'
env.Append(CCFLAGS = '-Os')
 
# Declare some variables about microcontroller.
# Microcontroller type.
DEVICE = 'atmega328p'
# Microcontroller frequency.
CPU_FREQUENCY = '16000000UL' # Hz
 
# Set environment for an Atmel AVR ATmega328p microcontroller.
env.Append(CCFLAGS = '-mmcu=' + DEVICE)
env.Append(LINKFLAGS = '-mmcu=' + DEVICE)
env.Append(CPPDEFINES = 'F_CPU=' + CPU_FREQUENCY)
 
# Append CPPPATH.
env.Append(CPPPATH = [ '#../' ])
 
# Build library.
SConscript(
'src/SConscript',
variant_dir = '#build/lib/',
exports = { 'env_target' : env, 'env_name' : 'env_arduino_uno', 'DEVICE' : DEVICE },
duplicate = 0
)
 
# Append LIBPATH and LIBS.
env.Append(LIBPATH = [ '#build/lib/'])
env.Append(LIBS = [ 'digital_io' ])
 
# Build demonstration program.
SConscript(
'demo/SConscript',
variant_dir = '#build/demo/',
exports = { 'env_target' : env, 'env_name' : 'env_arduino_uno', 'DEVICE' : DEVICE },
duplicate = 0
)
 
# Build test program.
SConscript(
'test/SConscript',
variant_dir = '#build/test/',
exports = { 'env_target' : env, 'env_name' : 'env_arduino_uno', 'DEVICE' : DEVICE },
duplicate = 0
)
 
/trunk/libraries/digital_io/SConscript
0,0 → 1,16
# Import environment set for target.
Import('env_target', 'env_name', 'DEVICE')
 
# Define directories to process.
directories = [
'src/'
]
 
# Process directories.
for directory in directories:
SConscript(
directory + 'SConscript',
variant_dir = '#build/' + env_name + '/libraries/digital_io/' + directory,
exports = { 'env_target' : env_target, 'env_name' : env_name },
duplicate = 0
)
/trunk/libraries/digital_io/digital_io.h
0,0 → 1,354
/**************************************************************************//**
* \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
******************************************************************************/
typedef uint8_t digital_io__port_t;
 
/**************************************************************************//**
* \typedef digital_io__pin_t
* \brief
******************************************************************************/
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 */
 
/trunk/helloworld.c
0,0 → 1,46
/**************************************************************************//**
* \file helloworld.c
******************************************************************************/
 
/******************************************************************************
* Header file inclusions.
******************************************************************************/
 
#include <digital_io/digital_io.h>
 
#include <avr/io.h>
#include <util/delay.h>
 
/******************************************************************************
* Public function definitions.
******************************************************************************/
 
/**************************************************************************//**
* \fn int main(void)
*
* \brief Main function.
******************************************************************************/
int
main
(
void
){
// Declare pin.
digital_io__pin_position_t pin = DIGITAL_IO__PORT_B | DIGITAL_IO__PIN_5;
// Configure pin as output.
digital_io__configure_pin(pin, DIGITAL_IO__DIRECTION__OUTPUT);
 
while (1)
{
// Set pin level.
digital_io__set_pin_level(pin, DIGITAL_IO__LEVEL__HIGH);
_delay_ms(1000);
 
// Reset pin level.
digital_io__set_pin_level(pin, DIGITAL_IO__LEVEL__LOW);
_delay_ms(1000);
}
 
return 0;
}