|
32 | 32 | #include "freenect_internal.h"
|
33 | 33 | #include "registration.h"
|
34 | 34 | #include "cameras.h"
|
| 35 | +#include "flags.h" |
35 | 36 |
|
36 | 37 | #define MAKE_RESERVED(res, fmt) (uint32_t)(((res & 0xff) << 8) | (((fmt & 0xff))))
|
37 | 38 | #define RESERVED_TO_RESOLUTION(reserved) (freenect_resolution)((reserved >> 8) & 0xff)
|
@@ -650,122 +651,6 @@ static void video_process(freenect_device *dev, uint8_t *pkt, int len)
|
650 | 651 | dev->video_cb(dev, dev->video.proc_buf, dev->video.timestamp);
|
651 | 652 | }
|
652 | 653 |
|
653 |
| -typedef struct { |
654 |
| - uint8_t magic[2]; |
655 |
| - uint16_t len; |
656 |
| - uint16_t cmd; |
657 |
| - uint16_t tag; |
658 |
| -} cam_hdr; |
659 |
| - |
660 |
| -static int send_cmd(freenect_device *dev, uint16_t cmd, void *cmdbuf, unsigned int cmd_len, void *replybuf, int reply_len) |
661 |
| -{ |
662 |
| - freenect_context *ctx = dev->parent; |
663 |
| - int res, actual_len; |
664 |
| - uint8_t obuf[0x400]; |
665 |
| - uint8_t ibuf[0x200]; |
666 |
| - cam_hdr *chdr = (cam_hdr*)obuf; |
667 |
| - cam_hdr *rhdr = (cam_hdr*)ibuf; |
668 |
| - |
669 |
| - if (cmd_len & 1 || cmd_len > (0x400 - sizeof(*chdr))) { |
670 |
| - FN_ERROR("send_cmd: Invalid command length (0x%x)\n", cmd_len); |
671 |
| - return -1; |
672 |
| - } |
673 |
| - |
674 |
| - chdr->magic[0] = 0x47; |
675 |
| - chdr->magic[1] = 0x4d; |
676 |
| - chdr->cmd = fn_le16(cmd); |
677 |
| - chdr->tag = fn_le16(dev->cam_tag); |
678 |
| - chdr->len = fn_le16(cmd_len / 2); |
679 |
| - |
680 |
| - memcpy(obuf+sizeof(*chdr), cmdbuf, cmd_len); |
681 |
| - |
682 |
| - res = fnusb_control(&dev->usb_cam, 0x40, 0, 0, 0, obuf, cmd_len + sizeof(*chdr)); |
683 |
| - FN_SPEW("Control cmd=%04x tag=%04x len=%04x: %d\n", cmd, dev->cam_tag, cmd_len, res); |
684 |
| - if (res < 0) { |
685 |
| - FN_ERROR("send_cmd: Output control transfer failed (%d)\n", res); |
686 |
| - return res; |
687 |
| - } |
688 |
| - |
689 |
| - do { |
690 |
| - actual_len = fnusb_control(&dev->usb_cam, 0xc0, 0, 0, 0, ibuf, 0x200); |
691 |
| - FN_FLOOD("actual_len: %d\n", actual_len); |
692 |
| - } while ((actual_len == 0) || (actual_len == 0x200)); |
693 |
| - FN_SPEW("Control reply: %d\n", res); |
694 |
| - if (actual_len < (int)sizeof(*rhdr)) { |
695 |
| - FN_ERROR("send_cmd: Input control transfer failed (%d)\n", res); |
696 |
| - return res; |
697 |
| - } |
698 |
| - actual_len -= sizeof(*rhdr); |
699 |
| - |
700 |
| - if (rhdr->magic[0] != 0x52 || rhdr->magic[1] != 0x42) { |
701 |
| - FN_ERROR("send_cmd: Bad magic %02x %02x\n", rhdr->magic[0], rhdr->magic[1]); |
702 |
| - return -1; |
703 |
| - } |
704 |
| - if (rhdr->cmd != chdr->cmd) { |
705 |
| - FN_ERROR("send_cmd: Bad cmd %02x != %02x\n", rhdr->cmd, chdr->cmd); |
706 |
| - return -1; |
707 |
| - } |
708 |
| - if (rhdr->tag != chdr->tag) { |
709 |
| - FN_ERROR("send_cmd: Bad tag %04x != %04x\n", rhdr->tag, chdr->tag); |
710 |
| - return -1; |
711 |
| - } |
712 |
| - if (fn_le16(rhdr->len) != (actual_len/2)) { |
713 |
| - FN_ERROR("send_cmd: Bad len %04x != %04x\n", fn_le16(rhdr->len), (int)(actual_len/2)); |
714 |
| - return -1; |
715 |
| - } |
716 |
| - |
717 |
| - if (actual_len > reply_len) { |
718 |
| - FN_WARNING("send_cmd: Data buffer is %d bytes long, but got %d bytes\n", reply_len, actual_len); |
719 |
| - memcpy(replybuf, ibuf+sizeof(*rhdr), reply_len); |
720 |
| - } else { |
721 |
| - memcpy(replybuf, ibuf+sizeof(*rhdr), actual_len); |
722 |
| - } |
723 |
| - |
724 |
| - dev->cam_tag++; |
725 |
| - |
726 |
| - return actual_len; |
727 |
| -} |
728 |
| - |
729 |
| -static int write_register(freenect_device *dev, uint16_t reg, uint16_t data) |
730 |
| -{ |
731 |
| - freenect_context *ctx = dev->parent; |
732 |
| - uint16_t reply[2]; |
733 |
| - uint16_t cmd[2]; |
734 |
| - int res; |
735 |
| - |
736 |
| - cmd[0] = fn_le16(reg); |
737 |
| - cmd[1] = fn_le16(data); |
738 |
| - |
739 |
| - FN_DEBUG("Write Reg 0x%04x <= 0x%02x\n", reg, data); |
740 |
| - res = send_cmd(dev, 0x03, cmd, 4, reply, 4); |
741 |
| - if (res < 0) |
742 |
| - return res; |
743 |
| - if (res != 2) { |
744 |
| - FN_WARNING("send_cmd returned %d [%04x %04x], 0000 expected\n", res, reply[0], reply[1]); |
745 |
| - } |
746 |
| - return 0; |
747 |
| -} |
748 |
| - |
749 |
| -// This function is here for completeness. We don't actually use it for anything right now. |
750 |
| -static uint16_t read_register(freenect_device *dev, uint16_t reg) |
751 |
| -{ |
752 |
| - freenect_context *ctx = dev->parent; |
753 |
| - uint16_t reply[2]; |
754 |
| - uint16_t cmd; |
755 |
| - int res; |
756 |
| - |
757 |
| - cmd = fn_le16(reg); |
758 |
| - |
759 |
| - FN_DEBUG("Read Reg 0x%04x =>\n", reg); |
760 |
| - res = send_cmd(dev, 0x02, &cmd, 2, reply, 4); |
761 |
| - if (res < 0) |
762 |
| - FN_ERROR("read_register: send_cmd() failed: %d\n", res); |
763 |
| - if (res != 4) |
764 |
| - FN_WARNING("send_cmd returned %d [%04x %04x], 0000 expected\n", res, reply[0], reply[1]); |
765 |
| - |
766 |
| - return reply[1]; |
767 |
| -} |
768 |
| - |
769 | 654 | static int freenect_fetch_reg_info(freenect_device *dev)
|
770 | 655 | {
|
771 | 656 | freenect_context *ctx = dev->parent;
|
|
0 commit comments