50 if (flag >= (1 << 16))
59 if (cmos_value == UINT16_MAX)
86 if (cmd_len & 1 || cmd_len > (0x400 -
sizeof(*chdr))) {
87 FN_ERROR(
"send_cmd: Invalid command length (0x%x)\n", cmd_len);
91 chdr->
magic[0] = 0x47;
92 chdr->
magic[1] = 0x4d;
97 memcpy(obuf+
sizeof(*chdr), cmdbuf, cmd_len);
100 FN_SPEW(
"send_cmd: cmd=%04x tag=%04x len=%04x: %d\n", cmd, dev->
cam_tag, cmd_len, res);
102 FN_ERROR(
"send_cmd: Output control transfer failed (%d)\n", res);
108 FN_FLOOD(
"send_cmd: actual length = %d\n", actual_len);
109 }
while ((actual_len == 0) || (actual_len == 0x200));
110 FN_SPEW(
"Control reply: %d\n", res);
111 if (actual_len < (
int)
sizeof(*rhdr)) {
112 FN_ERROR(
"send_cmd: Input control transfer failed (%d)\n", res);
115 actual_len -=
sizeof(*rhdr);
117 if (rhdr->
magic[0] != 0x52 || rhdr->
magic[1] != 0x42) {
121 if (rhdr->
cmd != chdr->
cmd) {
122 FN_ERROR(
"send_cmd: Bad cmd %02x != %02x\n", rhdr->
cmd, chdr->
cmd);
125 if (rhdr->
tag != chdr->
tag) {
126 FN_ERROR(
"send_cmd: Bad tag %04x != %04x\n", rhdr->
tag, chdr->
tag);
130 FN_ERROR(
"send_cmd: Bad len %04x != %04x\n",
fn_le16(rhdr->
len), (
int)(actual_len/2));
134 if (actual_len > reply_len) {
135 FN_WARNING(
"send_cmd: Data buffer is %d bytes long, but got %d bytes\n", reply_len, actual_len);
136 memcpy(replybuf, ibuf+
sizeof(*rhdr), reply_len);
138 memcpy(replybuf, ibuf+
sizeof(*rhdr), actual_len);
154 int res =
send_cmd(dev, 0x02, &cmd, 2, reply, 4);
157 FN_ERROR(
"read_register: send_cmd() failed: %d\n", res);
161 FN_WARNING(
"read_register: send_cmd() returned %d [%04x %04x], 0000 expected\n", res, reply[0], reply[1]);
163 FN_DEBUG(
"read_register: 0x%04x => 0x%04x\n", reg, reply[1]);
176 FN_DEBUG(
"write_register: 0x%04x <= 0x%02x\n", reg, data);
177 int res =
send_cmd(dev, 0x03, cmd, 4, reply, 4);
180 FN_ERROR(
"write_register: send_cmd() returned %d\n", res);
184 FN_WARNING(
"write_register: send_cmd() returned %d [%04x %04x], 0000 expected\n", res, reply[0], reply[1]);
197 cmdbuf[1] = reg & 0x7fff;
200 int res =
send_cmd(dev, 0x95, cmdbuf, 6, replybuf, 6);
203 FN_ERROR(
"read_cmos_register: send_cmd() returned %d\n", res);
207 FN_DEBUG(
"read_cmos_register: 0x%04x => 0x%04x\n", reg, replybuf[2]);
218 cmdbuf[1] = reg | 0x8000;
221 FN_DEBUG(
"write_cmos_register: 0x%04x <= 0x%04x\n", reg, value);
222 int res =
send_cmd(dev, 0x95, cmdbuf, 6, replybuf, 6);
224 FN_ERROR(
"write_cmos_register: send_cmd() returned %d\n", res);
freenect_flag
Enumeration of flags to toggle features with freenect_set_flag()
freenect_context * parent
freenect_flag_value
Possible values for setting each freenect_flag
FN_INTERNAL int register_for_flag(int flag)
FN_INTERNAL uint16_t read_cmos_register(freenect_device *dev, uint16_t reg)
FN_INTERNAL int fnusb_control(fnusb_dev *dev, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint8_t *data, uint16_t wLength)
int freenect_set_flag(freenect_device *dev, freenect_flag flag, freenect_flag_value value)
FN_INTERNAL uint16_t read_register(freenect_device *dev, uint16_t reg)
static freenect_context * ctx
FN_INTERNAL int write_register(freenect_device *dev, uint16_t reg, uint16_t data)
FN_INTERNAL int write_cmos_register(freenect_device *dev, uint16_t reg, uint16_t value)
FN_INTERNAL int send_cmd(freenect_device *dev, uint16_t cmd, void *cmdbuf, unsigned int cmd_len, void *replybuf, int reply_len)