speakup_audptr.c 5.1 KB

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