Skip to content

Commit

Permalink
Merge pull request #5 from mtribiere/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
mtribiere authored Jan 10, 2021
2 parents ea5e4db + fd65d35 commit e1f3737
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 51 deletions.
5 changes: 5 additions & 0 deletions main/EPD.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ esp_err_t epaper_update(){
//Set RAM position
epaper_write_cmd(0x4E);
epaper_write_data(0x00);

waitUntilIdle();

epaper_write_cmd(0x4F);
epaper_write_data(0x00);
Expand All @@ -66,6 +68,7 @@ esp_err_t epaper_update(){
}
}

waitUntilIdle();

//Send update command
epaper_write_cmd(0x22);
Expand All @@ -87,6 +90,8 @@ esp_err_t epaper_clear(){

esp_err_t epaper_deepsleep(){

waitUntilIdle();

//Send deep sleep command
epaper_write_cmd(0x10);
epaper_write_data(0x01);
Expand Down
72 changes: 29 additions & 43 deletions main/painterEPD.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
#include "painterEPD.h"


esp_err_t epaper_inverse_color(){

for(int j = 0;j<SCREEN_BUFFER_H;j++){
for(int i = 0;i<SCREEN_BUFFER_W;i++){
screenBuffer[i][j] = ~screenBuffer[i][j];
}
}

return ESP_OK;
}

esp_err_t epaper_draw_pixel(uint8_t x, uint8_t y, uint8_t value){

//If coordinates not in range
Expand Down Expand Up @@ -34,57 +46,31 @@ esp_err_t epaper_draw_square(uint8_t x, uint8_t y,uint8_t size){
return ESP_OK;
}

esp_err_t epaper_draw_line(uint8_t x, uint8_t y, enum Direction direction, uint8_t length ,uint8_t width){

uint8_t drawed = 0;

//Should not be multiple of 2 to keep line alignment
if(width%2 == 0)
width--;


//While not all line is drawned
while(drawed < length){
esp_err_t epaper_draw_line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1) {

//For each direction draw the pixel row
switch(direction){
case UP:
for(int i = 0;i<width;i++)
epaper_draw_pixel(x-((width-1)/2) + i,y,BLACK);
y++;
break;

case RIGHT:
for(int i = 0;i<width;i++)
epaper_draw_pixel(x,y + ((width-1)/2) - i,BLACK);
x++;
break;

case DOWN:
for(int i = 0;i<width;i++)
epaper_draw_pixel(x-((width-1)/2) + i,y,BLACK);
y--;
break;

case LEFT:
for(int i = 0;i<width;i++)
epaper_draw_pixel(x,y + ((width-1)/2) - i,BLACK);
x--;
break;

default:
return ESP_FAIL;
break;
/* Bresenham line algorithm */
int dx = x1 - x0 >= 0 ? x1 - x0 : x0 - x1;
int sx = x0 < x1 ? 1 : -1;
int dy = y1 - y0 <= 0 ? y1 - y0 : y0 - y1;
int sy = y0 < y1 ? 1 : -1;
int err = dx + dy;

while((x0 != x1) && (y0 != y1)) {
epaper_draw_pixel(x0, y0 , BLACK);
if (2 * err >= dy) {
err += dy;
x0 += sx;
}
if (2 * err <= dx) {
err += dx;
y0 += sy;
}

drawed++;
}

return ESP_OK;

}


esp_err_t epaper_draw_char(char c,uint8_t x, uint8_t y, Font font){

//Font size in pixel
Expand Down
6 changes: 2 additions & 4 deletions main/painterEPD.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@
#define BLACK 0
#define WHITE 1

//Define directions
enum Direction {UP, RIGHT, DOWN, LEFT};

//Define font struct
typedef struct{
uint16_t fontW; //Using 16 bits int to help memory management
uint16_t fontH; //
uint8_t *charset;
}Font;

esp_err_t epaper_inverse_color();
esp_err_t epaper_draw_pixel(uint8_t x, uint8_t y, uint8_t value);

esp_err_t epaper_draw_square(uint8_t x, uint8_t y,uint8_t size);
esp_err_t epaper_draw_line(uint8_t x, uint8_t y, enum Direction direction, uint8_t length ,uint8_t width);
esp_err_t epaper_draw_line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1);

esp_err_t epaper_draw_char(char c,uint8_t x, uint8_t y, Font font);
esp_err_t epaper_draw_string(char *str,uint32_t size,uint8_t x, uint8_t y, Font font);
Expand Down
4 changes: 2 additions & 2 deletions main/spiEPD.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ esp_err_t waitUntilIdle(){

esp_err_t epaper_rst()
{
gpio_set_level(EPAPER_RST_GPIO, 1);
delay_ms(200);
gpio_set_level(EPAPER_RST_GPIO, 0);
delay_ms(10);
gpio_set_level(EPAPER_RST_GPIO, 1);

delay_ms(200);
return ESP_OK;
}
Expand Down Expand Up @@ -171,6 +170,7 @@ esp_err_t init_SPI(){
trans.cmd = NULL;
trans.addr = NULL;
trans.mosi = NULL;
trans.miso = NULL;

return ESP_OK;
}
4 changes: 2 additions & 2 deletions main/spi_epaper.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/

#include <stdio.h>
#include <string.h>

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
Expand Down Expand Up @@ -66,11 +65,12 @@ void app_main(void)

epaper_draw_string("Hello world !",13,35,60,font20);
epaper_draw_string("from ESP8266",12,40,52,font12);

//Update the screen
epaper_update();

//Turn off the display
ESP_LOGI(TAG, "Sending deepsleep command");
epaper_deepsleep();

printf("====== Done, have a nice day ! ========\n");
Expand Down

0 comments on commit e1f3737

Please sign in to comment.