mirror of
https://github.com/eclipse/upm.git
synced 2025-03-24 01:10:22 +03:00
ssd1306: updated to C++ types and new exceptions, fixed repeated call to i2cfrequency
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
parent
3159005aa3
commit
4e70ed4973
@ -44,11 +44,19 @@ SSD1306::SSD1306(int bus_in, int addr_in) : m_i2c_lcd_control(bus_in)
|
|||||||
m_lcd_control_address = addr_in;
|
m_lcd_control_address = addr_in;
|
||||||
m_name = "SSD1306";
|
m_name = "SSD1306";
|
||||||
|
|
||||||
mraa_result_t error = m_i2c_lcd_control.address(m_lcd_control_address);
|
mraa::Result error = m_i2c_lcd_control.address(m_lcd_control_address);
|
||||||
m_i2c_lcd_control.frequency(MRAA_I2C_FAST);
|
|
||||||
|
if (error != mraa::SUCCESS) {
|
||||||
if (error != mraa_SUCCESS) {
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
fprintf(stderr, "Failed to initialize i2c bus\n");
|
": mraa_i2c_address() failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
error = m_i2c_lcd_control.frequency(mraa::I2C_FAST);
|
||||||
|
|
||||||
|
if (error != mraa::SUCCESS) {
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": mraa_i2c_frequency(MRAA_I2C_FAST) failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,11 +113,10 @@ SSD1306::~SSD1306()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
mraa_result_t
|
mraa::Result
|
||||||
SSD1306::draw(uint8_t* data, int bytes)
|
SSD1306::draw(uint8_t* data, int bytes)
|
||||||
{
|
{
|
||||||
m_i2c_lcd_control.frequency(MRAA_I2C_FAST);
|
mraa::Result error = mraa::SUCCESS;
|
||||||
mraa_result_t error = mraa_SUCCESS;
|
|
||||||
|
|
||||||
setAddressingMode(HORIZONTAL);
|
setAddressingMode(HORIZONTAL);
|
||||||
for (int idx = 0; idx < bytes; idx++) {
|
for (int idx = 0; idx < bytes; idx++) {
|
||||||
@ -124,11 +131,10 @@ SSD1306::draw(uint8_t* data, int bytes)
|
|||||||
* virtual area
|
* virtual area
|
||||||
* **************
|
* **************
|
||||||
*/
|
*/
|
||||||
mraa_result_t
|
mraa::Result
|
||||||
SSD1306::write(std::string msg)
|
SSD1306::write(std::string msg)
|
||||||
{
|
{
|
||||||
m_i2c_lcd_control.frequency(MRAA_I2C_FAST);
|
mraa::Result error = mraa::SUCCESS;
|
||||||
mraa_result_t error = mraa_SUCCESS;
|
|
||||||
|
|
||||||
setAddressingMode(PAGE);
|
setAddressingMode(PAGE);
|
||||||
for (std::string::size_type i = 0; i < msg.size(); ++i) {
|
for (std::string::size_type i = 0; i < msg.size(); ++i) {
|
||||||
@ -138,11 +144,10 @@ SSD1306::write(std::string msg)
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
mraa_result_t
|
mraa::Result
|
||||||
SSD1306::setCursor(int row, int column)
|
SSD1306::setCursor(int row, int column)
|
||||||
{
|
{
|
||||||
m_i2c_lcd_control.frequency(MRAA_I2C_FAST);
|
mraa::Result error = mraa::SUCCESS;
|
||||||
mraa_result_t error = mraa_SUCCESS;
|
|
||||||
|
|
||||||
error = m_i2c_lcd_control.writeReg(LCD_CMD, BASE_PAGE_START_ADDR + row); // set page address
|
error = m_i2c_lcd_control.writeReg(LCD_CMD, BASE_PAGE_START_ADDR + row); // set page address
|
||||||
error = m_i2c_lcd_control.writeReg(LCD_CMD,
|
error = m_i2c_lcd_control.writeReg(LCD_CMD,
|
||||||
@ -155,11 +160,10 @@ SSD1306::setCursor(int row, int column)
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
mraa_result_t
|
mraa::Result
|
||||||
SSD1306::clear()
|
SSD1306::clear()
|
||||||
{
|
{
|
||||||
m_i2c_lcd_control.frequency(MRAA_I2C_FAST);
|
mraa::Result error = mraa::SUCCESS;
|
||||||
mraa_result_t error = mraa_SUCCESS;
|
|
||||||
uint8_t columnIdx, rowIdx;
|
uint8_t columnIdx, rowIdx;
|
||||||
|
|
||||||
m_i2c_lcd_control.writeReg(LCD_CMD, DISPLAY_CMD_OFF); // display off
|
m_i2c_lcd_control.writeReg(LCD_CMD, DISPLAY_CMD_OFF); // display off
|
||||||
@ -177,10 +181,9 @@ SSD1306::clear()
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
mraa_result_t
|
mraa::Result
|
||||||
SSD1306::home()
|
SSD1306::home()
|
||||||
{
|
{
|
||||||
m_i2c_lcd_control.frequency(MRAA_I2C_FAST);
|
|
||||||
return setCursor(0, 0);
|
return setCursor(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,11 +192,10 @@ SSD1306::home()
|
|||||||
* private area
|
* private area
|
||||||
* **************
|
* **************
|
||||||
*/
|
*/
|
||||||
mraa_result_t
|
mraa::Result
|
||||||
SSD1306::writeChar(uint8_t value)
|
SSD1306::writeChar(uint8_t value)
|
||||||
{
|
{
|
||||||
m_i2c_lcd_control.frequency(MRAA_I2C_FAST);
|
mraa::Result rv;
|
||||||
mraa_result_t rv;
|
|
||||||
if (value < 0x20 || value > 0x7F) {
|
if (value < 0x20 || value > 0x7F) {
|
||||||
value = 0x20; // space
|
value = 0x20; // space
|
||||||
}
|
}
|
||||||
@ -205,31 +207,28 @@ SSD1306::writeChar(uint8_t value)
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
mraa_result_t
|
mraa::Result
|
||||||
SSD1306::setNormalDisplay()
|
SSD1306::setNormalDisplay()
|
||||||
{
|
{
|
||||||
m_i2c_lcd_control.frequency(MRAA_I2C_FAST);
|
|
||||||
return m_i2c_lcd_control.writeReg(LCD_CMD,
|
return m_i2c_lcd_control.writeReg(LCD_CMD,
|
||||||
DISPLAY_CMD_SET_NORMAL_1306); // set to normal display '1' is
|
DISPLAY_CMD_SET_NORMAL_1306); // set to normal display '1' is
|
||||||
// ON
|
// ON
|
||||||
}
|
}
|
||||||
|
|
||||||
mraa_result_t
|
mraa::Result
|
||||||
SSD1306::setAddressingMode(displayAddressingMode mode)
|
SSD1306::setAddressingMode(displayAddressingMode mode)
|
||||||
{
|
{
|
||||||
m_i2c_lcd_control.frequency(MRAA_I2C_FAST);
|
mraa::Result rv;
|
||||||
mraa_result_t rv;
|
|
||||||
rv =m_i2c_lcd_control.writeReg(LCD_CMD, DISPLAY_CMD_MEM_ADDR_MODE); // set addressing mode
|
rv =m_i2c_lcd_control.writeReg(LCD_CMD, DISPLAY_CMD_MEM_ADDR_MODE); // set addressing mode
|
||||||
rv =m_i2c_lcd_control.writeReg(LCD_CMD, mode); // set page addressing mode
|
rv =m_i2c_lcd_control.writeReg(LCD_CMD, mode); // set page addressing mode
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mraa_result_t
|
mraa::Result
|
||||||
SSD1306::invert(bool i)
|
SSD1306::invert(bool i)
|
||||||
{
|
{
|
||||||
m_i2c_lcd_control.frequency(MRAA_I2C_FAST);
|
mraa::Result rv;
|
||||||
mraa_result_t rv;
|
|
||||||
if(i){
|
if(i){
|
||||||
rv = m_i2c_lcd_control.writeReg(LCD_CMD, DISPLAY_CMD_SET_INVERT_1306);
|
rv = m_i2c_lcd_control.writeReg(LCD_CMD, DISPLAY_CMD_SET_INVERT_1306);
|
||||||
} else {
|
} else {
|
||||||
@ -240,7 +239,6 @@ SSD1306::invert(bool i)
|
|||||||
|
|
||||||
|
|
||||||
void SSD1306::startscrollright(uint8_t start, uint8_t stop){
|
void SSD1306::startscrollright(uint8_t start, uint8_t stop){
|
||||||
m_i2c_lcd_control.frequency(MRAA_I2C_FAST);
|
|
||||||
m_i2c_lcd_control.writeReg(LCD_CMD,SSD1306_RIGHT_HORIZONTAL_SCROLL);
|
m_i2c_lcd_control.writeReg(LCD_CMD,SSD1306_RIGHT_HORIZONTAL_SCROLL);
|
||||||
m_i2c_lcd_control.writeReg(LCD_CMD,0X00);
|
m_i2c_lcd_control.writeReg(LCD_CMD,0X00);
|
||||||
m_i2c_lcd_control.writeReg(LCD_CMD,start);
|
m_i2c_lcd_control.writeReg(LCD_CMD,start);
|
||||||
@ -253,7 +251,6 @@ void SSD1306::startscrollright(uint8_t start, uint8_t stop){
|
|||||||
|
|
||||||
|
|
||||||
void SSD1306::startscrollleft(uint8_t start, uint8_t stop){
|
void SSD1306::startscrollleft(uint8_t start, uint8_t stop){
|
||||||
m_i2c_lcd_control.frequency(MRAA_I2C_FAST);
|
|
||||||
m_i2c_lcd_control.writeReg(LCD_CMD,SSD1306_LEFT_HORIZONTAL_SCROLL);
|
m_i2c_lcd_control.writeReg(LCD_CMD,SSD1306_LEFT_HORIZONTAL_SCROLL);
|
||||||
m_i2c_lcd_control.writeReg(LCD_CMD,0X00);
|
m_i2c_lcd_control.writeReg(LCD_CMD,0X00);
|
||||||
m_i2c_lcd_control.writeReg(LCD_CMD,start);
|
m_i2c_lcd_control.writeReg(LCD_CMD,start);
|
||||||
@ -265,7 +262,6 @@ void SSD1306::startscrollleft(uint8_t start, uint8_t stop){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SSD1306::startscrolldiagright(uint8_t start, uint8_t stop){
|
void SSD1306::startscrolldiagright(uint8_t start, uint8_t stop){
|
||||||
m_i2c_lcd_control.frequency(MRAA_I2C_FAST);
|
|
||||||
m_i2c_lcd_control.writeReg(LCD_CMD, SSD1306_SET_VERTICAL_SCROLL_AREA);
|
m_i2c_lcd_control.writeReg(LCD_CMD, SSD1306_SET_VERTICAL_SCROLL_AREA);
|
||||||
m_i2c_lcd_control.writeReg(LCD_CMD, 0X00);
|
m_i2c_lcd_control.writeReg(LCD_CMD, 0X00);
|
||||||
m_i2c_lcd_control.writeReg(LCD_CMD, SSD1306_LCDHEIGHT);
|
m_i2c_lcd_control.writeReg(LCD_CMD, SSD1306_LCDHEIGHT);
|
||||||
@ -279,7 +275,6 @@ void SSD1306::startscrolldiagright(uint8_t start, uint8_t stop){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SSD1306::startscrolldiagleft(uint8_t start, uint8_t stop){
|
void SSD1306::startscrolldiagleft(uint8_t start, uint8_t stop){
|
||||||
m_i2c_lcd_control.frequency(MRAA_I2C_FAST);
|
|
||||||
m_i2c_lcd_control.writeReg(LCD_CMD, SSD1306_SET_VERTICAL_SCROLL_AREA);
|
m_i2c_lcd_control.writeReg(LCD_CMD, SSD1306_SET_VERTICAL_SCROLL_AREA);
|
||||||
m_i2c_lcd_control.writeReg(LCD_CMD, 0X00);
|
m_i2c_lcd_control.writeReg(LCD_CMD, 0X00);
|
||||||
m_i2c_lcd_control.writeReg(LCD_CMD, SSD1306_LCDHEIGHT);
|
m_i2c_lcd_control.writeReg(LCD_CMD, SSD1306_LCDHEIGHT);
|
||||||
@ -293,7 +288,6 @@ void SSD1306::startscrolldiagleft(uint8_t start, uint8_t stop){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SSD1306::stopscroll(void){
|
void SSD1306::stopscroll(void){
|
||||||
m_i2c_lcd_control.frequency(MRAA_I2C_FAST);
|
|
||||||
m_i2c_lcd_control.writeReg(LCD_CMD,SSD1306_DEACTIVATE_SCROLL);
|
m_i2c_lcd_control.writeReg(LCD_CMD,SSD1306_DEACTIVATE_SCROLL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,7 +295,6 @@ void SSD1306::stopscroll(void){
|
|||||||
// dim = true: display is dimmed
|
// dim = true: display is dimmed
|
||||||
// dim = false: display is normal
|
// dim = false: display is normal
|
||||||
void SSD1306::dim(bool dim) {
|
void SSD1306::dim(bool dim) {
|
||||||
m_i2c_lcd_control.frequency(MRAA_I2C_FAST);
|
|
||||||
uint8_t contrast;
|
uint8_t contrast;
|
||||||
|
|
||||||
if (dim) {
|
if (dim) {
|
||||||
|
@ -127,7 +127,7 @@ class SSD1306 : public LCD
|
|||||||
* @param bytes Number of bytes to read from the pointer
|
* @param bytes Number of bytes to read from the pointer
|
||||||
* @return Result of the operation
|
* @return Result of the operation
|
||||||
*/
|
*/
|
||||||
mraa_result_t draw(uint8_t* data, int bytes);
|
mraa::Result draw(uint8_t* data, int bytes);
|
||||||
/**
|
/**
|
||||||
* Writes a string to the LCD
|
* Writes a string to the LCD
|
||||||
*
|
*
|
||||||
@ -135,7 +135,7 @@ class SSD1306 : public LCD
|
|||||||
* characters are supported
|
* characters are supported
|
||||||
* @return Result of the operation
|
* @return Result of the operation
|
||||||
*/
|
*/
|
||||||
mraa_result_t write(std::string msg);
|
mraa::Result write(std::string msg);
|
||||||
/**
|
/**
|
||||||
* Sets the cursor to specified coordinates
|
* Sets the cursor to specified coordinates
|
||||||
*
|
*
|
||||||
@ -143,26 +143,26 @@ class SSD1306 : public LCD
|
|||||||
* @param column Column to set the cursor to
|
* @param column Column to set the cursor to
|
||||||
* @return Result of the operation
|
* @return Result of the operation
|
||||||
*/
|
*/
|
||||||
mraa_result_t setCursor(int row, int column);
|
mraa::Result setCursor(int row, int column);
|
||||||
/**
|
/**
|
||||||
* Clears the display of all characters
|
* Clears the display of all characters
|
||||||
*
|
*
|
||||||
* @return Result of the operation
|
* @return Result of the operation
|
||||||
*/
|
*/
|
||||||
mraa_result_t clear();
|
mraa::Result clear();
|
||||||
/**
|
/**
|
||||||
* Returns to the original coordinates (0,0)
|
* Returns to the original coordinates (0,0)
|
||||||
*
|
*
|
||||||
* @return Result of the operation
|
* @return Result of the operation
|
||||||
*/
|
*/
|
||||||
mraa_result_t home();
|
mraa::Result home();
|
||||||
/**
|
/**
|
||||||
* Inverts the display
|
* Inverts the display
|
||||||
*
|
*
|
||||||
* @param i true to invert, false for normal display
|
* @param i true to invert, false for normal display
|
||||||
* @return Result of the operation
|
* @return Result of the operation
|
||||||
*/
|
*/
|
||||||
mraa_result_t invert(bool i);
|
mraa::Result invert(bool i);
|
||||||
/**
|
/**
|
||||||
* Activate a scroll to the right for rows start through stop
|
* Activate a scroll to the right for rows start through stop
|
||||||
* The display is 16 rows tall. To scroll the whole display, run:
|
* The display is 16 rows tall. To scroll the whole display, run:
|
||||||
@ -218,9 +218,9 @@ class SSD1306 : public LCD
|
|||||||
void dim(bool dim);
|
void dim(bool dim);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mraa_result_t writeChar(uint8_t value);
|
mraa::Result writeChar(uint8_t value);
|
||||||
mraa_result_t setNormalDisplay();
|
mraa::Result setNormalDisplay();
|
||||||
mraa_result_t setAddressingMode(displayAddressingMode mode);
|
mraa::Result setAddressingMode(displayAddressingMode mode);
|
||||||
|
|
||||||
int m_lcd_control_address;
|
int m_lcd_control_address;
|
||||||
mraa::I2c m_i2c_lcd_control;
|
mraa::I2c m_i2c_lcd_control;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user