/***************************************************************************//** * @file lcd.cpp * @brief Implementation of lcd.cpp * @author Rbolboac (ramona.bolboaca@analog.com) ******************************************************************************* * Copyright 2022(c) Analog Devices, Inc. * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * - Neither the name of Analog Devices, Inc. nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * - The use of this software may or may not infringe the patent rights * of one or more patent holders. This license does not release you * from the requirement that you obtain separate licenses from these * patent holders to use this software. * - Use of the software either in source or binary form, must be run * on or directly connected to an Analog Devices Inc. component. * * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ #ifdef EVAL_BUILD #include #include #include #include #include #include #include #include #define LCD_REVERSE 0x1 #define LCD_BLINK 0x2 #define LCD_BLINK_INTERVAL 500 #define FB_FLUSH_DELAY 30 uint8_t framebuffer_memory[4][128]; //512 bytes static uint8_t lcd_tty_buffer[128]; static int tty_cursor = 0; static bool blink_on = false; static const uint8_t ASC16[256][8] = { {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, 0x00, 0x00}, {0x00, 0x3E, 0x6B, 0x4F, 0x6B, 0x3E, 0x00, 0x00}, {0x00, 0x1C, 0x3E, 0x7C, 0x3E, 0x1C, 0x00, 0x00}, {0x00, 0x18, 0x3C, 0x7E, 0x3C, 0x18, 0x00, 0x00}, {0x00, 0x1C, 0x57, 0x7D, 0x57, 0x1C, 0x00, 0x00}, {0x00, 0x1C, 0x5E, 0x7F, 0x5E, 0x1C, 0x00, 0x00}, {0x00, 0x00, 0x18, 0x3C, 0x18, 0x00, 0x00, 0x00}, {0x00, 0xFF, 0xE7, 0xC3, 0xE7, 0xFF, 0x00, 0x00}, {0x00, 0x00, 0x18, 0x24, 0x18, 0x00, 0x00, 0x00}, {0x00, 0xFF, 0xE7, 0xDB, 0xE7, 0xFF, 0x00, 0x00}, {0x00, 0x30, 0x48, 0x3A, 0x06, 0x0E, 0x00, 0x00}, {0x00, 0x26, 0x29, 0x79, 0x29, 0x26, 0x00, 0x00}, {0x00, 0x40, 0x7F, 0x05, 0x05, 0x07, 0x00, 0x00}, {0x00, 0x40, 0x7F, 0x05, 0x25, 0x3F, 0x00, 0x00}, {0x00, 0x5A, 0x3C, 0xE7, 0x3C, 0x5A, 0x00, 0x00}, {0x00, 0x7F, 0x3E, 0x1C, 0x1C, 0x08, 0x00, 0x00}, {0x00, 0x08, 0x1C, 0x1C, 0x3E, 0x7F, 0x00, 0x00}, {0x00, 0x14, 0x22, 0x7F, 0x22, 0x14, 0x00, 0x00}, {0x00, 0x5F, 0x5F, 0x00, 0x5F, 0x5F, 0x00, 0x00}, {0x00, 0x06, 0x09, 0x7F, 0x01, 0x7F, 0x00, 0x00}, {0x00, 0x00, 0x66, 0x89, 0x95, 0x6A, 0x00, 0x00}, {0x00, 0x60, 0x60, 0x60, 0x60, 0x60, 0x00, 0x00}, {0x00, 0x94, 0xA2, 0xFF, 0xA2, 0x94, 0x00, 0x00}, {0x00, 0x08, 0x04, 0x7E, 0x04, 0x08, 0x00, 0x00}, {0x00, 0x10, 0x20, 0x7E, 0x20, 0x10, 0x00, 0x00}, {0x00, 0x08, 0x08, 0x2A, 0x1C, 0x08, 0x00, 0x00}, {0x00, 0x08, 0x1C, 0x2A, 0x08, 0x08, 0x00, 0x00}, {0x00, 0x1E, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00}, {0x00, 0x0C, 0x1E, 0x0C, 0x1E, 0x0C, 0x00, 0x00}, {0x00, 0x30, 0x38, 0x3E, 0x38, 0x30, 0x00, 0x00}, {0x00, 0x06, 0x0E, 0x3E, 0x0E, 0x06, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x5F, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x07, 0x00, 0x07, 0x00, 0x00, 0x00}, {0x00, 0x14, 0x7F, 0x14, 0x7F, 0x14, 0x00, 0x00}, {0x00, 0x24, 0x2A, 0x7F, 0x2A, 0x12, 0x00, 0x00}, {0x00, 0x23, 0x13, 0x08, 0x64, 0x62, 0x00, 0x00}, {0x00, 0x36, 0x49, 0x56, 0x20, 0x50, 0x00, 0x00}, {0x00, 0x00, 0x08, 0x07, 0x03, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x1C, 0x22, 0x41, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x41, 0x22, 0x1C, 0x00, 0x00, 0x00}, {0x00, 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, 0x00, 0x00}, {0x00, 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00, 0x00}, {0x00, 0x00, 0x80, 0x70, 0x30, 0x00, 0x00, 0x00}, {0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00}, {0x00, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00, 0x00}, {0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E, 0x00, 0x00}, {0x00, 0x00, 0x42, 0x7F, 0x40, 0x00, 0x00, 0x00}, {0x00, 0x72, 0x49, 0x49, 0x49, 0x46, 0x00, 0x00}, {0x00, 0x21, 0x41, 0x49, 0x4D, 0x33, 0x00, 0x00}, {0x00, 0x18, 0x14, 0x12, 0x7F, 0x10, 0x00, 0x00}, {0x00, 0x27, 0x45, 0x45, 0x45, 0x39, 0x00, 0x00}, {0x00, 0x3C, 0x4A, 0x49, 0x49, 0x31, 0x00, 0x00}, {0x00, 0x41, 0x21, 0x11, 0x09, 0x07, 0x00, 0x00}, {0x00, 0x36, 0x49, 0x49, 0x49, 0x36, 0x00, 0x00}, {0x00, 0x46, 0x49, 0x49, 0x29, 0x1E, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x40, 0x34, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x08, 0x14, 0x22, 0x41, 0x00, 0x00}, {0x00, 0x14, 0x14, 0x14, 0x14, 0x14, 0x00, 0x00}, {0x00, 0x00, 0x41, 0x22, 0x14, 0x08, 0x00, 0x00}, {0x00, 0x02, 0x01, 0x59, 0x09, 0x06, 0x00, 0x00}, {0x00, 0x3E, 0x41, 0x5D, 0x59, 0x4E, 0x00, 0x00}, {0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C, 0x00, 0x00}, {0x00, 0x7F, 0x49, 0x49, 0x49, 0x36, 0x00, 0x00}, {0x00, 0x3E, 0x41, 0x41, 0x41, 0x22, 0x00, 0x00}, {0x00, 0x7F, 0x41, 0x41, 0x41, 0x3E, 0x00, 0x00}, {0x00, 0x7F, 0x49, 0x49, 0x49, 0x41, 0x00, 0x00}, {0x00, 0x7F, 0x09, 0x09, 0x09, 0x01, 0x00, 0x00}, {0x00, 0x3E, 0x41, 0x41, 0x51, 0x73, 0x00, 0x00}, {0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00, 0x00}, {0x00, 0x00, 0x41, 0x7F, 0x41, 0x00, 0x00, 0x00}, {0x00, 0x20, 0x40, 0x41, 0x3F, 0x01, 0x00, 0x00}, {0x00, 0x7F, 0x08, 0x14, 0x22, 0x41, 0x00, 0x00}, {0x00, 0x7F, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00}, {0x00, 0x7F, 0x02, 0x1C, 0x02, 0x7F, 0x00, 0x00}, {0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F, 0x00, 0x00}, {0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00, 0x00}, {0x00, 0x7F, 0x09, 0x09, 0x09, 0x06, 0x00, 0x00}, {0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E, 0x00, 0x00}, {0x00, 0x7F, 0x09, 0x19, 0x29, 0x46, 0x00, 0x00}, {0x00, 0x26, 0x49, 0x49, 0x49, 0x32, 0x00, 0x00}, {0x00, 0x03, 0x01, 0x7F, 0x01, 0x03, 0x00, 0x00}, {0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F, 0x00, 0x00}, {0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F, 0x00, 0x00}, {0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F, 0x00, 0x00}, {0x00, 0x63, 0x14, 0x08, 0x14, 0x63, 0x00, 0x00}, {0x00, 0x03, 0x04, 0x78, 0x04, 0x03, 0x00, 0x00}, {0x00, 0x61, 0x59, 0x49, 0x4D, 0x43, 0x00, 0x00}, {0x00, 0x00, 0x7F, 0x41, 0x41, 0x41, 0x00, 0x00}, {0x00, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, 0x00}, {0x00, 0x00, 0x41, 0x41, 0x41, 0x7F, 0x00, 0x00}, {0x00, 0x04, 0x02, 0x01, 0x02, 0x04, 0x00, 0x00}, {0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00}, {0x00, 0x00, 0x03, 0x07, 0x08, 0x00, 0x00, 0x00}, {0x00, 0x20, 0x54, 0x54, 0x78, 0x40, 0x00, 0x00}, {0x00, 0x7F, 0x28, 0x44, 0x44, 0x38, 0x00, 0x00}, {0x00, 0x38, 0x44, 0x44, 0x44, 0x28, 0x00, 0x00}, {0x00, 0x38, 0x44, 0x44, 0x28, 0x7F, 0x00, 0x00}, {0x00, 0x38, 0x54, 0x54, 0x54, 0x18, 0x00, 0x00}, {0x00, 0x00, 0x08, 0x7E, 0x09, 0x02, 0x00, 0x00}, {0x00, 0x18, 0xA4, 0xA4, 0x9C, 0x78, 0x00, 0x00}, {0x00, 0x7F, 0x08, 0x04, 0x04, 0x78, 0x00, 0x00}, {0x00, 0x00, 0x44, 0x7D, 0x40, 0x00, 0x00, 0x00}, {0x00, 0x20, 0x40, 0x40, 0x3D, 0x00, 0x00, 0x00}, {0x00, 0x7F, 0x10, 0x28, 0x44, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x41, 0x7F, 0x40, 0x00, 0x00, 0x00}, {0x00, 0x7C, 0x04, 0x78, 0x04, 0x78, 0x00, 0x00}, {0x00, 0x7C, 0x08, 0x04, 0x04, 0x78, 0x00, 0x00}, {0x00, 0x38, 0x44, 0x44, 0x44, 0x38, 0x00, 0x00}, {0x00, 0xFC, 0x18, 0x24, 0x24, 0x18, 0x00, 0x00}, {0x00, 0x18, 0x24, 0x24, 0x18, 0xFC, 0x00, 0x00}, {0x00, 0x7C, 0x08, 0x04, 0x04, 0x08, 0x00, 0x00}, {0x00, 0x48, 0x54, 0x54, 0x54, 0x24, 0x00, 0x00}, {0x00, 0x04, 0x04, 0x3F, 0x44, 0x24, 0x00, 0x00}, {0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C, 0x00, 0x00}, {0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C, 0x00, 0x00}, {0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C, 0x00, 0x00}, {0x00, 0x44, 0x28, 0x10, 0x28, 0x44, 0x00, 0x00}, {0x00, 0x4C, 0x90, 0x90, 0x90, 0x7C, 0x00, 0x00}, {0x00, 0x44, 0x64, 0x54, 0x4C, 0x44, 0x00, 0x00}, {0x00, 0x00, 0x08, 0x36, 0x41, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x41, 0x36, 0x08, 0x00, 0x00, 0x00}, {0x00, 0x02, 0x01, 0x02, 0x04, 0x02, 0x00, 0x00}, {0x00, 0x3C, 0x26, 0x23, 0x26, 0x3C, 0x00, 0x00}, {0x00, 0x1E, 0xA1, 0xA1, 0x61, 0x12, 0x00, 0x00}, {0x00, 0x3A, 0x40, 0x40, 0x20, 0x7A, 0x00, 0x00}, {0x00, 0x38, 0x54, 0x54, 0x55, 0x59, 0x00, 0x00}, {0x00, 0x21, 0x55, 0x55, 0x79, 0x41, 0x00, 0x00}, {0x00, 0x22, 0x54, 0x54, 0x78, 0x42, 0x00, 0x00}, {0x00, 0x21, 0x55, 0x54, 0x78, 0x40, 0x00, 0x00}, {0x00, 0x20, 0x54, 0x55, 0x79, 0x40, 0x00, 0x00}, {0x00, 0x0C, 0x1E, 0x52, 0x72, 0x12, 0x00, 0x00}, {0x00, 0x39, 0x55, 0x55, 0x55, 0x59, 0x00, 0x00}, {0x00, 0x39, 0x54, 0x54, 0x54, 0x59, 0x00, 0x00}, {0x00, 0x39, 0x55, 0x54, 0x54, 0x58, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x45, 0x7C, 0x41, 0x00, 0x00}, {0x00, 0x00, 0x02, 0x45, 0x7D, 0x42, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x45, 0x7C, 0x40, 0x00, 0x00}, {0x00, 0x7D, 0x12, 0x11, 0x12, 0x7D, 0x00, 0x00}, {0x00, 0xF0, 0x28, 0x25, 0x28, 0xF0, 0x00, 0x00}, {0x00, 0x7C, 0x54, 0x55, 0x45, 0x00, 0x00, 0x00}, {0x00, 0x20, 0x54, 0x54, 0x7C, 0x54, 0x00, 0x00}, {0x00, 0x7C, 0x0A, 0x09, 0x7F, 0x49, 0x00, 0x00}, {0x00, 0x32, 0x49, 0x49, 0x49, 0x32, 0x00, 0x00}, {0x00, 0x3A, 0x44, 0x44, 0x44, 0x3A, 0x00, 0x00}, {0x00, 0x32, 0x4A, 0x48, 0x48, 0x30, 0x00, 0x00}, {0x00, 0x3A, 0x41, 0x41, 0x21, 0x7A, 0x00, 0x00}, {0x00, 0x3A, 0x42, 0x40, 0x20, 0x78, 0x00, 0x00}, {0x00, 0x00, 0x9D, 0xA0, 0xA0, 0x7D, 0x00, 0x00}, {0x00, 0x3D, 0x42, 0x42, 0x42, 0x3D, 0x00, 0x00}, {0x00, 0x3D, 0x40, 0x40, 0x40, 0x3D, 0x00, 0x00}, {0x00, 0x3C, 0x24, 0xFF, 0x24, 0x24, 0x00, 0x00}, {0x00, 0x48, 0x7E, 0x49, 0x43, 0x66, 0x00, 0x00}, {0x00, 0x2B, 0x2F, 0xFC, 0x2F, 0x2B, 0x00, 0x00}, {0x00, 0xFF, 0x09, 0x29, 0xF6, 0x20, 0x00, 0x00}, {0x00, 0xC0, 0x88, 0x7E, 0x09, 0x03, 0x00, 0x00}, {0x00, 0x20, 0x54, 0x54, 0x79, 0x41, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x44, 0x7D, 0x41, 0x00, 0x00}, {0x00, 0x30, 0x48, 0x48, 0x4A, 0x32, 0x00, 0x00}, {0x00, 0x38, 0x40, 0x40, 0x22, 0x7A, 0x00, 0x00}, {0x00, 0x00, 0x7A, 0x0A, 0x0A, 0x72, 0x00, 0x00}, {0x00, 0x7D, 0x0D, 0x19, 0x31, 0x7D, 0x00, 0x00}, {0x00, 0x26, 0x29, 0x29, 0x2F, 0x28, 0x00, 0x00}, {0x00, 0x26, 0x29, 0x29, 0x29, 0x26, 0x00, 0x00}, {0x00, 0x30, 0x48, 0x4D, 0x40, 0x20, 0x00, 0x00}, {0x00, 0x38, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00}, {0x00, 0x08, 0x08, 0x08, 0x08, 0x38, 0x00, 0x00}, {0x00, 0x2F, 0x10, 0xC8, 0xAC, 0xBA, 0x00, 0x00}, {0x00, 0x2F, 0x10, 0x28, 0x34, 0xFA, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x7B, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x08, 0x14, 0x2A, 0x14, 0x22, 0x00, 0x00}, {0x00, 0x22, 0x14, 0x2A, 0x14, 0x08, 0x00, 0x00}, {0x00, 0x55, 0x00, 0x55, 0x00, 0x55, 0x00, 0x00}, {0x00, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x00, 0x00}, {0x00, 0xFF, 0x55, 0xFF, 0x55, 0xFF, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00}, {0x00, 0x10, 0x10, 0x10, 0xFF, 0x00, 0x00, 0x00}, {0x00, 0x14, 0x14, 0x14, 0xFF, 0x00, 0x00, 0x00}, {0x00, 0x10, 0x10, 0xFF, 0x00, 0xFF, 0x00, 0x00}, {0x00, 0x10, 0x10, 0xF0, 0x10, 0xF0, 0x00, 0x00}, {0x00, 0x14, 0x14, 0x14, 0xFC, 0x00, 0x00, 0x00}, {0x00, 0x14, 0x14, 0xF7, 0x00, 0xFF, 0x00, 0x00}, {0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00}, {0x00, 0x14, 0x14, 0xF4, 0x04, 0xFC, 0x00, 0x00}, {0x00, 0x14, 0x14, 0x17, 0x10, 0x1F, 0x00, 0x00}, {0x00, 0x10, 0x10, 0x1F, 0x10, 0x1F, 0x00, 0x00}, {0x00, 0x14, 0x14, 0x14, 0x1F, 0x00, 0x00, 0x00}, {0x00, 0x10, 0x10, 0x10, 0xF0, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x1F, 0x10, 0x00, 0x00}, {0x00, 0x10, 0x10, 0x10, 0x1F, 0x10, 0x00, 0x00}, {0x00, 0x10, 0x10, 0x10, 0xF0, 0x10, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0xFF, 0x10, 0x00, 0x00}, {0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00}, {0x00, 0x10, 0x10, 0x10, 0xFF, 0x10, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0xFF, 0x14, 0x00, 0x00}, {0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x1F, 0x10, 0x17, 0x00, 0x00}, {0x00, 0x00, 0x00, 0xFC, 0x04, 0xF4, 0x00, 0x00}, {0x00, 0x14, 0x14, 0x17, 0x10, 0x17, 0x00, 0x00}, {0x00, 0x14, 0x14, 0xF4, 0x04, 0xF4, 0x00, 0x00}, {0x00, 0x00, 0x00, 0xFF, 0x00, 0xF7, 0x00, 0x00}, {0x00, 0x14, 0x14, 0x14, 0x14, 0x14, 0x00, 0x00}, {0x00, 0x14, 0x14, 0xF7, 0x00, 0xF7, 0x00, 0x00}, {0x00, 0x14, 0x14, 0x14, 0x17, 0x14, 0x00, 0x00}, {0x00, 0x10, 0x10, 0x1F, 0x10, 0x1F, 0x00, 0x00}, {0x00, 0x14, 0x14, 0x14, 0xF4, 0x14, 0x00, 0x00}, {0x00, 0x10, 0x10, 0xF0, 0x10, 0xF0, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x1F, 0x10, 0x1F, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x1F, 0x14, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0xFC, 0x14, 0x00, 0x00}, {0x00, 0x00, 0x00, 0xF0, 0x10, 0xF0, 0x00, 0x00}, {0x00, 0x10, 0x10, 0xFF, 0x10, 0xFF, 0x00, 0x00}, {0x00, 0x14, 0x14, 0x14, 0xFF, 0x14, 0x00, 0x00}, {0x00, 0x10, 0x10, 0x10, 0x1F, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0xF0, 0x10, 0x00, 0x00}, {0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00}, {0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00}, {0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00}, {0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00}, {0x00, 0x38, 0x44, 0x44, 0x38, 0x44, 0x00, 0x00}, {0x00, 0xFC, 0x4A, 0x4A, 0x4A, 0x34, 0x00, 0x00}, {0x00, 0x7E, 0x02, 0x02, 0x06, 0x06, 0x00, 0x00}, {0x00, 0x02, 0x7E, 0x02, 0x7E, 0x02, 0x00, 0x00}, {0x00, 0x63, 0x55, 0x49, 0x41, 0x63, 0x00, 0x00}, {0x00, 0x38, 0x44, 0x44, 0x3C, 0x04, 0x00, 0x00}, {0x00, 0x40, 0x7E, 0x20, 0x1E, 0x20, 0x00, 0x00}, {0x00, 0x06, 0x02, 0x7E, 0x02, 0x02, 0x00, 0x00}, {0x00, 0x99, 0xA5, 0xE7, 0xA5, 0x99, 0x00, 0x00}, {0x00, 0x1C, 0x2A, 0x49, 0x2A, 0x1C, 0x00, 0x00}, {0x00, 0x4C, 0x72, 0x01, 0x72, 0x4C, 0x00, 0x00}, {0x00, 0x30, 0x4A, 0x4D, 0x4D, 0x30, 0x00, 0x00}, {0x00, 0x30, 0x48, 0x78, 0x48, 0x30, 0x00, 0x00}, {0x00, 0xBC, 0x62, 0x5A, 0x46, 0x3D, 0x00, 0x00}, {0x00, 0x3E, 0x49, 0x49, 0x49, 0x00, 0x00, 0x00}, {0x00, 0x7E, 0x01, 0x01, 0x01, 0x7E, 0x00, 0x00}, {0x00, 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 0x00, 0x00}, {0x00, 0x44, 0x44, 0x5F, 0x44, 0x44, 0x00, 0x00}, {0x00, 0x40, 0x51, 0x4A, 0x44, 0x40, 0x00, 0x00}, {0x00, 0x40, 0x44, 0x4A, 0x51, 0x40, 0x00, 0x00}, {0x00, 0x00, 0x00, 0xFF, 0x01, 0x03, 0x00, 0x00}, {0x00, 0xE0, 0x80, 0xFF, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x08, 0x08, 0x6B, 0x6B, 0x08, 0x00, 0x00}, {0x00, 0x36, 0x12, 0x36, 0x24, 0x36, 0x00, 0x00}, {0x00, 0x06, 0x0F, 0x09, 0x0F, 0x06, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00}, {0x00, 0x30, 0x40, 0xFF, 0x01, 0x01, 0x00, 0x00}, {0x00, 0x00, 0x1F, 0x01, 0x01, 0x1E, 0x00, 0x00}, {0x00, 0x00, 0x19, 0x1D, 0x17, 0x12, 0x00, 0x00}, {0x00, 0x00, 0x3C, 0x3C, 0x3C, 0x3C, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }; void static lcd_write_control(const unsigned char &data) { GP0CLR_CLR4_BBA = true; pADI_SPI1->SPITX = data; while ((pADI_SPI1->SPISTA & SPI1STA_TXFSTA_MSK) != SPI1STA_TXFSTA_EMPTY) ; } void static lcd_write_image(const unsigned char data) { GP0SET_SET4_BBA = true; pADI_SPI1->SPITX = data; while ((pADI_SPI1->SPISTA & SPI1STA_TXFSTA_MSK) != SPI1STA_TXFSTA_EMPTY) ; } int send_spi_image(int argc, char *argv[]) { unsigned char page = 0xB0; // lcd_write_control(0xAE); // Display OFF lcd_write_control(0x40); // Display start address + 0x40 for (unsigned int i = 0; i < 4; i++) { // 32pixel display / 8 pixels per page = 4 pages lcd_write_control(page); // send page address lcd_write_control(0x10); // column address upper 4 bits + 0x10 lcd_write_control(0x00); // column address lower 4 bits + 0x00 for (unsigned int j = 0; j < 128; j++) { // 128 columns wide // todo lcd_write_image(framebuffer_memory[i][j]); // send picture data } page++; // after 128 columns, go to next page } // lcd_write_control(0xAF); // Display on return 0; } void static lcd_framebuffer_flush(void) { timer t; t.time = FB_FLUSH_DELAY; t.timer_app.fun = send_spi_image; t.timer_app.argc = 0; t.timer_app.argv = new char*; update_timer(t); } /* * lcd tty buffer size 128 * address 0~63 for character display * address 64~127 for reverse and blink control * * character register address map to LCD position * 8 x 16 pixel for each position * ┌───┬───┬──────┬───┬───┐ * │ 0 │ 1 │......│14 │15 │ * ├───┼───┼──────┼───┼───┤ * │16 │17 │......│30 │31 │ * ├───┼───┼──────┼───┼───┤ * │32 │33 │......│46 │47 │ * ├───┼───┼──────┼───┼───┤ * │48 │49 │......│62 │63 │ * └───┴───┴──────┴───┴───┘ * * reverse and blink register address map to LCD position * 8 x 16 pixel for each position * ┌───┬───┬──────┬───┬───┐ * │64 │65 │......│78 │79 │ * ├───┼───┼──────┼───┼───┤ * │80 │81 │......│94 │95 │ * ├───┼───┼──────┼───┼───┤ * │96 │97 │......│110│111│ * ├───┼───┼──────┼───┼───┤ * │112│113│......│126│127│ * └───┴───┴──────┴───┴───┘ * * reverse and blink register bit definition * B: 1 blink, 0 gaze * R: 1 reverse, 0 normal * others: null * ┌─┬─┬─┬─┬─┬─┬─┬─┐ * │7│6│5│4│3│2│B│R│ * └─┴─┴─┴─┴─┴─┴─┴─┘ */ ssize_t lcd_tty_write(const void *buf, size_t count) { if ((tty_cursor + count) > sizeof(lcd_tty_buffer)) { count = sizeof(lcd_tty_buffer) - tty_cursor; } memcpy(&lcd_tty_buffer[tty_cursor], buf, count); for (int j = 0; j < count; ++j) { int cursor = (tty_cursor + j) % 64; int y = cursor >> 4; // page int x = (cursor & 0xf) << 3; // segment for (int i = 0; i < 8; i++) framebuffer_memory[y][x+i] = ASC16[lcd_tty_buffer[cursor]][i]; } lcd_framebuffer_flush(); tty_cursor += count; return count; } int static lcd_blinking(int argc, char *argv[]) { blink_on = !blink_on; for (int cursor = 0; cursor < 64; ++cursor) { int y = cursor >> 4; // page int x = (cursor & 0xf) << 3; // segment if ((((lcd_tty_buffer[cursor + 64] & LCD_BLINK) == LCD_BLINK) && blink_on) || (((lcd_tty_buffer[cursor + 64] & LCD_REVERSE) == LCD_REVERSE))) { for (int i = 0; i < 8; i++) framebuffer_memory[y][x+i] = ~ASC16[lcd_tty_buffer[cursor]][i]; } else { for (int i = 0; i < 8; i++) framebuffer_memory[y][x+i] = ASC16[lcd_tty_buffer[cursor]][i]; } } lcd_framebuffer_flush(); timer t; t.time = LCD_BLINK_INTERVAL / 2; t.timer_app.fun = lcd_blinking; t.timer_app.argc = 0; t.timer_app.argv = new char*; update_timer(t); return 0; } off_t lcd_tty_lseek(off_t offset, int whence) { switch (whence) { case SEEK_SET: if (offset > sizeof(lcd_tty_buffer) || offset < 0) { errno = EINVAL; return -1; } tty_cursor = offset; break; case SEEK_CUR: if ((tty_cursor + offset) > sizeof(lcd_tty_buffer) || (tty_cursor + offset) < 0) { errno = EINVAL; return -1; } tty_cursor += offset; break; case SEEK_END: if (offset > 0 || (sizeof(lcd_tty_buffer) + offset) < 0) { errno = EINVAL; return -1; } tty_cursor = sizeof(lcd_tty_buffer) + offset; break; default: errno = ENXIO; return -1; } return tty_cursor; } void init_lcd(void) { flash_file * p_flash_file; decltype(flash_file::brightness) brightness; lcd_write_control(0xA0); // ADC select lcd_write_control(0xAE); // Display OFF lcd_write_control(0xC8); // COM direction scan lcd_write_control(0xA2); // LCD bias set lcd_write_control(0x2F); // Power Control set lcd_write_control(0x21); // Resistor Ratio Set fseek(p_flash, (int) (&p_flash_file->brightness) - (int) (p_flash_file), SEEK_SET); fread(&brightness, sizeof(flash_file::brightness), 1, p_flash); lcd_write_control( 0x81); // Electronic Volume Command (set contrast) Double Btye: 1 of 2 lcd_write_control( brightness & 0xFF); // Electronic Volume value (contrast value) Double Byte: 2 of 2 lcd_write_control(0xAF); // Display ON } void clear_lcd(void) { unsigned char page = 0xB0; // lcd_write_control(0xAE); // Display OFF lcd_write_control(0x40); // Display start address + 0x40 for (unsigned int i = 0; i < 4; i++) { // 32pixel display / 8 pixels per page = 4 pages lcd_write_control(page); // send page address // Sets the most significant 4 bits of the display RAM column address. lcd_write_control(0x10); // column address upper 4 bits + 0x10 // Sets the least significant 4 bits of the display RAM column address. lcd_write_control(0x00); // column address lower 4 bits + 0x00 for (unsigned int j = 0; j < 128; j++) { // 128 columns wide lcd_write_image(0x00); // send picture data } page++; // after 128 columns, go to next page } lcd_write_control(0xAF); // Display on } void lcd_open(void) { CLKDIS_DISSPI1CLK_BBA = false; pADI_CLKCTL->CLKCON1 = (pADI_CLKCTL->CLKCON1 & ~CLKCON1_SPI1CD_MSK) | CLKCON1_SPI1CD_DIV1; // according schematic pADI_GP0->GPCON = (pADI_GP0->GPCON & ~GP0CON_CON1_MSK) | GP0CON_CON1_SPI1SCLK; pADI_GP0->GPCON = (pADI_GP0->GPCON & ~GP0CON_CON2_MSK) | GP0CON_CON2_SPI1MOSI; pADI_GP0->GPCON = (pADI_GP0->GPCON & ~GP0CON_CON3_MSK) | GP0CON_CON3_SPI1CS0; pADI_GP0->GPCON = (pADI_GP0->GPCON & ~GP0CON_CON4_MSK) | GP0CON_CON4_GPIO; GP0OCE_OCE1_BBA = false; GP0OCE_OCE2_BBA = false; GP0OCE_OCE3_BBA = false; GP0OCE_OCE4_BBA = false; GP0OEN_OEN1_BBA = true; GP0OEN_OEN2_BBA = true; GP0OEN_OEN3_BBA = true; GP0OEN_OEN4_BBA = true; GP0PUL_PUL1_BBA = true; GP0PUL_PUL2_BBA = true; GP0PUL_PUL3_BBA = true; GP0PUL_PUL4_BBA = true; pADI_SPI1->SPIDIV = SPI1DIV_BCRST_DIS | (SPI1DIV_DIV_MSK & 0x0); pADI_SPI1->SPICON = SPI1CON_MOD_TX4RX4 | SPI1CON_TFLUSH_DIS | SPI1CON_RFLUSH_EN | SPI1CON_CON_EN | SPI1CON_LOOPBACK_DIS | SPI1CON_SOEN_DIS | SPI1CON_RXOF_EN | SPI1CON_ZEN_DIS | SPI1CON_TIM_TXWR | SPI1CON_LSB_DIS | SPI1CON_WOM_DIS | SPI1CON_CPOL_HIGH | SPI1CON_CPHA_SAMPLETRAILING | SPI1CON_MASEN_EN | SPI1CON_ENABLE_EN; init_lcd(); clear_lcd(); lcd_tty_lseek(0, SEEK_SET); lcd_blinking(0, nullptr); } #endif // EVAL_BUILD