MAXREFDES143#: DeepCover Embedded Security in IoT Authenticated Sensing & Notification
Dependencies: MaximInterface mbed
The MAXREFDES143# is an Internet of Things (IoT) embedded security reference design, built to protect an industrial sensing node by means of authentication and notification to a web server. The hardware includes a peripheral module representing a protected sensor node monitoring operating temperature and remaining life of a filter (simulated through ambient light sensing) and an mbed shield representing a controller node responsible for monitoring one or more sensor nodes. The design is hierarchical with each controller node communicating data from connected sensor nodes to a web server that maintains a centralized log and dispatches notifications as necessary. The mbed shield contains a Wi-Fi module, a DS2465 coprocessor with 1-Wire® master function, an LCD, LEDs, and pushbuttons. The protected sensor node contains a DS28E15 authenticator, a DS7505 temperature sensor, and a MAX44009 light sensor. The mbed shield communicates to a web server by the onboard Wi-Fi module and to the protected sensor node with I2C and 1-Wire. The MAXREFDES143# is equipped with a standard shield connector for immediate testing using an mbed board such as the MAX32600MBED#. The simplicity of this design enables rapid integration into any star-topology IoT network requiring the heightened security with low overhead provided by the SHA-256 symmetric-key algorithm.
More information about the MAXREFDES143# is available on the Maxim Integrated website.
Diff: Display.cpp
- Revision:
- 32:0a09505a656d
- Parent:
- 17:41be4896ed6d
diff -r 7b10bcb3e0fc -r 0a09505a656d Display.cpp
--- a/Display.cpp Tue Apr 04 14:10:48 2017 -0500
+++ b/Display.cpp Mon Nov 06 17:34:13 2017 -0600
@@ -28,63 +28,66 @@
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
-*******************************************************************************
-*/
+*******************************************************************************/
#include <sstream>
+#include <I2C.h>
+#include <wait_api.h>
#include "Display.hpp"
-#include "I2C.h"
-#include "wait_api.h"
-//LCD Commands
-//If the RS bit is set to logic 1, these display bytes are stored in the display RAM at the address specified by the data pointer. The data pointer is
-//automatically updated and the data is directed to the intended ST7036i device. If the RS bit of the last control byte is set to
-//logic 0, these command bytes will be decoded and the setting of the device will be changed according to the received commands.
-enum LCD_Commands
-{
- ControlByte = 0x00, //Only one control byte will be sent. Only a stream of data bytes is allowed to follow.
- ControlByte_RS_Set = 0x40, //Only one control byte will be sent with the RS bit set. Only a stream of data bytes is allowed to follow.
- ControlBytes = 0x80, //Another control byte will follow, unless an I2C Stop condition is received.
- ControlBytes_RS_Set = 0xC0, //RS Set and another control byte will follow, unless an I2C Stop condition is received.
+// LCD Commands
+// If the RS bit is set to logic 1, these display bytes are stored in the
+// display RAM at the address specified by the data pointer. The data pointer is
+// automatically updated and the data is directed to the intended ST7036i
+// device. If the RS bit of the last control byte is set to logic 0, these
+// command bytes will be decoded and the setting of the device will be changed
+// according to the received commands.
+enum LCD_Commands {
+ // Only one control byte will be sent.
+ // Only a stream of data bytes is allowed to follow.
+ ControlByte = 0x00,
+ // Only one control byte will be sent with the RS bit set.
+ // Only a stream of data bytes is allowed to follow.
+ ControlByte_RS_Set = 0x40,
+ // Another control byte will follow, unless an I2C Stop condition is received.
+ ControlBytes = 0x80,
+ // RS Set and another control byte will follow, unless an I2C Stop condition
+ // is received.
+ ControlBytes_RS_Set =0xC0
};
-//LCD Instructions
-enum LCD_Instructions
-{
+// LCD Instructions
+enum LCD_Instructions {
ClearDisplay = 0x01,
- Display_OFF = 0x08, //Display off
- Display_ON = 0x0C, //Display on, cursor off, cursor position off
+ Display_OFF = 0x08, // Display off
+ Display_ON = 0x0C, // Display on, cursor off, cursor position off
ReturnHome = 0x02,
SetDdramAddress = 0x80
};
// LED Driver Port Registers
// Initial port state 0x80
-enum LED_Driver_Ports
-{
+enum LED_Driver_Ports {
P1 = 0x01,
- P2 = 0x02, // Blue LED
- P3 = 0x03, // Green LED
- P4 = 0x04 // Red LED
+ P2 = 0x02, // Blue LED
+ P3 = 0x03, // Green LED
+ P4 = 0x04 // Red LED
};
// Convert a byte color value into the representation used by the MAX7306 PWM registers
-static uint8_t convertColorToPwmRegVal(uint8_t color)
-{
+static uint8_t convertColorToPwmRegVal(uint8_t color) {
const uint8_t staticOffRegVal = 0x80; // LED is static off by setting to input
- const uint8_t staticOnRegVal = 0x00; // LED is static on
- const uint8_t minOnRegVal = 0x01; // LED on for minimum duty cycle
-
+ const uint8_t staticOnRegVal = 0x00; // LED is static on
+ const uint8_t minOnRegVal = 0x01; // LED on for minimum duty cycle
+
uint8_t regVal;
if (color == 0x00) // Use static off for no color
{
regVal = staticOffRegVal;
- }
- else if (color == 0xFF) // Use static on for full color
+ } else if (color == 0xFF) // Use static on for full color
{
regVal = staticOnRegVal;
- }
- else // Use standard PWN for all other values
+ } else // Use standard PWN for all other values
{
// The 3 least significant bits cannot be rendered with the MAX7306
regVal = color >> 3;
@@ -94,176 +97,164 @@
return regVal;
}
-Display::Display(mbed::I2C & I2C_intf, uint8_t LCD_I2C_addr, uint8_t LED_driver_I2C_addr)
- : m_I2C_intf(I2C_intf), m_LCD_I2C_addr(LCD_I2C_addr), m_LED_driver_I2C_addr(LED_driver_I2C_addr)
-{
-
-}
+Display::Display(mbed::I2C & I2C_intf, uint8_t LCD_I2C_addr,
+ uint8_t LED_driver_I2C_addr)
+ : m_I2C_intf(I2C_intf), m_LCD_I2C_addr(LCD_I2C_addr),
+ m_LED_driver_I2C_addr(LED_driver_I2C_addr) {}
-void Display::initialize(void)
-{
+void Display::initialize() {
initializeLCD();
initializeLED_Driver();
}
-void Display::initializeLED_Driver(void)
-{
- const uint8_t Configuration26 = 0x26; //intial port state 0xEC
- const uint8_t Configuration27 = 0x27; //intial port state 0x8F
-
- //Intial mode
- //write to Configuration Register 0x26
+void Display::initializeLED_Driver() {
+ const uint8_t Configuration26 = 0x26; // Intial port state 0xEC
+ const uint8_t Configuration27 = 0x27; // Intial port state 0x8F
+
+ // Intial mode
+ // Write to Configuration Register 0x26
m_I2C_intf.start();
m_I2C_intf.write(m_LED_driver_I2C_addr);
m_I2C_intf.write(Configuration26);
- //RST does reset PWM/blink counters, RST resets registers to power-on-reset state
- m_I2C_intf.write(0x1F);
+ // RST resets registers to power-on-reset state
+ // RST does reset PWM/blink counters,
+ m_I2C_intf.write(0x1F);
m_I2C_intf.stop();
-
- //Write to Configuration Register 0x27
+
+ // Write to Configuration Register 0x27
m_I2C_intf.start();
m_I2C_intf.write(m_LED_driver_I2C_addr);
m_I2C_intf.write(Configuration27);
- //Enable bus time out, set P1,P2,P3 to be controlled by their registers (0x01,0x02,0x03)
- m_I2C_intf.write(0x0E);
+ // Enable bus time out, and set P1, P2, P3 to be controlled by their registers
+ // (0x01, 0x02, 0x03)
+ m_I2C_intf.write(0x0E);
m_I2C_intf.stop();
}
-void Display::setBackLightColor(const Color & color)
-{
+void Display::setBackLightColor(const Color & color) {
// Red
m_I2C_intf.start();
m_I2C_intf.write(m_LED_driver_I2C_addr);
m_I2C_intf.write(P4);
- m_I2C_intf.write(convertColorToPwmRegVal(color.R));
+ m_I2C_intf.write(convertColorToPwmRegVal(color.R));
m_I2C_intf.stop();
-
+
// Green
m_I2C_intf.start();
m_I2C_intf.write(m_LED_driver_I2C_addr);
m_I2C_intf.write(P3);
- m_I2C_intf.write(convertColorToPwmRegVal(color.G));
+ m_I2C_intf.write(convertColorToPwmRegVal(color.G));
m_I2C_intf.stop();
-
+
// Blue
m_I2C_intf.start();
m_I2C_intf.write(m_LED_driver_I2C_addr);
m_I2C_intf.write(P2);
- m_I2C_intf.write(convertColorToPwmRegVal(color.B));
+ m_I2C_intf.write(convertColorToPwmRegVal(color.B));
m_I2C_intf.stop();
}
-void Display::clearLine(Line line)
-{
+void Display::clearLine(Line line) {
writeCompleteLine("", line);
setCursorPosition(line);
}
-void Display::clearDisplay(void)
-{
+void Display::clearDisplay() {
m_I2C_intf.start();
m_I2C_intf.write(m_LCD_I2C_addr);
- m_I2C_intf.write(ControlByte); //No more control bytes will be sent
+ m_I2C_intf.write(ControlByte); //No more control bytes will be sent
m_I2C_intf.write(ClearDisplay);
m_I2C_intf.stop();
}
-void Display::initializeLCD(void)
-{
+void Display::initializeLCD() {
m_I2C_intf.start();
m_I2C_intf.write(m_LCD_I2C_addr);
- m_I2C_intf.write(ControlByte); //No more control bytes will be sent
- m_I2C_intf.write(0x38); //Function Set IS[2:1] = 0,0 (&h38 = Single height font, 0x3C = double height font)
- m_I2C_intf.write(0x39); //Function Set IS[2:1] = (0,1)
- //When IS[2:1]=(0,0): normal instruction be selected(refer instruction table 0)
- //When IS[2:1]=(0,1): extension instruction be selected(refer instruction table 1 )
- //When IS[2:1]=(1,0): extension instruction be selected(refer instruction table 2 )
- m_I2C_intf.write(0x14); //BIAS SET
- m_I2C_intf.write(0x70); //CONTRAST (was 0x78)
- m_I2C_intf.write(0x5E); //POWER/ICON CONTROL/CONTRAST (upper two bits)
- m_I2C_intf.write(0x6D); //FOLLOWER CONTROL
+ m_I2C_intf.write(ControlByte); // No more control bytes will be sent
+ // Function Set IS[2:1] = 0,0 (&h38 = Single height font, 0x3C = double height font)
+ m_I2C_intf.write(0x38);
+ m_I2C_intf.write(0x39); //Function Set IS[2:1] = (0,1)
+ // When IS[2:1]=(0,0): normal instruction be selected(refer instruction table 0)
+ // When IS[2:1]=(0,1): extension instruction be selected(refer instruction table 1)
+ // When IS[2:1]=(1,0): extension instruction be selected(refer instruction table 2)
+ m_I2C_intf.write(0x14); // BIAS SET
+ m_I2C_intf.write(0x70); // CONTRAST (was 0x78)
+ m_I2C_intf.write(0x5E); // POWER/ICON CONTROL/CONTRAST (upper two bits)
+ m_I2C_intf.write(0x6D); // FOLLOWER CONTROL
m_I2C_intf.stop();
- wait_ms(200); //Wait for power stable
+ wait_ms(200); // Wait for power stable
m_I2C_intf.start();
m_I2C_intf.write(m_LCD_I2C_addr);
- m_I2C_intf.write(ControlByte); //No more control bytes will be sent
- m_I2C_intf.write(Display_ON); //Display on, cursor on, cursor position on
- m_I2C_intf.write(ClearDisplay); //Clear Display
- m_I2C_intf.write(0x06); //ENTRY MODE
+ m_I2C_intf.write(ControlByte); // No more control bytes will be sent
+ m_I2C_intf.write(Display_ON); // Display on, cursor on, cursor position on
+ m_I2C_intf.write(ClearDisplay); // Clear Display
+ m_I2C_intf.write(0x06); // ENTRY MODE
m_I2C_intf.stop();
}
-void Display::writeCharacter(uint8_t character)
-{
+void Display::writeCharacter(uint8_t character) {
m_I2C_intf.start();
m_I2C_intf.write(m_LCD_I2C_addr);
- m_I2C_intf.write(ControlByte_RS_Set); //No more control bytes will be sent
- m_I2C_intf.write(character); //Display on, cursor on, cursor position on
- m_I2C_intf.stop();
+ m_I2C_intf.write(ControlByte_RS_Set); // No more control bytes will be sent
+ m_I2C_intf.write(character); // Display on, cursor on, cursor position on
+ m_I2C_intf.stop();
}
-void Display::writeText(const std::string & text)
-{
+void Display::writeText(const std::string & text) {
const char RETURN_CHAR = 0x16;
-
+
size_t length = text.length();
if (length > lineLength)
length = lineLength;
-
+
//Write to LCD
m_I2C_intf.start();
m_I2C_intf.write(m_LCD_I2C_addr);
m_I2C_intf.write(ControlByte_RS_Set);
-
- for(size_t i = 0; i < length; i++)
- {
- if(text[i] != RETURN_CHAR)
+
+ for (size_t i = 0; i < length; i++) {
+ if (text[i] != RETURN_CHAR)
m_I2C_intf.write(text[i]);
}
-
+
m_I2C_intf.stop();
}
-void Display::setCursorPosition(Line line, size_t position)
-{
- if (position > (lineLength - 1)) // Set to last line character for values outside the upper bound
+void Display::setCursorPosition(Line line, size_t position) {
+ // Set to last line character for values outside the upper bound
+ if (position > (lineLength - 1))
position = (lineLength - 1);
m_I2C_intf.start();
m_I2C_intf.write(m_LCD_I2C_addr);
m_I2C_intf.write(ControlByte); // No more control bytes will be sent
- if(line == SecondLine) // Offset for second line
+ if (line == SecondLine) // Offset for second line
position += 0x40;
m_I2C_intf.write(SetDdramAddress | position);
m_I2C_intf.stop();
}
-void Display::writeLine(const std::string & text, Line line)
-{
+void Display::writeLine(const std::string & text, Line line) {
setCursorPosition(line);
writeText(text);
}
-void Display::writeCompleteLine(const std::string & text, Line line)
-{
+void Display::writeCompleteLine(const std::string & text, Line line) {
// Add padding to user's string
std::string writeText(text);
if (writeText.length() < lineLength)
writeText.append(lineLength - writeText.length(), ' ');
-
+
writeLine(writeText, line);
}
-void Display::writeMessage(const std::string & message)
-{
- if (message.length() > lineLength)
- {
+void Display::writeMessage(const std::string & message) {
+ if (message.length() > lineLength) {
// Find split point
std::istringstream messageStream(message);
std::string word;
size_t splitIndex = 0;
- do
- {
+ do {
if (word.length() > 0)
splitIndex += (word.length() + 1);
std::getline(messageStream, word, ' ');
@@ -272,15 +263,11 @@
{
writeCompleteLine(message.substr(0, lineLength), FirstLine);
writeCompleteLine(message.substr(lineLength), SecondLine);
- }
- else
- {
+ } else {
writeCompleteLine(message.substr(0, splitIndex - 1), FirstLine);
writeCompleteLine(message.substr(splitIndex), SecondLine);
}
- }
- else
- {
+ } else {
writeCompleteLine(message, FirstLine);
writeCompleteLine("", SecondLine);
}
MAXREFDES143#: DeepCover Embedded Security in IoT Authenticated Sensing & Notification