1 /* $Id: serial-kb.h,v 1.3 2006/09/30 12:35:01 fredette Exp $ */
2 
3 /* serial/serial-kb.h - implementation header file for serial keyboard
4    emulation: */
5 
6 /*
7  * Copyright (c) 2003 Matt Fredette
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *      This product includes software developed by Matt Fredette.
21  * 4. The name of the author may not be used to endorse or promote products
22  *    derived from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
28  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  */
36 
37 #ifndef _SERIAL_SERIAL_KB_H
38 #define _SERIAL_SERIAL_KB_H
39 
40 #include <tme/common.h>
41 _TME_RCSID("$Id: serial-kb.h,v 1.3 2006/09/30 12:35:01 fredette Exp $");
42 
43 /* includes: */
44 #include <tme/generic/keyboard.h>
45 #include <tme/generic/serial.h>
46 #include <tme/element.h>
47 #include <tme/threads.h>
48 
49 /* macros: */
50 
51 /* the callout flags: */
52 #define TME_SERIAL_KB_CALLOUT_CHECK		(0)
53 #define TME_SERIAL_KB_CALLOUT_RUNNING		TME_BIT(0)
54 #define TME_SERIAL_KB_CALLOUTS_MASK		(-2)
55 #define  TME_SERIAL_KB_CALLOUT_SERIAL_CTRL	TME_BIT(1)
56 #define  TME_SERIAL_KB_CALLOUT_SERIAL_CONFIG	TME_BIT(2)
57 #define  TME_SERIAL_KB_CALLOUT_SERIAL_READ	TME_BIT(3)
58 #define  TME_SERIAL_KB_CALLOUT_KEYBOARD_CTRL	TME_BIT(4)
59 #define  TME_SERIAL_KB_CALLOUT_KEYBOARD_READ	TME_BIT(5)
60 
61 /* types: */
62 
63 /* a serial keyboard: */
64 struct tme_serial_kb {
65 
66   /* backpointer to our element: */
67   struct tme_element *tme_serial_kb_element;
68 
69   /* our mutex: */
70   tme_mutex_t tme_serial_kb_mutex;
71 
72   /* our type: */
73   _tme_const char *tme_serial_kb_type;
74 
75   /* our type-specific state: */
76   void *tme_serial_kb_type_state;
77 
78   /* our type-specific pre-map-adding function: */
79   int (*tme_serial_kb_type_map_add_pre) _TME_P((struct tme_serial_kb *,
80 						struct tme_keyboard_map *));
81 
82   /* our type-specific post-map-adding function: */
83   int (*tme_serial_kb_type_map_add_post) _TME_P((struct tme_serial_kb *,
84 						 _tme_const struct tme_keyboard_map *));
85 
86   /* our type-specific event function: */
87   tme_uint8_t (*tme_serial_kb_type_event) _TME_P((struct tme_serial_kb *,
88 						  _tme_const struct tme_keyboard_event *));
89 
90   /* our type-specific serial control function: */
91   int (*tme_serial_kb_type_serial_ctrl) _TME_P((struct tme_serial_kb *,
92 						unsigned int));
93 
94   /* our type-specific serial input function: */
95   int (*tme_serial_kb_type_serial_input) _TME_P((struct tme_serial_kb *,
96 						 tme_uint8_t *,
97 						 unsigned int,
98 						 tme_serial_data_flags_t));
99 
100   /* our type-specific serial configuration: */
101   struct tme_serial_config tme_serial_kb_type_config;
102 
103   /* our stored macros: */
104   char **tme_serial_kb_macros;
105 
106   /* our stored map entries: */
107   char **tme_serial_kb_map;
108 
109   /* our keyboard connection: */
110   struct tme_keyboard_connection *tme_serial_kb_connection_kb;
111 
112   /* our serial connection: */
113   struct tme_serial_connection *tme_serial_kb_connection_serial;
114 
115   /* the callout flags: */
116   int tme_serial_kb_callout_flags;
117 
118   /* our keyboard buffer: */
119   struct tme_keyboard_buffer *tme_serial_kb_keyboard_buffer;
120 
121   /* our serial output buffer: */
122   struct tme_serial_buffer tme_serial_kb_serial_buffer;
123 
124   /* our current keyboard control outputs: */
125   unsigned int tme_serial_kb_keyboard_ctrl;
126 
127   /* our current serial control outputs: */
128   unsigned int tme_serial_kb_serial_ctrl;
129 
130   /* when nonzero, the rate-limiting sleep time, in microseconds: */
131   unsigned long tme_serial_kb_rate_sleep;
132 
133   /* when nonzero, rate-limiting is active: */
134   int tme_serial_kb_rate_limited;
135 
136   /* when nonzero, rate-limiting is active and sleeping: */
137   int tme_serial_kb_rate_sleeping;
138 
139   /* our rate-limiting thread condition: */
140   tme_cond_t tme_serial_kb_rate_cond;
141 };
142 
143 /* prototypes: */
144 int _tme_serial_kb_sun_init _TME_P((struct tme_serial_kb *));
145 
146 #endif /* !_SERIAL_SERIAL_KB_H */
147