Fork of Silabs MemoryLCD library
Dependents: demoUI whrmDemoUI Host_Software_MAX32664GWEB_HR_EXTENDED Host_Software_MAX32664GWEC_SpO2_HR-_EXTE ... more
C++ library for Sharp Microelectronics 1.28 inch LCD TFT, LS013B7DH03, SPI bus. Forked from Silicon Labs MemoryLCD display driver.
BufferedDisplay.cpp@0:a0faa86660d4, 2015-03-18 (annotated)
- Committer:
- Steven Cooreman
- Date:
- Wed Mar 18 10:57:16 2015 -0500
- Revision:
- 0:a0faa86660d4
- Child:
- 6:fe04073fe90c
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Steven Cooreman |
0:a0faa86660d4 | 1 | /***************************************************************************//** |
Steven Cooreman |
0:a0faa86660d4 | 2 | * @file BufferedDisplay.cpp |
Steven Cooreman |
0:a0faa86660d4 | 3 | * @brief Buffered version of GraphicsDisplay |
Steven Cooreman |
0:a0faa86660d4 | 4 | ******************************************************************************* |
Steven Cooreman |
0:a0faa86660d4 | 5 | * @section License |
Steven Cooreman |
0:a0faa86660d4 | 6 | * <b>(C) Copyright 2015 Silicon Labs, http://www.silabs.com</b> |
Steven Cooreman |
0:a0faa86660d4 | 7 | ******************************************************************************* |
Steven Cooreman |
0:a0faa86660d4 | 8 | * |
Steven Cooreman |
0:a0faa86660d4 | 9 | * Permission is granted to anyone to use this software for any purpose, |
Steven Cooreman |
0:a0faa86660d4 | 10 | * including commercial applications, and to alter it and redistribute it |
Steven Cooreman |
0:a0faa86660d4 | 11 | * freely, subject to the following restrictions: |
Steven Cooreman |
0:a0faa86660d4 | 12 | * |
Steven Cooreman |
0:a0faa86660d4 | 13 | * 1. The origin of this software must not be misrepresented; you must not |
Steven Cooreman |
0:a0faa86660d4 | 14 | * claim that you wrote the original software. |
Steven Cooreman |
0:a0faa86660d4 | 15 | * 2. Altered source versions must be plainly marked as such, and must not be |
Steven Cooreman |
0:a0faa86660d4 | 16 | * misrepresented as being the original software. |
Steven Cooreman |
0:a0faa86660d4 | 17 | * 3. This notice may not be removed or altered from any source distribution. |
Steven Cooreman |
0:a0faa86660d4 | 18 | * |
Steven Cooreman |
0:a0faa86660d4 | 19 | * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no |
Steven Cooreman |
0:a0faa86660d4 | 20 | * obligation to support this Software. Silicon Labs is providing the |
Steven Cooreman |
0:a0faa86660d4 | 21 | * Software "AS IS", with no express or implied warranties of any kind, |
Steven Cooreman |
0:a0faa86660d4 | 22 | * including, but not limited to, any implied warranties of merchantability |
Steven Cooreman |
0:a0faa86660d4 | 23 | * or fitness for any particular purpose or warranties against infringement |
Steven Cooreman |
0:a0faa86660d4 | 24 | * of any proprietary rights of a third party. |
Steven Cooreman |
0:a0faa86660d4 | 25 | * |
Steven Cooreman |
0:a0faa86660d4 | 26 | * Silicon Labs will not be liable for any consequential, incidental, or |
Steven Cooreman |
0:a0faa86660d4 | 27 | * special damages, or any other relief, or for any claim by any third party, |
Steven Cooreman |
0:a0faa86660d4 | 28 | * arising from your use of this Software. |
Steven Cooreman |
0:a0faa86660d4 | 29 | * |
Steven Cooreman |
0:a0faa86660d4 | 30 | ******************************************************************************/ |
Steven Cooreman |
0:a0faa86660d4 | 31 | |
Steven Cooreman |
0:a0faa86660d4 | 32 | #include "BufferedDisplay.h" |
Steven Cooreman |
0:a0faa86660d4 | 33 | |
Steven Cooreman |
0:a0faa86660d4 | 34 | #define SWAP8(a) ((((a) & 0x80) >> 7) | (((a) & 0x40) >> 5) | (((a) & 0x20) >> 3) | (((a) & 0x10) >> 1) | (((a) & 0x08) << 1) | (((a) & 0x04) << 3) | (((a) & 0x02) << 5) | (((a) & 0x01) << 7)) |
Steven Cooreman |
0:a0faa86660d4 | 35 | |
Steven Cooreman |
0:a0faa86660d4 | 36 | namespace silabs { |
Steven Cooreman |
0:a0faa86660d4 | 37 | |
Steven Cooreman |
0:a0faa86660d4 | 38 | BufferedDisplay::BufferedDisplay(const char *name) : GraphicsDisplay(name) { |
Steven Cooreman |
0:a0faa86660d4 | 39 | memset((uint8_t*)_pixelBuffer, White, sizeof(_pixelBuffer)); // init full frame buffer |
Steven Cooreman |
0:a0faa86660d4 | 40 | memset((uint8_t*)_dirtyRows, 0xFF, sizeof(_dirtyRows)); // init dirty status |
Steven Cooreman |
0:a0faa86660d4 | 41 | } |
Steven Cooreman |
0:a0faa86660d4 | 42 | |
Steven Cooreman |
0:a0faa86660d4 | 43 | /** |
Steven Cooreman |
0:a0faa86660d4 | 44 | * Override of GraphicsDisplay's pixel() |
Steven Cooreman |
0:a0faa86660d4 | 45 | */ |
Steven Cooreman |
0:a0faa86660d4 | 46 | |
Steven Cooreman |
0:a0faa86660d4 | 47 | void BufferedDisplay::pixel(int x, int y, int colour) { |
Steven Cooreman |
0:a0faa86660d4 | 48 | uint8_t swapx = 7 - ((unsigned int)x & 0x07); |
Steven Cooreman |
0:a0faa86660d4 | 49 | x = ((unsigned int)x & 0xFFFFFFF8) | swapx; |
Steven Cooreman |
0:a0faa86660d4 | 50 | |
Steven Cooreman |
0:a0faa86660d4 | 51 | // determine change |
Steven Cooreman |
0:a0faa86660d4 | 52 | bool change = ((_pixelBuffer[((y * DISPLAY_WIDTH) + x) / DISPLAY_BUFFER_TYPE_SIZE] & (1 << (x % DISPLAY_BUFFER_TYPE_SIZE))) != ((colour & 0x01) << (x % DISPLAY_BUFFER_TYPE_SIZE))); |
Steven Cooreman |
0:a0faa86660d4 | 53 | if(change) { |
Steven Cooreman |
0:a0faa86660d4 | 54 | // xor operation |
Steven Cooreman |
0:a0faa86660d4 | 55 | _pixelBuffer[((y * DISPLAY_WIDTH) + x) / DISPLAY_BUFFER_TYPE_SIZE] ^= (1 << (x % DISPLAY_BUFFER_TYPE_SIZE)); |
Steven Cooreman |
0:a0faa86660d4 | 56 | |
Steven Cooreman |
0:a0faa86660d4 | 57 | // notify dirty status of this line |
Steven Cooreman |
0:a0faa86660d4 | 58 | _dirtyRows[y / DISPLAY_BUFFER_TYPE_SIZE] |= (1 << (y % DISPLAY_BUFFER_TYPE_SIZE)); |
Steven Cooreman |
0:a0faa86660d4 | 59 | } |
Steven Cooreman |
0:a0faa86660d4 | 60 | } |
Steven Cooreman |
0:a0faa86660d4 | 61 | |
Steven Cooreman |
0:a0faa86660d4 | 62 | int BufferedDisplay::width() { |
Steven Cooreman |
0:a0faa86660d4 | 63 | return DISPLAY_WIDTH; |
Steven Cooreman |
0:a0faa86660d4 | 64 | } |
Steven Cooreman |
0:a0faa86660d4 | 65 | int BufferedDisplay::height() { |
Steven Cooreman |
0:a0faa86660d4 | 66 | return DISPLAY_HEIGHT; |
Steven Cooreman |
0:a0faa86660d4 | 67 | } |
Steven Cooreman |
0:a0faa86660d4 | 68 | |
Steven Cooreman |
0:a0faa86660d4 | 69 | /** |
Steven Cooreman |
0:a0faa86660d4 | 70 | * Function to move bitmap into frame buffer |
Steven Cooreman |
0:a0faa86660d4 | 71 | * arguments: |
Steven Cooreman |
0:a0faa86660d4 | 72 | * * bitmap: pointer to uint8 array containing horizontal pixel data |
Steven Cooreman |
0:a0faa86660d4 | 73 | * * bmpWidth: width of the bitmap in pixels (must be byte multiple) |
Steven Cooreman |
0:a0faa86660d4 | 74 | * * bmpHeight: height of the bitmap in pixels (must be byte multiple) |
Steven Cooreman |
0:a0faa86660d4 | 75 | * * startX: starting position to apply bitmap in horizontal direction (0 = leftmost) (must be byte multiple) |
Steven Cooreman |
0:a0faa86660d4 | 76 | * * startY: starting position to apply bitmap in vertical direction (0 = topmost) (must be byte multiple) |
Steven Cooreman |
0:a0faa86660d4 | 77 | */ |
Steven Cooreman |
0:a0faa86660d4 | 78 | void BufferedDisplay::showBMP(const uint8_t* bitmap, const uint32_t bmpWidth, const uint32_t bmpHeight, const uint32_t startX, const uint32_t startY) { |
Steven Cooreman |
0:a0faa86660d4 | 79 | uint32_t iterBMP = 0, iterFB = startY; |
Steven Cooreman |
0:a0faa86660d4 | 80 | |
Steven Cooreman |
0:a0faa86660d4 | 81 | /* Apply constraints */ |
Steven Cooreman |
0:a0faa86660d4 | 82 | if((bmpWidth & 0x07) != 0) return; |
Steven Cooreman |
0:a0faa86660d4 | 83 | if((bmpHeight & 0x07) != 0) return; |
Steven Cooreman |
0:a0faa86660d4 | 84 | if((startX & 0x07) != 0) return; |
Steven Cooreman |
0:a0faa86660d4 | 85 | if(startX > DISPLAY_WIDTH) return; |
Steven Cooreman |
0:a0faa86660d4 | 86 | if((startY & 0x07) != 0) return; |
Steven Cooreman |
0:a0faa86660d4 | 87 | |
Steven Cooreman |
0:a0faa86660d4 | 88 | /* Copy over bytes to the framebuffer */ |
Steven Cooreman |
0:a0faa86660d4 | 89 | for(; iterFB < DISPLAY_HEIGHT; iterFB++) { |
Steven Cooreman |
0:a0faa86660d4 | 90 | memcpy( (void*) &(_pixelBuffer[((iterFB * DISPLAY_WIDTH) + startX) / DISPLAY_BUFFER_TYPE_SIZE]), |
Steven Cooreman |
0:a0faa86660d4 | 91 | (const void*) &(bitmap[iterBMP * (bmpWidth / 8)]), |
Steven Cooreman |
0:a0faa86660d4 | 92 | (DISPLAY_WIDTH - startX) / 8); |
Steven Cooreman |
0:a0faa86660d4 | 93 | |
Steven Cooreman |
0:a0faa86660d4 | 94 | _dirtyRows[iterFB / DISPLAY_BUFFER_TYPE_SIZE] |= (1 << (iterFB % DISPLAY_BUFFER_TYPE_SIZE)); |
Steven Cooreman |
0:a0faa86660d4 | 95 | iterBMP++; |
Steven Cooreman |
0:a0faa86660d4 | 96 | } |
Steven Cooreman |
0:a0faa86660d4 | 97 | |
Steven Cooreman |
0:a0faa86660d4 | 98 | return; |
Steven Cooreman |
0:a0faa86660d4 | 99 | } |
Steven Cooreman |
0:a0faa86660d4 | 100 | } |