Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 /*
0003  * originally written by: Kirk Reiser <kirk@braille.uwo.ca>
0004  * this version considerably modified by David Borowski, david575@rogers.com
0005  *
0006  * Copyright (C) 1998-99  Kirk Reiser.
0007  * Copyright (C) 2003 David Borowski.
0008  *
0009  * specifically written as a driver for the speakup screenreview
0010  * s not a general device driver.
0011  */
0012 #include <linux/jiffies.h>
0013 #include <linux/sched.h>
0014 #include <linux/timer.h>
0015 #include <linux/kthread.h>
0016 
0017 #include "spk_priv.h"
0018 #include "speakup.h"
0019 
0020 #define DRV_VERSION "2.14"
0021 #define SYNTH_CLEAR 0x03
0022 #define PROCSPEECH 0x0b
0023 
0024 static volatile unsigned char last_char;
0025 
0026 static void read_buff_add(u_char ch)
0027 {
0028     last_char = ch;
0029 }
0030 
0031 static inline bool synth_full(void)
0032 {
0033     return last_char == 0x13;
0034 }
0035 
0036 static void do_catch_up(struct spk_synth *synth);
0037 static void synth_flush(struct spk_synth *synth);
0038 
0039 static int in_escape;
0040 
0041 static struct var_t vars[] = {
0042     { CAPS_START, .u.s = {"[:dv ap 222]" } },
0043     { CAPS_STOP, .u.s = {"[:dv ap 100]" } },
0044     { RATE, .u.n = {"[:ra %d]", 7, 0, 9, 150, 25, NULL } },
0045     { PITCH, .u.n = {"[:dv ap %d]", 100, 0, 100, 0, 0, NULL } },
0046     { INFLECTION, .u.n = {"[:dv pr %d] ", 100, 0, 10000, 0, 0, NULL } },
0047     { VOL, .u.n = {"[:dv gv %d]", 13, 0, 16, 0, 5, NULL } },
0048     { PUNCT, .u.n = {"[:pu %c]", 0, 0, 2, 0, 0, "nsa" } },
0049     { VOICE, .u.n = {"[:n%c]", 0, 0, 9, 0, 0, "phfdburwkv" } },
0050     { DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } },
0051     V_LAST_VAR
0052 };
0053 
0054 /*
0055  * These attributes will appear in /sys/accessibility/speakup/decext.
0056  */
0057 static struct kobj_attribute caps_start_attribute =
0058     __ATTR(caps_start, 0644, spk_var_show, spk_var_store);
0059 static struct kobj_attribute caps_stop_attribute =
0060     __ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
0061 static struct kobj_attribute pitch_attribute =
0062     __ATTR(pitch, 0644, spk_var_show, spk_var_store);
0063 static struct kobj_attribute inflection_attribute =
0064     __ATTR(inflection, 0644, spk_var_show, spk_var_store);
0065 static struct kobj_attribute punct_attribute =
0066     __ATTR(punct, 0644, spk_var_show, spk_var_store);
0067 static struct kobj_attribute rate_attribute =
0068     __ATTR(rate, 0644, spk_var_show, spk_var_store);
0069 static struct kobj_attribute voice_attribute =
0070     __ATTR(voice, 0644, spk_var_show, spk_var_store);
0071 static struct kobj_attribute vol_attribute =
0072     __ATTR(vol, 0644, spk_var_show, spk_var_store);
0073 
0074 static struct kobj_attribute delay_time_attribute =
0075     __ATTR(delay_time, 0644, spk_var_show, spk_var_store);
0076 static struct kobj_attribute direct_attribute =
0077     __ATTR(direct, 0644, spk_var_show, spk_var_store);
0078 static struct kobj_attribute full_time_attribute =
0079     __ATTR(full_time, 0644, spk_var_show, spk_var_store);
0080 static struct kobj_attribute jiffy_delta_attribute =
0081     __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
0082 static struct kobj_attribute trigger_time_attribute =
0083     __ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
0084 
0085 /*
0086  * Create a group of attributes so that we can create and destroy them all
0087  * at once.
0088  */
0089 static struct attribute *synth_attrs[] = {
0090     &caps_start_attribute.attr,
0091     &caps_stop_attribute.attr,
0092     &pitch_attribute.attr,
0093     &inflection_attribute.attr,
0094     &punct_attribute.attr,
0095     &rate_attribute.attr,
0096     &voice_attribute.attr,
0097     &vol_attribute.attr,
0098     &delay_time_attribute.attr,
0099     &direct_attribute.attr,
0100     &full_time_attribute.attr,
0101     &jiffy_delta_attribute.attr,
0102     &trigger_time_attribute.attr,
0103     NULL,   /* need to NULL terminate the list of attributes */
0104 };
0105 
0106 static struct spk_synth synth_decext = {
0107     .name = "decext",
0108     .version = DRV_VERSION,
0109     .long_name = "Dectalk External",
0110     .init = "[:pe -380]",
0111     .procspeech = PROCSPEECH,
0112     .clear = SYNTH_CLEAR,
0113     .delay = 500,
0114     .trigger = 50,
0115     .jiffies = 50,
0116     .full = 40000,
0117     .flags = SF_DEC,
0118     .dev_name = SYNTH_DEFAULT_DEV,
0119     .startup = SYNTH_START,
0120     .checkval = SYNTH_CHECK,
0121     .vars = vars,
0122     .io_ops = &spk_ttyio_ops,
0123     .probe = spk_ttyio_synth_probe,
0124     .release = spk_ttyio_release,
0125     .synth_immediate = spk_ttyio_synth_immediate,
0126     .catch_up = do_catch_up,
0127     .flush = synth_flush,
0128     .is_alive = spk_synth_is_alive_restart,
0129     .synth_adjust = NULL,
0130     .read_buff_add = read_buff_add,
0131     .get_index = NULL,
0132     .indexing = {
0133         .command = NULL,
0134         .lowindex = 0,
0135         .highindex = 0,
0136         .currindex = 0,
0137     },
0138     .attributes = {
0139         .attrs = synth_attrs,
0140         .name = "decext",
0141     },
0142 };
0143 
0144 static void do_catch_up(struct spk_synth *synth)
0145 {
0146     u_char ch;
0147     static u_char last = '\0';
0148     unsigned long flags;
0149     unsigned long jiff_max;
0150     struct var_t *jiffy_delta;
0151     struct var_t *delay_time;
0152     int jiffy_delta_val = 0;
0153     int delay_time_val = 0;
0154 
0155     jiffy_delta = spk_get_var(JIFFY);
0156     delay_time = spk_get_var(DELAY);
0157 
0158     spin_lock_irqsave(&speakup_info.spinlock, flags);
0159     jiffy_delta_val = jiffy_delta->u.n.value;
0160     spin_unlock_irqrestore(&speakup_info.spinlock, flags);
0161     jiff_max = jiffies + jiffy_delta_val;
0162 
0163     while (!kthread_should_stop()) {
0164         spin_lock_irqsave(&speakup_info.spinlock, flags);
0165         if (speakup_info.flushing) {
0166             speakup_info.flushing = 0;
0167             spin_unlock_irqrestore(&speakup_info.spinlock, flags);
0168             synth->flush(synth);
0169             continue;
0170         }
0171         synth_buffer_skip_nonlatin1();
0172         if (synth_buffer_empty()) {
0173             spin_unlock_irqrestore(&speakup_info.spinlock, flags);
0174             break;
0175         }
0176         ch = synth_buffer_peek();
0177         set_current_state(TASK_INTERRUPTIBLE);
0178         delay_time_val = delay_time->u.n.value;
0179         spin_unlock_irqrestore(&speakup_info.spinlock, flags);
0180         if (ch == '\n')
0181             ch = 0x0D;
0182         if (synth_full() || !synth->io_ops->synth_out(synth, ch)) {
0183             schedule_timeout(msecs_to_jiffies(delay_time_val));
0184             continue;
0185         }
0186         set_current_state(TASK_RUNNING);
0187         spin_lock_irqsave(&speakup_info.spinlock, flags);
0188         synth_buffer_getc();
0189         spin_unlock_irqrestore(&speakup_info.spinlock, flags);
0190         if (ch == '[') {
0191             in_escape = 1;
0192         } else if (ch == ']') {
0193             in_escape = 0;
0194         } else if (ch <= SPACE) {
0195             if (!in_escape && strchr(",.!?;:", last))
0196                 synth->io_ops->synth_out(synth, PROCSPEECH);
0197             if (time_after_eq(jiffies, jiff_max)) {
0198                 if (!in_escape)
0199                     synth->io_ops->synth_out(synth,
0200                                  PROCSPEECH);
0201                 spin_lock_irqsave(&speakup_info.spinlock,
0202                           flags);
0203                 jiffy_delta_val = jiffy_delta->u.n.value;
0204                 delay_time_val = delay_time->u.n.value;
0205                 spin_unlock_irqrestore(&speakup_info.spinlock,
0206                                flags);
0207                 schedule_timeout(msecs_to_jiffies
0208                          (delay_time_val));
0209                 jiff_max = jiffies + jiffy_delta_val;
0210             }
0211         }
0212         last = ch;
0213     }
0214     if (!in_escape)
0215         synth->io_ops->synth_out(synth, PROCSPEECH);
0216 }
0217 
0218 static void synth_flush(struct spk_synth *synth)
0219 {
0220     in_escape = 0;
0221     synth->io_ops->flush_buffer(synth);
0222     synth->synth_immediate(synth, "\033P;10z\033\\");
0223 }
0224 
0225 module_param_named(ser, synth_decext.ser, int, 0444);
0226 module_param_named(dev, synth_decext.dev_name, charp, 0444);
0227 module_param_named(start, synth_decext.startup, short, 0444);
0228 
0229 MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");
0230 MODULE_PARM_DESC(dev, "Set the device e.g. ttyUSB0, for the synthesizer.");
0231 MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
0232 
0233 module_spk_synth(synth_decext);
0234 
0235 MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
0236 MODULE_AUTHOR("David Borowski");
0237 MODULE_DESCRIPTION("Speakup support for DECtalk External synthesizers");
0238 MODULE_LICENSE("GPL");
0239 MODULE_VERSION(DRV_VERSION);
0240