SSD1306/lib/ssd1306.h

238 lines
5.9 KiB
C
Raw Normal View History

2022-12-01 09:00:32 -05:00
/**
* -------------------------------------------------------------------------------------+
2020-10-13 04:45:09 -04:00
* @desc SSD1306 OLED Driver
2022-12-01 09:00:32 -05:00
* -------------------------------------------------------------------------------------+
2020-10-13 04:45:09 -04:00
* Copyright (C) 2020 Marian Hrinko.
* Written by Marian Hrinko (mato.hrinko@gmail.com)
*
* @author Marian Hrinko
* @datum 06.10.2020
2022-12-01 09:00:32 -05:00
* @update 21.11.2022
2020-10-13 04:45:09 -04:00
* @file ssd1306.h
2022-12-01 09:00:32 -05:00
* @version 3.0
* @tested AVR Atmega328p
2020-10-13 04:45:09 -04:00
*
2021-07-19 09:06:29 -04:00
* @depend font.h, twi.h
2022-12-01 09:00:32 -05:00
* -------------------------------------------------------------------------------------+
2021-07-19 09:06:29 -04:00
* @descr Version 1.0 -> applicable for 1 display
* Version 2.0 -> rebuild to 'cacheMemLcd' array
2022-12-01 09:00:32 -05:00
* Version 3.0 -> remove 'cacheMemLcd' approach
* -------------------------------------------------------------------------------------+
2021-04-29 03:11:44 -04:00
* @usage Basic Setup for OLED Display
2020-10-13 04:45:09 -04:00
*/
#ifndef __SSD1306_H__
#define __SSD1306_H__
2022-11-24 16:51:10 -05:00
// includes
#include "font.h"
#include "twi.h"
2022-12-01 09:00:32 -05:00
// Success / Error
// ------------------------------------------------------------------------------------
2021-07-19 09:06:29 -04:00
#define SSD1306_SUCCESS 0
#define SSD1306_ERROR 1
2020-10-13 04:45:09 -04:00
// Address definition
2022-12-01 09:00:32 -05:00
// ------------------------------------------------------------------------------------
2022-11-24 16:51:10 -05:00
#define SSD1306_ADDR 0x3C
2020-10-13 04:45:09 -04:00
// Command definition
2022-12-01 09:00:32 -05:00
// ------------------------------------------------------------------------------------
2020-10-13 04:45:09 -04:00
#define SSD1306_COMMAND 0x80 // Continuation bit=1, D/C=0; 1000 0000
#define SSD1306_COMMAND_STREAM 0x00 // Continuation bit=0, D/C=0; 0000 0000
#define SSD1306_DATA 0xC0 // Continuation bit=1, D/C=1; 1100 0000
#define SSD1306_DATA_STREAM 0x40 // Continuation bit=0, D/C=1; 0100 0000
#define SSD1306_SET_MUX_RATIO 0xA8
#define SSD1306_DISPLAY_OFFSET 0xD3
#define SSD1306_DISPLAY_ON 0xAF
#define SSD1306_DISPLAY_OFF 0xAE
#define SSD1306_DIS_ENT_DISP_ON 0xA4
2020-10-27 08:05:53 -04:00
#define SSD1306_DIS_IGNORE_RAM 0xA5
2020-10-13 04:45:09 -04:00
#define SSD1306_DIS_NORMAL 0xA6
#define SSD1306_DIS_INVERSE 0xA7
#define SSD1306_DEACT_SCROLL 0x2E
#define SSD1306_ACTIVE_SCROLL 0x2F
#define SSD1306_SET_START_LINE 0x40
#define SSD1306_MEMORY_ADDR_MODE 0x20
#define SSD1306_SET_COLUMN_ADDR 0x21
#define SSD1306_SET_PAGE_ADDR 0x22
#define SSD1306_SEG_REMAP 0xA0
#define SSD1306_SEG_REMAP_OP 0xA1
#define SSD1306_COM_SCAN_DIR 0xC0
2020-10-27 08:05:53 -04:00
#define SSD1306_COM_SCAN_DIR_OP 0xC8
2020-10-13 04:45:09 -04:00
#define SSD1306_COM_PIN_CONF 0xDA
#define SSD1306_SET_CONTRAST 0x81
#define SSD1306_SET_OSC_FREQ 0xD5
#define SSD1306_SET_CHAR_REG 0x8D
2020-10-27 08:05:53 -04:00
#define SSD1306_SET_PRECHARGE 0xD9
#define SSD1306_VCOM_DESELECT 0xDB
2020-10-13 04:45:09 -04:00
// Clear Color
2022-12-01 09:00:32 -05:00
// ------------------------------------------------------------------------------------
2020-10-13 04:45:09 -04:00
#define CLEAR_COLOR 0x00
// Init Status
2022-12-01 09:00:32 -05:00
// ------------------------------------------------------------------------------------
2020-10-13 04:45:09 -04:00
#define INIT_STATUS 0xFF
// AREA definition
2022-12-01 09:00:32 -05:00
// ------------------------------------------------------------------------------------
2021-04-29 03:11:44 -04:00
#define START_PAGE_ADDR 0
2022-12-01 09:00:32 -05:00
#define END_PAGE_ADDR 7 // 7 for 128x64, 3 for 128x32 version
#define START_COL_ADDR 0
#define END_COL_ADDR 127
2021-07-19 09:06:29 -04:00
2022-12-01 09:00:32 -05:00
#define CACHE_SIZE_MEM (1 + END_PAGE_ADDR) * (1 + END_COL_ADDR)
2020-10-27 08:05:53 -04:00
2022-12-01 09:00:32 -05:00
#define MAX_X END_COL_ADDR
#define MAX_Y (END_PAGE_ADDR + 1) * 8
2020-10-13 04:45:09 -04:00
/**
2021-07-21 01:21:35 -04:00
* @desc SSD1306 Init
2020-10-13 04:45:09 -04:00
*
2022-11-24 16:51:10 -05:00
* @param void
2020-10-13 04:45:09 -04:00
*
2021-07-19 09:06:29 -04:00
* @return uint8_t
2020-10-13 04:45:09 -04:00
*/
2022-11-24 16:51:10 -05:00
uint8_t SSD1306_Init (void);
2020-10-13 04:45:09 -04:00
/**
* @desc SSD1306 Send Start and SLAW request
*
2022-12-01 09:00:32 -05:00
* @param uint8_t address
2020-10-13 04:45:09 -04:00
*
2021-07-19 09:06:29 -04:00
* @return uint8_t
2020-10-13 04:45:09 -04:00
*/
2021-07-19 09:06:29 -04:00
uint8_t SSD1306_Send_StartAndSLAW (uint8_t);
2020-10-13 04:45:09 -04:00
/**
2021-07-21 01:21:35 -04:00
* @desc SSD1306 Send command
2020-10-13 04:45:09 -04:00
*
2022-12-01 09:00:32 -05:00
* @param uint8_t command
2020-10-13 04:45:09 -04:00
*
2021-07-19 09:06:29 -04:00
* @return uint8_t
2020-10-13 04:45:09 -04:00
*/
2021-07-19 09:06:29 -04:00
uint8_t SSD1306_Send_Command (uint8_t);
2020-10-13 04:45:09 -04:00
/**
2021-07-21 01:21:35 -04:00
* @desc SSD1306 Clear screen
2020-10-13 04:45:09 -04:00
*
* @param void
2020-10-27 08:05:53 -04:00
*
2022-11-24 16:51:10 -05:00
* @return uint8_t
2020-10-27 08:05:53 -04:00
*/
2022-11-24 16:51:10 -05:00
uint8_t SSD1306_ClearScreen (void);
2020-10-27 08:05:53 -04:00
/**
2021-07-21 01:21:35 -04:00
* @desc SSD1306 Normal colors
2020-10-27 08:05:53 -04:00
*
2022-11-24 16:51:10 -05:00
* @param void
2020-10-13 04:45:09 -04:00
*
2021-07-19 09:06:29 -04:00
* @return uint8_t
2020-10-13 04:45:09 -04:00
*/
2022-11-24 16:51:10 -05:00
uint8_t SSD1306_NormalScreen (void);
2020-10-27 08:05:53 -04:00
/**
2021-07-21 01:21:35 -04:00
* @desc SSD1306 Inverse colors
2020-10-27 08:05:53 -04:00
*
2022-11-24 16:51:10 -05:00
* @param void
2021-07-20 05:03:40 -04:00
*
* @return uint8_t
*/
2022-11-24 16:51:10 -05:00
uint8_t SSD1306_InverseScreen (void);
2021-07-20 05:03:40 -04:00
2022-12-01 09:00:32 -05:00
/**
* @desc SSD1306 Update screen
*
* @param void
*
* @return uint8_t
*/
uint8_t SSD1306_UpdateScreen (void);
2020-10-27 08:05:53 -04:00
/**
* @desc SSD1306 Update text position
2020-10-27 08:05:53 -04:00
*
* @param void
2020-10-27 08:05:53 -04:00
*
2021-07-19 09:06:29 -04:00
* @return uint8_t
2020-10-27 08:05:53 -04:00
*/
2022-11-24 16:51:10 -05:00
uint8_t SSD1306_UpdatePosition (void);
2020-10-13 04:45:09 -04:00
/**
* @desc SSD1306 Set position
2020-10-13 04:45:09 -04:00
*
2022-12-01 09:00:32 -05:00
* @param uint8_t x
* @param uint8_t y
2020-10-13 04:45:09 -04:00
*
2022-11-24 16:51:10 -05:00
* @return uint8_t
2020-10-13 04:45:09 -04:00
*/
2022-11-24 16:51:10 -05:00
uint8_t SSD1306_SetPosition (uint8_t, uint8_t);
2020-10-13 04:45:09 -04:00
2022-12-01 09:00:32 -05:00
/**
* @desc SSD1306 Set window
*
* @param uint8_t x1
* @param uint8_t x2
* @param uint8_t y1
* @param uint8_t y2
*
* @return void
*/
uint8_t SSD1306_SetWindow (uint8_t, uint8_t, uint8_t, uint8_t);
2020-10-13 04:45:09 -04:00
/**
* @desc SSD1306 Draw character
2020-10-13 04:45:09 -04:00
*
* @param char
*
2021-07-19 09:06:29 -04:00
* @return uint8_t
2020-10-13 04:45:09 -04:00
*/
uint8_t SSD1306_DrawChar (char);
2020-10-13 04:45:09 -04:00
/**
* @desc SSD1306 Draw string
2020-10-13 04:45:09 -04:00
*
* @param char *
*
2022-11-24 16:51:10 -05:00
* @return uint8_t
2020-10-13 04:45:09 -04:00
*/
2022-11-24 16:51:10 -05:00
uint8_t SSD1306_DrawString (char *);
2020-10-13 04:45:09 -04:00
2020-10-27 08:05:53 -04:00
/**
2021-07-19 09:06:29 -04:00
* @desc Draw pixel
2020-10-27 08:05:53 -04:00
*
2022-12-01 09:00:32 -05:00
* @param uint8_t x
* @param uint8_t y
2020-10-27 08:05:53 -04:00
*
* @return uint8_t
2020-10-27 08:05:53 -04:00
*/
uint8_t SSD1306_DrawPixel (uint8_t, uint8_t);
2020-10-27 08:05:53 -04:00
2022-12-01 09:00:32 -05:00
/**
* @desc Draw line horizontal
*
* @param uint8_t y
* @param uint8_t x1
* @param uint8_t x2
*
* @return uint8_t
*/
uint8_t SSD1306_DrawLineHorz (uint8_t, uint8_t, uint8_t);
2020-10-27 08:05:53 -04:00
/**
2021-07-19 09:06:29 -04:00
* @desc Draw line
2022-12-01 09:00:32 -05:00
*
* @param uint8_t x1
* @param uint8_t x2
* @param uint8_t y1
* @param uint8_t y2
2021-07-19 09:06:29 -04:00
*
* @return uint8_t
*/
uint8_t SSD1306_DrawLine (uint8_t, uint8_t, uint8_t, uint8_t);
2020-10-27 08:05:53 -04:00
2020-10-13 04:45:09 -04:00
#endif