Skip to content

Commit

Permalink
[linux/usb] Add ep:reset_ep, ep:set_interface and ep:clear_halt.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpc committed Nov 9, 2015
1 parent 9eecc74 commit 0288f89
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lualib/linux/usb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ endpoint.new = constructor(function (self, ctx, udevh, intf)
self.bEndpointAddress = udevh:get_sysattr_value'bEndpointAddress'
self.type = udevh:get_sysattr_value'type'
self.direction = udevh:get_sysattr_value'direction'
assert(_usb.clear_halt(self.f, fromhex(self.bEndpointAddress)))
assert(_usb.reset_ep(self.f, fromhex(self.bEndpointAddress)))
end)

function endpoint:write(data, callback)
Expand Down
40 changes: 40 additions & 0 deletions p-linux/l_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,21 @@ struct usbdevfs_urb {
struct usbdevfs_iso_packet_desc iso_frame_desc[0];
};

struct usbdevfs_setinterface {
unsigned int interface;
unsigned int altsetting;
};

#define USBDEVFS_RESETEP _IOR('U', 3, unsigned int)
#define USBDEVFS_SETINTERFACE _IOR('U', 4, struct usbdevfs_setinterface)
#define USBDEVFS_SETCONFIGURATION _IOR('U', 5, unsigned int)
#define USBDEVFS_GETDRIVER _IOW('U', 8, struct usbdevfs_getdriver)
#define USBDEVFS_SUBMITURB _IOR('U', 10, struct usbdevfs_urb)
#define USBDEVFS_REAPURBNDELAY _IOW('U', 13, void *)
#define USBDEVFS_CLAIMINTERFACE _IOR('U', 15, unsigned int)
#define USBDEVFS_RELEASEINTERFACE _IOR('U', 16, unsigned int)
#define USBDEVFS_IOCTL _IOWR('U', 18, struct usbdevfs_ioctl)
#define USBDEVFS_CLEAR_HALT _IOR('U', 21, unsigned int)
#define USBDEVFS_DISCONNECT _IO('U', 22)
#define USBDEVFS_CONNECT _IO('U', 23)

Expand All @@ -76,6 +84,35 @@ static int _simple_ioctl(lua_State *L, int fd, int code, void *arg, const char *
: (lua_pushboolean (L, 1), 1);
}

static int reset_ep (lua_State *L)
{
int fd = luaLM_checkfd (L, 1);
unsigned int ep = luaL_checknumber (L, 2);
eprintf("reset_ep: %02x\n", ep);
return _simple_ioctl(L, fd, USBDEVFS_RESETEP, &ep, __FUNCTION__);
}

static int set_interface (lua_State *L)
{
int fd = luaLM_checkfd (L, 1);
unsigned int intf = luaL_checknumber (L, 2);
unsigned int altsetting = luaL_checknumber (L, 3);
struct usbdevfs_setinterface setintf = {
.interface = intf,
.altsetting = altsetting,
};
eprintf("set_interface: %02x %02x\n", intf, altsetting);
return _simple_ioctl(L, fd, USBDEVFS_SETINTERFACE, &setintf, __FUNCTION__);
}

static int clear_halt (lua_State *L)
{
int fd = luaLM_checkfd (L, 1);
unsigned int ep = luaL_checknumber (L, 2);
eprintf("clear_halt: %02x\n", ep);
return _simple_ioctl(L, fd, USBDEVFS_CLEAR_HALT, &ep, __FUNCTION__);
}

static int set_configuration (lua_State *L)
{
int fd = luaLM_checkfd (L, 1);
Expand Down Expand Up @@ -202,6 +239,9 @@ static int reap_urb (lua_State *L)
}

static const struct luaL_reg funcs[] = {
{ "reset_ep", reset_ep },
{ "set_interface", set_interface },
{ "clear_halt", clear_halt },
{ "set_configuration", set_configuration },
{ "get_driver", get_driver },
{ "claim_interface", claim_interface },
Expand Down

0 comments on commit 0288f89

Please sign in to comment.