PageRenderTime 36ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/ptp.h

https://bitbucket.org/alins/magic-lantern-for-500d/
C Header | 173 lines | 101 code | 24 blank | 48 comment | 0 complexity | 0f1622b725a02b391e93072f68dacbdf MD5 | raw file
Possible License(s): GPL-2.0
  1. #ifndef _ptp_h_
  2. #define _ptp_h_
  3. /** \file
  4. * PTP protocol and interface.
  5. *
  6. * The PTP protocol defines how the camera and a host computer communicate
  7. * over USB. It defines operations and properties, and is callback driven.
  8. * Handlers for operations can be registered by calling ptp_register_handler()
  9. * and will be called when the host initiates that operation.
  10. */
  11. /** \group PTP IDs
  12. *
  13. * These are some of the "well known" Canon PTP commands.
  14. * @{
  15. */
  16. #define PTP_FM_OBJECTSIZE 0x910a
  17. #define PTP_SET_DEVICE_PROP 0x9110
  18. #define PTP_HD_CAPACITY 0x911a
  19. #define PTP_GUI_OFF 0x911b
  20. #define PTP_LCD_ON 0x911c
  21. #define PTP_911E 0x911e // unknown
  22. #define PTP_UPDATE_FIRMARE 0x911f
  23. #define PTP_LV_DATA 0x9153
  24. #define PTP_LV_ZOOM_MAYBE 0x9154
  25. #define PTP_LV_ZOOM 0x9158
  26. #define PTP_LV_AFFRAME 0x915a
  27. #define PTP_AF_START 0x9160
  28. #define PTP_FAPI_MESSAGE_TX 0x91fe
  29. #define PTP_RC_OK 0x2001
  30. #define PTP_RC_ERROR 0x2002
  31. /** @} */
  32. struct ptp_handle;
  33. /** PTP message on the USB wire.
  34. *
  35. */
  36. struct ptp_msg
  37. {
  38. uint32_t id;
  39. uint32_t session;
  40. uint32_t transaction;
  41. uint32_t param_count;
  42. uint32_t param[ 5 ];
  43. } __PACKED__;
  44. SIZE_CHECK_STRUCT( ptp_msg, 0x24 );
  45. /** DryOS PTP callback context.
  46. *
  47. * When a handler is registered it will be called with a ptp_context
  48. * as its first argument. These callbacks are to be used to reply
  49. * to the host.
  50. */
  51. struct ptp_context
  52. {
  53. struct ptp_handle * handle; // off_0x00;
  54. int (*send_data)(
  55. struct ptp_handle * handle,
  56. void * buf,
  57. int part_size,
  58. int total_size, // total_size should be 0 except for the first call
  59. int, // that's brainfuck for me...
  60. int,
  61. int
  62. );
  63. // off 0x08
  64. int (*recv_data)(
  65. struct ptp_handle * handle,
  66. void * buf,
  67. size_t len,
  68. void (*callback)(
  69. void * cb_priv,
  70. int status
  71. ),
  72. void * cb_priv
  73. );
  74. // Sends a formatted buffer
  75. // \note format to be determined
  76. // off_0x0c
  77. int (*send_resp)(
  78. struct ptp_handle * handle,
  79. struct ptp_msg * msg
  80. );
  81. // Returns length of message to receive
  82. // off 0x10
  83. int (*get_data_size)(
  84. struct ptp_handle * handle
  85. );
  86. // CHDK equiv: int (*get_data_size)(int handle);
  87. void * off_0x14; // int (*send_err_resp)(int handle, PTPContainer *resp); ?
  88. void * off_0x18; // priv to close handler?
  89. void * off_0x1c; // close?
  90. };
  91. /** DryOS function to register a USB PTP handler.
  92. */
  93. extern void
  94. ptp_register_handler(
  95. uint32_t id,
  96. int (*handler)(
  97. void * priv,
  98. struct ptp_context * context,
  99. void * r2, // unknown
  100. void * r3 // unknown
  101. ),
  102. void * priv
  103. );
  104. /** Magic Lantern PTP handler segment.
  105. *
  106. * \internal These are generated by the PTP_HANDLER() macro to
  107. * create a list of handlers that will be automatically registered
  108. * when Magic Lantern boots.
  109. */
  110. struct ptp_handler
  111. {
  112. uint32_t id;
  113. void * handler;
  114. void * priv;
  115. };
  116. /** Register a compile-time Magic Lantern PTP handler.
  117. *
  118. * \internal Typically PTP_HANDLER() is a better choice.
  119. */
  120. #define REGISTER_PTP_HANDLER( ID, HANDLER, PRIV ) \
  121. struct ptp_handler \
  122. __attribute__((section(".ptp_handlers"))) \
  123. __ptp_handler_##ID = { \
  124. .id = ID, \
  125. .handler = HANDLER, \
  126. .priv = PRIV, \
  127. }
  128. /** Register a compile-time Magic Lantern PTP handler.
  129. *
  130. * Register a PTP handler with the ID. Magic Lantern will automatically
  131. * call the DryOS functions to register all the handlers that are
  132. * in the .ptp_handlers segment.
  133. */
  134. #define PTP_HANDLER( ID, PRIV ) \
  135. static int ptp_handler_##ID(); \
  136. REGISTER_PTP_HANDLER( ID, ptp_handler_##ID, PRIV ); \
  137. static int ptp_handler_##ID( \
  138. void * priv, \
  139. struct ptp_context * context, \
  140. uint32_t opcode, \
  141. uint32_t session, \
  142. uint32_t transaction, \
  143. uint32_t param1, \
  144. uint32_t param2, \
  145. uint32_t param3, \
  146. uint32_t param4, \
  147. uint32_t param5 \
  148. ) \
  149. #endif