|
| 1 | +#include "Arduino_ST77916.h" |
| 2 | + |
| 3 | +Arduino_ST77916::Arduino_ST77916( |
| 4 | + Arduino_DataBus *bus, int8_t rst, uint8_t r, |
| 5 | + bool ips, int16_t w, int16_t h, |
| 6 | + uint8_t col_offset1, uint8_t row_offset1, uint8_t col_offset2, uint8_t row_offset2) |
| 7 | + : Arduino_TFT(bus, rst, r, ips, w, h, col_offset1, row_offset1, col_offset2, row_offset2) |
| 8 | +{ |
| 9 | +} |
| 10 | + |
| 11 | +bool Arduino_ST77916::begin(int32_t speed) |
| 12 | +{ |
| 13 | + return Arduino_TFT::begin(speed); |
| 14 | +} |
| 15 | + |
| 16 | +/**************************************************************************/ |
| 17 | +/*! |
| 18 | + @brief Set origin of (0,0) and orientation of TFT display |
| 19 | + @param m The index for rotation, from 0-3 inclusive |
| 20 | +*/ |
| 21 | +/**************************************************************************/ |
| 22 | +void Arduino_ST77916::setRotation(uint8_t r) |
| 23 | +{ |
| 24 | + Arduino_TFT::setRotation(r); |
| 25 | + switch (_rotation) |
| 26 | + { |
| 27 | + case 1: |
| 28 | + r = ST77916_MADCTL_MX | ST77916_MADCTL_MV | ST77916_MADCTL_RGB; |
| 29 | + break; |
| 30 | + case 2: |
| 31 | + r = ST77916_MADCTL_MX | ST77916_MADCTL_MY | ST77916_MADCTL_RGB; |
| 32 | + break; |
| 33 | + case 3: |
| 34 | + r = ST77916_MADCTL_MY | ST77916_MADCTL_MV | ST77916_MADCTL_RGB; |
| 35 | + break; |
| 36 | + default: // case 0: |
| 37 | + r = ST77916_MADCTL_RGB; |
| 38 | + break; |
| 39 | + } |
| 40 | + _bus->beginWrite(); |
| 41 | + _bus->writeC8D8(ST77916_MADCTL, r); |
| 42 | + _bus->endWrite(); |
| 43 | +} |
| 44 | + |
| 45 | +void Arduino_ST77916::writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t h) |
| 46 | +{ |
| 47 | + if ((x != _currentX) || (w != _currentW)) |
| 48 | + { |
| 49 | + _currentX = x; |
| 50 | + _currentW = w; |
| 51 | + x += _xStart; |
| 52 | + _bus->writeC8D16D16(ST77916_CASET, x, x + w - 1); |
| 53 | + } |
| 54 | + |
| 55 | + if ((y != _currentY) || (h != _currentH)) |
| 56 | + { |
| 57 | + _currentY = y; |
| 58 | + _currentH = h; |
| 59 | + y += _yStart; |
| 60 | + _bus->writeC8D16D16(ST77916_RASET, y, y + h - 1); |
| 61 | + } |
| 62 | + |
| 63 | + _bus->writeCommand(ST77916_RAMWR); // write to RAM |
| 64 | +} |
| 65 | + |
| 66 | +void Arduino_ST77916::invertDisplay(bool i) |
| 67 | +{ |
| 68 | + _bus->sendCommand((_ips ^ i) ? ST77916_INVON : ST77916_INVOFF); |
| 69 | +} |
| 70 | + |
| 71 | +void Arduino_ST77916::displayOn(void) |
| 72 | +{ |
| 73 | + _bus->sendCommand(ST77916_SLPOUT); |
| 74 | + delay(ST77916_SLPOUT_DELAY); |
| 75 | +} |
| 76 | + |
| 77 | +void Arduino_ST77916::displayOff(void) |
| 78 | +{ |
| 79 | + _bus->sendCommand(ST77916_SLPIN); |
| 80 | + delay(ST77916_SLPIN_DELAY); |
| 81 | +} |
| 82 | + |
| 83 | +// Companion code to the above tables. Reads and issues |
| 84 | +// a series of LCD commands stored in PROGMEM byte array. |
| 85 | +void Arduino_ST77916::tftInit() |
| 86 | +{ |
| 87 | + if (_rst != GFX_NOT_DEFINED) |
| 88 | + { |
| 89 | + pinMode(_rst, OUTPUT); |
| 90 | + digitalWrite(_rst, HIGH); |
| 91 | + delay(100); |
| 92 | + digitalWrite(_rst, LOW); |
| 93 | + delay(ST77916_RST_DELAY); |
| 94 | + digitalWrite(_rst, HIGH); |
| 95 | + delay(ST77916_RST_DELAY); |
| 96 | + } |
| 97 | + else |
| 98 | + { |
| 99 | + // Software Rest |
| 100 | + _bus->sendCommand(ST77916_SWRESET); |
| 101 | + delay(ST77916_RST_DELAY); |
| 102 | + } |
| 103 | + |
| 104 | + _bus->batchOperation(st77916_init_operations, sizeof(st77916_init_operations)); |
| 105 | + |
| 106 | + invertDisplay(false); |
| 107 | +} |
0 commit comments