martinberlin / CalEPD

Epaper ESP-IDF component with GFX capabilities and multi SPI support

Home Page:https://fasani.de

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using the Driver with C coded Program

matti122 opened this issue · comments

Hello Martin,
I got some an issue at using the Driver with an C coded Program.
First issue is that you will need to force C++ Compile of the include header gdew075T7.h and others.
The second issue is that there is a wrapper needed to access the functions from the C Code.
Can you please support.
Thanks

Hello Matthias,
Sorry but this class was programmed with C++ in mind and I have no plans to do it in C directly.
It has an structure that is object oriented. However feel free to make a C port if you want. I cannot really provide support on this since my C is not good enough for this mission.

Just one suggestion, can you check this repository:
https://github.com/martinberlin/cale-idf

There I implemented some demos using CalEPD as a component. Maybe you can use part of this as an example?
C and C++ can actually live together. But of course your main program should be also C++ if you want to use this library, and that's probably something you don't want to update. Sorry life is like this, once you make a choice, there is something left behind.
Update: check how NVS is implemented on ESP-IDF I might be able to help but only if someone else can take the responsibility to test this. The language I feel more comfortable with programming is C++

Feel free to reopen this if there is a possibility to go forward

@matti122 Just wanted to let you know there is a nice way to use a C graphics library. For example EZdib

Relevant parts to be added:

// Constants EPAPER for example 4.2"
#define EPD_WIDTH  400
#define EPD_HEIGHT 300
#define BLACK 0
#define WHITE 1
#define EPD_BUFFER_SIZE EPD_WIDTH*EPD_HEIGHT/8

// GFX library test in STM32:
#include <ezdib.c>
// Orientation (only 2: LANDSCAPE & LANDSCAPE_INVERTED)
#define LANDSCAPE_INVERTED

// Our 15K buffer
static uint8_t framebuf[EPD_BUFFER_SIZE]; // 15000 + imagesize extra EZD
HEZDIMAGE himage;
HEZDFONT hFont;

// Some test functions and implementation of drawPixel callback
int draw_pixel( void *pUser, int x, int y, int c, int f ) {
	if ((x < 0) || (x >= EPD_WIDTH) || (y < 0) || (y >= EPD_HEIGHT)) return 0;
	// MIRROR Issue. Swap X axis (For sure there is a smarter solution than this one)
	x = EPD_WIDTH-x;

#ifdef LANDSCAPE_INVERTED
    x = EPD_WIDTH - x - 1;
    y = EPD_HEIGHT - y - 1;
#endif
	uint16_t i = x / 8 + y * EPD_WIDTH / 8;

	  // This formulas are from gxEPD that apparently got the color right:
	framebuf[i] = (framebuf[i] & (0xFF ^ (1 << (7 - x % 8))));

	if (c != 0) {
	 framebuf[i] = (framebuf[i] | (1 << (7 - x % 8)));
	}
	return 1;
}

void epd_fb_init() {
	// Fill buffer with WHITE
	memset(framebuf, 0xFF, sizeof(framebuf));
	// Create HEZDIMAGE
	himage = ezd_create(EPD_WIDTH, EPD_HEIGHT, 1, EZD_FLAG_USER_IMAGE_BUFFER);  // EZD_FLAG_USER_IMAGE_BUFFER = Do not need buffer

	// Set pixel callback function
	ezd_set_pixel_callback( himage, &draw_pixel, (void *)0);
}

// HEZDIMAGE x_hDib, int x1, int y1, int x2, int y2, int x_col )
void epd_line(int x1, int y1, int x2, int y2, int color) {
	ezd_line( himage, x1, y1, x2, y2, color);
}

void epd_fill_rect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, int color) {
    ezd_fill_rect(himage, x, y, x+w, y+h, color);
}

void epd_font(const void *x_pFt, const char * text, uint16_t x, uint16_t y, uint16_t color) {
	hFont = ezd_load_font( x_pFt, 1, 0);
	if ( hFont ) {
		ezd_text( himage, hFont, text, -1, x, y, color);
	}
}

void epd_circle(uint16_t x, uint16_t y, uint16_t radio, uint8_t color) {
	ezd_circle( himage, x, y, radio, color);
}

Closed due to lack of feedback. C compatible reference given with the hope someone can use it to create a new Library