#include "string.h"
#include "usr_system.h"
#include "usr_spi.h"
#define SPI_1 1
#define SPI_2 2
#define SPI_3 3
#define MAX_WIDTH 0x9F - 1
#define MAX_HEIGHT 0x83 - 1
#define MAX_WIDTH_SPACE 6
#define MAX_HEIGHT_SPACE 8
#define RGB(R,G,B) (((R>>3)<<11) | ((G>>2)<<5) | (B>>3))
typedef enum{
COLOR_BLACK = RGB( 0, 0, 0), // black
COLOR_GREY = RGB(192,192,192), // grey
COLOR_WHITE = RGB(255,255,255), // white
COLOR_RED = RGB(255, 0, 0), // red
COLOR_PINK = RGB(255,192,203), // pink
COLOR_YELLOW = RGB(255,255, 0), // yellow
COLOR_GOLDEN = RGB(255,215, 0), // golden
COLOR_BROWN = RGB(128, 42, 42), // brown
COLOR_BLUE = RGB( 0, 0,255), // blue
COLOR_CYAN = RGB( 0,255,255), // cyan
COLOR_GREEN = RGB( 0,255, 0), // green
COLOR_PURPLE = RGB(160, 32,240), // purple
}eCOLOR;
typedef enum{
eUPVERTICAL = 0x00,
eDOWNVERTICAL = 0x01,
eDIAGONAL = 0x02
}eSCROLLINGDIR;
typedef enum{
eFILL = 0x00,
eEMPTY = 0x01,
}eFILL_EMPTY;
typedef enum{
eNORMAL = 0x00,
eRIGHT = 0x01,
eLEFT = 0x02,
eBACK = 0x03
}eCHARDIR;
const u8 F6x8[][6] =
{
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, //sp0
{ 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00 }, // !1
{ 0x00, 0x00, 0x07, 0x00, 0x07, 0x00 }, // "2
{ 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // #3
{ 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // $4
{ 0x00, 0x62, 0x64, 0x08, 0x13, 0x23 }, // %5
{ 0x00, 0x36, 0x49, 0x55, 0x22, 0x50 }, // &6
{ 0x00, 0x00, 0x05, 0x03, 0x00, 0x00 }, // '7
{ 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00 }, // (8
{ 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00 }, // )9
{ 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14 }, // *10
{ 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08 }, // +11
{ 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00 }, // ,12
{ 0x00, 0x08, 0x08, 0x08, 0x08, 0x08 }, // -13
{ 0x00, 0x00, 0x60, 0x60, 0x00, 0x00 }, // .14
{ 0x00, 0x20, 0x10, 0x08, 0x04, 0x02 }, // /15
{ 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E }, // 016
{ 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00 }, // 117
{ 0x00, 0x42, 0x61, 0x51, 0x49, 0x46 }, // 218
{ 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31 }, // 319
{ 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10 }, // 420
{ 0x00, 0x27, 0x45, 0x45, 0x45, 0x39 }, // 521
{ 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30 }, // 622
{ 0x00, 0x01, 0x71, 0x09, 0x05, 0x03 }, // 723
{ 0x00, 0x36, 0x49, 0x49, 0x49, 0x36 }, // 824
{ 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E }, // 925
{ 0x00, 0x00, 0x36, 0x36, 0x00, 0x00 }, // :26
{ 0x00, 0x00, 0x56, 0x36, 0x00, 0x00 }, // ;27
{ 0x00, 0x08, 0x14, 0x22, 0x41, 0x00 }, // <28
{ 0x00, 0x14, 0x14, 0x14, 0x14, 0x14 }, // =29
{ 0x00, 0x00, 0x41, 0x22, 0x14, 0x08 }, // >30
{ 0x00, 0x02, 0x01, 0x51, 0x09, 0x06 }, // ?31
{ 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E }, // @32
{ 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C }, // A33
{ 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36 }, // B34
{ 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22 }, // C35
{ 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C }, // D36
{ 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41 }, // E37
{ 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01 }, // F38
{ 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A }, // G39
{ 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F }, // H40
{ 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00 }, // I41
{ 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01 }, // J42
{ 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41 }, // K43
{ 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40 }, // L44
{ 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F }, // M45
{ 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F }, // N46
{ 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E }, // O47
{ 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06 }, // P48
{ 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E }, // Q49
{ 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46 }, // R50
{ 0x00, 0x46, 0x49, 0x49, 0x49, 0x31 }, // S51
{ 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01 }, // T52
{ 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F }, // U53
{ 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F }, // V54
{ 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F }, // W55
{ 0x00, 0x63, 0x14, 0x08, 0x14, 0x63 }, // X56
{ 0x00, 0x07, 0x08, 0x70, 0x08, 0x07 }, // Y57
{ 0x00, 0x61, 0x51, 0x49, 0x45, 0x43 }, // Z58
{ 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00 }, // [59
{ 0x00, 0x02, 0x04, 0x08, 0x10, 0x20 }, // \60
{ 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00 }, // ]61
{ 0x00, 0x04, 0x02, 0x01, 0x02, 0x04 }, // ^62
{ 0x00, 0x40, 0x40, 0x40, 0x40, 0x40 }, // _63
{ 0x00, 0x00, 0x01, 0x02, 0x04, 0x00 }, // '64
{ 0x00, 0x20, 0x54, 0x54, 0x54, 0x78 }, // a65
{ 0x00, 0x7F, 0x48, 0x44, 0x44, 0x38 }, // b66
{ 0x00, 0x38, 0x44, 0x44, 0x44, 0x20 }, // c67
{ 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F }, // d68
{ 0x00, 0x38, 0x54, 0x54, 0x54, 0x18 }, // e69
{ 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02 }, // f70
{ 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C }, // g71
{ 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78 }, // h72
{ 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00 }, // i73
{ 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00 }, // j74
{ 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00 }, // k75
{ 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00 }, // l76
{ 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78 }, // m77
{ 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78 }, // n78
{ 0x00, 0x38, 0x44, 0x44, 0x44, 0x38 }, // o79
{ 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18 }, // p80
{ 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC }, // q81
{ 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08 }, // r82
{ 0x00, 0x48, 0x54, 0x54, 0x54, 0x20 }, // s83
{ 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20 }, // t84
{ 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C }, // u85
{ 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C }, // v86
{ 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C }, // w87
{ 0x00, 0x44, 0x28, 0x10, 0x28, 0x44 }, // x88
{ 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C }, // y89
{ 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44 }, // z90
{ 0x14, 0x14, 0x14, 0x14, 0x14, 0x14 } // horiz lines91
};
/*******************************************************************************
* Function Name : void OLED_DELAY(vu32 nCount)
* Description : Microsecond delay
* Parameters : Microsecond conunt
* Return : None
*******************************************************************************/
void OLED_DELAY(vu32 nCount)
{
#if 0
nCount *= 1;
for(; nCount!=0; nCount--);
#else
__ASM volatile ("nop");
#endif
}
/*******************************************************************************
* Function Name :
* Parameters :
* Return : none
* Description :
*******************************************************************************/
void OLED_EN(FunctionalState NewState)
{
if (NewState == DISABLE){
GPIO_ResetBits(GPIOB, GPIO_Pin_10);
}
else{
GPIO_SetBits(GPIOB, GPIO_Pin_10);
}
}
/*******************************************************************************
* Function Name :
* Parameters :
* Return : none
* Description :
This pin is reset signal input.
When the pin is pulled LOW, initialization of the chip is executed.
Keep this pin pull HIGH during normal operation.
*******************************************************************************/
void OLED_RES(FunctionalState NewState)
{
if (NewState == DISABLE){
GPIO_SetBits(GPIOB, GPIO_Pin_11);
}
else{
GPIO_ResetBits(GPIOB, GPIO_Pin_11);
}
}
/*******************************************************************************
* Function Name :
* Parameters :
* Return : none
* Description :
high = Data
low = Command
*******************************************************************************/
static void OLED_DC(OLEDCmdStatus NewState)
{
if (NewState == eOLEDCMD){
GPIO_ResetBits(GPIOB, GPIO_Pin_14);
}
else{
GPIO_SetBits(GPIOB, GPIO_Pin_14);
}
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
*******************************************************************************/
void SPI_OLED_CS_HIGH(void)
{
GPIO_SetBits(GPIOB, GPIO_Pin_12);
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
*******************************************************************************/
void SPI_OLED_CS_LOW(void)
{
GPIO_ResetBits(GPIOB, GPIO_Pin_12);
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
*******************************************************************************/
uint8_t SPI_FLASH_SendByte(uint8_t byte, u8 softspi)
{
uint8_t RXDat = 0;
uint8_t SPI_count;
for (SPI_count = 0; SPI_count < 8; SPI_count++)
{
if((byte & 0x80) == 0x80){
GPIO_SetBits(GPIOB, GPIO_Pin_15);//MOSI HIGH
}
else{
GPIO_ResetBits(GPIOB, GPIO_Pin_15); //MOSI LOW
}
byte = byte << 1; // shift next bit into MSB
OLED_DELAY(2);
GPIO_SetBits(GPIOB, GPIO_Pin_13);//SCK HIGH
OLED_DELAY(3);
GPIO_ResetBits(GPIOB, GPIO_Pin_13);//SCK LOW
OLED_DELAY(2);
}
/* Read SPIz received data */
return RXDat;
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
*******************************************************************************/
void SPI_Config(u8 spi, u8 softspi)
{
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure;
if(spi == SPI_1){
}
else if(spi == SPI_2){
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
/* LCD CS */
GPIO_SetBits(GPIOB, GPIO_Pin_12);
/* GPIO configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
OLED_INIT_SSD1353();
// OLED_LINE(0, 0, 50, 50, 30);
// delay_ms(500);
// OLED_CLEAR(0, 0, MAX_WIDTH, MAX_HEIGHT);
// OLED_RECTANGLE(0, 0, 50, 50, COLOR_BLUE, COLOR_RED, 1);
// delay_ms(500);
// OLED_CLEAR(0, 0, MAX_WIDTH, MAX_HEIGHT);
// OLED_PIXEL(50, 50, COLOR_BLUE);
// OLED_PIXEL(51, 50, COLOR_BLUE);
// OLED_PIXEL(52, 50, COLOR_BLUE);
// OLED_PIXEL(53, 50, COLOR_BLUE);
// delay_ms(500);
// OLED_CLEAR(0, 0, MAX_WIDTH, MAX_HEIGHT);
// OLED_Circle(20, 50, 50, COLOR_RED, eFILL);
// delay_ms(500);
// OLED_CLEAR(0, 0, MAX_WIDTH, MAX_HEIGHT);
// OLED_TRIANGLE(20, 10, 40, 40, 0, 40, COLOR_RED);
// OLED_EN_INVERT(1);
// OLED_SET_Scolling(eVERTICAL, 10, 10, 80);
//OLED_CHAR_F6_8(100, 10, '2', COLOR_BLUE, COLOR_BLACK, eNORMAL);
OLED_PRINTF(50, 20, COLOR_RED, COLOR_BLACK, "TEST V1.0.0");
while(1){
// delay_ms(500);
OLED_RED();
// delay_ms(500);
OLED_GREEN();
// delay_ms(500);
OLED_BLUE();
}
}
/*******************************************************************************
* Function Name :
* Description : Draw Char
* Parameters :
* Return : None
*******************************************************************************/
void OLED_PRINTF(u8 X, u8 Y, u16 Color, u16 BGColor, char MSG[])
{
int ii=0;
for (ii=0 ; ii<strlen(MSG); ii++){
OLED_CHAR_F6_8((ii*MAX_WIDTH_SPACE)+X, Y, MSG[ii], Color, BGColor, eNORMAL);
}
}
/*******************************************************************************
* Function Name :
* Description : Draw Char
* Parameters :
* Return : None
*******************************************************************************/
void OLED_CHAR_F6_8(u8 X, u8 Y, u8 CHAR, u16 Color, u16 BGColor, u8 CHDIR)
{
u8 LoadFont, Char_Loop;
s8 DirL;
CHAR = CHAR - 32;
for(Char_Loop=0; Char_Loop<6; Char_Loop++){
LoadFont = F6x8[CHAR][Char_Loop];
if(CHDIR == eNORMAL){
for (DirL = 0; DirL < 8; DirL++){
if((LoadFont & 0x01) == 0x01){
OLED_PIXEL(MAX_WIDTH-X-Char_Loop, Y+DirL, Color);
}
else{
OLED_PIXEL(MAX_WIDTH-X-Char_Loop, Y+DirL, BGColor);
}
LoadFont = LoadFont >> 1; // shift next bit into MSB
}
}
if(CHDIR == eLEFT){
for (DirL = 7; DirL >= 0; DirL--){
if((LoadFont & 0x80) == 0x80){
OLED_PIXEL(X+DirL, Y+Char_Loop, Color);
}
else{
OLED_PIXEL(X+DirL, Y+Char_Loop, BGColor);
}
LoadFont = LoadFont << 1; // shift next bit into MSB
}
}
else if(CHDIR == eRIGHT){
for (DirL = 0; DirL < 8; DirL++){
if((LoadFont & 0x80) == 0x80){
OLED_PIXEL(X+DirL, Y+Char_Loop, Color);
}
else{
OLED_PIXEL(X+DirL, Y+Char_Loop, BGColor);
}
LoadFont = LoadFont << 1; // shift next bit into MSB
}
}
else if(CHDIR == eBACK){
for (DirL = 0; DirL < 8; DirL++){
if((LoadFont & 0x80) == 0x80){
OLED_PIXEL(X+Char_Loop, Y+DirL, Color);
}
else{
OLED_PIXEL(X+Char_Loop, Y+DirL, BGColor);
}
LoadFont = LoadFont << 1; // shift next bit into MSB
}
}
}
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
*******************************************************************************/
void OLED_COPYWINDOW(u8 X, u8 XSize, u8 Y, u8 YSize)
{
OLED_CMD(0x23);
if(XSize + X > MAX_WIDTH){
X = MAX_WIDTH - XSize;
}
OLED_DAT(X);
if(YSize + Y > MAX_HEIGHT){
Y = MAX_HEIGHT - YSize;
}
OLED_DAT(Y);
OLED_DAT(XSize);
OLED_DAT(YSize);
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
*******************************************************************************/
void OLED_SET_Scrolling(eSCROLLINGDIR Dir, u8 RowAddr, u8 RowNum, u8 Interval)
{
switch(Dir){
case eUPVERTICAL:
OLED_CMD(0x27);
OLED_DAT(0x00);
OLED_DAT(0x00);
OLED_DAT(0x00);
OLED_DAT(0x01);
OLED_DAT(Interval);
OLED_CMD(0x2F);
break;
case eDOWNVERTICAL:
OLED_CMD(0xa1);
OLED_DAT(0xa3);
OLED_DAT(0x00);
OLED_DAT(0x84);
OLED_CMD(0x27);
OLED_DAT(0x00);
OLED_DAT(0x00);
OLED_DAT(0x84);
OLED_DAT(0x01);
OLED_DAT(Interval);
OLED_CMD(0x2F);
break;
case eDIAGONAL:
OLED_CMD(0xa1);
OLED_DAT(0xa3);
OLED_DAT(0x00);
OLED_DAT(0x84);
OLED_CMD(0x27);
OLED_DAT(0x01);
OLED_DAT(0x00);
OLED_DAT(0x84);
OLED_DAT(0x01);
OLED_DAT(Interval);
OLED_CMD(0x2F);
break;
default:
break;
}
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
*******************************************************************************/
void OLED_EN_Scrolling(u8 EnSCROLL)
{
if(EnSCROLL){
OLED_CMD(0x2F);
}
else{
OLED_CMD(0x2E);
}
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
*******************************************************************************/
void OLED_EN_INVERT(u8 Eninvert)
{
if(Eninvert){
OLED_CMD(0xA7);
}
else{
OLED_CMD(0xA4);
}
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
*******************************************************************************/
void OLED_DIMWINDOW(u8 X, u8 XSize, u8 Y, u8 YSize)
{
OLED_CMD(0x24);
if(XSize + X > MAX_WIDTH){
X = MAX_WIDTH - XSize;
}
OLED_DAT(X);
if(YSize + Y > MAX_HEIGHT){
Y = MAX_HEIGHT - YSize;
}
OLED_DAT(Y);
OLED_DAT(XSize);
OLED_DAT(YSize);
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
*******************************************************************************/
void OLED_CLEAR(u8 X, u8 Y, u8 XSize, u8 YSize)
{
OLED_CMD(0x25); //Window Clear
if(XSize + X > MAX_WIDTH){
X = MAX_WIDTH - XSize;
}
OLED_DAT(X);
if(YSize + Y > MAX_HEIGHT){
Y = MAX_HEIGHT - YSize;
}
OLED_DAT(Y);
OLED_DAT(XSize);
OLED_DAT(YSize);
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
*******************************************************************************/
void OLED_RECTANGLE(u8 X, u8 Y, u8 XSize, u8 YSize, u16 OUTLINECOLOR, u16 INNERCOLOR, u8 FILL)
{
u8 R, G, B;
OLED_CMD(0x26); //Fill Enable/Disable
if(FILL == 1){
OLED_DAT(0x01);
}
else{
OLED_DAT(0x00);
}
OLED_CMD(0x22); //Draw Rectangle
if(XSize + X > MAX_WIDTH){
X = MAX_WIDTH - XSize;
// X = 0;
// XSize = 0x9F;
}
OLED_DAT(X);
if(YSize + Y > MAX_HEIGHT){
Y = MAX_HEIGHT - YSize;
// Y = 0;
// YSize = 0x83;
}
OLED_DAT(Y);
OLED_DAT(XSize);
OLED_DAT(YSize);
R = (u8)(((OUTLINECOLOR>>11)&0x1F));
G = (u8)((OUTLINECOLOR>>5)&0x3F);
B = (u8)((OUTLINECOLOR&0x1F));
OLED_DAT(R);
OLED_DAT(G);
OLED_DAT(B);
R = (u8)(((INNERCOLOR>>11)&0x1F));
G = (u8)((INNERCOLOR>>5)&0x3F);
B = (u8)((INNERCOLOR&0x1F));
OLED_DAT(R);
OLED_DAT(G);
OLED_DAT(B);
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
A[7:0] : Column Address of Start
B[7:0] : Row Address of Start
C[7:0] : Column Address of End
D[7:0] : Row Address of End
E[5:0] : Color C of the line
F[5:0] : Color B of the line
G[5:0] : Color A of the line
OLED_DAT(0x9F); //X End
OLED_DAT(0x83); //Y End
*******************************************************************************/
void OLED_LINE(s8 X, s8 Y, s8 XSize, s8 YSize, u16 Color)
{
u8 R, G, B;
OLED_CMD(0x21); //Draw Line
if(XSize + X > MAX_WIDTH){
X = MAX_WIDTH - XSize;
// X = 0;
// XSize = 0x9F;
}
OLED_DAT(X);
if(YSize + Y > MAX_HEIGHT){
Y = MAX_HEIGHT - YSize;
// Y = 0;
// YSize = 0x83;
}
OLED_DAT(Y);
OLED_DAT(XSize);
OLED_DAT(YSize);
R = (u8)(((Color>>11)&0x1F));
G = (u8)((Color>>5)&0x3F);
B = (u8)((Color&0x1F));
OLED_DAT(R);
OLED_DAT(G);
OLED_DAT(B);
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
OLED_DAT(0x00); //BLUE
OLED_DAT(0x1f);
OLED_DAT(0x07); //GREEN
OLED_DAT(0xe0);
OLED_DAT(0xf8); //RED
OLED_DAT(0x00);
*******************************************************************************/
void OLED_Circle(u8 radius, u8 X, u8 Y , u16 Color, u16 Fill)
{
s16 cx, cy, d;
if(X > MAX_WIDTH) X = MAX_WIDTH;
if(Y > MAX_HEIGHT) Y = MAX_HEIGHT;
d = 3 - 2 * radius;
cy = radius;
OLED_PIXEL(X, radius+Y, Color);
OLED_PIXEL(X, -radius+Y, Color);
OLED_PIXEL(radius+X, Y, Color);
OLED_PIXEL(-radius+X, Y, Color);
if(Fill == eFILL) {
OLED_LINE(X, radius+Y, X, -radius+Y, Color);
OLED_LINE(radius+X, Y, -radius+X,Y, Color);
}
for (cx = 0; cx <= cy; cx++) {
if(d>=0) {
d+=10+4*cx-4*cy;
cy--;
} else {
d+=6+4*cx;
}
OLED_PIXEL(cy+X, cx+Y, Color);
OLED_PIXEL(cx+X, cy+Y, Color);
OLED_PIXEL(-cx+X, cy+Y, Color);
OLED_PIXEL(-cy+X, cx+Y, Color);
OLED_PIXEL(-cy+X, -cx+Y, Color);
OLED_PIXEL(-cx+X, -cy+Y, Color);
OLED_PIXEL(cx+X, -cy+Y, Color);
OLED_PIXEL(cy+X, -cx+Y, Color);
if(Fill == eFILL) {
OLED_LINE(cy+X, cx+Y, cy+X, -cx+Y, Color);
OLED_LINE(cx+X, cy+Y, cx+X, -cy + Y, Color);
OLED_LINE(-cx+X, cy+Y, -cx+X, cy+Y, Color);
OLED_LINE(-cy+X, cx+Y, -cy+X, cx+Y, Color);
OLED_LINE(-cy+X, -cx+Y, -cy+X, cx+Y, Color);
OLED_LINE(-cx+X, -cy+Y, -cx+X, cy+Y, Color);
OLED_LINE(cx+X, -cy+Y, cx+X, cy+Y, Color);
OLED_LINE(cy+X, -cx+Y, cy+X, cx+Y, Color);
}
}
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
*******************************************************************************/
void OLED_TRIANGLE(s16 X0, s16 Y0, s16 X1, s16 Y1,s16 X2, s16 Y2, u16 Color)
{
OLED_LINE(X0, Y0, X1, Y1, Color);
OLED_LINE(X1, Y1, X2, Y2, Color);
OLED_LINE(X2, Y2, X0, Y0, Color);
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
OLED_DAT(0x00); //BLUE
OLED_DAT(0x1f);
OLED_DAT(0x07); //GREEN
OLED_DAT(0xe0);
OLED_DAT(0xf8); //RED
OLED_DAT(0x00);
*******************************************************************************/
void OLED_PIXEL(u8 X, u8 Y, u16 Color)
{
u8 Buf[2];
Buf[0] = Color >> 8;
Buf[1] = Color;
if ((X>MAX_WIDTH)||(Y>MAX_HEIGHT)) return ;
OLED_CMD(0x15);
OLED_DAT(X);
OLED_DAT(MAX_WIDTH);
OLED_CMD(0x75);
OLED_DAT(Y);
OLED_DAT(MAX_HEIGHT);
OLED_CMD(0x5c);
OLED_DAT(Buf[0]);
OLED_DAT(Buf[1]);
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
Set Column start and end address
A[7:0]: Set start column address from 00d-159d
[reset= 0d (00h)]
B[7:0]: Set end column address from 00d-159d
[reset= 159d (9Fh)
*******************************************************************************/
void SET_COLUMN_ADDR(uint8_t X)
{
OLED_CMD(0x15);
if(X > 0x9F){
X = 0x9F;
}
OLED_DAT(X);
OLED_DAT(X);
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
Set Row start and end address
A[7:0]: Set start row address
from 00d-131d [reset= 0d (00h)]
B[7:0]: Set end row address
from 00d-131d [reset= 131d (83h)]
*******************************************************************************/
void SET_ROW_ADDR(uint8_t Y)
{
OLED_CMD(0x75);
if(Y > 0x83){
Y = 0x83;
}
OLED_DAT(Y);
OLED_DAT(Y);
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
*******************************************************************************/
void OLED_CMD(uint8_t data){
OLED_DC(eOLEDCMD);// GPIO_ResetBits(GPIOB, GPIO_Pin_14);
OLED_DELAY(5);
SPI_OLED_CS_LOW();
OLED_DELAY(5);
SPI_FLASH_SendByte(data, SW_SPI);
OLED_DELAY(7);
SPI_OLED_CS_HIGH();
OLED_DELAY(10);
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
*******************************************************************************/
void OLED_DAT(uint8_t data){
OLED_DC(eOLEDDAT);// GPIO_SetBits(GPIOB, GPIO_Pin_14);
OLED_DELAY(5);
SPI_OLED_CS_LOW();
OLED_DELAY(5);
SPI_FLASH_SendByte(data, SW_SPI);
OLED_DELAY(7);
SPI_OLED_CS_HIGH();
OLED_DELAY(10);
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
*******************************************************************************/
void OLED_INIT_SSD1353(void)
{
/* LCD RES */
OLED_RES(DISABLE);// GPIO_SetBits(GPIOB, GPIO_Pin_11);
delay_ms(1); //OLED_DELAY(100);
OLED_RES(ENABLE);// GPIO_ResetBits(GPIOB, GPIO_Pin_11);
delay_ms(1); //OLED_DELAY(100);
SPI_OLED_CS_LOW();
delay_us(5);
OLED_DC(eOLEDDAT);
delay_us(5);
OLED_CMD(0xae); //Display off 1010 1110
OLED_CMD(0xa8); //Set MUX ratio
OLED_DAT(0x7f);
OLED_CMD(0xa1); //Display start line
OLED_DAT(0x00);
OLED_CMD(0xa2); //Set display offset
OLED_DAT(0x00);
OLED_CMD(0xa4); //Normal display
OLED_CMD(0xa0); //Set re-map
OLED_DAT(0x77);// OLED_DAT(0x64);
OLED_CMD(0x87); //Master current control
OLED_DAT(0x0f);
OLED_CMD(0x81); //Set contrast level for R
OLED_DAT(102);//OLED_DAT(0x75); //Red contrast set
OLED_CMD(0x82); //Set contrast level for G
OLED_DAT(102);//OLED_DAT(0x60); //Green contrast set
OLED_CMD(0x83); //Set contrast level for B
OLED_DAT(102);//OLED_DAT(0x6a); //Blue contrast set
OLED_CMD(0xb1); //Phase adjust
OLED_DAT(0x22);
OLED_CMD(0xb3); //Set frame rate
OLED_DAT(0xf0);//OLED_DAT(0x40);
OLED_CMD(0xbb); //Set Pre-charge level
OLED_DAT(0x08);
OLED_CMD(0xbe); //VCOMH setting
OLED_DAT(0x3c);
OLED_CMD(0x15);
OLED_DAT(0x00);
OLED_DAT(0x9f);
OLED_CMD(0x75);
OLED_DAT(0x00);
OLED_DAT(0x7f);
OLED_CMD(0xb9);
OLED_CLEANDDR(); //Clear the whole DDRAM
/* LCD EN */
OLED_EN(ENABLE);
delay_ms(200);
OLED_CMD(0xaf); //Set Display ON
// OLED_CMD(0x5c);
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
*******************************************************************************/
void OLED_CLEANDDR(void) //Clear the whole DDRAM
{
int i,j;
OLED_CMD(0x15);
OLED_DAT(0x00);
OLED_DAT(0x9f);
OLED_CMD(0x75);
OLED_DAT(0x00);
OLED_DAT(0x83);
OLED_CMD(0x5c);
for(i=0;i<132;i++)
{
for(j=0;j<160;j++)
{
OLED_DAT(0x00);
OLED_DAT(0x00);
}
}
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description : 0001 0101 15
*******************************************************************************/
void OLED_RED(void)
{
int i,j;
OLED_RAMADDR( );
OLED_CMD(0x5c);
for(i=0;i<160;i++)
{
for (j=0;j<128;j++)
{
OLED_DAT(0xf8); //RED
OLED_DAT(0x00);
}
}
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
*******************************************************************************/
void OLED_GREEN(void)
{
int i,j;
OLED_RAMADDR( );
OLED_CMD(0x5c);
for(i=0;i<160;i++)
{
for (j=0;j<128;j++)
{
OLED_DAT(0x07); //GREEN
OLED_DAT(0xe0);
}
}
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
*******************************************************************************/
void OLED_BLUE(void)
{
int i,j;
OLED_RAMADDR( );
OLED_CMD(0x5c);
for(i=0;i<160;i++)
{
for (j=0;j<128;j++)
{
OLED_DAT(0x00); //BLUE
OLED_DAT(0x1f);
}
}
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
*******************************************************************************/
void OLED_WHITE(void)
{
int i,j;
OLED_RAMADDR( );
OLED_CMD(0x5c);
for(i=0;i<160;i++)
{
for (j=0;j<128;j++)
{
OLED_DAT(0xff); //WHITE
OLED_DAT(0xff);
}
}
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
*******************************************************************************/
void OLED_RAMADDR(void)
{
OLED_CMD(0x15); //set column address
OLED_DAT(0x00); //Column Start Address
OLED_DAT(0x9f); //Column End Address
OLED_CMD(0x75); //Set Row Address
OLED_DAT(0x00); //Row Start Address
OLED_DAT(0x7f); //Row End Address
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
*******************************************************************************/
void OLED_BRIGHTNESS3 (void)
{
OLED_CMD(0x87); //Master current control
OLED_DAT(0x0f);
OLED_CMD(0x81); //Set contrast level for R
OLED_DAT(0x75); //Red contrast set
OLED_CMD(0x82); //Set contrast level for G
OLED_DAT(0x60); //Green contrast set
OLED_CMD(0x83); //Set contrast level for B
OLED_DAT(0x6a); //Blue contrast set
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
*******************************************************************************/
void OLED_BRIGHTNESS4 (void)
{
OLED_CMD(0x87); //Master current control
OLED_DAT(0x0b);
OLED_CMD(0x81); //Set contrast level for R
OLED_DAT(0x86); //Red contrast set
OLED_CMD(0x82); //Set contrast level for G
OLED_DAT(0x69); //Green contrast set
OLED_CMD(0x83); //Set contrast level for B
OLED_DAT(0x7c); //Blue contrast set
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
*******************************************************************************/
void OLED_BRIGHTNESS5 (void)
{
OLED_CMD(0x87); //Master current control
OLED_DAT(0x05);
OLED_CMD(0x81); //Set contrast level for R
OLED_DAT(0x80); //Red contrast set
OLED_CMD(0x82); //Set contrast level for G
OLED_DAT(0x6b); //Green contrast set
OLED_CMD(0x83); //Set contrast level for B
OLED_DAT(0x7f); //Blue contrast set
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
*******************************************************************************/
void OLED_CONTRAST(char VAL)
{
int Value = VAL*20;
if(Value > 180) {
Value = 180;
}
OLED_CMD(0x87); //Master current control
OLED_DAT(0x05);
OLED_CMD(0x81); //Set contrast level for R
OLED_DAT(Value); //Red contrast set
OLED_CMD(0x82); //Set contrast level for G
OLED_DAT(Value); //Green contrast set
OLED_CMD(0x83); //Set contrast level for B
OLED_DAT(Value); //Blue contrast set
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
*******************************************************************************/
void OLED_ON(void)
{
OLED_CMD(0xAF);
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
*******************************************************************************/
void OLED_OFF(void)
{
OLED_CMD(0xAE);
}
'초보의 아웅다웅 설계하기 > STM32' 카테고리의 다른 글
STM32L432KC - TOUCH (0) | 2020.12.01 |
---|---|
STM32 USB CDC-ACM(Virtual Com Port) 리눅스 확인 (0) | 2020.11.20 |
GPIO로 딜레이를 사용하여 Uart TX 출력 - Soft Uart (0) | 2020.07.02 |
Demonstrator GUI V2.9.0 RC8 (0) | 2020.05.22 |
STM32L496 Unique ID 확인하기 (0) | 2020.05.21 |