SSD1306 LCD 96x16 model
Dependents: testSoftware8_alles_display
Fork of ssd1306_library by
ssd1306.cpp@11:1b5a69808460, 2018-08-09 (annotated)
- Committer:
- mikevd1
- Date:
- Thu Aug 09 12:41:15 2018 +0000
- Revision:
- 11:1b5a69808460
- Parent:
- 10:346065d26cc9
- Child:
- 12:42a98fa363b4
Werkend display
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; |
mikevd1 | 11:1b5a69808460 | 236 | fb = new char[196]; |
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; |
mikevd1 | 11:1b5a69808460 | 254 | fb = new char[196]; |
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 | { |
mikevd1 | 11:1b5a69808460 | 321 | |
rodriguj | 3:bb6fba3e84ff | 322 | static const char comando[] = {0x80, SSD1306_DISPLAYOFF, |
mikevd1 | 11:1b5a69808460 | 323 | 0x80, SSD1306_SETDISPLAYCLOCKDIV, |
mikevd1 | 11:1b5a69808460 | 324 | 0x80, 0x80, |
mikevd1 | 11:1b5a69808460 | 325 | 0x80, SSD1306_SETMULTIPLEX, |
mikevd1 | 11:1b5a69808460 | 326 | 0x80, 0x0F, |
mikevd1 | 11:1b5a69808460 | 327 | 0x80, SSD1306_SETDISPLAYOFFSET, |
mikevd1 | 11:1b5a69808460 | 328 | 0x80, 0x00, |
mikevd1 | 11:1b5a69808460 | 329 | 0x80, SSD1306_SETSTARTLINE, |
mikevd1 | 11:1b5a69808460 | 330 | |
mikevd1 | 11:1b5a69808460 | 331 | 0x80, SSD1306_MEMORYMODE, |
mikevd1 | 11:1b5a69808460 | 332 | 0x80, 0x00, |
mikevd1 | 11:1b5a69808460 | 333 | |
mikevd1 | 11:1b5a69808460 | 334 | 0x80, SSD1306_SETCOLUMNADRESS, |
mikevd1 | 11:1b5a69808460 | 335 | 0x80, 0x00, |
mikevd1 | 11:1b5a69808460 | 336 | 0x80, 0x60, |
mikevd1 | 11:1b5a69808460 | 337 | 0x80, SSD1306_SETPAGEADRESS, |
mikevd1 | 11:1b5a69808460 | 338 | 0x80, 0x00, |
mikevd1 | 11:1b5a69808460 | 339 | 0x80, 0x01, |
mikevd1 | 11:1b5a69808460 | 340 | |
rodriguj | 3:bb6fba3e84ff | 341 | 0x80, SSD1306_CHARGEPUMP, |
rodriguj | 3:bb6fba3e84ff | 342 | 0x80, 0x14, |
rodriguj | 3:bb6fba3e84ff | 343 | 0x80, SSD1306_SEGREMAP | 0x1, |
mikevd1 | 11:1b5a69808460 | 344 | 0x80, SSD1306_COMSCANDEC, |
mikevd1 | 11:1b5a69808460 | 345 | 0x80, SSD1306_SETCOMPINS, |
mikevd1 | 11:1b5a69808460 | 346 | 0x80, 0x02, |
rodriguj | 3:bb6fba3e84ff | 347 | 0x80, SSD1306_SETCONTRAST, |
mikevd1 | 11:1b5a69808460 | 348 | 0x80, 0xFF, |
mikevd1 | 11:1b5a69808460 | 349 | 0x80, SSD1306_SETPRECHARGE, |
mikevd1 | 11:1b5a69808460 | 350 | 0x80, 0xF1, |
mikevd1 | 11:1b5a69808460 | 351 | 0x80, SSD1306_SETVCOMDETECT, |
mikevd1 | 11:1b5a69808460 | 352 | 0x80, 0x20, |
mikevd1 | 11:1b5a69808460 | 353 | 0x80, SSD1306_DISPLAYALLON_RESUME, |
mikevd1 | 11:1b5a69808460 | 354 | 0x80, SSD1306_NORMALDISPLAY, |
rodriguj | 3:bb6fba3e84ff | 355 | 0x00, SSD1306_DISPLAYON |
rodriguj | 3:bb6fba3e84ff | 356 | }; |
mikevd1 | 11:1b5a69808460 | 357 | |
rodriguj | 0:3d84b3bfb794 | 358 | return bus->write (ssd1306_i2c_addr, comando, sizeof comando); |
rodriguj | 0:3d84b3bfb794 | 359 | } |
rodriguj | 0:3d84b3bfb794 | 360 | |
mikevd1 | 10:346065d26cc9 | 361 | |
mikevd1 | 11:1b5a69808460 | 362 | // static const char comando[] = {0x80, SSD1306_DISPLAYOFF, |
mikevd1 | 11:1b5a69808460 | 363 | // 0x80, SSD1306_CHARGEPUMP, |
mikevd1 | 11:1b5a69808460 | 364 | // 0x80, 0x14, |
mikevd1 | 11:1b5a69808460 | 365 | // 0x80, SSD1306_MEMORYMODE, |
mikevd1 | 11:1b5a69808460 | 366 | // 0x80, 0x00, |
mikevd1 | 11:1b5a69808460 | 367 | // 0x80, SSD1306_SETMULTIPLEX, |
mikevd1 | 11:1b5a69808460 | 368 | // 0x80, 0x0F, |
mikevd1 | 11:1b5a69808460 | 369 | // 0x80, SSD1306_SETDISPLAYOFFSET, |
mikevd1 | 11:1b5a69808460 | 370 | // 0x80, 0x00, |
mikevd1 | 11:1b5a69808460 | 371 | // 0x80, SSD1306_SETDISPLAYCLOCKDIV, |
mikevd1 | 11:1b5a69808460 | 372 | // 0x80, 0x80, |
mikevd1 | 11:1b5a69808460 | 373 | // 0x80, SSD1306_SETSTARTLINE, |
mikevd1 | 11:1b5a69808460 | 374 | // 0x80, SSD1306_SETCOLUMNADRESS, |
mikevd1 | 11:1b5a69808460 | 375 | // 0x80, 0x00, |
mikevd1 | 11:1b5a69808460 | 376 | // 0x80, 0x60, |
mikevd1 | 11:1b5a69808460 | 377 | // 0x80, SSD1306_SETPAGEADRESS, |
mikevd1 | 11:1b5a69808460 | 378 | // 0x80, 0x00, |
mikevd1 | 11:1b5a69808460 | 379 | // 0x80, 0x01, |
mikevd1 | 11:1b5a69808460 | 380 | // 0x80, 0x41, |
mikevd1 | 11:1b5a69808460 | 381 | // 0x80, SSD1306_SEGREMAP | 0x1, |
mikevd1 | 11:1b5a69808460 | 382 | // 0x80, 0x2E, |
mikevd1 | 11:1b5a69808460 | 383 | // 0x80, SSD1306_COMSCANDEC, |
mikevd1 | 11:1b5a69808460 | 384 | // 0x80, SSD1306_SETCONTRAST, |
mikevd1 | 11:1b5a69808460 | 385 | // 0x80, 0x7F, |
mikevd1 | 11:1b5a69808460 | 386 | // 0x00, SSD1306_DISPLAYON |
mikevd1 | 11:1b5a69808460 | 387 | // }; |
mikevd1 | 11:1b5a69808460 | 388 | |
mikevd1 | 11:1b5a69808460 | 389 | // static const char comando[] = {0x80, SSD1306_DISPLAYOFF, |
mikevd1 | 11:1b5a69808460 | 390 | // 0x80, SSD1306_CHARGEPUMP, |
mikevd1 | 11:1b5a69808460 | 391 | // 0x80, 0x14, |
mikevd1 | 11:1b5a69808460 | 392 | // 0x80, SSD1306_MEMORYMODE, |
mikevd1 | 11:1b5a69808460 | 393 | // 0x80, SSD1306_SETMULTIPLEX, |
mikevd1 | 11:1b5a69808460 | 394 | // 0x80, 0x00, |
mikevd1 | 11:1b5a69808460 | 395 | // 0x80, 0x00, |
mikevd1 | 11:1b5a69808460 | 396 | // 0x80, SSD1306_SEGREMAP | 0x1, |
mikevd1 | 11:1b5a69808460 | 397 | // 0x80, SSD1306_COMSCANDEC, |
mikevd1 | 11:1b5a69808460 | 398 | // 0x80, SSD1306_SETCONTRAST, |
mikevd1 | 11:1b5a69808460 | 399 | // 0x80, 0x7F, |
mikevd1 | 11:1b5a69808460 | 400 | // 0x00, SSD1306_DISPLAYON |
mikevd1 | 11:1b5a69808460 | 401 | // }; |
mikevd1 | 11:1b5a69808460 | 402 | // |
mikevd1 | 11:1b5a69808460 | 403 | |
mikevd1 | 11:1b5a69808460 | 404 | |
mikevd1 | 11:1b5a69808460 | 405 | |
mikevd1 | 10:346065d26cc9 | 406 | |
mikevd1 | 10:346065d26cc9 | 407 | |
rodriguj | 1:c5cf4ca5939f | 408 | void SSD1306::scroll (bool refresh) |
rodriguj | 0:3d84b3bfb794 | 409 | { |
rodriguj | 0:3d84b3bfb794 | 410 | int i; |
rodriguj | 2:7f1160c1a741 | 411 | |
mikevd1 | 11:1b5a69808460 | 412 | for (i=98; i<196; i++) |
mikevd1 | 11:1b5a69808460 | 413 | fb[i-98] = fb[i]; |
mikevd1 | 11:1b5a69808460 | 414 | for (i=98; i<196; i++) |
rodriguj | 0:3d84b3bfb794 | 415 | fb[i] = 0; |
rodriguj | 1:c5cf4ca5939f | 416 | if (refresh) |
rodriguj | 8:09b1578f93d9 | 417 | redraw(); |
rodriguj | 2:7f1160c1a741 | 418 | } |
rodriguj | 2:7f1160c1a741 | 419 | |
rodriguj | 2:7f1160c1a741 | 420 | void SSD1306::locate (char row, char column) |
rodriguj | 2:7f1160c1a741 | 421 | { |
mikevd1 | 11:1b5a69808460 | 422 | idxfb = row*97+column*8; |
rodriguj | 0:3d84b3bfb794 | 423 | } |
rodriguj | 0:3d84b3bfb794 | 424 | |
rodriguj | 1:c5cf4ca5939f | 425 | void SSD1306::putchar (char c, bool refresh) |
rodriguj | 0:3d84b3bfb794 | 426 | { |
rodriguj | 0:3d84b3bfb794 | 427 | int idx,i; |
rodriguj | 2:7f1160c1a741 | 428 | |
rodriguj | 0:3d84b3bfb794 | 429 | idx = c*8; |
mikevd1 | 11:1b5a69808460 | 430 | if (idxfb == 196) { |
rodriguj | 2:7f1160c1a741 | 431 | scroll(refresh); |
mikevd1 | 11:1b5a69808460 | 432 | idxfb = 97; |
rodriguj | 2:7f1160c1a741 | 433 | } |
rodriguj | 0:3d84b3bfb794 | 434 | for (i=0; i<8; i++) { |
rodriguj | 0:3d84b3bfb794 | 435 | fb[idxfb] = charset[idx+i]; |
rodriguj | 0:3d84b3bfb794 | 436 | idxfb++; |
rodriguj | 0:3d84b3bfb794 | 437 | } |
rodriguj | 1:c5cf4ca5939f | 438 | if (refresh) |
rodriguj | 8:09b1578f93d9 | 439 | redraw(); |
rodriguj | 2:7f1160c1a741 | 440 | } |
rodriguj | 2:7f1160c1a741 | 441 | |
rodriguj | 2:7f1160c1a741 | 442 | void SSD1306::puts (char *s, bool refresh) |
rodriguj | 2:7f1160c1a741 | 443 | { |
rodriguj | 2:7f1160c1a741 | 444 | while (*s) putchar (*s++, refresh); |
rodriguj | 0:3d84b3bfb794 | 445 | } |
rodriguj | 0:3d84b3bfb794 | 446 | |
rodriguj | 4:35757c8b7625 | 447 | void SSD1306::printf (const char *fmt,...) |
rodriguj | 3:bb6fba3e84ff | 448 | { |
mikevd1 | 11:1b5a69808460 | 449 | char *s = new char[98]; |
rodriguj | 3:bb6fba3e84ff | 450 | va_list args; |
rodriguj | 3:bb6fba3e84ff | 451 | |
rodriguj | 3:bb6fba3e84ff | 452 | va_start (args, fmt); |
mikevd1 | 11:1b5a69808460 | 453 | vsnprintf (s, 97, fmt, args); |
rodriguj | 3:bb6fba3e84ff | 454 | puts (s, false); |
rodriguj | 3:bb6fba3e84ff | 455 | delete[] s; |
rodriguj | 3:bb6fba3e84ff | 456 | va_end (args); |
rodriguj | 3:bb6fba3e84ff | 457 | } |
rodriguj | 3:bb6fba3e84ff | 458 | |
rodriguj | 3:bb6fba3e84ff | 459 | |
rodriguj | 8:09b1578f93d9 | 460 | void SSD1306::redraw (void) |
rodriguj | 0:3d84b3bfb794 | 461 | { |
rodriguj | 0:3d84b3bfb794 | 462 | int i; |
rodriguj | 2:7f1160c1a741 | 463 | |
rodriguj | 0:3d84b3bfb794 | 464 | command (0xb0); |
mikevd1 | 11:1b5a69808460 | 465 | command (SSD1306_SETLOWCOLUMN | 0x00); // low col = 0 |
mikevd1 | 11:1b5a69808460 | 466 | command (SSD1306_SETHIGHCOLUMN | 0x00); // hi col = 0 |
mikevd1 | 11:1b5a69808460 | 467 | command (SSD1306_SETSTARTLINE | 0x00); // line #0 |
rodriguj | 2:7f1160c1a741 | 468 | |
rodriguj | 0:3d84b3bfb794 | 469 | bus->start(); |
rodriguj | 0:3d84b3bfb794 | 470 | bus->write (ssd1306_i2c_addr); |
rodriguj | 0:3d84b3bfb794 | 471 | bus->write (0x40); |
mikevd1 | 11:1b5a69808460 | 472 | for (i=0; i < 195 ; i++) |
mikevd1 | 11:1b5a69808460 | 473 | { |
rodriguj | 0:3d84b3bfb794 | 474 | bus->write (fb[i]); |
rodriguj | 0:3d84b3bfb794 | 475 | } |
rodriguj | 0:3d84b3bfb794 | 476 | bus->stop(); |
rodriguj | 0:3d84b3bfb794 | 477 | } |
rodriguj | 0:3d84b3bfb794 | 478 | |
rodriguj | 8:09b1578f93d9 | 479 | void SSD1306::display (void) |
rodriguj | 8:09b1578f93d9 | 480 | { |
rodriguj | 8:09b1578f93d9 | 481 | redraw(); |
rodriguj | 8:09b1578f93d9 | 482 | } |
rodriguj | 8:09b1578f93d9 | 483 | |
rodriguj | 0:3d84b3bfb794 | 484 | void SSD1306::set_contrast (char v) |
rodriguj | 0:3d84b3bfb794 | 485 | { |
rodriguj | 0:3d84b3bfb794 | 486 | command (SSD1306_SETCONTRAST); |
rodriguj | 0:3d84b3bfb794 | 487 | command (v); |
rodriguj | 0:3d84b3bfb794 | 488 | } |
rodriguj | 0:3d84b3bfb794 | 489 | |
mikevd1 | 11:1b5a69808460 | 490 | |
mikevd1 | 11:1b5a69808460 | 491 | |
rodriguj | 1:c5cf4ca5939f | 492 | void SSD1306::cls (char *bkground, bool refresh) |
rodriguj | 0:3d84b3bfb794 | 493 | { |
rodriguj | 0:3d84b3bfb794 | 494 | int i; |
mikevd1 | 11:1b5a69808460 | 495 | static int refreshD = 0 ; |
rodriguj | 2:7f1160c1a741 | 496 | if (!bkground) { |
mikevd1 | 11:1b5a69808460 | 497 | for (i=0; i<196; i++) |
mikevd1 | 11:1b5a69808460 | 498 | { |
mikevd1 | 11:1b5a69808460 | 499 | if ( refreshD == 0 ) |
mikevd1 | 11:1b5a69808460 | 500 | { |
mikevd1 | 11:1b5a69808460 | 501 | //fb[i] = 0xFF ; //0x81; |
mikevd1 | 11:1b5a69808460 | 502 | } |
mikevd1 | 11:1b5a69808460 | 503 | else |
mikevd1 | 11:1b5a69808460 | 504 | { |
mikevd1 | 11:1b5a69808460 | 505 | fb[i] = 0x00 ; //0x81; |
mikevd1 | 11:1b5a69808460 | 506 | } |
mikevd1 | 11:1b5a69808460 | 507 | } |
rodriguj | 2:7f1160c1a741 | 508 | } else { |
mikevd1 | 11:1b5a69808460 | 509 | |
mikevd1 | 11:1b5a69808460 | 510 | for (i=0; i<196; i++) |
mikevd1 | 11:1b5a69808460 | 511 | { |
mikevd1 | 11:1b5a69808460 | 512 | if ( refreshD == 0 ) |
mikevd1 | 11:1b5a69808460 | 513 | { |
mikevd1 | 11:1b5a69808460 | 514 | //fb[i] = 0xFF ; //0x81; |
mikevd1 | 11:1b5a69808460 | 515 | } |
mikevd1 | 11:1b5a69808460 | 516 | else |
mikevd1 | 11:1b5a69808460 | 517 | { |
mikevd1 | 11:1b5a69808460 | 518 | fb[i] = 0x00 ; //0x81; |
mikevd1 | 11:1b5a69808460 | 519 | } |
mikevd1 | 11:1b5a69808460 | 520 | } |
rodriguj | 0:3d84b3bfb794 | 521 | } |
mikevd1 | 11:1b5a69808460 | 522 | if ( refreshD == 1 ) |
mikevd1 | 11:1b5a69808460 | 523 | { |
mikevd1 | 11:1b5a69808460 | 524 | refreshD = 0 ; |
mikevd1 | 11:1b5a69808460 | 525 | } |
mikevd1 | 11:1b5a69808460 | 526 | else |
mikevd1 | 11:1b5a69808460 | 527 | { |
mikevd1 | 11:1b5a69808460 | 528 | refreshD = 1; |
mikevd1 | 11:1b5a69808460 | 529 | } |
mikevd1 | 11:1b5a69808460 | 530 | |
rodriguj | 0:3d84b3bfb794 | 531 | idxfb = 0; |
rodriguj | 1:c5cf4ca5939f | 532 | if (refresh) |
rodriguj | 8:09b1578f93d9 | 533 | redraw(); |
rodriguj | 0:3d84b3bfb794 | 534 | } |
rodriguj | 0:3d84b3bfb794 | 535 | |
mikevd1 | 10:346065d26cc9 | 536 | void SSD1306::bitMap (char *bkground, bool refresh) |
mikevd1 | 11:1b5a69808460 | 537 | { |
mikevd1 | 10:346065d26cc9 | 538 | int i; |
mikevd1 | 10:346065d26cc9 | 539 | static int l = 3 ; |
mikevd1 | 10:346065d26cc9 | 540 | |
mikevd1 | 11:1b5a69808460 | 541 | if (!bkground) |
mikevd1 | 11:1b5a69808460 | 542 | { |
mikevd1 | 10:346065d26cc9 | 543 | for (i=0; i<1024; i++) |
mikevd1 | 11:1b5a69808460 | 544 | { |
mikevd1 | 10:346065d26cc9 | 545 | if ( l == 0) |
mikevd1 | 10:346065d26cc9 | 546 | { |
mikevd1 | 11:1b5a69808460 | 547 | //fb[i] = nunu_logo0[i]; |
mikevd1 | 10:346065d26cc9 | 548 | } |
mikevd1 | 10:346065d26cc9 | 549 | else if ( l == 1) |
mikevd1 | 10:346065d26cc9 | 550 | { |
mikevd1 | 11:1b5a69808460 | 551 | //fb[i] = nunu_logo1[i]; |
mikevd1 | 10:346065d26cc9 | 552 | } |
mikevd1 | 10:346065d26cc9 | 553 | else if ( l == 2) |
mikevd1 | 10:346065d26cc9 | 554 | { |
mikevd1 | 11:1b5a69808460 | 555 | //fb[i] = nunu_logo2[i]; |
mikevd1 | 10:346065d26cc9 | 556 | } |
mikevd1 | 10:346065d26cc9 | 557 | else |
mikevd1 | 10:346065d26cc9 | 558 | { |
mikevd1 | 11:1b5a69808460 | 559 | //fb[i] = nunu_logo3[i]; |
mikevd1 | 10:346065d26cc9 | 560 | } |
mikevd1 | 10:346065d26cc9 | 561 | if ( l == 4 ) |
mikevd1 | 10:346065d26cc9 | 562 | { |
mikevd1 | 10:346065d26cc9 | 563 | l = 0 ; |
mikevd1 | 10:346065d26cc9 | 564 | } |
mikevd1 | 11:1b5a69808460 | 565 | } |
mikevd1 | 11:1b5a69808460 | 566 | } |
mikevd1 | 11:1b5a69808460 | 567 | else |
mikevd1 | 11:1b5a69808460 | 568 | { |
mikevd1 | 11:1b5a69808460 | 569 | for (i=0; i<1024; i++) |
mikevd1 | 11:1b5a69808460 | 570 | { |
mikevd1 | 11:1b5a69808460 | 571 | //fb[i] = nunu_logo1[i]; |
mikevd1 | 11:1b5a69808460 | 572 | } |
mikevd1 | 10:346065d26cc9 | 573 | |
mikevd1 | 10:346065d26cc9 | 574 | } |
mikevd1 | 10:346065d26cc9 | 575 | idxfb = 0; |
mikevd1 | 10:346065d26cc9 | 576 | if (refresh) |
mikevd1 | 10:346065d26cc9 | 577 | redraw(); |
mikevd1 | 10:346065d26cc9 | 578 | } |
mikevd1 | 10:346065d26cc9 | 579 | |
rodriguj | 4:35757c8b7625 | 580 | void SSD1306::plot (char x, char y, PlotStyle mode, bool refresh) |
rodriguj | 0:3d84b3bfb794 | 581 | { |
rodriguj | 0:3d84b3bfb794 | 582 | x = x % 128; |
rodriguj | 0:3d84b3bfb794 | 583 | y = y % 64; |
rodriguj | 3:bb6fba3e84ff | 584 | |
rodriguj | 4:35757c8b7625 | 585 | switch (mode) { |
rodriguj | 2:7f1160c1a741 | 586 | case Normal: |
rodriguj | 2:7f1160c1a741 | 587 | fb[(y/8)*128+x] |= (1<<(y%8)); |
rodriguj | 2:7f1160c1a741 | 588 | break; |
rodriguj | 2:7f1160c1a741 | 589 | case Inverse: |
rodriguj | 2:7f1160c1a741 | 590 | fb[(y/8)*128+x] &= ~(1<<(y%8)); |
rodriguj | 2:7f1160c1a741 | 591 | break; |
rodriguj | 2:7f1160c1a741 | 592 | case Xor: |
rodriguj | 2:7f1160c1a741 | 593 | fb[(y/8)*128+x] ^= (1<<(y%8)); |
rodriguj | 2:7f1160c1a741 | 594 | break; |
rodriguj | 0:3d84b3bfb794 | 595 | } |
rodriguj | 1:c5cf4ca5939f | 596 | if (refresh) |
rodriguj | 8:09b1578f93d9 | 597 | redraw(); |
rodriguj | 0:3d84b3bfb794 | 598 | } |
rodriguj | 1:c5cf4ca5939f | 599 | |
rodriguj | 3:bb6fba3e84ff | 600 | bool SSD1306::point (char x, char y) |
rodriguj | 3:bb6fba3e84ff | 601 | { |
rodriguj | 3:bb6fba3e84ff | 602 | x = x % 128; |
rodriguj | 3:bb6fba3e84ff | 603 | y = y % 64; |
rodriguj | 3:bb6fba3e84ff | 604 | |
rodriguj | 3:bb6fba3e84ff | 605 | if ( fb[(y/8)*128+x] & (1<<(y%8)) ) |
rodriguj | 3:bb6fba3e84ff | 606 | return true; |
rodriguj | 3:bb6fba3e84ff | 607 | else |
rodriguj | 3:bb6fba3e84ff | 608 | return false; |
rodriguj | 3:bb6fba3e84ff | 609 | } |
rodriguj | 3:bb6fba3e84ff | 610 | |
rodriguj | 4:35757c8b7625 | 611 | void SSD1306::line (char x0, char y0, char x1, char y1, PlotStyle mode, bool refresh) |
rodriguj | 1:c5cf4ca5939f | 612 | { |
rodriguj | 1:c5cf4ca5939f | 613 | int dx = abs (x1 - x0), sx = x0 < x1 ? 1 : -1; |
rodriguj | 1:c5cf4ca5939f | 614 | int dy = -abs (y1 - y0), sy = y0 < y1 ? 1 : -1; |
rodriguj | 1:c5cf4ca5939f | 615 | int err = dx + dy, e2; /* error value e_xy */ |
rodriguj | 1:c5cf4ca5939f | 616 | |
rodriguj | 2:7f1160c1a741 | 617 | for (;;) { |
rodriguj | 2:7f1160c1a741 | 618 | /* loop */ |
rodriguj | 4:35757c8b7625 | 619 | plot (x0, y0, mode, false); |
rodriguj | 1:c5cf4ca5939f | 620 | if (x0 == x1 && y0 == y1) break; |
rodriguj | 1:c5cf4ca5939f | 621 | e2 = 2 * err; |
rodriguj | 2:7f1160c1a741 | 622 | if (e2 >= dy) { |
rodriguj | 2:7f1160c1a741 | 623 | err += dy; /* e_xy+e_x > 0 */ |
rodriguj | 2:7f1160c1a741 | 624 | x0 += sx; |
rodriguj | 2:7f1160c1a741 | 625 | } |
rodriguj | 2:7f1160c1a741 | 626 | if (e2 <= dx) { |
rodriguj | 2:7f1160c1a741 | 627 | err += dx; /* e_xy+e_y < 0 */ |
rodriguj | 2:7f1160c1a741 | 628 | y0 += sy; |
rodriguj | 2:7f1160c1a741 | 629 | } |
rodriguj | 1:c5cf4ca5939f | 630 | } |
rodriguj | 1:c5cf4ca5939f | 631 | if (refresh) |
rodriguj | 8:09b1578f93d9 | 632 | redraw(); |
rodriguj | 1:c5cf4ca5939f | 633 | } |
rodriguj | 3:bb6fba3e84ff | 634 | |
rodriguj | 4:35757c8b7625 | 635 | void SSD1306::circle (char x0, char y0, char r, PlotStyle mode, bool refresh) |
rodriguj | 3:bb6fba3e84ff | 636 | { |
rodriguj | 3:bb6fba3e84ff | 637 | int x = r-1; |
rodriguj | 3:bb6fba3e84ff | 638 | int y = 0; |
rodriguj | 3:bb6fba3e84ff | 639 | int dx = 1; |
rodriguj | 3:bb6fba3e84ff | 640 | int dy = 1; |
rodriguj | 3:bb6fba3e84ff | 641 | int err = dx - 2*r; |
rodriguj | 3:bb6fba3e84ff | 642 | |
rodriguj | 3:bb6fba3e84ff | 643 | while (x >= y) |
rodriguj | 3:bb6fba3e84ff | 644 | { |
rodriguj | 4:35757c8b7625 | 645 | plot (x0 + x, y0 + y, mode); |
rodriguj | 4:35757c8b7625 | 646 | plot (x0 + y, y0 + x, mode); |
rodriguj | 4:35757c8b7625 | 647 | plot (x0 - y, y0 + x, mode); |
rodriguj | 4:35757c8b7625 | 648 | plot (x0 - x, y0 + y, mode); |
rodriguj | 4:35757c8b7625 | 649 | plot (x0 - x, y0 - y, mode); |
rodriguj | 4:35757c8b7625 | 650 | plot (x0 - y, y0 - x, mode); |
rodriguj | 4:35757c8b7625 | 651 | plot (x0 + y, y0 - x, mode); |
rodriguj | 4:35757c8b7625 | 652 | plot (x0 + x, y0 - y, mode); |
rodriguj | 3:bb6fba3e84ff | 653 | |
rodriguj | 3:bb6fba3e84ff | 654 | if (err <= 0) |
rodriguj | 3:bb6fba3e84ff | 655 | { |
rodriguj | 3:bb6fba3e84ff | 656 | y++; |
rodriguj | 3:bb6fba3e84ff | 657 | err += dy; |
rodriguj | 3:bb6fba3e84ff | 658 | dy += 2; |
rodriguj | 3:bb6fba3e84ff | 659 | } |
rodriguj | 3:bb6fba3e84ff | 660 | if (err > 0) |
rodriguj | 3:bb6fba3e84ff | 661 | { |
rodriguj | 3:bb6fba3e84ff | 662 | x--; |
rodriguj | 3:bb6fba3e84ff | 663 | dx += 2; |
rodriguj | 3:bb6fba3e84ff | 664 | err += dx - 2*r; |
rodriguj | 3:bb6fba3e84ff | 665 | } |
rodriguj | 3:bb6fba3e84ff | 666 | } |
rodriguj | 3:bb6fba3e84ff | 667 | if (refresh) |
rodriguj | 8:09b1578f93d9 | 668 | redraw(); |
rodriguj | 3:bb6fba3e84ff | 669 | } |
rodriguj | 8:09b1578f93d9 | 670 | |
rodriguj | 8:09b1578f93d9 | 671 | void SSD1306::fill (char x, char y, bool refresh) |
rodriguj | 8:09b1578f93d9 | 672 | { |
rodriguj | 8:09b1578f93d9 | 673 | unsigned char rqueue = 0, wqueue = 1; |
rodriguj | 8:09b1578f93d9 | 674 | char *qpixel_x = new char[256]; |
rodriguj | 8:09b1578f93d9 | 675 | char *qpixel_y = new char[256]; |
rodriguj | 8:09b1578f93d9 | 676 | |
rodriguj | 8:09b1578f93d9 | 677 | if (!qpixel_x || !qpixel_y) |
rodriguj | 8:09b1578f93d9 | 678 | { |
rodriguj | 8:09b1578f93d9 | 679 | if (qpixel_x) delete[] qpixel_x; |
rodriguj | 8:09b1578f93d9 | 680 | if (qpixel_y) delete[] qpixel_y; |
rodriguj | 8:09b1578f93d9 | 681 | printf ("SSD1306::fill ERROR. Not enough memory\r\n"); |
rodriguj | 8:09b1578f93d9 | 682 | return; |
rodriguj | 8:09b1578f93d9 | 683 | } |
rodriguj | 8:09b1578f93d9 | 684 | |
rodriguj | 8:09b1578f93d9 | 685 | qpixel_x[0] = x; |
rodriguj | 8:09b1578f93d9 | 686 | qpixel_y[0] = y; |
rodriguj | 9:57209a7e9cba | 687 | plot (x, y, SSD1306::Normal); |
rodriguj | 8:09b1578f93d9 | 688 | while (wqueue != rqueue) |
rodriguj | 8:09b1578f93d9 | 689 | { |
rodriguj | 8:09b1578f93d9 | 690 | x = qpixel_x[rqueue]; |
rodriguj | 8:09b1578f93d9 | 691 | y = qpixel_y[rqueue]; |
rodriguj | 8:09b1578f93d9 | 692 | rqueue++; |
rodriguj | 8:09b1578f93d9 | 693 | |
rodriguj | 9:57209a7e9cba | 694 | if (x!=127 && !point (x+1,y)) |
rodriguj | 8:09b1578f93d9 | 695 | { |
rodriguj | 9:57209a7e9cba | 696 | plot (x+1, y, SSD1306::Normal); |
rodriguj | 8:09b1578f93d9 | 697 | qpixel_x[wqueue] = x+1; |
rodriguj | 8:09b1578f93d9 | 698 | qpixel_y[wqueue] = y; |
rodriguj | 8:09b1578f93d9 | 699 | wqueue++; |
rodriguj | 8:09b1578f93d9 | 700 | } |
rodriguj | 8:09b1578f93d9 | 701 | |
rodriguj | 9:57209a7e9cba | 702 | if (x!=0 && !point (x-1,y)) |
rodriguj | 8:09b1578f93d9 | 703 | { |
rodriguj | 9:57209a7e9cba | 704 | plot (x-1, y, SSD1306::Normal); |
rodriguj | 8:09b1578f93d9 | 705 | qpixel_x[wqueue] = x-1; |
rodriguj | 8:09b1578f93d9 | 706 | qpixel_y[wqueue] = y; |
rodriguj | 8:09b1578f93d9 | 707 | wqueue++; |
rodriguj | 8:09b1578f93d9 | 708 | } |
rodriguj | 8:09b1578f93d9 | 709 | |
rodriguj | 9:57209a7e9cba | 710 | if (y!=63 && !point (x,y+1)) |
rodriguj | 8:09b1578f93d9 | 711 | { |
rodriguj | 9:57209a7e9cba | 712 | plot (x, y+1, SSD1306::Normal); |
rodriguj | 8:09b1578f93d9 | 713 | qpixel_x[wqueue] = x; |
rodriguj | 8:09b1578f93d9 | 714 | qpixel_y[wqueue] = y+1; |
rodriguj | 8:09b1578f93d9 | 715 | wqueue++; |
rodriguj | 8:09b1578f93d9 | 716 | } |
rodriguj | 8:09b1578f93d9 | 717 | |
rodriguj | 9:57209a7e9cba | 718 | if (y!=0 && !point (x,y-1)) |
rodriguj | 8:09b1578f93d9 | 719 | { |
rodriguj | 9:57209a7e9cba | 720 | plot (x, y-1, SSD1306::Normal); |
rodriguj | 8:09b1578f93d9 | 721 | qpixel_x[wqueue] = x; |
rodriguj | 8:09b1578f93d9 | 722 | qpixel_y[wqueue] = y-1; |
rodriguj | 8:09b1578f93d9 | 723 | wqueue++; |
rodriguj | 8:09b1578f93d9 | 724 | } |
rodriguj | 8:09b1578f93d9 | 725 | } |
rodriguj | 8:09b1578f93d9 | 726 | delete[] qpixel_x; |
rodriguj | 8:09b1578f93d9 | 727 | delete[] qpixel_y; |
rodriguj | 8:09b1578f93d9 | 728 | |
rodriguj | 8:09b1578f93d9 | 729 | if (refresh) |
rodriguj | 8:09b1578f93d9 | 730 | redraw(); |
rodriguj | 8:09b1578f93d9 | 731 | } |