Sarted testing the i2c library wiht the 0.9Inc oled display, and it is working! just need to to the reset manually

master
kerem yollu 2 years ago
parent 4030ed9611
commit 3ebdf34db2

@ -1 +1 @@
set(DRIVERS_LIST pf8574 max7219 max31865)
set(DRIVERS_LIST pf8574 max7219 max31865 ssd1306_i2c)

@ -0,0 +1,28 @@
/******
Demo for ssd1306 i2c driver for Raspberry Pi
******/
#include "ssd1306_i2c.h"
void main() {
ssd1306_begin(SSD1306_SWITCHCAPVCC, SSD1306_I2C_ADDRESS);
ssd1306_display(); //Adafruit logo is visible
ssd1306_clearDisplay();
delay(5000);
char* text = "This is demo for SSD1306 i2c driver for Raspberry Pi";
ssd1306_drawString(text);
ssd1306_display();
delay(5000);
ssd1306_dim(1);
ssd1306_startscrollright(00,0xFF);
delay(5000);
ssd1306_clearDisplay();
ssd1306_fillRect(10,10, 50, 20, WHITE);
ssd1306_fillRect(80, 10, 130, 50, WHITE);
ssd1306_display();
}

@ -0,0 +1,266 @@
#ifndef OLED_FONTS_H
#define OLED_FONTS_H
#define PROGMEM
// Standard ASCII 5x7 font Adaf
static const unsigned char font[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00,
0x3E, 0x5B, 0x4F, 0x5B, 0x3E,
0x3E, 0x6B, 0x4F, 0x6B, 0x3E,
0x1C, 0x3E, 0x7C, 0x3E, 0x1C,
0x18, 0x3C, 0x7E, 0x3C, 0x18,
0x1C, 0x57, 0x7D, 0x57, 0x1C,
0x1C, 0x5E, 0x7F, 0x5E, 0x1C,
0x00, 0x18, 0x3C, 0x18, 0x00,
0xFF, 0xE7, 0xC3, 0xE7, 0xFF,
0x00, 0x18, 0x24, 0x18, 0x00,
0xFF, 0xE7, 0xDB, 0xE7, 0xFF,
0x30, 0x48, 0x3A, 0x06, 0x0E,
0x26, 0x29, 0x79, 0x29, 0x26,
0x40, 0x7F, 0x05, 0x05, 0x07,
0x40, 0x7F, 0x05, 0x25, 0x3F,
0x5A, 0x3C, 0xE7, 0x3C, 0x5A,
0x7F, 0x3E, 0x1C, 0x1C, 0x08,
0x08, 0x1C, 0x1C, 0x3E, 0x7F,
0x14, 0x22, 0x7F, 0x22, 0x14,
0x5F, 0x5F, 0x00, 0x5F, 0x5F,
0x06, 0x09, 0x7F, 0x01, 0x7F,
0x00, 0x66, 0x89, 0x95, 0x6A,
0x60, 0x60, 0x60, 0x60, 0x60,
0x94, 0xA2, 0xFF, 0xA2, 0x94,
0x08, 0x04, 0x7E, 0x04, 0x08,
0x10, 0x20, 0x7E, 0x20, 0x10,
0x08, 0x08, 0x2A, 0x1C, 0x08,
0x08, 0x1C, 0x2A, 0x08, 0x08,
0x1E, 0x10, 0x10, 0x10, 0x10,
0x0C, 0x1E, 0x0C, 0x1E, 0x0C,
0x30, 0x38, 0x3E, 0x38, 0x30,
0x06, 0x0E, 0x3E, 0x0E, 0x06,
0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x5F, 0x00, 0x00,
0x00, 0x07, 0x00, 0x07, 0x00,
0x14, 0x7F, 0x14, 0x7F, 0x14,
0x24, 0x2A, 0x7F, 0x2A, 0x12,
0x23, 0x13, 0x08, 0x64, 0x62,
0x36, 0x49, 0x56, 0x20, 0x50,
0x00, 0x08, 0x07, 0x03, 0x00,
0x00, 0x1C, 0x22, 0x41, 0x00,
0x00, 0x41, 0x22, 0x1C, 0x00,
0x2A, 0x1C, 0x7F, 0x1C, 0x2A,
0x08, 0x08, 0x3E, 0x08, 0x08,
0x00, 0x80, 0x70, 0x30, 0x00,
0x08, 0x08, 0x08, 0x08, 0x08,
0x00, 0x00, 0x60, 0x60, 0x00,
0x20, 0x10, 0x08, 0x04, 0x02,
0x3E, 0x51, 0x49, 0x45, 0x3E,
0x00, 0x42, 0x7F, 0x40, 0x00,
0x72, 0x49, 0x49, 0x49, 0x46,
0x21, 0x41, 0x49, 0x4D, 0x33,
0x18, 0x14, 0x12, 0x7F, 0x10,
0x27, 0x45, 0x45, 0x45, 0x39,
0x3C, 0x4A, 0x49, 0x49, 0x31,
0x41, 0x21, 0x11, 0x09, 0x07,
0x36, 0x49, 0x49, 0x49, 0x36,
0x46, 0x49, 0x49, 0x29, 0x1E,
0x00, 0x00, 0x14, 0x00, 0x00,
0x00, 0x40, 0x34, 0x00, 0x00,
0x00, 0x08, 0x14, 0x22, 0x41,
0x14, 0x14, 0x14, 0x14, 0x14,
0x00, 0x41, 0x22, 0x14, 0x08,
0x02, 0x01, 0x59, 0x09, 0x06,
0x3E, 0x41, 0x5D, 0x59, 0x4E,
0x7C, 0x12, 0x11, 0x12, 0x7C,
0x7F, 0x49, 0x49, 0x49, 0x36,
0x3E, 0x41, 0x41, 0x41, 0x22,
0x7F, 0x41, 0x41, 0x41, 0x3E,
0x7F, 0x49, 0x49, 0x49, 0x41,
0x7F, 0x09, 0x09, 0x09, 0x01,
0x3E, 0x41, 0x41, 0x51, 0x73,
0x7F, 0x08, 0x08, 0x08, 0x7F,
0x00, 0x41, 0x7F, 0x41, 0x00,
0x20, 0x40, 0x41, 0x3F, 0x01,
0x7F, 0x08, 0x14, 0x22, 0x41,
0x7F, 0x40, 0x40, 0x40, 0x40,
0x7F, 0x02, 0x1C, 0x02, 0x7F,
0x7F, 0x04, 0x08, 0x10, 0x7F,
0x3E, 0x41, 0x41, 0x41, 0x3E,
0x7F, 0x09, 0x09, 0x09, 0x06,
0x3E, 0x41, 0x51, 0x21, 0x5E,
0x7F, 0x09, 0x19, 0x29, 0x46,
0x26, 0x49, 0x49, 0x49, 0x32,
0x03, 0x01, 0x7F, 0x01, 0x03,
0x3F, 0x40, 0x40, 0x40, 0x3F,
0x1F, 0x20, 0x40, 0x20, 0x1F,
0x3F, 0x40, 0x38, 0x40, 0x3F,
0x63, 0x14, 0x08, 0x14, 0x63,
0x03, 0x04, 0x78, 0x04, 0x03,
0x61, 0x59, 0x49, 0x4D, 0x43,
0x00, 0x7F, 0x41, 0x41, 0x41,
0x02, 0x04, 0x08, 0x10, 0x20,
0x00, 0x41, 0x41, 0x41, 0x7F,
0x04, 0x02, 0x01, 0x02, 0x04,
0x40, 0x40, 0x40, 0x40, 0x40,
0x00, 0x03, 0x07, 0x08, 0x00,
0x20, 0x54, 0x54, 0x78, 0x40,
0x7F, 0x28, 0x44, 0x44, 0x38,
0x38, 0x44, 0x44, 0x44, 0x28,
0x38, 0x44, 0x44, 0x28, 0x7F,
0x38, 0x54, 0x54, 0x54, 0x18,
0x00, 0x08, 0x7E, 0x09, 0x02,
0x18, 0xA4, 0xA4, 0x9C, 0x78,
0x7F, 0x08, 0x04, 0x04, 0x78,
0x00, 0x44, 0x7D, 0x40, 0x00,
0x20, 0x40, 0x40, 0x3D, 0x00,
0x7F, 0x10, 0x28, 0x44, 0x00,
0x00, 0x41, 0x7F, 0x40, 0x00,
0x7C, 0x04, 0x78, 0x04, 0x78,
0x7C, 0x08, 0x04, 0x04, 0x78,
0x38, 0x44, 0x44, 0x44, 0x38,
0xFC, 0x18, 0x24, 0x24, 0x18,
0x18, 0x24, 0x24, 0x18, 0xFC,
0x7C, 0x08, 0x04, 0x04, 0x08,
0x48, 0x54, 0x54, 0x54, 0x24,
0x04, 0x04, 0x3F, 0x44, 0x24,
0x3C, 0x40, 0x40, 0x20, 0x7C,
0x1C, 0x20, 0x40, 0x20, 0x1C,
0x3C, 0x40, 0x30, 0x40, 0x3C,
0x44, 0x28, 0x10, 0x28, 0x44,
0x4C, 0x90, 0x90, 0x90, 0x7C,
0x44, 0x64, 0x54, 0x4C, 0x44,
0x00, 0x08, 0x36, 0x41, 0x00,
0x00, 0x00, 0x77, 0x00, 0x00,
0x00, 0x41, 0x36, 0x08, 0x00,
0x02, 0x01, 0x02, 0x04, 0x02,
0x3C, 0x26, 0x23, 0x26, 0x3C,
0x1E, 0xA1, 0xA1, 0x61, 0x12,
0x3A, 0x40, 0x40, 0x20, 0x7A,
0x38, 0x54, 0x54, 0x55, 0x59,
0x21, 0x55, 0x55, 0x79, 0x41,
0x21, 0x54, 0x54, 0x78, 0x41,
0x21, 0x55, 0x54, 0x78, 0x40,
0x20, 0x54, 0x55, 0x79, 0x40,
0x0C, 0x1E, 0x52, 0x72, 0x12,
0x39, 0x55, 0x55, 0x55, 0x59,
0x39, 0x54, 0x54, 0x54, 0x59,
0x39, 0x55, 0x54, 0x54, 0x58,
0x00, 0x00, 0x45, 0x7C, 0x41,
0x00, 0x02, 0x45, 0x7D, 0x42,
0x00, 0x01, 0x45, 0x7C, 0x40,
0xF0, 0x29, 0x24, 0x29, 0xF0,
0xF0, 0x28, 0x25, 0x28, 0xF0,
0x7C, 0x54, 0x55, 0x45, 0x00,
0x20, 0x54, 0x54, 0x7C, 0x54,
0x7C, 0x0A, 0x09, 0x7F, 0x49,
0x32, 0x49, 0x49, 0x49, 0x32,
0x32, 0x48, 0x48, 0x48, 0x32,
0x32, 0x4A, 0x48, 0x48, 0x30,
0x3A, 0x41, 0x41, 0x21, 0x7A,
0x3A, 0x42, 0x40, 0x20, 0x78,
0x00, 0x9D, 0xA0, 0xA0, 0x7D,
0x39, 0x44, 0x44, 0x44, 0x39,
0x3D, 0x40, 0x40, 0x40, 0x3D,
0x3C, 0x24, 0xFF, 0x24, 0x24,
0x48, 0x7E, 0x49, 0x43, 0x66,
0x2B, 0x2F, 0xFC, 0x2F, 0x2B,
0xFF, 0x09, 0x29, 0xF6, 0x20,
0xC0, 0x88, 0x7E, 0x09, 0x03,
0x20, 0x54, 0x54, 0x79, 0x41,
0x00, 0x00, 0x44, 0x7D, 0x41,
0x30, 0x48, 0x48, 0x4A, 0x32,
0x38, 0x40, 0x40, 0x22, 0x7A,
0x00, 0x7A, 0x0A, 0x0A, 0x72,
0x7D, 0x0D, 0x19, 0x31, 0x7D,
0x26, 0x29, 0x29, 0x2F, 0x28,
0x26, 0x29, 0x29, 0x29, 0x26,
0x30, 0x48, 0x4D, 0x40, 0x20,
0x38, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x38,
0x2F, 0x10, 0xC8, 0xAC, 0xBA,
0x2F, 0x10, 0x28, 0x34, 0xFA,
0x00, 0x00, 0x7B, 0x00, 0x00,
0x08, 0x14, 0x2A, 0x14, 0x22,
0x22, 0x14, 0x2A, 0x14, 0x08,
0xAA, 0x00, 0x55, 0x00, 0xAA,
0xAA, 0x55, 0xAA, 0x55, 0xAA,
0x00, 0x00, 0x00, 0xFF, 0x00,
0x10, 0x10, 0x10, 0xFF, 0x00,
0x14, 0x14, 0x14, 0xFF, 0x00,
0x10, 0x10, 0xFF, 0x00, 0xFF,
0x10, 0x10, 0xF0, 0x10, 0xF0,
0x14, 0x14, 0x14, 0xFC, 0x00,
0x14, 0x14, 0xF7, 0x00, 0xFF,
0x00, 0x00, 0xFF, 0x00, 0xFF,
0x14, 0x14, 0xF4, 0x04, 0xFC,
0x14, 0x14, 0x17, 0x10, 0x1F,
0x10, 0x10, 0x1F, 0x10, 0x1F,
0x14, 0x14, 0x14, 0x1F, 0x00,
0x10, 0x10, 0x10, 0xF0, 0x00,
0x00, 0x00, 0x00, 0x1F, 0x10,
0x10, 0x10, 0x10, 0x1F, 0x10,
0x10, 0x10, 0x10, 0xF0, 0x10,
0x00, 0x00, 0x00, 0xFF, 0x10,
0x10, 0x10, 0x10, 0x10, 0x10,
0x10, 0x10, 0x10, 0xFF, 0x10,
0x00, 0x00, 0x00, 0xFF, 0x14,
0x00, 0x00, 0xFF, 0x00, 0xFF,
0x00, 0x00, 0x1F, 0x10, 0x17,
0x00, 0x00, 0xFC, 0x04, 0xF4,
0x14, 0x14, 0x17, 0x10, 0x17,
0x14, 0x14, 0xF4, 0x04, 0xF4,
0x00, 0x00, 0xFF, 0x00, 0xF7,
0x14, 0x14, 0x14, 0x14, 0x14,
0x14, 0x14, 0xF7, 0x00, 0xF7,
0x14, 0x14, 0x14, 0x17, 0x14,
0x10, 0x10, 0x1F, 0x10, 0x1F,
0x14, 0x14, 0x14, 0xF4, 0x14,
0x10, 0x10, 0xF0, 0x10, 0xF0,
0x00, 0x00, 0x1F, 0x10, 0x1F,
0x00, 0x00, 0x00, 0x1F, 0x14,
0x00, 0x00, 0x00, 0xFC, 0x14,
0x00, 0x00, 0xF0, 0x10, 0xF0,
0x10, 0x10, 0xFF, 0x10, 0xFF,
0x14, 0x14, 0x14, 0xFF, 0x14,
0x10, 0x10, 0x10, 0x1F, 0x00,
0x00, 0x00, 0x00, 0xF0, 0x10,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xFF, 0xFF, 0xFF, 0x00, 0x00,
0x00, 0x00, 0x00, 0xFF, 0xFF,
0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
0x38, 0x44, 0x44, 0x38, 0x44,
0x7C, 0x2A, 0x2A, 0x3E, 0x14,
0x7E, 0x02, 0x02, 0x06, 0x06,
0x02, 0x7E, 0x02, 0x7E, 0x02,
0x63, 0x55, 0x49, 0x41, 0x63,
0x38, 0x44, 0x44, 0x3C, 0x04,
0x40, 0x7E, 0x20, 0x1E, 0x20,
0x06, 0x02, 0x7E, 0x02, 0x02,
0x99, 0xA5, 0xE7, 0xA5, 0x99,
0x1C, 0x2A, 0x49, 0x2A, 0x1C,
0x4C, 0x72, 0x01, 0x72, 0x4C,
0x30, 0x4A, 0x4D, 0x4D, 0x30,
0x30, 0x48, 0x78, 0x48, 0x30,
0xBC, 0x62, 0x5A, 0x46, 0x3D,
0x3E, 0x49, 0x49, 0x49, 0x00,
0x7E, 0x01, 0x01, 0x01, 0x7E,
0x2A, 0x2A, 0x2A, 0x2A, 0x2A,
0x44, 0x44, 0x5F, 0x44, 0x44,
0x40, 0x51, 0x4A, 0x44, 0x40,
0x40, 0x44, 0x4A, 0x51, 0x40,
0x00, 0x00, 0xFF, 0x01, 0x03,
0xE0, 0x80, 0xFF, 0x00, 0x00,
0x08, 0x08, 0x6B, 0x6B, 0x08,
0x36, 0x12, 0x36, 0x24, 0x36,
0x06, 0x0F, 0x09, 0x0F, 0x06,
0x00, 0x00, 0x18, 0x18, 0x00,
0x00, 0x00, 0x10, 0x10, 0x00,
0x30, 0x40, 0xFF, 0x01, 0x01,
0x00, 0x1F, 0x01, 0x01, 0x1E,
0x00, 0x19, 0x1D, 0x17, 0x12,
0x00, 0x3C, 0x3C, 0x3C, 0x3C,
0x00, 0x00, 0x00, 0x00, 0x00
};
#endif

@ -0,0 +1,801 @@
/*********************************************************************
SSD1306 I2C Library for Raspberry Pi.
Based on Adafruit SSD1306 Arduino library. Some functions came from Adafruit GFX lib
Modified by Ilia Penev
Tested on Raspberry Pi 2 with 0.96 Yellow/Blue OLED
*********************************************************************/
/*********************************************************************
This is a library for our Monochrome OLEDs based on SSD1306 drivers
Pick one up today in the adafruit shop!
------> http://www.adafruit.com/category/63_98
These displays use SPI to communicate, 4 or 5 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, check license.txt for more information
All text above, and the splash screen below must be included in any redistribution
*********************************************************************/
#include <stdint.h>
#include <string.h>
#include "ssd1306_i2c.h"
#include "oled_fonts.h"
#define true 1
#define false 0
#define rotation 0
#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
int cursor_y = 0;
int cursor_x = 0;
// the memory buffer for the LCD. Displays Adafruit logo
uint16_t buffer[SSD1306_LCDWIDTH * SSD1306_LCDHEIGHT / 8] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80,
0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x80, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xF8, 0xE0,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x80, 0x80, 0x80,
0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80,
0x80, 0x80, 0x00, 0xFF,
#if (SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH > 96*16)
0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00,
0x80, 0x80, 0x00, 0x00,
0x80, 0xFF, 0xFF, 0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80,
0x80, 0x00, 0x80, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x8C, 0x8E, 0x84,
0x00, 0x00, 0x80, 0xF8,
0xF8, 0xF8, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xE0, 0xE0, 0xC0, 0x80,
0x00, 0xE0, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE,
0xFF, 0xC7, 0x01, 0x01,
0x01, 0x01, 0x83, 0xFF, 0xFF, 0x00, 0x00, 0x7C, 0xFE, 0xC7, 0x01, 0x01,
0x01, 0x01, 0x83, 0xFF,
0xFF, 0xFF, 0x00, 0x38, 0xFE, 0xC7, 0x83, 0x01, 0x01, 0x01, 0x83, 0xC7,
0xFF, 0xFF, 0x00, 0x00,
0x01, 0xFF, 0xFF, 0x01, 0x01, 0x00, 0xFF, 0xFF, 0x07, 0x01, 0x01, 0x01,
0x00, 0x00, 0x7F, 0xFF,
0x80, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x01, 0xFF,
0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x03, 0x0F, 0x3F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xE7, 0xC7, 0xC7, 0x8F,
0x8F, 0x9F, 0xBF, 0xFF, 0xFF, 0xC3, 0xC0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFC, 0xFC, 0xFC,
0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xF8, 0xF8, 0xF0, 0xF0, 0xE0, 0xC0, 0x00,
0x01, 0x03, 0x03, 0x03,
0x03, 0x03, 0x01, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03,
0x03, 0x03, 0x01, 0x01,
0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01,
0x03, 0x03, 0x00, 0x00,
0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01,
0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x01,
0x00, 0x00, 0x00, 0x03,
0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
#if (SSD1306_LCDHEIGHT == 64)
0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF9, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0x3F, 0x1F, 0x0F,
0x87, 0xC7, 0xF7, 0xFF, 0xFF, 0x1F, 0x1F, 0x3D, 0xFC, 0xF8, 0xF8, 0xF8,
0xF8, 0x7C, 0x7D, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x0F, 0x07, 0x00,
0x30, 0x30, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xE0, 0xC0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0xC0, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x7F, 0x7F, 0x3F, 0x1F,
0x0F, 0x07, 0x1F, 0x7F, 0xFF, 0xFF, 0xF8, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFE, 0xF8, 0xE0,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFE, 0xFE, 0x00, 0x00,
0x00, 0xFC, 0xFE, 0xFC, 0x0C, 0x06, 0x06, 0x0E, 0xFC, 0xF8, 0x00, 0x00,
0xF0, 0xF8, 0x1C, 0x0E,
0x06, 0x06, 0x06, 0x0C, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFE, 0xFE, 0x00,
0x00, 0x00, 0x00, 0xFC,
0xFE, 0xFC, 0x00, 0x18, 0x3C, 0x7E, 0x66, 0xE6, 0xCE, 0x84, 0x00, 0x00,
0x06, 0xFF, 0xFF, 0x06,
0x06, 0xFC, 0xFE, 0xFC, 0x0C, 0x06, 0x06, 0x06, 0x00, 0x00, 0xFE, 0xFE,
0x00, 0x00, 0xC0, 0xF8,
0xFC, 0x4E, 0x46, 0x46, 0x46, 0x4E, 0x7C, 0x78, 0x40, 0x18, 0x3C, 0x76,
0xE6, 0xCE, 0xCC, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x0F, 0x1F, 0x1F, 0x3F, 0x3F, 0x3F,
0x3F, 0x1F, 0x0F, 0x03,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0F, 0x0F, 0x00, 0x00,
0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00,
0x03, 0x07, 0x0E, 0x0C,
0x18, 0x18, 0x0C, 0x06, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x01, 0x0F, 0x0E,
0x0C, 0x18, 0x0C, 0x0F,
0x07, 0x01, 0x00, 0x04, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 0x07, 0x00, 0x00,
0x00, 0x0F, 0x0F, 0x00,
0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F,
0x00, 0x00, 0x00, 0x07,
0x07, 0x0C, 0x0C, 0x18, 0x1C, 0x0C, 0x06, 0x06, 0x00, 0x04, 0x0E, 0x0C,
0x18, 0x0C, 0x0F, 0x07,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
#endif
#endif
};
int _vccstate;
int i2cd;
#define ssd1306_swap(a, b) { int t = a; a = b; b = t; }
// the most basic function, set a single pixel
void ssd1306_drawPixel(int x, int y, unsigned int color)
{
if ((x < 0) || (x >= WIDTH) || (y < 0) || (y >= HEIGHT))
return;
// check rotation, move pixel around if necessary
switch (rotation) {
case 1:
ssd1306_swap(x, y);
x = WIDTH - x - 1;
break;
case 2:
x = WIDTH - x - 1;
y = HEIGHT - y - 1;
break;
case 3:
ssd1306_swap(x, y);
y = HEIGHT - y - 1;
break;
}
// x is which column
switch (color) {
case WHITE:
buffer[x + (y / 8) * SSD1306_LCDWIDTH] |= (1 << (y & 7));
break;
case BLACK:
buffer[x + (y / 8) * SSD1306_LCDWIDTH] &= ~(1 << (y & 7));
break;
case INVERSE:
buffer[x + (y / 8) * SSD1306_LCDWIDTH] ^= (1 << (y & 7));
break;
}
}
// Init SSD1306
void ssd1306_begin(i2c_t *i2c_dev, unsigned int vccstate, unsigned int i2caddr)
{
// I2C Init
_vccstate = vccstate;
// Init sequence
ssd1306_command(i2c_dev,SSD1306_DISPLAYOFF); // 0xAE
ssd1306_command(i2c_dev,SSD1306_SETDISPLAYCLOCKDIV); // 0xD5
ssd1306_command(i2c_dev,0x80); // the suggested ratio 0x80
ssd1306_command(i2c_dev,SSD1306_SETMULTIPLEX); // 0xA8
ssd1306_command(i2c_dev,SSD1306_LCDHEIGHT - 1);
ssd1306_command(i2c_dev,SSD1306_SETDISPLAYOFFSET); // 0xD3
ssd1306_command(i2c_dev,0x0); // no offset
ssd1306_command(i2c_dev,SSD1306_SETSTARTLINE | 0x0); // line #0
ssd1306_command(i2c_dev,SSD1306_CHARGEPUMP); // 0x8D
if (vccstate == SSD1306_EXTERNALVCC) {
ssd1306_command(i2c_dev,0x10);
} else {
ssd1306_command(i2c_dev,0x14);
}
ssd1306_command(i2c_dev,SSD1306_MEMORYMODE); // 0x20
ssd1306_command(i2c_dev,0x00); // 0x0 act like ks0108
ssd1306_command(i2c_dev,SSD1306_SEGREMAP | 0x1);
ssd1306_command(i2c_dev,SSD1306_COMSCANDEC);
#if defined SSD1306_128_32
ssd1306_command(i2c_dev,SSD1306_SETCOMPINS); // 0xDA
ssd1306_command(i2c_dev,0x02);
ssd1306_command(i2c_dev,SSD1306_SETCONTRAST); // 0x81
ssd1306_command(i2c_dev,0x8F);
#elif defined SSD1306_128_64
ssd1306_command(i2c_dev,SSD1306_SETCOMPINS); // 0xDA
ssd1306_command(i2c_dev,0x12);
ssd1306_command(i2c_dev,SSD1306_SETCONTRAST); // 0x81
if (vccstate == SSD1306_EXTERNALVCC) {
ssd1306_command(i2c_dev,0x9F);
} else {
ssd1306_command(i2c_dev,0xCF);
}
#elif defined SSD1306_96_16
ssd1306_command(i2c_dev,SSD1306_SETCOMPINS); // 0xDA
ssd1306_command(i2c_dev,0x2); // ada x12
ssd1306_command(i2c_dev,SSD1306_SETCONTRAST); // 0x81
if (vccstate == SSD1306_EXTERNALVCC) {
ssd1306_command(i2c_dev,0x10);
} else {
ssd1306_command(i2c_dev,0xAF);
}
#endif
ssd1306_command(i2c_dev,SSD1306_SETPRECHARGE); // 0xd9
if (vccstate == SSD1306_EXTERNALVCC) {
ssd1306_command(i2c_dev,0x22);
} else {
ssd1306_command(i2c_dev,0xF1);
}
ssd1306_command(i2c_dev,SSD1306_SETVCOMDETECT); // 0xDB
ssd1306_command(i2c_dev,0x40);
ssd1306_command(i2c_dev,SSD1306_DISPLAYALLON_RESUME); // 0xA4
ssd1306_command(i2c_dev,SSD1306_NORMALDISPLAY); // 0xA6
ssd1306_command(i2c_dev,SSD1306_DEACTIVATE_SCROLL);
ssd1306_command(i2c_dev,SSD1306_DISPLAYON); // --turn on oled panel
}
void ssd1306_invertDisplay(i2c_t *i2c_dev, unsigned int i)
{
if (i) {
ssd1306_command(i2c_dev,SSD1306_INVERTDISPLAY);
} else {
ssd1306_command(i2c_dev,SSD1306_NORMALDISPLAY);
}
}
void ssd1306_command(i2c_t *i2c_dev,unsigned int c)
{
// I2C
unsigned int control = 0x00; // Co = 0, D/C = 0
unsigned char i2cDataLenght = 1; // Co = 0, D/C = 0
unsigned int address = SSD1306_I2C_ADDRESS; // Co = 0, D/C = 0
i2c_write(i2c_dev, &address, &control, &c, &i2cDataLenght);
}
void ssd1306_display(i2c_t *i2c_dev)
{
ssd1306_command(i2c_dev,SSD1306_COLUMNADDR);
ssd1306_command(i2c_dev,0); // Column start address (0 = reset)
ssd1306_command(i2c_dev,SSD1306_LCDWIDTH - 1); // Column end address (127
// = reset)
ssd1306_command(i2c_dev,SSD1306_PAGEADDR);
ssd1306_command(i2c_dev,0); // Page start address (0 = reset)
#if SSD1306_LCDHEIGHT == 64
ssd1306_command(i2c_dev,7); // Page end address
#endif
#if SSD1306_LCDHEIGHT == 32
ssd1306_command(i2c_dev,3); // Page end address
#endif
#if SSD1306_LCDHEIGHT == 16
ssd1306_command(i2c_dev,1); // Page end address
#endif
unsigned char i2cDataLenght = 1; // Co = 0, D/C = 0
unsigned int address = SSD1306_I2C_ADDRESS; // Co = 0, D/C = 0
uint8_t reg = 0x40;
// I2C
int i;
for (i = 0; i < (SSD1306_LCDWIDTH * SSD1306_LCDHEIGHT / 8); i++) {
i2c_write(i2c_dev, &address, &reg, &buffer[i], &i2cDataLenght);
//This sends byte by byte.
//Better to send all buffer without 0x40 first
//Should be optimized
}
}
// startscrollright
// Activate a right handed scroll for rows start through stop
// Hint, the display is 16 rows tall. To scroll the whole display, run:
// ssd1306_scrollright(0x00, 0x0F)
void ssd1306_startscrollright(i2c_t *i2c_dev, unsigned int start, unsigned int stop)
{
ssd1306_command(i2c_dev,SSD1306_RIGHT_HORIZONTAL_SCROLL);
ssd1306_command(i2c_dev,0X00);
ssd1306_command(i2c_dev,start);
ssd1306_command(i2c_dev,0X00);
ssd1306_command(i2c_dev,stop);
ssd1306_command(i2c_dev,0X00);
ssd1306_command(i2c_dev,0XFF);
ssd1306_command(i2c_dev,SSD1306_ACTIVATE_SCROLL);
}
// startscrollleft
// Activate a right handed scroll for rows start through stop
// Hint, the display is 16 rows tall. To scroll the whole display, run:
// ssd1306_scrollright(0x00, 0x0F)
void ssd1306_startscrollleft(i2c_t *i2c_dev,unsigned int start, unsigned int stop)
{
ssd1306_command(i2c_dev,SSD1306_LEFT_HORIZONTAL_SCROLL);
ssd1306_command(i2c_dev,0X00);
ssd1306_command(i2c_dev,start);
ssd1306_command(i2c_dev,0X00);
ssd1306_command(i2c_dev,stop);
ssd1306_command(i2c_dev,0X00);
ssd1306_command(i2c_dev,0XFF);
ssd1306_command(i2c_dev,SSD1306_ACTIVATE_SCROLL);
}
// startscrolldiagright
// Activate a diagonal scroll for rows start through stop
// Hint, the display is 16 rows tall. To scroll the whole display, run:
// ssd1306_scrollright(0x00, 0x0F)
void ssd1306_startscrolldiagright(i2c_t *i2c_dev, unsigned int start, unsigned int stop)
{
ssd1306_command(i2c_dev,SSD1306_SET_VERTICAL_SCROLL_AREA);
ssd1306_command(i2c_dev,0X00);
ssd1306_command(i2c_dev,SSD1306_LCDHEIGHT);
ssd1306_command(i2c_dev,SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL);
ssd1306_command(i2c_dev,0X00);
ssd1306_command(i2c_dev,start);
ssd1306_command(i2c_dev,0X00);
ssd1306_command(i2c_dev,stop);
ssd1306_command(i2c_dev,0X01);
ssd1306_command(i2c_dev,SSD1306_ACTIVATE_SCROLL);
}
// startscrolldiagleft
// Activate a diagonal scroll for rows start through stop
// Hint, the display is 16 rows tall. To scroll the whole display, run:
// ssd1306_scrollright(0x00, 0x0F)
void ssd1306_startscrolldiagleft(i2c_t *i2c_dev, unsigned int start, unsigned int stop)
{
ssd1306_command(i2c_dev,SSD1306_SET_VERTICAL_SCROLL_AREA);
ssd1306_command(i2c_dev,0X00);
ssd1306_command(i2c_dev,SSD1306_LCDHEIGHT);
ssd1306_command(i2c_dev,SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL);
ssd1306_command(i2c_dev,0X00);
ssd1306_command(i2c_dev,start);
ssd1306_command(i2c_dev,0X00);
ssd1306_command(i2c_dev,stop);
ssd1306_command(i2c_dev,0X01);
ssd1306_command(i2c_dev,SSD1306_ACTIVATE_SCROLL);
}
void ssd1306_stopscroll(i2c_t *i2c_dev)
{
ssd1306_command(i2c_dev,SSD1306_DEACTIVATE_SCROLL);
}
// Dim the display
// dim = true: display is dimmed
// dim = false: display is normal
void ssd1306_dim(i2c_t *i2c_dev, unsigned int dim)
{
unsigned int contrast;
if (dim) {
contrast = 0; // Dimmed display
} else {
if (_vccstate == SSD1306_EXTERNALVCC) {
contrast = 0x9F;
} else {
contrast = 0xCF;
}
}
// the range of contrast to too small to be really useful
// it is useful to dim the display
ssd1306_command(i2c_dev,SSD1306_SETCONTRAST);
ssd1306_command(i2c_dev,contrast);
}
// clear everything
void ssd1306_clearDisplay(void)
{
memset(buffer, 0,
(SSD1306_LCDWIDTH * SSD1306_LCDHEIGHT / 8) * sizeof(int));
cursor_y = 0;
cursor_x = 0;
}
void ssd1306_drawFastHLineInternal(int x, int y, int w, unsigned int color)
{
// Do bounds/limit checks
if (y < 0 || y >= HEIGHT) {
return;
}
// make sure we don't try to draw below 0
if (x < 0) {
w += x;
x = 0;
}
// make sure we don't go off the edge of the display
if ((x + w) > WIDTH) {
w = (WIDTH - x);
}
// if our width is now negative, punt
if (w <= 0) {
return;
}
// set up the pointer for movement through the buffer
unsigned int *pBuf = buffer;
// adjust the buffer pointer for the current row
pBuf += ((y / 8) * SSD1306_LCDWIDTH);
// and offset x columns in
pBuf += x;
unsigned int mask = 1 << (y & 7);
switch (color) {
case WHITE:
while (w--) {
*pBuf++ |= mask;
};
break;
case BLACK:
mask = ~mask;
while (w--) {
*pBuf++ &= mask;
};
break;
case INVERSE:
while (w--) {
*pBuf++ ^= mask;
};
break;
}
}
void ssd1306_drawFastVLineInternal(int x, int __y, int __h, unsigned int color)
{
// do nothing if we're off the left or right side of the screen
if (x < 0 || x >= WIDTH) {
return;
}
// make sure we don't try to draw below 0
if (__y < 0) {
// __y is negative, this will subtract enough from __h to account
// for __y being 0
__h += __y;
__y = 0;
}
// make sure we don't go past the height of the display
if ((__y + __h) > HEIGHT) {
__h = (HEIGHT - __y);
}
// if our height is now negative, punt
if (__h <= 0) {
return;
}
// this display doesn't need ints for coordinates, use local byte
// registers for faster juggling
unsigned int y = __y;
unsigned int h = __h;
// set up the pointer for fast movement through the buffer
unsigned int *pBuf = buffer;
// adjust the buffer pointer for the current row
pBuf += ((y / 8) * SSD1306_LCDWIDTH);
// and offset x columns in
pBuf += x;
// do the first partial byte, if necessary - this requires some
// masking
unsigned int mod = (y & 7);
if (mod) {
// mask off the high n bits we want to set
mod = 8 - mod;
// note - lookup table results in a nearly 10% performance
// improvement in fill* functions
// register unsigned int mask = ~(0xFF >> (mod));
static unsigned int premask[8] =
{ 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE };
unsigned int mask = premask[mod];
// adjust the mask if we're not going to reach the end of this
// byte
if (h < mod) {
mask &= (0XFF >> (mod - h));
}
switch (color) {
case WHITE:
*pBuf |= mask;
break;
case BLACK:
*pBuf &= ~mask;
break;
case INVERSE:
*pBuf ^= mask;
break;
}
// fast exit if we're done here!
if (h < mod) {
return;
}
h -= mod;
pBuf += SSD1306_LCDWIDTH;
}
// write solid bytes while we can - effectively doing 8 rows at a time
if (h >= 8) {
if (color == INVERSE) { // separate copy of the code so we don't
// impact performance of the black/white
// write version with an extra comparison
// per loop
do {
*pBuf = ~(*pBuf);
// adjust the buffer forward 8 rows worth of data
pBuf += SSD1306_LCDWIDTH;
// adjust h & y (there's got to be a faster way for me to
// do this, but this should still help a fair bit for now)
h -= 8;
}
while (h >= 8);
} else {
// store a local value to work with
register unsigned int val = (color == WHITE) ? 255 : 0;
do {
// write our value in
*pBuf = val;
// adjust the buffer forward 8 rows worth of data
pBuf += SSD1306_LCDWIDTH;
// adjust h & y (there's got to be a faster way for me to
// do this, but this should still help a fair bit for now)
h -= 8;
}
while (h >= 8);
}
}
// now do the final partial byte, if necessary
if (h) {
mod = h & 7;
// this time we want to mask the low bits of the byte, vs the high
// bits we did above
// register unsigned int mask = (1 << mod) - 1;
// note - lookup table results in a nearly 10% performance
// improvement in fill* functions
static unsigned int postmask[8] =
{ 0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F };
unsigned int mask = postmask[mod];
switch (color) {
case WHITE:
*pBuf |= mask;
break;
case BLACK:
*pBuf &= ~mask;
break;
case INVERSE:
*pBuf ^= mask;
break;
}
}
}
void ssd1306_drawFastHLine(int x, int y, int w, unsigned int color)
{
unsigned int bSwap = false;
switch (rotation) {
case 0:
// 0 degree rotation, do nothing
break;
case 1:
// 90 degree rotation, swap x & y for rotation, then invert x
bSwap = true;
ssd1306_swap(x, y);
x = WIDTH - x - 1;
break;
case 2:
// 180 degree rotation, invert x and y - then shift y around for
// height.
x = WIDTH - x - 1;
y = HEIGHT - y - 1;
x -= (w - 1);
break;
case 3:
// 270 degree rotation, swap x & y for rotation, then invert y and
// adjust y for w (not to become h)
bSwap = true;
ssd1306_swap(x, y);
y = HEIGHT - y - 1;
y -= (w - 1);
break;
}
if (bSwap) {
ssd1306_drawFastVLineInternal(x, y, w, color);
} else {
ssd1306_drawFastHLineInternal(x, y, w, color);
}
}
void ssd1306_drawFastVLine(int x, int y, int h, unsigned int color)
{
unsigned int bSwap = false;
switch (rotation) {
case 0:
break;
case 1:
// 90 degree rotation, swap x & y for rotation, then invert x and
// adjust x for h (now to become w)
bSwap = true;
ssd1306_swap(x, y);
x = WIDTH - x - 1;
x -= (h - 1);
break;
case 2:
// 180 degree rotation, invert x and y - then shift y around for
// height.
x = WIDTH - x - 1;
y = HEIGHT - y - 1;
y -= (h - 1);
break;
case 3:
// 270 degree rotation, swap x & y for rotation, then invert y
bSwap = true;
ssd1306_swap(x, y);
y = HEIGHT - y - 1;
break;
}
if (bSwap) {
ssd1306_drawFastHLineInternal(x, y, h, color);
} else {
ssd1306_drawFastVLineInternal(x, y, h, color);
}
}
void ssd1306_fillRect(int x, int y, int w, int h, int fillcolor)
{
// Bounds check
if ((x >= WIDTH) || (y >= HEIGHT))
return;
// Y bounds check
if (y + h > HEIGHT) {
h = HEIGHT - y - 1;
}
// X bounds check
if (x + w > WIDTH) {
w = WIDTH - x - 1;
}
switch (rotation) {
case 1:
swap_values(x, y);
x = WIDTH - x - 1;
break;
case 2:
x = WIDTH - x - 1;
y = HEIGHT - y - 1;
break;
case 3:
swap_values(x, y);
y = HEIGHT - y - 1;
break;
}
int i;
for (i = 0; i < h; i++)
ssd1306_drawFastHLine(x, y + i, w, fillcolor);
}
int textsize = 1;
int wrap = 1;
void ssd1306_setTextSize(int s)
{
textsize = (s > 0) ? s : 1;
}
void ssd1306_write(int c)
{
if (c == '\n') {
cursor_y += textsize * 8;
cursor_x = 0;
} else if (c == '\r') {
// skip em
} else {
ssd1306_drawChar(cursor_x, cursor_y, c, WHITE, textsize);
cursor_x += textsize * 6;
if (wrap && (cursor_x > (WIDTH - textsize * 6))) {
cursor_y += textsize * 8;
cursor_x = 0;
}
}
}
void ssd1306_drawString(char *str)
{
int i, end;
end = strlen(str);
for (i = 0; i < end; i++)
ssd1306_write(str[i]);
}
// Draw a character
void ssd1306_drawChar(int x, int y, unsigned char c, int color, int size)
{
if ((x >= WIDTH) || // Clip right
(y >= HEIGHT) || // Clip bottom
((x + 6 * size - 1) < 0) || // Clip left
((y + 8 * size - 1) < 0)) // Clip top
return;
int i;
int j;
for (i = 0; i < 6; i++) {
int line;
if (i == 5)
line = 0x0;
else
line = pgm_read_byte(font + (c * 5) + i);
for (j = 0; j < 8; j++) {
if (line & 0x1) {
if (size == 1) // default size
ssd1306_drawPixel(x + i, y + j, color);
else { // big size
ssd1306_fillRect(x + (i * size),
y + (j * size), size,
size, color);
}
}
line >>= 1;
}
}
}

@ -0,0 +1,167 @@
/*********************************************************************
SSD1306 I2C Library for Raspberry Pi.
Based on Adafruit SSD1306 Arduino library. Some functions came from Adafruit GFX lib.
Modified by Ilia Penev
Tested on Raspberry Pi 2 with 0.96 Yellow/Blue OLED
*********************************************************************/
/*********************************************************************
This is a library for our Monochrome OLEDs based on SSD1306 drivers
Pick one up today in the adafruit shop!
------> http://www.adafruit.com/category/63_98
These displays use SPI to communicate, 4 or 5 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, check license.txt for more information
All text above, and the splash screen must be included in any redistribution
*********************************************************************/
#ifndef SSD1306_I2C_H_
#define SSD1306_I2C_H_
#include "i2c.h"
#define BLACK 0
#define WHITE 1
#define INVERSE 2
#define SSD1306_I2C_ADDRESS 0x3C // 011110+SA0+RW - 0x3C or 0x3D
// Address for 128x32 is 0x3C
// Address for 128x64 is 0x3D (default) or 0x3C (if SA0 is grounded)
/*=========================================================================
SSD1306 Displays
-----------------------------------------------------------------------
The driver is used in multiple displays (128x64, 128x32, etc.).
Select the appropriate display below to create an appropriately
sized framebuffer, etc.
SSD1306_128_64 128x64 pixel display
SSD1306_128_32 128x32 pixel display
SSD1306_96_16
-----------------------------------------------------------------------*/
#define SSD1306_128_64
// #define SSD1306_128_32
// #define SSD1306_96_16
/*=========================================================================*/
#if defined SSD1306_128_32
#define WIDTH 128
#define HEIGHT 32
#endif
#if defined SSD1306_128_64
#define WIDTH 128
#define HEIGHT 64
#endif
#if defined SSD1306_96_16
#define WIDTH 96
#define HEIGHT 16
#endif
#if defined SSD1306_128_64 && defined SSD1306_128_32
#error "Only one SSD1306 display can be specified at once in SSD1306.h"
#endif
#if !defined SSD1306_128_64 && !defined SSD1306_128_32 && !defined SSD1306_96_16
#error "At least one SSD1306 display must be specified in SSD1306.h"
#endif
#if defined SSD1306_128_64
#define SSD1306_LCDWIDTH 128
#define SSD1306_LCDHEIGHT 64
#endif
#if defined SSD1306_128_32
#define SSD1306_LCDWIDTH 128
#define SSD1306_LCDHEIGHT 32
#endif
#if defined SSD1306_96_16
#define SSD1306_LCDWIDTH 96
#define SSD1306_LCDHEIGHT 16
#endif
#define SSD1306_SETCONTRAST 0x81
#define SSD1306_DISPLAYALLON_RESUME 0xA4
#define SSD1306_DISPLAYALLON 0xA5
#define SSD1306_NORMALDISPLAY 0xA6
#define SSD1306_INVERTDISPLAY 0xA7
#define SSD1306_DISPLAYOFF 0xAE
#define SSD1306_DISPLAYON 0xAF
#define SSD1306_SETDISPLAYOFFSET 0xD3
#define SSD1306_SETCOMPINS 0xDA
#define SSD1306_SETVCOMDETECT 0xDB
#define SSD1306_SETDISPLAYCLOCKDIV 0xD5
#define SSD1306_SETPRECHARGE 0xD9
#define SSD1306_SETMULTIPLEX 0xA8
#define SSD1306_SETLOWCOLUMN 0x00
#define SSD1306_SETHIGHCOLUMN 0x10
#define SSD1306_SETSTARTLINE 0x40
#define SSD1306_MEMORYMODE 0x20
#define SSD1306_COLUMNADDR 0x21
#define SSD1306_PAGEADDR 0x22
#define SSD1306_COMSCANINC 0xC0
#define SSD1306_COMSCANDEC 0xC8
#define SSD1306_SEGREMAP 0xA0
#define SSD1306_CHARGEPUMP 0x8D
#define SSD1306_EXTERNALVCC 0x1
#define SSD1306_SWITCHCAPVCC 0x2
// Scrolling #defines
#define SSD1306_ACTIVATE_SCROLL 0x2F
#define SSD1306_DEACTIVATE_SCROLL 0x2E
#define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3
#define SSD1306_RIGHT_HORIZONTAL_SCROLL 0x26
#define SSD1306_LEFT_HORIZONTAL_SCROLL 0x27
#define SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29
#define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A
//switchvcc should be SSD1306_SWITCHCAPVCC
void ssd1306_begin(i2c_t *i2c_dev, unsigned int vccstate, unsigned int i2caddr);
void ssd1306_command(i2c_t *i2c_dev,unsigned int c);
void ssd1306_display(i2c_t *i2c_dev);
void ssd1306_invertDisplay(i2c_t *i2c_dev, unsigned int i);
void ssd1306_display(i2c_t *i2c_dev);
void ssd1306_startscrollright(i2c_t *i2c_dev, unsigned int start, unsigned int stop);
void ssd1306_startscrollleft(i2c_t *i2c_dev,unsigned int start, unsigned int stop);
void ssd1306_startscrolldiagright(i2c_t *i2c_dev, unsigned int start, unsigned int stop);
void ssd1306_startscrolldiagleft(i2c_t *i2c_dev, unsigned int start, unsigned int stop);
void ssd1306_stopscroll(i2c_t *i2c_dev);
void ssd1306_dim(i2c_t *i2c_dev, unsigned int dim);
void ssd1306_drawPixel(int x, int y, unsigned int color);
void ssd1306_drawFastVLine(int x, int y, int h, unsigned int color);
void ssd1306_drawFastHLine(int x, int y, int w, unsigned int color);
void ssd1306_fillRect(int x, int y, int w, int h, int fillcolor);
void ssd1306_setTextSize(int s);
void ssd1306_drawString(char *str);
void ssd1306_drawChar(int x, int y, unsigned char c, int color, int size);
#endif /* _SSD1306_I2C_H_ */

@ -0,0 +1,182 @@
#include "main.h"
#include "delay.h"
#include "deviceSetup.h"
#include "usart.h"
#include "ascii.h"
#include "timer.h"
#include "i2c.h"
#include "ssd1306_i2c.h"
void timer_test(timerNo_t timer, pinNo_t pin)
{
timerInitCounter(timer, 4000, 999, downCounting);
timerSart(timer);
for(int i = 0; i < 10 ; i++)
{
while(!timerGetUpdateInterrupt(timer));
timerClearUpdateInterrupt(timer);
pinToggle(pin);
}
pinWrite(pin,0);
}
void timer_capture_compare_test(timerNo_t timer)
{
uint16_t i = 0;
timerInitCounter(timer, 100, 99, downCounting);
// We use pin PA3 (Arduino header A2)
//timerInitOutputCompare(timer, toggle, 4, pinA3, 2,0, 300);
timerInitOutputCompare(timer, pwm_normal, 2, pinB3, 2,0, 900);
timerSart(timer);
while(1){
delayMs(200);
timerSetCounterCompareValue(timer, 2, i);
i += 10;
if(i>99) i = 0;
}
}
void printBinary32(uint32_t toPrint, uint8_t lsbFirst)
{
int i;
char pt;
if(lsbFirst)
{
print_Usart(usart2, "Bit Pos | 0| 1| 2| 3| 4| 5| 6| 7| 8| 9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|");
print_Usart(usart2, "\n\r");
print_Usart(usart2, "Bits |");
for(i=0; i < 32; i++)
{
pt = (toPrint >> i) & 1;
usartSendChar(usart2, ' ');
usartSendChar(usart2, pt + 0x30);
usartSendChar(usart2, '|');
}
}
else
{
print_Usart(usart2, "Bit Pos |31|30|29|28|27|26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10| 9| 8| 7| 6| 5| 4| 3| 2| 1| 0|");
print_Usart(usart2, "\n\r");
print_Usart(usart2, "Bits |");
for(i=0; i < 32; i++)
{
pt = (toPrint >> (31-i)) & 1;
usartSendChar(usart2, ' ');
usartSendChar(usart2, pt + 0x30);
usartSendChar(usart2, '|');
}
}
}
void printBinary8(uint8_t toPrint, uint8_t lsbFirst)
{
int i;
char pt;
if(lsbFirst)
{
print_Usart(usart2, "Bit Pos | 0| 1| 2| 3| 4| 5| 6| 7|");
print_Usart(usart2, "\n\r");
print_Usart(usart2, "Bits |");
for(i=0; i < 8; i++)
{
pt = (toPrint >> i) & 1;
usartSendChar(usart2, ' ');
usartSendChar(usart2, pt + 0x30);
usartSendChar(usart2, '|');
}
}
else
{
print_Usart(usart2, "Bit Pos | 7| 6| 5| 4| 3| 2| 1| 0|");
print_Usart(usart2, "\n\r");
print_Usart(usart2, "Bits |");
for(i=0; i < 8; i++)
{
pt = (toPrint >> (7-i)) & 1;
usartSendChar(usart2, ' ');
usartSendChar(usart2, pt + 0x30);
usartSendChar(usart2, '|');
}
}
}
int main(int argc, char *argv[])
{
uint8_t i = 0;
uint16_t slaveAddress = 0xC0;
uint8_t registerToRead = 0x00;
uint8_t i2cRecieved = 0;
uint8_t i2cData = 0xFF;
uint8_t i2cDataLenght = 1;
i2c_t i2c_1;
delayInitMs(8000000, 1000); // Clock Freq and Divider for ARM library
pinConfig(pinB3, output, pushPull, def_res, def_speed);
pinConfig(pinA0, input, def_stage, pullDown, def_speed);
setupInit(); // This is the sescond call of System init the assebly start code is calling it before the main.
usartInit( usart2,
pinA2,
pinA15,
115200,
eight,
NO_PARITY_CTRL,
noFlowControl);
//clears screen and send the wellcome messgae
print_Usart(usart2, ASCII_clear);
print_Usart(usart2, "Hello to our KED project\n\r");
//blinks 10 times to indicate the sicsessfull init if the device
for(i = 0 ; i < 2 ; i++) {
delayMs(100);
pinToggle(pinB3);
delayMs(100);
}
pinWrite(pinB3,0);
i2c_init(&i2c_1, I2C_CH_1, i2c_mode_master, 0x00,0x00, i2c_address_count_single, i2c_address_size_7b, i2c_clk_speed_standart, i2c_clk_stretching_disable, i2c_wake_disabled);
slaveAddress = SSD1306_I2C_ADDRESS;
registerToRead = 0x02;
registerToRead = 0x06;
i2cData = 0xAA;
i2c_check_device(&i2c_1, &slaveAddress);
// i2c_write(&i2c_1, &slaveAddress, &registerToRead, &i2cData, &i2cDataLenght);
// i2c_read(&i2c_1, &slaveAddress, &registerToRead, &i2cRecieved,&i2cDataLenght);
print_Usart(usart2, "\n\r");
print_Usart(usart2, "All Is Working fine ");
print_Usart(usart2, "\n\r");
ssd1306_begin(&i2c_1, SSD1306_SWITCHCAPVCC, SSD1306_I2C_ADDRESS);
delayMs(5);
ssd1306_begin(&i2c_1, SSD1306_SWITCHCAPVCC, SSD1306_I2C_ADDRESS);
delayMs(5);
ssd1306_display(&i2c_1); //Adafruit logo is visible
delayMs(5000);
while(1)
{
delayMs(100);
pinToggle(pinB3);
delayMs(100);
}
return 1;
}

@ -0,0 +1,15 @@
#ifndef MAIN_H
#define MAIN_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#ifdef __cplusplus
}
#endif
#endif /* MAIN_H */

@ -0,0 +1,20 @@
#Declareing header directory for the project
#To add a new directory
# -> list(APPEND PROJECT_HEADERS_DIR ${PROJECT_DIR}/YOUR_DESIRED_DIRECTORY)
# list() = List declaration "DON'T CHANGE"
# PROJECT_HEADERS_DIR = Variable containing the listed direcotries "DON'T CHANCE
# ${PROJECT_DIR} = Direcotry of the main project this is per default the current direcotry it is defined in ked/CMakeLists.txt
list(APPEND PROJECT_HEADERS_DIR ${PROJECT_DIR})
#Declaring sources directory for the project
#To add a new directory
# -> list(APPEND PROJECT_SOURCES_DIR ${PROJECT_DIR}/YOUR_DESIRED_DIRECTORY)
# list() = List declaration "DON'T CHANGE"
# PROJECT_SOURCES_DIR = Variable containing the listed direcotries "DON'T CHANCE
# ${PROJECT_DIR} = Direcotry of the main project this is per default the current direcotry it is defined in ked/CMakeLists.txt
# list(APPEND PROJECT_SOURCES_DIR ${PROJECT_DIR}/src)
#Declaring sources to be compiled for the project.
#CMake will look in each previsouly declarec sources directory until to find this files.
# set(PROJECT_SOURCES_DIR_LIST uartComm sensor)

@ -7,6 +7,28 @@ PROJECT_DIR=$SCRIPT_DIR/..
BUILD_DIR=$SCRIPT_DIR/../ked_build
cd $SCRIPT_DIR
stmLinkInstall()
{
# https://github.com/stlink-org/stlink/blob/develop/doc/compiling.md
echo -e "\e[36m"
echo "+--------------------------------------+"
echo -e "\tInstalling STM link"
echo "+--------------------------------------+"
echo -e "\e[32m"
sudo apt install gcc cmake libusb-1.0 libusb-1.0-0-dev
git clone https://github.com/stlink-org/stlink.git
cd stlink
sudo make install
sudo ldconfig
echo -e "\e[36m"
echo "+--------------------------------------+"
echo -e "\tIntalling Finished"
echo "+--------------------------------------+"
echo -e "\e[32m"
}
build()
{
if [ -z "$CSL_TO_USE" ];then
@ -55,7 +77,7 @@ build()
echo "+--------------------------------------+"
echo -e "\e[32m"
st-flash write $CSL_TO_USE.bin 0x08000000
sudo st-flash write $CSL_TO_USE.bin 0x08000000
echo -e "\e[36m"
echo "+--------------------------------------+"
@ -68,13 +90,18 @@ build()
autoInit()
{
if [[ -f "$SCRIPT_DIR/../main.c" ]];then
build
if [ "$CSL_TO_USE" == "install" ];then
stmLinkInstall
else
echo "Main.c is not fount"
echo "Creating sample project"
cp -r $SCRIPT_DIR/examples/autoInit/* $PROJECT_DIR/
build
if [[ -f "$SCRIPT_DIR/../main.c" ]];then
build
else
echo "Main.c is not fount"
echo "Creating sample project"
cp -r $SCRIPT_DIR/examples/autoInit/* $PROJECT_DIR/
build
fi
fi
}

Loading…
Cancel
Save