source: rtems/c/src/lib/libbsp/arm/nds/touchscreen/parser.c @ ef4c461

4.115
Last change on this file since ef4c461 was ef4c461, checked in by Joel Sherrill <joel.sherrill@…>, on 10/09/14 at 20:35:10

arm/nds: Warning clean up

This patch eliminates most of the warnings in this BSP but attempts
very little clean up. This BSP includes copies of a lot of code
from free NDS libraries and modifications should be kept to a minimum.

  • Property mode set to 100644
File size: 3.8 KB
Line 
1/*
2 * RTEMS for Nintendo DS input parser.
3 *
4 * Copyright (c) 2008 by Matthieu Bucchianeri <mbucchia@gmail.com>
5 *
6 * The license and distribution terms for this file may be
7 * found in the file LICENSE in this distribution or at
8 *
9 * http://www.rtems.org/license/LICENSE
10 */
11
12#include <stdio.h>
13#include <stdlib.h>
14#include <rtems.h>
15
16#include <nds.h>
17
18#include <rtems/mw_uid.h>
19
20/*
21 * from console/console.c
22 */
23
24extern void console_push (char c);
25extern void register_kbd_msg_queue (char *q_name);
26extern void unregister_kbd_msg_queue (void);
27
28/*
29 * from reco.c
30 */
31
32extern char PA_CheckLetter (int down, int x, int y);
33
34/*
35 * message queue for touchscreen and graffiti events.
36 */
37extern void register_mou_msg_queue (char *q_name);
38extern void unregister_mou_msg_queue (void);
39static rtems_id mou_queue_id = 0;
40static rtems_id kbd_queue_id = 0;
41
42/*
43 * old position.
44 */
45
46static int old_x = 0;
47static int old_y = 0;
48static int old_btns = 0;
49
50/*
51 * hand mode.
52 */
53
54static int hand = 0;
55
56/*
57 * Shared methods
58 */
59void update_touchscreen (void);
60void touchscreen_sethand (int h);
61
62/*
63 * update touchscreen position
64 */
65void
66update_touchscreen (void)
67{
68  static int graffiti = 0;
69  struct MW_UID_MESSAGE m;
70  int x, y, k, kh, btns = 0;
71  touchPosition pos;
72  char c;
73
74  /* update keypad & touchscreen */
75  scanKeys ();
76  pos = touchReadXY ();
77  x = pos.px;
78  y = pos.py;
79  k = keysDown ();
80  kh = keysHeld ();
81
82  /* check for character recognition */
83  if ((kh & KEY_L) || (kh & KEY_R)) {
84    graffiti = 1;
85    c = PA_CheckLetter ((kh & KEY_TOUCH ? 1 : 0), x, y);
86    if (c) {
87      /* signal the console driver */
88      console_push (c);
89      if (kbd_queue_id != 0) {
90        /* send the read character */
91        m.type = MV_UID_KBD;
92        m.m.kbd.code = c;
93        m.m.kbd.modifiers = 0;
94        m.m.kbd.mode = MV_KEY_MODE_ASCII;
95        rtems_message_queue_send (kbd_queue_id, (void *) &m,
96                                  sizeof (struct MW_UID_MESSAGE));
97      }
98    }
99  } else {
100    if (graffiti == 1) {
101      x = old_x;
102      y = old_y;
103    }
104    graffiti = 0;
105  }
106
107  if (mou_queue_id == 0)
108    return;
109
110  if (hand == 1) {
111    if (k & KEY_LEFT) {
112      btns = MV_BUTTON_LEFT;
113    }
114    if (k & KEY_RIGHT) {
115      btns = MV_BUTTON_RIGHT;
116    }
117  } else {
118    if (k & KEY_A) {
119      btns = MV_BUTTON_LEFT;
120    }
121    if (k & KEY_B) {
122      btns = MV_BUTTON_RIGHT;
123    }
124  }
125
126  if (!((kh & KEY_L) || (kh & KEY_R)) && (kh & KEY_TOUCH)
127      && (x != old_x || y != old_y || btns)) {
128    /* send the read position */
129    m.type = MV_UID_ABS_POS;
130    old_btns = m.m.pos.btns = btns;
131    old_x = m.m.pos.x = x;
132    old_y = m.m.pos.y = y;
133    m.m.pos.z = 0;
134    rtems_message_queue_send (mou_queue_id, (void *) &m,
135                              sizeof (struct MW_UID_MESSAGE));
136  }
137}
138
139/*
140 * register a message queue for touchscreen events.
141 */
142
143void
144register_mou_msg_queue (char *q_name)
145{
146  rtems_name queue_name;
147  rtems_status_code status;
148
149  queue_name = rtems_build_name (q_name[0], q_name[1], q_name[2], q_name[3]);
150  status = rtems_message_queue_ident (queue_name, RTEMS_LOCAL, &mou_queue_id);
151  if (status != RTEMS_SUCCESSFUL) {
152    printk ("[!] cannot create queue %d\n", status);
153    return;
154  }
155
156  update_touchscreen ();
157}
158
159/*
160 * unregister the message queue.
161 */
162
163void
164unregister_mou_msg_queue (void)
165{
166  /* nothing here */
167}
168
169/*
170 * register a message queue for graffiti events.
171 */
172
173void
174register_kbd_msg_queue (char *q_name)
175{
176  rtems_name queue_name;
177  rtems_status_code status;
178
179  queue_name = rtems_build_name (q_name[0], q_name[1], q_name[2], q_name[3]);
180  status = rtems_message_queue_ident (queue_name, RTEMS_LOCAL, &kbd_queue_id);
181  if (status != RTEMS_SUCCESSFUL) {
182    printk ("[!] cannot create queue %d\n", status);
183    return;
184  }
185}
186
187/*
188 * unregister the message queue.
189 */
190
191void
192unregister_kbd_msg_queue (void)
193{
194  /* nothing here */
195}
196
197/*
198 * set hand mode.
199 */
200
201void
202touchscreen_sethand (int h)
203{
204  hand = h;
205}
Note: See TracBrowser for help on using the repository browser.