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:
Wouter van Verre 2015-04-08 14:06:49 +01:00 committed by Mihai Tudor Panu
parent 3abd3a5ee9
commit bb59d5db7a
11 changed files with 663 additions and 619 deletions

View File

@ -29,7 +29,8 @@
using namespace upm; using namespace upm;
I2CLcd::I2CLcd (int bus, int lcdAddress) { I2CLcd::I2CLcd(int bus, int lcdAddress)
{
m_lcd_control_address = lcdAddress; m_lcd_control_address = lcdAddress;
m_bus = bus; m_bus = bus;
@ -42,13 +43,15 @@ I2CLcd::I2CLcd (int bus, int lcdAddress) {
} }
mraa_result_t mraa_result_t
I2CLcd::write (int row, int column, std::string msg) { I2CLcd::write(int row, int column, std::string msg)
{
setCursor(row, column); setCursor(row, column);
write(msg); write(msg);
} }
mraa_result_t 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; mraa_result_t error = MRAA_SUCCESS;
charSlot &= 0x07; // only have 8 positions we can set charSlot &= 0x07; // only have 8 positions we can set
error = i2Cmd(m_i2c_lcd_control, LCD_SETCGRAMADDR | (charSlot << 3)); error = i2Cmd(m_i2c_lcd_control, LCD_SETCGRAMADDR | (charSlot << 3));
@ -62,12 +65,20 @@ I2CLcd::createChar(uint8_t charSlot, uint8_t charData[]) {
} }
mraa_result_t mraa_result_t
I2CLcd::close() { I2CLcd::close()
{
return mraa_i2c_stop(m_i2c_lcd_control); return mraa_i2c_stop(m_i2c_lcd_control);
} }
std::string
I2CLcd::name()
{
return m_name;
}
mraa_result_t 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; mraa_result_t error = MRAA_SUCCESS;
uint8_t data[2] = { addr, value }; uint8_t data[2] = { addr, value };
@ -78,7 +89,8 @@ I2CLcd::i2cReg (mraa_i2c_context ctx, int deviceAdress, int addr, uint8_t value)
} }
mraa_result_t 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; mraa_result_t error = MRAA_SUCCESS;
uint8_t data[2] = { LCD_CMD, value }; uint8_t data[2] = { LCD_CMD, value };
@ -89,7 +101,8 @@ I2CLcd::i2Cmd (mraa_i2c_context ctx, uint8_t value) {
} }
mraa_result_t 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; mraa_result_t error = MRAA_SUCCESS;
uint8_t data[2] = { LCD_DATA, value }; uint8_t data[2] = { LCD_DATA, value };

View File

@ -26,8 +26,8 @@
#include <string> #include <string>
#include <mraa/i2c.h> #include <mraa/i2c.h>
namespace upm { namespace upm
{
// commands // commands
#define LCD_CLEARDISPLAY 0x01 #define LCD_CLEARDISPLAY 0x01
#define LCD_RETURNHOME 0x02 #define LCD_RETURNHOME 0x02
@ -80,7 +80,8 @@ namespace upm {
* @defgroup i2clcd libupm-i2clcd * @defgroup i2clcd libupm-i2clcd
* @ingroup seeed sparkfun adafruit i2c display gsk * @ingroup seeed sparkfun adafruit i2c display gsk
*/ */
class I2CLcd { class I2CLcd
{
public: public:
I2CLcd(int bus, int lcdAddress); I2CLcd(int bus, int lcdAddress);
mraa_result_t write(int x, int y, std::string msg); mraa_result_t write(int x, int y, std::string msg);
@ -95,15 +96,12 @@ class I2CLcd {
virtual mraa_result_t i2cData(mraa_i2c_context ctx, uint8_t value); virtual mraa_result_t i2cData(mraa_i2c_context ctx, uint8_t value);
mraa_result_t close(); mraa_result_t close();
std::string name() std::string name();
{
return m_name;
}
protected: protected:
std::string m_name; std::string m_name;
int m_lcd_control_address; int m_lcd_control_address;
int m_bus; int m_bus;
mraa_i2c_context m_i2c_lcd_control; mraa_i2c_context m_i2c_lcd_control;
}; };
} }

View File

@ -29,7 +29,8 @@
using namespace upm; 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; mraa_result_t error = MRAA_SUCCESS;
m_rgb_address = rgbAddress; m_rgb_address = rgbAddress;
@ -53,9 +54,7 @@ Jhd1313m1::Jhd1313m1 (int bus, int lcdAddress, int rgbAddress) : I2CLcd(bus, lcd
clear(); clear();
usleep(4500); usleep(4500);
i2Cmd (m_i2c_lcd_control, LCD_ENTRYMODESET | i2Cmd(m_i2c_lcd_control, LCD_ENTRYMODESET | LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT);
LCD_ENTRYLEFT |
LCD_ENTRYSHIFTDECREMENT);
i2cReg(m_i2c_lcd_rgb, m_rgb_address, 0, 0); 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, 1, 0);
@ -66,8 +65,8 @@ Jhd1313m1::Jhd1313m1 (int bus, int lcdAddress, int rgbAddress) : I2CLcd(bus, lcd
i2cReg(m_i2c_lcd_rgb, m_rgb_address, 0x02, 255); i2cReg(m_i2c_lcd_rgb, m_rgb_address, 0x02, 255);
} }
Jhd1313m1::~Jhd1313m1() { Jhd1313m1::~Jhd1313m1()
{
} }
mraa_result_t mraa_result_t
@ -98,7 +97,8 @@ Jhd1313m1::scroll(bool direction)
* ************** * **************
*/ */
mraa_result_t mraa_result_t
Jhd1313m1::write (std::string msg) { Jhd1313m1::write(std::string msg)
{
usleep(1000); usleep(1000);
mraa_result_t error = MRAA_SUCCESS; mraa_result_t error = MRAA_SUCCESS;
for (std::string::size_type i = 0; i < msg.size(); ++i) { for (std::string::size_type i = 0; i < msg.size(); ++i) {
@ -109,7 +109,8 @@ Jhd1313m1::write (std::string msg) {
} }
mraa_result_t mraa_result_t
Jhd1313m1::setCursor (int row, int column) { Jhd1313m1::setCursor(int row, int column)
{
mraa_result_t error = MRAA_SUCCESS; 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]); uint8_t offset = ((column % 16) + row_addr[row]);
@ -119,11 +120,13 @@ Jhd1313m1::setCursor (int row, int column) {
} }
mraa_result_t mraa_result_t
Jhd1313m1::clear () { Jhd1313m1::clear()
{
return i2Cmd(m_i2c_lcd_control, LCD_CLEARDISPLAY); return i2Cmd(m_i2c_lcd_control, LCD_CLEARDISPLAY);
} }
mraa_result_t mraa_result_t
Jhd1313m1::home () { Jhd1313m1::home()
{
return i2Cmd(m_i2c_lcd_control, LCD_RETURNHOME); return i2Cmd(m_i2c_lcd_control, LCD_RETURNHOME);
} }

View File

@ -26,8 +26,8 @@
#include <string> #include <string>
#include "i2clcd.h" #include "i2clcd.h"
namespace upm { namespace upm
{
/** /**
* @library i2clcd * @library i2clcd
* @sensor jhd1313m1 * @sensor jhd1313m1
@ -50,7 +50,8 @@ namespace upm {
* @image html grovergblcd.jpg * @image html grovergblcd.jpg
* @snippet jhd1313m1-lcd.cxx Interesting * @snippet jhd1313m1-lcd.cxx Interesting
*/ */
class Jhd1313m1 : public I2CLcd { class Jhd1313m1 : public I2CLcd
{
public: public:
/** /**
* Jhd1313m1 constructor * Jhd1313m1 constructor
@ -113,5 +114,4 @@ class Jhd1313m1 : public I2CLcd {
int m_rgb_address; int m_rgb_address;
mraa_i2c_context m_i2c_lcd_rgb; mraa_i2c_context m_i2c_lcd_rgb;
}; };
} }

View File

@ -32,7 +32,8 @@
using namespace upm; 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; mraa_result_t error = MRAA_SUCCESS;
usleep(50000); usleep(50000);
@ -60,8 +61,8 @@ Lcm1602::Lcm1602(int bus_in, int addr_in) : I2CLcd (bus_in, addr_in) {
home(); home();
} }
Lcm1602::~Lcm1602 () { Lcm1602::~Lcm1602()
{
} }
/* /*
@ -70,7 +71,8 @@ Lcm1602::~Lcm1602 () {
* ************** * **************
*/ */
mraa_result_t mraa_result_t
Lcm1602::write (std::string msg) { Lcm1602::write(std::string msg)
{
mraa_result_t error = MRAA_SUCCESS; mraa_result_t error = MRAA_SUCCESS;
for (std::string::size_type i = 0; i < msg.size(); ++i) { for (std::string::size_type i = 0; i < msg.size(); ++i) {
error = send(msg[i], LCD_RS); error = send(msg[i], LCD_RS);
@ -79,7 +81,8 @@ Lcm1602::write (std::string msg) {
} }
mraa_result_t mraa_result_t
Lcm1602::setCursor (int row, int column) { Lcm1602::setCursor(int row, int column)
{
mraa_result_t error = MRAA_SUCCESS; mraa_result_t error = MRAA_SUCCESS;
int row_addr[] = { 0x80, 0xc0, 0x14, 0x54 }; int row_addr[] = { 0x80, 0xc0, 0x14, 0x54 };
@ -89,12 +92,14 @@ Lcm1602::setCursor (int row, int column) {
} }
mraa_result_t mraa_result_t
Lcm1602::clear () { Lcm1602::clear()
{
return send(LCD_CLEARDISPLAY, 0); return send(LCD_CLEARDISPLAY, 0);
} }
mraa_result_t mraa_result_t
Lcm1602::home () { Lcm1602::home()
{
return send(LCD_RETURNHOME, 0); return send(LCD_RETURNHOME, 0);
} }
@ -104,7 +109,8 @@ Lcm1602::home () {
* ************** * **************
*/ */
mraa_result_t mraa_result_t
Lcm1602::send (uint8_t value, int mode) { Lcm1602::send(uint8_t value, int mode)
{
mraa_result_t ret = MRAA_SUCCESS; mraa_result_t ret = MRAA_SUCCESS;
uint8_t h = value & 0xf0; uint8_t h = value & 0xf0;
uint8_t l = (value << 4) & 0xf0; uint8_t l = (value << 4) & 0xf0;

View File

@ -30,7 +30,8 @@
#include <string> #include <string>
#include "i2clcd.h" #include "i2clcd.h"
namespace upm { namespace upm
{
/** /**
* @library i2clcd * @library i2clcd
* @sensor lcm1602 * @sensor lcm1602
@ -51,7 +52,8 @@ namespace upm {
* @image html lcm1602.jpeg * @image html lcm1602.jpeg
* @snippet lcm1602-lcd.cxx Interesting * @snippet lcm1602-lcd.cxx Interesting
*/ */
class Lcm1602 : public I2CLcd { class Lcm1602 : public I2CLcd
{
public: public:
/** /**
* Lcm1602 Constructor, calls libmraa initialisation functions * Lcm1602 Constructor, calls libmraa initialisation functions

View File

@ -24,8 +24,8 @@
#pragma once #pragma once
namespace upm { namespace upm
{
#define DISPLAY_CMD_OFF 0xAE #define DISPLAY_CMD_OFF 0xAE
#define DISPLAY_CMD_ON 0xAF #define DISPLAY_CMD_ON 0xAF
@ -34,9 +34,7 @@ namespace upm {
#define BASE_PAGE_START_ADDR 0xB0 #define BASE_PAGE_START_ADDR 0xB0
#define DISPLAY_CMD_MEM_ADDR_MODE 0x20 #define DISPLAY_CMD_MEM_ADDR_MODE 0x20
const uint8_t BasicFont[][8] = const uint8_t BasicFont[][8] = { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
{
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{ 0x00, 0x00, 0x5F, 0x00, 0x00, 0x00, 0x00, 0x00 }, { 0x00, 0x00, 0x5F, 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0x00, 0x00, 0x07, 0x00, 0x07, 0x00, 0x00, 0x00 }, { 0x00, 0x00, 0x07, 0x00, 0x07, 0x00, 0x00, 0x00 },
{ 0x00, 0x14, 0x7F, 0x14, 0x7F, 0x14, 0x00, 0x00 }, { 0x00, 0x14, 0x7F, 0x14, 0x7F, 0x14, 0x00, 0x00 },
@ -131,13 +129,7 @@ const uint8_t BasicFont[][8] =
{ 0x00, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00 }, { 0x00, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0x00, 0x41, 0x36, 0x08, 0x00, 0x00, 0x00, 0x00 }, { 0x00, 0x41, 0x36, 0x08, 0x00, 0x00, 0x00, 0x00 },
{ 0x00, 0x02, 0x01, 0x01, 0x02, 0x01, 0x00, 0x00 }, { 0x00, 0x02, 0x01, 0x01, 0x02, 0x01, 0x00, 0x00 },
{0x00,0x02,0x05,0x05,0x02,0x00,0x00,0x00} { 0x00, 0x02, 0x05, 0x05, 0x02, 0x00, 0x00, 0x00 } };
};
typedef enum {
HORIZONTAL = 0,
VERTICAL = 1,
PAGE = 2
} displayAddressingMode;
typedef enum { HORIZONTAL = 0, VERTICAL = 1, PAGE = 2 } displayAddressingMode;
} }

View File

@ -29,7 +29,8 @@
using namespace upm; using namespace upm;
SSD1308::SSD1308 (int bus_in, int addr_in) : I2CLcd (bus_in, addr_in) { SSD1308::SSD1308(int bus_in, int addr_in) : I2CLcd(bus_in, addr_in)
{
i2Cmd(m_i2c_lcd_control, DISPLAY_CMD_OFF); // display off i2Cmd(m_i2c_lcd_control, DISPLAY_CMD_OFF); // display off
usleep(4500); usleep(4500);
i2Cmd(m_i2c_lcd_control, DISPLAY_CMD_ON); // display on i2Cmd(m_i2c_lcd_control, DISPLAY_CMD_ON); // display on
@ -40,12 +41,13 @@ SSD1308::SSD1308 (int bus_in, int addr_in) : I2CLcd (bus_in, addr_in) {
setAddressingMode(PAGE); setAddressingMode(PAGE);
} }
SSD1308::~SSD1308 () { SSD1308::~SSD1308()
{
} }
mraa_result_t mraa_result_t
SSD1308::draw (uint8_t *data, int bytes) { SSD1308::draw(uint8_t* data, int bytes)
{
mraa_result_t error = MRAA_SUCCESS; mraa_result_t error = MRAA_SUCCESS;
setAddressingMode(HORIZONTAL); setAddressingMode(HORIZONTAL);
@ -62,7 +64,8 @@ SSD1308::draw (uint8_t *data, int bytes) {
* ************** * **************
*/ */
mraa_result_t mraa_result_t
SSD1308::write (std::string msg) { SSD1308::write(std::string msg)
{
mraa_result_t error = MRAA_SUCCESS; mraa_result_t error = MRAA_SUCCESS;
uint8_t data[2] = { 0x40, 0 }; uint8_t data[2] = { 0x40, 0 };
@ -75,18 +78,22 @@ SSD1308::write (std::string msg) {
} }
mraa_result_t mraa_result_t
SSD1308::setCursor (int row, int column) { SSD1308::setCursor(int row, int column)
{
mraa_result_t error = MRAA_SUCCESS; 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_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,
error = i2Cmd (m_i2c_lcd_control, BASE_HIGH_COLUMN_ADDR + ((8 * column >> 4) & 0x0F)); // set column higher address 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; return error;
} }
mraa_result_t mraa_result_t
SSD1308::clear () { SSD1308::clear()
{
mraa_result_t error = MRAA_SUCCESS; mraa_result_t error = MRAA_SUCCESS;
uint8_t columnIdx, rowIdx; uint8_t columnIdx, rowIdx;
@ -106,7 +113,8 @@ SSD1308::clear () {
} }
mraa_result_t mraa_result_t
SSD1308::home () { SSD1308::home()
{
return setCursor(0, 0); return setCursor(0, 0);
} }
@ -116,7 +124,8 @@ SSD1308::home () {
* ************** * **************
*/ */
mraa_result_t 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) { if (value < 0x20 || value > 0x7F) {
value = 0x20; // space value = 0x20; // space
} }
@ -127,12 +136,14 @@ SSD1308::writeChar (mraa_i2c_context ctx, uint8_t value) {
} }
mraa_result_t mraa_result_t
SSD1308::setNormalDisplay () { SSD1308::setNormalDisplay()
{
return i2Cmd(m_i2c_lcd_control, DISPLAY_CMD_SET_NORMAL_1308); // set to normal display '1' is ON return i2Cmd(m_i2c_lcd_control, DISPLAY_CMD_SET_NORMAL_1308); // set to normal display '1' is ON
} }
mraa_result_t mraa_result_t
SSD1308::setAddressingMode (displayAddressingMode mode) { SSD1308::setAddressingMode(displayAddressingMode mode)
{
i2Cmd(m_i2c_lcd_control, DISPLAY_CMD_MEM_ADDR_MODE); // set addressing mode i2Cmd(m_i2c_lcd_control, DISPLAY_CMD_MEM_ADDR_MODE); // set addressing mode
i2Cmd(m_i2c_lcd_control, mode); // set page addressing mode i2Cmd(m_i2c_lcd_control, mode); // set page addressing mode
} }

View File

@ -28,8 +28,8 @@
#include "i2clcd.h" #include "i2clcd.h"
#include "ssd.h" #include "ssd.h"
namespace upm { namespace upm
{
#define DISPLAY_CMD_SET_NORMAL_1308 0xA6 #define DISPLAY_CMD_SET_NORMAL_1308 0xA6
/** /**
@ -52,7 +52,8 @@ namespace upm {
* @image html ssd1308.jpeg * @image html ssd1308.jpeg
* @snippet ssd1308-oled.cxx Interesting * @snippet ssd1308-oled.cxx Interesting
*/ */
class SSD1308 : public I2CLcd { class SSD1308 : public I2CLcd
{
public: public:
/** /**
* SSD1308 Constructor, calls libmraa initialisation functions * SSD1308 Constructor, calls libmraa initialisation functions
@ -102,6 +103,7 @@ class SSD1308 : public I2CLcd {
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t home(); mraa_result_t home();
private: private:
mraa_result_t writeChar(mraa_i2c_context ctx, uint8_t value); mraa_result_t writeChar(mraa_i2c_context ctx, uint8_t value);
mraa_result_t setNormalDisplay(); mraa_result_t setNormalDisplay();

View File

@ -32,10 +32,12 @@ using namespace upm;
#define INIT_SLEEP 50000 #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) { SSD1327::SSD1327(int bus_in, int addr_in) : I2CLcd(bus_in, addr_in)
{
mraa_result_t error = MRAA_SUCCESS; mraa_result_t error = MRAA_SUCCESS;
usleep(INIT_SLEEP); usleep(INIT_SLEEP);
i2Cmd (m_i2c_lcd_control, 0xFD); // Unlock OLED driver IC MCU interface from entering command. i.e: Accept commands i2Cmd(m_i2c_lcd_control,
0xFD); // Unlock OLED driver IC MCU interface from entering command. i.e: Accept commands
usleep(INIT_SLEEP); usleep(INIT_SLEEP);
i2Cmd(m_i2c_lcd_control, 0x12); i2Cmd(m_i2c_lcd_control, 0x12);
usleep(INIT_SLEEP); usleep(INIT_SLEEP);
@ -109,9 +111,11 @@ SSD1327::SSD1327 (int bus_in, int addr_in) : I2CLcd (bus_in, addr_in) {
// Column Address // Column Address
error = i2Cmd(m_i2c_lcd_control, 0x15); // Set Column Address error = i2Cmd(m_i2c_lcd_control, 0x15); // Set Column Address
usleep(INIT_SLEEP); usleep(INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x08); // Start from 8th Column of driver IC. This is 0th Column for OLED error = i2Cmd(m_i2c_lcd_control,
0x08); // Start from 8th Column of driver IC. This is 0th Column for OLED
usleep(INIT_SLEEP); usleep(INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x37); // End at (8 + 47)th column. Each Column has 2 pixels(segments) error = i2Cmd(m_i2c_lcd_control, 0x37); // End at (8 + 47)th column. Each Column has 2
// pixels(segments)
usleep(INIT_SLEEP); usleep(INIT_SLEEP);
clear(); clear();
@ -119,12 +123,13 @@ SSD1327::SSD1327 (int bus_in, int addr_in) : I2CLcd (bus_in, addr_in) {
setVerticalMode(); setVerticalMode();
} }
SSD1327::~SSD1327 () { SSD1327::~SSD1327()
{
} }
mraa_result_t mraa_result_t
SSD1327::draw (uint8_t *data, int bytes) { SSD1327::draw(uint8_t* data, int bytes)
{
mraa_result_t error = MRAA_SUCCESS; mraa_result_t error = MRAA_SUCCESS;
setHorizontalMode(); setHorizontalMode();
@ -152,7 +157,8 @@ SSD1327::draw (uint8_t *data, int bytes) {
* ************** * **************
*/ */
mraa_result_t mraa_result_t
SSD1327::write (std::string msg) { SSD1327::write(std::string msg)
{
mraa_result_t error = MRAA_SUCCESS; mraa_result_t error = MRAA_SUCCESS;
setVerticalMode(); setVerticalMode();
@ -164,7 +170,8 @@ SSD1327::write (std::string msg) {
} }
mraa_result_t mraa_result_t
SSD1327::setCursor (int row, int column) { SSD1327::setCursor(int row, int column)
{
mraa_result_t error = MRAA_SUCCESS; mraa_result_t error = MRAA_SUCCESS;
// Column Address // Column Address
@ -186,7 +193,8 @@ SSD1327::setCursor (int row, int column) {
} }
mraa_result_t mraa_result_t
SSD1327::clear () { SSD1327::clear()
{
mraa_result_t error = MRAA_SUCCESS; mraa_result_t error = MRAA_SUCCESS;
uint8_t columnIdx, rowIdx; uint8_t columnIdx, rowIdx;
@ -201,12 +209,14 @@ SSD1327::clear () {
} }
mraa_result_t mraa_result_t
SSD1327::home () { SSD1327::home()
{
return setCursor(0, 0); return setCursor(0, 0);
} }
mraa_result_t mraa_result_t
SSD1327::setGrayLevel (uint8_t level) { SSD1327::setGrayLevel(uint8_t level)
{
grayHigh = (level << 4) & 0xF0; grayHigh = (level << 4) & 0xF0;
grayLow = level & 0x0F; grayLow = level & 0x0F;
} }
@ -217,7 +227,8 @@ SSD1327::setGrayLevel (uint8_t level) {
* ************** * **************
*/ */
mraa_result_t 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) { if (value < 0x20 || value > 0x7F) {
value = 0x20; // space value = 0x20; // space
} }
@ -239,12 +250,14 @@ SSD1327::writeChar (mraa_i2c_context ctx, uint8_t value) {
} }
mraa_result_t mraa_result_t
SSD1327::setNormalDisplay () { SSD1327::setNormalDisplay()
{
return i2Cmd(m_i2c_lcd_control, DISPLAY_CMD_SET_NORMAL); // set to normal display '1' is ON return i2Cmd(m_i2c_lcd_control, DISPLAY_CMD_SET_NORMAL); // set to normal display '1' is ON
} }
mraa_result_t mraa_result_t
SSD1327::setHorizontalMode () { SSD1327::setHorizontalMode()
{
i2Cmd(m_i2c_lcd_control, 0xA0); // remap to i2Cmd(m_i2c_lcd_control, 0xA0); // remap to
usleep(CMD_SLEEP); usleep(CMD_SLEEP);
i2Cmd(m_i2c_lcd_control, 0x42); // horizontal mode i2Cmd(m_i2c_lcd_control, 0x42); // horizontal mode
@ -261,14 +274,17 @@ SSD1327::setHorizontalMode () {
// Column Address // Column Address
i2Cmd(m_i2c_lcd_control, 0x15); // Set Column Address i2Cmd(m_i2c_lcd_control, 0x15); // Set Column Address
usleep(CMD_SLEEP); usleep(CMD_SLEEP);
i2Cmd (m_i2c_lcd_control, 0x08); // Start from 8th Column of driver IC. This is 0th Column for OLED i2Cmd(m_i2c_lcd_control,
0x08); // Start from 8th Column of driver IC. This is 0th Column for OLED
usleep(CMD_SLEEP); usleep(CMD_SLEEP);
i2Cmd (m_i2c_lcd_control, 0x37); // End at (8 + 47)th column. Each Column has 2 pixels(or segments) i2Cmd(m_i2c_lcd_control,
0x37); // End at (8 + 47)th column. Each Column has 2 pixels(or segments)
usleep(CMD_SLEEP); usleep(CMD_SLEEP);
} }
mraa_result_t mraa_result_t
SSD1327::setVerticalMode () { SSD1327::setVerticalMode()
{
i2Cmd(m_i2c_lcd_control, 0xA0); // remap to i2Cmd(m_i2c_lcd_control, 0xA0); // remap to
usleep(CMD_SLEEP); usleep(CMD_SLEEP);
i2Cmd(m_i2c_lcd_control, 0x46); // Vertical mode i2Cmd(m_i2c_lcd_control, 0x46); // Vertical mode

View File

@ -28,8 +28,8 @@
#include "i2clcd.h" #include "i2clcd.h"
#include "ssd.h" #include "ssd.h"
namespace upm { namespace upm
{
#define DISPLAY_CMD_SET_NORMAL 0xA4 #define DISPLAY_CMD_SET_NORMAL 0xA4
/** /**
@ -52,7 +52,8 @@ namespace upm {
* @image html ssd1327.jpeg * @image html ssd1327.jpeg
* @snippet ssd1327-oled.cxx Interesting * @snippet ssd1327-oled.cxx Interesting
*/ */
class SSD1327 : public I2CLcd { class SSD1327 : public I2CLcd
{
public: public:
/** /**
* SSD1327 Constructor, calls libmraa initialisation functions * SSD1327 Constructor, calls libmraa initialisation functions