Bracciale Slave
Adafruit_SSD1306.cpp@19:e5d8d6e7fac5, 2019-02-25 (annotated)
- Committer:
- gandhi4
- Date:
- Mon Feb 25 21:14:16 2019 +0000
- Revision:
- 19:e5d8d6e7fac5
- Parent:
- 18:a267f00528be
a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nkhorman | 0:c3dcd4c4983a | 1 | #include "mbed.h" |
nkhorman | 0:c3dcd4c4983a | 2 | #include "Adafruit_SSD1306.h" |
nkhorman | 0:c3dcd4c4983a | 3 | |
nkhorman | 9:ddb97c9850a2 | 4 | #define SSD1306_SETCONTRAST 0x81 |
nkhorman | 9:ddb97c9850a2 | 5 | #define SSD1306_DISPLAYALLON_RESUME 0xA4 |
nkhorman | 9:ddb97c9850a2 | 6 | #define SSD1306_DISPLAYALLON 0xA5 |
nkhorman | 9:ddb97c9850a2 | 7 | #define SSD1306_NORMALDISPLAY 0xA6 |
nkhorman | 9:ddb97c9850a2 | 8 | #define SSD1306_INVERTDISPLAY 0xA7 |
nkhorman | 9:ddb97c9850a2 | 9 | #define SSD1306_DISPLAYOFF 0xAE |
nkhorman | 9:ddb97c9850a2 | 10 | #define SSD1306_DISPLAYON 0xAF |
nkhorman | 9:ddb97c9850a2 | 11 | #define SSD1306_SETDISPLAYOFFSET 0xD3 |
nkhorman | 9:ddb97c9850a2 | 12 | #define SSD1306_SETCOMPINS 0xDA |
nkhorman | 9:ddb97c9850a2 | 13 | #define SSD1306_SETVCOMDETECT 0xDB |
nkhorman | 9:ddb97c9850a2 | 14 | #define SSD1306_SETDISPLAYCLOCKDIV 0xD5 |
nkhorman | 9:ddb97c9850a2 | 15 | #define SSD1306_SETPRECHARGE 0xD9 |
nkhorman | 9:ddb97c9850a2 | 16 | #define SSD1306_SETMULTIPLEX 0xA8 |
nkhorman | 9:ddb97c9850a2 | 17 | #define SSD1306_SETLOWCOLUMN 0x00 |
nkhorman | 9:ddb97c9850a2 | 18 | #define SSD1306_SETHIGHCOLUMN 0x10 |
nkhorman | 9:ddb97c9850a2 | 19 | #define SSD1306_SETSTARTLINE 0x40 |
nkhorman | 9:ddb97c9850a2 | 20 | #define SSD1306_MEMORYMODE 0x20 |
nkhorman | 9:ddb97c9850a2 | 21 | #define SSD1306_COMSCANINC 0xC0 |
nkhorman | 9:ddb97c9850a2 | 22 | #define SSD1306_COMSCANDEC 0xC8 |
nkhorman | 9:ddb97c9850a2 | 23 | #define SSD1306_SEGREMAP 0xA0 |
nkhorman | 9:ddb97c9850a2 | 24 | #define SSD1306_CHARGEPUMP 0x8D |
nkhorman | 0:c3dcd4c4983a | 25 | |
nkhorman | 0:c3dcd4c4983a | 26 | void Adafruit_SSD1306::begin(uint8_t vccstate) |
nkhorman | 0:c3dcd4c4983a | 27 | { |
nkhorman | 9:ddb97c9850a2 | 28 | |
nkhorman | 9:ddb97c9850a2 | 29 | command(SSD1306_DISPLAYOFF); |
nkhorman | 9:ddb97c9850a2 | 30 | command(SSD1306_SETDISPLAYCLOCKDIV); |
nkhorman | 9:ddb97c9850a2 | 31 | command(0x80); // the suggested ratio 0x80 |
nkhorman | 9:ddb97c9850a2 | 32 | |
nkhorman | 9:ddb97c9850a2 | 33 | command(SSD1306_SETMULTIPLEX); |
nkhorman | 9:ddb97c9850a2 | 34 | command(_rawHeight-1); |
nkhorman | 9:ddb97c9850a2 | 35 | |
nkhorman | 9:ddb97c9850a2 | 36 | command(SSD1306_SETDISPLAYOFFSET); |
nkhorman | 9:ddb97c9850a2 | 37 | command(0x0); // no offset |
nkhorman | 9:ddb97c9850a2 | 38 | |
nkhorman | 9:ddb97c9850a2 | 39 | command(SSD1306_SETSTARTLINE | 0x0); // line #0 |
nkhorman | 9:ddb97c9850a2 | 40 | |
nkhorman | 9:ddb97c9850a2 | 41 | command(SSD1306_CHARGEPUMP); |
nkhorman | 9:ddb97c9850a2 | 42 | command((vccstate == SSD1306_EXTERNALVCC) ? 0x10 : 0x14); |
nkhorman | 9:ddb97c9850a2 | 43 | |
nkhorman | 9:ddb97c9850a2 | 44 | command(SSD1306_MEMORYMODE); |
nkhorman | 9:ddb97c9850a2 | 45 | command(0x00); // 0x0 act like ks0108 |
chrta | 4:853097cfa773 | 46 | |
nkhorman | 9:ddb97c9850a2 | 47 | command(SSD1306_SEGREMAP | 0x1); |
nkhorman | 9:ddb97c9850a2 | 48 | |
nkhorman | 9:ddb97c9850a2 | 49 | command(SSD1306_COMSCANDEC); |
nkhorman | 9:ddb97c9850a2 | 50 | |
nkhorman | 9:ddb97c9850a2 | 51 | command(SSD1306_SETCOMPINS); |
nkhorman | 9:ddb97c9850a2 | 52 | command(_rawHeight == 32 ? 0x02 : 0x12); // TODO - calculate based on _rawHieght ? |
nkhorman | 9:ddb97c9850a2 | 53 | |
nkhorman | 9:ddb97c9850a2 | 54 | command(SSD1306_SETCONTRAST); |
nkhorman | 9:ddb97c9850a2 | 55 | command(_rawHeight == 32 ? 0x8F : ((vccstate == SSD1306_EXTERNALVCC) ? 0x9F : 0xCF) ); |
nkhorman | 9:ddb97c9850a2 | 56 | |
nkhorman | 9:ddb97c9850a2 | 57 | command(SSD1306_SETPRECHARGE); |
nkhorman | 9:ddb97c9850a2 | 58 | command((vccstate == SSD1306_EXTERNALVCC) ? 0x22 : 0xF1); |
nkhorman | 9:ddb97c9850a2 | 59 | |
nkhorman | 9:ddb97c9850a2 | 60 | command(SSD1306_SETVCOMDETECT); |
nkhorman | 9:ddb97c9850a2 | 61 | command(0x40); |
nkhorman | 9:ddb97c9850a2 | 62 | |
nkhorman | 9:ddb97c9850a2 | 63 | command(SSD1306_DISPLAYALLON_RESUME); |
nkhorman | 9:ddb97c9850a2 | 64 | |
JojoS | 16:7fb1d4d3525d | 65 | command(SSD1306_NORMALDISPLAY); |
nkhorman | 0:c3dcd4c4983a | 66 | |
JojoS | 16:7fb1d4d3525d | 67 | command(SSD1306_DISPLAYON); |
nkhorman | 0:c3dcd4c4983a | 68 | } |
nkhorman | 0:c3dcd4c4983a | 69 | |
nkhorman | 9:ddb97c9850a2 | 70 | // Set a single pixel |
nkhorman | 0:c3dcd4c4983a | 71 | void Adafruit_SSD1306::drawPixel(int16_t x, int16_t y, uint16_t color) |
nkhorman | 0:c3dcd4c4983a | 72 | { |
nkhorman | 0:c3dcd4c4983a | 73 | if ((x < 0) || (x >= width()) || (y < 0) || (y >= height())) |
nkhorman | 0:c3dcd4c4983a | 74 | return; |
nkhorman | 0:c3dcd4c4983a | 75 | |
gandhi4 | 19:e5d8d6e7fac5 | 76 | |
nkhorman | 0:c3dcd4c4983a | 77 | |
nkhorman | 0:c3dcd4c4983a | 78 | // x is which column |
nkhorman | 0:c3dcd4c4983a | 79 | if (color == WHITE) |
nkhorman | 9:ddb97c9850a2 | 80 | buffer[x+ (y/8)*_rawWidth] |= _BV((y%8)); |
nkhorman | 9:ddb97c9850a2 | 81 | else // else black |
nkhorman | 9:ddb97c9850a2 | 82 | buffer[x+ (y/8)*_rawWidth] &= ~_BV((y%8)); |
nkhorman | 0:c3dcd4c4983a | 83 | } |
nkhorman | 0:c3dcd4c4983a | 84 | |
nkhorman | 0:c3dcd4c4983a | 85 | void Adafruit_SSD1306::invertDisplay(bool i) |
nkhorman | 0:c3dcd4c4983a | 86 | { |
nkhorman | 9:ddb97c9850a2 | 87 | command(i ? SSD1306_INVERTDISPLAY : SSD1306_NORMALDISPLAY); |
nkhorman | 0:c3dcd4c4983a | 88 | } |
nkhorman | 0:c3dcd4c4983a | 89 | |
nkhorman | 9:ddb97c9850a2 | 90 | // Send the display buffer out to the display |
nkhorman | 9:ddb97c9850a2 | 91 | void Adafruit_SSD1306::display(void) |
nkhorman | 0:c3dcd4c4983a | 92 | { |
nkhorman | 9:ddb97c9850a2 | 93 | command(SSD1306_SETLOWCOLUMN | 0x0); // low col = 0 |
nkhorman | 9:ddb97c9850a2 | 94 | command(SSD1306_SETHIGHCOLUMN | 0x0); // hi col = 0 |
nkhorman | 9:ddb97c9850a2 | 95 | command(SSD1306_SETSTARTLINE | 0x0); // line #0 |
nkhorman | 9:ddb97c9850a2 | 96 | sendDisplayBuffer(); |
nkhorman | 0:c3dcd4c4983a | 97 | } |
nkhorman | 0:c3dcd4c4983a | 98 | |
nkhorman | 9:ddb97c9850a2 | 99 | // Clear the display buffer. Requires a display() call at some point afterwards |
nkhorman | 9:ddb97c9850a2 | 100 | void Adafruit_SSD1306::clearDisplay(void) |
nkhorman | 0:c3dcd4c4983a | 101 | { |
nkhorman | 9:ddb97c9850a2 | 102 | std::fill(buffer.begin(),buffer.end(),0); |
nkhorman | 0:c3dcd4c4983a | 103 | } |
nkhorman | 0:c3dcd4c4983a | 104 | |
nkhorman | 9:ddb97c9850a2 | 105 |