2 * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3 * Copyright (c) 2014 Intel Corporation.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 SSD1308::SSD1308 (int bus_in, int addr_in) : I2CLcd (bus_in, addr_in) {
33 i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_OFF); // display off
34 printf ("NO_GDB :: DISPLAY_CMD_OFF \n");
36 i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_ON); // display on
38 setNormalDisplay (); // set to normal display '1' is ON
41 setAddressingMode (PAGE);
44 SSD1308::~SSD1308 () {
49 SSD1308::draw (uint8_t *data, int bytes) {
50 maa_result_t error = MAA_SUCCESS;
52 setAddressingMode (HORIZONTAL);
53 for (int idx = 0; idx < bytes; idx++) {
54 i2cData (m_i2c_lcd_control, data[idx]);
66 SSD1308::write (std::string msg) {
67 maa_result_t error = MAA_SUCCESS;
68 uint8_t data[2] = {0x40, 0};
70 setAddressingMode (PAGE);
71 for (std::string::size_type i = 0; i < msg.size(); ++i) {
72 writeChar (m_i2c_lcd_control, msg[i]);
79 SSD1308::setCursor (int row, int column) {
80 maa_result_t error = MAA_SUCCESS;
82 error = i2Cmd (m_i2c_lcd_control, BASE_PAGE_START_ADDR + row); // set page address
83 error = i2Cmd (m_i2c_lcd_control, BASE_LOW_COLUMN_ADDR + (8 * column & 0x0F)); // set column lower address
84 error = i2Cmd (m_i2c_lcd_control, BASE_HIGH_COLUMN_ADDR + ((8 * column >> 4) & 0x0F)); // set column higher address
91 maa_result_t error = MAA_SUCCESS;
92 uint8_t columnIdx, rowIdx;
94 i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_OFF); // display off
95 for(rowIdx = 0; rowIdx < 8; rowIdx++) {
96 setCursor (rowIdx, 0);
99 for(columnIdx = 0; columnIdx < 16; columnIdx++) {
100 writeChar (m_i2c_lcd_control, ' ');
103 i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_ON); // display on
111 return setCursor (0, 0);
120 SSD1308::writeChar (maa_i2c_context ctx, uint8_t value) {
121 if (value < 0x20 || value > 0x7F) {
122 value = 0x20; // space
125 for (uint8_t idx = 0; idx < 8; idx++) {
126 i2cData (m_i2c_lcd_control, BasicFont[value - 32][idx]);
131 SSD1308::setNormalDisplay () {
132 return i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_SET_NORMAL); // set to normal display '1' is ON
136 SSD1308::setAddressingMode (displayAddressingMode mode) {
137 i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_MEM_ADDR_MODE); //set addressing mode
138 i2Cmd (m_i2c_lcd_control, mode); //set page addressing mode