Compare commits
No commits in common. "6a8488c60e47cc5887f3e6356b12d58cc39cc92c" and "b5843612c7cb1906394c3d82b24946851c7a6e30" have entirely different histories.
6a8488c60e
...
b5843612c7
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +0,0 @@
|
|||||||
build
|
|
10
README.md
10
README.md
@ -1,6 +1,6 @@
|
|||||||
# ST7735 SPI Display Toolkit
|
# ST7735 SPI Display Toolkit
|
||||||
|
|
||||||
Built and tested with OrangePi Zero (running Armbian) and ST7735 128x160 v1.1 and 240x320 SPI displays.
|
Built and tested with OrangePi Zero and ST7735 128x160 v1.1 SPI display.
|
||||||
|
|
||||||
## Hardware Connections
|
## Hardware Connections
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ ninja -C build
|
|||||||
TODO
|
TODO
|
||||||
|
|
||||||
## Resources
|
## Resources
|
||||||
* [orangepi-xunlong/WiringOP](https://github.com/orangepi-xunlong/WiringOP) - GPIO controlling library compatible with Raspberry Pi's WiringPi
|
* [https://github.com/orangepi-xunlong/WiringOP](orangepi-xunlong/WiringOP) - GPIO controlling library compatible with Raspberry Pi's WiringPi
|
||||||
* [dhepper/font8x8](https://github.com/dhepper/font8x8) - 8x8 pixels monospaced font
|
* [https://github.com/dhepper/font8x8](dhepper/font8x8) - 8x8 pixels monospaced font
|
||||||
* [vadzimyatskevich/SSD1306](https://github.com/vadzimyatskevich/SSD1306) - Similar driver for SSD1306 OLED displays
|
* [https://github.com/vadzimyatskevich/SSD1306](vadzimyatskevich/SSD1306) - Similar driver for SSD1306 OLED displays
|
||||||
* [michal037/driver-ST7735S](https://github.com/michal037/driver-ST7735S) - ST7735 driver
|
|
||||||
|
@ -20,9 +20,9 @@ lcd_t* demo_init()
|
|||||||
|
|
||||||
wiringPiSetup();
|
wiringPiSetup();
|
||||||
|
|
||||||
lcd_t* lcd = lcd_init(30000000, 1, 15, 7, 8);
|
lcd_t* lcd = lcd_init(40000000, 1, 15, 7, 8);
|
||||||
|
|
||||||
lcd_setOrientation(lcd, 4);
|
lcd_setOrientation(lcd, 2);
|
||||||
|
|
||||||
return lcd;
|
return lcd;
|
||||||
}
|
}
|
||||||
|
8
spilcd.h
8
spilcd.h
@ -2,17 +2,13 @@
|
|||||||
#define uint8 unsigned char
|
#define uint8 unsigned char
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef uint16
|
|
||||||
#define uint16 unsigned short
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef __SPILCD_H__
|
#ifndef __SPILCD_H__
|
||||||
#define __SPILCD_H__
|
#define __SPILCD_H__
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int channel;
|
int channel;
|
||||||
int cs, a0, rs;
|
int cs, a0, rs;
|
||||||
uint16 width, height;
|
uint8 width, height;
|
||||||
} lcd_t;
|
} lcd_t;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -53,7 +49,7 @@ void lcd_deinit(lcd_t *lcd);
|
|||||||
* Return: 0 for success, 1 for error.
|
* Return: 0 for success, 1 for error.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
uint16 lcd_setWindow(lcd_t* lcd, uint16 x1, uint16 y1, uint16 x2, uint16 y2);
|
uint8 lcd_setWindow(lcd_t* lcd, uint8 x1, uint8 y1, uint8 x2, uint8 y2);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Push a pixel into the previously set drawing area.
|
* Push a pixel into the previously set drawing area.
|
||||||
|
82
st7735.c
82
st7735.c
@ -28,13 +28,13 @@ struct
|
|||||||
};
|
};
|
||||||
/****************************** END EASY PORT END *****************************/
|
/****************************** END EASY PORT END *****************************/
|
||||||
|
|
||||||
static uint8 screen_buffer[SCREEN_HEIGHT * SCREEN_WIDTH * 3]; // TODO: make dynamic
|
static uint8 screen_buffer[128 * 160 * 3]; // TODO: make dynamic
|
||||||
static uint16 screen_window_x1;
|
static uint8 screen_window_x1;
|
||||||
static uint16 screen_window_x2;
|
static uint8 screen_window_x2;
|
||||||
static uint16 screen_window_y1;
|
static uint8 screen_window_y1;
|
||||||
static uint16 screen_window_y2;
|
static uint8 screen_window_y2;
|
||||||
static uint16 screen_cursor_x;
|
static uint8 screen_cursor_x;
|
||||||
static uint16 screen_cursor_y;
|
static uint8 screen_cursor_y;
|
||||||
|
|
||||||
void advance_screen_cursor()
|
void advance_screen_cursor()
|
||||||
{
|
{
|
||||||
@ -74,12 +74,12 @@ static inline void *safeMalloc(size_t size)
|
|||||||
} /* safeMalloc */
|
} /* safeMalloc */
|
||||||
|
|
||||||
|
|
||||||
uint16 lcdhw_setWindow(lcd_t* lcd, uint16 x1, uint16 y1, uint16 x2, uint16 y2);
|
uint8 lcdhw_setWindow(lcd_t* lcd, uint8 x1, uint8 y1, uint8 x2, uint8 y2);
|
||||||
void lcdhw_pushPixel(lcd_t* lcd, uint8 r, uint8 g, uint8 b);
|
void lcdhw_pushPixel(lcd_t* lcd, uint8 r, uint8 g, uint8 b);
|
||||||
void lcdhw_pushPixels(lcd_t* lcd, uint8* pixels, size_t count);
|
void lcdhw_pushPixels(lcd_t* lcd, uint8* pixels, size_t count);
|
||||||
|
|
||||||
void lcd_setOrientation(lcd_t* lcd, uint16 orientation);
|
void lcd_setOrientation(lcd_t* lcd, uint8 orientation);
|
||||||
void lcd_setGamma(lcd_t* lcd, uint16 state);
|
void lcd_setGamma(lcd_t* lcd, uint8 state);
|
||||||
void lcd_pushPixel(lcd_t* lcd, uint8 r, uint8 g, uint8 b);
|
void lcd_pushPixel(lcd_t* lcd, uint8 r, uint8 g, uint8 b);
|
||||||
void lcd_pushPixels(lcd_t* lcd, uint8* pixels, size_t count);
|
void lcd_pushPixels(lcd_t* lcd, uint8* pixels, size_t count);
|
||||||
|
|
||||||
@ -174,53 +174,43 @@ void lcd_deinit(lcd_t *display)
|
|||||||
free(display);
|
free(display);
|
||||||
} /* lcdst_uninit */
|
} /* lcdst_uninit */
|
||||||
|
|
||||||
void lcd_setOrientation(lcd_t* lcd, uint16 orientation)
|
void lcd_setOrientation(lcd_t* lcd, uint8 orientation)
|
||||||
{
|
{
|
||||||
writeCommand(0x36); /* Memory Data Access Control */
|
writeCommand(0x36); /* Memory Data Access Control */
|
||||||
|
|
||||||
int sw = SCREEN_WIDTH;
|
|
||||||
int sh = SCREEN_HEIGHT;
|
|
||||||
|
|
||||||
uint8 my = 1 << 7; // row address order bit
|
|
||||||
uint8 mx = 1 << 6; // column address order bit
|
|
||||||
uint8 mv = 1 << 5; // row/column exchange bit
|
|
||||||
switch(orientation)
|
switch(orientation)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
writeData(mx & mv);
|
writeData(0x60); /* MX + MV */
|
||||||
activeDisplay->width = sw;
|
activeDisplay->width = 160;
|
||||||
activeDisplay->height = sh;
|
activeDisplay->height = 128;
|
||||||
|
lcdhw_setWindow(lcd, 0, 0, 159, 127);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
writeData(my & mx);
|
writeData(0xC0); /* MY + MX */
|
||||||
activeDisplay->width = sh;
|
activeDisplay->width = 128;
|
||||||
activeDisplay->height = sw;
|
activeDisplay->height = 160;
|
||||||
|
lcdhw_setWindow(lcd, 0, 0, 127, 159);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
writeData(my & mv);
|
writeData(0xA0); /* MY + MV */
|
||||||
activeDisplay->width = sw;
|
activeDisplay->width = 160;
|
||||||
activeDisplay->height = sh;
|
activeDisplay->height = 128;
|
||||||
|
lcdhw_setWindow(lcd, 0, 0, 159, 127);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
|
||||||
writeData(mx);
|
|
||||||
activeDisplay->width = sh;
|
|
||||||
activeDisplay->height = sw;
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
writeData(0); /* None */
|
writeData(0x00); /* None */
|
||||||
activeDisplay->width = sh;
|
activeDisplay->width = 128;
|
||||||
activeDisplay->height = sw;
|
activeDisplay->height = 160;
|
||||||
|
lcdhw_setWindow(lcd, 0, 0, 127, 159);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
lcdhw_setWindow(lcd, 0, 0, activeDisplay->width - 1, activeDisplay->height - 1);
|
|
||||||
} /* lcdst_setOrientation */
|
} /* lcdst_setOrientation */
|
||||||
|
|
||||||
void lcd_setGamma(lcd_t* lcd, uint16 state)
|
void lcd_setGamma(lcd_t* lcd, uint8 state)
|
||||||
{
|
{
|
||||||
/* The status (0 or 1) of the GS pin can only be empirically tested */
|
/* The status (0 or 1) of the GS pin can only be empirically tested */
|
||||||
switch(state)
|
switch(state)
|
||||||
@ -236,13 +226,13 @@ void lcd_setGamma(lcd_t* lcd, uint16 state)
|
|||||||
writeData(state);
|
writeData(state);
|
||||||
} /* lcdst_setGamma */
|
} /* lcdst_setGamma */
|
||||||
|
|
||||||
void lcd_setInversion(lcd_t* lcd, uint16 state)
|
void lcd_setInversion(lcd_t* lcd, uint8 state)
|
||||||
{
|
{
|
||||||
/* Display inversion ON/OFF */
|
/* Display inversion ON/OFF */
|
||||||
writeCommand(state ? 0x21 : 0x20);
|
writeCommand(state ? 0x21 : 0x20);
|
||||||
} /* lcdst_setInversion */
|
} /* lcdst_setInversion */
|
||||||
|
|
||||||
uint16 lcdhw_setWindow(lcd_t* lcd, uint16 x1, uint16 y1, uint16 x2, uint16 y2)
|
uint8 lcdhw_setWindow(lcd_t* lcd, uint8 x1, uint8 y1, uint8 x2, uint8 y2)
|
||||||
{
|
{
|
||||||
/* Accept: 0 <= x1 <= x2 < activeDisplay->width */
|
/* Accept: 0 <= x1 <= x2 < activeDisplay->width */
|
||||||
if(x2 < x1) return 1;
|
if(x2 < x1) return 1;
|
||||||
@ -254,13 +244,13 @@ uint16 lcdhw_setWindow(lcd_t* lcd, uint16 x1, uint16 y1, uint16 x2, uint16 y2)
|
|||||||
|
|
||||||
/* Set column address */
|
/* Set column address */
|
||||||
writeCommand(0x2A);
|
writeCommand(0x2A);
|
||||||
writeData(x1 >> 8); writeData(x1 & 0xFF);
|
writeData(0); writeData(x1);
|
||||||
writeData(x2 >> 8); writeData(x2 & 0XFF);
|
writeData(0); writeData(x2);
|
||||||
|
|
||||||
/* Set row address */
|
/* Set row address */
|
||||||
writeCommand(0x2B);
|
writeCommand(0x2B);
|
||||||
writeData(y1 >> 8); writeData(y1 & 0xFF);
|
writeData(0); writeData(y1);
|
||||||
writeData(y2 >> 8); writeData(y2 & 0xFF);
|
writeData(0); writeData(y2);
|
||||||
|
|
||||||
/* Activate RAW write */
|
/* Activate RAW write */
|
||||||
writeCommand(0x2C);
|
writeCommand(0x2C);
|
||||||
@ -292,7 +282,7 @@ void lcdhw_pushPixels(lcd_t* lcd, uint8* pixels, size_t count)
|
|||||||
gpio.spiDataRW(activeDisplay->channel, pixels, count * 3);
|
gpio.spiDataRW(activeDisplay->channel, pixels, count * 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8 line_buffer[SCREEN_WIDTH*3]; // lcd->width or lcd->height
|
uint8 line_buffer[160*3]; // lcd->width or lcd->height
|
||||||
|
|
||||||
void lcd_redrawBuffer(lcd_t* lcd)
|
void lcd_redrawBuffer(lcd_t* lcd)
|
||||||
{
|
{
|
||||||
@ -303,7 +293,7 @@ void lcd_redrawBuffer(lcd_t* lcd)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16 lcd_setWindow(lcd_t* lcd, uint16 x1, uint16 y1, uint16 x2, uint16 y2)
|
uint8 lcd_setWindow(lcd_t* lcd, uint8 x1, uint8 y1, uint8 x2, uint8 y2)
|
||||||
{
|
{
|
||||||
screen_window_x1 = x1;
|
screen_window_x1 = x1;
|
||||||
screen_window_x2 = x2;
|
screen_window_x2 = x2;
|
||||||
|
13
st7735.h
13
st7735.h
@ -1,17 +1,4 @@
|
|||||||
#include "spilcd.h"
|
#include "spilcd.h"
|
||||||
|
|
||||||
#define SCREEN_320x240
|
|
||||||
//#define SCREEN_160x128
|
|
||||||
|
|
||||||
#ifdef SCREEN_320x240
|
|
||||||
#define SCREEN_WIDTH 320
|
|
||||||
#define SCREEN_HEIGHT 240
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef SCREEN_160x128
|
|
||||||
#define SCREEN_WIDTH 160
|
|
||||||
#define SCREEN_HEIGHT 128
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// TODO: optional HW-specific functions
|
// TODO: optional HW-specific functions
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user