| Line No. | Rev | Author | Line |
|---|---|---|---|
| 1 | 6 | kaklik | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 2 | <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> |
||
| 3 | <title>Procyon AVRlib: rprintf.h Source File</title> |
||
| 4 | <link href="dox.css" rel="stylesheet" type="text/css"> |
||
| 5 | </head><body> |
||
| 6 | <!-- Generated by Doxygen 1.4.2 --> |
||
| 7 | <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> |
||
| 8 | <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> |
||
| 9 | 00002 <span class="comment">//****************************************************************************</span> |
||
| 10 | 00003 <span class="comment">//</span> |
||
| 11 | 00004 <span class="comment">// File Name : 'rprintf.h'</span> |
||
| 12 | 00005 <span class="comment">// Title : printf routine and associated routines</span> |
||
| 13 | 00006 <span class="comment">// Author : Pascal Stang - Copyright (C) 2000-2002</span> |
||
| 14 | 00007 <span class="comment">// Created : 2000.12.26</span> |
||
| 15 | 00008 <span class="comment">// Revised : 2003.5.1</span> |
||
| 16 | 00009 <span class="comment">// Version : 1.0</span> |
||
| 17 | 00010 <span class="comment">// Target MCU : Atmel AVR series and other targets</span> |
||
| 18 | 00011 <span class="comment">// Editor Tabs : 4</span> |
||
| 19 | 00012 <span class="comment">//</span> |
||
| 20 | 00013 <span class="comment">// NOTE: This code is currently below version 1.0, and therefore is considered</span> |
||
| 21 | 00014 <span class="comment">// to be lacking in some functionality or documentation, or may not be fully</span> |
||
| 22 | 00015 <span class="comment">// tested. Nonetheless, you can expect most functions to work.</span> |
||
| 23 | 00016 <span class="comment">//</span> |
||
| 24 | 00017 <span class="comment">// This code is distributed under the GNU Public License</span> |
||
| 25 | 00018 <span class="comment">// which can be found at http://www.gnu.org/licenses/gpl.txt</span> |
||
| 26 | 00019 <span class="comment">//</span><span class="comment"></span> |
||
| 27 | 00020 <span class="comment">/// \ingroup general</span> |
||
| 28 | 00021 <span class="comment">/// \defgroup rprintf printf() Function Library (rprintf.c)</span> |
||
| 29 | 00022 <span class="comment">/// \code #include "rprintf.h" \endcode</span> |
||
| 30 | 00023 <span class="comment">/// \par Overview</span> |
||
| 31 | 00024 <span class="comment">/// The rprintf function library provides a simplified (reduced) version of</span> |
||
| 32 | 00025 <span class="comment">/// the common C printf() function. See the code files for details about</span> |
||
| 33 | 00026 <span class="comment">/// which printf features are supported. Also in this library are a</span> |
||
| 34 | 00027 <span class="comment">/// variety of functions for fast printing of certain common data types</span> |
||
| 35 | 00028 <span class="comment">/// (variable types). Functions include print string from RAM, print</span> |
||
| 36 | 00029 <span class="comment">/// string from ROM, print string snippet, print hex byte/short/long, and</span> |
||
| 37 | 00030 <span class="comment">/// a custom-formatted number print, as well as an optional floating-point</span> |
||
| 38 | 00031 <span class="comment">/// print routine.</span> |
||
| 39 | 00032 <span class="comment">///</span> |
||
| 40 | 00033 <span class="comment">/// \note All output from the rprintf library can be directed to any device</span> |
||
| 41 | 00034 <span class="comment">/// or software which accepts characters. This means that rprintf output</span> |
||
| 42 | 00035 <span class="comment">/// can be sent to the UART (serial port) or can be used with the LCD</span> |
||
| 43 | 00036 <span class="comment">/// display libraries to print formatted text on the screen.</span> |
||
| 44 | 00037 <span class="comment"></span><span class="comment">//</span> |
||
| 45 | 00038 <span class="comment">//****************************************************************************</span><span class="comment"></span> |
||
| 46 | 00039 <span class="comment">//@{</span> |
||
| 47 | 00040 <span class="comment"></span> |
||
| 48 | 00041 <span class="preprocessor">#ifndef RPRINTF_H</span> |
||
| 49 | 00042 <span class="preprocessor"></span><span class="preprocessor">#define RPRINTF_H</span> |
||
| 50 | 00043 <span class="preprocessor"></span> |
||
| 51 | 00044 <span class="comment">// needed for use of PSTR below</span> |
||
| 52 | 00045 <span class="preprocessor">#include <avr/pgmspace.h></span> |
||
| 53 | 00046 |
||
| 54 | 00047 <span class="comment">// configuration</span> |
||
| 55 | 00048 <span class="comment">// defining RPRINTF_SIMPLE will compile a smaller, simpler, and faster printf() function</span> |
||
| 56 | 00049 <span class="comment">// defining RPRINTF_COMPLEX will compile a larger, more capable, and slower printf() function</span> |
||
| 57 | 00050 <span class="preprocessor">#ifndef RPRINTF_COMPLEX</span> |
||
| 58 | 00051 <span class="preprocessor"></span><span class="preprocessor"> #define RPRINTF_SIMPLE</span> |
||
| 59 | 00052 <span class="preprocessor"></span><span class="preprocessor">#endif</span> |
||
| 60 | 00053 <span class="preprocessor"></span> |
||
| 61 | 00054 <span class="comment">// Define RPRINTF_FLOAT to enable the floating-point printf function: rprintfFloat()</span> |
||
| 62 | 00055 <span class="comment">// (adds +4600bytes or 2.2Kwords of code)</span> |
||
| 63 | 00056 |
||
| 64 | 00057 <span class="comment">// defines/constants</span> |
||
| 65 | 00058 <span class="preprocessor">#define STRING_IN_RAM 0</span> |
||
| 66 | 00059 <span class="preprocessor"></span><span class="preprocessor">#define STRING_IN_ROM 1</span> |
||
| 67 | 00060 <span class="preprocessor"></span> |
||
| 68 | 00061 <span class="comment">// make a putchar for those that are used to using it</span> |
||
| 69 | 00062 <span class="comment">//#define putchar(c) rprintfChar(c);</span> |
||
| 70 | 00063 |
||
| 71 | 00064 <span class="comment">// functions</span> |
||
| 72 | 00065 <span class="comment"></span> |
||
| 73 | 00066 <span class="comment">//! Initializes the rprintf library for an output stream.</span> |
||
| 74 | 00067 <span class="comment">/// You must call this initializer once before using any other rprintf function.</span> |
||
| 75 | 00068 <span class="comment">/// The argument must be a character stream output function.</span> |
||
| 76 | 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)); |
||
| 77 | 00070 <span class="comment"></span> |
||
| 78 | 00071 <span class="comment">//! prints a single character to the current output device</span> |
||
| 79 | 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); |
||
| 80 | 00073 <span class="comment"></span> |
||
| 81 | 00074 <span class="comment">//! prints a null-terminated string stored in RAM</span> |
||
| 82 | 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[]); |
||
| 83 | 00076 <span class="comment"></span> |
||
| 84 | 00077 <span class="comment">//! Prints a section of a string stored in RAM.</span> |
||
| 85 | 00078 <span class="comment">/// Begins printing at position indicated by <start>,</span> |
||
| 86 | 00079 <span class="comment">/// and prints number of characters indicated by <len>.</span> |
||
| 87 | 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); |
||
| 88 | 00081 <span class="comment"></span> |
||
| 89 | 00082 <span class="comment">//! prints a string stored in program rom</span> |
||
| 90 | 00083 <span class="comment">/// \note This function does not actually store your string in</span> |
||
| 91 | 00084 <span class="comment">/// program rom, but merely reads it assuming you stored it properly.</span> |
||
| 92 | 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[]); |
||
| 93 | 00086 <span class="comment"></span> |
||
| 94 | 00087 <span class="comment">//! Using the function rprintfProgStrM(...) automatically causes </span> |
||
| 95 | 00088 <span class="comment">/// your string to be stored in ROM, thereby not wasting precious RAM.</span> |
||
| 96 | 00089 <span class="comment">/// Example usage:</span> |
||
| 97 | 00090 <span class="comment">/// \code</span> |
||
| 98 | 00091 <span class="comment">/// rprintfProgStrM("Hello, this string is stored in program rom");</span> |
||
| 99 | 00092 <span class="comment">/// \endcode</span> |
||
| 100 | <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> |
||
| 101 | 00094 <span class="preprocessor"></span><span class="comment"></span> |
||
| 102 | 00095 <span class="comment">//! Prints a carriage-return and line-feed.</span> |
||
| 103 | 00096 <span class="comment">/// Useful when printing to serial ports/terminals.</span> |
||
| 104 | 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>); |
||
| 105 | 00098 |
||
| 106 | 00099 <span class="comment">// Prints the number contained in "data" in hex format</span> |
||
| 107 | 00100 <span class="comment">// u04,u08,u16,and u32 functions handle 4,8,16,or 32 bits respectively</span> |
||
| 108 | 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> |
||
| 109 | 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> |
||
| 110 | 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> |
||
| 111 | 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> |
||
| 112 | 00105 <span class="comment"></span><span class="comment"></span> |
||
| 113 | 00106 <span class="comment">//! A flexible integer-number printing routine.</span> |
||
| 114 | 00107 <span class="comment">/// Print the number "n" in the given "base", using exactly "numDigits".</span> |
||
| 115 | 00108 <span class="comment">/// Print +/- if signed flag "isSigned" is TRUE.</span> |
||
| 116 | 00109 <span class="comment">/// The character specified in "padchar" will be used to pad extra characters.</span> |
||
| 117 | 00110 <span class="comment">///</span> |
||
| 118 | 00111 <span class="comment">/// Examples:</span> |
||
| 119 | 00112 <span class="comment">/// \code</span> |
||
| 120 | 00113 <span class="comment">/// uartPrintfNum(10, 6, TRUE, ' ', 1234); --> " +1234"</span> |
||
| 121 | 00114 <span class="comment">/// uartPrintfNum(10, 6, FALSE, '0', 1234); --> "001234"</span> |
||
| 122 | 00115 <span class="comment">/// uartPrintfNum(16, 6, FALSE, '.', 0x5AA5); --> "..5AA5"</span> |
||
| 123 | 00116 <span class="comment">/// \endcode</span> |
||
| 124 | 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); |
||
| 125 | 00118 |
||
| 126 | 00119 <span class="preprocessor">#ifdef RPRINTF_FLOAT</span> |
||
| 127 | 00120 <span class="preprocessor"></span><span class="comment"> //! floating-point print routine</span> |
||
| 128 | 00121 <span class="comment"></span> <span class="keywordtype">void</span> rprintfFloat(<span class="keywordtype">char</span> numDigits, <span class="keywordtype">double</span> x); |
||
| 129 | 00122 <span class="preprocessor">#endif</span> |
||
| 130 | 00123 <span class="preprocessor"></span> |
||
| 131 | 00124 <span class="comment">// NOTE: Below you'll see the function prototypes of rprintf1RamRom and </span> |
||
| 132 | 00125 <span class="comment">// rprintf2RamRom. rprintf1RamRom and rprintf2RamRom are both reduced versions</span> |
||
| 133 | 00126 <span class="comment">// of the regular C printf() command. However, they are modified to be able</span> |
||
| 134 | 00127 <span class="comment">// to read their text/format strings from RAM or ROM in the Atmel microprocessors.</span> |
||
| 135 | 00128 <span class="comment">// Unless you really intend to, do not use the "RamRom" versions of the functions</span> |
||
| 136 | 00129 <span class="comment">// directly. Instead use the #defined function versions:</span> |
||
| 137 | 00130 <span class="comment">//</span> |
||
| 138 | 00131 <span class="comment">// printfx("text/format",args) ...to keep your text/format string stored in RAM</span> |
||
| 139 | 00132 <span class="comment">// - or -</span> |
||
| 140 | 00133 <span class="comment">// printfxROM("text/format",args) ...to keep your text/format string stored in ROM</span> |
||
| 141 | 00134 <span class="comment">//</span> |
||
| 142 | 00135 <span class="comment">// where x is either 1 or 2 for the simple or more powerful version of printf()</span> |
||
| 143 | 00136 <span class="comment">//</span> |
||
| 144 | 00137 <span class="comment">// Since there is much more ROM than RAM available in the Atmel microprocessors,</span> |
||
| 145 | 00138 <span class="comment">// and nearly all text/format strings are constant (never change in the course</span> |
||
| 146 | 00139 <span class="comment">// of the program), you should try to use the ROM printf version exclusively.</span> |
||
| 147 | 00140 <span class="comment">// This will ensure you leave as much RAM as possible for program variables and</span> |
||
| 148 | 00141 <span class="comment">// data.</span> |
||
| 149 | 00142 <span class="comment"></span> |
||
| 150 | 00143 <span class="comment">//! \fn int rprintf(const char *format, ...);</span> |
||
| 151 | 00144 <span class="comment">/// A reduced substitute for the usual C printf() function.</span> |
||
| 152 | 00145 <span class="comment">/// This function actually points to either rprintf1RamRom or rprintf2RamRom</span> |
||
| 153 | 00146 <span class="comment">/// depending on the user's selection. Rprintf1 is a simple small fast print</span> |
||
| 154 | 00147 <span class="comment">/// routine while rprintf2 is larger and slower but more capable. To choose</span> |
||
| 155 | 00148 <span class="comment">/// the routine you would like to use, define either RPRINTF_SIMPLE or</span> |
||
| 156 | 00149 <span class="comment">/// RPRINTF_COMPLEX in global.h.</span> |
||
| 157 | 00150 <span class="comment"></span> |
||
| 158 | 00151 <span class="preprocessor">#ifdef RPRINTF_SIMPLE</span><span class="comment"></span> |
||
| 159 | 00152 <span class="comment"> //! A simple printf routine.</span> |
||
| 160 | 00153 <span class="comment"> /// Called by rprintf() - does a simple printf (supports %d, %x, %c).</span> |
||
| 161 | 00154 <span class="comment"> /// Supports:</span> |
||
| 162 | 00155 <span class="comment"> /// - %d - decimal</span> |
||
| 163 | 00156 <span class="comment"> /// - %x - hex</span> |
||
| 164 | 00157 <span class="comment"> /// - %c - character</span> |
||
| 165 | 00158 <span class="comment"></span> int rprintf1RamRom(unsigned char stringInRom, const char *format, ...); |
||
| 166 | 00159 <span class="comment">// #defines for RAM or ROM operation</span> |
||
| 167 | 00160 <span class="preprocessor"> #define rprintf1(format, args...) rprintf1RamRom(STRING_IN_ROM, PSTR(format), ## args)</span> |
||
| 168 | 00161 <span class="preprocessor"></span><span class="preprocessor"> #define rprintf1RAM(format, args...) rprintf1RamRom(STRING_IN_RAM, format, ## args)</span> |
||
| 169 | 00162 <span class="preprocessor"></span> |
||
| 170 | 00163 <span class="comment">// *** Default rprintf(...) ***</span> |
||
| 171 | 00164 <span class="comment">// this next line determines what the the basic rprintf() defaults to:</span> |
||
| 172 | 00165 <span class="preprocessor"> #define rprintf(format, args...) rprintf1RamRom(STRING_IN_ROM, PSTR(format), ## args)</span> |
||
| 173 | 00166 <span class="preprocessor"></span><span class="preprocessor">#endif</span> |
||
| 174 | 00167 <span class="preprocessor"></span> |
||
| 175 | 00168 <span class="preprocessor">#ifdef RPRINTF_COMPLEX</span><span class="comment"></span> |
||
| 176 | 00169 <span class="comment"> //! A more powerful printf routine.</span> |
||
| 177 | 00170 <span class="comment"> /// Called by rprintf() - does a more powerful printf (supports %d, %u, %o, %x, %c, %s).</span> |
||
| 178 | 00171 <span class="comment"> /// Supports:</span> |
||
| 179 | 00172 <span class="comment"> /// - %d - decimal</span> |
||
| 180 | 00173 <span class="comment"> /// - %u - unsigned decimal</span> |
||
| 181 | 00174 <span class="comment"> /// - %o - octal</span> |
||
| 182 | 00175 <span class="comment"> /// - %x - hex</span> |
||
| 183 | 00176 <span class="comment"> /// - %c - character</span> |
||
| 184 | 00177 <span class="comment"> /// - %s - strings</span> |
||
| 185 | 00178 <span class="comment"> /// - and the width,precision,padding modifiers</span> |
||
| 186 | 00179 <span class="comment"> /// \note This printf does not support floating point numbers.</span> |
||
| 187 | 00180 <span class="comment"></span> int rprintf2RamRom(unsigned char stringInRom, const char *sfmt, ...); |
||
| 188 | 00181 <span class="comment">// #defines for RAM or ROM operation</span> |
||
| 189 | 00182 <span class="preprocessor"> #define rprintf2(format, args...) rprintf2RamRom(STRING_IN_ROM, format, ## args)</span> |
||
| 190 | 00183 <span class="preprocessor"></span><span class="preprocessor"> #define rprintf2RAM(format, args...) rprintf2RamRom(STRING_IN_RAM, format, ## args)</span> |
||
| 191 | 00184 <span class="preprocessor"></span> |
||
| 192 | 00185 <span class="comment">// *** Default rprintf(...) ***</span> |
||
| 193 | 00186 <span class="comment">// this next line determines what the the basic rprintf() defaults to:</span> |
||
| 194 | 00187 <span class="preprocessor"> #define rprintf(format, args...) rprintf2RamRom(STRING_IN_ROM, PSTR(format), ## args)</span> |
||
| 195 | 00188 <span class="preprocessor"></span><span class="preprocessor">#endif</span> |
||
| 196 | 00189 <span class="preprocessor"></span> |
||
| 197 | 00190 <span class="preprocessor">#endif</span> |
||
| 198 | 00191 <span class="preprocessor"></span><span class="comment">//@}</span> |
||
| 199 | </span></pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:07 2006 for Procyon AVRlib by |
||
| 200 | <a href="http://www.doxygen.org/index.html"> |
||
| 201 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address> |
||
| 202 | </body> |
||
| 203 | </html> |
Powered by WebSVN v2.8.3