Path: blob/master/drivers/accessibility/speakup/speakup_decext.c
26282 views
// SPDX-License-Identifier: GPL-2.0+1/*2* originally written by: Kirk Reiser <[email protected]>3* this version considerably modified by David Borowski, [email protected]4*5* Copyright (C) 1998-99 Kirk Reiser.6* Copyright (C) 2003 David Borowski.7*8* specifically written as a driver for the speakup screenreview9* s not a general device driver.10*/11#include <linux/jiffies.h>12#include <linux/sched.h>13#include <linux/timer.h>14#include <linux/kthread.h>1516#include "spk_priv.h"17#include "speakup.h"1819#define DRV_VERSION "2.14"20#define SYNTH_CLEAR 0x0321#define PROCSPEECH 0x0b2223static volatile unsigned char last_char;2425static void read_buff_add(u_char ch)26{27last_char = ch;28}2930static inline bool synth_full(void)31{32return last_char == 0x13;33}3435static void do_catch_up(struct spk_synth *synth);36static void synth_flush(struct spk_synth *synth);3738static int in_escape;394041enum default_vars_id {42CAPS_START_ID = 0, CAPS_STOP_ID,43RATE_ID, PITCH_ID, INFLECTION_ID,44VOL_ID, PUNCT_ID, VOICE_ID,45DIRECT_ID, V_LAST_ID,46NB_ID,47};4849static struct var_t vars[NB_ID] = {50[CAPS_START_ID] = { CAPS_START, .u.s = {"[:dv ap 222]" } },51[CAPS_STOP_ID] = { CAPS_STOP, .u.s = {"[:dv ap 100]" } },52[RATE_ID] = { RATE, .u.n = {"[:ra %d]", 7, 0, 9, 150, 25, NULL } },53[PITCH_ID] = { PITCH, .u.n = {"[:dv ap %d]", 100, 0, 100, 0, 0, NULL } },54[INFLECTION_ID] = { INFLECTION, .u.n = {"[:dv pr %d] ", 100, 0, 10000, 0, 0, NULL } },55[VOL_ID] = { VOL, .u.n = {"[:dv gv %d]", 13, 0, 16, 0, 5, NULL } },56[PUNCT_ID] = { PUNCT, .u.n = {"[:pu %c]", 0, 0, 2, 0, 0, "nsa" } },57[VOICE_ID] = { VOICE, .u.n = {"[:n%c]", 0, 0, 9, 0, 0, "phfdburwkv" } },58[DIRECT_ID] = { DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } },59V_LAST_VAR60};6162/*63* These attributes will appear in /sys/accessibility/speakup/decext.64*/65static struct kobj_attribute caps_start_attribute =66__ATTR(caps_start, 0644, spk_var_show, spk_var_store);67static struct kobj_attribute caps_stop_attribute =68__ATTR(caps_stop, 0644, spk_var_show, spk_var_store);69static struct kobj_attribute pitch_attribute =70__ATTR(pitch, 0644, spk_var_show, spk_var_store);71static struct kobj_attribute inflection_attribute =72__ATTR(inflection, 0644, spk_var_show, spk_var_store);73static struct kobj_attribute punct_attribute =74__ATTR(punct, 0644, spk_var_show, spk_var_store);75static struct kobj_attribute rate_attribute =76__ATTR(rate, 0644, spk_var_show, spk_var_store);77static struct kobj_attribute voice_attribute =78__ATTR(voice, 0644, spk_var_show, spk_var_store);79static struct kobj_attribute vol_attribute =80__ATTR(vol, 0644, spk_var_show, spk_var_store);8182static struct kobj_attribute delay_time_attribute =83__ATTR(delay_time, 0644, spk_var_show, spk_var_store);84static struct kobj_attribute direct_attribute =85__ATTR(direct, 0644, spk_var_show, spk_var_store);86static struct kobj_attribute full_time_attribute =87__ATTR(full_time, 0644, spk_var_show, spk_var_store);88static struct kobj_attribute jiffy_delta_attribute =89__ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);90static struct kobj_attribute trigger_time_attribute =91__ATTR(trigger_time, 0644, spk_var_show, spk_var_store);9293/*94* Create a group of attributes so that we can create and destroy them all95* at once.96*/97static struct attribute *synth_attrs[] = {98&caps_start_attribute.attr,99&caps_stop_attribute.attr,100&pitch_attribute.attr,101&inflection_attribute.attr,102&punct_attribute.attr,103&rate_attribute.attr,104&voice_attribute.attr,105&vol_attribute.attr,106&delay_time_attribute.attr,107&direct_attribute.attr,108&full_time_attribute.attr,109&jiffy_delta_attribute.attr,110&trigger_time_attribute.attr,111NULL, /* need to NULL terminate the list of attributes */112};113114static struct spk_synth synth_decext = {115.name = "decext",116.version = DRV_VERSION,117.long_name = "Dectalk External",118.init = "[:pe -380]",119.procspeech = PROCSPEECH,120.clear = SYNTH_CLEAR,121.delay = 500,122.trigger = 50,123.jiffies = 50,124.full = 40000,125.flags = SF_DEC,126.dev_name = SYNTH_DEFAULT_DEV,127.startup = SYNTH_START,128.checkval = SYNTH_CHECK,129.vars = vars,130.io_ops = &spk_ttyio_ops,131.probe = spk_ttyio_synth_probe,132.release = spk_ttyio_release,133.synth_immediate = spk_ttyio_synth_immediate,134.catch_up = do_catch_up,135.flush = synth_flush,136.is_alive = spk_synth_is_alive_restart,137.synth_adjust = NULL,138.read_buff_add = read_buff_add,139.get_index = NULL,140.indexing = {141.command = NULL,142.lowindex = 0,143.highindex = 0,144.currindex = 0,145},146.attributes = {147.attrs = synth_attrs,148.name = "decext",149},150};151152static void do_catch_up(struct spk_synth *synth)153{154u_char ch;155static u_char last = '\0';156unsigned long flags;157unsigned long jiff_max;158struct var_t *jiffy_delta;159struct var_t *delay_time;160int jiffy_delta_val = 0;161int delay_time_val = 0;162163jiffy_delta = spk_get_var(JIFFY);164delay_time = spk_get_var(DELAY);165166spin_lock_irqsave(&speakup_info.spinlock, flags);167jiffy_delta_val = jiffy_delta->u.n.value;168spin_unlock_irqrestore(&speakup_info.spinlock, flags);169jiff_max = jiffies + jiffy_delta_val;170171while (!kthread_should_stop()) {172spin_lock_irqsave(&speakup_info.spinlock, flags);173if (speakup_info.flushing) {174speakup_info.flushing = 0;175spin_unlock_irqrestore(&speakup_info.spinlock, flags);176synth->flush(synth);177continue;178}179synth_buffer_skip_nonlatin1();180if (synth_buffer_empty()) {181spin_unlock_irqrestore(&speakup_info.spinlock, flags);182break;183}184ch = synth_buffer_peek();185set_current_state(TASK_INTERRUPTIBLE);186delay_time_val = delay_time->u.n.value;187spin_unlock_irqrestore(&speakup_info.spinlock, flags);188if (ch == '\n')189ch = 0x0D;190if (synth_full() || !synth->io_ops->synth_out(synth, ch)) {191schedule_timeout(msecs_to_jiffies(delay_time_val));192continue;193}194set_current_state(TASK_RUNNING);195spin_lock_irqsave(&speakup_info.spinlock, flags);196synth_buffer_getc();197spin_unlock_irqrestore(&speakup_info.spinlock, flags);198if (ch == '[') {199in_escape = 1;200} else if (ch == ']') {201in_escape = 0;202} else if (ch <= SPACE) {203if (!in_escape && strchr(",.!?;:", last))204synth->io_ops->synth_out(synth, PROCSPEECH);205if (time_after_eq(jiffies, jiff_max)) {206if (!in_escape)207synth->io_ops->synth_out(synth,208PROCSPEECH);209spin_lock_irqsave(&speakup_info.spinlock,210flags);211jiffy_delta_val = jiffy_delta->u.n.value;212delay_time_val = delay_time->u.n.value;213spin_unlock_irqrestore(&speakup_info.spinlock,214flags);215schedule_timeout(msecs_to_jiffies216(delay_time_val));217jiff_max = jiffies + jiffy_delta_val;218}219}220last = ch;221}222if (!in_escape)223synth->io_ops->synth_out(synth, PROCSPEECH);224}225226static void synth_flush(struct spk_synth *synth)227{228in_escape = 0;229synth->io_ops->flush_buffer(synth);230synth->synth_immediate(synth, "\033P;10z\033\\");231}232233module_param_named(ser, synth_decext.ser, int, 0444);234module_param_named(dev, synth_decext.dev_name, charp, 0444);235module_param_named(start, synth_decext.startup, short, 0444);236module_param_named(rate, vars[RATE_ID].u.n.default_val, int, 0444);237module_param_named(pitch, vars[PITCH_ID].u.n.default_val, int, 0444);238module_param_named(inflection, vars[INFLECTION_ID].u.n.default_val, int, 0444);239module_param_named(vol, vars[VOL_ID].u.n.default_val, int, 0444);240module_param_named(punct, vars[PUNCT_ID].u.n.default_val, int, 0444);241module_param_named(voice, vars[VOICE_ID].u.n.default_val, int, 0444);242module_param_named(direct, vars[DIRECT_ID].u.n.default_val, int, 0444);243244245MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");246MODULE_PARM_DESC(dev, "Set the device e.g. ttyUSB0, for the synthesizer.");247MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");248MODULE_PARM_DESC(rate, "Set the rate variable on load.");249MODULE_PARM_DESC(pitch, "Set the pitch variable on load.");250MODULE_PARM_DESC(inflection, "Set the inflection variable on load.");251MODULE_PARM_DESC(vol, "Set the vol variable on load.");252MODULE_PARM_DESC(punct, "Set the punct variable on load.");253MODULE_PARM_DESC(voice, "Set the voice variable on load.");254MODULE_PARM_DESC(direct, "Set the direct variable on load.");255256module_spk_synth(synth_decext);257258MODULE_AUTHOR("Kirk Reiser <[email protected]>");259MODULE_AUTHOR("David Borowski");260MODULE_DESCRIPTION("Speakup support for DECtalk External synthesizers");261MODULE_LICENSE("GPL");262MODULE_VERSION(DRV_VERSION);263264265266