mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
i2clcd: Reformat the lcd source code
Reformatted to prepare for improving the error handling. This reformatting was done using clang-format. Signed-off-by: Wouter van Verre <wouter.van.verre@intel.com> Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
parent
3abd3a5ee9
commit
bb59d5db7a
@ -29,7 +29,8 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
I2CLcd::I2CLcd (int bus, int lcdAddress) {
|
||||
I2CLcd::I2CLcd(int bus, int lcdAddress)
|
||||
{
|
||||
m_lcd_control_address = lcdAddress;
|
||||
m_bus = bus;
|
||||
|
||||
@ -42,13 +43,15 @@ I2CLcd::I2CLcd (int bus, int lcdAddress) {
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
I2CLcd::write (int row, int column, std::string msg) {
|
||||
setCursor (row, column);
|
||||
write (msg);
|
||||
I2CLcd::write(int row, int column, std::string msg)
|
||||
{
|
||||
setCursor(row, column);
|
||||
write(msg);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
I2CLcd::createChar(uint8_t charSlot, uint8_t charData[]) {
|
||||
I2CLcd::createChar(uint8_t charSlot, uint8_t charData[])
|
||||
{
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
charSlot &= 0x07; // only have 8 positions we can set
|
||||
error = i2Cmd(m_i2c_lcd_control, LCD_SETCGRAMADDR | (charSlot << 3));
|
||||
@ -62,39 +65,49 @@ I2CLcd::createChar(uint8_t charSlot, uint8_t charData[]) {
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
I2CLcd::close() {
|
||||
I2CLcd::close()
|
||||
{
|
||||
return mraa_i2c_stop(m_i2c_lcd_control);
|
||||
}
|
||||
|
||||
std::string
|
||||
I2CLcd::name()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
I2CLcd::i2cReg (mraa_i2c_context ctx, int deviceAdress, int addr, uint8_t value) {
|
||||
I2CLcd::i2cReg(mraa_i2c_context ctx, int deviceAdress, int addr, uint8_t value)
|
||||
{
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
uint8_t data[2] = { addr, value };
|
||||
error = mraa_i2c_address (ctx, deviceAdress);
|
||||
error = mraa_i2c_write (ctx, data, 2);
|
||||
error = mraa_i2c_address(ctx, deviceAdress);
|
||||
error = mraa_i2c_write(ctx, data, 2);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
I2CLcd::i2Cmd (mraa_i2c_context ctx, uint8_t value) {
|
||||
I2CLcd::i2Cmd(mraa_i2c_context ctx, uint8_t value)
|
||||
{
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
uint8_t data[2] = { LCD_CMD, value };
|
||||
error = mraa_i2c_address (ctx, m_lcd_control_address);
|
||||
error = mraa_i2c_write (ctx, data, 2);
|
||||
error = mraa_i2c_address(ctx, m_lcd_control_address);
|
||||
error = mraa_i2c_write(ctx, data, 2);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
I2CLcd::i2cData (mraa_i2c_context ctx, uint8_t value) {
|
||||
I2CLcd::i2cData(mraa_i2c_context ctx, uint8_t value)
|
||||
{
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
uint8_t data[2] = { LCD_DATA, value };
|
||||
error = mraa_i2c_address (ctx, m_lcd_control_address);
|
||||
error = mraa_i2c_write (ctx, data, 2);
|
||||
error = mraa_i2c_address(ctx, m_lcd_control_address);
|
||||
error = mraa_i2c_write(ctx, data, 2);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
@ -26,8 +26,8 @@
|
||||
#include <string>
|
||||
#include <mraa/i2c.h>
|
||||
|
||||
namespace upm {
|
||||
|
||||
namespace upm
|
||||
{
|
||||
// commands
|
||||
#define LCD_CLEARDISPLAY 0x01
|
||||
#define LCD_RETURNHOME 0x02
|
||||
@ -80,30 +80,28 @@ namespace upm {
|
||||
* @defgroup i2clcd libupm-i2clcd
|
||||
* @ingroup seeed sparkfun adafruit i2c display gsk
|
||||
*/
|
||||
class I2CLcd {
|
||||
public:
|
||||
I2CLcd (int bus, int lcdAddress);
|
||||
mraa_result_t write (int x, int y, std::string msg);
|
||||
class I2CLcd
|
||||
{
|
||||
public:
|
||||
I2CLcd(int bus, int lcdAddress);
|
||||
mraa_result_t write(int x, int y, std::string msg);
|
||||
|
||||
virtual mraa_result_t write (std::string msg) = 0;
|
||||
virtual mraa_result_t setCursor (int row, int column) = 0;
|
||||
virtual mraa_result_t clear () = 0;
|
||||
virtual mraa_result_t home () = 0;
|
||||
virtual mraa_result_t createChar(uint8_t charSlot, uint8_t charData[]);
|
||||
virtual mraa_result_t i2Cmd (mraa_i2c_context ctx, uint8_t value);
|
||||
virtual mraa_result_t i2cReg (mraa_i2c_context ctx, int deviceAdress, int addr, uint8_t data);
|
||||
virtual mraa_result_t i2cData (mraa_i2c_context ctx, uint8_t value);
|
||||
virtual mraa_result_t write(std::string msg) = 0;
|
||||
virtual mraa_result_t setCursor(int row, int column) = 0;
|
||||
virtual mraa_result_t clear() = 0;
|
||||
virtual mraa_result_t home() = 0;
|
||||
virtual mraa_result_t createChar(uint8_t charSlot, uint8_t charData[]);
|
||||
virtual mraa_result_t i2Cmd(mraa_i2c_context ctx, uint8_t value);
|
||||
virtual mraa_result_t i2cReg(mraa_i2c_context ctx, int deviceAdress, int addr, uint8_t data);
|
||||
virtual mraa_result_t i2cData(mraa_i2c_context ctx, uint8_t value);
|
||||
|
||||
mraa_result_t close();
|
||||
std::string name()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
protected:
|
||||
std::string m_name;
|
||||
int m_lcd_control_address;
|
||||
int m_bus;
|
||||
mraa_i2c_context m_i2c_lcd_control;
|
||||
mraa_result_t close();
|
||||
std::string name();
|
||||
|
||||
protected:
|
||||
std::string m_name;
|
||||
int m_lcd_control_address;
|
||||
int m_bus;
|
||||
mraa_i2c_context m_i2c_lcd_control;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -29,7 +29,8 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
Jhd1313m1::Jhd1313m1 (int bus, int lcdAddress, int rgbAddress) : I2CLcd(bus, lcdAddress) {
|
||||
Jhd1313m1::Jhd1313m1(int bus, int lcdAddress, int rgbAddress) : I2CLcd(bus, lcdAddress)
|
||||
{
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
m_rgb_address = rgbAddress;
|
||||
@ -41,45 +42,43 @@ Jhd1313m1::Jhd1313m1 (int bus, int lcdAddress, int rgbAddress) : I2CLcd(bus, lcd
|
||||
}
|
||||
|
||||
usleep(50000);
|
||||
i2Cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
|
||||
i2Cmd(m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
|
||||
usleep(4500);
|
||||
i2Cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
|
||||
i2Cmd(m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
|
||||
usleep(4500);
|
||||
i2Cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
|
||||
i2Cmd(m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
|
||||
usleep(4500);
|
||||
i2Cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
|
||||
i2Cmd(m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
|
||||
|
||||
i2Cmd (m_i2c_lcd_control, LCD_DISPLAYCONTROL | LCD_DISPLAYON);
|
||||
clear ();
|
||||
i2Cmd(m_i2c_lcd_control, LCD_DISPLAYCONTROL | LCD_DISPLAYON);
|
||||
clear();
|
||||
usleep(4500);
|
||||
|
||||
i2Cmd (m_i2c_lcd_control, LCD_ENTRYMODESET |
|
||||
LCD_ENTRYLEFT |
|
||||
LCD_ENTRYSHIFTDECREMENT);
|
||||
i2Cmd(m_i2c_lcd_control, LCD_ENTRYMODESET | LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT);
|
||||
|
||||
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0, 0);
|
||||
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 1, 0);
|
||||
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x08, 0xAA);
|
||||
i2cReg(m_i2c_lcd_rgb, m_rgb_address, 0, 0);
|
||||
i2cReg(m_i2c_lcd_rgb, m_rgb_address, 1, 0);
|
||||
i2cReg(m_i2c_lcd_rgb, m_rgb_address, 0x08, 0xAA);
|
||||
|
||||
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x04, 255);
|
||||
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x03, 255);
|
||||
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x02, 255);
|
||||
i2cReg(m_i2c_lcd_rgb, m_rgb_address, 0x04, 255);
|
||||
i2cReg(m_i2c_lcd_rgb, m_rgb_address, 0x03, 255);
|
||||
i2cReg(m_i2c_lcd_rgb, m_rgb_address, 0x02, 255);
|
||||
}
|
||||
|
||||
Jhd1313m1::~Jhd1313m1() {
|
||||
|
||||
Jhd1313m1::~Jhd1313m1()
|
||||
{
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
Jhd1313m1::setColor(uint8_t r, uint8_t g, uint8_t b)
|
||||
{
|
||||
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0, 0);
|
||||
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 1, 0);
|
||||
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x08, 0xAA);
|
||||
i2cReg(m_i2c_lcd_rgb, m_rgb_address, 0, 0);
|
||||
i2cReg(m_i2c_lcd_rgb, m_rgb_address, 1, 0);
|
||||
i2cReg(m_i2c_lcd_rgb, m_rgb_address, 0x08, 0xAA);
|
||||
|
||||
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x04, r);
|
||||
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x03, g);
|
||||
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x02, b);
|
||||
i2cReg(m_i2c_lcd_rgb, m_rgb_address, 0x04, r);
|
||||
i2cReg(m_i2c_lcd_rgb, m_rgb_address, 0x03, g);
|
||||
i2cReg(m_i2c_lcd_rgb, m_rgb_address, 0x02, b);
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
@ -88,8 +87,8 @@ mraa_result_t
|
||||
Jhd1313m1::scroll(bool direction)
|
||||
{
|
||||
if (direction)
|
||||
return i2Cmd (m_i2c_lcd_control, (LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT));
|
||||
return i2Cmd (m_i2c_lcd_control, (LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT));
|
||||
return i2Cmd(m_i2c_lcd_control, (LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT));
|
||||
return i2Cmd(m_i2c_lcd_control, (LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -98,32 +97,36 @@ Jhd1313m1::scroll(bool direction)
|
||||
* **************
|
||||
*/
|
||||
mraa_result_t
|
||||
Jhd1313m1::write (std::string msg) {
|
||||
Jhd1313m1::write(std::string msg)
|
||||
{
|
||||
usleep(1000);
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
for (std::string::size_type i = 0; i < msg.size(); ++i) {
|
||||
error = i2cData (m_i2c_lcd_control, msg[i]);
|
||||
error = i2cData(m_i2c_lcd_control, msg[i]);
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
Jhd1313m1::setCursor (int row, int column) {
|
||||
Jhd1313m1::setCursor(int row, int column)
|
||||
{
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
int row_addr[] = { 0x80, 0xc0, 0x14, 0x54};
|
||||
int row_addr[] = { 0x80, 0xc0, 0x14, 0x54 };
|
||||
uint8_t offset = ((column % 16) + row_addr[row]);
|
||||
error = i2Cmd (m_i2c_lcd_control, offset);
|
||||
error = i2Cmd(m_i2c_lcd_control, offset);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
Jhd1313m1::clear () {
|
||||
return i2Cmd (m_i2c_lcd_control, LCD_CLEARDISPLAY);
|
||||
Jhd1313m1::clear()
|
||||
{
|
||||
return i2Cmd(m_i2c_lcd_control, LCD_CLEARDISPLAY);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
Jhd1313m1::home () {
|
||||
return i2Cmd (m_i2c_lcd_control, LCD_RETURNHOME);
|
||||
Jhd1313m1::home()
|
||||
{
|
||||
return i2Cmd(m_i2c_lcd_control, LCD_RETURNHOME);
|
||||
}
|
||||
|
@ -26,8 +26,8 @@
|
||||
#include <string>
|
||||
#include "i2clcd.h"
|
||||
|
||||
namespace upm {
|
||||
|
||||
namespace upm
|
||||
{
|
||||
/**
|
||||
* @library i2clcd
|
||||
* @sensor jhd1313m1
|
||||
@ -50,68 +50,68 @@ namespace upm {
|
||||
* @image html grovergblcd.jpg
|
||||
* @snippet jhd1313m1-lcd.cxx Interesting
|
||||
*/
|
||||
class Jhd1313m1 : public I2CLcd {
|
||||
public:
|
||||
/**
|
||||
* Jhd1313m1 constructor
|
||||
*
|
||||
* @param bus i2c bus to use
|
||||
* @param address the slave address the lcd is registered on
|
||||
* @param address the slave address the rgb backlight is on
|
||||
*/
|
||||
Jhd1313m1(int bus, int lcdAddress=0x3E, int rgbAddress=0x62);
|
||||
/**
|
||||
* Jhd1313m1 destructor
|
||||
*/
|
||||
~Jhd1313m1();
|
||||
/**
|
||||
* Make the LCD scroll text
|
||||
*
|
||||
* @param direction, true is typical scrolling to the right
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t scroll (bool direction);
|
||||
/**
|
||||
* Set the color of the backlight
|
||||
*
|
||||
* @param r 0-255 value for red
|
||||
* @param g 0-255 value for green
|
||||
* @param b 0-255 value for blue
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t setColor(uint8_t r, uint8_t g, uint8_t b);
|
||||
/**
|
||||
* Write a string to LCD
|
||||
*
|
||||
* @param msg The std::string to write to display, note only ascii
|
||||
* chars are supported
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t write(std::string msg);
|
||||
/**
|
||||
* Set cursor to a coordinate
|
||||
*
|
||||
* @param row The row to set cursor to
|
||||
* @param column The column to set cursor to
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t setCursor(int row, int column);
|
||||
/**
|
||||
* Clear display from characters
|
||||
*
|
||||
* @return Result of operatio
|
||||
*/
|
||||
mraa_result_t clear();
|
||||
/**
|
||||
* Return to coordinate 0,0
|
||||
*
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t home();
|
||||
class Jhd1313m1 : public I2CLcd
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Jhd1313m1 constructor
|
||||
*
|
||||
* @param bus i2c bus to use
|
||||
* @param address the slave address the lcd is registered on
|
||||
* @param address the slave address the rgb backlight is on
|
||||
*/
|
||||
Jhd1313m1(int bus, int lcdAddress = 0x3E, int rgbAddress = 0x62);
|
||||
/**
|
||||
* Jhd1313m1 destructor
|
||||
*/
|
||||
~Jhd1313m1();
|
||||
/**
|
||||
* Make the LCD scroll text
|
||||
*
|
||||
* @param direction, true is typical scrolling to the right
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t scroll(bool direction);
|
||||
/**
|
||||
* Set the color of the backlight
|
||||
*
|
||||
* @param r 0-255 value for red
|
||||
* @param g 0-255 value for green
|
||||
* @param b 0-255 value for blue
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t setColor(uint8_t r, uint8_t g, uint8_t b);
|
||||
/**
|
||||
* Write a string to LCD
|
||||
*
|
||||
* @param msg The std::string to write to display, note only ascii
|
||||
* chars are supported
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t write(std::string msg);
|
||||
/**
|
||||
* Set cursor to a coordinate
|
||||
*
|
||||
* @param row The row to set cursor to
|
||||
* @param column The column to set cursor to
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t setCursor(int row, int column);
|
||||
/**
|
||||
* Clear display from characters
|
||||
*
|
||||
* @return Result of operatio
|
||||
*/
|
||||
mraa_result_t clear();
|
||||
/**
|
||||
* Return to coordinate 0,0
|
||||
*
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t home();
|
||||
|
||||
private:
|
||||
int m_rgb_address;
|
||||
mraa_i2c_context m_i2c_lcd_rgb;
|
||||
private:
|
||||
int m_rgb_address;
|
||||
mraa_i2c_context m_i2c_lcd_rgb;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -32,7 +32,8 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
Lcm1602::Lcm1602(int bus_in, int addr_in) : I2CLcd (bus_in, addr_in) {
|
||||
Lcm1602::Lcm1602(int bus_in, int addr_in) : I2CLcd(bus_in, addr_in)
|
||||
{
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
usleep(50000);
|
||||
@ -60,8 +61,8 @@ Lcm1602::Lcm1602(int bus_in, int addr_in) : I2CLcd (bus_in, addr_in) {
|
||||
home();
|
||||
}
|
||||
|
||||
Lcm1602::~Lcm1602 () {
|
||||
|
||||
Lcm1602::~Lcm1602()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
@ -70,31 +71,35 @@ Lcm1602::~Lcm1602 () {
|
||||
* **************
|
||||
*/
|
||||
mraa_result_t
|
||||
Lcm1602::write (std::string msg) {
|
||||
Lcm1602::write(std::string msg)
|
||||
{
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
for (std::string::size_type i = 0; i < msg.size(); ++i) {
|
||||
error = send (msg[i], LCD_RS);
|
||||
error = send(msg[i], LCD_RS);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
Lcm1602::setCursor (int row, int column) {
|
||||
Lcm1602::setCursor(int row, int column)
|
||||
{
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
int row_addr[] = { 0x80, 0xc0, 0x14, 0x54};
|
||||
int row_addr[] = { 0x80, 0xc0, 0x14, 0x54 };
|
||||
uint8_t offset = ((column % 16) + row_addr[row]);
|
||||
|
||||
return send (LCD_CMD | offset, 0);
|
||||
return send(LCD_CMD | offset, 0);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
Lcm1602::clear () {
|
||||
Lcm1602::clear()
|
||||
{
|
||||
return send(LCD_CLEARDISPLAY, 0);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
Lcm1602::home () {
|
||||
Lcm1602::home()
|
||||
{
|
||||
return send(LCD_RETURNHOME, 0);
|
||||
}
|
||||
|
||||
@ -104,7 +109,8 @@ Lcm1602::home () {
|
||||
* **************
|
||||
*/
|
||||
mraa_result_t
|
||||
Lcm1602::send (uint8_t value, int mode) {
|
||||
Lcm1602::send(uint8_t value, int mode)
|
||||
{
|
||||
mraa_result_t ret = MRAA_SUCCESS;
|
||||
uint8_t h = value & 0xf0;
|
||||
uint8_t l = (value << 4) & 0xf0;
|
||||
|
@ -30,7 +30,8 @@
|
||||
#include <string>
|
||||
#include "i2clcd.h"
|
||||
|
||||
namespace upm {
|
||||
namespace upm
|
||||
{
|
||||
/**
|
||||
* @library i2clcd
|
||||
* @sensor lcm1602
|
||||
@ -39,7 +40,7 @@ namespace upm {
|
||||
* @man adafruit sparkfun
|
||||
* @web https://www.adafruit.com/datasheets/TC1602A-01T.pdf
|
||||
* @con i2c
|
||||
*
|
||||
*
|
||||
* @brief C++ API for LCM1602 i2c controller for HD44780 based displays
|
||||
*
|
||||
* This supports all sizes of HD44780 displays from 16x2 to 4x20, the
|
||||
@ -51,52 +52,53 @@ namespace upm {
|
||||
* @image html lcm1602.jpeg
|
||||
* @snippet lcm1602-lcd.cxx Interesting
|
||||
*/
|
||||
class Lcm1602 : public I2CLcd {
|
||||
public:
|
||||
/**
|
||||
* Lcm1602 Constructor, calls libmraa initialisation functions
|
||||
*
|
||||
* @param bus i2c bus to use
|
||||
* @param address the slave address the lcd is registered on
|
||||
*/
|
||||
Lcm1602(int bus, int address);
|
||||
/**
|
||||
* Lcm1602 Destructor
|
||||
*/
|
||||
~Lcm1602();
|
||||
/**
|
||||
* Write a string to LCD
|
||||
*
|
||||
* @param msg The std::string to write to display, note only ascii
|
||||
* chars are supported
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t write(std::string msg);
|
||||
/**
|
||||
* Set cursor to a coordinate
|
||||
*
|
||||
* @param row The row to set cursor to
|
||||
* @param column The column to set cursor to
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t setCursor(int row, int column);
|
||||
/**
|
||||
* Clear display from characters
|
||||
*
|
||||
* @return Result of operatio
|
||||
*/
|
||||
mraa_result_t clear();
|
||||
/**
|
||||
* Return to coordinate 0,0
|
||||
*
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t home();
|
||||
class Lcm1602 : public I2CLcd
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Lcm1602 Constructor, calls libmraa initialisation functions
|
||||
*
|
||||
* @param bus i2c bus to use
|
||||
* @param address the slave address the lcd is registered on
|
||||
*/
|
||||
Lcm1602(int bus, int address);
|
||||
/**
|
||||
* Lcm1602 Destructor
|
||||
*/
|
||||
~Lcm1602();
|
||||
/**
|
||||
* Write a string to LCD
|
||||
*
|
||||
* @param msg The std::string to write to display, note only ascii
|
||||
* chars are supported
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t write(std::string msg);
|
||||
/**
|
||||
* Set cursor to a coordinate
|
||||
*
|
||||
* @param row The row to set cursor to
|
||||
* @param column The column to set cursor to
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t setCursor(int row, int column);
|
||||
/**
|
||||
* Clear display from characters
|
||||
*
|
||||
* @return Result of operatio
|
||||
*/
|
||||
mraa_result_t clear();
|
||||
/**
|
||||
* Return to coordinate 0,0
|
||||
*
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t home();
|
||||
|
||||
private :
|
||||
mraa_result_t send(uint8_t value, int mode);
|
||||
mraa_result_t write4bits(uint8_t value);
|
||||
mraa_result_t expandWrite(uint8_t value);
|
||||
mraa_result_t pulseEnable(uint8_t value);
|
||||
};
|
||||
private:
|
||||
mraa_result_t send(uint8_t value, int mode);
|
||||
mraa_result_t write4bits(uint8_t value);
|
||||
mraa_result_t expandWrite(uint8_t value);
|
||||
mraa_result_t pulseEnable(uint8_t value);
|
||||
};
|
||||
}
|
||||
|
218
src/lcd/ssd.h
218
src/lcd/ssd.h
@ -24,120 +24,112 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace upm {
|
||||
|
||||
#define DISPLAY_CMD_OFF 0xAE
|
||||
#define DISPLAY_CMD_ON 0xAF
|
||||
|
||||
#define BASE_LOW_COLUMN_ADDR 0x00
|
||||
#define BASE_HIGH_COLUMN_ADDR 0x10
|
||||
#define BASE_PAGE_START_ADDR 0xB0
|
||||
#define DISPLAY_CMD_MEM_ADDR_MODE 0x20
|
||||
|
||||
const uint8_t BasicFont[][8] =
|
||||
namespace upm
|
||||
{
|
||||
{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}
|
||||
};
|
||||
#define DISPLAY_CMD_OFF 0xAE
|
||||
#define DISPLAY_CMD_ON 0xAF
|
||||
|
||||
typedef enum {
|
||||
HORIZONTAL = 0,
|
||||
VERTICAL = 1,
|
||||
PAGE = 2
|
||||
} displayAddressingMode;
|
||||
#define BASE_LOW_COLUMN_ADDR 0x00
|
||||
#define BASE_HIGH_COLUMN_ADDR 0x10
|
||||
#define BASE_PAGE_START_ADDR 0xB0
|
||||
#define DISPLAY_CMD_MEM_ADDR_MODE 0x20
|
||||
|
||||
const uint8_t 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 } };
|
||||
|
||||
typedef enum { HORIZONTAL = 0, VERTICAL = 1, PAGE = 2 } displayAddressingMode;
|
||||
}
|
||||
|
@ -29,28 +29,30 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
SSD1308::SSD1308 (int bus_in, int addr_in) : I2CLcd (bus_in, addr_in) {
|
||||
i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_OFF); // display off
|
||||
usleep (4500);
|
||||
i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_ON); // display on
|
||||
usleep (4500);
|
||||
setNormalDisplay (); // set to normal display '1' is ON
|
||||
SSD1308::SSD1308(int bus_in, int addr_in) : I2CLcd(bus_in, addr_in)
|
||||
{
|
||||
i2Cmd(m_i2c_lcd_control, DISPLAY_CMD_OFF); // display off
|
||||
usleep(4500);
|
||||
i2Cmd(m_i2c_lcd_control, DISPLAY_CMD_ON); // display on
|
||||
usleep(4500);
|
||||
setNormalDisplay(); // set to normal display '1' is ON
|
||||
|
||||
clear ();
|
||||
setAddressingMode (PAGE);
|
||||
clear();
|
||||
setAddressingMode(PAGE);
|
||||
}
|
||||
|
||||
SSD1308::~SSD1308 () {
|
||||
|
||||
SSD1308::~SSD1308()
|
||||
{
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
SSD1308::draw (uint8_t *data, int bytes) {
|
||||
SSD1308::draw(uint8_t* data, int bytes)
|
||||
{
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
setAddressingMode (HORIZONTAL);
|
||||
setAddressingMode(HORIZONTAL);
|
||||
for (int idx = 0; idx < bytes; idx++) {
|
||||
i2cData (m_i2c_lcd_control, data[idx]);
|
||||
i2cData(m_i2c_lcd_control, data[idx]);
|
||||
}
|
||||
|
||||
return error;
|
||||
@ -62,52 +64,58 @@ SSD1308::draw (uint8_t *data, int bytes) {
|
||||
* **************
|
||||
*/
|
||||
mraa_result_t
|
||||
SSD1308::write (std::string msg) {
|
||||
SSD1308::write(std::string msg)
|
||||
{
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
uint8_t data[2] = {0x40, 0};
|
||||
uint8_t data[2] = { 0x40, 0 };
|
||||
|
||||
setAddressingMode (PAGE);
|
||||
setAddressingMode(PAGE);
|
||||
for (std::string::size_type i = 0; i < msg.size(); ++i) {
|
||||
writeChar (m_i2c_lcd_control, msg[i]);
|
||||
writeChar(m_i2c_lcd_control, msg[i]);
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
SSD1308::setCursor (int row, int column) {
|
||||
SSD1308::setCursor(int row, int column)
|
||||
{
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
error = i2Cmd (m_i2c_lcd_control, BASE_PAGE_START_ADDR + row); // set page address
|
||||
error = i2Cmd (m_i2c_lcd_control, BASE_LOW_COLUMN_ADDR + (8 * column & 0x0F)); // set column lower address
|
||||
error = i2Cmd (m_i2c_lcd_control, BASE_HIGH_COLUMN_ADDR + ((8 * column >> 4) & 0x0F)); // set column higher address
|
||||
error = i2Cmd(m_i2c_lcd_control, BASE_PAGE_START_ADDR + row); // set page address
|
||||
error = i2Cmd(m_i2c_lcd_control,
|
||||
BASE_LOW_COLUMN_ADDR + (8 * column & 0x0F)); // set column lower address
|
||||
error = i2Cmd(m_i2c_lcd_control,
|
||||
BASE_HIGH_COLUMN_ADDR + ((8 * column >> 4) & 0x0F)); // set column higher address
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
SSD1308::clear () {
|
||||
SSD1308::clear()
|
||||
{
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
uint8_t columnIdx, rowIdx;
|
||||
|
||||
i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_OFF); // display off
|
||||
for(rowIdx = 0; rowIdx < 8; rowIdx++) {
|
||||
setCursor (rowIdx, 0);
|
||||
i2Cmd(m_i2c_lcd_control, DISPLAY_CMD_OFF); // display off
|
||||
for (rowIdx = 0; rowIdx < 8; rowIdx++) {
|
||||
setCursor(rowIdx, 0);
|
||||
|
||||
// clear all columns
|
||||
for(columnIdx = 0; columnIdx < 16; columnIdx++) {
|
||||
writeChar (m_i2c_lcd_control, ' ');
|
||||
for (columnIdx = 0; columnIdx < 16; columnIdx++) {
|
||||
writeChar(m_i2c_lcd_control, ' ');
|
||||
}
|
||||
}
|
||||
i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_ON); // display on
|
||||
home ();
|
||||
i2Cmd(m_i2c_lcd_control, DISPLAY_CMD_ON); // display on
|
||||
home();
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
SSD1308::home () {
|
||||
return setCursor (0, 0);
|
||||
SSD1308::home()
|
||||
{
|
||||
return setCursor(0, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -116,23 +124,26 @@ SSD1308::home () {
|
||||
* **************
|
||||
*/
|
||||
mraa_result_t
|
||||
SSD1308::writeChar (mraa_i2c_context ctx, uint8_t value) {
|
||||
SSD1308::writeChar(mraa_i2c_context ctx, uint8_t value)
|
||||
{
|
||||
if (value < 0x20 || value > 0x7F) {
|
||||
value = 0x20; // space
|
||||
}
|
||||
|
||||
for (uint8_t idx = 0; idx < 8; idx++) {
|
||||
i2cData (m_i2c_lcd_control, BasicFont[value - 32][idx]);
|
||||
i2cData(m_i2c_lcd_control, BasicFont[value - 32][idx]);
|
||||
}
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
SSD1308::setNormalDisplay () {
|
||||
return i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_SET_NORMAL_1308); // set to normal display '1' is ON
|
||||
SSD1308::setNormalDisplay()
|
||||
{
|
||||
return i2Cmd(m_i2c_lcd_control, DISPLAY_CMD_SET_NORMAL_1308); // set to normal display '1' is ON
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
SSD1308::setAddressingMode (displayAddressingMode mode) {
|
||||
i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_MEM_ADDR_MODE); //set addressing mode
|
||||
i2Cmd (m_i2c_lcd_control, mode); //set page addressing mode
|
||||
SSD1308::setAddressingMode(displayAddressingMode mode)
|
||||
{
|
||||
i2Cmd(m_i2c_lcd_control, DISPLAY_CMD_MEM_ADDR_MODE); // set addressing mode
|
||||
i2Cmd(m_i2c_lcd_control, mode); // set page addressing mode
|
||||
}
|
||||
|
@ -28,9 +28,9 @@
|
||||
#include "i2clcd.h"
|
||||
#include "ssd.h"
|
||||
|
||||
namespace upm {
|
||||
|
||||
#define DISPLAY_CMD_SET_NORMAL_1308 0xA6
|
||||
namespace upm
|
||||
{
|
||||
#define DISPLAY_CMD_SET_NORMAL_1308 0xA6
|
||||
|
||||
/**
|
||||
* @library i2clcd
|
||||
@ -42,7 +42,7 @@ namespace upm {
|
||||
* @web http://garden.seeedstudio.com/images/4/46/SSD1308_1.0.pdf
|
||||
* @web http://www.seeedstudio.com/wiki/Grove_-_OLED_Display_0.96%22
|
||||
* @con i2c
|
||||
*
|
||||
*
|
||||
* @brief C++ API for SSD1308 i2c controlled OLED displays
|
||||
*
|
||||
* The SSD1308 is a 128x64 Dot matrix OLED/PLED segment driver with
|
||||
@ -52,59 +52,61 @@ namespace upm {
|
||||
* @image html ssd1308.jpeg
|
||||
* @snippet ssd1308-oled.cxx Interesting
|
||||
*/
|
||||
class SSD1308 : public I2CLcd {
|
||||
public:
|
||||
/**
|
||||
* SSD1308 Constructor, calls libmraa initialisation functions
|
||||
*
|
||||
* @param bus i2c bus to use
|
||||
* @param address the slave address the lcd is registered on
|
||||
*/
|
||||
SSD1308 (int bus, int address=0x3C);
|
||||
/**
|
||||
* SSD1308 Destructor
|
||||
*/
|
||||
~SSD1308 ();
|
||||
/**
|
||||
* Draw an image, see examples/python/make_oled_pic.py for an
|
||||
* explanation on how the pixels are mapped to bytes
|
||||
*
|
||||
* @param data the buffer to read
|
||||
* @param bytes the amount of bytes to read from the pointer
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t draw(uint8_t *data, int bytes);
|
||||
/**
|
||||
* Write a string to LCD
|
||||
*
|
||||
* @param msg The std::string to write to display, note only ascii
|
||||
* chars are supported
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t write(std::string msg);
|
||||
/**
|
||||
* Set cursor to a coordinate
|
||||
*
|
||||
* @param row The row to set cursor to
|
||||
* @param column The column to set cursor to
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t setCursor(int row, int column);
|
||||
/**
|
||||
* Clear display from characters
|
||||
*
|
||||
* @return Result of operatio
|
||||
*/
|
||||
mraa_result_t clear();
|
||||
/**
|
||||
* Return to coordinate 0,0
|
||||
*
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t home();
|
||||
private:
|
||||
mraa_result_t writeChar (mraa_i2c_context ctx, uint8_t value);
|
||||
mraa_result_t setNormalDisplay ();
|
||||
mraa_result_t setAddressingMode (displayAddressingMode mode);
|
||||
};
|
||||
class SSD1308 : public I2CLcd
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* SSD1308 Constructor, calls libmraa initialisation functions
|
||||
*
|
||||
* @param bus i2c bus to use
|
||||
* @param address the slave address the lcd is registered on
|
||||
*/
|
||||
SSD1308(int bus, int address = 0x3C);
|
||||
/**
|
||||
* SSD1308 Destructor
|
||||
*/
|
||||
~SSD1308();
|
||||
/**
|
||||
* Draw an image, see examples/python/make_oled_pic.py for an
|
||||
* explanation on how the pixels are mapped to bytes
|
||||
*
|
||||
* @param data the buffer to read
|
||||
* @param bytes the amount of bytes to read from the pointer
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t draw(uint8_t* data, int bytes);
|
||||
/**
|
||||
* Write a string to LCD
|
||||
*
|
||||
* @param msg The std::string to write to display, note only ascii
|
||||
* chars are supported
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t write(std::string msg);
|
||||
/**
|
||||
* Set cursor to a coordinate
|
||||
*
|
||||
* @param row The row to set cursor to
|
||||
* @param column The column to set cursor to
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t setCursor(int row, int column);
|
||||
/**
|
||||
* Clear display from characters
|
||||
*
|
||||
* @return Result of operatio
|
||||
*/
|
||||
mraa_result_t clear();
|
||||
/**
|
||||
* Return to coordinate 0,0
|
||||
*
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t home();
|
||||
|
||||
private:
|
||||
mraa_result_t writeChar(mraa_i2c_context ctx, uint8_t value);
|
||||
mraa_result_t setNormalDisplay();
|
||||
mraa_result_t setAddressingMode(displayAddressingMode mode);
|
||||
};
|
||||
}
|
||||
|
@ -30,106 +30,111 @@
|
||||
using namespace upm;
|
||||
|
||||
#define INIT_SLEEP 50000
|
||||
#define CMD_SLEEP 10000
|
||||
#define CMD_SLEEP 10000
|
||||
|
||||
SSD1327::SSD1327 (int bus_in, int addr_in) : I2CLcd (bus_in, addr_in) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
usleep (INIT_SLEEP);
|
||||
i2Cmd (m_i2c_lcd_control, 0xFD); // Unlock OLED driver IC MCU interface from entering command. i.e: Accept commands
|
||||
usleep (INIT_SLEEP);
|
||||
i2Cmd (m_i2c_lcd_control, 0x12);
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0xAE); // Set display off
|
||||
usleep (INIT_SLEEP);
|
||||
i2Cmd (m_i2c_lcd_control, 0xA8); // set multiplex ratio
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0x5F); // 96
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0xA1); // set display start line
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0x00); //
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0xA2); // set display offset
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0x60);
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0xA0); // set remap
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0x46);
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0xAB); // set vdd internal
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0x01); //
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0x81); // set contrasr
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0x53); // 100 nit
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0xB1); // Set Phase Length
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0X51); //
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0xB3); // Set Display Clock Divide Ratio/Oscillator Frequency
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0x01); //
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0xB9); //
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0xBC); // set pre_charge voltage/VCOMH
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0x08); // (0x08);
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0xBE); // set VCOMH
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0X07); // (0x07);
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0xB6); // Set second pre-charge period
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0x01); //
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0xD5); // enable second precharge and enternal vsl
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0X62); // (0x62);
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0xA4); // Set Normal Display Mode
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0x2E); // Deactivate Scroll
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0xAF); // Switch on display
|
||||
usleep (INIT_SLEEP);
|
||||
SSD1327::SSD1327(int bus_in, int addr_in) : I2CLcd(bus_in, addr_in)
|
||||
{
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
usleep(INIT_SLEEP);
|
||||
i2Cmd(m_i2c_lcd_control,
|
||||
0xFD); // Unlock OLED driver IC MCU interface from entering command. i.e: Accept commands
|
||||
usleep(INIT_SLEEP);
|
||||
i2Cmd(m_i2c_lcd_control, 0x12);
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0xAE); // Set display off
|
||||
usleep(INIT_SLEEP);
|
||||
i2Cmd(m_i2c_lcd_control, 0xA8); // set multiplex ratio
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0x5F); // 96
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0xA1); // set display start line
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0x00); //
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0xA2); // set display offset
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0x60);
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0xA0); // set remap
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0x46);
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0xAB); // set vdd internal
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0x01); //
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0x81); // set contrasr
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0x53); // 100 nit
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0xB1); // Set Phase Length
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0X51); //
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0xB3); // Set Display Clock Divide Ratio/Oscillator Frequency
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0x01); //
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0xB9); //
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0xBC); // set pre_charge voltage/VCOMH
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0x08); // (0x08);
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0xBE); // set VCOMH
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0X07); // (0x07);
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0xB6); // Set second pre-charge period
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0x01); //
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0xD5); // enable second precharge and enternal vsl
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0X62); // (0x62);
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0xA4); // Set Normal Display Mode
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0x2E); // Deactivate Scroll
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0xAF); // Switch on display
|
||||
usleep(INIT_SLEEP);
|
||||
|
||||
// Row Address
|
||||
error = i2Cmd (m_i2c_lcd_control, 0x75); // Set Row Address
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0x00); // Start 0
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0x5f); // End 95
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0x75); // Set Row Address
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0x00); // Start 0
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0x5f); // End 95
|
||||
usleep(INIT_SLEEP);
|
||||
|
||||
// Column Address
|
||||
error = i2Cmd (m_i2c_lcd_control, 0x15); // Set Column Address
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0x08); // Start from 8th Column of driver IC. This is 0th Column for OLED
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd (m_i2c_lcd_control, 0x37); // End at (8 + 47)th column. Each Column has 2 pixels(segments)
|
||||
usleep (INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0x15); // Set Column Address
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control,
|
||||
0x08); // Start from 8th Column of driver IC. This is 0th Column for OLED
|
||||
usleep(INIT_SLEEP);
|
||||
error = i2Cmd(m_i2c_lcd_control, 0x37); // End at (8 + 47)th column. Each Column has 2
|
||||
// pixels(segments)
|
||||
usleep(INIT_SLEEP);
|
||||
|
||||
clear ();
|
||||
setNormalDisplay ();
|
||||
setVerticalMode ();
|
||||
clear();
|
||||
setNormalDisplay();
|
||||
setVerticalMode();
|
||||
}
|
||||
|
||||
SSD1327::~SSD1327 () {
|
||||
|
||||
SSD1327::~SSD1327()
|
||||
{
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
SSD1327::draw (uint8_t *data, int bytes) {
|
||||
SSD1327::draw(uint8_t* data, int bytes)
|
||||
{
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
setHorizontalMode ();
|
||||
setHorizontalMode();
|
||||
for (int row = 0; row < bytes; row++) {
|
||||
for (uint8_t col = 0; col < 8; col+=2) {
|
||||
for (uint8_t col = 0; col < 8; col += 2) {
|
||||
uint8_t value = 0x0;
|
||||
|
||||
uint8_t bitOne = (data[row] << col) & 0x80;
|
||||
@ -138,8 +143,8 @@ SSD1327::draw (uint8_t *data, int bytes) {
|
||||
value |= (bitOne) ? grayHigh : 0x00;
|
||||
value |= (bitTwo) ? grayLow : 0x00;
|
||||
|
||||
i2cData (m_i2c_lcd_control, value);
|
||||
usleep (CMD_SLEEP - 2000);
|
||||
i2cData(m_i2c_lcd_control, value);
|
||||
usleep(CMD_SLEEP - 2000);
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,48 +157,51 @@ SSD1327::draw (uint8_t *data, int bytes) {
|
||||
* **************
|
||||
*/
|
||||
mraa_result_t
|
||||
SSD1327::write (std::string msg) {
|
||||
SSD1327::write(std::string msg)
|
||||
{
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
setVerticalMode ();
|
||||
setVerticalMode();
|
||||
for (std::string::size_type i = 0; i < msg.size(); ++i) {
|
||||
writeChar (m_i2c_lcd_control, msg[i]);
|
||||
writeChar(m_i2c_lcd_control, msg[i]);
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
SSD1327::setCursor (int row, int column) {
|
||||
SSD1327::setCursor(int row, int column)
|
||||
{
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
//Column Address
|
||||
i2Cmd (m_i2c_lcd_control, 0x15); /* Set Column Address */
|
||||
usleep (CMD_SLEEP);
|
||||
i2Cmd (m_i2c_lcd_control, 0x08 + (column * 4)); /* Start Column: Start from 8 */
|
||||
usleep (CMD_SLEEP);
|
||||
i2Cmd (m_i2c_lcd_control, 0x37); /* End Column */
|
||||
usleep (CMD_SLEEP);
|
||||
// Column Address
|
||||
i2Cmd(m_i2c_lcd_control, 0x15); /* Set Column Address */
|
||||
usleep(CMD_SLEEP);
|
||||
i2Cmd(m_i2c_lcd_control, 0x08 + (column * 4)); /* Start Column: Start from 8 */
|
||||
usleep(CMD_SLEEP);
|
||||
i2Cmd(m_i2c_lcd_control, 0x37); /* End Column */
|
||||
usleep(CMD_SLEEP);
|
||||
// Row Address
|
||||
i2Cmd (m_i2c_lcd_control, 0x75); /* Set Row Address */
|
||||
usleep (CMD_SLEEP);
|
||||
i2Cmd (m_i2c_lcd_control, 0x00 + (row * 8)); /* Start Row*/
|
||||
usleep (CMD_SLEEP);
|
||||
i2Cmd (m_i2c_lcd_control, 0x07 + (row * 8)); /* End Row*/
|
||||
usleep (CMD_SLEEP);
|
||||
i2Cmd(m_i2c_lcd_control, 0x75); /* Set Row Address */
|
||||
usleep(CMD_SLEEP);
|
||||
i2Cmd(m_i2c_lcd_control, 0x00 + (row * 8)); /* Start Row*/
|
||||
usleep(CMD_SLEEP);
|
||||
i2Cmd(m_i2c_lcd_control, 0x07 + (row * 8)); /* End Row*/
|
||||
usleep(CMD_SLEEP);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
SSD1327::clear () {
|
||||
SSD1327::clear()
|
||||
{
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
uint8_t columnIdx, rowIdx;
|
||||
|
||||
for(rowIdx = 0; rowIdx < 12; rowIdx++) {
|
||||
for (rowIdx = 0; rowIdx < 12; rowIdx++) {
|
||||
// clear all columns
|
||||
for(columnIdx = 0; columnIdx < 12; columnIdx++) {
|
||||
writeChar (m_i2c_lcd_control, ' ');
|
||||
for (columnIdx = 0; columnIdx < 12; columnIdx++) {
|
||||
writeChar(m_i2c_lcd_control, ' ');
|
||||
}
|
||||
}
|
||||
|
||||
@ -201,14 +209,16 @@ SSD1327::clear () {
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
SSD1327::home () {
|
||||
return setCursor (0, 0);
|
||||
SSD1327::home()
|
||||
{
|
||||
return setCursor(0, 0);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
SSD1327::setGrayLevel (uint8_t level) {
|
||||
SSD1327::setGrayLevel(uint8_t level)
|
||||
{
|
||||
grayHigh = (level << 4) & 0xF0;
|
||||
grayLow = level & 0x0F;
|
||||
grayLow = level & 0x0F;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -217,12 +227,13 @@ SSD1327::setGrayLevel (uint8_t level) {
|
||||
* **************
|
||||
*/
|
||||
mraa_result_t
|
||||
SSD1327::writeChar (mraa_i2c_context ctx, uint8_t value) {
|
||||
SSD1327::writeChar(mraa_i2c_context ctx, uint8_t value)
|
||||
{
|
||||
if (value < 0x20 || value > 0x7F) {
|
||||
value = 0x20; // space
|
||||
}
|
||||
|
||||
for (uint8_t row = 0; row < 8; row=row+2) {
|
||||
for (uint8_t row = 0; row < 8; row = row + 2) {
|
||||
for (uint8_t col = 0; col < 8; col++) {
|
||||
uint8_t data = 0x0;
|
||||
|
||||
@ -232,45 +243,50 @@ SSD1327::writeChar (mraa_i2c_context ctx, uint8_t value) {
|
||||
data |= (bitOne) ? grayHigh : 0x00;
|
||||
data |= (bitTwo) ? grayLow : 0x00;
|
||||
|
||||
i2cData (m_i2c_lcd_control, data);
|
||||
usleep (CMD_SLEEP - 2000);
|
||||
i2cData(m_i2c_lcd_control, data);
|
||||
usleep(CMD_SLEEP - 2000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
SSD1327::setNormalDisplay () {
|
||||
return i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_SET_NORMAL); // set to normal display '1' is ON
|
||||
SSD1327::setNormalDisplay()
|
||||
{
|
||||
return i2Cmd(m_i2c_lcd_control, DISPLAY_CMD_SET_NORMAL); // set to normal display '1' is ON
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
SSD1327::setHorizontalMode () {
|
||||
i2Cmd (m_i2c_lcd_control, 0xA0); // remap to
|
||||
usleep (CMD_SLEEP);
|
||||
i2Cmd (m_i2c_lcd_control, 0x42); // horizontal mode
|
||||
usleep (CMD_SLEEP);
|
||||
SSD1327::setHorizontalMode()
|
||||
{
|
||||
i2Cmd(m_i2c_lcd_control, 0xA0); // remap to
|
||||
usleep(CMD_SLEEP);
|
||||
i2Cmd(m_i2c_lcd_control, 0x42); // horizontal mode
|
||||
usleep(CMD_SLEEP);
|
||||
|
||||
// Row Address
|
||||
i2Cmd (m_i2c_lcd_control, 0x75); // Set Row Address
|
||||
usleep (CMD_SLEEP);
|
||||
i2Cmd (m_i2c_lcd_control, 0x00); // Start 0
|
||||
usleep (CMD_SLEEP);
|
||||
i2Cmd (m_i2c_lcd_control, 0x5f); // End 95
|
||||
usleep (CMD_SLEEP);
|
||||
i2Cmd(m_i2c_lcd_control, 0x75); // Set Row Address
|
||||
usleep(CMD_SLEEP);
|
||||
i2Cmd(m_i2c_lcd_control, 0x00); // Start 0
|
||||
usleep(CMD_SLEEP);
|
||||
i2Cmd(m_i2c_lcd_control, 0x5f); // End 95
|
||||
usleep(CMD_SLEEP);
|
||||
|
||||
// Column Address
|
||||
i2Cmd (m_i2c_lcd_control, 0x15); // Set Column Address
|
||||
usleep (CMD_SLEEP);
|
||||
i2Cmd (m_i2c_lcd_control, 0x08); // Start from 8th Column of driver IC. This is 0th Column for OLED
|
||||
usleep (CMD_SLEEP);
|
||||
i2Cmd (m_i2c_lcd_control, 0x37); // End at (8 + 47)th column. Each Column has 2 pixels(or segments)
|
||||
usleep (CMD_SLEEP);
|
||||
i2Cmd(m_i2c_lcd_control, 0x15); // Set Column Address
|
||||
usleep(CMD_SLEEP);
|
||||
i2Cmd(m_i2c_lcd_control,
|
||||
0x08); // Start from 8th Column of driver IC. This is 0th Column for OLED
|
||||
usleep(CMD_SLEEP);
|
||||
i2Cmd(m_i2c_lcd_control,
|
||||
0x37); // End at (8 + 47)th column. Each Column has 2 pixels(or segments)
|
||||
usleep(CMD_SLEEP);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
SSD1327::setVerticalMode () {
|
||||
i2Cmd (m_i2c_lcd_control, 0xA0); // remap to
|
||||
usleep (CMD_SLEEP);
|
||||
i2Cmd (m_i2c_lcd_control, 0x46); // Vertical mode
|
||||
usleep (CMD_SLEEP);
|
||||
SSD1327::setVerticalMode()
|
||||
{
|
||||
i2Cmd(m_i2c_lcd_control, 0xA0); // remap to
|
||||
usleep(CMD_SLEEP);
|
||||
i2Cmd(m_i2c_lcd_control, 0x46); // Vertical mode
|
||||
usleep(CMD_SLEEP);
|
||||
}
|
||||
|
@ -28,9 +28,9 @@
|
||||
#include "i2clcd.h"
|
||||
#include "ssd.h"
|
||||
|
||||
namespace upm {
|
||||
|
||||
#define DISPLAY_CMD_SET_NORMAL 0xA4
|
||||
namespace upm
|
||||
{
|
||||
#define DISPLAY_CMD_SET_NORMAL 0xA4
|
||||
|
||||
/**
|
||||
* @library i2clcd
|
||||
@ -42,7 +42,7 @@ namespace upm {
|
||||
* @web http://garden.seeedstudio.com/images/8/82/SSD1327_datasheet.pdf
|
||||
* @web http://www.seeedstudio.com/wiki/Grove_-_OLED_Display_1.12%22
|
||||
* @con i2c
|
||||
*
|
||||
*
|
||||
* @brief C++ API for SSD1327 i2c controlled OLED displays
|
||||
*
|
||||
* The SSD1327 is a 96x96 Dot matrix OLED/PLED segment driver with controller.
|
||||
@ -52,71 +52,72 @@ namespace upm {
|
||||
* @image html ssd1327.jpeg
|
||||
* @snippet ssd1327-oled.cxx Interesting
|
||||
*/
|
||||
class SSD1327 : public I2CLcd {
|
||||
public:
|
||||
/**
|
||||
* SSD1327 Constructor, calls libmraa initialisation functions
|
||||
*
|
||||
* @param bus i2c bus to use
|
||||
* @param address the slave address the lcd is registered on
|
||||
*/
|
||||
SSD1327 (int bus, int address=0x3C);
|
||||
/**
|
||||
* SSD1327 destructor
|
||||
*/
|
||||
~SSD1327 ();
|
||||
/**
|
||||
* Draw an image, see examples/python/make_oled_pic.py for an
|
||||
* explanation on how the pixels are mapped to bytes
|
||||
*
|
||||
* @param data the buffer to read
|
||||
* @param bytes the amount of bytes to read from the pointer
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t draw(uint8_t *data, int bytes);
|
||||
/**
|
||||
* Set gray level for LCD panel
|
||||
*
|
||||
* @param gray level from 0-255
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t setGrayLevel (uint8_t level);
|
||||
/**
|
||||
* Write a string to LCD
|
||||
*
|
||||
* @param msg The std::string to write to display, note only ascii
|
||||
* chars are supported
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t write(std::string msg);
|
||||
/**
|
||||
* Set cursor to a coordinate
|
||||
*
|
||||
* @param row The row to set cursor to
|
||||
* @param column The column to set cursor to
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t setCursor(int row, int column);
|
||||
/**
|
||||
* Clear display from characters
|
||||
*
|
||||
* @return Result of operatio
|
||||
*/
|
||||
mraa_result_t clear();
|
||||
/**
|
||||
* Return to coordinate 0,0
|
||||
*
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t home();
|
||||
class SSD1327 : public I2CLcd
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* SSD1327 Constructor, calls libmraa initialisation functions
|
||||
*
|
||||
* @param bus i2c bus to use
|
||||
* @param address the slave address the lcd is registered on
|
||||
*/
|
||||
SSD1327(int bus, int address = 0x3C);
|
||||
/**
|
||||
* SSD1327 destructor
|
||||
*/
|
||||
~SSD1327();
|
||||
/**
|
||||
* Draw an image, see examples/python/make_oled_pic.py for an
|
||||
* explanation on how the pixels are mapped to bytes
|
||||
*
|
||||
* @param data the buffer to read
|
||||
* @param bytes the amount of bytes to read from the pointer
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t draw(uint8_t* data, int bytes);
|
||||
/**
|
||||
* Set gray level for LCD panel
|
||||
*
|
||||
* @param gray level from 0-255
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t setGrayLevel(uint8_t level);
|
||||
/**
|
||||
* Write a string to LCD
|
||||
*
|
||||
* @param msg The std::string to write to display, note only ascii
|
||||
* chars are supported
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t write(std::string msg);
|
||||
/**
|
||||
* Set cursor to a coordinate
|
||||
*
|
||||
* @param row The row to set cursor to
|
||||
* @param column The column to set cursor to
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t setCursor(int row, int column);
|
||||
/**
|
||||
* Clear display from characters
|
||||
*
|
||||
* @return Result of operatio
|
||||
*/
|
||||
mraa_result_t clear();
|
||||
/**
|
||||
* Return to coordinate 0,0
|
||||
*
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t home();
|
||||
|
||||
private:
|
||||
mraa_result_t writeChar (mraa_i2c_context ctx, uint8_t value);
|
||||
mraa_result_t setNormalDisplay ();
|
||||
mraa_result_t setHorizontalMode ();
|
||||
mraa_result_t setVerticalMode ();
|
||||
private:
|
||||
mraa_result_t writeChar(mraa_i2c_context ctx, uint8_t value);
|
||||
mraa_result_t setNormalDisplay();
|
||||
mraa_result_t setHorizontalMode();
|
||||
mraa_result_t setVerticalMode();
|
||||
|
||||
uint8_t grayHigh;
|
||||
uint8_t grayLow;
|
||||
};
|
||||
uint8_t grayHigh;
|
||||
uint8_t grayLow;
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user