speakup_audptr.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * originally written by: Kirk Reiser <kirk@braille.uwo.ca>
  4. * this version considerably modified by David Borowski, david575@rogers.com
  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 "spk_priv.h"
  13. #include "speakup.h"
  14. #define DRV_VERSION "2.11"
  15. #define SYNTH_CLEAR 0x18 /* flush synth buffer */
  16. #define PROCSPEECH '\r' /* start synth processing speech char */
  17. static int synth_probe(struct spk_synth *synth);
  18. static void synth_flush(struct spk_synth *synth);
  19. enum default_vars_id {
  20. CAPS_START_ID = 0, CAPS_STOP_ID,
  21. RATE_ID, PITCH_ID,
  22. VOL_ID, TONE_ID, PUNCT_ID,
  23. DIRECT_ID, V_LAST_VAR_ID,
  24. NB_ID
  25. };
  26. static struct var_t vars[NB_ID] = {
  27. [CAPS_START_ID] = { CAPS_START, .u.s = {"\x05[f99]" } },
  28. [CAPS_STOP_ID] = { CAPS_STOP, .u.s = {"\x05[f80]" } },
  29. [RATE_ID] = { RATE, .u.n = {"\x05[r%d]", 10, 0, 20, 100, -10, NULL } },
  30. [PITCH_ID] = { PITCH, .u.n = {"\x05[f%d]", 80, 39, 4500, 0, 0, NULL } },
  31. [VOL_ID] = { VOL, .u.n = {"\x05[g%d]", 21, 0, 40, 0, 0, NULL } },
  32. [TONE_ID] = { TONE, .u.n = {"\x05[s%d]", 9, 0, 63, 0, 0, NULL } },
  33. [PUNCT_ID] = { PUNCT, .u.n = {"\x05[A%c]", 0, 0, 3, 0, 0, "nmsa" } },
  34. [DIRECT_ID] = { DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } },
  35. V_LAST_VAR
  36. };
  37. /*
  38. * These attributes will appear in /sys/accessibility/speakup/audptr.
  39. */
  40. static struct kobj_attribute caps_start_attribute =
  41. __ATTR(caps_start, 0644, spk_var_show, spk_var_store);
  42. static struct kobj_attribute caps_stop_attribute =
  43. __ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
  44. static struct kobj_attribute pitch_attribute =
  45. __ATTR(pitch, 0644, spk_var_show, spk_var_store);
  46. static struct kobj_attribute punct_attribute =
  47. __ATTR(punct, 0644, spk_var_show, spk_var_store);
  48. static struct kobj_attribute rate_attribute =
  49. __ATTR(rate, 0644, spk_var_show, spk_var_store);
  50. static struct kobj_attribute tone_attribute =
  51. __ATTR(tone, 0644, spk_var_show, spk_var_store);
  52. static struct kobj_attribute vol_attribute =
  53. __ATTR(vol, 0644, spk_var_show, spk_var_store);
  54. static struct kobj_attribute delay_time_attribute =
  55. __ATTR(delay_time, 0644, spk_var_show, spk_var_store);
  56. static struct kobj_attribute direct_attribute =
  57. __ATTR(direct, 0644, spk_var_show, spk_var_store);
  58. static struct kobj_attribute full_time_attribute =
  59. __ATTR(full_time, 0644, spk_var_show, spk_var_store);
  60. static struct kobj_attribute jiffy_delta_attribute =
  61. __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
  62. static struct kobj_attribute trigger_time_attribute =
  63. __ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
  64. /*
  65. * Create a group of attributes so that we can create and destroy them all
  66. * at once.
  67. */
  68. static struct attribute *synth_attrs[] = {
  69. &caps_start_attribute.attr,
  70. &caps_stop_attribute.attr,
  71. &pitch_attribute.attr,
  72. &punct_attribute.attr,
  73. &rate_attribute.attr,
  74. &tone_attribute.attr,
  75. &vol_attribute.attr,
  76. &delay_time_attribute.attr,
  77. &direct_attribute.attr,
  78. &full_time_attribute.attr,
  79. &jiffy_delta_attribute.attr,
  80. &trigger_time_attribute.attr,
  81. NULL, /* need to NULL terminate the list of attributes */
  82. };
  83. static struct spk_synth synth_audptr = {
  84. .name = "audptr",
  85. .version = DRV_VERSION,
  86. .long_name = "Audapter",
  87. .init = "\x05[D1]\x05[Ol]",
  88. .procspeech = PROCSPEECH,
  89. .clear = SYNTH_CLEAR,
  90. .delay = 400,
  91. .trigger = 50,
  92. .jiffies = 30,
  93. .full = 18000,
  94. .dev_name = SYNTH_DEFAULT_DEV,
  95. .startup = SYNTH_START,
  96. .checkval = SYNTH_CHECK,
  97. .vars = vars,
  98. .io_ops = &spk_ttyio_ops,
  99. .probe = synth_probe,
  100. .release = spk_ttyio_release,
  101. .synth_immediate = spk_ttyio_synth_immediate,
  102. .catch_up = spk_do_catch_up,
  103. .flush = synth_flush,
  104. .is_alive = spk_synth_is_alive_restart,
  105. .synth_adjust = NULL,
  106. .read_buff_add = NULL,
  107. .get_index = NULL,
  108. .indexing = {
  109. .command = NULL,
  110. .lowindex = 0,
  111. .highindex = 0,
  112. .currindex = 0,
  113. },
  114. .attributes = {
  115. .attrs = synth_attrs,
  116. .name = "audptr",
  117. },
  118. };
  119. static void synth_flush(struct spk_synth *synth)
  120. {
  121. synth->io_ops->flush_buffer(synth);
  122. synth->io_ops->send_xchar(synth, SYNTH_CLEAR);
  123. synth->io_ops->synth_out(synth, PROCSPEECH);
  124. }
  125. static void synth_version(struct spk_synth *synth)
  126. {
  127. unsigned i;
  128. char synth_id[33];
  129. synth->synth_immediate(synth, "\x05[Q]");
  130. synth_id[0] = synth->io_ops->synth_in(synth);
  131. if (synth_id[0] != 'A')
  132. return;
  133. for (i = 1; i < sizeof(synth_id) - 1; i++) {
  134. /* read version string from synth */
  135. synth_id[i] = synth->io_ops->synth_in(synth);
  136. if (synth_id[i] == '\n')
  137. break;
  138. }
  139. synth_id[i] = '\0';
  140. pr_info("%s version: %s", synth->long_name, synth_id);
  141. }
  142. static int synth_probe(struct spk_synth *synth)
  143. {
  144. int failed;
  145. failed = spk_ttyio_synth_probe(synth);
  146. if (failed == 0)
  147. synth_version(synth);
  148. synth->alive = !failed;
  149. return 0;
  150. }
  151. module_param_named(ser, synth_audptr.ser, int, 0444);
  152. module_param_named(dev, synth_audptr.dev_name, charp, 0444);
  153. module_param_named(start, synth_audptr.startup, short, 0444);
  154. module_param_named(rate, vars[RATE_ID].u.n.default_val, int, 0444);
  155. module_param_named(pitch, vars[PITCH_ID].u.n.default_val, int, 0444);
  156. module_param_named(vol, vars[VOL_ID].u.n.default_val, int, 0444);
  157. module_param_named(tone, vars[TONE_ID].u.n.default_val, int, 0444);
  158. module_param_named(punct, vars[PUNCT_ID].u.n.default_val, int, 0444);
  159. module_param_named(direct, vars[DIRECT_ID].u.n.default_val, int, 0444);
  160. MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");
  161. MODULE_PARM_DESC(dev, "Set the device e.g. ttyUSB0, for the synthesizer.");
  162. MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
  163. MODULE_PARM_DESC(rate, "Set the rate variable on load.");
  164. MODULE_PARM_DESC(pitch, "Set the pitch variable on load.");
  165. MODULE_PARM_DESC(vol, "Set the vol variable on load.");
  166. MODULE_PARM_DESC(tone, "Set the tone variable on load.");
  167. MODULE_PARM_DESC(punct, "Set the punct variable on load.");
  168. MODULE_PARM_DESC(direct, "Set the direct variable on load.");
  169. module_spk_synth(synth_audptr);
  170. MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
  171. MODULE_AUTHOR("David Borowski");
  172. MODULE_DESCRIPTION("Speakup support for Audapter synthesizer");
  173. MODULE_LICENSE("GPL");
  174. MODULE_VERSION(DRV_VERSION);