File: eu_usb.c

package info (click to toggle)
brltty 4.2-7+squeeze2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 15,152 kB
  • ctags: 12,570
  • sloc: ansic: 76,159; sh: 4,295; makefile: 1,375; tcl: 645; awk: 568; ml: 293; java: 272; python: 6
file content (108 lines) | stat: -rw-r--r-- 2,640 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
 * BRLTTY - A background process providing access to the console screen (when in
 *          text mode) for a blind person using a refreshable braille display.
 *
 * Copyright (C) 1995-2010 by The BRLTTY Developers.
 *
 * BRLTTY comes with ABSOLUTELY NO WARRANTY.
 *
 * This is free software, placed under the terms of the
 * GNU General Public License, as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any
 * later version. Please see the file LICENSE-GPL for details.
 *
 * Web Page: http://mielke.cc/brltty/
 *
 * This software is maintained by Dave Mielke <dave@mielke.cc>.
 */

/* EuroBraille -- Input/Output handling
** USB Specific low-level IO routines.
*/

#include <string.h>

#include "prologue.h"

#include <errno.h>

#include "log.h"

#include "eu_io.h"

#define USB_PACKET_SIZE 64


#include "io_usb.h"

static UsbChannel *usb = NULL;
int
eubrl_usbInit (BrailleDisplay *brl, char **parameters, const char *device) {
  static const UsbChannelDefinition definitions[] = {
    { /* ESYS 12/40 (with SD-Card inserted) */
      .vendor=0XC251, .product=0X1122,
      .configuration=1, .interface=0, .alternative=0,
      .inputEndpoint=1, .outputEndpoint=0,
      .disableAutosuspend=0
    }
    ,
    { /* ESYS 12/40 (with SD-Card not inserted) */
      .vendor=0XC251, .product=0X1124,
      .configuration=1, .interface=0, .alternative=0,
      .inputEndpoint=1, .outputEndpoint=0,
      .disableAutosuspend=0
    }
    ,
    { .vendor=0 }
  };

  if ((usb = usbFindChannel(definitions, (void *)device))) 
    {
      return 1;
    }
  return 0;
}

int
eubrl_usbClose (BrailleDisplay *brl) 
{
  if (usb) {
    usbCloseChannel(usb);
    usb = NULL;
  }
  return 0;
}


ssize_t
eubrl_usbRead (BrailleDisplay *brl, void *buffer, size_t length) 
{
  ssize_t count=0;

  if(length>=USB_PACKET_SIZE) count = usbReapInput(usb->device, usb->definition.inputEndpoint, buffer, USB_PACKET_SIZE, 0,2);
  if(count>0 && count<USB_PACKET_SIZE)
    {
      LogPrint(LOG_DEBUG,"eu: We received a too small packet");
      return (-1);
    }
  return count;
}

ssize_t
eubrl_usbWrite(BrailleDisplay *brl, const void *buffer, size_t length)
{
  size_t pos = 0;
  while (pos < length) {
    char packetToSend[USB_PACKET_SIZE];
    size_t tosend = length - pos;
    if (tosend > USB_PACKET_SIZE) {
      tosend = USB_PACKET_SIZE;
    }
    memset(packetToSend,0x55,USB_PACKET_SIZE);
    memcpy(packetToSend,buffer+pos,tosend);
    if (usbHidSetReport(usb->device, usb->definition.interface, 0, packetToSend, USB_PACKET_SIZE, 10) < 0)
      return -1;
    pos += tosend;
  }
  return length;
}