speakup_decext.c 7.4 KB

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