Stefan Staub / EADOG

Dependencies:   Fonts

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers EADOG.h Source File

EADOG.h

00001 /* mbed library for the EA DOGM128 (128x64), DOGM132 (132x32), DOGL128 (128x64) pixel LCD
00002  * use ST7565R controller
00003  * Copyright (c) 2016 Stefan Staub
00004  * Released under the MIT License: http://mbed.org/license/mit
00005  *
00006  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00007  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00008  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00009  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00010  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00011  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00012  * THE SOFTWARE.
00013  */
00014 
00015 #ifndef EADOG_H
00016 #define EADOG_H
00017 
00018 #include "mbed.h"
00019 
00020 /** display type
00021   *
00022   * @param DOGM128 128x64 2.3''
00023   * @param DOGM132 132x32 2.1''
00024   * @param DOGL128 128x64 2.8''
00025   *
00026   */
00027 enum {DOGM128, DOGM132, DOGL128};
00028 
00029 /** update modes
00030   *
00031   * @param AUTO default
00032   * @param MANUELL
00033   *
00034   */
00035 enum {MANUAL, AUTO};
00036 
00037 /** display settings
00038   *
00039   * @param ON display on, default
00040   * @param OFF display off
00041   * @param SLEEP sets the display to sleep mode
00042   * @param DEFAULT default
00043   * @param INVERT inverts display
00044   * @param BOTTOM default 0°
00045   * @param TOPVIEW rotate the screento 180°
00046   *
00047   */
00048 enum {ON, OFF, SLEEP, DEFAULT, INVERT, BOTTOM, TOPVIEW, CONTRAST, RST};
00049 
00050 /** bitmap
00051   *
00052   */
00053 struct Bitmap {
00054   int xSize;
00055   int ySize;
00056   int byte_in_Line;
00057   char *data;
00058   };
00059 
00060 /** Library for the EADOG LCD displays from electronic assembly
00061  *
00062  * Example for EA DOGM132x-5 with STM32F401RE Nucleo
00063  * @code
00064  * // display test for EA DOGM132x-5 with STM32F401RE Nucleo
00065  * // sstaub(c)2016
00066  *
00067  * #include "mbed.h"
00068  * #include "EADOG.h"
00069  * #include "Small_7.h"
00070  * #include "Fonts/ArialR12x14.h"
00071  *
00072  * // DOGM132x-5 Wide Range
00073  * // Pins for STM32F401RE Nucleo
00074  *
00075  * // DOG Pin   Purpose   ST Pin
00076  * // 40        CS        PB_6(D10)
00077  * // 39        Reset     PC_7(D9)
00078  * // 38        A0        PA_9(D8)
00079  * // 37        SCK       PA_5(D13, SCK)
00080  * // 36        MOSI      PA_7(D11, MOSI)
00081  * // 35        VDD       3.3V
00082  * // 34        VDD2      3.3V
00083  * // 33        VSS       GND
00084  * // 32        VOUT      1uF -> GND
00085  * // 31        CAP3P     1uF -> CAP1N
00086  * // 30        CAP1N     1uF -> CAP1P
00087  * // 29        CAP1P
00088  * // 28        CAP2P     1uF -> CAP2N
00089  * // 27        CAP2N
00090  * // 26        VSS       GND
00091  * // 25        V4        1uF -> GND
00092  * // 24        V3        1uF -> GND
00093  * // 23        V2        1uF -> GND
00094  * // 22        V1        1uF -> GND
00095  * // 21        V0        1uF -> GND
00096  * 
00097  *
00098  * EADOG lcd(PA_7, PA_5, PC_7, PA_9, PB_6, DOGM132); // MOSI, SCK, Reset, A0, CS
00099  * 
00100  * int main() {
00101  *   // create logo
00102  *   lcd.update(MANUAL);
00103  *   lcd.rectangle(0, 0, 131, 31, 1);
00104  *   lcd.fillrect(2, 2, 4, 4, 1);
00105  *   lcd.fillrect(2, 27, 4, 29, 1);
00106  *   lcd.fillrect(61, 2, 63, 4, 1);
00107  *   lcd.fillrect(61, 27, 63, 29, 1);
00108  *   lcd.line(65, 0, 65, 31, 1);
00109  *   lcd.circle(33, 15, 10, 1);
00110  *   lcd.circle(33, 15, 6, 1);
00111  *   lcd.fillcircle(33, 15, 3, 1);
00112  *   lcd.update();
00113  *   lcd.update(AUTO);
00114  *   // create description text
00115  *   lcd.locate(70, 1);
00116  *   lcd.font((unsigned char*)ArialR12x14);
00117  *   lcd.printf("mbed");
00118  *   lcd.locate(70, 13);
00119  *   lcd.font((unsigned char*)Small_7);
00120  *   lcd.printf("EA");
00121  *   lcd.locate(70, 22);
00122  *   lcd.printf("DOGM132x-5");
00123  *
00124  *   wait(1);
00125  *   lcd.display(CONTRAST, 16); // contrast low
00126  *   wait(1);
00127  *   lcd.display(CONTRAST, 40); // contrast high
00128  *   wait(1);
00129  *   lcd.display(CONTRAST);     // contrast default
00130  *   wait(1);
00131  *   lcd.display(OFF);          // display off
00132  *   wait(1);
00133  *   lcd.display(ON);           // display on
00134  *   wait(1);
00135  *   lcd.display(SLEEP);        // display sleep
00136  *   wait(1);
00137  *   lcd.display(ON);           // display wake up
00138  *
00139  *   while(1) {                 // main loop
00140  *     lcd.display(INVERT);     // display inverted
00141  *     lcd.display(BOTTOM);     // display normal orientation
00142  *     wait(2);
00143  *     lcd.display(DEFAULT);    // display 
00144  *     lcd.display(TOPVIEW);    // display rotated
00145  *     wait(2);    
00146  *     }
00147  *   }
00148  * @endcode
00149  */
00150 class EADOG : public Stream  {
00151 
00152 public:
00153 
00154   /** create a EADOG object connected to SPI
00155     *
00156     * @param mosi pinname
00157     * @param sck pinname
00158     * @param reset pinname
00159     * @param a0 pinname
00160     * @param cs pinname
00161     *
00162     */
00163   EADOG(PinName mosi, PinName sck, PinName reset, PinName a0, PinName cs, uint8_t type);
00164 
00165   /** draw a pixel in buffer at x, y black or white
00166     *
00167     * @param x horizontal position
00168     * @param y vertical position
00169     * @param colour 1 set pixel, 0 erase pixel
00170     * there is no update, it writes the pixel only in the buffer
00171     */
00172   void pixel(int x, int y, uint8_t colour);
00173 
00174   /** draw a single point
00175     *
00176     * @param x horizontal position
00177     * @param y vertical position
00178     * @param colour 1 set pixel, 0 erase pixel
00179     *
00180     */
00181   void point(int x, int y, uint8_t colour);
00182 
00183   /** draw a 1 pixel line
00184     *
00185     * @param x0,y0 start point
00186     * @param x1,y1 end point
00187     * @param color 1 set pixel, 0 erase pixel
00188     *
00189     */
00190   void line(int x0, int y0, int x1, int y1, uint8_t colour);
00191 
00192   /** draw a rect
00193     *
00194     * @param x0,y0 top left corner
00195     * @param x1,y1 down right corner
00196     * @param color 1 set pixel, 0 erase pixel
00197     *
00198     */
00199   void rectangle(int x0, int y0, int x1, int y1, uint8_t colour);
00200 
00201   /** draw a filled rect
00202     *
00203     * @param x0,y0 top left corner
00204     * @param x1,y1 down right corner
00205     * @param color 1 set pixel, 0 erase pixel
00206     *
00207     */
00208   void fillrect(int x0, int y0, int x1, int y1, uint8_t colour);
00209 
00210   /** draw a rounded rect
00211     *
00212     * @param x0,y0 top left corner
00213     * @param x1,y1 down right corner
00214     * @param rnd radius of the rounding
00215     * @param color 1 set pixel, 0 erase pixel
00216     *
00217     */
00218   void roundrect(int x0, int y0, int x1, int y1, int rnd, uint8_t colour);
00219 
00220   /** draw a filled rounded rect
00221     *
00222     * @param x0,y0 top left corner
00223     * @param x1,y1 down right corner
00224     * @param rnd radius of the rounding
00225     * @param color 1 set pixel, 0 erase pixel
00226     *
00227     */
00228   void fillrrect(int x0, int y0, int x1, int y1, int rnd, uint8_t colour);
00229 
00230 
00231   /** draw a circle
00232     *
00233     * @param x0,y0 center
00234     * @param r radius
00235     * @param colour 1 set pixel, 0 erase pixel
00236     *
00237     */
00238   void circle(int x, int y, int r, uint8_t colour);
00239 
00240   /** draw a filled circle
00241     *
00242     * @param x0,y0 center
00243     * @param r radius
00244     * @param color 1 set pixel, 0 erase pixel
00245     *
00246     * use circle with different radius,
00247     * can miss some pixel
00248     *
00249     */
00250   void fillcircle(int x, int y, int r, uint8_t colour);
00251 
00252   /** update copy display buffer to lcd
00253     *
00254     * @param AUTO set update mode to auto, default
00255     * @param MANUELL the update function must manually set
00256     * update() copy display buffer to lcd
00257     */
00258   void update();
00259   void update(uint8_t mode);
00260 
00261   /** display functions
00262     *
00263     * @param display ON switch display on, or wake up from sleep
00264     * @param display OFF set display off
00265     * @param display SLEEP set display off and to sleep mode
00266     * @param display BOTTOM (default) set display orientation 0°
00267     * @param display TOPVIEW draw display oriention to 180°
00268     * @param display INVERT invert the pixels
00269     * @param display DEFAULT normal pixel display
00270     * @param display CONTRAST set display contrast to default
00271     *
00272     */
00273   void display(uint8_t display);
00274 
00275   /** display functions
00276     *
00277     * @param display CONTRAST set display contrast with value,
00278     * @param value sets display contrast 0 - 63, default 31
00279     *
00280     */
00281   void display(uint8_t display, uint8_t value);
00282 
00283   /** clear the screen
00284     *
00285     */
00286   void cls();
00287 
00288   /** draw a character on given position out of the active font to the LCD
00289     *
00290     * @param x x-position of char (top left)
00291     * @param y y-position
00292     * @param c char to print
00293     *
00294     */
00295   void character(uint8_t x, uint8_t y, uint8_t c);
00296 
00297   /** set top left position of char/printf
00298     *
00299     * @param x x-position
00300     * @param y y-position
00301     *
00302     */
00303   void locate(uint8_t x, uint8_t y);
00304 
00305   /** select the font to use
00306     *
00307     * @param f pointer to font array
00308     *
00309     *   font array can created with GLCD Font Creator from http://www.mikroe.com
00310     *   you have to add 4 parameter at the beginning of the font array to use:
00311     *   - the number of byte / char
00312     *   - the vertial size in pixel
00313     *   - the horizontal size in pixel
00314     *   - the number of byte per vertical line
00315     *   you also have to change the array to char[]
00316     * @code
00317     * lcd.font((unsigned char*)Small_7);
00318     * @endcode
00319     */
00320   void font(uint8_t *f);
00321 
00322   /** print bitmap to buffer
00323     *
00324     * @param bm Bitmap in flash
00325     * @param x  x start
00326     * @param y  y start
00327     *
00328     */
00329   void bitmap(Bitmap bm, int x, int y);
00330 
00331   // declarations
00332   SPI _spi;
00333   DigitalOut _reset;
00334   DigitalOut _a0;
00335   DigitalOut _cs;
00336 
00337 protected:
00338 
00339   /** stream class, put a char on the screen
00340     *
00341     * @param value char to print
00342     * @returns printed char
00343     *
00344     */
00345   virtual int _putc(int value);
00346 
00347   /** stream class, dummy
00348     *
00349     */
00350   virtual int _getc();
00351 
00352   /** init the DOGM132 LCD controller
00353     *
00354     */
00355   void init(); //Init the ST7565R LCD controller
00356 
00357   /** write data to the LCD controller
00358     *
00359     * @param dat data written to LCD controller
00360     *
00361     */
00362   void write_data(uint8_t data); // Write data to the LCD controller
00363 
00364   /** Write a command the LCD controller
00365     *
00366     * @param cmd command to be written
00367     *
00368     */
00369   void write_command(uint8_t command); // Write a command the LCD controller
00370 
00371   // Variables
00372   uint8_t *font_buffer;
00373   uint8_t char_x;
00374   uint8_t char_y;
00375   uint8_t auto_update;
00376   uint8_t width;
00377   uint8_t height;
00378   uint8_t _type;
00379   uint8_t *graphic_buffer;
00380   uint32_t graphic_buffer_size;
00381 
00382   };
00383 
00384 #endif