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 #define INIT_SLEEP 50000
33 #define CMD_SLEEP 10000
35 SSD1327::SSD1327 (int bus_in, int addr_in) : IICLcd (bus_in, addr_in) {
36 maa_result_t error = MAA_SUCCESS;
38 i2Cmd (m_i2c_lcd_control, 0xFD); // Unlock OLED driver IC MCU interface from entering command. i.e: Accept commands
40 i2Cmd (m_i2c_lcd_control, 0x12);
42 error = i2Cmd (m_i2c_lcd_control, 0xAE); // Set display off
44 i2Cmd (m_i2c_lcd_control, 0xA8); // set multiplex ratio
46 error = i2Cmd (m_i2c_lcd_control, 0x5F); // 96
48 error = i2Cmd (m_i2c_lcd_control, 0xA1); // set display start line
50 error = i2Cmd (m_i2c_lcd_control, 0x00); //
52 error = i2Cmd (m_i2c_lcd_control, 0xA2); // set display offset
54 error = i2Cmd (m_i2c_lcd_control, 0x60);
56 error = i2Cmd (m_i2c_lcd_control, 0xA0); // set remap
58 error = i2Cmd (m_i2c_lcd_control, 0x46);
60 error = i2Cmd (m_i2c_lcd_control, 0xAB); // set vdd internal
62 error = i2Cmd (m_i2c_lcd_control, 0x01); //
64 error = i2Cmd (m_i2c_lcd_control, 0x81); // set contrasr
66 error = i2Cmd (m_i2c_lcd_control, 0x53); // 100 nit
68 error = i2Cmd (m_i2c_lcd_control, 0xB1); // Set Phase Length
70 error = i2Cmd (m_i2c_lcd_control, 0X51); //
72 error = i2Cmd (m_i2c_lcd_control, 0xB3); // Set Display Clock Divide Ratio/Oscillator Frequency
74 error = i2Cmd (m_i2c_lcd_control, 0x01); //
76 error = i2Cmd (m_i2c_lcd_control, 0xB9); //
78 error = i2Cmd (m_i2c_lcd_control, 0xBC); // set pre_charge voltage/VCOMH
80 error = i2Cmd (m_i2c_lcd_control, 0x08); // (0x08);
82 error = i2Cmd (m_i2c_lcd_control, 0xBE); // set VCOMH
84 error = i2Cmd (m_i2c_lcd_control, 0X07); // (0x07);
86 error = i2Cmd (m_i2c_lcd_control, 0xB6); // Set second pre-charge period
88 error = i2Cmd (m_i2c_lcd_control, 0x01); //
90 error = i2Cmd (m_i2c_lcd_control, 0xD5); // enable second precharge and enternal vsl
92 error = i2Cmd (m_i2c_lcd_control, 0X62); // (0x62);
94 error = i2Cmd (m_i2c_lcd_control, 0xA4); // Set Normal Display Mode
96 error = i2Cmd (m_i2c_lcd_control, 0x2E); // Deactivate Scroll
98 error = i2Cmd (m_i2c_lcd_control, 0xAF); // Switch on display
102 error = i2Cmd (m_i2c_lcd_control, 0x75); // Set Row Address
104 error = i2Cmd (m_i2c_lcd_control, 0x00); // Start 0
106 error = i2Cmd (m_i2c_lcd_control, 0x5f); // End 95
110 error = i2Cmd (m_i2c_lcd_control, 0x15); // Set Column Address
112 error = i2Cmd (m_i2c_lcd_control, 0x08); // Start from 8th Column of driver IC. This is 0th Column for OLED
114 error = i2Cmd (m_i2c_lcd_control, 0x37); // End at (8 + 47)th column. Each Column has 2 pixels(segments)
122 SSD1327::~SSD1327 () {
127 SSD1327::draw (uint8_t *data, int bytes) {
128 maa_result_t error = MAA_SUCCESS;
130 setHorizontalMode ();
131 for (int row = 0; row < bytes; row++) {
132 for (uint8_t col = 0; col < 8; col+=2) {
135 uint8_t bitOne = (data[row] << col) & 0x80;
136 uint8_t bitTwo = (data[row] << (col + 1)) & 0x80;
138 value |= (bitOne) ? grayHigh : 0x00;
139 value |= (bitTwo) ? grayLow : 0x00;
141 i2cData (m_i2c_lcd_control, value);
142 usleep (CMD_SLEEP - 2000);
155 SSD1327::write (std::string msg) {
156 maa_result_t error = MAA_SUCCESS;
159 for (std::string::size_type i = 0; i < msg.size(); ++i) {
160 writeChar (m_i2c_lcd_control, msg[i]);
167 SSD1327::setCursor (int row, int column) {
168 maa_result_t error = MAA_SUCCESS;
171 i2Cmd (m_i2c_lcd_control, 0x15); /* Set Column Address */
173 i2Cmd (m_i2c_lcd_control, 0x08 + (column * 4)); /* Start Column: Start from 8 */
175 i2Cmd (m_i2c_lcd_control, 0x37); /* End Column */
178 i2Cmd (m_i2c_lcd_control, 0x75); /* Set Row Address */
180 i2Cmd (m_i2c_lcd_control, 0x00 + (row * 8)); /* Start Row*/
182 i2Cmd (m_i2c_lcd_control, 0x07 + (row * 8)); /* End Row*/
190 maa_result_t error = MAA_SUCCESS;
191 uint8_t columnIdx, rowIdx;
193 for(rowIdx = 0; rowIdx < 12; rowIdx++) {
195 for(columnIdx = 0; columnIdx < 12; columnIdx++) {
196 writeChar (m_i2c_lcd_control, ' ');
205 return setCursor (0, 0);
209 SSD1327::setGrayLevel (uint8_t level) {
210 grayHigh = (level << 4) & 0xF0;
211 grayLow = level & 0x0F;
220 SSD1327::writeChar (maa_i2c_context ctx, uint8_t value) {
221 if (value < 0x20 || value > 0x7F) {
222 value = 0x20; // space
225 for (uint8_t row = 0; row < 8; row=row+2) {
226 for (uint8_t col = 0; col < 8; col++) {
229 uint8_t bitOne = ((BasicFont[value - 32][row]) >> col) & 0x1;
230 uint8_t bitTwo = ((BasicFont[value - 32][row + 1]) >> col) & 0x1;
232 data |= (bitOne) ? grayHigh : 0x00;
233 data |= (bitTwo) ? grayLow : 0x00;
235 i2cData (m_i2c_lcd_control, data);
236 usleep (CMD_SLEEP - 2000);
242 SSD1327::setNormalDisplay () {
243 return i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_SET_NORMAL); // set to normal display '1' is ON
247 SSD1327::setHorizontalMode () {
248 i2Cmd (m_i2c_lcd_control, 0xA0); // remap to
250 i2Cmd (m_i2c_lcd_control, 0x42); // horizontal mode
254 i2Cmd (m_i2c_lcd_control, 0x75); // Set Row Address
256 i2Cmd (m_i2c_lcd_control, 0x00); // Start 0
258 i2Cmd (m_i2c_lcd_control, 0x5f); // End 95
262 i2Cmd (m_i2c_lcd_control, 0x15); // Set Column Address
264 i2Cmd (m_i2c_lcd_control, 0x08); // Start from 8th Column of driver IC. This is 0th Column for OLED
266 i2Cmd (m_i2c_lcd_control, 0x37); // End at (8 + 47)th column. Each Column has 2 pixels(or segments)
271 SSD1327::setVerticalMode () {
272 i2Cmd (m_i2c_lcd_control, 0xA0); // remap to
274 i2Cmd (m_i2c_lcd_control, 0x46); // Vertical mode