mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
lcm1602: added backlight control and default bus/address for I2C variants
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
parent
3eda1bce16
commit
de986764d4
@ -50,6 +50,7 @@ Lcm1602::Lcm1602(int bus_in, int addr_in, bool isExpander,
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
m_name = "Lcm1602 (I2C)";
|
||||
m_isI2C = true;
|
||||
m_backlight = LCD_BACKLIGHT;
|
||||
|
||||
m_lcd_control_address = addr_in;
|
||||
|
||||
@ -73,7 +74,7 @@ Lcm1602::Lcm1602(int bus_in, int addr_in, bool isExpander,
|
||||
return;
|
||||
|
||||
usleep(50000);
|
||||
expandWrite(LCD_BACKLIGHT);
|
||||
backlightOn();
|
||||
usleep(100000);
|
||||
|
||||
write4bits(0x03 << 4);
|
||||
@ -111,6 +112,7 @@ Lcm1602::Lcm1602(uint8_t rs, uint8_t enable, uint8_t d0,
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
m_name = "Lcm1602 (4-bit GPIO)";
|
||||
m_isI2C = false;
|
||||
m_backlight = LCD_BACKLIGHT;
|
||||
|
||||
// setup our gpios
|
||||
|
||||
@ -322,6 +324,18 @@ mraa::Result Lcm1602::cursorBlinkOff()
|
||||
return command(LCD_DISPLAYCONTROL | m_displayControl);
|
||||
}
|
||||
|
||||
mraa::Result Lcm1602::backlightOn()
|
||||
{
|
||||
m_backlight = LCD_BACKLIGHT;
|
||||
return expandWrite(m_backlight);
|
||||
}
|
||||
|
||||
mraa::Result Lcm1602::backlightOff()
|
||||
{
|
||||
m_backlight = LCD_NOBACKLIGHT;
|
||||
return expandWrite(m_backlight);
|
||||
}
|
||||
|
||||
mraa::Result Lcm1602::scrollDisplayLeft()
|
||||
{
|
||||
return command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT);
|
||||
@ -431,7 +445,7 @@ Lcm1602::expandWrite(uint8_t value)
|
||||
if (!m_isI2C)
|
||||
return mraa::ERROR_INVALID_RESOURCE;
|
||||
|
||||
uint8_t buffer = value | LCD_BACKLIGHT;
|
||||
uint8_t buffer = value | m_backlight;
|
||||
return m_i2c_lcd_control->writeByte(buffer);
|
||||
}
|
||||
|
||||
|
@ -73,13 +73,15 @@ class Lcm1602 : public LCD
|
||||
/**
|
||||
* Lcm1602 constructor; calls libmraa initialisation functions
|
||||
*
|
||||
* @param bus I2C bus to use
|
||||
* @param address Slave address the LCD is registered on
|
||||
* @param bus I2C bus to use. Default 0 (autodetect).
|
||||
* @param address Slave address the LCD is registered on. Default 0x27
|
||||
* @param isExpander True if we are dealing with an I2C expander,
|
||||
* false otherwise. Default is true.
|
||||
* @param numColumns Number of columns the display has. Default 16.
|
||||
* @param numRows Number of rows the display has. Default 2.
|
||||
*/
|
||||
Lcm1602(int bus, int address, bool isExpander=true,
|
||||
uint8_t numColumns = 16, uint8_t numRows = 4);
|
||||
Lcm1602(int bus = 0, int address = 0x27, bool isExpander=true,
|
||||
uint8_t numColumns = 16, uint8_t numRows = 2);
|
||||
|
||||
/**
|
||||
* Lcm1602 alternate constructor, used for GPIO based HD44780
|
||||
@ -92,10 +94,12 @@ class Lcm1602 : public LCD
|
||||
* @param d1 Data 1 pin
|
||||
* @param d2 Data 2 pin
|
||||
* @param d3 Data 3 pin
|
||||
* @param numColumns Number of columns the display has. Default 16.
|
||||
* @param numRows Number of rows the display has. Default 2.
|
||||
*/
|
||||
Lcm1602(uint8_t rs, uint8_t enable,
|
||||
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
|
||||
uint8_t numColumns = 16, uint8_t numRows = 4);
|
||||
uint8_t numColumns = 16, uint8_t numRows = 2);
|
||||
|
||||
/**
|
||||
* Lcm1602 destructor
|
||||
@ -181,6 +185,20 @@ class Lcm1602 : public LCD
|
||||
*/
|
||||
mraa::Result cursorBlinkOff();
|
||||
|
||||
/**
|
||||
* Turn backlight on
|
||||
*
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa::Result backlightOn();
|
||||
|
||||
/**
|
||||
* Turn backlight off
|
||||
*
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa::Result backlightOff();
|
||||
|
||||
/**
|
||||
* Scroll the display left, without changing the character RAM
|
||||
*
|
||||
@ -236,6 +254,9 @@ class Lcm1602 : public LCD
|
||||
// Display size
|
||||
uint8_t m_numColumns;
|
||||
uint8_t m_numRows;
|
||||
|
||||
// Backlight
|
||||
uint8_t m_backlight;
|
||||
|
||||
// Add a command() and data() virtual member functions, with a
|
||||
// default implementation in lcm1602. This is expected to be
|
||||
|
Loading…
x
Reference in New Issue
Block a user