|
本帖最后由 飞向狙沙 于 2023-6-21 16:24 编辑
偶然间看到一个屏幕,JDI的MemoryLCD,感觉跟以前诺基亚手机上用的日光屏应该是一个原理,外界光线越亮屏幕越清晰,和普通TFT的环境光越亮屏幕越不清晰正好相反,这玩意刷新率和残影效果吊打墨水屏,不知道为啥没火起来
效果:环境光无背光
效果:开闪光灯无背光
背光没接线,暂时没测,这个屏感觉两个有意思的点,一个就是上边说的日光效果,另一个就是没有驱动IC,没有缓存,电路直接刻再玻璃上,所以只能整行刷新,不能像普通屏幕一样单独刷新一个点,所以对单片机的ram要求比较高,或者外挂外部ram
既然是发到了单片机区,多少得整点代码
点屏使用了arduino的JDI_MIP_Display库,但是这个库有个缺点,不支持屏幕旋转,研究了一下,转屏也好实现
库实现原理是整一个和屏幕尺寸一样大的数组,写图案或者文字时先局部往数组里更新,最后再一次性全部刷新到屏幕,实现转屏只需要在图案往数组更新时按照屏幕旋转后的坐标更新到合适的
修改前的写像素点代码
- void JDI_MIP_Display::drawPixel(int16_t x, int16_t y, uint16_t color)
- {
- if(x < 0 || x >= width() || y < 0 || y >= height()){
- return;
- }
- int pixelIdx = ((width() / 2) * y) + (x / 2);
- if(x % 2 == 0){
- _backBuffer[pixelIdx] &= 0x0F;
- _backBuffer[pixelIdx] |= (color & 0x0F) << 4;
- }
- else{
- _backBuffer[pixelIdx] &= 0xF0;
- _backBuffer[pixelIdx] |= color & 0x0F;
- }
- }
复制代码 修改后的写像素点代码
- void JDI_MIP_Display::drawPixel(int16_t x, int16_t y, uint16_t color)
- {
- if (x < 0 || x >= width() || y < 0 || y >= height())
- {
- return;
- }
- int16_t t;
- switch (rotation)
- {
- case 1:
- t = x;
- x = WIDTH - 1 - y;
- y = t;
- break;
- case 2:
- x = WIDTH - 1 - x;
- y = HEIGHT - 1 - y;
- break;
- case 3:
- t = x;
- x = y;
- y = HEIGHT - 1 - t;
- break;
- default:
- break;
- }
- int pixelIdx = ((WIDTH / 2) * y) + (x / 2);
- // 一char8位,前4位后4位存两个像素点,判断x奇偶,确定x是前4位还是后4位
- if (x % 2 == 0)
- {
- _backBuffer[pixelIdx] &= 0x0F;
- _backBuffer[pixelIdx] |= (color & 0x0F) << 4;
- }
- else
- {
- _backBuffer[pixelIdx] &= 0xF0;
- _backBuffer[pixelIdx] |= color & 0x0F;
- }
- }
复制代码
完整的cpp文件
- // MIT License
- //
- // Copyright(c) 2021 Giovanni Bertazzoni <nottheworstdev@gmail.com>
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files(the "Software"), to deal
- // in the Software without restriction, including without limitation the rights
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- // copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions :
- //
- // The above copyright notice and this permission notice shall be included in all
- // copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- // SOFTWARE.
- #include <JDI_MIP_Display.h>
- JDI_MIP_Display::JDI_MIP_Display() : Adafruit_GFX(DISPLAY_WIDTH, DISPLAY_HEIGHT)
- {
- _scs = PIN_SCS;
- _disp = PIN_DISP;
- _frontlight = PIN_FRONTLIGHT;
- }
- void JDI_MIP_Display::begin()
- {
- _background = COLOR_BLACK;
- digitalWrite(_scs, LOW);
- pinMode(_scs, OUTPUT);
- pinMode(_disp, OUTPUT);
- pinMode(_frontlight, OUTPUT);
- memset(&_backBuffer[0], (char)((_background & 0x0F) | ((_background & 0x0F) << 4)), sizeof(_backBuffer));
- #ifdef DIFF_LINE_UPDATE
- memset(&_dispBuffer[0], (char)((_background & 0x0F) | ((_background & 0x0F) << 4)), sizeof(_dispBuffer));
- #endif
- SPI.begin();
- }
- void JDI_MIP_Display::refresh()
- {
- for (int i = 0; i < HEIGHT; i++)
- {
- int lineIdx = HALF_WIDTH * i;
- char *line_cmd;
- #ifdef DIFF_LINE_UPDATE
- if (compareBuffersLine(lineIdx) == true)
- continue;
- memcpy(&_dispBuffer[lineIdx], &_backBuffer[lineIdx], HALF_WIDTH);
- line_cmd = &_dispBuffer[lineIdx];
- #else
- line_cmd = &_backBuffer[lineIdx];
- #endif
- sendLineCommand(line_cmd, i);
- }
- }
- bool JDI_MIP_Display::compareBuffersLine(int lineIndex)
- {
- #ifdef DIFF_LINE_UPDATE
- for (int i = 0; i < HALF_WIDTH; i++)
- {
- int pixelIdx = lineIndex + i;
- if (_backBuffer[pixelIdx] != _dispBuffer[pixelIdx])
- return false;
- }
- #endif
- return true;
- }
- void JDI_MIP_Display::clearScreen()
- {
- digitalWrite(_scs, HIGH);
- SPI.transfer(CMD_ALL_CLEAR);
- SPI.transfer(0x00);
- digitalWrite(_scs, LOW);
- }
- void JDI_MIP_Display::sendLineCommand(char *line_cmd, int line)
- {
- if ((line < 0) || (line >= HEIGHT))
- {
- return;
- }
- digitalWrite(_scs, HIGH);
- SPI.transfer(CMD_UPDATE);
- SPI.transfer(line + 1);
- for (int i = 0; i < HALF_WIDTH; i++)
- {
- SPI.transfer(line_cmd[i]);
- }
- SPI.transfer(0x00);
- SPI.transfer(0x00);
- digitalWrite(_scs, LOW);
- }
- void JDI_MIP_Display::drawPixel(int16_t x, int16_t y, uint16_t color)
- {
- if (x < 0 || x >= width() || y < 0 || y >= height())
- {
- return;
- }
- int16_t t;
- switch (rotation)
- {
- case 1:
- t = x;
- x = WIDTH - 1 - y;
- y = t;
- break;
- case 2:
- x = WIDTH - 1 - x;
- y = HEIGHT - 1 - y;
- break;
- case 3:
- t = x;
- x = y;
- y = HEIGHT - 1 - t;
- break;
- default:
- break;
- }
- int pixelIdx = ((WIDTH / 2) * y) + (x / 2);
- // 一char8位,前4位后4位存两个像素点,判断x奇偶,确定x是前4位还是后4位
- if (x % 2 == 0)
- {
- _backBuffer[pixelIdx] &= 0x0F;
- _backBuffer[pixelIdx] |= (color & 0x0F) << 4;
- }
- else
- {
- _backBuffer[pixelIdx] &= 0xF0;
- _backBuffer[pixelIdx] |= color & 0x0F;
- }
- }
- void JDI_MIP_Display::setBackgroundColor(uint16_t color)
- {
- _background = color;
- }
- void JDI_MIP_Display::displayOn()
- {
- digitalWrite(_disp, HIGH);
- }
- void JDI_MIP_Display::displayOff()
- {
- digitalWrite(_disp, LOW);
- }
- void JDI_MIP_Display::frontlightOn()
- {
- digitalWrite(_frontlight, HIGH);
- }
- void JDI_MIP_Display::frontlightOff()
- {
- digitalWrite(_frontlight, LOW);
- }
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
打赏
-
查看全部打赏
|