DeepCover Embedded Security in IoT: Public-key Secured Data Paths
Dependencies: MaximInterface
main.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 <string> 00034 #include <MaximInterfaceDevices/DS28C36_DS2476.hpp> 00035 #include <MaximInterfaceMbed/I2CMaster.hpp> 00036 #include <MaximInterfaceMbed/Sleep.hpp> 00037 #include <mbed-os/drivers/DigitalIn.h> 00038 #include <mbed-os/drivers/I2C.h> 00039 #include "CC3100.hpp" 00040 #include "Display.hpp" 00041 #include "InitWindow.hpp" 00042 #include "Keys.hpp" 00043 #include "SensorNode.hpp" 00044 #include "WindowManager.hpp" 00045 00046 static mbed::DigitalIn upButton(MBED_CONF_APP_UP_BUTTON_PIN); 00047 static mbed::DigitalIn downButton(MBED_CONF_APP_DOWN_BUTTON_PIN); 00048 static mbed::DigitalIn leftButton(MBED_CONF_APP_LEFT_BUTTON_PIN); 00049 static mbed::DigitalIn rightButton(MBED_CONF_APP_RIGHT_BUTTON_PIN); 00050 static mbed::DigitalIn leftClickButton(MBED_CONF_APP_LEFT_CLICK_BUTTON_PIN); 00051 static mbed::DigitalIn rightClickButton(MBED_CONF_APP_RIGHT_CLICK_BUTTON_PIN); 00052 00053 static Display display(MBED_CONF_APP_DISPLAY_MOSI_PIN, 00054 MBED_CONF_APP_DISPLAY_MISO_PIN, 00055 MBED_CONF_APP_DISPLAY_SCLK_PIN, 00056 MBED_CONF_APP_DISPLAY_SSEL_PIN, 00057 MBED_CONF_APP_DISPLAY_A0_PIN); 00058 static WindowManager windowManager(display.canvas()); 00059 00060 static mbed::I2C mbedI2C(MBED_CONF_APP_SDA_PIN, MBED_CONF_APP_SCL_PIN); 00061 static MaximInterfaceMbed::I2CMaster i2c(mbedI2C); 00062 static MaximInterfaceMbed::Sleep sleep; 00063 MaximInterfaceDevices::DS2476 coproc(sleep, i2c); 00064 SensorNode sensorNode(sleep, i2c, coproc); 00065 00066 std::string webId; 00067 00068 static bool buttonPressed(mbed::DigitalIn & button); 00069 00070 int main() { 00071 mbedI2C.frequency(100000); 00072 display.initialize(); 00073 // Set initial window. 00074 { 00075 std::auto_ptr<Window> window(new InitWindow(InitWindow::InitMode)); 00076 windowManager.push(window); 00077 } 00078 while (true) { 00079 // Update window manager and redraw screen if necessary. 00080 if (windowManager.update()) { 00081 display.update(); 00082 } 00083 // Update CC3100 Wi-Fi interface. 00084 CC3100::instance().update(); 00085 // Check if any buttons are pressed. 00086 if (buttonPressed(leftClickButton)) { 00087 windowManager.processKey(LeftClickKey); 00088 } else if (buttonPressed(rightClickButton)) { 00089 windowManager.processKey(RightClickKey); 00090 } else if (buttonPressed(upButton)) { 00091 windowManager.processKey(UpKey); 00092 } else if (buttonPressed(downButton)) { 00093 windowManager.processKey(DownKey); 00094 } else if (buttonPressed(leftButton)) { 00095 windowManager.processKey(LeftKey); 00096 } else if (buttonPressed(rightButton)) { 00097 windowManager.processKey(RightKey); 00098 } 00099 } 00100 } 00101 00102 /// @brief Checks if button is pressed and waits for release. 00103 /// @param button Active low button to check. 00104 /// @returns True if pressed. 00105 static bool buttonPressed(mbed::DigitalIn & button) { 00106 const int buttonPressed = 0; // Active low 00107 if (button == buttonPressed) { 00108 while (button == buttonPressed) 00109 ; 00110 return true; 00111 } 00112 // else 00113 return false; 00114 }
Generated on Tue Jul 12 2022 12:06:48 by 1.7.2