SPKDisplay - A mbed display class and processing imaging tools for 128x64 OLEDs using the SSD1305 driver, connected via SPI.
Dependents: SPK-DVIMXR SPK-DMXer
spk_oled_ssd1305.h@0:76bb084fa033, 2012-04-15 (annotated)
- Committer:
- tobyspark
- Date:
- Sun Apr 15 16:51:01 2012 +0000
- Revision:
- 0:76bb084fa033
- Child:
- 1:dd3faa2ab1dd
Initial commit after internal dev as part of SPK-DVIMXR
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tobyspark | 0:76bb084fa033 | 1 | // OLED display using SSD1305 driver |
tobyspark | 0:76bb084fa033 | 2 | // Copyright *spark audio-visual 2012 |
tobyspark | 0:76bb084fa033 | 3 | |
tobyspark | 0:76bb084fa033 | 4 | |
tobyspark | 0:76bb084fa033 | 5 | #ifndef SPK_OLED_SSD1305_h |
tobyspark | 0:76bb084fa033 | 6 | #define SPK_OLED_SSD1305_h |
tobyspark | 0:76bb084fa033 | 7 | |
tobyspark | 0:76bb084fa033 | 8 | #include "mbed.h" |
tobyspark | 0:76bb084fa033 | 9 | #include <string> |
tobyspark | 0:76bb084fa033 | 10 | |
tobyspark | 0:76bb084fa033 | 11 | #define bufferCount 1056 |
tobyspark | 0:76bb084fa033 | 12 | #define bufferWidth 132 |
tobyspark | 0:76bb084fa033 | 13 | #define pixelWidth 128 |
tobyspark | 0:76bb084fa033 | 14 | #define pixelHeight 64 |
tobyspark | 0:76bb084fa033 | 15 | #define pixInPage 8 |
tobyspark | 0:76bb084fa033 | 16 | #define pageCount 8 |
tobyspark | 0:76bb084fa033 | 17 | |
tobyspark | 0:76bb084fa033 | 18 | /** Display class for 128x64 OLEDs using the SSD1305 driver |
tobyspark | 0:76bb084fa033 | 19 | * ie. DENSITRON - DD-12864YO-3A |
tobyspark | 0:76bb084fa033 | 20 | * |
tobyspark | 0:76bb084fa033 | 21 | * This is a ground-up, minimal library. Currently it will display a full-screen image, draw horizontal lines, and display rows of text. |
tobyspark | 0:76bb084fa033 | 22 | * |
tobyspark | 0:76bb084fa033 | 23 | * This library includes two processing sketches to create a font and full-screen image in the required byte representations. |
tobyspark | 0:76bb084fa033 | 24 | * It won't compile without you doing that - it expects const uint8_t image[] and const uint8_t* characterBytes[] |
tobyspark | 0:76bb084fa033 | 25 | * |
tobyspark | 0:76bb084fa033 | 26 | * Terminology: |
tobyspark | 0:76bb084fa033 | 27 | * 'rows' are 8 pixel high rows across the display, 0 being the topmost and 7 the bottom. |
tobyspark | 0:76bb084fa033 | 28 | * 'lines' are single pixel lines, origin top left |
tobyspark | 0:76bb084fa033 | 29 | * |
tobyspark | 0:76bb084fa033 | 30 | * Example: |
tobyspark | 0:76bb084fa033 | 31 | * @code |
tobyspark | 0:76bb084fa033 | 32 | * SPKDisplay screen(p5, p7, p8, p10, p9) |
tobyspark | 0:76bb084fa033 | 33 | * screen.imageToBuffer(); |
tobyspark | 0:76bb084fa033 | 34 | * screen.textToBuffer("*spark OLED SSD1305",0); |
tobyspark | 0:76bb084fa033 | 35 | * screen.textToBuffer("v01",1); |
tobyspark | 0:76bb084fa033 | 36 | * screen.sendBuffer |
tobyspark | 0:76bb084fa033 | 37 | * @endcode |
tobyspark | 0:76bb084fa033 | 38 | */ |
tobyspark | 0:76bb084fa033 | 39 | class SPKDisplay |
tobyspark | 0:76bb084fa033 | 40 | { |
tobyspark | 0:76bb084fa033 | 41 | public: |
tobyspark | 0:76bb084fa033 | 42 | /** Create a display object connected via SPI |
tobyspark | 0:76bb084fa033 | 43 | * |
tobyspark | 0:76bb084fa033 | 44 | * @param mosi SPI MOSI |
tobyspark | 0:76bb084fa033 | 45 | * @param clk SPI SCK |
tobyspark | 0:76bb084fa033 | 46 | * @param cs Chip Select - a digital out pin |
tobyspark | 0:76bb084fa033 | 47 | * @param dc Data/Command - a digital out pin |
tobyspark | 0:76bb084fa033 | 48 | * @param res Reset - a digital out pin |
tobyspark | 0:76bb084fa033 | 49 | * @param debugSerial An optional serial object to log to |
tobyspark | 0:76bb084fa033 | 50 | */ |
tobyspark | 0:76bb084fa033 | 51 | SPKDisplay(PinName mosi, PinName clk, PinName cs, PinName dc, PinName res, Serial *debugSerial = NULL); |
tobyspark | 0:76bb084fa033 | 52 | |
tobyspark | 0:76bb084fa033 | 53 | /** Completely clear the object's display representation */ |
tobyspark | 0:76bb084fa033 | 54 | void clearBuffer(); |
tobyspark | 0:76bb084fa033 | 55 | |
tobyspark | 0:76bb084fa033 | 56 | /** Clear a row of the object's display representation |
tobyspark | 0:76bb084fa033 | 57 | * |
tobyspark | 0:76bb084fa033 | 58 | * @param row The row to clear. |
tobyspark | 0:76bb084fa033 | 59 | */ |
tobyspark | 0:76bb084fa033 | 60 | void clearBufferRow(int row); |
tobyspark | 0:76bb084fa033 | 61 | |
tobyspark | 0:76bb084fa033 | 62 | /** Replace the object\s display representation with the contents of image[] */ |
tobyspark | 0:76bb084fa033 | 63 | void imageToBuffer(); |
tobyspark | 0:76bb084fa033 | 64 | |
tobyspark | 0:76bb084fa033 | 65 | /** Draw a horizontal line in the object's display representation |
tobyspark | 0:76bb084fa033 | 66 | * |
tobyspark | 0:76bb084fa033 | 67 | * @param y The y position of the line to draw |
tobyspark | 0:76bb084fa033 | 68 | */ |
tobyspark | 0:76bb084fa033 | 69 | void horizLineToBuffer(int y); |
tobyspark | 0:76bb084fa033 | 70 | |
tobyspark | 0:76bb084fa033 | 71 | /** Write a line of text in the object's display representation |
tobyspark | 0:76bb084fa033 | 72 | * |
tobyspark | 0:76bb084fa033 | 73 | * @param message The text to write. The text will be truncated if longer than the screen's width. |
tobyspark | 0:76bb084fa033 | 74 | * @param row The row in which to write the text |
tobyspark | 0:76bb084fa033 | 75 | */ |
tobyspark | 0:76bb084fa033 | 76 | void textToBuffer(std::string message, int row); |
tobyspark | 0:76bb084fa033 | 77 | |
tobyspark | 0:76bb084fa033 | 78 | /** Send the object's display representation to the OLED |
tobyspark | 0:76bb084fa033 | 79 | * |
tobyspark | 0:76bb084fa033 | 80 | * You can safely call this once per main loop, it will only transmit the buffer contents if there has been an update |
tobyspark | 0:76bb084fa033 | 81 | */ |
tobyspark | 0:76bb084fa033 | 82 | void sendBuffer(); |
tobyspark | 0:76bb084fa033 | 83 | |
tobyspark | 0:76bb084fa033 | 84 | private: |
tobyspark | 0:76bb084fa033 | 85 | SPI *spi; |
tobyspark | 0:76bb084fa033 | 86 | DigitalOut *cs; |
tobyspark | 0:76bb084fa033 | 87 | DigitalOut *dc; |
tobyspark | 0:76bb084fa033 | 88 | DigitalOut *res; |
tobyspark | 0:76bb084fa033 | 89 | |
tobyspark | 0:76bb084fa033 | 90 | Serial *debug; |
tobyspark | 0:76bb084fa033 | 91 | uint8_t buffer[bufferCount]; |
tobyspark | 0:76bb084fa033 | 92 | |
tobyspark | 0:76bb084fa033 | 93 | bool bufferHasChanged; |
tobyspark | 0:76bb084fa033 | 94 | |
tobyspark | 0:76bb084fa033 | 95 | void setup(); |
tobyspark | 0:76bb084fa033 | 96 | }; |
tobyspark | 0:76bb084fa033 | 97 | |
tobyspark | 0:76bb084fa033 | 98 | #endif |