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