annotate lcdtest/phonemain.c @ 111:5bfb5a7262c1

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