Skip to content

Instantly share code, notes, and snippets.

@snobu
Created April 28, 2019 16:58
Show Gist options
  • Save snobu/e80f70fb2aa8951d725ef8c1d97a1002 to your computer and use it in GitHub Desktop.
Save snobu/e80f70fb2aa8951d725ef8c1d97a1002 to your computer and use it in GitHub Desktop.
MT3620 with SSD1306 OLED via i2c
{
"SchemaVersion": 1,
"Name" : "SeeedOLED_I2C",
"ComponentId" : "4595840c-94e8-48ea-9bd2-1b8167015973",
"EntryPoint": "/bin/app",
"CmdArgs": [],
"Capabilities": {
"AllowedConnections": [],
"AllowedTcpServerPorts": [],
"AllowedUdpServerPorts": [],
"Gpio": [],
"Uart": [],
"I2cMaster": ["ISU1"],
"SpiMaster": [],
"WifiConfig": false,
"NetworkConfig": false,
"SystemTime": false
}
}
#include <errno.h>
#include <signal.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
// applibs_versions.h defines the API struct versions to use for applibs APIs.
#include "applibs_versions.h"
#include <applibs/log.h>
#include <applibs/i2c.h>
#include "mt3620_rdb.h"
#include "seeedoled.h"
// Termination state
static volatile sig_atomic_t terminationRequired = false;
static const unsigned char SeeedLogo128x128[] =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1B, 0x00, 0x05, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1A, 0x00, 0x05, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x04, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x00, 0x06, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x00, 0x06, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x02, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0xC4, 0x00, 0x02, 0x30, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x84, 0x00, 0x03, 0x10, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x8C, 0x00, 0x03, 0x10, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x8C, 0x00, 0x03, 0x10, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x60, 0x01, 0x88, 0x00, 0x01, 0x18, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x60, 0x01, 0x88, 0x00, 0x01, 0x18, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x60, 0x01, 0x08, 0x00, 0x01, 0x08, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x70, 0x01, 0x08, 0x00, 0x01, 0x08, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x70, 0x01, 0x08, 0x00, 0x01, 0x08, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x50, 0x01, 0x08, 0x00, 0x01, 0x08, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x50, 0x01, 0x08, 0x00, 0x01, 0x08, 0x00, 0xB0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x50, 0x01, 0x08, 0x00, 0x01, 0x08, 0x00, 0xB0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x58, 0x01, 0x08, 0x00, 0x01, 0x08, 0x01, 0xB0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x48, 0x01, 0x08, 0x00, 0x01, 0x08, 0x01, 0x30, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x48, 0x01, 0x08, 0x00, 0x01, 0x08, 0x01, 0x20, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x4C, 0x01, 0x08, 0x00, 0x01, 0x08, 0x03, 0x20, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x4C, 0x01, 0x08, 0x00, 0x01, 0x08, 0x03, 0x20, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x44, 0x01, 0x08, 0x00, 0x01, 0x08, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x46, 0x01, 0x88, 0x00, 0x01, 0x18, 0x06, 0x20, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x62, 0x01, 0x88, 0x00, 0x01, 0x18, 0x04, 0x20, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x63, 0x00, 0x88, 0x00, 0x01, 0x10, 0x0C, 0x60, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x21, 0x00, 0x8C, 0x00, 0x03, 0x10, 0x08, 0x40, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x21, 0x00, 0x84, 0x00, 0x03, 0x10, 0x08, 0x40, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x31, 0x80, 0xC4, 0x00, 0x02, 0x30, 0x18, 0xC0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x10, 0x80, 0x44, 0x00, 0x02, 0x20, 0x10, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x18, 0xC0, 0x64, 0x00, 0x02, 0x60, 0x31, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x18, 0x40, 0x64, 0x00, 0x02, 0x60, 0x21, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x08, 0x20, 0x26, 0x00, 0x06, 0x40, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0C, 0x30, 0x36, 0x00, 0x06, 0xC0, 0xC3, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x04, 0x30, 0x1A, 0x00, 0x05, 0x80, 0x82, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x06, 0x18, 0x1A, 0x00, 0x05, 0x81, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0x0C, 0x0F, 0x00, 0x0F, 0x03, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x84, 0x07, 0x00, 0x0E, 0x02, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x86, 0x07, 0x00, 0x0E, 0x06, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xC3, 0x03, 0x80, 0x1C, 0x0E, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x81, 0x80, 0x18, 0x0C, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x39, 0x80, 0x80, 0x10, 0x18, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0xC0, 0x40, 0x20, 0x33, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x60, 0x00, 0x00, 0x67, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x30, 0x00, 0x00, 0xCE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xD8, 0x00, 0x01, 0xB8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x03, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x00,
0x00, 0x00, 0x7E, 0x00, 0x0F, 0xC0, 0x00, 0x7E, 0x00, 0x03, 0xE0, 0x00, 0x00, 0x1E, 0x00, 0x00,
0x00, 0x01, 0xFF, 0x80, 0x3F, 0xF0, 0x01, 0xFF, 0x80, 0x0F, 0xF8, 0x00, 0x3E, 0x1E, 0x00, 0x00,
0x00, 0x03, 0xFF, 0xE0, 0x7F, 0xF8, 0x03, 0xFF, 0xC0, 0x1F, 0xFE, 0x00, 0xFF, 0x9E, 0x00, 0x00,
0x00, 0x07, 0xFF, 0xC0, 0xFF, 0xFC, 0x07, 0xFF, 0xE0, 0x3F, 0xFF, 0x01, 0xFF, 0xDE, 0x00, 0x00,
0x00, 0x07, 0x83, 0xC1, 0xFC, 0x7E, 0x0F, 0xC3, 0xE0, 0x7E, 0x1F, 0x03, 0xFF, 0xFE, 0x00, 0x00,
0x00, 0x07, 0x80, 0x81, 0xF0, 0x3E, 0x0F, 0x81, 0xF0, 0xFC, 0x0F, 0x83, 0xFF, 0xFE, 0x00, 0x00,
0x00, 0x07, 0x80, 0x03, 0xE0, 0x1F, 0x1F, 0x00, 0xF0, 0xF8, 0x07, 0x87, 0xE1, 0xFE, 0x00, 0x00,
0x00, 0x07, 0x80, 0x03, 0xE0, 0x0F, 0x1E, 0x00, 0x78, 0xF0, 0x03, 0xC7, 0xC0, 0x7E, 0x00, 0x00,
0x00, 0x07, 0xC0, 0x03, 0xC0, 0x0F, 0x1E, 0x00, 0x79, 0xF0, 0x03, 0xCF, 0x80, 0x7E, 0x00, 0x00,
0x00, 0x07, 0xFE, 0x03, 0xFF, 0xFF, 0x3F, 0xFF, 0xF9, 0xFF, 0xFF, 0xCF, 0x80, 0x3E, 0x00, 0x00,
0x00, 0x03, 0xFF, 0x83, 0xFF, 0xFF, 0x3F, 0xFF, 0xF9, 0xFF, 0xFF, 0xCF, 0x00, 0x3E, 0x00, 0x00,
0x00, 0x03, 0xFF, 0xC3, 0xFF, 0xFF, 0x3F, 0xFF, 0xF9, 0xFF, 0xFF, 0xCF, 0x00, 0x3E, 0x00, 0x00,
0x00, 0x00, 0xFF, 0xE3, 0xFF, 0xFF, 0x3F, 0xFF, 0xF9, 0xFF, 0xFF, 0xCF, 0x00, 0x3E, 0x00, 0x00,
0x00, 0x00, 0x1F, 0xE3, 0xC0, 0x01, 0x3E, 0x00, 0x09, 0xF0, 0x00, 0x4F, 0x00, 0x3E, 0x00, 0x00,
0x00, 0x00, 0x01, 0xF3, 0xC0, 0x00, 0x1E, 0x00, 0x01, 0xF0, 0x00, 0x0F, 0x80, 0x3E, 0x00, 0x00,
0x00, 0x00, 0x00, 0xF3, 0xE0, 0x00, 0x1F, 0x00, 0x00, 0xF0, 0x00, 0x0F, 0x80, 0x7E, 0x00, 0x00,
0x00, 0x02, 0x00, 0xF1, 0xF0, 0x00, 0x1F, 0x00, 0x00, 0xF8, 0x00, 0x07, 0xC0, 0x7E, 0x00, 0x00,
0x00, 0x07, 0x01, 0xE1, 0xF8, 0x0C, 0x0F, 0x80, 0x60, 0x7C, 0x02, 0x07, 0xE1, 0xFE, 0x00, 0x00,
0x00, 0x07, 0xE7, 0xE0, 0xFC, 0x3E, 0x0F, 0xE1, 0xE0, 0x7F, 0x0F, 0x03, 0xFF, 0xFE, 0x00, 0x00,
0x00, 0x0F, 0xFF, 0xE0, 0xFF, 0xFE, 0x07, 0xFF, 0xF0, 0x3F, 0xFF, 0x83, 0xFF, 0xFE, 0x00, 0x00,
0x00, 0x07, 0xFF, 0xC0, 0x7F, 0xFC, 0x03, 0xFF, 0xE0, 0x1F, 0xFF, 0x01, 0xFF, 0xDE, 0x00, 0x00,
0x00, 0x01, 0xFF, 0x80, 0x1F, 0xF8, 0x00, 0xFF, 0xC0, 0x0F, 0xFE, 0x00, 0xFF, 0x9E, 0x00, 0x00,
0x00, 0x00, 0x7E, 0x00, 0x07, 0xE0, 0x00, 0x3F, 0x00, 0x01, 0xF0, 0x00, 0x3E, 0x1E, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,
0x00, 0x0F, 0x40, 0x04, 0x1F, 0x22, 0x00, 0x10, 0x00, 0x00, 0x38, 0x00, 0x82, 0x00, 0x00, 0x00,
0x00, 0x02, 0x40, 0x04, 0x04, 0x22, 0x00, 0x10, 0x00, 0x00, 0x20, 0x00, 0x82, 0x00, 0x00, 0x00,
0x00, 0x02, 0x7B, 0x85, 0xE4, 0x32, 0xA6, 0xF5, 0xAA, 0xEA, 0x21, 0xCE, 0xF2, 0xA6, 0x00, 0x00,
0x00, 0x02, 0x4A, 0x45, 0x24, 0x3E, 0x34, 0x95, 0xA2, 0xD2, 0x39, 0x62, 0x9A, 0xA4, 0x00, 0x00,
0x00, 0x02, 0x4B, 0xC5, 0x24, 0x22, 0xF4, 0x95, 0x8A, 0x9E, 0x21, 0x4A, 0x8A, 0xE4, 0x00, 0x00,
0x00, 0x02, 0x4A, 0x05, 0x24, 0x22, 0x94, 0x92, 0x4A, 0x98, 0x21, 0x5A, 0xD2, 0x84, 0x00, 0x00,
0x00, 0x02, 0x49, 0xC4, 0xC4, 0x22, 0xF4, 0x72, 0x4E, 0x8E, 0x3D, 0x4E, 0xF2, 0x64, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static const unsigned char SeeedLogo96x96[] =
{
0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xE0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xF0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x03, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xF8, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xF8,
0x00, 0x00, 0x00, 0x03, 0xC0, 0x00, 0x7E, 0x00, 0x00, 0x01, 0xE0, 0x00,
0x7F, 0x0F, 0xF8, 0x00, 0x00, 0x00, 0x03, 0xC0, 0x00, 0xFE, 0x00, 0x00,
0x01, 0xE0, 0x00, 0xFF, 0xEF, 0xF8, 0x00, 0x00, 0x00, 0x03, 0xC0, 0x00,
0xFE, 0x00, 0x00, 0x01, 0xE0, 0x00, 0xFF, 0xFF, 0xF8, 0x00, 0x00, 0x00,
0x03, 0xC0, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x7F, 0xFE, 0x7F,
0xC0, 0x00, 0x00, 0x03, 0xC0, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x0F, 0x00,
0x3F, 0xFE, 0x7F, 0xF8, 0x3F, 0xF1, 0xFB, 0xCF, 0xFC, 0xFE, 0xF3, 0xBC,
0x3D, 0xEF, 0xE0, 0x1F, 0xFE, 0x7F, 0xFF, 0x7F, 0xFB, 0xFF, 0xDF, 0xFE,
0xFE, 0xFF, 0xBC, 0x3D, 0xEF, 0xE0, 0x1F, 0xC6, 0xFF, 0xFF, 0x7F, 0xFB,
0xFF, 0xDF, 0xFE, 0xFE, 0xFF, 0xBC, 0x3D, 0xEF, 0xE0, 0x0F, 0xE3, 0xC7,
0xFE, 0x78, 0x7B, 0xC3, 0xDE, 0x1E, 0xF0, 0xFF, 0xBC, 0x3D, 0xEF, 0x00,
0x07, 0xFF, 0x87, 0xFC, 0x78, 0x7B, 0xC3, 0xDE, 0x1E, 0xF0, 0xF8, 0x3C,
0x3D, 0xEF, 0x00, 0x01, 0xFF, 0xFF, 0xF0, 0x00, 0x7B, 0xC3, 0xC0, 0x1E,
0xF0, 0xF0, 0x3C, 0x3D, 0xEF, 0x00, 0x01, 0xF3, 0x7F, 0xE0, 0x3F, 0xFB,
0xC3, 0xCF, 0xFE, 0xF0, 0xF0, 0x3C, 0x3D, 0xEF, 0x00, 0x03, 0xE3, 0x3F,
0x80, 0x7F, 0xFB, 0xC3, 0xDF, 0xFE, 0xF0, 0xF0, 0x3C, 0x3D, 0xEF, 0x00,
0x07, 0xE7, 0x3C, 0x00, 0x78, 0x7B, 0xC3, 0xDE, 0x1E, 0xF0, 0xF0, 0x3C,
0x3D, 0xEF, 0x00, 0x07, 0xFF, 0xBE, 0x00, 0x78, 0x7B, 0xC3, 0xDE, 0x1E,
0xF0, 0xF0, 0x3C, 0x3D, 0xEF, 0x00, 0x07, 0xFF, 0xFE, 0x00, 0x78, 0x7B,
0xC3, 0xDE, 0x1E, 0xF0, 0xF0, 0x3C, 0x3D, 0xEF, 0x00, 0x0F, 0xFF, 0xFE,
0x00, 0x7F, 0xFB, 0xFF, 0xDF, 0xFE, 0xF0, 0xF0, 0x3F, 0xFD, 0xEF, 0xE0,
0x0F, 0xFF, 0xFF, 0x00, 0x7F, 0xFB, 0xFF, 0xDF, 0xFE, 0xF0, 0xF0, 0x3F,
0xFD, 0xEF, 0xE0, 0x0F, 0xF9, 0xFF, 0x00, 0x3E, 0x79, 0xF9, 0xCF, 0x9E,
0xF0, 0xF0, 0x1F, 0x3D, 0xE7, 0xE0, 0x1F, 0xF1, 0xFF, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x80, 0xFF,
0x00, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0,
0x1C, 0x00, 0x7F, 0x00, 0x7F, 0xFF, 0xFF, 0xFF, 0xFE, 0xB4, 0x6D, 0x88,
0x8D, 0x18, 0xE0, 0x00, 0x00, 0x1F, 0x00, 0x7F, 0xFF, 0xFF, 0xFF, 0xFE,
0x95, 0xAD, 0x7D, 0xB5, 0x77, 0xE0, 0x00, 0x00, 0x0F, 0x00, 0x7F, 0xFF,
0xFF, 0xFF, 0xFE, 0xA5, 0xAD, 0x9D, 0x8D, 0x19, 0xE0, 0x00, 0x00, 0x06,
0x00, 0x7F, 0xFF, 0xFF, 0xFF, 0xFE, 0xB5, 0xAD, 0xED, 0xB5, 0x7E, 0xE0
};
/// <summary>
/// Signal handler for termination requests. This handler must be async-signal-safe.
/// </summary>
static void TerminationHandler(int signalNumber)
{
// Don't use Log_Debug here, as it is not guaranteed to be async-signal-safe.
terminationRequired = true;
}
/// <summary>
/// Main entry point for this sample.
/// </summary>
int main(int argc, char *argv[])
{
Log_Debug("Seeed oled 96*96 demo.\n");
const struct timespec sleepTime = { 1, 0 };
// Register a SIGTERM handler for termination requests
struct sigaction action;
memset(&action, 0, sizeof(struct sigaction));
action.sa_handler = TerminationHandler;
sigaction(SIGTERM, &action, NULL);
// Initialize I2C master
int i2cFd = I2CMaster_Open(MT3620_RDB_HEADER4_ISU12_I2C);
if (i2cFd < 0) {
Log_Debug("ERROR: I2CMaster_Open: errno=%d (%s)\n", errno, strerror(errno));
return -1;
}
int result = I2CMaster_SetBusSpeed(i2cFd, I2C_BUS_SPEED_STANDARD);
if (result != 0) {
Log_Debug("ERROR: I2CMaster_SetBusSpeed: errno=%d (%s)\n", errno, strerror(errno));
return -1;
}
result = I2CMaster_SetTimeout(i2cFd, 100);
if (result != 0) {
Log_Debug("ERROR: I2CMaster_SetTimeout: errno=%d (%s)\n", errno, strerror(errno));
return -1;
}
result = I2CMaster_SetDefaultTargetAddress(i2cFd, 0x3c); // OLED i2c address
if (result != 0) {
Log_Debug("ERROR: I2CMaster_SetDefaultTargetAddress: errno=%d (%s)\n", errno,
strerror(errno));
return -1;
}
//GroveOledDisplay_Init(i2cFd, SH1107G);
GroveOledDisplay_Init(i2cFd, SSD1327);
clearDisplay();
setNormalDisplay();
setVerticalMode();
// Main loop
while (!terminationRequired) {
for (uint8_t i = 0; i < 16; i++)
{
setTextXY(i, 0); //set Cursor to ith line, 0th column
setGrayLevel(i); //Set Grayscale level. Any number between 0 - 15.
putString("Hello from Sphere!"); //Print Hello World
}
nanosleep(&sleepTime, NULL);
clearDisplay();
if (SSD1327 == GroveOled_GetIC())
{
drawBitmap(SeeedLogo96x96, sizeof(SeeedLogo96x96));
}
else if (SH1107G == GroveOled_GetIC())
{
//drawBitmap(SeeedLogo128x128, sizeof(SeeedLogo128x128));
}
nanosleep(&sleepTime, NULL);
clearDisplay();
}
Log_Debug("Application exiting.\n");
return 0;
}
/**
Grove OLED Display 96x96 v2.0
*/
#include <errno.h>
#include <signal.h>
#include <unistd.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <applibs/log.h>
#include <time.h>
#include <applibs/i2c.h>
#include "seeedoled.h"
static int _i2cFd = -1;
static int Drive_IC = SSD1327;
static char addressingMode;
static uint8_t grayH;
static uint8_t grayL;
// This font can be freely used without any restriction(It is placed in public domain)
const unsigned char BasicFont[][8] =
{
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x5F,0x00,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,0x55,0x22,0x50,0x00,0x00},
{0x00,0x00,0x05,0x03,0x00,0x00,0x00,0x00},
{0x00,0x1C,0x22,0x41,0x00,0x00,0x00,0x00},
{0x00,0x41,0x22,0x1C,0x00,0x00,0x00,0x00},
{0x00,0x08,0x2A,0x1C,0x2A,0x08,0x00,0x00},
{0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00},
{0x00,0xA0,0x60,0x00,0x00,0x00,0x00,0x00},
{0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00},
{0x00,0x60,0x60,0x00,0x00,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,0x62,0x51,0x49,0x49,0x46,0x00,0x00},
{0x00,0x22,0x41,0x49,0x49,0x36,0x00,0x00},
{0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00},
{0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00},
{0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00},
{0x00,0x01,0x71,0x09,0x05,0x03,0x00,0x00},
{0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00},
{0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00},
{0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00},
{0x00,0x00,0xAC,0x6C,0x00,0x00,0x00,0x00},
{0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x00},
{0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00},
{0x00,0x41,0x22,0x14,0x08,0x00,0x00,0x00},
{0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00},
{0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00},
{0x00,0x7E,0x09,0x09,0x09,0x7E,0x00,0x00},
{0x00,0x7F,0x49,0x49,0x49,0x36,0x00,0x00},
{0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x00},
{0x00,0x7F,0x41,0x41,0x22,0x1C,0x00,0x00},
{0x00,0x7F,0x49,0x49,0x49,0x41,0x00,0x00},
{0x00,0x7F,0x09,0x09,0x09,0x01,0x00,0x00},
{0x00,0x3E,0x41,0x41,0x51,0x72,0x00,0x00},
{0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00},
{0x00,0x41,0x7F,0x41,0x00,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,0x0C,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,0x01,0x01,0x7F,0x01,0x01,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,0x51,0x49,0x45,0x43,0x00,0x00},
{0x00,0x7F,0x41,0x41,0x00,0x00,0x00,0x00},
{0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00},
{0x00,0x41,0x41,0x7F,0x00,0x00,0x00,0x00},
{0x00,0x04,0x02,0x01,0x02,0x04,0x00,0x00},
{0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00},
{0x00,0x01,0x02,0x04,0x00,0x00,0x00,0x00},
{0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00},
{0x00,0x7F,0x48,0x44,0x44,0x38,0x00,0x00},
{0x00,0x38,0x44,0x44,0x28,0x00,0x00,0x00},
{0x00,0x38,0x44,0x44,0x48,0x7F,0x00,0x00},
{0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00},
{0x00,0x08,0x7E,0x09,0x02,0x00,0x00,0x00},
{0x00,0x18,0xA4,0xA4,0xA4,0x7C,0x00,0x00},
{0x00,0x7F,0x08,0x04,0x04,0x78,0x00,0x00},
{0x00,0x00,0x7D,0x00,0x00,0x00,0x00,0x00},
{0x00,0x80,0x84,0x7D,0x00,0x00,0x00,0x00},
{0x00,0x7F,0x10,0x28,0x44,0x00,0x00,0x00},
{0x00,0x41,0x7F,0x40,0x00,0x00,0x00,0x00},
{0x00,0x7C,0x04,0x18,0x04,0x78,0x00,0x00},
{0x00,0x7C,0x08,0x04,0x7C,0x00,0x00,0x00},
{0x00,0x38,0x44,0x44,0x38,0x00,0x00,0x00},
{0x00,0xFC,0x24,0x24,0x18,0x00,0x00,0x00},
{0x00,0x18,0x24,0x24,0xFC,0x00,0x00,0x00},
{0x00,0x00,0x7C,0x08,0x04,0x00,0x00,0x00},
{0x00,0x48,0x54,0x54,0x24,0x00,0x00,0x00},
{0x00,0x04,0x7F,0x44,0x00,0x00,0x00,0x00},
{0x00,0x3C,0x40,0x40,0x7C,0x00,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,0x1C,0xA0,0xA0,0x7C,0x00,0x00,0x00},
{0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00},
{0x00,0x08,0x36,0x41,0x00,0x00,0x00,0x00},
{0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00},
{0x00,0x41,0x36,0x08,0x00,0x00,0x00,0x00},
{0x00,0x02,0x01,0x01,0x02,0x01,0x00,0x00},
{0x00,0x02,0x05,0x05,0x02,0x00,0x00,0x00}
};
static void sendCommand(uint8_t cmd)
{
//GroveI2C_WriteReg8(_i2cFd, SeeedGrayOLED_Address, SeeedGrayOLED_Command_Mode, cmd);
uint8_t data[2] = { SeeedGrayOLED_Command_Mode , cmd };
I2CMaster_Write(_i2cFd, SeeedGrayOLED_Address, data, 2);
}
static void sendData(uint8_t data)
{
//GroveI2C_WriteReg8(_i2cFd, SeeedGrayOLED_Address, SeeedGrayOLED_Data_Mode, data);
uint8_t bytes[2] = { SeeedGrayOLED_Data_Mode , data };
I2CMaster_Write(_i2cFd, SeeedGrayOLED_Address, bytes, 2);
}
unsigned int GroveOled_GetIC(void)
{
return Drive_IC;
}
void GroveOledDisplay_Init(int i2cFd, uint8_t IC)
{
_i2cFd = i2cFd;
Drive_IC = IC;
static const struct timespec sleepTime = { 0, 100000000 };
if (Drive_IC == SSD1327)
{
sendCommand(0xAE); // Set display OFF
sendCommand(0xD5); // Set Display Clock Divide Ratio / OSC Frequency
sendCommand(0x80); // Display Clock Divide Ratio / OSC Frequency
sendCommand(0xA8); // Set Multiplex Ratio
sendCommand(0x1F); // Multiplex Ratio
sendCommand(0xD3); // Set Display Offset
sendCommand(0x00); // Display Offset
sendCommand(0x40); // Set Display Start Line
sendCommand(0x8D); // Set Charge Pump
sendCommand(0x14); // Charge Pump (0x10 External, 0x14 Internal DC/DC)
sendCommand(0x20); // Memory mode
sendCommand(0x00); // Act like ks0108
sendCommand(0xA0); // Set Segment Re-Map
sendCommand(0xC8); // Set Com Output Scan Direction
sendCommand(0xDA); // Set COM Hardware Configuration
sendCommand(0x02);
sendCommand(0x81); // Set Contrast
sendCommand(0x8F); //
sendCommand(0xD9); // Set precharge
// optional? \/
//sendC ommand(0x12); // COM Hardware Configuration
sendCommand(0xF1); // 22 or F1 external vcc
sendCommand(0xDB); // Set VCOM detect
sendCommand(0x40); //
sendCommand(0xA4); // Set all pixels OFF
sendCommand(0xA6); // Set display not inverted
sendCommand(0xAF); // Set display On
}
else if (Drive_IC == SH1107G)
{
sendCommand(0xae); //Display OFF
sendCommand(0xd5); // Set Dclk
sendCommand(0x50); // 100Hz
sendCommand(0x20); // Set row address
sendCommand(0x81); // Set contrast control
sendCommand(0x80);
sendCommand(0xa0); // Segment remap
sendCommand(0xa4); // Set Entire Display ON
sendCommand(0xa6); // Normal display
sendCommand(0xad); // Set external VCC
sendCommand(0x80);
sendCommand(0xc0); // Set Common scan direction
sendCommand(0xd9); // Set phase leghth
sendCommand(0x1f);
sendCommand(0xdb); // Set Vcomh voltage
sendCommand(0x27);
sendCommand(0xaf); //Display ON
sendCommand(0xb0);
sendCommand(0x00);
sendCommand(0x11);
}
}
void setContrastLevel(unsigned char ContrastLevel)
{
sendCommand(SeeedGrayOLED_Set_ContrastLevel_Cmd);
sendCommand(ContrastLevel);
}
void setHorizontalMode(void)
{
if (Drive_IC == SSD1327)
{
sendCommand(0xA0); // remap to
sendCommand(0x42); // horizontal mode
// Row Address
sendCommand(0x75); // Set Row Address
sendCommand(0x00); // Start 0
sendCommand(0x1f); // End 31
// Column Address
sendCommand(0x15); // Set Column Address
sendCommand(0x08); // Start from 8th Column of driver IC. This is 0th Column for OLED
sendCommand(0x37); // End at (8 + 47)th column. Each Column has 2 pixels(or segments)
}
else if (Drive_IC == SH1107G)
{
sendCommand(0xA0);
sendCommand(0xC8);
}
}
void setVerticalMode(void)
{
if (Drive_IC == SSD1327)
{
sendCommand(0xA0); // remap to
sendCommand(0x46); // Vertical mode
}
else if (Drive_IC == SH1107G)
{
sendCommand(0xA0);
sendCommand(0xC0);
}
}
void setTextXY(unsigned char Row, unsigned char Column)
{
if (Drive_IC == SSD1327)
{
//Column Address
sendCommand(0x21); /* Set Column Address */
sendCommand((uint8_t)(0x08 + (Column * 4))); /* Start Column: Start from 8 */
sendCommand(0x37); /* End Column */
// Row Address
sendCommand(0xB0); /* Set Row Address */
sendCommand((uint8_t)(0x00 + (Row * 8))); /* Start Row*/
sendCommand((uint8_t)(0x07 + (Row * 8))); /* End Row*/
}
else if (Drive_IC == SH1107G)
{
sendCommand(0xb0 + (Row & 0x0F)); // set page/row
sendCommand(0x10 + ((Column >> 4) & 0x07)); // set column high 3 bytex
sendCommand(Column & 0x0F); // set column low 4 byte
}
}
void clearDisplay(void)
{
unsigned char i, j;
if (Drive_IC == SSD1327)
{
for (j = 0; j < 48; j++)
{
for (i = 0; i < 128; i++) //clear all columns
{
sendData(0x00);
}
}
}
else if (Drive_IC == SH1107G)
{
for (i = 0; i < 16; i++) {
sendCommand((uint8_t)(0xb0 + i));
sendCommand(0x0);
sendCommand(0x10);
for (j = 0; j < 128; j++) {
sendData(0x00);
}
}
}
}
void setGrayLevel(unsigned char grayLevel)
{
grayH = (uint8_t)((grayLevel << 4) & 0xF0);
grayL = (uint8_t)(grayLevel & 0x0F);
}
void putChar(unsigned char C)
{
if (C < 32 || C > 127) //Ignore non-printable ASCII characters. This can be modified for multilingual font.
{
C = ' '; //Space
}
if (Drive_IC == SSD1327)
{
for (int i = 0; i < 8; i = i + 2)
{
for (int j = 0; j < 8; j++)
{
// Character is constructed two pixel at a time using vertical mode from the default 8x8 font
char c = 0x00;
char bit1 = (BasicFont[C - 32][i] >> j) & 0x01;
char bit2 = (BasicFont[C - 32][i + 1] >> j) & 0x01;
// Each bit is changed to a nibble
c |= (bit1 == 1) ? grayH : 0x00;
c |= (bit2 == 1) ? grayL : 0x00;
sendData(c);
}
}
}
else if (Drive_IC == SH1107G)
{
for (int i = 0; i < 8; i++)
{
//read bytes from code memory
sendData((BasicFont[C - 32][i])); //font array starts at 0, ASCII starts at 32. Hence the translation
}
}
}
void putString(const char *String)
{
unsigned char i = 0;
while (String[i])
{
putChar(String[i]);
i++;
}
}
unsigned char putNumber(long long_num)
{
unsigned char char_buffer[10] = "";
unsigned char i = 0;
unsigned char f = 0;
if (long_num < 0)
{
f = 1;
putChar('-');
long_num = -long_num;
}
else if (long_num == 0)
{
f = 1;
putChar('0');
return f;
}
while (long_num > 0)
{
char_buffer[i++] = long_num % 10;
long_num /= 10;
}
f = f + i;
for (; i > 0; i--)
{
putChar('0' + char_buffer[i - 1]);
}
return f;
}
void drawBitmap(const unsigned char *bitmaparray, int bytes)
{
if (Drive_IC == SSD1327)
{
char localAddressMode = addressingMode;
if (addressingMode != HORIZONTAL_MODE)
{
//Bitmap is drawn in horizontal mode
setHorizontalMode();
}
for (int i = 0; i < bytes; i++)
{
for (int j = 0; j < 8; j = j + 2)
{
char c = 0x00;
char bit1 = (uint8_t)(bitmaparray[i] << j & 0x80);
char bit2 = (uint8_t)(bitmaparray[i] << (j + 1) & 0x80);
// Each bit is changed to a nibble
c |= (bit1) ? grayH : 0x00;
// Each bit is changed to a nibble
c |= (bit2) ? grayL : 0x00;
sendData(c);
}
}
if (localAddressMode == VERTICAL_MODE)
{
//If Vertical Mode was used earlier, restore it.
setVerticalMode();
}
}
else if (Drive_IC == SH1107G)
{
uint8_t Row = 0, column_l = 0x00, column_h = 0x10;
setHorizontalMode();
for (int i = 0; i < bytes; i++)
{
sendCommand((uint8_t)(0xb0 + Row));
sendCommand(column_l);
sendCommand(column_h);
char bits = (char)bitmaparray[i];
char tmp = 0x00;
for (int b = 0; b < 8; b++)
{
tmp |= ((bits >> (7 - b)) & 0x01) << b;
}
sendData(tmp);
// delay(10);
Row++;
if (Row >= 16) {
Row = 0;
column_l++;
if (column_l >= 16) {
column_l = 0x00;
column_h += 0x01;
}
}
}
}
}
void setHorizontalScrollProperties(bool direction, unsigned char startRow, unsigned char endRow, unsigned char startColumn, unsigned char endColumn, unsigned char scrollSpeed)
{
/*
Use the following defines for 'direction' :
Scroll_Left
Scroll_Right
Use the following defines for 'scrollSpeed' :
Scroll_2Frames
Scroll_3Frames
Scroll_4Frames
Scroll_5Frames
Scroll_25Frames
Scroll_64Frames
Scroll_128Frames
Scroll_256Frames
*/
if (Scroll_Right == direction)
{
//Scroll Right
sendCommand(0x27);
}
else
{
//Scroll Left
sendCommand(0x26);
}
sendCommand(0x00); //Dummmy byte
sendCommand(startRow);
sendCommand(scrollSpeed);
sendCommand(endRow);
sendCommand((uint8_t)(startColumn + 8));
sendCommand((uint8_t)(endColumn + 8));
sendCommand(0x00); //Dummmy byte
}
void activateScroll(void)
{
sendCommand(SeeedGrayOLED_Activate_Scroll_Cmd);
}
void deactivateScroll(void)
{
sendCommand(SeeedGrayOLED_Dectivate_Scroll_Cmd);
}
void setNormalDisplay(void)
{
sendCommand(SeeedGrayOLED_Normal_Display_Cmd);
}
void setInverseDisplay(void)
{
sendCommand(SeeedGrayOLED_Inverse_Display_Cmd);
}
#pragma once
#pragma once
//GROVE_NAME "Grove - OLED Display 1.12'' V2"
//SKU 101020132
//WIKI_URL http://wiki.seeedstudio.com/Grove-OLED_Display_1.12inch/
#pragma once
#include "applibs_versions.h"
#include <applibs/gpio.h>
#define SH1107G 1
#define SSD1327 2
#define VERTICAL_MODE 01
#define HORIZONTAL_MODE 02
#define SeeedGrayOLED_Address 0x3c
/*Command and register */
#define SeeedGrayOLED_Command_Mode 0x80
#define SeeedGrayOLED_Data_Mode 0x40
#define SeeedGrayOLED_Display_Off_Cmd 0xAE
#define SeeedGrayOLED_Display_On_Cmd 0xAF
#define SeeedGrayOLED_Normal_Display_Cmd 0xA6
#define SeeedGrayOLED_Inverse_Display_Cmd 0xA7
#define SeeedGrayOLED_Activate_Scroll_Cmd 0x2F
#define SeeedGrayOLED_Dectivate_Scroll_Cmd 0x2E
#define SeeedGrayOLED_Set_ContrastLevel_Cmd 0x81
#define Scroll_Left 0x00
#define Scroll_Right 0x01
#define Scroll_2Frames 0x7
#define Scroll_3Frames 0x4
#define Scroll_4Frames 0x5
#define Scroll_5Frames 0x0
#define Scroll_25Frames 0x6
#define Scroll_64Frames 0x1
#define Scroll_128Frames 0x2
#define Scroll_256Frames 0x3
unsigned int GroveOled_GetIC(void);
void GroveOledDisplay_Init(int i2cFd, uint8_t IC);
void setNormalDisplay(void);
void setInverseDisplay(void);
void setGrayLevel(unsigned char grayLevel);
void setVerticalMode(void);
void setHorizontalMode(void);
void setTextXY(unsigned char Row, unsigned char Column);
void clearDisplay(void);
void setContrastLevel(unsigned char ContrastLevel);
void putChar(unsigned char c);
void putString(const char *String);
unsigned char putNumber(long n);
void drawBitmap(const unsigned char *bitmaparray, int bytes);
void setHorizontalScrollProperties(bool direction, unsigned char startRow, unsigned char endRow, unsigned char startColumn, unsigned char endColumn, unsigned char scrollSpeed);
void activateScroll(void);
void deactivateScroll(void);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment