This module provides a simple API to the Maxim MAX7456 on-screen display chip

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers OSD7456.h Source File

OSD7456.h

00001 /*
00002     Copyright (c) 2010 Andy Kirkham
00003  
00004     Permission is hereby granted, free of charge, to any person obtaining a copy
00005     of this software and associated documentation files (the "Software"), to deal
00006     in the Software without restriction, including without limitation the rights
00007     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008     copies of the Software, and to permit persons to whom the Software is
00009     furnished to do so, subject to the following conditions:
00010  
00011     The above copyright notice and this permission notice shall be included in
00012     all copies or substantial portions of the Software.
00013  
00014     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020     THE SOFTWARE.
00021 */
00022 
00023 #ifndef MODOSD7456_H
00024 #define MODOSD7456_H
00025 
00026 #include "mbed.h"
00027 #include "MAX7456.h"
00028 
00029 /** defgroup OSD7456_API */
00030 
00031 #define OSD_NUM_LINES   13
00032 #define OSD_LINE_LEN    30
00033 
00034 typedef struct _osd_line {
00035     char line[OSD_LINE_LEN];
00036     char attrib[OSD_LINE_LEN];
00037     bool updated;
00038 } OSD_LINE;
00039 
00040 /** OSD7456 module
00041  *
00042  * The OSD7456 is a wrapper around the MAX7456 that abstracts the hardware
00043  * into a simple to use screen writer system. It provides buffered output.
00044  * To ensure a "flicker free" display, the buffers are written to the MAX7456
00045  * chip at the start of the vertical sync period.
00046  *
00047  * @see http://mbed.org/cookbook/
00048  * @see example2.cpp
00049  *
00050  * Example:
00051  * @code
00052  * #include "mbed.h"
00053  * #include "OSD7456.h"
00054  * 
00055  * DigitalOut led1(LED1);
00056  * 
00057  * OSD7456 *osd;
00058  * 
00059  * int main() {
00060  *     
00061  *     osd = new OSD7456(p5, p6, p7, p8, p20, p15);
00062  *     
00063  *     osd->print(1, "Hello World");
00064  *     osd->print2("This blinks", MAX7456::Blink);
00065  *     osd->print3("Background", MAX7456::LocalBG);    
00066  *     osd->print(5, 4, "Positioned");
00067  *     osd->print(5, 5, "Positioned", MAX7456::LocalBG);
00068  *     osd->print(3, 7, "Test");
00069  *     osd->print(12, 7, "Test", MAX7456::LocalBG | MAX7456::Blink);
00070  *     
00071  *     while(1) {
00072  *         led1 = 1;
00073  *         wait(0.5);        
00074  *         led1 = 0;
00075  *         wait(0.5);    
00076  *     }
00077  * }
00078  * @endcode
00079  */
00080  
00081 class OSD7456
00082 {
00083 public:
00084 
00085     //! OSD7456 constructor.
00086     /**
00087      * The OSD7456 constructor.
00088      *
00089      * @ingroup OSD7456_API
00090      * @param miso PinName p5 or p11
00091      * @param mosi PinName p6 or p12
00092      * @param sclk PinName p7 pr p13
00093      * @param name Optional const char * SSP object name
00094      * @param cs   PinName CS signal
00095      * @param rst  PinName RESET signal
00096      * @param vsync PinName Vertical sync signal
00097      */
00098     OSD7456(PinName mosi, PinName miso, PinName sclk, const char *name, PinName cs, PinName rst, PinName vsync) {
00099         max7456 = new MAX7456(mosi, miso, sclk, name, cs, rst, vsync); 
00100         init();       
00101     }
00102     
00103     //! OSD7456 constructor.
00104     /**
00105      * The OSD7456 constructor.
00106      *
00107      * @ingroup OSD7456_API
00108      * @param miso PinName p5 or p11
00109      * @param mosi PinName p6 or p12
00110      * @param sclk PinName p7 pr p13
00111      * @param cs   PinName CS signal
00112      * @param rst  PinName RESET signal
00113      * @param vsync PinName Vertical sync signal
00114      */
00115     OSD7456(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName rst, PinName vsync) {
00116         max7456 = new MAX7456(mosi, miso, sclk, NULL, cs, rst, vsync);        
00117         init();
00118     }
00119     
00120     //! print()
00121     /**
00122      * Print ASCII text at line.
00123      *
00124      * @ingroup OSD7456_API
00125      * @param line The line number to print at.
00126      * @param s A pointer to the null terminated string to print.
00127      */
00128     int print(int line, char *s);
00129     
00130     //! print()
00131     /**
00132      * Print ASCII text on line y at position x
00133      *
00134      * @ingroup OSD7456_API
00135      * @param x The line position to print at.
00136      * @param y The line to print on.
00137      * @param s A pointer to the null terminated string to print.
00138      */
00139     int print(int x, int y, char *s);
00140     
00141     //! print()
00142     /**
00143      * Print ASCII text on line y at position x with attribute.
00144      *
00145      * @ingroup OSD7456_API
00146      * @param x The line position to print at.
00147      * @param y The line to print on.
00148      * @param s A pointer to the null terminated string to print.
00149      * @param a An attribute byte to apply to the string.
00150      */
00151     int print(int line, char *s, char a);
00152     
00153     //! print()
00154     /**
00155      * Print ASCII text on line y at position x
00156      *
00157      * @ingroup OSD7456_API
00158      * @param x The line position to print at.
00159      * @param y The line to print on.
00160      * @param s A pointer to the null terminated string to print.
00161      * @param a An attribute byte to apply to the string.
00162      */
00163     int print(int x, int y, char *s, char attrib);    
00164     
00165     //! clear()
00166     /**
00167      * Clear the line number supplied.
00168      *
00169      * @ingroup OSD7456_API
00170      * @param line The line number to clear.
00171      */
00172     void clear(int line);
00173     
00174     /** @ingroup OSD7456_API */
00175     /** @{ */
00176     __INLINE int print0 (char *s) { return print(0, s); }
00177     __INLINE int print1(char *s) { return print(1, s); }
00178     __INLINE int print2(char *s) { return print(2, s); }
00179     __INLINE int print3(char *s) { return print(3, s); }
00180     __INLINE int print4(char *s) { return print(4, s); }
00181     __INLINE int print5(char *s) { return print(5, s); }
00182     __INLINE int print6(char *s) { return print(6, s); }
00183     __INLINE int print7(char *s) { return print(7, s); }
00184     __INLINE int print8(char *s) { return print(8, s); }
00185     __INLINE int print9(char *s) { return print(9, s); }
00186     __INLINE int print10(char *s) { return print(10, s); }
00187     __INLINE int print11(char *s) { return print(11, s); }
00188     __INLINE int print12(char *s) { return print(12, s); }
00189     __INLINE int print13(char *s) { return print(13, s); }
00190     
00191     __INLINE int print0 (char *s, char a) { return print(0, s, a); }
00192     __INLINE int print1(char *s, char a) { return print(1, s, a); }
00193     __INLINE int print2(char *s, char a) { return print(2, s, a); }
00194     __INLINE int print3(char *s, char a) { return print(3, s, a); }
00195     __INLINE int print4(char *s, char a) { return print(4, s, a); }
00196     __INLINE int print5(char *s, char a) { return print(5, s, a); }
00197     __INLINE int print6(char *s, char a) { return print(6, s, a); }
00198     __INLINE int print7(char *s, char a) { return print(7, s, a); }
00199     __INLINE int print8(char *s, char a) { return print(8, s, a); }
00200     __INLINE int print9(char *s, char a) { return print(9, s, a); }
00201     __INLINE int print10(char *s, char a) { return print(10, s, a); }
00202     __INLINE int print11(char *s, char a) { return print(11, s, a); }
00203     __INLINE int print12(char *s, char a) { return print(12, s, a); }
00204     __INLINE int print13(char *s, char a) { return print(13, s, a); }
00205     
00206     /** @} */
00207     
00208     // The function registered with teh MAX7456 vertical sync interrupt handler.
00209     void vsync(void);
00210     
00211     /**
00212      * Attach a user callback object/method to call when the vsync signal activates. 
00213      *
00214      *
00215      * @ingroup OSD7456_API
00216      * @param tptr pointer to the object to call the member function on
00217      * @param mptr pointer to the member function to be called
00218      */
00219     template<typename T>
00220     void attach_vsync(T* tptr, void (T::*mptr)(void)) { cb_vsync.attach(tptr, mptr); }
00221     
00222     /**
00223      * Attach a user callback function pointer to call when the vsync signal activates. 
00224      *
00225      * @ingroup OSD7456_API
00226      * @param fptr Callback function pointer
00227      */
00228     void attach_vsync(void (*fptr)(void)) { cb_vsync.attach(fptr); } 
00229     
00230     //! A callback object for the 1PPS user API.
00231     FunctionPointer cb_vsync;
00232     
00233     MAX7456 *max7456;
00234     
00235 protected:
00236     
00237     OSD_LINE lines[OSD_NUM_LINES];
00238     
00239     void init(void); 
00240     
00241     bool oddEven;   
00242 };
00243 
00244 #endif