speakup_decext.c 7.0 KB

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