Hexiwear OLED
Fork of Hexi_OLED_SSD1351 by
Diff: Hexi_OLED_SSD1351.cpp
- Revision:
- 2:fc06b5b5bf6a
- Parent:
- 1:3b5be0ee5f0c
- Child:
- 3:4121d3cd9f60
--- a/Hexi_OLED_SSD1351.cpp Thu Aug 18 23:01:06 2016 +0000 +++ b/Hexi_OLED_SSD1351.cpp Fri Aug 19 23:05:58 2016 +0000 @@ -1,9 +1,90 @@ +/** + * \file Hexi_OLED_SSD1351.cpp + * \version 1.00 + * \brief this file contains OLED driver functionality for + * drawing images and text + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this list + * of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * Neither the name of NXP, nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * visit: http://www.mikroe.com and http://www.nxp.com + * + * get support at: http://www.mikroe.com/forum and https://community.nxp.com + * + * Project HEXIWEAR, 2015 + */ + #include "OLED_types.h" #include "OLED_info.h" #include "mbed.h" #include "Hexi_OLED_SSD1351.h" #include "OLED_fonts.h" + +const init_cmd_t seq[] = { + OLED_CMD_SET_CMD_LOCK, CMD_BYTE, + OLED_UNLOCK, DATA_BYTE, + OLED_CMD_SET_CMD_LOCK, CMD_BYTE, + OLED_ACC_TO_CMD_YES, DATA_BYTE, + OLED_CMD_DISPLAYOFF, CMD_BYTE, + OLED_CMD_SET_OSC_FREQ_AND_CLOCKDIV, CMD_BYTE, + 0xF1, DATA_BYTE, + OLED_CMD_SET_MUX_RATIO, CMD_BYTE, + 0x5F, DATA_BYTE, + OLED_CMD_SET_REMAP, CMD_BYTE, + OLED_REMAP_SETTINGS, DATA_BYTE, + OLED_CMD_SET_COLUMN, CMD_BYTE, + 0x00, DATA_BYTE, + 0x5F, DATA_BYTE, + OLED_CMD_SET_ROW, CMD_BYTE, + 0x00, DATA_BYTE, + 0x5F, DATA_BYTE, + OLED_CMD_STARTLINE, CMD_BYTE, + 0x80, DATA_BYTE, + OLED_CMD_DISPLAYOFFSET, CMD_BYTE, + 0x60, DATA_BYTE, + OLED_CMD_PRECHARGE, CMD_BYTE, + 0x32, CMD_BYTE, + OLED_CMD_VCOMH, CMD_BYTE, + 0x05, CMD_BYTE, + OLED_CMD_NORMALDISPLAY, CMD_BYTE, + OLED_CMD_CONTRASTABC, CMD_BYTE, + 0x8A, DATA_BYTE, + 0x51, DATA_BYTE, + 0x8A, DATA_BYTE, + OLED_CMD_CONTRASTMASTER, CMD_BYTE, + 0xCF, DATA_BYTE, + OLED_CMD_SETVSL, CMD_BYTE, + 0xA0, DATA_BYTE, + 0xB5, DATA_BYTE, + 0x55, DATA_BYTE, + OLED_CMD_PRECHARGE2, CMD_BYTE, + 0x01, DATA_BYTE, + OLED_CMD_DISPLAYON, CMD_BYTE + }; +#if 0 /* oled_init arrays*/ const uint32_t oled_init_cmd[] = { OLED_CMD_SET_CMD_LOCK, @@ -48,46 +129,46 @@ const uint8_t oled_init_isFirst[] = { - FIRST_BYTE, - OTHER_BYTE, - FIRST_BYTE, - OTHER_BYTE, - FIRST_BYTE, - FIRST_BYTE, - OTHER_BYTE, - FIRST_BYTE, - OTHER_BYTE, - FIRST_BYTE, - OTHER_BYTE, - FIRST_BYTE, - OTHER_BYTE, - OTHER_BYTE, - FIRST_BYTE, - OTHER_BYTE, - OTHER_BYTE, - FIRST_BYTE, - OTHER_BYTE, - FIRST_BYTE, - OTHER_BYTE, - FIRST_BYTE, - FIRST_BYTE, - FIRST_BYTE, - FIRST_BYTE, - FIRST_BYTE, - FIRST_BYTE, - OTHER_BYTE, - OTHER_BYTE, - OTHER_BYTE, - FIRST_BYTE, - OTHER_BYTE, - FIRST_BYTE, - OTHER_BYTE, - OTHER_BYTE, - OTHER_BYTE, - FIRST_BYTE, - OTHER_BYTE, - FIRST_BYTE}; - + CMD_BYTE, + DATA_BYTE, + CMD_BYTE, + DATA_BYTE, + CMD_BYTE, + CMD_BYTE, + DATA_BYTE, + CMD_BYTE, + DATA_BYTE, + CMD_BYTE, + DATA_BYTE, + CMD_BYTE, + DATA_BYTE, + DATA_BYTE, + CMD_BYTE, + DATA_BYTE, + DATA_BYTE, + CMD_BYTE, + DATA_BYTE, + CMD_BYTE, + DATA_BYTE, + CMD_BYTE, + CMD_BYTE, + CMD_BYTE, + CMD_BYTE, + CMD_BYTE, + CMD_BYTE, + DATA_BYTE, + DATA_BYTE, + DATA_BYTE, + CMD_BYTE, + DATA_BYTE, + CMD_BYTE, + DATA_BYTE, + DATA_BYTE, + DATA_BYTE, + CMD_BYTE, + DATA_BYTE, + CMD_BYTE}; +#endif @@ -126,7 +207,8 @@ for (int i=0;i<39;i++) { - SendCmd(oled_init_cmd[i],oled_init_isFirst[i]); + //SendCmd(oled_init_cmd[i],oled_init_isFirst[i]); + SendCmd(seq[i].cmd, seq[i].type); } @@ -186,7 +268,7 @@ } - this->SendCmd( OLED_CMD_WRITERAM, FIRST_BYTE ); + this->SendCmd( OLED_CMD_WRITERAM, CMD_BYTE ); // sending data -> set DC pin @@ -266,12 +348,12 @@ OLED_AdjustColumnOffset(xCrd); OLED_AdjustRowOffset(yCrd); - SendCmd( OLED_CMD_SET_COLUMN, FIRST_BYTE); - SendCmd( xCrd, OTHER_BYTE ); - SendCmd( xCrd + (width-1), OTHER_BYTE ); - SendCmd( OLED_CMD_SET_ROW, FIRST_BYTE ); - SendCmd( yCrd, OTHER_BYTE ); - SendCmd( yCrd + (height-1), OTHER_BYTE ); + SendCmd( OLED_CMD_SET_COLUMN, CMD_BYTE); + SendCmd( xCrd, DATA_BYTE ); + SendCmd( xCrd + (width-1), DATA_BYTE ); + SendCmd( OLED_CMD_SET_ROW, CMD_BYTE ); + SendCmd( yCrd, DATA_BYTE ); + SendCmd( yCrd + (height-1), DATA_BYTE ); // fill the GRAM @@ -897,8 +979,8 @@ { for ( int i = 0; i < 16; i++ ) { - SendCmd( OLED_CMD_CONTRASTMASTER, FIRST_BYTE ); - SendCmd( 0xC0 | (0xF-i), OTHER_BYTE ); + SendCmd( OLED_CMD_CONTRASTMASTER, CMD_BYTE ); + SendCmd( 0xC0 | (0xF-i), DATA_BYTE ); wait_ms(20); //OSA_TimeDelay( 20 ); } @@ -907,8 +989,8 @@ void SSD1351::DimScreenOFF() { - SendCmd( OLED_CMD_CONTRASTMASTER, FIRST_BYTE ); - SendCmd( 0xC0 | 0xF, OTHER_BYTE ); + SendCmd( OLED_CMD_CONTRASTMASTER, CMD_BYTE ); + SendCmd( 0xC0 | 0xF, DATA_BYTE ); } @@ -1163,8 +1245,8 @@ Transpose( (oled_pixel_t)transImage, (const oled_pixel_t)image, width, height ); - SendCmd( OLED_CMD_SET_REMAP, FIRST_BYTE ); - SendCmd( OLED_REMAP_SETTINGS | REMAP_VERTICAL_INCREMENT, OTHER_BYTE ); + SendCmd( OLED_CMD_SET_REMAP, CMD_BYTE ); + SendCmd( OLED_REMAP_SETTINGS | REMAP_VERTICAL_INCREMENT, DATA_BYTE ); uint16_t transStep = OLED_TRANSITION_STEP; @@ -1200,8 +1282,8 @@ } - SendCmd( OLED_CMD_SET_REMAP, FIRST_BYTE ); - SendCmd( OLED_REMAP_SETTINGS, OTHER_BYTE ); + SendCmd( OLED_CMD_SET_REMAP, CMD_BYTE ); + SendCmd( OLED_REMAP_SETTINGS, DATA_BYTE ); DestroyDynamicArea(); return status; @@ -1248,8 +1330,8 @@ Transpose( (oled_pixel_t)transImage, (const oled_pixel_t)image, width, height ); - SendCmd( OLED_CMD_SET_REMAP, FIRST_BYTE ); - SendCmd( OLED_REMAP_SETTINGS | REMAP_VERTICAL_INCREMENT, OTHER_BYTE ); + SendCmd( OLED_CMD_SET_REMAP, CMD_BYTE ); + SendCmd( OLED_REMAP_SETTINGS | REMAP_VERTICAL_INCREMENT, DATA_BYTE ); uint16_t @@ -1287,8 +1369,8 @@ transStep++; } - SendCmd( OLED_CMD_SET_REMAP, FIRST_BYTE ); - SendCmd( OLED_REMAP_SETTINGS, OTHER_BYTE ); + SendCmd( OLED_CMD_SET_REMAP, CMD_BYTE ); + SendCmd( OLED_REMAP_SETTINGS, DATA_BYTE ); DestroyDynamicArea(); @@ -1315,12 +1397,12 @@ OLED_AdjustColumnOffset(xCrd); OLED_AdjustRowOffset(yCrd); - SendCmd( OLED_CMD_SET_COLUMN, FIRST_BYTE ); - SendCmd( xCrd, OTHER_BYTE ); - SendCmd( xCrd + (width-1), OTHER_BYTE ); - SendCmd( OLED_CMD_SET_ROW, FIRST_BYTE ); - SendCmd( yCrd, OTHER_BYTE ); - SendCmd( yCrd + (height-1), OTHER_BYTE ); + SendCmd( OLED_CMD_SET_COLUMN, CMD_BYTE ); + SendCmd( xCrd, DATA_BYTE ); + SendCmd( xCrd + (width-1), DATA_BYTE ); + SendCmd( OLED_CMD_SET_ROW, CMD_BYTE ); + SendCmd( yCrd, DATA_BYTE ); + SendCmd( yCrd + (height-1), DATA_BYTE ); }