2 * originally written by: Kirk Reiser <kirk@braille.uwo.ca>
3 * this version considerably modified by David Borowski, david575@rogers.com
5 * Copyright (C) 1998-99 Kirk Reiser.
6 * Copyright (C) 2003 David Borowski.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * specificly written as a driver for the speakup screenreview
23 * s not a general device driver.
25 #include <linux/unistd.h>
26 #include <linux/proc_fs.h>
27 #include <linux/jiffies.h>
28 #include <linux/spinlock.h>
29 #include <linux/sched.h>
30 #include <linux/timer.h>
31 #include <linux/kthread.h>
36 #define DRV_VERSION "2.20"
37 #define SYNTH_CLEAR 0x03
38 #define PROCSPEECH 0x0b
41 static inline int synth_full(void)
46 static void do_catch_up(struct spk_synth *synth);
47 static void synth_flush(struct spk_synth *synth);
48 static void read_buff_add(u_char c);
49 static unsigned char get_index(void);
52 static int is_flushing;
54 static spinlock_t flush_lock;
55 static DECLARE_WAIT_QUEUE_HEAD(flush);
57 static struct var_t vars[] = {
58 { CAPS_START, .u.s = {"[:dv ap 160] " } },
59 { CAPS_STOP, .u.s = {"[:dv ap 100 ] " } },
60 { RATE, .u.n = {"[:ra %d] ", 180, 75, 650, 0, 0, NULL } },
61 { PITCH, .u.n = {"[:dv ap %d] ", 122, 50, 350, 0, 0, NULL } },
62 { VOL, .u.n = {"[:dv g5 %d] ", 86, 60, 86, 0, 0, NULL } },
63 { PUNCT, .u.n = {"[:pu %c] ", 0, 0, 2, 0, 0, "nsa" } },
64 { VOICE, .u.n = {"[:n%c] ", 0, 0, 9, 0, 0, "phfdburwkv" } },
65 { DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } },
70 * These attributes will appear in /sys/accessibility/speakup/dectlk.
72 static struct kobj_attribute caps_start_attribute =
73 __ATTR(caps_start, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
74 static struct kobj_attribute caps_stop_attribute =
75 __ATTR(caps_stop, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
76 static struct kobj_attribute pitch_attribute =
77 __ATTR(pitch, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
78 static struct kobj_attribute punct_attribute =
79 __ATTR(punct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
80 static struct kobj_attribute rate_attribute =
81 __ATTR(rate, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
82 static struct kobj_attribute voice_attribute =
83 __ATTR(voice, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
84 static struct kobj_attribute vol_attribute =
85 __ATTR(vol, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
87 static struct kobj_attribute delay_time_attribute =
88 __ATTR(delay_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
89 static struct kobj_attribute direct_attribute =
90 __ATTR(direct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
91 static struct kobj_attribute full_time_attribute =
92 __ATTR(full_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
93 static struct kobj_attribute jiffy_delta_attribute =
94 __ATTR(jiffy_delta, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
95 static struct kobj_attribute trigger_time_attribute =
96 __ATTR(trigger_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
99 * Create a group of attributes so that we can create and destroy them all
102 static struct attribute *synth_attrs[] = {
103 &caps_start_attribute.attr,
104 &caps_stop_attribute.attr,
105 &pitch_attribute.attr,
106 &punct_attribute.attr,
107 &rate_attribute.attr,
108 &voice_attribute.attr,
110 &delay_time_attribute.attr,
111 &direct_attribute.attr,
112 &full_time_attribute.attr,
113 &jiffy_delta_attribute.attr,
114 &trigger_time_attribute.attr,
115 NULL, /* need to NULL terminate the list of attributes */
118 static int ap_defaults[] = {122, 89, 155, 110, 208, 240, 200, 106, 306};
119 static int g5_defaults[] = {86, 81, 86, 84, 81, 80, 83, 83, 73};
121 static struct spk_synth synth_dectlk = {
123 .version = DRV_VERSION,
124 .long_name = "Dectalk Express",
125 .init = "[:error sp :name paul :rate 180 :tsr off] ",
126 .procspeech = PROCSPEECH,
127 .clear = SYNTH_CLEAR,
132 .startup = SYNTH_START,
133 .checkval = SYNTH_CHECK,
135 .default_pitch = ap_defaults,
136 .default_vol = g5_defaults,
137 .probe = spk_serial_synth_probe,
138 .release = spk_serial_release,
139 .synth_immediate = spk_synth_immediate,
140 .catch_up = do_catch_up,
141 .flush = synth_flush,
142 .is_alive = spk_synth_is_alive_restart,
143 .synth_adjust = NULL,
144 .read_buff_add = read_buff_add,
145 .get_index = get_index,
147 .command = "[:in re %d ] ",
153 .attrs = synth_attrs,
158 static int is_indnum(u_char *ch)
160 if ((*ch >= '0') && (*ch <= '9')) {
167 static u_char lastind;
169 static unsigned char get_index(void)
178 static void read_buff_add(u_char c)
185 spin_lock_irqsave(&flush_lock, flags);
187 wake_up_interruptible(&flush);
188 spin_unlock_irqrestore(&flush_lock, flags);
189 } else if (c == 0x13) {
191 } else if (c == 0x11) {
193 } else if (is_indnum(&c)) {
198 } else if ((c > 31) && (c < 127)) {
200 lastind = (u_char)ind;
205 static void do_catch_up(struct spk_synth *synth)
207 int synth_full_val = 0;
209 static u_char last = '\0';
211 unsigned long jiff_max;
212 unsigned long timeout = msecs_to_jiffies(4000);
214 struct var_t *jiffy_delta;
215 struct var_t *delay_time;
219 jiffy_delta = spk_get_var(JIFFY);
220 delay_time = spk_get_var(DELAY);
221 spin_lock_irqsave(&speakup_info.spinlock, flags);
222 jiffy_delta_val = jiffy_delta->u.n.value;
223 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
224 jiff_max = jiffies + jiffy_delta_val;
226 while (!kthread_should_stop()) {
227 /* if no ctl-a in 4, send data anyway */
228 spin_lock_irqsave(&flush_lock, flags);
229 while (is_flushing && timeout) {
230 prepare_to_wait(&flush, &wait, TASK_INTERRUPTIBLE);
231 spin_unlock_irqrestore(&flush_lock, flags);
232 timeout = schedule_timeout(timeout);
233 spin_lock_irqsave(&flush_lock, flags);
235 finish_wait(&flush, &wait);
237 spin_unlock_irqrestore(&flush_lock, flags);
239 spin_lock_irqsave(&speakup_info.spinlock, flags);
240 if (speakup_info.flushing) {
241 speakup_info.flushing = 0;
242 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
246 if (synth_buffer_empty()) {
247 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
250 ch = synth_buffer_peek();
251 set_current_state(TASK_INTERRUPTIBLE);
252 delay_time_val = delay_time->u.n.value;
253 synth_full_val = synth_full();
254 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
257 if (synth_full_val || !spk_serial_out(ch)) {
258 schedule_timeout(msecs_to_jiffies(delay_time_val));
261 set_current_state(TASK_RUNNING);
262 spin_lock_irqsave(&speakup_info.spinlock, flags);
264 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
269 else if (ch <= SPACE) {
270 if (!in_escape && strchr(",.!?;:", last))
271 spk_serial_out(PROCSPEECH);
272 if (time_after_eq(jiffies, jiff_max)) {
274 spk_serial_out(PROCSPEECH);
275 spin_lock_irqsave(&speakup_info.spinlock,
277 jiffy_delta_val = jiffy_delta->u.n.value;
278 delay_time_val = delay_time->u.n.value;
279 spin_unlock_irqrestore(&speakup_info.spinlock,
281 schedule_timeout(msecs_to_jiffies
283 jiff_max = jiffies + jiffy_delta_val;
289 spk_serial_out(PROCSPEECH);
292 static void synth_flush(struct spk_synth *synth)
295 /* if in command output ']' so we don't get an error */
299 spk_serial_out(SYNTH_CLEAR);
302 module_param_named(ser, synth_dectlk.ser, int, S_IRUGO);
303 module_param_named(start, synth_dectlk.startup, short, S_IRUGO);
305 MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");
306 MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
308 module_spk_synth(synth_dectlk);
310 MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
311 MODULE_AUTHOR("David Borowski");
312 MODULE_DESCRIPTION("Speakup support for DECtalk Express synthesizers");
313 MODULE_LICENSE("GPL");
314 MODULE_VERSION(DRV_VERSION);