Subversion Repositories idreammicro-avr

Rev

Blame | Last modification | View Log | Download | RSS feed

/**************************************************************************//**
 * \brief MAX7219 library
 * \author Copyright (C) 2011  Julien Le Sech - www.idreammicro.com
 * \version 1.0
 * \date 20110908
 *
 * 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 max7219.h
 ******************************************************************************/

 
#ifndef H__IDREAMMICRO__MAX7219__H
#define H__IDREAMMICRO__MAX7219__H

#ifdef _cplusplus
extern "C"{
#endif

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


#include <stdbool.h>

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


/**************************************************************************//**
 * \enum max7219__decode_modes
 * \typedef max7219__decode_mode_t
 ******************************************************************************/

typedef enum max7219__decode_modes
{
    max7219__decode_mode__none          = 0x00,
    max7219__decode_mode__digit_0       = 0x01,
    max7219__decode_mode__digit_1       = 0x02,
    max7219__decode_mode__digit_2       = 0x04,
    max7219__decode_mode__digit_3       = 0x08,
    max7219__decode_mode__digit_4       = 0x10,
    max7219__decode_mode__digit_5       = 0x20,
    max7219__decode_mode__digit_6       = 0x40,
    max7219__decode_mode__digit_7       = 0x80,
    max7219__decode_mode__all_digits    = 0xFF
} max7219__decode_mode_t;

/**************************************************************************//**
 * \enum max7219__intensities
 * \typedef max7219__intensity_t
 ******************************************************************************/

typedef enum max7219__intensities
{
    max7219__intensity__level_0     = 0x00,
    max7219__intensity__level_1     = 0x01,
    max7219__intensity__level_2     = 0x02,
    max7219__intensity__level_3     = 0x03,
    max7219__intensity__level_4     = 0x04,
    max7219__intensity__level_5     = 0x05,
    max7219__intensity__level_6     = 0x06,
    max7219__intensity__level_7     = 0x07,
    max7219__intensity__level_8     = 0x08,
    max7219__intensity__level_9     = 0x09,
    max7219__intensity__level_10    = 0x0A,
    max7219__intensity__level_11    = 0x0B,
    max7219__intensity__level_12    = 0x0C,
    max7219__intensity__level_13    = 0x0D,
    max7219__intensity__level_14    = 0x0E,
    max7219__intensity__level_15    = 0x0F
} max7219__intensity_t;

/**************************************************************************//**
 * \enum max7219__scan_limits
 * \typedef max7219__scan_limit_t
 ******************************************************************************/

typedef enum max7219__scan_limits
{  
    max7219__scan_limit__digit_0        = 0x00,
    max7219__scan_limit__digit_0_to_1   = 0x01,
    max7219__scan_limit__digit_0_to_2   = 0x02,
    max7219__scan_limit__digit_0_to_3   = 0x03,
    max7219__scan_limit__digit_0_to_4   = 0x04,
    max7219__scan_limit__digit_0_to_5   = 0x05,
    max7219__scan_limit__digit_0_to_6   = 0x06,
    max7219__scan_limit__digit_0_to_7   = 0x07
} max7219__scan_limit_t;

/**************************************************************************//**
 * \enum max7219__shutdown_modes
 * \typedef max7219__shutdown_mode_t
 ******************************************************************************/

typedef enum max7219__shutdown_modes
{
    max7219__shutdown_mode__shutdown            = 0x00,
    max7219__shutdown_mode__normal_operation    = 0x01
} max7219__shutdown_mode_t;

/**************************************************************************//**
 * \enum max7219__display_test_modes
 * \typedef max7219__display_test_mode_t
 ******************************************************************************/

typedef enum max7219__display_test_modes
{
    max7219__display_test_mode__normal_operation    = 0x00,
    max7219__display_test_mode__test_mode           = 0x01
} max7219__display_test_mode_t;

/**************************************************************************//**
 * \enum max7219__digits
 * \typedef max7219__digit_t
 ******************************************************************************/

typedef enum max7219__digits
{
    max7219__digit__0   = 0x01,
    max7219__digit__1   = 0x02,
    max7219__digit__2   = 0x03,
    max7219__digit__3   = 0x04,
    max7219__digit__4   = 0x05,
    max7219__digit__5   = 0x06,
    max7219__digit__6   = 0x07,
    max7219__digit__7   = 0x08
} max7219__digit_t;

/**************************************************************************//**
 * \enum max7219__characters
 * \typedef max7219__character_t
 ******************************************************************************/

typedef enum max7219__characters
{
    max7219__character__zero    = 0x00,
    max7219__character__one     = 0x01,
    max7219__character__two     = 0x02,
    max7219__character__three   = 0x03,
    max7219__character__four    = 0x04,
    max7219__character__five    = 0x05,
    max7219__character__six     = 0x06,
    max7219__character__seven   = 0x07,
    max7219__character__eight   = 0x08,
    max7219__character__nine    = 0x09,
    max7219__character__dash    = 0x0A,
    max7219__character__e       = 0x0B,
    max7219__character__h       = 0x0C,
    max7219__character__l       = 0x0D,
    max7219__character__p       = 0x0E,
    max7219__character__blank   = 0x0F
} max7219__character_t;

/**************************************************************************//**
 * \enum max7219__segments
 * \typedef max7219__segment_t
 ******************************************************************************/

typedef enum max7219__segments
{
    max7219__segment__DP    = 0x80,
    max7219__segment__A     = 0x40,
    max7219__segment__B     = 0x20,
    max7219__segment__C     = 0x10,
    max7219__segment__D     = 0x08,
    max7219__segment__E     = 0x04,
    max7219__segment__F     = 0x02,
    max7219__segment__G     = 0x01
} max7219__segment_t;

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


/**************************************************************************//**
 * \fn void max7219__initialize(void)
 *
 * \brief Initialize SPI to drive MAX7219.
 ******************************************************************************/

void
max7219__initialize
(
    void
);    

/**************************************************************************//**
 * \fn void max7219__set_decode_mode(max7219__decode_mode_t mode)
 *
 * \brief Set MAX7219 decode mode.
 *
 * \param       mode    Decode mode to set.
 ******************************************************************************/

void
max7219__set_decode_mode
(
    max7219__decode_mode_t  mode
);

/**************************************************************************//**
 * \fn void max7219__set_intensity(max7219__intensity_t intensity)
 *
 * \brief Set MAX7219 intensity.
 *
 * \param       itensity        Intensity to set.
 ******************************************************************************/

void
max7219__set_intensity
(
    max7219__intensity_t    intensity
);

/**************************************************************************//**
 * \fn void max7219__set_scan_limit(max7219__scan_limit_t limit)
 *
 * \brief Set MAX7219 scan limit.
 *
 * \param       limit   Scan limit to set.
 ******************************************************************************/

void
max7219__set_scan_limit
(
    max7219__scan_limit_t   limit
);

/**************************************************************************//**
 * \fn void max7219__set_shutdown_mode(max7219__shutdown_mode_t mode)
 *
 * \brief Set MAX7219 shutdown mode.
 *
 * \param       mode    Shutdown mode to set.
 ******************************************************************************/

void
max7219__set_shutdown_mode
(
    max7219__shutdown_mode_t    mode
);

/**************************************************************************//**
 * \fn void max7219__set_display_test_mode(max7219__display_test_mode_t mode)
 *
 * \brief Set MAX7219 display test mode.
 *
 * \param       mode    Display test mode to set.
 *****************************************************************************/

void
max7219__set_display_test_mode
(
    max7219__display_test_mode_t    mode
);

/**************************************************************************//**
 * \fn void max7219__write_char_on_digit(
 * max7219__digit_t     digit,
 * max7219__character_t character,
 * bool                 decimal_point)
 *
 * \brief Write character on digit.
 *
 * \param       digit               Digit to write.
 * \param       character           Character to write.
 * \param   decimal_point   Display decimal point.
 ******************************************************************************/

void
max7219__write_char_on_digit
(
    max7219__digit_t        digit,
    max7219__character_t    character,
    bool                    decimal_point
);

/**************************************************************************//**
 * \fn void max7219__write_segments_on_digit(
 * max7219__digit_t     digit,
 * max7219__segment_t   segments)
 *
 * \brief Set segment(s) on digit.
 *
 * \param       digit   Digit to write.
 * \param       segment Segment(s) to set.
 ******************************************************************************/

void
max7219__write_segments_on_digit
(
    max7219__digit_t    digit,
    max7219__segment_t  segment
);

#ifdef _cplusplus
}
#endif

#endif /* H__IDREAMMICRO__MAX7219__H */