SSD1306 LCD 96x16 model
Dependents: testSoftware8_alles_display
Fork of ssd1306_library by
ssd1306.cpp@4:35757c8b7625, 2017-11-01 (annotated)
- Committer:
- rodriguj
- Date:
- Wed Nov 01 16:19:50 2017 +0000
- Revision:
- 4:35757c8b7625
- Parent:
- 3:bb6fba3e84ff
- Child:
- 8:09b1578f93d9
Attempting to sucess on autogenerating documentation from the source code to have some API docs for users to review
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rodriguj | 3:bb6fba3e84ff | 1 | /* |
rodriguj | 4:35757c8b7625 | 2 | * ssd1306.h |
rodriguj | 3:bb6fba3e84ff | 3 | * |
rodriguj | 3:bb6fba3e84ff | 4 | * Created on: 20 oct. 2017 |
rodriguj | 3:bb6fba3e84ff | 5 | * Author: Miguel Angel Rodriguez Jodar |
rodriguj | 3:bb6fba3e84ff | 6 | * |
rodriguj | 3:bb6fba3e84ff | 7 | * Based upon Adafruit library. |
rodriguj | 3:bb6fba3e84ff | 8 | * GPL licensed. |
rodriguj | 3:bb6fba3e84ff | 9 | * |
rodriguj | 3:bb6fba3e84ff | 10 | */ |
rodriguj | 3:bb6fba3e84ff | 11 | |
rodriguj | 0:3d84b3bfb794 | 12 | #include "ssd1306.h" |
rodriguj | 0:3d84b3bfb794 | 13 | #include "mbed.h" |
rodriguj | 0:3d84b3bfb794 | 14 | |
rodriguj | 4:35757c8b7625 | 15 | /* I believe this charset was taken from the compilation from Joseph Gil years ago |
rodriguj | 4:35757c8b7625 | 16 | * when I needed a charset for a different (FPGA) project, but I cannot remember |
rodriguj | 4:35757c8b7625 | 17 | * exactly the website I took it from. |
rodriguj | 4:35757c8b7625 | 18 | * What I do remember is that the owner of the website claimed that this charset |
rodriguj | 4:35757c8b7625 | 19 | * is in the public domain. |
rodriguj | 4:35757c8b7625 | 20 | * This a complete (256 ASCII codes) 8x8 charset, using the 437 page code (original IBM) |
rodriguj | 4:35757c8b7625 | 21 | * so you can use its graphic blocks to build decent text based GUIs without the need |
rodriguj | 4:35757c8b7625 | 22 | * to use plot, line and circle primitives |
rodriguj | 4:35757c8b7625 | 23 | */ |
rodriguj | 0:3d84b3bfb794 | 24 | static const char charset[2048] = { |
rodriguj | 0:3d84b3bfb794 | 25 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x81, |
rodriguj | 0:3d84b3bfb794 | 26 | 0x95, 0xB1, 0xB1, 0x95, 0x81, 0x7E, 0x7E, 0xFF, 0xEB, 0xCF, |
rodriguj | 0:3d84b3bfb794 | 27 | 0xCF, 0xEB, 0xFF, 0x7E, 0x0E, 0x1F, 0x3F, 0x7E, 0x3F, 0x1F, |
rodriguj | 0:3d84b3bfb794 | 28 | 0x0E, 0x00, 0x08, 0x1C, 0x3E, 0x7F, 0x3E, 0x1C, 0x08, 0x00, |
rodriguj | 0:3d84b3bfb794 | 29 | 0x38, 0x3A, 0x9F, 0xFF, 0x9F, 0x3A, 0x38, 0x00, 0x18, 0x3C, |
rodriguj | 0:3d84b3bfb794 | 30 | 0xBE, 0xFF, 0xBE, 0x3C, 0x18, 0x00, 0x00, 0x00, 0x18, 0x3C, |
rodriguj | 0:3d84b3bfb794 | 31 | 0x3C, 0x18, 0x00, 0x00, 0xFF, 0xFF, 0xE7, 0xC3, 0xC3, 0xE7, |
rodriguj | 0:3d84b3bfb794 | 32 | 0xFF, 0xFF, 0x00, 0x3C, 0x66, 0x42, 0x42, 0x66, 0x3C, 0x00, |
rodriguj | 0:3d84b3bfb794 | 33 | 0xFF, 0xC3, 0x99, 0xBD, 0xBD, 0x99, 0xC3, 0xFF, 0x70, 0xF8, |
rodriguj | 0:3d84b3bfb794 | 34 | 0x88, 0x88, 0xFD, 0x7F, 0x07, 0x0F, 0x00, 0x4E, 0x5F, 0xF1, |
rodriguj | 0:3d84b3bfb794 | 35 | 0xF1, 0x5F, 0x4E, 0x00, 0xC0, 0xE0, 0xFF, 0x7F, 0x05, 0x05, |
rodriguj | 0:3d84b3bfb794 | 36 | 0x07, 0x07, 0xC0, 0xFF, 0x7F, 0x05, 0x05, 0x65, 0x7F, 0x3F, |
rodriguj | 0:3d84b3bfb794 | 37 | 0x5A, 0x5A, 0x3C, 0xE7, 0xE7, 0x3C, 0x5A, 0x5A, 0x7F, 0x3E, |
rodriguj | 0:3d84b3bfb794 | 38 | 0x3E, 0x1C, 0x1C, 0x08, 0x08, 0x00, 0x08, 0x08, 0x1C, 0x1C, |
rodriguj | 0:3d84b3bfb794 | 39 | 0x3E, 0x3E, 0x7F, 0x00, 0x00, 0x24, 0x66, 0xFF, 0xFF, 0x66, |
rodriguj | 0:3d84b3bfb794 | 40 | 0x24, 0x00, 0x00, 0x5F, 0x5F, 0x00, 0x00, 0x5F, 0x5F, 0x00, |
rodriguj | 0:3d84b3bfb794 | 41 | 0x06, 0x0F, 0x09, 0x7F, 0x7F, 0x01, 0x7F, 0x7F, 0x40, 0x9A, |
rodriguj | 0:3d84b3bfb794 | 42 | 0xBF, 0xA5, 0xA5, 0xFD, 0x59, 0x02, 0x00, 0x70, 0x70, 0x70, |
rodriguj | 0:3d84b3bfb794 | 43 | 0x70, 0x70, 0x70, 0x00, 0x80, 0x94, 0xB6, 0xFF, 0xFF, 0xB6, |
rodriguj | 0:3d84b3bfb794 | 44 | 0x94, 0x80, 0x00, 0x04, 0x06, 0x7F, 0x7F, 0x06, 0x04, 0x00, |
rodriguj | 0:3d84b3bfb794 | 45 | 0x00, 0x10, 0x30, 0x7F, 0x7F, 0x30, 0x10, 0x00, 0x08, 0x08, |
rodriguj | 0:3d84b3bfb794 | 46 | 0x08, 0x2A, 0x3E, 0x1C, 0x08, 0x00, 0x08, 0x1C, 0x3E, 0x2A, |
rodriguj | 0:3d84b3bfb794 | 47 | 0x08, 0x08, 0x08, 0x00, 0x3C, 0x3C, 0x20, 0x20, 0x20, 0x20, |
rodriguj | 0:3d84b3bfb794 | 48 | 0x20, 0x00, 0x08, 0x1C, 0x3E, 0x08, 0x08, 0x3E, 0x1C, 0x08, |
rodriguj | 0:3d84b3bfb794 | 49 | 0x30, 0x38, 0x3C, 0x3E, 0x3E, 0x3C, 0x38, 0x30, 0x06, 0x0E, |
rodriguj | 0:3d84b3bfb794 | 50 | 0x1E, 0x3E, 0x3E, 0x1E, 0x0E, 0x06, 0x00, 0x00, 0x00, 0x00, |
rodriguj | 0:3d84b3bfb794 | 51 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x5F, 0x5F, 0x06, |
rodriguj | 0:3d84b3bfb794 | 52 | 0x00, 0x00, 0x00, 0x03, 0x07, 0x00, 0x00, 0x07, 0x03, 0x00, |
rodriguj | 0:3d84b3bfb794 | 53 | 0x14, 0x7F, 0x7F, 0x14, 0x7F, 0x7F, 0x14, 0x00, 0x00, 0x24, |
rodriguj | 0:3d84b3bfb794 | 54 | 0x2E, 0x6B, 0x6B, 0x3A, 0x12, 0x00, 0x46, 0x66, 0x30, 0x18, |
rodriguj | 0:3d84b3bfb794 | 55 | 0x0C, 0x66, 0x62, 0x00, 0x30, 0x7A, 0x4F, 0x5D, 0x37, 0x7A, |
rodriguj | 0:3d84b3bfb794 | 56 | 0x48, 0x00, 0x00, 0x00, 0x04, 0x07, 0x03, 0x00, 0x00, 0x00, |
rodriguj | 0:3d84b3bfb794 | 57 | 0x00, 0x00, 0x1C, 0x3E, 0x63, 0x41, 0x00, 0x00, 0x00, 0x00, |
rodriguj | 0:3d84b3bfb794 | 58 | 0x41, 0x63, 0x3E, 0x1C, 0x00, 0x00, 0x08, 0x2A, 0x3E, 0x1C, |
rodriguj | 0:3d84b3bfb794 | 59 | 0x1C, 0x3E, 0x2A, 0x08, 0x00, 0x08, 0x08, 0x3E, 0x3E, 0x08, |
rodriguj | 0:3d84b3bfb794 | 60 | 0x08, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x60, 0x00, 0x00, 0x00, |
rodriguj | 0:3d84b3bfb794 | 61 | 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, |
rodriguj | 0:3d84b3bfb794 | 62 | 0x00, 0x60, 0x60, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x0C, |
rodriguj | 0:3d84b3bfb794 | 63 | 0x06, 0x03, 0x01, 0x00, 0x1C, 0x3E, 0x63, 0x49, 0x63, 0x3E, |
rodriguj | 0:3d84b3bfb794 | 64 | 0x1C, 0x00, 0x00, 0x40, 0x42, 0x7F, 0x7F, 0x40, 0x40, 0x00, |
rodriguj | 0:3d84b3bfb794 | 65 | 0x42, 0x63, 0x71, 0x59, 0x49, 0x6F, 0x66, 0x00, 0x22, 0x63, |
rodriguj | 0:3d84b3bfb794 | 66 | 0x49, 0x49, 0x49, 0x7F, 0x36, 0x00, 0x18, 0x1C, 0x16, 0x53, |
rodriguj | 0:3d84b3bfb794 | 67 | 0x7F, 0x7F, 0x50, 0x00, 0x2F, 0x6F, 0x49, 0x49, 0x49, 0x79, |
rodriguj | 0:3d84b3bfb794 | 68 | 0x31, 0x00, 0x3C, 0x7E, 0x4B, 0x49, 0x49, 0x78, 0x30, 0x00, |
rodriguj | 0:3d84b3bfb794 | 69 | 0x03, 0x03, 0x71, 0x79, 0x0D, 0x07, 0x03, 0x00, 0x36, 0x7F, |
rodriguj | 0:3d84b3bfb794 | 70 | 0x49, 0x49, 0x49, 0x7F, 0x36, 0x00, 0x06, 0x4F, 0x49, 0x49, |
rodriguj | 0:3d84b3bfb794 | 71 | 0x69, 0x3F, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x00, |
rodriguj | 0:3d84b3bfb794 | 72 | 0x00, 0x00, 0x00, 0x00, 0x80, 0xE6, 0x66, 0x00, 0x00, 0x00, |
rodriguj | 0:3d84b3bfb794 | 73 | 0x00, 0x00, 0x08, 0x1C, 0x36, 0x63, 0x41, 0x00, 0x00, 0x24, |
rodriguj | 0:3d84b3bfb794 | 74 | 0x24, 0x24, 0x24, 0x24, 0x24, 0x00, 0x00, 0x41, 0x63, 0x36, |
rodriguj | 0:3d84b3bfb794 | 75 | 0x1C, 0x08, 0x00, 0x00, 0x02, 0x03, 0x01, 0x59, 0x5D, 0x07, |
rodriguj | 0:3d84b3bfb794 | 76 | 0x02, 0x00, 0x3E, 0x7F, 0x41, 0x5D, 0x5D, 0x1F, 0x1E, 0x00, |
rodriguj | 0:3d84b3bfb794 | 77 | 0x7C, 0x7E, 0x0B, 0x09, 0x0B, 0x7E, 0x7C, 0x00, 0x41, 0x7F, |
rodriguj | 0:3d84b3bfb794 | 78 | 0x7F, 0x49, 0x49, 0x7F, 0x36, 0x00, 0x1C, 0x3E, 0x63, 0x41, |
rodriguj | 0:3d84b3bfb794 | 79 | 0x41, 0x63, 0x22, 0x00, 0x41, 0x7F, 0x7F, 0x41, 0x63, 0x3E, |
rodriguj | 0:3d84b3bfb794 | 80 | 0x1C, 0x00, 0x41, 0x7F, 0x7F, 0x49, 0x5D, 0x41, 0x63, 0x00, |
rodriguj | 0:3d84b3bfb794 | 81 | 0x41, 0x7F, 0x7F, 0x49, 0x1D, 0x01, 0x03, 0x00, 0x1C, 0x3E, |
rodriguj | 0:3d84b3bfb794 | 82 | 0x63, 0x41, 0x51, 0x33, 0x72, 0x00, 0x7F, 0x7F, 0x08, 0x08, |
rodriguj | 0:3d84b3bfb794 | 83 | 0x08, 0x7F, 0x7F, 0x00, 0x00, 0x00, 0x41, 0x7F, 0x7F, 0x41, |
rodriguj | 0:3d84b3bfb794 | 84 | 0x00, 0x00, 0x30, 0x70, 0x40, 0x41, 0x7F, 0x3F, 0x01, 0x00, |
rodriguj | 0:3d84b3bfb794 | 85 | 0x41, 0x7F, 0x7F, 0x08, 0x1C, 0x77, 0x63, 0x00, 0x41, 0x7F, |
rodriguj | 0:3d84b3bfb794 | 86 | 0x7F, 0x41, 0x40, 0x60, 0x70, 0x00, 0x7F, 0x7F, 0x0E, 0x1C, |
rodriguj | 0:3d84b3bfb794 | 87 | 0x0E, 0x7F, 0x7F, 0x00, 0x7F, 0x7F, 0x06, 0x0C, 0x18, 0x7F, |
rodriguj | 0:3d84b3bfb794 | 88 | 0x7F, 0x00, 0x3E, 0x7F, 0x41, 0x41, 0x41, 0x7F, 0x3E, 0x00, |
rodriguj | 0:3d84b3bfb794 | 89 | 0x41, 0x7F, 0x7F, 0x49, 0x09, 0x0F, 0x06, 0x00, 0x3E, 0x7F, |
rodriguj | 0:3d84b3bfb794 | 90 | 0x41, 0x41, 0xE1, 0xFF, 0xBE, 0x00, 0x41, 0x7F, 0x7F, 0x09, |
rodriguj | 0:3d84b3bfb794 | 91 | 0x19, 0x7F, 0x66, 0x00, 0x00, 0x22, 0x67, 0x4D, 0x59, 0x73, |
rodriguj | 0:3d84b3bfb794 | 92 | 0x22, 0x00, 0x00, 0x07, 0x43, 0x7F, 0x7F, 0x43, 0x07, 0x00, |
rodriguj | 0:3d84b3bfb794 | 93 | 0x3F, 0x7F, 0x40, 0x40, 0x40, 0x7F, 0x3F, 0x00, 0x1F, 0x3F, |
rodriguj | 0:3d84b3bfb794 | 94 | 0x60, 0x40, 0x60, 0x3F, 0x1F, 0x00, 0x3F, 0x7F, 0x60, 0x38, |
rodriguj | 0:3d84b3bfb794 | 95 | 0x60, 0x7F, 0x3F, 0x00, 0x63, 0x77, 0x1C, 0x08, 0x1C, 0x77, |
rodriguj | 0:3d84b3bfb794 | 96 | 0x63, 0x00, 0x00, 0x07, 0x4F, 0x78, 0x78, 0x4F, 0x07, 0x00, |
rodriguj | 0:3d84b3bfb794 | 97 | 0x47, 0x63, 0x71, 0x59, 0x4D, 0x67, 0x73, 0x00, 0x00, 0x00, |
rodriguj | 0:3d84b3bfb794 | 98 | 0x7F, 0x7F, 0x41, 0x41, 0x00, 0x00, 0x01, 0x03, 0x06, 0x0C, |
rodriguj | 0:3d84b3bfb794 | 99 | 0x18, 0x30, 0x60, 0x00, 0x00, 0x00, 0x41, 0x41, 0x7F, 0x7F, |
rodriguj | 0:3d84b3bfb794 | 100 | 0x00, 0x00, 0x08, 0x0C, 0x06, 0x03, 0x06, 0x0C, 0x08, 0x00, |
rodriguj | 0:3d84b3bfb794 | 101 | 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, |
rodriguj | 0:3d84b3bfb794 | 102 | 0x01, 0x03, 0x06, 0x04, 0x00, 0x00, 0x20, 0x74, 0x54, 0x54, |
rodriguj | 0:3d84b3bfb794 | 103 | 0x3C, 0x78, 0x40, 0x00, 0x41, 0x7F, 0x3F, 0x44, 0x44, 0x7C, |
rodriguj | 0:3d84b3bfb794 | 104 | 0x38, 0x00, 0x38, 0x7C, 0x44, 0x44, 0x44, 0x6C, 0x28, 0x00, |
rodriguj | 0:3d84b3bfb794 | 105 | 0x38, 0x7C, 0x44, 0x45, 0x3F, 0x7F, 0x40, 0x00, 0x38, 0x7C, |
rodriguj | 0:3d84b3bfb794 | 106 | 0x54, 0x54, 0x54, 0x5C, 0x18, 0x00, 0x48, 0x7E, 0x7F, 0x49, |
rodriguj | 0:3d84b3bfb794 | 107 | 0x09, 0x03, 0x02, 0x00, 0x98, 0xBC, 0xA4, 0xA4, 0xF8, 0x7C, |
rodriguj | 0:3d84b3bfb794 | 108 | 0x04, 0x00, 0x41, 0x7F, 0x7F, 0x08, 0x04, 0x7C, 0x78, 0x00, |
rodriguj | 0:3d84b3bfb794 | 109 | 0x00, 0x00, 0x44, 0x7D, 0x7D, 0x40, 0x00, 0x00, 0x00, 0x60, |
rodriguj | 0:3d84b3bfb794 | 110 | 0xE0, 0x80, 0x80, 0xFD, 0x7D, 0x00, 0x41, 0x7F, 0x7F, 0x10, |
rodriguj | 0:3d84b3bfb794 | 111 | 0x38, 0x6C, 0x44, 0x00, 0x00, 0x00, 0x41, 0x7F, 0x7F, 0x40, |
rodriguj | 0:3d84b3bfb794 | 112 | 0x00, 0x00, 0x7C, 0x7C, 0x0C, 0x78, 0x0C, 0x7C, 0x78, 0x00, |
rodriguj | 0:3d84b3bfb794 | 113 | 0x04, 0x7C, 0x78, 0x04, 0x04, 0x7C, 0x78, 0x00, 0x38, 0x7C, |
rodriguj | 0:3d84b3bfb794 | 114 | 0x44, 0x44, 0x44, 0x7C, 0x38, 0x00, 0x84, 0xFC, 0xF8, 0xA4, |
rodriguj | 0:3d84b3bfb794 | 115 | 0x24, 0x3C, 0x18, 0x00, 0x18, 0x3C, 0x24, 0xA4, 0xF8, 0xFC, |
rodriguj | 0:3d84b3bfb794 | 116 | 0x84, 0x00, 0x44, 0x7C, 0x78, 0x4C, 0x04, 0x0C, 0x08, 0x00, |
rodriguj | 0:3d84b3bfb794 | 117 | 0x48, 0x5C, 0x54, 0x54, 0x54, 0x74, 0x24, 0x00, 0x04, 0x04, |
rodriguj | 0:3d84b3bfb794 | 118 | 0x3F, 0x7F, 0x44, 0x64, 0x20, 0x00, 0x3C, 0x7C, 0x40, 0x40, |
rodriguj | 0:3d84b3bfb794 | 119 | 0x3C, 0x7C, 0x40, 0x00, 0x1C, 0x3C, 0x60, 0x40, 0x60, 0x3C, |
rodriguj | 0:3d84b3bfb794 | 120 | 0x1C, 0x00, 0x3C, 0x7C, 0x60, 0x38, 0x60, 0x7C, 0x3C, 0x00, |
rodriguj | 0:3d84b3bfb794 | 121 | 0x44, 0x6C, 0x38, 0x10, 0x38, 0x6C, 0x44, 0x00, 0x9C, 0xBC, |
rodriguj | 0:3d84b3bfb794 | 122 | 0xA0, 0xA0, 0xA0, 0xFC, 0x7C, 0x00, 0x00, 0x4C, 0x64, 0x74, |
rodriguj | 0:3d84b3bfb794 | 123 | 0x5C, 0x4C, 0x64, 0x00, 0x00, 0x08, 0x08, 0x3E, 0x77, 0x41, |
rodriguj | 0:3d84b3bfb794 | 124 | 0x41, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x7F, 0x00, 0x00, 0x00, |
rodriguj | 0:3d84b3bfb794 | 125 | 0x00, 0x41, 0x41, 0x77, 0x3E, 0x08, 0x08, 0x00, 0x02, 0x03, |
rodriguj | 0:3d84b3bfb794 | 126 | 0x01, 0x03, 0x02, 0x03, 0x01, 0x00, 0x70, 0x78, 0x4C, 0x46, |
rodriguj | 0:3d84b3bfb794 | 127 | 0x4C, 0x78, 0x70, 0x00, 0x1E, 0xBF, 0xA1, 0xA1, 0xE1, 0x73, |
rodriguj | 0:3d84b3bfb794 | 128 | 0x12, 0x00, 0x3D, 0x7D, 0x40, 0x40, 0x3D, 0x7D, 0x40, 0x00, |
rodriguj | 0:3d84b3bfb794 | 129 | 0x38, 0x7C, 0x54, 0x56, 0x57, 0x5D, 0x18, 0x00, 0x22, 0x75, |
rodriguj | 0:3d84b3bfb794 | 130 | 0x55, 0x55, 0x3D, 0x79, 0x42, 0x00, 0x21, 0x75, 0x54, 0x54, |
rodriguj | 0:3d84b3bfb794 | 131 | 0x3C, 0x79, 0x41, 0x00, 0x20, 0x74, 0x55, 0x57, 0x3E, 0x78, |
rodriguj | 0:3d84b3bfb794 | 132 | 0x40, 0x00, 0x20, 0x74, 0x57, 0x57, 0x3C, 0x78, 0x40, 0x00, |
rodriguj | 0:3d84b3bfb794 | 133 | 0x18, 0x3C, 0xA4, 0xA4, 0xE4, 0x64, 0x24, 0x00, 0x3A, 0x7D, |
rodriguj | 0:3d84b3bfb794 | 134 | 0x55, 0x55, 0x55, 0x5D, 0x1A, 0x00, 0x39, 0x7D, 0x54, 0x54, |
rodriguj | 0:3d84b3bfb794 | 135 | 0x54, 0x5D, 0x19, 0x00, 0x38, 0x7C, 0x55, 0x57, 0x56, 0x5C, |
rodriguj | 0:3d84b3bfb794 | 136 | 0x18, 0x00, 0x00, 0x01, 0x45, 0x7C, 0x7C, 0x41, 0x01, 0x00, |
rodriguj | 0:3d84b3bfb794 | 137 | 0x02, 0x01, 0x45, 0x7D, 0x7D, 0x41, 0x02, 0x00, 0x00, 0x00, |
rodriguj | 0:3d84b3bfb794 | 138 | 0x49, 0x7B, 0x7A, 0x40, 0x00, 0x00, 0x79, 0x7D, 0x16, 0x12, |
rodriguj | 0:3d84b3bfb794 | 139 | 0x16, 0x7D, 0x79, 0x00, 0x78, 0x7E, 0x17, 0x15, 0x17, 0x7E, |
rodriguj | 0:3d84b3bfb794 | 140 | 0x78, 0x00, 0x7C, 0x7C, 0x56, 0x57, 0x55, 0x44, 0x44, 0x00, |
rodriguj | 0:3d84b3bfb794 | 141 | 0x20, 0x74, 0x54, 0x7C, 0x7C, 0x54, 0x54, 0x00, 0x7C, 0x7E, |
rodriguj | 0:3d84b3bfb794 | 142 | 0x0B, 0x09, 0x7F, 0x7F, 0x49, 0x00, 0x3A, 0x7D, 0x45, 0x45, |
rodriguj | 0:3d84b3bfb794 | 143 | 0x45, 0x7D, 0x3A, 0x00, 0x39, 0x7D, 0x44, 0x44, 0x44, 0x7D, |
rodriguj | 0:3d84b3bfb794 | 144 | 0x39, 0x00, 0x38, 0x7C, 0x45, 0x47, 0x46, 0x7C, 0x38, 0x00, |
rodriguj | 0:3d84b3bfb794 | 145 | 0x3A, 0x79, 0x41, 0x41, 0x39, 0x7A, 0x40, 0x00, 0x3C, 0x7D, |
rodriguj | 0:3d84b3bfb794 | 146 | 0x43, 0x42, 0x3C, 0x7C, 0x40, 0x00, 0x9D, 0xBD, 0xA0, 0xA0, |
rodriguj | 0:3d84b3bfb794 | 147 | 0xA0, 0xFD, 0x7D, 0x00, 0x19, 0x3D, 0x66, 0x42, 0x66, 0x3D, |
rodriguj | 0:3d84b3bfb794 | 148 | 0x19, 0x00, 0x3D, 0x7D, 0x40, 0x40, 0x40, 0x7D, 0x3D, 0x00, |
rodriguj | 0:3d84b3bfb794 | 149 | 0x18, 0x3C, 0x24, 0xE7, 0xE7, 0x24, 0x24, 0x00, 0x48, 0x7E, |
rodriguj | 0:3d84b3bfb794 | 150 | 0x7F, 0x49, 0x43, 0x66, 0x20, 0x00, 0x00, 0x2B, 0x2F, 0xFC, |
rodriguj | 0:3d84b3bfb794 | 151 | 0xFC, 0x2F, 0x2B, 0x00, 0xFF, 0xFF, 0x09, 0x09, 0x2F, 0xF6, |
rodriguj | 0:3d84b3bfb794 | 152 | 0xF8, 0xA0, 0x20, 0x60, 0x48, 0x7E, 0x3F, 0x09, 0x03, 0x02, |
rodriguj | 0:3d84b3bfb794 | 153 | 0x20, 0x74, 0x56, 0x57, 0x3D, 0x78, 0x40, 0x00, 0x00, 0x00, |
rodriguj | 0:3d84b3bfb794 | 154 | 0x48, 0x7A, 0x7B, 0x41, 0x00, 0x00, 0x38, 0x7C, 0x44, 0x46, |
rodriguj | 0:3d84b3bfb794 | 155 | 0x47, 0x7D, 0x38, 0x00, 0x3C, 0x7C, 0x42, 0x43, 0x3D, 0x7C, |
rodriguj | 0:3d84b3bfb794 | 156 | 0x40, 0x00, 0x0A, 0x7B, 0x71, 0x0B, 0x0A, 0x7B, 0x71, 0x00, |
rodriguj | 0:3d84b3bfb794 | 157 | 0x7A, 0x7B, 0x19, 0x33, 0x62, 0x7B, 0x79, 0x00, 0x00, 0x26, |
rodriguj | 0:3d84b3bfb794 | 158 | 0x2F, 0x29, 0x2F, 0x2F, 0x28, 0x00, 0x00, 0x26, 0x2F, 0x29, |
rodriguj | 0:3d84b3bfb794 | 159 | 0x2F, 0x26, 0x00, 0x00, 0x00, 0x20, 0x70, 0x5D, 0x4D, 0x40, |
rodriguj | 0:3d84b3bfb794 | 160 | 0x60, 0x20, 0x38, 0x38, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, |
rodriguj | 0:3d84b3bfb794 | 161 | 0x08, 0x08, 0x08, 0x08, 0x08, 0x38, 0x38, 0x00, 0x42, 0x6F, |
rodriguj | 0:3d84b3bfb794 | 162 | 0x3F, 0x18, 0xCC, 0xEE, 0xBB, 0x91, 0x42, 0x6F, 0x3F, 0x58, |
rodriguj | 0:3d84b3bfb794 | 163 | 0x6C, 0xD6, 0xFB, 0x41, 0x00, 0x00, 0x30, 0x7D, 0x7D, 0x30, |
rodriguj | 0:3d84b3bfb794 | 164 | 0x00, 0x00, 0x08, 0x1C, 0x36, 0x22, 0x08, 0x1C, 0x36, 0x22, |
rodriguj | 0:3d84b3bfb794 | 165 | 0x22, 0x36, 0x1C, 0x08, 0x22, 0x36, 0x1C, 0x08, 0xAA, 0x00, |
rodriguj | 0:3d84b3bfb794 | 166 | 0x55, 0x00, 0xAA, 0x00, 0x55, 0x00, 0xAA, 0x55, 0xAA, 0x55, |
rodriguj | 0:3d84b3bfb794 | 167 | 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0xFF, 0x55, 0xFF, 0xAA, 0xFF, |
rodriguj | 0:3d84b3bfb794 | 168 | 0x55, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, |
rodriguj | 0:3d84b3bfb794 | 169 | 0x10, 0x10, 0x10, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x14, 0x14, |
rodriguj | 0:3d84b3bfb794 | 170 | 0x14, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x10, 0x10, 0xFF, 0xFF, |
rodriguj | 0:3d84b3bfb794 | 171 | 0x00, 0xFF, 0xFF, 0x00, 0x10, 0x10, 0xF0, 0xF0, 0x10, 0xF0, |
rodriguj | 0:3d84b3bfb794 | 172 | 0xF0, 0x00, 0x14, 0x14, 0x14, 0xFC, 0xFC, 0x00, 0x00, 0x00, |
rodriguj | 0:3d84b3bfb794 | 173 | 0x14, 0x14, 0xF7, 0xF7, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, |
rodriguj | 0:3d84b3bfb794 | 174 | 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0x14, 0x14, 0xF4, 0xF4, |
rodriguj | 0:3d84b3bfb794 | 175 | 0x04, 0xFC, 0xFC, 0x00, 0x14, 0x14, 0x17, 0x17, 0x10, 0x1F, |
rodriguj | 0:3d84b3bfb794 | 176 | 0x1F, 0x00, 0x10, 0x10, 0x1F, 0x1F, 0x10, 0x1F, 0x1F, 0x00, |
rodriguj | 0:3d84b3bfb794 | 177 | 0x14, 0x14, 0x14, 0x1F, 0x1F, 0x00, 0x00, 0x00, 0x10, 0x10, |
rodriguj | 0:3d84b3bfb794 | 178 | 0x10, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, |
rodriguj | 0:3d84b3bfb794 | 179 | 0x1F, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1F, 0x1F, 0x10, |
rodriguj | 0:3d84b3bfb794 | 180 | 0x10, 0x10, 0x10, 0x10, 0x10, 0xF0, 0xF0, 0x10, 0x10, 0x10, |
rodriguj | 0:3d84b3bfb794 | 181 | 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x10, 0x10, 0x10, 0x10, 0x10, |
rodriguj | 0:3d84b3bfb794 | 182 | 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0xFF, |
rodriguj | 0:3d84b3bfb794 | 183 | 0xFF, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x14, |
rodriguj | 0:3d84b3bfb794 | 184 | 0x14, 0x14, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x10, |
rodriguj | 0:3d84b3bfb794 | 185 | 0x00, 0x00, 0x1F, 0x1F, 0x10, 0x17, 0x17, 0x14, 0x00, 0x00, |
rodriguj | 0:3d84b3bfb794 | 186 | 0xFC, 0xFC, 0x04, 0xF4, 0xF4, 0x14, 0x14, 0x14, 0x17, 0x17, |
rodriguj | 0:3d84b3bfb794 | 187 | 0x10, 0x17, 0x17, 0x14, 0x14, 0x14, 0xF4, 0xF4, 0x04, 0xF4, |
rodriguj | 0:3d84b3bfb794 | 188 | 0xF4, 0x14, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0xF7, 0xF7, 0x14, |
rodriguj | 0:3d84b3bfb794 | 189 | 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, |
rodriguj | 0:3d84b3bfb794 | 190 | 0xF7, 0xF7, 0x00, 0xF7, 0xF7, 0x14, 0x14, 0x14, 0x14, 0x17, |
rodriguj | 0:3d84b3bfb794 | 191 | 0x17, 0x14, 0x14, 0x14, 0x10, 0x10, 0x1F, 0x1F, 0x10, 0x1F, |
rodriguj | 0:3d84b3bfb794 | 192 | 0x1F, 0x10, 0x14, 0x14, 0x14, 0xF4, 0xF4, 0x14, 0x14, 0x14, |
rodriguj | 0:3d84b3bfb794 | 193 | 0x10, 0x10, 0xF0, 0xF0, 0x10, 0xF0, 0xF0, 0x10, 0x00, 0x00, |
rodriguj | 0:3d84b3bfb794 | 194 | 0x1F, 0x1F, 0x10, 0x1F, 0x1F, 0x10, 0x00, 0x00, 0x00, 0x1F, |
rodriguj | 0:3d84b3bfb794 | 195 | 0x1F, 0x14, 0x14, 0x14, 0x00, 0x00, 0x00, 0xFC, 0xFC, 0x14, |
rodriguj | 0:3d84b3bfb794 | 196 | 0x14, 0x14, 0x00, 0x00, 0xF0, 0xF0, 0x10, 0xF0, 0xF0, 0x10, |
rodriguj | 0:3d84b3bfb794 | 197 | 0x10, 0x10, 0xFF, 0xFF, 0x10, 0xFF, 0xFF, 0x10, 0x14, 0x14, |
rodriguj | 0:3d84b3bfb794 | 198 | 0x14, 0xFF, 0xFF, 0x14, 0x14, 0x14, 0x10, 0x10, 0x10, 0x1F, |
rodriguj | 0:3d84b3bfb794 | 199 | 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0x10, |
rodriguj | 0:3d84b3bfb794 | 200 | 0x10, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, |
rodriguj | 0:3d84b3bfb794 | 201 | 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, |
rodriguj | 0:3d84b3bfb794 | 202 | 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
rodriguj | 0:3d84b3bfb794 | 203 | 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, |
rodriguj | 0:3d84b3bfb794 | 204 | 0x0F, 0x0F, 0x38, 0x7C, 0x44, 0x6C, 0x38, 0x6C, 0x44, 0x00, |
rodriguj | 0:3d84b3bfb794 | 205 | 0x7E, 0x7F, 0x01, 0x09, 0x5F, 0x76, 0x20, 0x00, 0x7F, 0x7F, |
rodriguj | 0:3d84b3bfb794 | 206 | 0x01, 0x01, 0x01, 0x03, 0x03, 0x00, 0x04, 0x7C, 0x7C, 0x04, |
rodriguj | 0:3d84b3bfb794 | 207 | 0x7C, 0x7C, 0x04, 0x00, 0x63, 0x77, 0x5D, 0x49, 0x41, 0x63, |
rodriguj | 0:3d84b3bfb794 | 208 | 0x63, 0x00, 0x38, 0x7C, 0x44, 0x7C, 0x3C, 0x04, 0x04, 0x00, |
rodriguj | 0:3d84b3bfb794 | 209 | 0x80, 0xFC, 0x7C, 0x40, 0x40, 0x7C, 0x3C, 0x00, 0x04, 0x06, |
rodriguj | 0:3d84b3bfb794 | 210 | 0x02, 0x7E, 0x7C, 0x06, 0x02, 0x00, 0x00, 0x99, 0xBD, 0xE7, |
rodriguj | 0:3d84b3bfb794 | 211 | 0xE7, 0xBD, 0x99, 0x00, 0x1C, 0x3E, 0x6B, 0x49, 0x6B, 0x3E, |
rodriguj | 0:3d84b3bfb794 | 212 | 0x1C, 0x00, 0x4C, 0x7E, 0x73, 0x01, 0x73, 0x7E, 0x4C, 0x00, |
rodriguj | 0:3d84b3bfb794 | 213 | 0x00, 0x30, 0x78, 0x4A, 0x4F, 0x7D, 0x39, 0x00, 0x18, 0x3C, |
rodriguj | 0:3d84b3bfb794 | 214 | 0x24, 0x3C, 0x3C, 0x24, 0x3C, 0x18, 0x98, 0xFC, 0x64, 0x3C, |
rodriguj | 0:3d84b3bfb794 | 215 | 0x3E, 0x27, 0x3D, 0x18, 0x00, 0x1C, 0x3E, 0x6B, 0x49, 0x49, |
rodriguj | 0:3d84b3bfb794 | 216 | 0x49, 0x00, 0x7C, 0x7E, 0x02, 0x02, 0x02, 0x7E, 0x7C, 0x00, |
rodriguj | 0:3d84b3bfb794 | 217 | 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 0x00, 0x00, 0x44, |
rodriguj | 0:3d84b3bfb794 | 218 | 0x44, 0x5F, 0x5F, 0x44, 0x44, 0x00, 0x00, 0x40, 0x51, 0x5B, |
rodriguj | 0:3d84b3bfb794 | 219 | 0x4E, 0x44, 0x40, 0x00, 0x00, 0x40, 0x44, 0x4E, 0x5B, 0x51, |
rodriguj | 0:3d84b3bfb794 | 220 | 0x40, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0x01, 0x07, 0x06, |
rodriguj | 0:3d84b3bfb794 | 221 | 0x60, 0xE0, 0x80, 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x08, |
rodriguj | 0:3d84b3bfb794 | 222 | 0x08, 0x2A, 0x2A, 0x08, 0x08, 0x00, 0x24, 0x36, 0x12, 0x36, |
rodriguj | 0:3d84b3bfb794 | 223 | 0x24, 0x36, 0x12, 0x00, 0x00, 0x06, 0x0F, 0x09, 0x0F, 0x06, |
rodriguj | 0:3d84b3bfb794 | 224 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, |
rodriguj | 0:3d84b3bfb794 | 225 | 0x00, 0x00, 0x00, 0x08, 0x08, 0x00, 0x00, 0x00, 0x10, 0x30, |
rodriguj | 0:3d84b3bfb794 | 226 | 0x70, 0xC0, 0xFF, 0xFF, 0x01, 0x01, 0x00, 0x01, 0x1F, 0x1E, |
rodriguj | 0:3d84b3bfb794 | 227 | 0x01, 0x1F, 0x1E, 0x00, 0x00, 0x11, 0x19, 0x1D, 0x17, 0x12, |
rodriguj | 0:3d84b3bfb794 | 228 | 0x00, 0x00, 0x00, 0x00, 0x3C, 0x3C, 0x3C, 0x3C, 0x00, 0x00, |
rodriguj | 0:3d84b3bfb794 | 229 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
rodriguj | 0:3d84b3bfb794 | 230 | }; |
rodriguj | 0:3d84b3bfb794 | 231 | |
rodriguj | 0:3d84b3bfb794 | 232 | |
rodriguj | 3:bb6fba3e84ff | 233 | SSD1306::SSD1306 (PinName sda, PinName scl, char ssd1306_addr) |
rodriguj | 0:3d84b3bfb794 | 234 | { |
rodriguj | 0:3d84b3bfb794 | 235 | idxfb = 0; |
rodriguj | 0:3d84b3bfb794 | 236 | fb = new char[1024]; |
rodriguj | 2:7f1160c1a741 | 237 | if (!fb) { |
rodriguj | 0:3d84b3bfb794 | 238 | printf ("SSD1306: Framebuffer allocation failed!\r\n"); |
rodriguj | 0:3d84b3bfb794 | 239 | for (;;) { } |
rodriguj | 0:3d84b3bfb794 | 240 | } |
rodriguj | 2:7f1160c1a741 | 241 | |
rodriguj | 0:3d84b3bfb794 | 242 | bus = new I2C (sda, scl); |
rodriguj | 3:bb6fba3e84ff | 243 | ssd1306_i2c_addr = ssd1306_addr; |
rodriguj | 3:bb6fba3e84ff | 244 | do_not_delete_bus = 0; |
rodriguj | 0:3d84b3bfb794 | 245 | #ifdef SSD1306_DEBUG |
rodriguj | 0:3d84b3bfb794 | 246 | printf ("SSD1306 debug: fb = 0x%08.8X\r\n", fb); |
rodriguj | 0:3d84b3bfb794 | 247 | #endif |
rodriguj | 3:bb6fba3e84ff | 248 | } |
rodriguj | 2:7f1160c1a741 | 249 | |
rodriguj | 3:bb6fba3e84ff | 250 | SSD1306::SSD1306 (I2C &busi2c, char ssd1306_addr) |
rodriguj | 3:bb6fba3e84ff | 251 | { |
rodriguj | 3:bb6fba3e84ff | 252 | bus = &busi2c; |
rodriguj | 3:bb6fba3e84ff | 253 | idxfb = 0; |
rodriguj | 3:bb6fba3e84ff | 254 | fb = new char[1024]; |
rodriguj | 3:bb6fba3e84ff | 255 | if (!fb) { |
rodriguj | 3:bb6fba3e84ff | 256 | printf ("SSD1306: Framebuffer allocation failed!\r\n"); |
rodriguj | 3:bb6fba3e84ff | 257 | for (;;) { } |
rodriguj | 3:bb6fba3e84ff | 258 | } |
rodriguj | 3:bb6fba3e84ff | 259 | ssd1306_i2c_addr = ssd1306_addr; |
rodriguj | 3:bb6fba3e84ff | 260 | do_not_delete_bus = 1; |
rodriguj | 0:3d84b3bfb794 | 261 | } |
rodriguj | 0:3d84b3bfb794 | 262 | |
rodriguj | 0:3d84b3bfb794 | 263 | void SSD1306::speed (I2CSpeed spd) |
rodriguj | 0:3d84b3bfb794 | 264 | { |
rodriguj | 2:7f1160c1a741 | 265 | switch (spd) { |
rodriguj | 4:35757c8b7625 | 266 | case Slow: |
rodriguj | 2:7f1160c1a741 | 267 | bus->frequency(100000); |
rodriguj | 2:7f1160c1a741 | 268 | break; |
rodriguj | 2:7f1160c1a741 | 269 | case Medium: |
rodriguj | 2:7f1160c1a741 | 270 | bus->frequency(400000); |
rodriguj | 2:7f1160c1a741 | 271 | break; |
rodriguj | 2:7f1160c1a741 | 272 | case Fast: |
rodriguj | 2:7f1160c1a741 | 273 | bus->frequency(1000000); |
rodriguj | 2:7f1160c1a741 | 274 | break; |
rodriguj | 0:3d84b3bfb794 | 275 | } |
rodriguj | 0:3d84b3bfb794 | 276 | } |
rodriguj | 0:3d84b3bfb794 | 277 | |
rodriguj | 0:3d84b3bfb794 | 278 | char SSD1306::scan (void) |
rodriguj | 0:3d84b3bfb794 | 279 | { |
rodriguj | 0:3d84b3bfb794 | 280 | int addr; |
rodriguj | 0:3d84b3bfb794 | 281 | int res; |
rodriguj | 0:3d84b3bfb794 | 282 | char i2caddr = 0; |
rodriguj | 2:7f1160c1a741 | 283 | |
rodriguj | 0:3d84b3bfb794 | 284 | for (addr=0; addr<256; addr++) { |
rodriguj | 0:3d84b3bfb794 | 285 | res = bus->write (addr, NULL, 0); |
rodriguj | 0:3d84b3bfb794 | 286 | if (res == 0) |
rodriguj | 0:3d84b3bfb794 | 287 | i2caddr = addr & 0xFE; |
rodriguj | 0:3d84b3bfb794 | 288 | } |
rodriguj | 0:3d84b3bfb794 | 289 | return i2caddr; |
rodriguj | 0:3d84b3bfb794 | 290 | } |
rodriguj | 0:3d84b3bfb794 | 291 | |
rodriguj | 0:3d84b3bfb794 | 292 | int SSD1306::command_data (char c, char c_or_d, char lastitem) |
rodriguj | 0:3d84b3bfb794 | 293 | { |
rodriguj | 0:3d84b3bfb794 | 294 | int res; |
rodriguj | 2:7f1160c1a741 | 295 | |
rodriguj | 0:3d84b3bfb794 | 296 | bus->start(); |
rodriguj | 2:7f1160c1a741 | 297 | res = bus->write(ssd1306_i2c_addr); |
rodriguj | 2:7f1160c1a741 | 298 | if (!res) goto terminate_transaction; |
rodriguj | 2:7f1160c1a741 | 299 | res = bus->write(c_or_d | lastitem); |
rodriguj | 2:7f1160c1a741 | 300 | if (!res) goto terminate_transaction; |
rodriguj | 2:7f1160c1a741 | 301 | res = bus->write(c); |
rodriguj | 2:7f1160c1a741 | 302 | if (!res) goto terminate_transaction; |
rodriguj | 2:7f1160c1a741 | 303 | |
rodriguj | 2:7f1160c1a741 | 304 | terminate_transaction: |
rodriguj | 2:7f1160c1a741 | 305 | bus->stop(); |
rodriguj | 0:3d84b3bfb794 | 306 | return res; |
rodriguj | 0:3d84b3bfb794 | 307 | } |
rodriguj | 0:3d84b3bfb794 | 308 | |
rodriguj | 0:3d84b3bfb794 | 309 | int SSD1306::command (char c) |
rodriguj | 0:3d84b3bfb794 | 310 | { |
rodriguj | 4:35757c8b7625 | 311 | return command_data (c, SSD1306_IS_COMMAND, SSD1306_IS_LAST); |
rodriguj | 0:3d84b3bfb794 | 312 | } |
rodriguj | 0:3d84b3bfb794 | 313 | |
rodriguj | 0:3d84b3bfb794 | 314 | int SSD1306::data (char d) |
rodriguj | 0:3d84b3bfb794 | 315 | { |
rodriguj | 4:35757c8b7625 | 316 | return command_data (d, SSD1306_IS_DATA, SSD1306_IS_LAST); |
rodriguj | 0:3d84b3bfb794 | 317 | } |
rodriguj | 0:3d84b3bfb794 | 318 | |
rodriguj | 0:3d84b3bfb794 | 319 | int SSD1306::init (void) |
rodriguj | 0:3d84b3bfb794 | 320 | { |
rodriguj | 3:bb6fba3e84ff | 321 | static const char comando[] = {0x80, SSD1306_DISPLAYOFF, |
rodriguj | 3:bb6fba3e84ff | 322 | 0x80, SSD1306_CHARGEPUMP, |
rodriguj | 3:bb6fba3e84ff | 323 | 0x80, 0x14, |
rodriguj | 3:bb6fba3e84ff | 324 | 0x80, SSD1306_MEMORYMODE, |
rodriguj | 3:bb6fba3e84ff | 325 | 0x80, 0x00, |
rodriguj | 3:bb6fba3e84ff | 326 | 0x80, SSD1306_SEGREMAP | 0x1, |
rodriguj | 3:bb6fba3e84ff | 327 | 0x80, SSD1306_COMSCANDEC, |
rodriguj | 3:bb6fba3e84ff | 328 | 0x80, SSD1306_SETCONTRAST, |
rodriguj | 3:bb6fba3e84ff | 329 | 0x80, 0x7F, |
rodriguj | 3:bb6fba3e84ff | 330 | 0x00, SSD1306_DISPLAYON |
rodriguj | 3:bb6fba3e84ff | 331 | }; |
rodriguj | 2:7f1160c1a741 | 332 | |
rodriguj | 0:3d84b3bfb794 | 333 | return bus->write (ssd1306_i2c_addr, comando, sizeof comando); |
rodriguj | 0:3d84b3bfb794 | 334 | } |
rodriguj | 0:3d84b3bfb794 | 335 | |
rodriguj | 1:c5cf4ca5939f | 336 | void SSD1306::scroll (bool refresh) |
rodriguj | 0:3d84b3bfb794 | 337 | { |
rodriguj | 0:3d84b3bfb794 | 338 | int i; |
rodriguj | 2:7f1160c1a741 | 339 | |
rodriguj | 0:3d84b3bfb794 | 340 | for (i=128; i<1024; i++) |
rodriguj | 0:3d84b3bfb794 | 341 | fb[i-128] = fb[i]; |
rodriguj | 0:3d84b3bfb794 | 342 | for (i=896; i<1024; i++) |
rodriguj | 0:3d84b3bfb794 | 343 | fb[i] = 0; |
rodriguj | 1:c5cf4ca5939f | 344 | if (refresh) |
rodriguj | 2:7f1160c1a741 | 345 | display(); |
rodriguj | 2:7f1160c1a741 | 346 | } |
rodriguj | 2:7f1160c1a741 | 347 | |
rodriguj | 2:7f1160c1a741 | 348 | void SSD1306::locate (char row, char column) |
rodriguj | 2:7f1160c1a741 | 349 | { |
rodriguj | 2:7f1160c1a741 | 350 | idxfb = row*128+column*8; |
rodriguj | 0:3d84b3bfb794 | 351 | } |
rodriguj | 0:3d84b3bfb794 | 352 | |
rodriguj | 1:c5cf4ca5939f | 353 | void SSD1306::putchar (char c, bool refresh) |
rodriguj | 0:3d84b3bfb794 | 354 | { |
rodriguj | 0:3d84b3bfb794 | 355 | int idx,i; |
rodriguj | 2:7f1160c1a741 | 356 | |
rodriguj | 0:3d84b3bfb794 | 357 | idx = c*8; |
rodriguj | 2:7f1160c1a741 | 358 | if (idxfb == 1024) { |
rodriguj | 2:7f1160c1a741 | 359 | scroll(refresh); |
rodriguj | 2:7f1160c1a741 | 360 | idxfb = 896; |
rodriguj | 2:7f1160c1a741 | 361 | } |
rodriguj | 0:3d84b3bfb794 | 362 | for (i=0; i<8; i++) { |
rodriguj | 0:3d84b3bfb794 | 363 | fb[idxfb] = charset[idx+i]; |
rodriguj | 0:3d84b3bfb794 | 364 | idxfb++; |
rodriguj | 0:3d84b3bfb794 | 365 | } |
rodriguj | 1:c5cf4ca5939f | 366 | if (refresh) |
rodriguj | 2:7f1160c1a741 | 367 | display(); |
rodriguj | 2:7f1160c1a741 | 368 | } |
rodriguj | 2:7f1160c1a741 | 369 | |
rodriguj | 2:7f1160c1a741 | 370 | void SSD1306::puts (char *s, bool refresh) |
rodriguj | 2:7f1160c1a741 | 371 | { |
rodriguj | 2:7f1160c1a741 | 372 | while (*s) putchar (*s++, refresh); |
rodriguj | 0:3d84b3bfb794 | 373 | } |
rodriguj | 0:3d84b3bfb794 | 374 | |
rodriguj | 4:35757c8b7625 | 375 | void SSD1306::printf (const char *fmt,...) |
rodriguj | 3:bb6fba3e84ff | 376 | { |
rodriguj | 3:bb6fba3e84ff | 377 | char *s = new char[129]; |
rodriguj | 3:bb6fba3e84ff | 378 | va_list args; |
rodriguj | 3:bb6fba3e84ff | 379 | |
rodriguj | 3:bb6fba3e84ff | 380 | va_start (args, fmt); |
rodriguj | 3:bb6fba3e84ff | 381 | vsnprintf (s, 128, fmt, args); |
rodriguj | 3:bb6fba3e84ff | 382 | puts (s, false); |
rodriguj | 3:bb6fba3e84ff | 383 | delete[] s; |
rodriguj | 3:bb6fba3e84ff | 384 | va_end (args); |
rodriguj | 3:bb6fba3e84ff | 385 | } |
rodriguj | 3:bb6fba3e84ff | 386 | |
rodriguj | 3:bb6fba3e84ff | 387 | |
rodriguj | 0:3d84b3bfb794 | 388 | void SSD1306::display(void) |
rodriguj | 0:3d84b3bfb794 | 389 | { |
rodriguj | 0:3d84b3bfb794 | 390 | int i; |
rodriguj | 2:7f1160c1a741 | 391 | |
rodriguj | 0:3d84b3bfb794 | 392 | command (0xb0); |
rodriguj | 0:3d84b3bfb794 | 393 | command (SSD1306_SETLOWCOLUMN | 0x0); // low col = 0 |
rodriguj | 0:3d84b3bfb794 | 394 | command (SSD1306_SETHIGHCOLUMN | 0x0); // hi col = 0 |
rodriguj | 0:3d84b3bfb794 | 395 | command (SSD1306_SETSTARTLINE | 0x0); // line #0 |
rodriguj | 2:7f1160c1a741 | 396 | |
rodriguj | 0:3d84b3bfb794 | 397 | bus->start(); |
rodriguj | 0:3d84b3bfb794 | 398 | bus->write (ssd1306_i2c_addr); |
rodriguj | 0:3d84b3bfb794 | 399 | bus->write (0x40); |
rodriguj | 0:3d84b3bfb794 | 400 | for (i=0; i<1024; i++) { |
rodriguj | 0:3d84b3bfb794 | 401 | bus->write (fb[i]); |
rodriguj | 0:3d84b3bfb794 | 402 | } |
rodriguj | 0:3d84b3bfb794 | 403 | bus->stop(); |
rodriguj | 0:3d84b3bfb794 | 404 | } |
rodriguj | 0:3d84b3bfb794 | 405 | |
rodriguj | 0:3d84b3bfb794 | 406 | void SSD1306::set_contrast (char v) |
rodriguj | 0:3d84b3bfb794 | 407 | { |
rodriguj | 0:3d84b3bfb794 | 408 | command (SSD1306_SETCONTRAST); |
rodriguj | 0:3d84b3bfb794 | 409 | command (v); |
rodriguj | 0:3d84b3bfb794 | 410 | } |
rodriguj | 0:3d84b3bfb794 | 411 | |
rodriguj | 1:c5cf4ca5939f | 412 | void SSD1306::cls (char *bkground, bool refresh) |
rodriguj | 0:3d84b3bfb794 | 413 | { |
rodriguj | 0:3d84b3bfb794 | 414 | int i; |
rodriguj | 1:c5cf4ca5939f | 415 | |
rodriguj | 2:7f1160c1a741 | 416 | if (!bkground) { |
rodriguj | 1:c5cf4ca5939f | 417 | for (i=0; i<1024; i++) |
rodriguj | 1:c5cf4ca5939f | 418 | fb[i] = 0; |
rodriguj | 2:7f1160c1a741 | 419 | } else { |
rodriguj | 1:c5cf4ca5939f | 420 | for (i=0; i<1024; i++) |
rodriguj | 1:c5cf4ca5939f | 421 | fb[i] = bkground[i]; |
rodriguj | 0:3d84b3bfb794 | 422 | } |
rodriguj | 0:3d84b3bfb794 | 423 | idxfb = 0; |
rodriguj | 1:c5cf4ca5939f | 424 | if (refresh) |
rodriguj | 2:7f1160c1a741 | 425 | display(); |
rodriguj | 0:3d84b3bfb794 | 426 | } |
rodriguj | 0:3d84b3bfb794 | 427 | |
rodriguj | 4:35757c8b7625 | 428 | void SSD1306::plot (char x, char y, PlotStyle mode, bool refresh) |
rodriguj | 0:3d84b3bfb794 | 429 | { |
rodriguj | 0:3d84b3bfb794 | 430 | x = x % 128; |
rodriguj | 0:3d84b3bfb794 | 431 | y = y % 64; |
rodriguj | 3:bb6fba3e84ff | 432 | |
rodriguj | 4:35757c8b7625 | 433 | switch (mode) { |
rodriguj | 2:7f1160c1a741 | 434 | case Normal: |
rodriguj | 2:7f1160c1a741 | 435 | fb[(y/8)*128+x] |= (1<<(y%8)); |
rodriguj | 2:7f1160c1a741 | 436 | break; |
rodriguj | 2:7f1160c1a741 | 437 | case Inverse: |
rodriguj | 2:7f1160c1a741 | 438 | fb[(y/8)*128+x] &= ~(1<<(y%8)); |
rodriguj | 2:7f1160c1a741 | 439 | break; |
rodriguj | 2:7f1160c1a741 | 440 | case Xor: |
rodriguj | 2:7f1160c1a741 | 441 | fb[(y/8)*128+x] ^= (1<<(y%8)); |
rodriguj | 2:7f1160c1a741 | 442 | break; |
rodriguj | 0:3d84b3bfb794 | 443 | } |
rodriguj | 1:c5cf4ca5939f | 444 | if (refresh) |
rodriguj | 2:7f1160c1a741 | 445 | display(); |
rodriguj | 0:3d84b3bfb794 | 446 | } |
rodriguj | 1:c5cf4ca5939f | 447 | |
rodriguj | 3:bb6fba3e84ff | 448 | bool SSD1306::point (char x, char y) |
rodriguj | 3:bb6fba3e84ff | 449 | { |
rodriguj | 3:bb6fba3e84ff | 450 | x = x % 128; |
rodriguj | 3:bb6fba3e84ff | 451 | y = y % 64; |
rodriguj | 3:bb6fba3e84ff | 452 | |
rodriguj | 3:bb6fba3e84ff | 453 | if ( fb[(y/8)*128+x] & (1<<(y%8)) ) |
rodriguj | 3:bb6fba3e84ff | 454 | return true; |
rodriguj | 3:bb6fba3e84ff | 455 | else |
rodriguj | 3:bb6fba3e84ff | 456 | return false; |
rodriguj | 3:bb6fba3e84ff | 457 | } |
rodriguj | 3:bb6fba3e84ff | 458 | |
rodriguj | 4:35757c8b7625 | 459 | void SSD1306::line (char x0, char y0, char x1, char y1, PlotStyle mode, bool refresh) |
rodriguj | 1:c5cf4ca5939f | 460 | { |
rodriguj | 1:c5cf4ca5939f | 461 | int dx = abs (x1 - x0), sx = x0 < x1 ? 1 : -1; |
rodriguj | 1:c5cf4ca5939f | 462 | int dy = -abs (y1 - y0), sy = y0 < y1 ? 1 : -1; |
rodriguj | 1:c5cf4ca5939f | 463 | int err = dx + dy, e2; /* error value e_xy */ |
rodriguj | 1:c5cf4ca5939f | 464 | |
rodriguj | 2:7f1160c1a741 | 465 | for (;;) { |
rodriguj | 2:7f1160c1a741 | 466 | /* loop */ |
rodriguj | 4:35757c8b7625 | 467 | plot (x0, y0, mode, false); |
rodriguj | 1:c5cf4ca5939f | 468 | if (x0 == x1 && y0 == y1) break; |
rodriguj | 1:c5cf4ca5939f | 469 | e2 = 2 * err; |
rodriguj | 2:7f1160c1a741 | 470 | if (e2 >= dy) { |
rodriguj | 2:7f1160c1a741 | 471 | err += dy; /* e_xy+e_x > 0 */ |
rodriguj | 2:7f1160c1a741 | 472 | x0 += sx; |
rodriguj | 2:7f1160c1a741 | 473 | } |
rodriguj | 2:7f1160c1a741 | 474 | if (e2 <= dx) { |
rodriguj | 2:7f1160c1a741 | 475 | err += dx; /* e_xy+e_y < 0 */ |
rodriguj | 2:7f1160c1a741 | 476 | y0 += sy; |
rodriguj | 2:7f1160c1a741 | 477 | } |
rodriguj | 1:c5cf4ca5939f | 478 | } |
rodriguj | 1:c5cf4ca5939f | 479 | if (refresh) |
rodriguj | 1:c5cf4ca5939f | 480 | display(); |
rodriguj | 1:c5cf4ca5939f | 481 | } |
rodriguj | 3:bb6fba3e84ff | 482 | |
rodriguj | 4:35757c8b7625 | 483 | void SSD1306::circle (char x0, char y0, char r, PlotStyle mode, bool refresh) |
rodriguj | 3:bb6fba3e84ff | 484 | { |
rodriguj | 3:bb6fba3e84ff | 485 | int x = r-1; |
rodriguj | 3:bb6fba3e84ff | 486 | int y = 0; |
rodriguj | 3:bb6fba3e84ff | 487 | int dx = 1; |
rodriguj | 3:bb6fba3e84ff | 488 | int dy = 1; |
rodriguj | 3:bb6fba3e84ff | 489 | int err = dx - 2*r; |
rodriguj | 3:bb6fba3e84ff | 490 | |
rodriguj | 3:bb6fba3e84ff | 491 | while (x >= y) |
rodriguj | 3:bb6fba3e84ff | 492 | { |
rodriguj | 4:35757c8b7625 | 493 | plot (x0 + x, y0 + y, mode); |
rodriguj | 4:35757c8b7625 | 494 | plot (x0 + y, y0 + x, mode); |
rodriguj | 4:35757c8b7625 | 495 | plot (x0 - y, y0 + x, mode); |
rodriguj | 4:35757c8b7625 | 496 | plot (x0 - x, y0 + y, mode); |
rodriguj | 4:35757c8b7625 | 497 | plot (x0 - x, y0 - y, mode); |
rodriguj | 4:35757c8b7625 | 498 | plot (x0 - y, y0 - x, mode); |
rodriguj | 4:35757c8b7625 | 499 | plot (x0 + y, y0 - x, mode); |
rodriguj | 4:35757c8b7625 | 500 | plot (x0 + x, y0 - y, mode); |
rodriguj | 3:bb6fba3e84ff | 501 | |
rodriguj | 3:bb6fba3e84ff | 502 | if (err <= 0) |
rodriguj | 3:bb6fba3e84ff | 503 | { |
rodriguj | 3:bb6fba3e84ff | 504 | y++; |
rodriguj | 3:bb6fba3e84ff | 505 | err += dy; |
rodriguj | 3:bb6fba3e84ff | 506 | dy += 2; |
rodriguj | 3:bb6fba3e84ff | 507 | } |
rodriguj | 3:bb6fba3e84ff | 508 | if (err > 0) |
rodriguj | 3:bb6fba3e84ff | 509 | { |
rodriguj | 3:bb6fba3e84ff | 510 | x--; |
rodriguj | 3:bb6fba3e84ff | 511 | dx += 2; |
rodriguj | 3:bb6fba3e84ff | 512 | err += dx - 2*r; |
rodriguj | 3:bb6fba3e84ff | 513 | } |
rodriguj | 3:bb6fba3e84ff | 514 | } |
rodriguj | 3:bb6fba3e84ff | 515 | if (refresh) |
rodriguj | 3:bb6fba3e84ff | 516 | display(); |
rodriguj | 3:bb6fba3e84ff | 517 | } |