comparison lcdtest/phonemain.c @ 28:de3d3cfcbb35

lcdtest: lcdphone program put together, compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 27 May 2018 22:26:58 +0000
parents
children 60bcd401363a
comparison
equal deleted inserted replaced
27:4b7cac119fb5 28:de3d3cfcbb35
1 #include <sys/types.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <strings.h>
6 #include <unistd.h>
7 #include <ftdi.h>
8 #include <rvinterf/etm.h>
9 #include <rvinterf/localtypes.h>
10 #include "exitcodes.h"
11
12 extern int init_haoran();
13 extern int init_startek();
14
15 extern char *socket_pathname;
16
17 char *device_serial, *display_type;
18 struct ftdi_context ftdi;
19 int (*lcd_init_func)();
20 u32 framebuffer_base_addr;
21
22 process_cmdline(argc, argv)
23 char **argv;
24 {
25 int c;
26 extern int optind;
27 extern char *optarg;
28
29 while ((c = getopt(argc, argv, "d:s:")) != EOF) {
30 switch (c) {
31 case 'd':
32 device_serial = optarg;
33 continue;
34 case 's':
35 socket_pathname = optarg;
36 continue;
37 default:
38 /* error msg already printed */
39 exit(ERROR_USAGE);
40 }
41 }
42 if (argc != optind + 2) {
43 fprintf(stderr,
44 "usage: %s [options] display_type framebuffer_base_addr\n",
45 argv[0]);
46 exit(ERROR_USAGE);
47 }
48 display_type = argv[optind];
49 if (!strcmp(display_type, "haoran"))
50 lcd_init_func = init_haoran;
51 else if (!strcmp(display_type, "startek"))
52 lcd_init_func = init_startek;
53 else {
54 fprintf(stderr, "error: display type \"%s\" unknown\n",
55 display_type);
56 exit(ERROR_USAGE);
57 }
58 framebuffer_base_addr = strtoul(argv[optind+1], 0, 16);
59 }
60
61 ftdi_setup()
62 {
63 ftdi_init(&ftdi);
64 if (ftdi_usb_open_desc(&ftdi, 0x0403, 0x7157, 0, device_serial) < 0) {
65 fprintf(stderr, "FTDI USB open failed: %s\n", ftdi.error_str);
66 exit(ERROR_FTDI);
67 }
68 if (ftdi_set_bitmode(&ftdi, 0, BITMODE_MCU) < 0) {
69 fprintf(stderr, "unable to enter MCU mode: %s\n",
70 ftdi.error_str);
71 exit(ERROR_FTDI);
72 }
73 }
74
75 lcd_init()
76 {
77 reset_pulse();
78 usleep(50000);
79 lcd_init_func();
80 usleep(50000);
81 write_ir(0x20);
82 write_dr(0);
83 write_ir(0x21);
84 write_dr(0);
85 write_ir(0x22);
86 set_gpio_pins(1, 1);
87 }
88
89 fb_poll()
90 {
91 unsigned row, col;
92 u_char membuf[176*2], *sp;
93 u_char ftbuf[176*6], *dp;
94 int rc;
95
96 for (row = 0; row < 220; row++) {
97 rc = do_memory_read_32(framebuffer_base_addr + row * 356,
98 membuf, 44);
99 if (rc)
100 exit(rc);
101 rc = do_memory_read_32(framebuffer_base_addr + row * 356 + 176,
102 membuf + 176, 44);
103 if (rc)
104 exit(rc);
105 sp = membuf;
106 dp = ftbuf;
107 for (col = 0; col < 176; col++) {
108 /* upper byte */
109 *dp++ = 0x92;
110 *dp++ = 0; /* dummy addr */
111 *dp++ = sp[1];
112 /* lower byte */
113 *dp++ = 0x92;
114 *dp++ = 0; /* dummy addr */
115 *dp++ = sp[0];
116 sp += 2;
117 }
118 do_ftdi_write(ftbuf, sizeof ftbuf);
119 }
120 }
121
122 main(argc, argv)
123 char **argv;
124 {
125 process_cmdline(argc, argv);
126 ftdi_setup();
127 connect_local_socket();
128 lcd_init();
129
130 for (;;)
131 fb_poll();
132 }