Testé pour projet BTS SN

Fork of MODMAX7456 by Andy K

Committer:
AjK
Date:
Tue Nov 16 10:47:25 2010 +0000
Revision:
0:d7cd54ad4c3d
1.7

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AjK 0:d7cd54ad4c3d 1 /*
AjK 0:d7cd54ad4c3d 2 Copyright (c) 2010 Andy Kirkham
AjK 0:d7cd54ad4c3d 3
AjK 0:d7cd54ad4c3d 4 Permission is hereby granted, free of charge, to any person obtaining a copy
AjK 0:d7cd54ad4c3d 5 of this software and associated documentation files (the "Software"), to deal
AjK 0:d7cd54ad4c3d 6 in the Software without restriction, including without limitation the rights
AjK 0:d7cd54ad4c3d 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
AjK 0:d7cd54ad4c3d 8 copies of the Software, and to permit persons to whom the Software is
AjK 0:d7cd54ad4c3d 9 furnished to do so, subject to the following conditions:
AjK 0:d7cd54ad4c3d 10
AjK 0:d7cd54ad4c3d 11 The above copyright notice and this permission notice shall be included in
AjK 0:d7cd54ad4c3d 12 all copies or substantial portions of the Software.
AjK 0:d7cd54ad4c3d 13
AjK 0:d7cd54ad4c3d 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
AjK 0:d7cd54ad4c3d 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
AjK 0:d7cd54ad4c3d 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AjK 0:d7cd54ad4c3d 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
AjK 0:d7cd54ad4c3d 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
AjK 0:d7cd54ad4c3d 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
AjK 0:d7cd54ad4c3d 20 THE SOFTWARE.
AjK 0:d7cd54ad4c3d 21 */
AjK 0:d7cd54ad4c3d 22
AjK 0:d7cd54ad4c3d 23 #ifndef MODOSD7456_H
AjK 0:d7cd54ad4c3d 24 #define MODOSD7456_H
AjK 0:d7cd54ad4c3d 25
AjK 0:d7cd54ad4c3d 26 #include "mbed.h"
AjK 0:d7cd54ad4c3d 27 #include "MAX7456.h"
AjK 0:d7cd54ad4c3d 28
AjK 0:d7cd54ad4c3d 29 /** defgroup OSD7456_API */
AjK 0:d7cd54ad4c3d 30
AjK 0:d7cd54ad4c3d 31 #define OSD_NUM_LINES 13
AjK 0:d7cd54ad4c3d 32 #define OSD_LINE_LEN 30
AjK 0:d7cd54ad4c3d 33
AjK 0:d7cd54ad4c3d 34 typedef struct _osd_line {
AjK 0:d7cd54ad4c3d 35 char line[OSD_LINE_LEN];
AjK 0:d7cd54ad4c3d 36 char attrib[OSD_LINE_LEN];
AjK 0:d7cd54ad4c3d 37 bool updated;
AjK 0:d7cd54ad4c3d 38 } OSD_LINE;
AjK 0:d7cd54ad4c3d 39
AjK 0:d7cd54ad4c3d 40 /** OSD7456 module
AjK 0:d7cd54ad4c3d 41 *
AjK 0:d7cd54ad4c3d 42 * The OSD7456 is a wrapper around the MAX7456 that abstracts the hardware
AjK 0:d7cd54ad4c3d 43 * into a simple to use screen writer system. It provides buffered output.
AjK 0:d7cd54ad4c3d 44 * To ensure a "flicker free" display, the buffers are written to the MAX7456
AjK 0:d7cd54ad4c3d 45 * chip at the start of the vertical sync period.
AjK 0:d7cd54ad4c3d 46 *
AjK 0:d7cd54ad4c3d 47 * @see http://mbed.org/cookbook/
AjK 0:d7cd54ad4c3d 48 * @see example2.cpp
AjK 0:d7cd54ad4c3d 49 *
AjK 0:d7cd54ad4c3d 50 * Example:
AjK 0:d7cd54ad4c3d 51 * @code
AjK 0:d7cd54ad4c3d 52 * #include "mbed.h"
AjK 0:d7cd54ad4c3d 53 * #include "OSD7456.h"
AjK 0:d7cd54ad4c3d 54 *
AjK 0:d7cd54ad4c3d 55 * DigitalOut led1(LED1);
AjK 0:d7cd54ad4c3d 56 *
AjK 0:d7cd54ad4c3d 57 * OSD7456 *osd;
AjK 0:d7cd54ad4c3d 58 *
AjK 0:d7cd54ad4c3d 59 * int main() {
AjK 0:d7cd54ad4c3d 60 *
AjK 0:d7cd54ad4c3d 61 * osd = new OSD7456(p5, p6, p7, p8, p20, p15);
AjK 0:d7cd54ad4c3d 62 *
AjK 0:d7cd54ad4c3d 63 * osd->print(1, "Hello World");
AjK 0:d7cd54ad4c3d 64 * osd->print2("This blinks", MAX7456::Blink);
AjK 0:d7cd54ad4c3d 65 * osd->print3("Background", MAX7456::LocalBG);
AjK 0:d7cd54ad4c3d 66 * osd->print(5, 4, "Positioned");
AjK 0:d7cd54ad4c3d 67 * osd->print(5, 5, "Positioned", MAX7456::LocalBG);
AjK 0:d7cd54ad4c3d 68 * osd->print(3, 7, "Test");
AjK 0:d7cd54ad4c3d 69 * osd->print(12, 7, "Test", MAX7456::LocalBG | MAX7456::Blink);
AjK 0:d7cd54ad4c3d 70 *
AjK 0:d7cd54ad4c3d 71 * while(1) {
AjK 0:d7cd54ad4c3d 72 * led1 = 1;
AjK 0:d7cd54ad4c3d 73 * wait(0.5);
AjK 0:d7cd54ad4c3d 74 * led1 = 0;
AjK 0:d7cd54ad4c3d 75 * wait(0.5);
AjK 0:d7cd54ad4c3d 76 * }
AjK 0:d7cd54ad4c3d 77 * }
AjK 0:d7cd54ad4c3d 78 * @endcode
AjK 0:d7cd54ad4c3d 79 */
AjK 0:d7cd54ad4c3d 80
AjK 0:d7cd54ad4c3d 81 class OSD7456
AjK 0:d7cd54ad4c3d 82 {
AjK 0:d7cd54ad4c3d 83 public:
AjK 0:d7cd54ad4c3d 84
AjK 0:d7cd54ad4c3d 85 //! OSD7456 constructor.
AjK 0:d7cd54ad4c3d 86 /**
AjK 0:d7cd54ad4c3d 87 * The OSD7456 constructor.
AjK 0:d7cd54ad4c3d 88 *
AjK 0:d7cd54ad4c3d 89 * @ingroup OSD7456_API
AjK 0:d7cd54ad4c3d 90 * @param miso PinName p5 or p11
AjK 0:d7cd54ad4c3d 91 * @param mosi PinName p6 or p12
AjK 0:d7cd54ad4c3d 92 * @param sclk PinName p7 pr p13
AjK 0:d7cd54ad4c3d 93 * @param name Optional const char * SSP object name
AjK 0:d7cd54ad4c3d 94 * @param cs PinName CS signal
AjK 0:d7cd54ad4c3d 95 * @param rst PinName RESET signal
AjK 0:d7cd54ad4c3d 96 * @param vsync PinName Vertical sync signal
AjK 0:d7cd54ad4c3d 97 */
AjK 0:d7cd54ad4c3d 98 OSD7456(PinName mosi, PinName miso, PinName sclk, const char *name, PinName cs, PinName rst, PinName vsync) {
AjK 0:d7cd54ad4c3d 99 max7456 = new MAX7456(mosi, miso, sclk, name, cs, rst, vsync);
AjK 0:d7cd54ad4c3d 100 init();
AjK 0:d7cd54ad4c3d 101 }
AjK 0:d7cd54ad4c3d 102
AjK 0:d7cd54ad4c3d 103 //! OSD7456 constructor.
AjK 0:d7cd54ad4c3d 104 /**
AjK 0:d7cd54ad4c3d 105 * The OSD7456 constructor.
AjK 0:d7cd54ad4c3d 106 *
AjK 0:d7cd54ad4c3d 107 * @ingroup OSD7456_API
AjK 0:d7cd54ad4c3d 108 * @param miso PinName p5 or p11
AjK 0:d7cd54ad4c3d 109 * @param mosi PinName p6 or p12
AjK 0:d7cd54ad4c3d 110 * @param sclk PinName p7 pr p13
AjK 0:d7cd54ad4c3d 111 * @param cs PinName CS signal
AjK 0:d7cd54ad4c3d 112 * @param rst PinName RESET signal
AjK 0:d7cd54ad4c3d 113 * @param vsync PinName Vertical sync signal
AjK 0:d7cd54ad4c3d 114 */
AjK 0:d7cd54ad4c3d 115 OSD7456(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName rst, PinName vsync) {
AjK 0:d7cd54ad4c3d 116 max7456 = new MAX7456(mosi, miso, sclk, NULL, cs, rst, vsync);
AjK 0:d7cd54ad4c3d 117 init();
AjK 0:d7cd54ad4c3d 118 }
AjK 0:d7cd54ad4c3d 119
AjK 0:d7cd54ad4c3d 120 //! print()
AjK 0:d7cd54ad4c3d 121 /**
AjK 0:d7cd54ad4c3d 122 * Print ASCII text at line.
AjK 0:d7cd54ad4c3d 123 *
AjK 0:d7cd54ad4c3d 124 * @ingroup OSD7456_API
AjK 0:d7cd54ad4c3d 125 * @param line The line number to print at.
AjK 0:d7cd54ad4c3d 126 * @param s A pointer to the null terminated string to print.
AjK 0:d7cd54ad4c3d 127 */
AjK 0:d7cd54ad4c3d 128 int print(int line, char *s);
AjK 0:d7cd54ad4c3d 129
AjK 0:d7cd54ad4c3d 130 //! print()
AjK 0:d7cd54ad4c3d 131 /**
AjK 0:d7cd54ad4c3d 132 * Print ASCII text on line y at position x
AjK 0:d7cd54ad4c3d 133 *
AjK 0:d7cd54ad4c3d 134 * @ingroup OSD7456_API
AjK 0:d7cd54ad4c3d 135 * @param x The line position to print at.
AjK 0:d7cd54ad4c3d 136 * @param y The line to print on.
AjK 0:d7cd54ad4c3d 137 * @param s A pointer to the null terminated string to print.
AjK 0:d7cd54ad4c3d 138 */
AjK 0:d7cd54ad4c3d 139 int print(int x, int y, char *s);
AjK 0:d7cd54ad4c3d 140
AjK 0:d7cd54ad4c3d 141 //! print()
AjK 0:d7cd54ad4c3d 142 /**
AjK 0:d7cd54ad4c3d 143 * Print ASCII text on line y at position x with attribute.
AjK 0:d7cd54ad4c3d 144 *
AjK 0:d7cd54ad4c3d 145 * @ingroup OSD7456_API
AjK 0:d7cd54ad4c3d 146 * @param x The line position to print at.
AjK 0:d7cd54ad4c3d 147 * @param y The line to print on.
AjK 0:d7cd54ad4c3d 148 * @param s A pointer to the null terminated string to print.
AjK 0:d7cd54ad4c3d 149 * @param a An attribute byte to apply to the string.
AjK 0:d7cd54ad4c3d 150 */
AjK 0:d7cd54ad4c3d 151 int print(int line, char *s, char a);
AjK 0:d7cd54ad4c3d 152
AjK 0:d7cd54ad4c3d 153 //! print()
AjK 0:d7cd54ad4c3d 154 /**
AjK 0:d7cd54ad4c3d 155 * Print ASCII text on line y at position x
AjK 0:d7cd54ad4c3d 156 *
AjK 0:d7cd54ad4c3d 157 * @ingroup OSD7456_API
AjK 0:d7cd54ad4c3d 158 * @param x The line position to print at.
AjK 0:d7cd54ad4c3d 159 * @param y The line to print on.
AjK 0:d7cd54ad4c3d 160 * @param s A pointer to the null terminated string to print.
AjK 0:d7cd54ad4c3d 161 * @param a An attribute byte to apply to the string.
AjK 0:d7cd54ad4c3d 162 */
AjK 0:d7cd54ad4c3d 163 int print(int x, int y, char *s, char attrib);
AjK 0:d7cd54ad4c3d 164
AjK 0:d7cd54ad4c3d 165 //! clear()
AjK 0:d7cd54ad4c3d 166 /**
AjK 0:d7cd54ad4c3d 167 * Clear the line number supplied.
AjK 0:d7cd54ad4c3d 168 *
AjK 0:d7cd54ad4c3d 169 * @ingroup OSD7456_API
AjK 0:d7cd54ad4c3d 170 * @param line The line number to clear.
AjK 0:d7cd54ad4c3d 171 */
AjK 0:d7cd54ad4c3d 172 void clear(int line);
AjK 0:d7cd54ad4c3d 173
AjK 0:d7cd54ad4c3d 174 /** @ingroup OSD7456_API */
AjK 0:d7cd54ad4c3d 175 /** @{ */
AjK 0:d7cd54ad4c3d 176 __INLINE int print0(char *s) { return print(0, s); }
AjK 0:d7cd54ad4c3d 177 __INLINE int print1(char *s) { return print(1, s); }
AjK 0:d7cd54ad4c3d 178 __INLINE int print2(char *s) { return print(2, s); }
AjK 0:d7cd54ad4c3d 179 __INLINE int print3(char *s) { return print(3, s); }
AjK 0:d7cd54ad4c3d 180 __INLINE int print4(char *s) { return print(4, s); }
AjK 0:d7cd54ad4c3d 181 __INLINE int print5(char *s) { return print(5, s); }
AjK 0:d7cd54ad4c3d 182 __INLINE int print6(char *s) { return print(6, s); }
AjK 0:d7cd54ad4c3d 183 __INLINE int print7(char *s) { return print(7, s); }
AjK 0:d7cd54ad4c3d 184 __INLINE int print8(char *s) { return print(8, s); }
AjK 0:d7cd54ad4c3d 185 __INLINE int print9(char *s) { return print(9, s); }
AjK 0:d7cd54ad4c3d 186 __INLINE int print10(char *s) { return print(10, s); }
AjK 0:d7cd54ad4c3d 187 __INLINE int print11(char *s) { return print(11, s); }
AjK 0:d7cd54ad4c3d 188 __INLINE int print12(char *s) { return print(12, s); }
AjK 0:d7cd54ad4c3d 189 __INLINE int print13(char *s) { return print(13, s); }
AjK 0:d7cd54ad4c3d 190
AjK 0:d7cd54ad4c3d 191 __INLINE int print0(char *s, char a) { return print(0, s, a); }
AjK 0:d7cd54ad4c3d 192 __INLINE int print1(char *s, char a) { return print(1, s, a); }
AjK 0:d7cd54ad4c3d 193 __INLINE int print2(char *s, char a) { return print(2, s, a); }
AjK 0:d7cd54ad4c3d 194 __INLINE int print3(char *s, char a) { return print(3, s, a); }
AjK 0:d7cd54ad4c3d 195 __INLINE int print4(char *s, char a) { return print(4, s, a); }
AjK 0:d7cd54ad4c3d 196 __INLINE int print5(char *s, char a) { return print(5, s, a); }
AjK 0:d7cd54ad4c3d 197 __INLINE int print6(char *s, char a) { return print(6, s, a); }
AjK 0:d7cd54ad4c3d 198 __INLINE int print7(char *s, char a) { return print(7, s, a); }
AjK 0:d7cd54ad4c3d 199 __INLINE int print8(char *s, char a) { return print(8, s, a); }
AjK 0:d7cd54ad4c3d 200 __INLINE int print9(char *s, char a) { return print(9, s, a); }
AjK 0:d7cd54ad4c3d 201 __INLINE int print10(char *s, char a) { return print(10, s, a); }
AjK 0:d7cd54ad4c3d 202 __INLINE int print11(char *s, char a) { return print(11, s, a); }
AjK 0:d7cd54ad4c3d 203 __INLINE int print12(char *s, char a) { return print(12, s, a); }
AjK 0:d7cd54ad4c3d 204 __INLINE int print13(char *s, char a) { return print(13, s, a); }
AjK 0:d7cd54ad4c3d 205
AjK 0:d7cd54ad4c3d 206 /** @} */
AjK 0:d7cd54ad4c3d 207
AjK 0:d7cd54ad4c3d 208 // The function registered with teh MAX7456 vertical sync interrupt handler.
AjK 0:d7cd54ad4c3d 209 void vsync(void);
AjK 0:d7cd54ad4c3d 210
AjK 0:d7cd54ad4c3d 211 /**
AjK 0:d7cd54ad4c3d 212 * Attach a user callback object/method to call when the vsync signal activates.
AjK 0:d7cd54ad4c3d 213 *
AjK 0:d7cd54ad4c3d 214 *
AjK 0:d7cd54ad4c3d 215 * @ingroup OSD7456_API
AjK 0:d7cd54ad4c3d 216 * @param tptr pointer to the object to call the member function on
AjK 0:d7cd54ad4c3d 217 * @param mptr pointer to the member function to be called
AjK 0:d7cd54ad4c3d 218 */
AjK 0:d7cd54ad4c3d 219 template<typename T>
AjK 0:d7cd54ad4c3d 220 void attach_vsync(T* tptr, void (T::*mptr)(void)) { cb_vsync.attach(tptr, mptr); }
AjK 0:d7cd54ad4c3d 221
AjK 0:d7cd54ad4c3d 222 /**
AjK 0:d7cd54ad4c3d 223 * Attach a user callback function pointer to call when the vsync signal activates.
AjK 0:d7cd54ad4c3d 224 *
AjK 0:d7cd54ad4c3d 225 * @ingroup OSD7456_API
AjK 0:d7cd54ad4c3d 226 * @param fptr Callback function pointer
AjK 0:d7cd54ad4c3d 227 */
AjK 0:d7cd54ad4c3d 228 void attach_vsync(void (*fptr)(void)) { cb_vsync.attach(fptr); }
AjK 0:d7cd54ad4c3d 229
AjK 0:d7cd54ad4c3d 230 //! A callback object for the 1PPS user API.
AjK 0:d7cd54ad4c3d 231 FunctionPointer cb_vsync;
AjK 0:d7cd54ad4c3d 232
AjK 0:d7cd54ad4c3d 233 MAX7456 *max7456;
AjK 0:d7cd54ad4c3d 234
AjK 0:d7cd54ad4c3d 235 protected:
AjK 0:d7cd54ad4c3d 236
AjK 0:d7cd54ad4c3d 237 OSD_LINE lines[OSD_NUM_LINES];
AjK 0:d7cd54ad4c3d 238
AjK 0:d7cd54ad4c3d 239 void init(void);
AjK 0:d7cd54ad4c3d 240
AjK 0:d7cd54ad4c3d 241 bool oddEven;
AjK 0:d7cd54ad4c3d 242 };
AjK 0:d7cd54ad4c3d 243
AjK 0:d7cd54ad4c3d 244 #endif