这款芯片主打蓝牙低功耗,而墨水屏也是以低功耗而生。结合起来,那肯定是完美:
【实现步骤】
2. 添加spi端口定义:
/* *** 墨水屏IO定义 *****************
* MOSI PA2
* SCK PA1
* CS PA3
* DC PA4
* RST PA5
* BUSY PA6
********** 定义结束 ***********************/
#define EP_MOSI_GPIO_Port GPIOA
#define EP_SCK_GPIO_Port GPIOA
#define EPD_W21_CS_Port GPIOA
#define EPD_W21_DC_Port GPIOA
#define EPD_W21_RST_Port GPIOA
#define EP_BUSY_GPIO_Port GPIOA
#define EP_MOSI_Pin GPIO_PIN_2
#define EP_SCK_Pin GPIO_PIN_1
#define EP_CS_Pin GPIO_PIN_3
#define EP_DC_Pin GPIO_PIN_4
#define EP_REST_Pin GPIO_PIN_5
#define EP_BUSY_Pin GPIO_PIN_6
#define EPD_W21_MOSI_0 EP_MOSI_GPIO_Port->PBC = (uint32_t)EP_MOSI_Pin
#define EPD_W21_MOSI_1 EP_MOSI_GPIO_Port->PBSC = (uint32_t)EP_MOSI_Pin
#define EPD_W21_CLK_0 EP_SCK_GPIO_Port->PBC = (uint32_t)EP_SCK_Pin
#define EPD_W21_CLK_1 EP_SCK_GPIO_Port->PBSC = (uint32_t)EP_SCK_Pin
#define EPD_W21_CS_0 EPD_W21_CS_Port->PBC = (uint32_t)EP_CS_Pin
#define EPD_W21_CS_1 EPD_W21_CS_Port->PBSC = (uint32_t)EP_CS_Pin
#define EPD_W21_DC_0 EPD_W21_DC_Port->PBC = (uint32_t)EP_DC_Pin
#define EPD_W21_DC_1 EPD_W21_DC_Port->PBSC = (uint32_t)EP_DC_Pin
#define EPD_W21_RST_0 EPD_W21_RST_Port->PBC = (uint32_t)EP_REST_Pin
#define EPD_W21_RST_1 EPD_W21_RST_Port->PBSC = (uint32_t)EP_REST_Pin
#define isEPD_W21_BUSY GPIO_ReadInputDataBit(EP_BUSY_GPIO_Port, EP_BUSY_Pin) // for solomen solutions
3、声明spi IO驱动初始化
void EPD_GPIO_Init(void)
{
GPIO_InitType GPIO_InitStructure;
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE);
/* Configure the GPIO pin */
GPIO_InitStruct(&GPIO_InitStructure);
GPIO_InitStructure.Pin = EP_MOSI_Pin | EP_SCK_Pin | EP_CS_Pin | EP_DC_Pin | EP_REST_Pin;
GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitPeripheral(EP_MOSI_GPIO_Port, &GPIO_InitStructure);
GPIO_InitStructure.Pin = EP_BUSY_Pin;
GPIO_InitStructure.GPIO_Mode = GPIO_MODE_INPUT;
GPIO_InitPeripheral(EP_BUSY_GPIO_Port, &GPIO_InitStructure);
}
4、写代码:
void SPI_Write(unsigned char value)
{
unsigned char i;
for(i=0; i<8; i++)
{
EPD_W21_CLK_0;
if(value & 0x80)
EPD_W21_MOSI_1;
else
EPD_W21_MOSI_0;
value = (value << 1);
EPD_W21_CLK_1;
}
}
void EPD_W21_WriteCMD(unsigned char command)
{
EPD_W21_CS_0;
EPD_W21_DC_0; // command write
SPI_Write(command);
EPD_W21_CS_1;
}
void EPD_W21_WriteDATA(unsigned char data)
{
EPD_W21_CS_0;
EPD_W21_DC_1; // data write
SPI_Write(data);
EPD_W21_CS_1;
}
其余main.c:
#include "fonts.h"
#include "GUI_Paint.h"
#include "Ap_29demo.h"
#include "Display_EPD_w21.h"
unsigned char BlackImage[4736];//Define canvas space
int main(void)
{
unsigned char fen_L,fen_H,miao_L,miao_H;
log_init();
LedInit(LED1_PORT, LED1_PIN);
LedInit(LED2_PORT, LED2_PIN);
LedOn(LED1_PORT, LED1_PIN);
LedOn(LED2_PORT, LED2_PIN);
KeyInputExtiInit(KEY_INPUT_PORT, KEY_INPUT_PIN);
EPD_GPIO_Init(); //EPD GPIO initialization
Paint_NewImage(BlackImage, 128, 296, 270, WHITE); //Set screen size and display orientation
Paint_SelectImage(BlackImage);//Set the virtual canvas data storage location
while (1)
{
log_debug("debug\r\n");
LedBlink(LED1_PORT, LED1_PIN);
Delay(0x28FFFF);
log_info("LED FLASH\r\n");
//////////////////////Partial refresh time demo/////////////////////////////////////
EPD_HW_Init(); //Electronic paper initialization
EPD_SetRAMValue_BaseMap(gImage_basemap); //Partial refresh background color
for(fen_H=0;fen_H<6;fen_H++)
{
for(fen_L=0;fen_L<10;fen_L++)
{
for(miao_H=0;miao_H<6;miao_H++)
{
for(miao_L=0;miao_L<10;miao_L++)
{
EPD_Dis_Part_myself(48,90,(unsigned char *)&Num[miao_L], //x-A,y-A,DATA-A
48,122,(unsigned char *)&Num[miao_H], //x-B,y-B,DATA-B
48,162,(unsigned char *)gImage_numdot, //x-C,y-C,DATA-C
48,204,(unsigned char *)&Num[fen_L], //x-D,y-D,DATA-D
48,236,(unsigned char *)&Num[fen_H],32,64); //x-E,y-E,DATA-E,Resolution 32*64
if((fen_L==5)&&(miao_H==0)&&(miao_L==9))
goto Clear;
}
}
}
}
//Clear screen
Clear:
EPD_HW_Init(); //Electronic paper initialization
EPD_WhiteScreen_White(); //Show all white
EPD_DeepSleep(); //Enter deep sleep,Sleep instruction is necessary, please do not delete!!!
}
}
【效果】见视频:
引用: xutong 发表于 2023-4-30 08:23 看起来电子墨水屏刷新速度不会太慢
还好吧,还是没有掌握好。
引用: 秦天qintian0303 发表于 2023-5-1 17:03 五一大家都没有出去啊
在家里写报告,今天完成三篇。开心开心呀!