123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- /*****************************************************************************
- * | File : OLED_Driver.cpp
- * | Author : Waveshare team
- * | Function : 1.5inch RGB OLED Module Drive function
- * | Info :
- *----------------
- * | This version: V2.0
- * | Date : 2020-08-20
- * | Info :
- * -----------------------------------------------------------------------------
- #
- # Permission is hereby granted, free of charge, to any person obtaining a copy
- # of this software and associated documnetation files (the "Software"), to deal
- # in the Software without restriction, including without limitation the rights
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- # copies of the Software, and to permit persons to whom the Software is
- # furished to do so, subject to the following conditions:
- #
- # The above copyright notice and this permission notice shall be included in
- # all copies or substantial portions of the Software.
- #
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- # FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- # LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- # THE SOFTWARE.
- #
- ******************************************************************************/
- #include "OLED_Driver.h"
- #include "stdio.h"
- /*******************************************************************************
- function:
- Hardware reset
- *******************************************************************************/
- static void OLED_Reset(void)
- {
- OLED_RST_1;
- Driver_Delay_ms(100);
- OLED_RST_0;
- Driver_Delay_ms(100);
- OLED_RST_1;
- Driver_Delay_ms(100);
- }
- /*******************************************************************************
- function:
- Write register address and data
- *******************************************************************************/
- static void OLED_WriteReg(uint8_t Reg)
- {
- #if USE_SPI_4W
- OLED_DC_0;
- OLED_CS_0;
- SPI4W_Write_Byte(Reg);
- OLED_CS_1;
- #endif
- }
- static void OLED_WriteData(uint8_t Data)
- {
- #if USE_SPI_4W
- OLED_DC_1;
- OLED_CS_0;
- SPI4W_Write_Byte(Data);
- OLED_CS_1;
- #endif
- }
- /*******************************************************************************
- function:
- Common register initialization
- *******************************************************************************/
- static void OLED_InitReg(void)
- {
- OLED_WriteReg(0xfd); // command lock
- OLED_WriteData(0x12);
- OLED_WriteReg(0xfd); // command lock
- OLED_WriteData(0xB1);
- OLED_WriteReg(0xae); // display off
- OLED_WriteReg(0xa4); // Normal Display mode
- OLED_WriteReg(0x15); //set column address
- OLED_WriteData(0x00); //column address start 00
- OLED_WriteData(0x7f); //column address end 127
- OLED_WriteReg(0x75); //set row address
- OLED_WriteData(0x00); //row address start 00
- OLED_WriteData(0x7f); //row address end 127
- OLED_WriteReg(0xB3);
- OLED_WriteData(0xF1);
- OLED_WriteReg(0xCA);
- OLED_WriteData(0x7F);
- OLED_WriteReg(0xa0); //set re-map & data format
- OLED_WriteData(0x74); //Horizontal address increment
- OLED_WriteReg(0xa1); //set display start line
- OLED_WriteData(0x00); //start 00 line
- OLED_WriteReg(0xa2); //set display offset
- OLED_WriteData(0x00);
- OLED_WriteReg(0xAB);
- OLED_WriteReg(0x01);
- OLED_WriteReg(0xB4);
- OLED_WriteData(0xA0);
- OLED_WriteData(0xB5);
- OLED_WriteData(0x55);
- OLED_WriteReg(0xC1);
- OLED_WriteData(0xC8);
- OLED_WriteData(0x80);
- OLED_WriteData(0xC0);
- OLED_WriteReg(0xC7);
- OLED_WriteData(0x0F);
- OLED_WriteReg(0xB1);
- OLED_WriteData(0x32);
- OLED_WriteReg(0xB2);
- OLED_WriteData(0xA4);
- OLED_WriteData(0x00);
- OLED_WriteData(0x00);
- OLED_WriteReg(0xBB);
- OLED_WriteData(0x17);
- OLED_WriteReg(0xB6);
- OLED_WriteData(0x01);
- OLED_WriteReg(0xBE);
- OLED_WriteData(0x05);
- OLED_WriteReg(0xA6);
- }
- /********************************************************************************
- function:
- initialization
- ********************************************************************************/
- void OLED_1in5_rgb_Init(void)
- {
- //Hardware reset
- OLED_Reset();
- //Set the initialization register
- OLED_InitReg();
- Driver_Delay_ms(200);
- //Turn on the OLED display
- OLED_WriteReg(0xAF);
- }
- /********************************************************************************
- function:
- Clear screen
- ********************************************************************************/
- void OLED_1in5_rgb_Clear(void)
- {
- UWORD i;
- OLED_WriteReg(0x15);
- OLED_WriteData(0);
- OLED_WriteData(127);
- OLED_WriteReg(0x75);
- OLED_WriteData(0);
- OLED_WriteData(127);
- // fill!
- OLED_WriteReg(0x5C);
- for(i=0; i<OLED_1in5_RGB_WIDTH*OLED_1in5_RGB_HEIGHT*2; i++){
- OLED_WriteData(0x00);
- }
- }
- /********************************************************************************
- function: Draw a point
- ********************************************************************************/
- void OLED_1in5_rgb_Set_Point(UBYTE Xpoint, UBYTE Ypoint, UWORD Color)
- {
- OLED_WriteReg(0x15);
- OLED_WriteData(Xpoint);
- OLED_WriteData(Xpoint);
- OLED_WriteReg(0x75);
- OLED_WriteData(Ypoint);
- OLED_WriteData(Ypoint);
- // fill!
- OLED_WriteReg(0x5C);
-
- OLED_WriteData(Color>>8);
- OLED_WriteData(Color);
- }
- /********************************************************************************
- function: Update all memory to OLED
- ********************************************************************************/
- void OLED_1in5_rgb_Display(const UBYTE *Image)
- {
- UWORD i, j, temp;
- OLED_WriteReg(0x15);
- OLED_WriteData(0);
- OLED_WriteData(127);
- OLED_WriteReg(0x75);
- OLED_WriteData(0);
- OLED_WriteData(127);
- // fill!
- OLED_WriteReg(0x5C);
-
- for(i=0; i<OLED_1in5_RGB_HEIGHT; i++)
- for(j=0; j<OLED_1in5_RGB_WIDTH*2; j++)
- {
- temp = Image[j + i*256];
- OLED_WriteData(temp);
-
- }
- }
- /********************************************************************************
- function: Update all memory to OLED
- ********************************************************************************/
- void OLED_1in5_rgb_Display_Part(const UBYTE *Image, UBYTE Xstart, UBYTE Ystart, UBYTE Xend, UBYTE Yend)
- {
- UWORD i, j, temp;
- OLED_WriteReg(0x15);
- OLED_WriteData(Xstart);
- OLED_WriteData(Xend-1);
- OLED_WriteReg(0x75);
- OLED_WriteData(Ystart);
- OLED_WriteData(Yend-1);
- // fill!
- OLED_WriteReg(0x5C);
-
- for(i=0; i<Yend-Ystart; i++)
- for(j=0; j<(Xend-Xstart)*2; j++)
- {
- temp = pgm_read_byte(&Image[j + i*(Xend-Xstart)*2]);
- OLED_WriteData(temp);
- }
- }
|