display.c 2.57 KB
Newer Older
1
#include "LCD/LCD_Driver.h"
2
3
4
#include "framebuffer.h"
#include "gfx.h"
#include "textbuffer.h"
5
6

#include "gpio.h"
7
8
#include "portexpander.h"
#include "MAX77650-Arduino-Library.h"
9
10
11

#include <stdint.h>
#include <stdio.h>
12

13
/***** Globals *****/
schneider's avatar
schneider committed
14
const gpio_cfg_t DEV_DC_PIN = { PORT_1, PIN_6, GPIO_FUNC_OUT, GPIO_PAD_NONE };
15

16
17
18
struct gfx_region display_screen;
struct txt_buffer display_textb;

Stefan Haun's avatar
Stefan Haun committed
19
20
/***** Virtual framebuffers *****/
static uint8_t app_buffer[LCD_HEIGHT][LCD_WIDTH][2];
Stefan Haun's avatar
Stefan Haun committed
21
22
23
24
25
26
static struct framebuffer app_framebuffer = { .data   = app_buffer,
					      .width  = LCD_WIDTH,
					      .height = LCD_HEIGHT,
					      .stride = LCD_WIDTH * LCD_HEIGHT *
							2,
					      .orientation = FB_O_180,
Stefan Haun's avatar
Stefan Haun committed
27

Stefan Haun's avatar
Stefan Haun committed
28
					      .update = NULL };
Stefan Haun's avatar
Stefan Haun committed
29
30
31
32

struct gfx_region application_screen;

static uint8_t ovl_buffer[LCD_HEIGHT][LCD_WIDTH][2];
Stefan Haun's avatar
Stefan Haun committed
33
34
35
36
37
38
static struct framebuffer ovl_framebuffer = { .data   = ovl_buffer,
					      .width  = LCD_WIDTH,
					      .height = LCD_HEIGHT,
					      .stride = LCD_WIDTH * LCD_HEIGHT *
							2,
					      .orientation = FB_O_180,
Stefan Haun's avatar
Stefan Haun committed
39

Stefan Haun's avatar
Stefan Haun committed
40
					      .update = NULL };
Stefan Haun's avatar
Stefan Haun committed
41
42
43

struct gfx_region overlay_screen;

44
/***** Functions *****/
45
46
void display_set_reset_pin(uint8_t state)
{
schneider's avatar
schneider committed
47
48
49
	if (!portexpander_detected()) {
		MAX77650_setDO(state ? true : false);
	} else {
50
		portexpander_out_put(PIN_4, state ? 0xFF : 0);
schneider's avatar
schneider committed
51
	}
52
}
53
54
55

void display_init(void)
{
schneider's avatar
schneider committed
56
57
58
59
60
61
	if (!portexpander_detected()) {
		// Open-drain
		MAX77650_setDRV(false);
		// Output
		MAX77650_setDIR(false);
	}
62

schneider's avatar
schneider committed
63
	GPIO_Config(&DEV_DC_PIN);
64

65
	LCD_SetBacklight(20);
schneider's avatar
schneider committed
66
	LCD_Init();
67

68
69
70
	display_screen = gfx_screen(LCD_framebuffer());
	txt_init(&display_textb, &display_screen, &Font12);
	gfx_clear(&display_screen);
Stefan Haun's avatar
Stefan Haun committed
71

Stefan Haun's avatar
Stefan Haun committed
72
73
74
	app_framebuffer.encode_color_rgb = display_screen.fb->encode_color_rgb;
	application_screen               = gfx_screen(&app_framebuffer);
	gfx_clear(&application_screen);
Stefan Haun's avatar
Stefan Haun committed
75

Stefan Haun's avatar
Stefan Haun committed
76
77
78
	ovl_framebuffer.encode_color_rgb = display_screen.fb->encode_color_rgb;
	overlay_screen                   = gfx_screen(&ovl_framebuffer);
	gfx_clear(&overlay_screen);
79
}
80
81
82
83
84
85
86
87
88
89
90
91
92
93

void display_init_slim(void)
{
	if (!portexpander_detected()) {
		// Open-drain
		MAX77650_setDRV(false);
		// Output
		MAX77650_setDIR(false);
	}

	GPIO_Config(&DEV_DC_PIN);

	display_screen = gfx_screen(LCD_framebuffer());
	txt_init(&display_textb, &display_screen, &Font12);
Stefan Haun's avatar
Stefan Haun committed
94

Stefan Haun's avatar
Stefan Haun committed
95
96
97
	app_framebuffer.encode_color_rgb = display_screen.fb->encode_color_rgb;
	application_screen               = gfx_screen(&app_framebuffer);
	gfx_clear(&application_screen);
Stefan Haun's avatar
Stefan Haun committed
98

Stefan Haun's avatar
Stefan Haun committed
99
100
101
	ovl_framebuffer.encode_color_rgb = display_screen.fb->encode_color_rgb;
	overlay_screen                   = gfx_screen(&ovl_framebuffer);
	gfx_clear(&overlay_screen);
102
}