162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * originally written by: Kirk Reiser <kirk@braille.uwo.ca> 462306a36Sopenharmony_ci * this version considerably modified by David Borowski, david575@rogers.com 562306a36Sopenharmony_ci * 662306a36Sopenharmony_ci * Copyright (C) 1998-99 Kirk Reiser. 762306a36Sopenharmony_ci * Copyright (C) 2003 David Borowski. 862306a36Sopenharmony_ci * 962306a36Sopenharmony_ci * specifically written as a driver for the speakup screenreview 1062306a36Sopenharmony_ci * s not a general device driver. 1162306a36Sopenharmony_ci */ 1262306a36Sopenharmony_ci#include "spk_priv.h" 1362306a36Sopenharmony_ci#include "speakup.h" 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci#define DRV_VERSION "2.11" 1662306a36Sopenharmony_ci#define SYNTH_CLEAR 0x18 /* flush synth buffer */ 1762306a36Sopenharmony_ci#define PROCSPEECH '\r' /* start synth processing speech char */ 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_cistatic int synth_probe(struct spk_synth *synth); 2062306a36Sopenharmony_cistatic void synth_flush(struct spk_synth *synth); 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_cienum default_vars_id { 2462306a36Sopenharmony_ci CAPS_START_ID = 0, CAPS_STOP_ID, 2562306a36Sopenharmony_ci RATE_ID, PITCH_ID, 2662306a36Sopenharmony_ci VOL_ID, TONE_ID, PUNCT_ID, 2762306a36Sopenharmony_ci DIRECT_ID, V_LAST_VAR_ID, 2862306a36Sopenharmony_ci NB_ID 2962306a36Sopenharmony_ci}; 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_cistatic struct var_t vars[NB_ID] = { 3262306a36Sopenharmony_ci [CAPS_START_ID] = { CAPS_START, .u.s = {"\x05[f99]" } }, 3362306a36Sopenharmony_ci [CAPS_STOP_ID] = { CAPS_STOP, .u.s = {"\x05[f80]" } }, 3462306a36Sopenharmony_ci [RATE_ID] = { RATE, .u.n = {"\x05[r%d]", 10, 0, 20, 100, -10, NULL } }, 3562306a36Sopenharmony_ci [PITCH_ID] = { PITCH, .u.n = {"\x05[f%d]", 80, 39, 4500, 0, 0, NULL } }, 3662306a36Sopenharmony_ci [VOL_ID] = { VOL, .u.n = {"\x05[g%d]", 21, 0, 40, 0, 0, NULL } }, 3762306a36Sopenharmony_ci [TONE_ID] = { TONE, .u.n = {"\x05[s%d]", 9, 0, 63, 0, 0, NULL } }, 3862306a36Sopenharmony_ci [PUNCT_ID] = { PUNCT, .u.n = {"\x05[A%c]", 0, 0, 3, 0, 0, "nmsa" } }, 3962306a36Sopenharmony_ci [DIRECT_ID] = { DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } }, 4062306a36Sopenharmony_ci V_LAST_VAR 4162306a36Sopenharmony_ci}; 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci/* 4462306a36Sopenharmony_ci * These attributes will appear in /sys/accessibility/speakup/audptr. 4562306a36Sopenharmony_ci */ 4662306a36Sopenharmony_cistatic struct kobj_attribute caps_start_attribute = 4762306a36Sopenharmony_ci __ATTR(caps_start, 0644, spk_var_show, spk_var_store); 4862306a36Sopenharmony_cistatic struct kobj_attribute caps_stop_attribute = 4962306a36Sopenharmony_ci __ATTR(caps_stop, 0644, spk_var_show, spk_var_store); 5062306a36Sopenharmony_cistatic struct kobj_attribute pitch_attribute = 5162306a36Sopenharmony_ci __ATTR(pitch, 0644, spk_var_show, spk_var_store); 5262306a36Sopenharmony_cistatic struct kobj_attribute punct_attribute = 5362306a36Sopenharmony_ci __ATTR(punct, 0644, spk_var_show, spk_var_store); 5462306a36Sopenharmony_cistatic struct kobj_attribute rate_attribute = 5562306a36Sopenharmony_ci __ATTR(rate, 0644, spk_var_show, spk_var_store); 5662306a36Sopenharmony_cistatic struct kobj_attribute tone_attribute = 5762306a36Sopenharmony_ci __ATTR(tone, 0644, spk_var_show, spk_var_store); 5862306a36Sopenharmony_cistatic struct kobj_attribute vol_attribute = 5962306a36Sopenharmony_ci __ATTR(vol, 0644, spk_var_show, spk_var_store); 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_cistatic struct kobj_attribute delay_time_attribute = 6262306a36Sopenharmony_ci __ATTR(delay_time, 0644, spk_var_show, spk_var_store); 6362306a36Sopenharmony_cistatic struct kobj_attribute direct_attribute = 6462306a36Sopenharmony_ci __ATTR(direct, 0644, spk_var_show, spk_var_store); 6562306a36Sopenharmony_cistatic struct kobj_attribute full_time_attribute = 6662306a36Sopenharmony_ci __ATTR(full_time, 0644, spk_var_show, spk_var_store); 6762306a36Sopenharmony_cistatic struct kobj_attribute jiffy_delta_attribute = 6862306a36Sopenharmony_ci __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store); 6962306a36Sopenharmony_cistatic struct kobj_attribute trigger_time_attribute = 7062306a36Sopenharmony_ci __ATTR(trigger_time, 0644, spk_var_show, spk_var_store); 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci/* 7362306a36Sopenharmony_ci * Create a group of attributes so that we can create and destroy them all 7462306a36Sopenharmony_ci * at once. 7562306a36Sopenharmony_ci */ 7662306a36Sopenharmony_cistatic struct attribute *synth_attrs[] = { 7762306a36Sopenharmony_ci &caps_start_attribute.attr, 7862306a36Sopenharmony_ci &caps_stop_attribute.attr, 7962306a36Sopenharmony_ci &pitch_attribute.attr, 8062306a36Sopenharmony_ci &punct_attribute.attr, 8162306a36Sopenharmony_ci &rate_attribute.attr, 8262306a36Sopenharmony_ci &tone_attribute.attr, 8362306a36Sopenharmony_ci &vol_attribute.attr, 8462306a36Sopenharmony_ci &delay_time_attribute.attr, 8562306a36Sopenharmony_ci &direct_attribute.attr, 8662306a36Sopenharmony_ci &full_time_attribute.attr, 8762306a36Sopenharmony_ci &jiffy_delta_attribute.attr, 8862306a36Sopenharmony_ci &trigger_time_attribute.attr, 8962306a36Sopenharmony_ci NULL, /* need to NULL terminate the list of attributes */ 9062306a36Sopenharmony_ci}; 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_cistatic struct spk_synth synth_audptr = { 9362306a36Sopenharmony_ci .name = "audptr", 9462306a36Sopenharmony_ci .version = DRV_VERSION, 9562306a36Sopenharmony_ci .long_name = "Audapter", 9662306a36Sopenharmony_ci .init = "\x05[D1]\x05[Ol]", 9762306a36Sopenharmony_ci .procspeech = PROCSPEECH, 9862306a36Sopenharmony_ci .clear = SYNTH_CLEAR, 9962306a36Sopenharmony_ci .delay = 400, 10062306a36Sopenharmony_ci .trigger = 50, 10162306a36Sopenharmony_ci .jiffies = 30, 10262306a36Sopenharmony_ci .full = 18000, 10362306a36Sopenharmony_ci .dev_name = SYNTH_DEFAULT_DEV, 10462306a36Sopenharmony_ci .startup = SYNTH_START, 10562306a36Sopenharmony_ci .checkval = SYNTH_CHECK, 10662306a36Sopenharmony_ci .vars = vars, 10762306a36Sopenharmony_ci .io_ops = &spk_ttyio_ops, 10862306a36Sopenharmony_ci .probe = synth_probe, 10962306a36Sopenharmony_ci .release = spk_ttyio_release, 11062306a36Sopenharmony_ci .synth_immediate = spk_ttyio_synth_immediate, 11162306a36Sopenharmony_ci .catch_up = spk_do_catch_up, 11262306a36Sopenharmony_ci .flush = synth_flush, 11362306a36Sopenharmony_ci .is_alive = spk_synth_is_alive_restart, 11462306a36Sopenharmony_ci .synth_adjust = NULL, 11562306a36Sopenharmony_ci .read_buff_add = NULL, 11662306a36Sopenharmony_ci .get_index = NULL, 11762306a36Sopenharmony_ci .indexing = { 11862306a36Sopenharmony_ci .command = NULL, 11962306a36Sopenharmony_ci .lowindex = 0, 12062306a36Sopenharmony_ci .highindex = 0, 12162306a36Sopenharmony_ci .currindex = 0, 12262306a36Sopenharmony_ci }, 12362306a36Sopenharmony_ci .attributes = { 12462306a36Sopenharmony_ci .attrs = synth_attrs, 12562306a36Sopenharmony_ci .name = "audptr", 12662306a36Sopenharmony_ci }, 12762306a36Sopenharmony_ci}; 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_cistatic void synth_flush(struct spk_synth *synth) 13062306a36Sopenharmony_ci{ 13162306a36Sopenharmony_ci synth->io_ops->flush_buffer(synth); 13262306a36Sopenharmony_ci synth->io_ops->send_xchar(synth, SYNTH_CLEAR); 13362306a36Sopenharmony_ci synth->io_ops->synth_out(synth, PROCSPEECH); 13462306a36Sopenharmony_ci} 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_cistatic void synth_version(struct spk_synth *synth) 13762306a36Sopenharmony_ci{ 13862306a36Sopenharmony_ci unsigned i; 13962306a36Sopenharmony_ci char synth_id[33]; 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_ci synth->synth_immediate(synth, "\x05[Q]"); 14262306a36Sopenharmony_ci synth_id[0] = synth->io_ops->synth_in(synth); 14362306a36Sopenharmony_ci if (synth_id[0] != 'A') 14462306a36Sopenharmony_ci return; 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_ci for (i = 1; i < sizeof(synth_id) - 1; i++) { 14762306a36Sopenharmony_ci /* read version string from synth */ 14862306a36Sopenharmony_ci synth_id[i] = synth->io_ops->synth_in(synth); 14962306a36Sopenharmony_ci if (synth_id[i] == '\n') 15062306a36Sopenharmony_ci break; 15162306a36Sopenharmony_ci } 15262306a36Sopenharmony_ci synth_id[i] = '\0'; 15362306a36Sopenharmony_ci pr_info("%s version: %s", synth->long_name, synth_id); 15462306a36Sopenharmony_ci} 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_cistatic int synth_probe(struct spk_synth *synth) 15762306a36Sopenharmony_ci{ 15862306a36Sopenharmony_ci int failed; 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_ci failed = spk_ttyio_synth_probe(synth); 16162306a36Sopenharmony_ci if (failed == 0) 16262306a36Sopenharmony_ci synth_version(synth); 16362306a36Sopenharmony_ci synth->alive = !failed; 16462306a36Sopenharmony_ci return 0; 16562306a36Sopenharmony_ci} 16662306a36Sopenharmony_ci 16762306a36Sopenharmony_cimodule_param_named(ser, synth_audptr.ser, int, 0444); 16862306a36Sopenharmony_cimodule_param_named(dev, synth_audptr.dev_name, charp, 0444); 16962306a36Sopenharmony_cimodule_param_named(start, synth_audptr.startup, short, 0444); 17062306a36Sopenharmony_cimodule_param_named(rate, vars[RATE_ID].u.n.default_val, int, 0444); 17162306a36Sopenharmony_cimodule_param_named(pitch, vars[PITCH_ID].u.n.default_val, int, 0444); 17262306a36Sopenharmony_cimodule_param_named(vol, vars[VOL_ID].u.n.default_val, int, 0444); 17362306a36Sopenharmony_cimodule_param_named(tone, vars[TONE_ID].u.n.default_val, int, 0444); 17462306a36Sopenharmony_cimodule_param_named(punct, vars[PUNCT_ID].u.n.default_val, int, 0444); 17562306a36Sopenharmony_cimodule_param_named(direct, vars[DIRECT_ID].u.n.default_val, int, 0444); 17662306a36Sopenharmony_ci 17762306a36Sopenharmony_ci 17862306a36Sopenharmony_ci 17962306a36Sopenharmony_ciMODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based)."); 18062306a36Sopenharmony_ciMODULE_PARM_DESC(dev, "Set the device e.g. ttyUSB0, for the synthesizer."); 18162306a36Sopenharmony_ciMODULE_PARM_DESC(start, "Start the synthesizer once it is loaded."); 18262306a36Sopenharmony_ciMODULE_PARM_DESC(rate, "Set the rate variable on load."); 18362306a36Sopenharmony_ciMODULE_PARM_DESC(pitch, "Set the pitch variable on load."); 18462306a36Sopenharmony_ciMODULE_PARM_DESC(vol, "Set the vol variable on load."); 18562306a36Sopenharmony_ciMODULE_PARM_DESC(tone, "Set the tone variable on load."); 18662306a36Sopenharmony_ciMODULE_PARM_DESC(punct, "Set the punct variable on load."); 18762306a36Sopenharmony_ciMODULE_PARM_DESC(direct, "Set the direct variable on load."); 18862306a36Sopenharmony_ci 18962306a36Sopenharmony_ci 19062306a36Sopenharmony_cimodule_spk_synth(synth_audptr); 19162306a36Sopenharmony_ci 19262306a36Sopenharmony_ciMODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>"); 19362306a36Sopenharmony_ciMODULE_AUTHOR("David Borowski"); 19462306a36Sopenharmony_ciMODULE_DESCRIPTION("Speakup support for Audapter synthesizer"); 19562306a36Sopenharmony_ciMODULE_LICENSE("GPL"); 19662306a36Sopenharmony_ciMODULE_VERSION(DRV_VERSION); 19762306a36Sopenharmony_ci 198