DeepCover Embedded Security in IoT: Public-key Secured Data Paths
Dependencies: MaximInterface
Display.cpp
00001 /******************************************************************************* 00002 * Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved. 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a 00005 * copy of this software and associated documentation files (the "Software"), 00006 * to deal in the Software without restriction, including without limitation 00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00008 * and/or sell copies of the Software, and to permit persons to whom the 00009 * Software is furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included 00012 * in all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00017 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES 00018 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00019 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00020 * OTHER DEALINGS IN THE SOFTWARE. 00021 * 00022 * Except as contained in this notice, the name of Maxim Integrated 00023 * Products, Inc. shall not be used except as stated in the Maxim Integrated 00024 * Products, Inc. Branding Policy. 00025 * 00026 * The mere transfer of this software does not imply any licenses 00027 * of trade secrets, proprietary technology, copyrights, patents, 00028 * trademarks, maskwork rights, or any other form of intellectual 00029 * property whatsoever. Maxim Integrated Products, Inc. retains all 00030 * ownership rights. 00031 *******************************************************************************/ 00032 00033 #include "Display.hpp" 00034 00035 /// @{ 00036 /// Width and height of the display in pixels. 00037 static const int width = 128; 00038 static const int height = 64; 00039 /// @} 00040 00041 Display::Display(PinName mosi, PinName miso, PinName sclk, PinName ssel, 00042 PinName a0) 00043 : canvas_(width, height), spi(mosi, miso, sclk), cs(ssel, 1), a0(a0, 0) { 00044 spi.format(8, 3); // CPOL = 1, CPHA = 1 00045 } 00046 00047 void Display::initialize() { 00048 sendCommand(0xA0); 00049 sendCommand(0xAE); 00050 sendCommand(0xC0); 00051 sendCommand(0xA2); 00052 sendCommand(0x2F); 00053 sendCommand(0x26); 00054 sendCommand(0x81); 00055 sendCommand(0x11); 00056 sendCommand(0xAF); 00057 } 00058 00059 void Display::update() { 00060 const int rowsPerPage = 8; 00061 const int pages = height / rowsPerPage; 00062 sendCommand(0xAE); 00063 sendCommand(0x40); 00064 for (int page = 0; page < pages; ++page) { 00065 sendCommand(0xB0 + page); 00066 sendCommand(0x10); 00067 sendCommand(0x00); 00068 for (int column = 0; column < width; ++column) { 00069 uint8_t segment = 0; 00070 for (int pixel = 0; pixel < rowsPerPage; ++pixel) { 00071 segment <<= 1; 00072 if (canvas_.pixelEnabled(column, 00073 ((pages - 1 - page) * rowsPerPage) + pixel)) { 00074 segment |= 1; 00075 } 00076 } 00077 sendData(segment); 00078 } 00079 } 00080 sendCommand(0xAF); 00081 } 00082 00083 void Display::sendCommand(uint8_t command) { 00084 cs = 0; 00085 a0 = 0; 00086 spi.write(command); 00087 cs = 1; 00088 } 00089 00090 void Display::sendData(uint8_t data) { 00091 cs = 0; 00092 a0 = 1; 00093 spi.write(data); 00094 cs = 1; 00095 }
Generated on Tue Jul 12 2022 12:06:48 by 1.7.2