-
Notifications
You must be signed in to change notification settings - Fork 0
/
kobo_helpers.c
87 lines (77 loc) · 2.44 KB
/
kobo_helpers.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* SPDX-License-Identifier: MIT */
#define _GNU_SOURCE
#define __STDC_FORMAT_MACROS
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/types.h>
#include "kobo_fb.h"
#include <sys/ioctl.h>
#include <stdint.h>
#include "lvgl.h"
static struct mxcfb_update_data fullUpdRegion;
/* static struct mxcfb_update_marker_data wait_for_update_data; */
static int fb0fd = 0;
struct fb_var_screeninfo vinfo;
struct fb_fix_screeninfo finfo;
static uint32_t current_update = 0;
void kobo_force_update(lv_area_t *area)
{
/* Setup the update region data structure. */
if(area != NULL) {
/*
wait_for_update_data.update_marker = fullUpdRegion.update_marker;
wait_for_update_data.collision_test = 0;
ioctl(fb0fd, MXCFB_WAIT_FOR_UPDATE_COMPLETE, (unsigned long int)&wait_for_update_data);
*/
fullUpdRegion.update_region.top = area->y1;
fullUpdRegion.update_region.left = area->x1;
fullUpdRegion.update_region.width = (area->x2 - area->x1 + 1);
fullUpdRegion.update_region.height = (area->y2 - area->y1 + 1);
}
fullUpdRegion.update_mode = UPDATE_MODE_PARTIAL;
fullUpdRegion.flags = 0;
fullUpdRegion.update_marker = current_update++;
/* Send the update request to the eInk chip */
ioctl(fb0fd , MXCFB_SEND_UPDATE, (unsigned long int)&fullUpdRegion);
}
char oldrot;
void kobo_deinitialize(void)
{
/* Restore the previous rotation */
int sysfd = open("/sys/class/graphics/fb0/rotate", O_WRONLY);
if(sysfd >= 0) {
write(sysfd, &oldrot, 1);
close(sysfd);
}
}
int kobo_initialize(void)
{
/* First set the screen rotation to be 0 (landscape on Aura) */
int sysfd = open("/sys/class/graphics/fb0/rotate", O_RDWR);
if(sysfd >= 0) {
char c = '0';
read(sysfd, &oldrot, 1);
write(sysfd, &c, 1);
close(sysfd);
}
/* Now open the framebuffer and collect the necessary information */
fb0fd = open("/dev/fb0", O_RDWR);
if(fb0fd == -1)
return -1;
ioctl(fb0fd, FBIOGET_FSCREENINFO, &finfo);
/* Set common options in the update region data structure */
fullUpdRegion.update_marker = 999;
fullUpdRegion.update_region.top = 0;
fullUpdRegion.update_region.left = 0;
fullUpdRegion.update_region.width = vinfo.xres - 1;
fullUpdRegion.update_region.height = vinfo.yres - 1;
fullUpdRegion.waveform_mode = 3;
fullUpdRegion.update_mode = UPDATE_MODE_FULL;
fullUpdRegion.temp = TEMP_USE_AMBIENT;
fullUpdRegion.flags = 0;
/* Update the screen once */
kobo_force_update(NULL);
printf("kobo hw initialized\n");
return fb0fd;
}