102 lines
2.6 KiB
C
102 lines
2.6 KiB
C
/*
|
|
* (c) danielinux 2019
|
|
* GPLv.2
|
|
*
|
|
* See LICENSE for details
|
|
*/
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include "display.h"
|
|
#include "systick.h"
|
|
#include "system.h"
|
|
|
|
|
|
static uint8_t contrast = 0xcf;
|
|
|
|
|
|
void display_scroll(void *priv, uint8_t line)
|
|
{
|
|
display_send_cmd1(priv, SSD1306_SETSTARTLINE, (line % 0x40) + 0x40);
|
|
}
|
|
|
|
void display_setcontrast(void *priv, uint8_t c)
|
|
{
|
|
contrast = c;
|
|
display_send_cmd1(priv, SSD1306_SETCONTRAST, contrast);
|
|
}
|
|
|
|
uint8_t display_getcontrast(void *priv)
|
|
{
|
|
return contrast;
|
|
}
|
|
|
|
void display_clear(void *priv)
|
|
{
|
|
|
|
int i,j;
|
|
uint8_t zeros[8] = {0, 0, 0, 0, 0, 0, 0, 0 };
|
|
display_send_cmd(NULL, 0x00);
|
|
display_send_cmd(NULL, 0x10);
|
|
|
|
for (i = 0; i < 8; i++)
|
|
{
|
|
display_send_cmd2(NULL, SSD1306_PAGEADDR, i, 0xFF);
|
|
for (j = 0; j < WIDTH; j++)
|
|
display_send_data(NULL, zeros, 8);
|
|
}
|
|
}
|
|
|
|
void display_text(int row, const char *text)
|
|
{
|
|
int k;
|
|
display_send_cmd(NULL, 0x00);
|
|
display_send_cmd(NULL, 0x10);
|
|
display_send_cmd2(NULL, SSD1306_PAGEADDR, 7 - row, 0xFF);
|
|
for(k = 0; k < strlen(text); k++)
|
|
display_send_data(NULL, fb_font[text[k]], 8);
|
|
}
|
|
|
|
int display_init(void *priv)
|
|
{
|
|
int i;
|
|
int k = 0;
|
|
int row = 0;
|
|
volatile int j;
|
|
uint8_t dbuf2[64] = {};
|
|
int page = 0;
|
|
int seg = 0;
|
|
volatile uint32_t now;
|
|
|
|
|
|
for (i = 1; i < 65; i++) {
|
|
dbuf2[i] = 0;
|
|
}
|
|
display_send_cmd(priv, SSD1306_DISPLAYOFF);
|
|
display_send_cmd1(priv, 0xD6, 0x01);
|
|
display_send_cmd(priv, 0xA1);
|
|
display_setcontrast(priv, contrast);
|
|
display_send_cmd1(priv, SSD1306_CHARGEPUMP, 0x14);
|
|
display_send_cmd1(priv, SSD1306_MEMORYMODE, 0x00);
|
|
display_send_cmd1(priv, SSD1306_SETCOMPINS, 0x12);
|
|
display_send_cmd1(priv, SSD1306_SETDISPLAYOFFSET, 0x00);
|
|
display_send_cmd1(priv, SSD1306_SETVCOMDETECT, 0x00);
|
|
display_send_cmd1(priv, SSD1306_SETMULTIPLEX, 63);
|
|
display_send_cmd(priv, SSD1306_COMSCANINC);
|
|
display_send_cmd(priv, SSD1306_DISPLAYALLON_RESUME);
|
|
display_send_cmd(priv, SSD1306_DISPLAYON);
|
|
display_send_cmd(priv, 0x2E);
|
|
|
|
display_send_cmd2(priv, SSD1306_PAGEADDR, 0, 0xFF);
|
|
display_send_cmd2(priv, SSD1306_COLUMNADDR, 0, WIDTH - 1);
|
|
display_send_cmd1(priv, SSD1306_SETSTARTLINE, 0);
|
|
display_send_cmd(priv, 0x00);
|
|
display_send_cmd(priv, 0x10);
|
|
for (page = 0; page < 8; page++) {
|
|
display_send_cmd2(priv, SSD1306_PAGEADDR, page, 0xFF);
|
|
for (seg= 0; seg < 32; seg++) {
|
|
display_send_data(priv, dbuf2, 8);
|
|
}
|
|
display_send_cmd1(priv, SSD1306_SETSTARTLINE, row);
|
|
}
|
|
return 0;
|
|
}
|