<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Procyon AVRlib: rprintf.h Source File</title>
<link href="dox.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.2 -->
<div class="qindex"><a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related Pages</a></div>
<h1>rprintf.h</h1><a href="rprintf_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file rprintf.h \brief printf routine and associated routines. */</span>
00002 <span class="comment">//****************************************************************************</span>
00003 <span class="comment">//</span>
00004 <span class="comment">// File Name : 'rprintf.h'</span>
00005 <span class="comment">// Title : printf routine and associated routines</span>
00006 <span class="comment">// Author : Pascal Stang - Copyright (C) 2000-2002</span>
00007 <span class="comment">// Created : 2000.12.26</span>
00008 <span class="comment">// Revised : 2003.5.1</span>
00009 <span class="comment">// Version : 1.0</span>
00010 <span class="comment">// Target MCU : Atmel AVR series and other targets</span>
00011 <span class="comment">// Editor Tabs : 4</span>
00012 <span class="comment">//</span>
00013 <span class="comment">// NOTE: This code is currently below version 1.0, and therefore is considered</span>
00014 <span class="comment">// to be lacking in some functionality or documentation, or may not be fully</span>
00015 <span class="comment">// tested. Nonetheless, you can expect most functions to work.</span>
00016 <span class="comment">//</span>
00017 <span class="comment">// This code is distributed under the GNU Public License</span>
00018 <span class="comment">// which can be found at http://www.gnu.org/licenses/gpl.txt</span>
00019 <span class="comment">//</span><span class="comment"></span>
00020 <span class="comment">/// \ingroup general</span>
00021 <span class="comment">/// \defgroup rprintf printf() Function Library (rprintf.c)</span>
00022 <span class="comment">/// \code #include "rprintf.h" \endcode</span>
00023 <span class="comment">/// \par Overview</span>
00024 <span class="comment">/// The rprintf function library provides a simplified (reduced) version of</span>
00025 <span class="comment">/// the common C printf() function. See the code files for details about</span>
00026 <span class="comment">/// which printf features are supported. Also in this library are a</span>
00027 <span class="comment">/// variety of functions for fast printing of certain common data types</span>
00028 <span class="comment">/// (variable types). Functions include print string from RAM, print</span>
00029 <span class="comment">/// string from ROM, print string snippet, print hex byte/short/long, and</span>
00030 <span class="comment">/// a custom-formatted number print, as well as an optional floating-point</span>
00031 <span class="comment">/// print routine.</span>
00032 <span class="comment">///</span>
00033 <span class="comment">/// \note All output from the rprintf library can be directed to any device</span>
00034 <span class="comment">/// or software which accepts characters. This means that rprintf output</span>
00035 <span class="comment">/// can be sent to the UART (serial port) or can be used with the LCD</span>
00036 <span class="comment">/// display libraries to print formatted text on the screen.</span>
00037 <span class="comment"></span><span class="comment">//</span>
00038 <span class="comment">//****************************************************************************</span><span class="comment"></span>
00039 <span class="comment">//@{</span>
00040 <span class="comment"></span>
00041 <span class="preprocessor">#ifndef RPRINTF_H</span>
00042 <span class="preprocessor"></span><span class="preprocessor">#define RPRINTF_H</span>
00043 <span class="preprocessor"></span>
00044 <span class="comment">// needed for use of PSTR below</span>
00045 <span class="preprocessor">#include <avr/pgmspace.h></span>
00046
00047 <span class="comment">// configuration</span>
00048 <span class="comment">// defining RPRINTF_SIMPLE will compile a smaller, simpler, and faster printf() function</span>
00049 <span class="comment">// defining RPRINTF_COMPLEX will compile a larger, more capable, and slower printf() function</span>
00050 <span class="preprocessor">#ifndef RPRINTF_COMPLEX</span>
00051 <span class="preprocessor"></span><span class="preprocessor"> #define RPRINTF_SIMPLE</span>
00052 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
00053 <span class="preprocessor"></span>
00054 <span class="comment">// Define RPRINTF_FLOAT to enable the floating-point printf function: rprintfFloat()</span>
00055 <span class="comment">// (adds +4600bytes or 2.2Kwords of code)</span>
00056
00057 <span class="comment">// defines/constants</span>
00058 <span class="preprocessor">#define STRING_IN_RAM 0</span>
00059 <span class="preprocessor"></span><span class="preprocessor">#define STRING_IN_ROM 1</span>
00060 <span class="preprocessor"></span>
00061 <span class="comment">// make a putchar for those that are used to using it</span>
00062 <span class="comment">//#define putchar(c) rprintfChar(c);</span>
00063
00064 <span class="comment">// functions</span>
00065 <span class="comment"></span>
00066 <span class="comment">//! Initializes the rprintf library for an output stream.</span>
00067 <span class="comment">/// You must call this initializer once before using any other rprintf function.</span>
00068 <span class="comment">/// The argument must be a character stream output function.</span>
00069 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__rprintf.html#ga0">rprintfInit</a>(<span class="keywordtype">void</span> (*putchar_func)(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c));
00070 <span class="comment"></span>
00071 <span class="comment">//! prints a single character to the current output device</span>
00072 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c);
00073 <span class="comment"></span>
00074 <span class="comment">//! prints a null-terminated string stored in RAM</span>
00075 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__rprintf.html#ga2">rprintfStr</a>(<span class="keywordtype">char</span> str[]);
00076 <span class="comment"></span>
00077 <span class="comment">//! Prints a section of a string stored in RAM.</span>
00078 <span class="comment">/// Begins printing at position indicated by <start>,</span>
00079 <span class="comment">/// and prints number of characters indicated by <len>.</span>
00080 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__rprintf.html#ga3">rprintfStrLen</a>(<span class="keywordtype">char</span> str[], <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> start, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> len);
00081 <span class="comment"></span>
00082 <span class="comment">//! prints a string stored in program rom</span>
00083 <span class="comment">/// \note This function does not actually store your string in</span>
00084 <span class="comment">/// program rom, but merely reads it assuming you stored it properly.</span>
00085 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__rprintf.html#ga4">rprintfProgStr</a>(<span class="keyword">const</span> prog_char str[]);
00086 <span class="comment"></span>
00087 <span class="comment">//! Using the function rprintfProgStrM(...) automatically causes </span>
00088 <span class="comment">/// your string to be stored in ROM, thereby not wasting precious RAM.</span>
00089 <span class="comment">/// Example usage:</span>
00090 <span class="comment">/// \code</span>
00091 <span class="comment">/// rprintfProgStrM("Hello, this string is stored in program rom");</span>
00092 <span class="comment">/// \endcode</span>
<a name="l00093"></a><a class="code" href="group__rprintf.html#ga15">00093</a> <span class="comment"></span><span class="preprocessor">#define rprintfProgStrM(string) (rprintfProgStr(PSTR(string)))</span>
00094 <span class="preprocessor"></span><span class="comment"></span>
00095 <span class="comment">//! Prints a carriage-return and line-feed.</span>
00096 <span class="comment">/// Useful when printing to serial ports/terminals.</span>
00097 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__rprintf.html#ga5">rprintfCRLF</a>(<span class="keywordtype">void</span>);
00098
00099 <span class="comment">// Prints the number contained in "data" in hex format</span>
00100 <span class="comment">// u04,u08,u16,and u32 functions handle 4,8,16,or 32 bits respectively</span>
00101 <span class="keywordtype">void</span> <a class="code" href="group__rprintf.html#ga6">rprintfu04</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> data); <span class="comment">///< Print 4-bit hex number. Outputs a single hex character.</span>
00102 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__rprintf.html#ga7">rprintfu08</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> data); <span class="comment">///< Print 8-bit hex number. Outputs two hex characters.</span>
00103 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__rprintf.html#ga8">rprintfu16</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> data); <span class="comment">///< Print 16-bit hex number. Outputs four hex characters.</span>
00104 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__rprintf.html#ga9">rprintfu32</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> data); <span class="comment">///< Print 32-bit hex number. Outputs eight hex characters.</span>
00105 <span class="comment"></span><span class="comment"></span>
00106 <span class="comment">//! A flexible integer-number printing routine.</span>
00107 <span class="comment">/// Print the number "n" in the given "base", using exactly "numDigits".</span>
00108 <span class="comment">/// Print +/- if signed flag "isSigned" is TRUE.</span>
00109 <span class="comment">/// The character specified in "padchar" will be used to pad extra characters.</span>
00110 <span class="comment">///</span>
00111 <span class="comment">/// Examples:</span>
00112 <span class="comment">/// \code</span>
00113 <span class="comment">/// uartPrintfNum(10, 6, TRUE, ' ', 1234); --> " +1234"</span>
00114 <span class="comment">/// uartPrintfNum(10, 6, FALSE, '0', 1234); --> "001234"</span>
00115 <span class="comment">/// uartPrintfNum(16, 6, FALSE, '.', 0x5AA5); --> "..5AA5"</span>
00116 <span class="comment">/// \endcode</span>
00117 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__rprintf.html#ga10">rprintfNum</a>(<span class="keywordtype">char</span> base, <span class="keywordtype">char</span> numDigits, <span class="keywordtype">char</span> isSigned, <span class="keywordtype">char</span> padchar, <span class="keywordtype">long</span> n);
00118
00119 <span class="preprocessor">#ifdef RPRINTF_FLOAT</span>
00120 <span class="preprocessor"></span><span class="comment"> //! floating-point print routine</span>
00121 <span class="comment"></span> <span class="keywordtype">void</span> rprintfFloat(<span class="keywordtype">char</span> numDigits, <span class="keywordtype">double</span> x);
00122 <span class="preprocessor">#endif</span>
00123 <span class="preprocessor"></span>
00124 <span class="comment">// NOTE: Below you'll see the function prototypes of rprintf1RamRom and </span>
00125 <span class="comment">// rprintf2RamRom. rprintf1RamRom and rprintf2RamRom are both reduced versions</span>
00126 <span class="comment">// of the regular C printf() command. However, they are modified to be able</span>
00127 <span class="comment">// to read their text/format strings from RAM or ROM in the Atmel microprocessors.</span>
00128 <span class="comment">// Unless you really intend to, do not use the "RamRom" versions of the functions</span>
00129 <span class="comment">// directly. Instead use the #defined function versions:</span>
00130 <span class="comment">//</span>
00131 <span class="comment">// printfx("text/format",args) ...to keep your text/format string stored in RAM</span>
00132 <span class="comment">// - or -</span>
00133 <span class="comment">// printfxROM("text/format",args) ...to keep your text/format string stored in ROM</span>
00134 <span class="comment">//</span>
00135 <span class="comment">// where x is either 1 or 2 for the simple or more powerful version of printf()</span>
00136 <span class="comment">//</span>
00137 <span class="comment">// Since there is much more ROM than RAM available in the Atmel microprocessors,</span>
00138 <span class="comment">// and nearly all text/format strings are constant (never change in the course</span>
00139 <span class="comment">// of the program), you should try to use the ROM printf version exclusively.</span>
00140 <span class="comment">// This will ensure you leave as much RAM as possible for program variables and</span>
00141 <span class="comment">// data.</span>
00142 <span class="comment"></span>
00143 <span class="comment">//! \fn int rprintf(const char *format, ...);</span>
00144 <span class="comment">/// A reduced substitute for the usual C printf() function.</span>
00145 <span class="comment">/// This function actually points to either rprintf1RamRom or rprintf2RamRom</span>
00146 <span class="comment">/// depending on the user's selection. Rprintf1 is a simple small fast print</span>
00147 <span class="comment">/// routine while rprintf2 is larger and slower but more capable. To choose</span>
00148 <span class="comment">/// the routine you would like to use, define either RPRINTF_SIMPLE or</span>
00149 <span class="comment">/// RPRINTF_COMPLEX in global.h.</span>
00150 <span class="comment"></span>
00151 <span class="preprocessor">#ifdef RPRINTF_SIMPLE</span><span class="comment"></span>
00152 <span class="comment"> //! A simple printf routine.</span>
00153 <span class="comment"> /// Called by rprintf() - does a simple printf (supports %d, %x, %c).</span>
00154 <span class="comment"> /// Supports:</span>
00155 <span class="comment"> /// - %d - decimal</span>
00156 <span class="comment"> /// - %x - hex</span>
00157 <span class="comment"> /// - %c - character</span>
00158 <span class="comment"></span> int rprintf1RamRom(unsigned char stringInRom, const char *format, ...);
00159 <span class="comment">// #defines for RAM or ROM operation</span>
00160 <span class="preprocessor"> #define rprintf1(format, args...) rprintf1RamRom(STRING_IN_ROM, PSTR(format), ## args)</span>
00161 <span class="preprocessor"></span><span class="preprocessor"> #define rprintf1RAM(format, args...) rprintf1RamRom(STRING_IN_RAM, format, ## args)</span>
00162 <span class="preprocessor"></span>
00163 <span class="comment">// *** Default rprintf(...) ***</span>
00164 <span class="comment">// this next line determines what the the basic rprintf() defaults to:</span>
00165 <span class="preprocessor"> #define rprintf(format, args...) rprintf1RamRom(STRING_IN_ROM, PSTR(format), ## args)</span>
00166 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
00167 <span class="preprocessor"></span>
00168 <span class="preprocessor">#ifdef RPRINTF_COMPLEX</span><span class="comment"></span>
00169 <span class="comment"> //! A more powerful printf routine.</span>
00170 <span class="comment"> /// Called by rprintf() - does a more powerful printf (supports %d, %u, %o, %x, %c, %s).</span>
00171 <span class="comment"> /// Supports:</span>
00172 <span class="comment"> /// - %d - decimal</span>
00173 <span class="comment"> /// - %u - unsigned decimal</span>
00174 <span class="comment"> /// - %o - octal</span>
00175 <span class="comment"> /// - %x - hex</span>
00176 <span class="comment"> /// - %c - character</span>
00177 <span class="comment"> /// - %s - strings</span>
00178 <span class="comment"> /// - and the width,precision,padding modifiers</span>
00179 <span class="comment"> /// \note This printf does not support floating point numbers.</span>
00180 <span class="comment"></span> int rprintf2RamRom(unsigned char stringInRom, const char *sfmt, ...);
00181 <span class="comment">// #defines for RAM or ROM operation</span>
00182 <span class="preprocessor"> #define rprintf2(format, args...) rprintf2RamRom(STRING_IN_ROM, format, ## args)</span>
00183 <span class="preprocessor"></span><span class="preprocessor"> #define rprintf2RAM(format, args...) rprintf2RamRom(STRING_IN_RAM, format, ## args)</span>
00184 <span class="preprocessor"></span>
00185 <span class="comment">// *** Default rprintf(...) ***</span>
00186 <span class="comment">// this next line determines what the the basic rprintf() defaults to:</span>
00187 <span class="preprocessor"> #define rprintf(format, args...) rprintf2RamRom(STRING_IN_ROM, PSTR(format), ## args)</span>
00188 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
00189 <span class="preprocessor"></span>
00190 <span class="preprocessor">#endif</span>
00191 <span class="preprocessor"></span><span class="comment">//@}</span>
</span></pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:07 2006 for Procyon AVRlib by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address>
</body>
</html>
|