mirror of
				https://github.com/eclipse/upm.git
				synced 2025-10-31 15:15:07 +03:00 
			
		
		
		
	lcd: changed the OOO generalisation.
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
This commit is contained in:
		| @@ -51,3 +51,36 @@ maa_result_t | |||||||
| IICLcd::close() { | IICLcd::close() { | ||||||
|     return maa_i2c_stop(m_i2c_lcd_control); |     return maa_i2c_stop(m_i2c_lcd_control); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | maa_result_t | ||||||
|  | IICLcd::i2cReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t value) { | ||||||
|  |     maa_result_t error = MAA_SUCCESS; | ||||||
|  |  | ||||||
|  |     uint8_t data[2] = { addr, value }; | ||||||
|  |     error = maa_i2c_address (ctx, deviceAdress); | ||||||
|  |     error = maa_i2c_write (ctx, data, 2); | ||||||
|  |  | ||||||
|  |     return error; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | maa_result_t | ||||||
|  | IICLcd::i2Cmd (maa_i2c_context ctx, uint8_t value) { | ||||||
|  |     maa_result_t error = MAA_SUCCESS; | ||||||
|  |  | ||||||
|  |     uint8_t data[2] = { LCD_CMD, value }; | ||||||
|  |     error = maa_i2c_address (ctx, m_lcd_control_address); | ||||||
|  |     error = maa_i2c_write (ctx, data, 2); | ||||||
|  |  | ||||||
|  |     return error; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | maa_result_t | ||||||
|  | IICLcd::i2cData (maa_i2c_context ctx, uint8_t value) { | ||||||
|  |     maa_result_t error = MAA_SUCCESS; | ||||||
|  |  | ||||||
|  |     uint8_t data[2] = { LCD_DATA, value }; | ||||||
|  |     error = maa_i2c_address (ctx, m_lcd_control_address); | ||||||
|  |     error = maa_i2c_write (ctx, data, 2); | ||||||
|  |  | ||||||
|  |     return error; | ||||||
|  | } | ||||||
|   | |||||||
| @@ -35,8 +35,8 @@ namespace upm { | |||||||
| #define LCD_DISPLAYCONTROL 0x08 | #define LCD_DISPLAYCONTROL 0x08 | ||||||
| #define LCD_CURSORSHIFT 0x10 | #define LCD_CURSORSHIFT 0x10 | ||||||
| #define LCD_FUNCTIONSET 0x20 | #define LCD_FUNCTIONSET 0x20 | ||||||
| #define LCD_SETCGRAMADDR 0x40 | #define LCD_DATA 0x40 | ||||||
| #define LCD_SETDDRAMADDR 0x80 | #define LCD_CMD 0x80 | ||||||
|  |  | ||||||
| #define LCD_BACKLIGHT 0x08 | #define LCD_BACKLIGHT 0x08 | ||||||
| #define LCD_NOBACKLIGHT 0x00 | #define LCD_NOBACKLIGHT 0x00 | ||||||
| @@ -70,11 +70,16 @@ namespace upm { | |||||||
| class IICLcd { | class IICLcd { | ||||||
|     public: |     public: | ||||||
|         IICLcd (int bus, int lcdAddress); |         IICLcd (int bus, int lcdAddress); | ||||||
|         virtual maa_result_t write (std::string msg) = 0; |  | ||||||
|         maa_result_t write (int x, int y, std::string msg); |         maa_result_t write (int x, int y, std::string msg); | ||||||
|  |          | ||||||
|  |         virtual maa_result_t write (std::string msg) = 0; | ||||||
|         virtual maa_result_t setCursor (int row, int column) = 0; |         virtual maa_result_t setCursor (int row, int column) = 0; | ||||||
|         virtual maa_result_t clear () = 0; |         virtual maa_result_t clear () = 0; | ||||||
|         virtual maa_result_t home () = 0; |         virtual maa_result_t home () = 0; | ||||||
|  |         virtual maa_result_t i2Cmd (maa_i2c_context ctx, uint8_t value); | ||||||
|  |         virtual maa_result_t i2cReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t data); | ||||||
|  |         virtual maa_result_t i2cData (maa_i2c_context ctx, uint8_t value); | ||||||
|  |          | ||||||
|         maa_result_t close(); |         maa_result_t close(); | ||||||
|         std::string name() |         std::string name() | ||||||
|         { |         { | ||||||
|   | |||||||
| @@ -41,29 +41,29 @@ Jhd1313m1::Jhd1313m1 (int bus, int lcdAddress, int rgbAddress) : IICLcd(bus, lcd | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     usleep(50000); |     usleep(50000); | ||||||
|     cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE); |     i2Cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE); | ||||||
|     usleep(4500); |     usleep(4500); | ||||||
|     cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE); |     i2Cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE); | ||||||
|     usleep(4500); |     usleep(4500); | ||||||
|     cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE); |     i2Cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE); | ||||||
|     usleep(4500); |     usleep(4500); | ||||||
|     cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE); |     i2Cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE); | ||||||
|  |  | ||||||
|     cmd (m_i2c_lcd_control, LCD_DISPLAYCONTROL | LCD_DISPLAYON); |     i2Cmd (m_i2c_lcd_control, LCD_DISPLAYCONTROL | LCD_DISPLAYON); | ||||||
|     clear (); |     clear (); | ||||||
|     usleep(4500); |     usleep(4500); | ||||||
|      |      | ||||||
|     cmd (m_i2c_lcd_control,     LCD_ENTRYMODESET | |     i2Cmd (m_i2c_lcd_control, LCD_ENTRYMODESET | | ||||||
|                             LCD_ENTRYLEFT | |                               LCD_ENTRYLEFT | | ||||||
|                             LCD_ENTRYSHIFTDECREMENT); |                               LCD_ENTRYSHIFTDECREMENT); | ||||||
|  |  | ||||||
|     setReg (m_i2c_lcd_rgb, m_rgb_address, 0, 0); |     i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0, 0); | ||||||
|     setReg (m_i2c_lcd_rgb, m_rgb_address, 1, 0); |     i2cReg (m_i2c_lcd_rgb, m_rgb_address, 1, 0); | ||||||
|     setReg (m_i2c_lcd_rgb, m_rgb_address, 0x08, 0xAA); |     i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x08, 0xAA); | ||||||
|  |  | ||||||
|     setReg (m_i2c_lcd_rgb, m_rgb_address, 0x04, 255); |     i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x04, 255); | ||||||
|     setReg (m_i2c_lcd_rgb, m_rgb_address, 0x03, 255); |     i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x03, 255); | ||||||
|     setReg (m_i2c_lcd_rgb, m_rgb_address, 0x02, 255); |     i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x02, 255); | ||||||
| } | } | ||||||
|  |  | ||||||
| Jhd1313m1::~Jhd1313m1() { | Jhd1313m1::~Jhd1313m1() { | ||||||
| @@ -80,9 +80,7 @@ Jhd1313m1::write (std::string msg) { | |||||||
|     maa_result_t error = MAA_SUCCESS; |     maa_result_t error = MAA_SUCCESS; | ||||||
|     uint8_t data[2] = {0x40, 0}; |     uint8_t data[2] = {0x40, 0}; | ||||||
|     for (std::string::size_type i = 0; i < msg.size(); ++i) { |     for (std::string::size_type i = 0; i < msg.size(); ++i) { | ||||||
|         data[1] = msg[i]; |         error = i2cData (m_i2c_lcd_control, msg[i]); | ||||||
|         error = maa_i2c_address (m_i2c_lcd_control, m_lcd_control_address); |  | ||||||
|         error = maa_i2c_write (m_i2c_lcd_control, data, 2); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     return error; |     return error; | ||||||
| @@ -91,50 +89,19 @@ Jhd1313m1::write (std::string msg) { | |||||||
| maa_result_t | maa_result_t | ||||||
| Jhd1313m1::setCursor (int row, int column) { | Jhd1313m1::setCursor (int row, int column) { | ||||||
|     maa_result_t error = MAA_SUCCESS; |     maa_result_t error = MAA_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]); | ||||||
|  |     error =  i2Cmd (m_i2c_lcd_control, offset); | ||||||
|     uint8_t data[2] = { 0x80, offset }; |  | ||||||
|     error = maa_i2c_address (m_i2c_lcd_control, m_lcd_control_address); |  | ||||||
|     error = maa_i2c_write (m_i2c_lcd_control, data, 2); |  | ||||||
|  |  | ||||||
|     return error; |     return error; | ||||||
| } | } | ||||||
|  |  | ||||||
| maa_result_t | maa_result_t | ||||||
| Jhd1313m1::clear () { | Jhd1313m1::clear () { | ||||||
|     return cmd (m_i2c_lcd_control, LCD_CLEARDISPLAY); |     return i2Cmd (m_i2c_lcd_control, LCD_CLEARDISPLAY); | ||||||
| } | } | ||||||
|  |  | ||||||
| maa_result_t | maa_result_t | ||||||
| Jhd1313m1::home () { | Jhd1313m1::home () { | ||||||
|     return cmd (m_i2c_lcd_control, LCD_RETURNHOME); |     return i2Cmd (m_i2c_lcd_control, LCD_RETURNHOME); | ||||||
| } |  | ||||||
|  |  | ||||||
| /* |  | ||||||
|  * ************** |  | ||||||
|  *  private area |  | ||||||
|  * ************** |  | ||||||
|  */ |  | ||||||
| maa_result_t |  | ||||||
| Jhd1313m1::setReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t value) { |  | ||||||
|     maa_result_t error = MAA_SUCCESS; |  | ||||||
|  |  | ||||||
|     uint8_t data[2] = { addr, value }; |  | ||||||
|     error = maa_i2c_address (ctx, deviceAdress); |  | ||||||
|     error = maa_i2c_write (ctx, data, 2); |  | ||||||
|  |  | ||||||
|     return error; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| maa_result_t |  | ||||||
| Jhd1313m1::cmd (maa_i2c_context ctx, uint8_t value) { |  | ||||||
|     maa_result_t error = MAA_SUCCESS; |  | ||||||
|  |  | ||||||
|     uint8_t data[2] = { 0x80, value }; |  | ||||||
|     error = maa_i2c_address (ctx, m_lcd_control_address); |  | ||||||
|     error = maa_i2c_write (ctx, data, 2); |  | ||||||
|  |  | ||||||
|     return error; |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -38,9 +38,6 @@ class Jhd1313m1 : public IICLcd { | |||||||
|         maa_result_t home (); |         maa_result_t home (); | ||||||
|  |  | ||||||
|     private: |     private: | ||||||
|         maa_result_t cmd (maa_i2c_context ctx, uint8_t value); |  | ||||||
|         maa_result_t setReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t data); |  | ||||||
|  |  | ||||||
|         int m_rgb_address; |         int m_rgb_address; | ||||||
|         maa_i2c_context m_i2c_lcd_rgb; |         maa_i2c_context m_i2c_lcd_rgb; | ||||||
| }; | }; | ||||||
|   | |||||||
| @@ -85,7 +85,7 @@ Lcm1602::setCursor (int row, int column) { | |||||||
|     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]); | ||||||
|  |  | ||||||
|     return send (LCD_SETDDRAMADDR | offset, 0); |     return send (LCD_CMD | offset, 0); | ||||||
| } | } | ||||||
|  |  | ||||||
| maa_result_t | maa_result_t | ||||||
|   | |||||||
| @@ -116,39 +116,6 @@ SSD1308::home () { | |||||||
|  *  private area |  *  private area | ||||||
|  * ************** |  * ************** | ||||||
|  */ |  */ | ||||||
| maa_result_t |  | ||||||
| SSD1308::i2cReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t value) { |  | ||||||
|     maa_result_t error = MAA_SUCCESS; |  | ||||||
|  |  | ||||||
|     uint8_t data[2] = { addr, value }; |  | ||||||
|     error = maa_i2c_address (ctx, deviceAdress); |  | ||||||
|     error = maa_i2c_write (ctx, data, 2); |  | ||||||
|  |  | ||||||
|     return error; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| maa_result_t |  | ||||||
| SSD1308::i2Cmd (maa_i2c_context ctx, uint8_t value) { |  | ||||||
|     maa_result_t error = MAA_SUCCESS; |  | ||||||
|  |  | ||||||
|     uint8_t data[2] = { 0x80, value }; |  | ||||||
|     error = maa_i2c_address (ctx, m_lcd_control_address); |  | ||||||
|     error = maa_i2c_write (ctx, data, 2); |  | ||||||
|  |  | ||||||
|     return error; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| maa_result_t |  | ||||||
| SSD1308::i2cData (maa_i2c_context ctx, uint8_t value) { |  | ||||||
|     maa_result_t error = MAA_SUCCESS; |  | ||||||
|  |  | ||||||
|     uint8_t data[2] = { 0x40, value }; |  | ||||||
|     error = maa_i2c_address (ctx, m_lcd_control_address); |  | ||||||
|     error = maa_i2c_write (ctx, data, 2); |  | ||||||
|  |  | ||||||
|     return error; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| maa_result_t | maa_result_t | ||||||
| SSD1308::writeChar (maa_i2c_context ctx, uint8_t value) { | SSD1308::writeChar (maa_i2c_context ctx, uint8_t value) { | ||||||
|     if (value < 0x20 || value > 0x7F) { |     if (value < 0x20 || value > 0x7F) { | ||||||
|   | |||||||
| @@ -156,16 +156,13 @@ class SSD1308 : public IICLcd { | |||||||
|         ~SSD1308 (); |         ~SSD1308 (); | ||||||
|         maa_result_t draw(uint8_t *data, int bytes); |         maa_result_t draw(uint8_t *data, int bytes); | ||||||
|  |  | ||||||
|         // virtual methods |         // pure virtual methods | ||||||
|         maa_result_t write (std::string msg); |         maa_result_t write (std::string msg); | ||||||
|         maa_result_t setCursor (int row, int column); |         maa_result_t setCursor (int row, int column); | ||||||
|         maa_result_t clear (); |         maa_result_t clear (); | ||||||
|         maa_result_t home (); |         maa_result_t home (); | ||||||
|  |  | ||||||
|     private: |     private: | ||||||
|         maa_result_t i2Cmd (maa_i2c_context ctx, uint8_t value); |  | ||||||
|         maa_result_t i2cReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t data); |  | ||||||
|         maa_result_t i2cData (maa_i2c_context ctx, uint8_t value); |  | ||||||
|         maa_result_t writeChar (maa_i2c_context ctx, uint8_t value); |         maa_result_t writeChar (maa_i2c_context ctx, uint8_t value); | ||||||
|         maa_result_t setNormalDisplay (); |         maa_result_t setNormalDisplay (); | ||||||
|         maa_result_t setAddressingMode (displayAddressingMode mode); |         maa_result_t setAddressingMode (displayAddressingMode mode); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Kiveisha Yevgeniy
					Kiveisha Yevgeniy