2 // Micro-Windows/Nano-X additional setup fo eCos
5 #include <pkgconf/system.h>
6 #include <pkgconf/kernel.h>
7 #include <pkgconf/hal.h>
8 #include <pkgconf/microwindows.h>
9 #include <cyg/kernel/kapi.h>
10 #include <cyg/infra/diag.h>
22 #define MWINCLUDECOLORS
23 #include <microwin/nano-X.h>
29 static bool closed = false;
32 do_close(NBUTTON * w, int b)
34 printf("Button %d was clicked in widget %p\n",b,w);
39 // Display a number of ticks as microseconds
40 // Note: for improved calculation significance, values are kept in ticks*1000
44 diag_printf("%5d.%02d", (int)(ns/1000), (int)((ns%1000)/10));
47 static long rtc_resolution[] = CYGNUM_KERNEL_COUNTERS_RTC_RESOLUTION;
48 static long ns_per_system_clock;
56 ns_per_system_clock = 1000000/rtc_resolution[1];
58 ns = (ns_per_system_clock * (long long)off) / CYGNUM_KERNEL_COUNTERS_RTC_PERIOD;
59 ns += 5; // for rounding to .01us
60 clocks = (cyg_current_time() * 10000000) + ns;
67 long long start_time, end_time;
69 unsigned char buf[256];
72 start_time = ns_time();
74 if ((fp = fopen("/redhat.logo", "r")) != (FILE *)NULL) {
75 while (fgets(buf, sizeof(buf), fp)) {
81 diag_printf("'fgets': %d bytes in ", len); show_ns(end_time-start_time); diag_printf("ns\n");
83 start_time = ns_time();
85 if ((fp = fopen("/redhat.logo", "r")) != (FILE *)NULL) {
86 while ((n = fread(buf, 1, sizeof(buf), fp))) {
92 diag_printf("'fread': %d bytes in ", len); show_ns(end_time-start_time); diag_printf("ns\n");
94 start_time = ns_time();
96 if ((fd = open("/redhat.logo", O_RDONLY)) >= 0) {
97 while ((n = read(fd, buf, sizeof(buf)))) {
102 end_time = ns_time();
103 diag_printf("'read': %d bytes in ", len); show_ns(end_time-start_time); diag_printf("ns\n");
107 ecos_nx_init(CYG_ADDRWORD data)
109 GR_SCREEN_INFO si; /* window information */
110 GR_FONT_INFO fi; /* font information */
111 GR_WINDOW_ID mainwid; /* main window id */
112 GR_WM_PROPERTIES props;
120 cyg_thread_delay(50);
121 INIT_PER_THREAD_DATA();
126 fprintf(stderr, "Couldn't connect to Nano-X server\n");
130 #if (defined CYGPKG_HAL_ARM_SA11X0_IPAQ) && (!defined CYGBLD_MICROWINDOWS_VNC_DRIVERS)
131 GrSetPortraitMode(MWPORTRAIT_RIGHT);
134 GrGetScreenInfo(&si);
135 GrGetFontInfo(0, &fi);
138 mainwid = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, si.cols, si.rows,
141 props.flags = GR_WM_FLAGS_PROPS;
142 props.props = GR_WM_PROPS_BORDER;
143 GrSetWMProperties(mainwid, &props);
145 GrMapWindow(mainwid);
147 cyg_thread_delay(50);
150 GrSetGCForeground(gct, WHITE);
152 #ifdef CYGPKG_IO_FILEIO
154 struct stat stat_data;
155 if (0 == stat("/redhat.logo", &stat_data)) {
156 GrDrawImageFromFile(mainwid, gct, 0, 0, si.cols, si.rows, "/redhat.logo", 0);
161 #if (defined CYGPKG_HAL_ARM) && (!defined CYGBLD_MICROWINDOWS_VNC_DRIVERS)
162 // Touch sensitive screen calibration, only relevant on some
164 GrSetGCFont(gct, GrCreateFont(GR_FONT_GUI_VAR, 0, NULL));
165 GrText(mainwid, gct, 80, 350, "Tap all 4 corners", 17, GR_TFTOP);
167 printf("Tap all four corners\n");
168 cyg_thread_delay(10*100);
172 n_init_button_class();
173 n_init_textfield_class();
175 w = NEW_NOBJECT(widget);
177 n_widget_resize(w, si.cols - 10, si.rows - 30);
178 n_widget_background(w, "/redhat.logo");
181 b = NEW_NOBJECT(button);
182 n_button_init(b, w, "Close");
183 n_button_onclick(b, do_close);
184 n_widget_resize(b, 40, 20);
185 n_widget_move(b,180,260);
188 t = NEW_NOBJECT(textfield);
189 n_textfield_init(t,w,"Tap all 4 corners");
190 n_widget_move(t,45,220);
191 n_widget_resize(t,120,20);
194 t = NEW_NOBJECT(textfield);
195 n_textfield_init(t,w,"Then press close");
196 n_widget_move(t,45,250);
197 n_widget_resize(t,120,20);