• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * originally written by: Kirk Reiser <kirk@braille.uwo.ca>
3  * this version considerably modified by David Borowski, david575@rogers.com
4  *
5  * Copyright (C) 1998-99  Kirk Reiser.
6  * Copyright (C) 2003 David Borowski.
7  *
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.
12  *
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.
17  *
18  * specificly written as a driver for the speakup screenreview
19  * s not a general device driver.
20  */
21 #include <linux/jiffies.h>
22 #include <linux/sched.h>
23 #include <linux/timer.h>
24 #include <linux/kthread.h>
25 
26 #include "spk_priv.h"
27 #include "speakup.h"
28 
29 #define DRV_VERSION "2.14"
30 #define SYNTH_CLEAR 0x03
31 #define PROCSPEECH 0x0b
32 
33 static volatile unsigned char last_char;
34 
read_buff_add(u_char ch)35 static void read_buff_add(u_char ch)
36 {
37 	last_char = ch;
38 }
39 
synth_full(void)40 static inline bool synth_full(void)
41 {
42 	return last_char == 0x13;
43 }
44 
45 static void do_catch_up(struct spk_synth *synth);
46 static void synth_flush(struct spk_synth *synth);
47 
48 static int in_escape;
49 
50 static struct var_t vars[] = {
51 	{ CAPS_START, .u.s = {"[:dv ap 222]" } },
52 	{ CAPS_STOP, .u.s = {"[:dv ap 100]" } },
53 	{ RATE, .u.n = {"[:ra %d]", 7, 0, 9, 150, 25, NULL } },
54 	{ PITCH, .u.n = {"[:dv ap %d]", 100, 0, 100, 0, 0, NULL } },
55 	{ VOL, .u.n = {"[:dv gv %d]", 13, 0, 16, 0, 5, NULL } },
56 	{ PUNCT, .u.n = {"[:pu %c]", 0, 0, 2, 0, 0, "nsa" } },
57 	{ VOICE, .u.n = {"[:n%c]", 0, 0, 9, 0, 0, "phfdburwkv" } },
58 	{ DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } },
59 	V_LAST_VAR
60 };
61 
62 /*
63  * These attributes will appear in /sys/accessibility/speakup/decext.
64  */
65 static struct kobj_attribute caps_start_attribute =
66 	__ATTR(caps_start, 0644, spk_var_show, spk_var_store);
67 static struct kobj_attribute caps_stop_attribute =
68 	__ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
69 static struct kobj_attribute pitch_attribute =
70 	__ATTR(pitch, 0644, spk_var_show, spk_var_store);
71 static struct kobj_attribute punct_attribute =
72 	__ATTR(punct, 0644, spk_var_show, spk_var_store);
73 static struct kobj_attribute rate_attribute =
74 	__ATTR(rate, 0644, spk_var_show, spk_var_store);
75 static struct kobj_attribute voice_attribute =
76 	__ATTR(voice, 0644, spk_var_show, spk_var_store);
77 static struct kobj_attribute vol_attribute =
78 	__ATTR(vol, 0644, spk_var_show, spk_var_store);
79 
80 static struct kobj_attribute delay_time_attribute =
81 	__ATTR(delay_time, 0644, spk_var_show, spk_var_store);
82 static struct kobj_attribute direct_attribute =
83 	__ATTR(direct, 0644, spk_var_show, spk_var_store);
84 static struct kobj_attribute full_time_attribute =
85 	__ATTR(full_time, 0644, spk_var_show, spk_var_store);
86 static struct kobj_attribute jiffy_delta_attribute =
87 	__ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
88 static struct kobj_attribute trigger_time_attribute =
89 	__ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
90 
91 /*
92  * Create a group of attributes so that we can create and destroy them all
93  * at once.
94  */
95 static struct attribute *synth_attrs[] = {
96 	&caps_start_attribute.attr,
97 	&caps_stop_attribute.attr,
98 	&pitch_attribute.attr,
99 	&punct_attribute.attr,
100 	&rate_attribute.attr,
101 	&voice_attribute.attr,
102 	&vol_attribute.attr,
103 	&delay_time_attribute.attr,
104 	&direct_attribute.attr,
105 	&full_time_attribute.attr,
106 	&jiffy_delta_attribute.attr,
107 	&trigger_time_attribute.attr,
108 	NULL,	/* need to NULL terminate the list of attributes */
109 };
110 
111 static struct spk_synth synth_decext = {
112 	.name = "decext",
113 	.version = DRV_VERSION,
114 	.long_name = "Dectalk External",
115 	.init = "[:pe -380]",
116 	.procspeech = PROCSPEECH,
117 	.clear = SYNTH_CLEAR,
118 	.delay = 500,
119 	.trigger = 50,
120 	.jiffies = 50,
121 	.full = 40000,
122 	.flags = SF_DEC,
123 	.dev_name = SYNTH_DEFAULT_DEV,
124 	.startup = SYNTH_START,
125 	.checkval = SYNTH_CHECK,
126 	.vars = vars,
127 	.io_ops = &spk_ttyio_ops,
128 	.probe = spk_ttyio_synth_probe,
129 	.release = spk_ttyio_release,
130 	.synth_immediate = spk_ttyio_synth_immediate,
131 	.catch_up = do_catch_up,
132 	.flush = synth_flush,
133 	.is_alive = spk_synth_is_alive_restart,
134 	.synth_adjust = NULL,
135 	.read_buff_add = read_buff_add,
136 	.get_index = NULL,
137 	.indexing = {
138 		.command = NULL,
139 		.lowindex = 0,
140 		.highindex = 0,
141 		.currindex = 0,
142 	},
143 	.attributes = {
144 		.attrs = synth_attrs,
145 		.name = "decext",
146 	},
147 };
148 
do_catch_up(struct spk_synth * synth)149 static void do_catch_up(struct spk_synth *synth)
150 {
151 	u_char ch;
152 	static u_char last = '\0';
153 	unsigned long flags;
154 	unsigned long jiff_max;
155 	struct var_t *jiffy_delta;
156 	struct var_t *delay_time;
157 	int jiffy_delta_val = 0;
158 	int delay_time_val = 0;
159 
160 	jiffy_delta = spk_get_var(JIFFY);
161 	delay_time = spk_get_var(DELAY);
162 
163 	spin_lock_irqsave(&speakup_info.spinlock, flags);
164 	jiffy_delta_val = jiffy_delta->u.n.value;
165 	spin_unlock_irqrestore(&speakup_info.spinlock, flags);
166 	jiff_max = jiffies + jiffy_delta_val;
167 
168 	while (!kthread_should_stop()) {
169 		spin_lock_irqsave(&speakup_info.spinlock, flags);
170 		if (speakup_info.flushing) {
171 			speakup_info.flushing = 0;
172 			spin_unlock_irqrestore(&speakup_info.spinlock, flags);
173 			synth->flush(synth);
174 			continue;
175 		}
176 		synth_buffer_skip_nonlatin1();
177 		if (synth_buffer_empty()) {
178 			spin_unlock_irqrestore(&speakup_info.spinlock, flags);
179 			break;
180 		}
181 		ch = synth_buffer_peek();
182 		set_current_state(TASK_INTERRUPTIBLE);
183 		delay_time_val = delay_time->u.n.value;
184 		spin_unlock_irqrestore(&speakup_info.spinlock, flags);
185 		if (ch == '\n')
186 			ch = 0x0D;
187 		if (synth_full() || !synth->io_ops->synth_out(synth, ch)) {
188 			schedule_timeout(msecs_to_jiffies(delay_time_val));
189 			continue;
190 		}
191 		set_current_state(TASK_RUNNING);
192 		spin_lock_irqsave(&speakup_info.spinlock, flags);
193 		synth_buffer_getc();
194 		spin_unlock_irqrestore(&speakup_info.spinlock, flags);
195 		if (ch == '[') {
196 			in_escape = 1;
197 		} else if (ch == ']') {
198 			in_escape = 0;
199 		} else if (ch <= SPACE) {
200 			if (!in_escape && strchr(",.!?;:", last))
201 				synth->io_ops->synth_out(synth, PROCSPEECH);
202 			if (time_after_eq(jiffies, jiff_max)) {
203 				if (!in_escape)
204 					synth->io_ops->synth_out(synth, PROCSPEECH);
205 				spin_lock_irqsave(&speakup_info.spinlock,
206 						  flags);
207 				jiffy_delta_val = jiffy_delta->u.n.value;
208 				delay_time_val = delay_time->u.n.value;
209 				spin_unlock_irqrestore(&speakup_info.spinlock,
210 						       flags);
211 				schedule_timeout(msecs_to_jiffies
212 						 (delay_time_val));
213 				jiff_max = jiffies + jiffy_delta_val;
214 			}
215 		}
216 		last = ch;
217 	}
218 	if (!in_escape)
219 		synth->io_ops->synth_out(synth, PROCSPEECH);
220 }
221 
synth_flush(struct spk_synth * synth)222 static void synth_flush(struct spk_synth *synth)
223 {
224 	in_escape = 0;
225 	synth->io_ops->flush_buffer();
226 	synth->synth_immediate(synth, "\033P;10z\033\\");
227 }
228 
229 module_param_named(ser, synth_decext.ser, int, 0444);
230 module_param_named(dev, synth_decext.dev_name, charp, S_IRUGO);
231 module_param_named(start, synth_decext.startup, short, 0444);
232 
233 MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");
234 MODULE_PARM_DESC(dev, "Set the device e.g. ttyUSB0, for the synthesizer.");
235 MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
236 
237 module_spk_synth(synth_decext);
238 
239 MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
240 MODULE_AUTHOR("David Borowski");
241 MODULE_DESCRIPTION("Speakup support for DECtalk External synthesizers");
242 MODULE_LICENSE("GPL");
243 MODULE_VERSION(DRV_VERSION);
244 
245