84a1efbe3cc4d5e7c85c3a866fd9eab3b3f6b1d8
[libam7xxx.git] / src / am7xxx.h
1 /* am7xxx - communication with AM7XXX based USB Pico Projectors and DPFs
2  *
3  * Copyright (C) 2011  Antonio Ospite <ospite@studenti.unina.it>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #ifndef __AM7XXX_H
20 #define __AM7XXX_H
21
22 #include <stdint.h>
23 #include <libusb-1.0/libusb.h>
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 typedef libusb_device_handle *am7xxx_device;
30
31 typedef enum {
32         AM7XXX_PACKET_TYPE_INIT    = 0x01,
33         AM7XXX_PACKET_TYPE_IMAGE   = 0x02,
34         AM7XXX_PACKET_TYPE_POWER   = 0x04,
35         AM7XXX_PACKET_TYPE_UNKNOWN = 0x05,
36 } am7xxx_packet_type;
37
38 typedef enum {
39         AM7XXX_IMAGE_FORMAT_JPEG = 1,
40 } am7xxx_image_format;
41
42 typedef enum {
43         AM7XXX_POWER_OFF  = 0,
44         AM7XXX_POWER_LOW  = 1,
45         AM7XXX_POWER_MID  = 2,
46         AM7XXX_POWER_HIGH = 3,
47 } am7xxx_power_mode;
48
49 struct am7xxx_image_header {
50         uint32_t format;
51         uint32_t width;
52         uint32_t height;
53         uint32_t image_size;
54 };
55
56 struct am7xxx_power_header {
57         uint32_t power_low;
58         uint32_t power_mid;
59         uint32_t power_high;
60 };
61
62 /*
63  * Examples of packet headers:
64  *
65  * Image header:
66  * 02 00 00 00 00 10 3e 10 01 00 00 00 20 03 00 00 e0 01 00 00 53 E8 00 00
67  *
68  * Power header:
69  * 04 00 00 00 00 0c ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
70  */
71
72 struct am7xxx_header {
73         uint32_t packet_type;
74         uint8_t unknown0;
75         uint8_t header_data_len;
76         uint8_t unknown2;
77         uint8_t unknown3;
78         union {
79                 struct am7xxx_image_header image;
80                 struct am7xxx_power_header power;
81         } header_data;
82 };
83
84 am7xxx_device am7xxx_init(void);
85
86 void am7xxx_shutdown(am7xxx_device dev);
87
88 int am7xxx_send_image(am7xxx_device dev,
89                       am7xxx_image_format format,
90                       unsigned int width,
91                       unsigned int height,
92                       uint8_t *image,
93                       unsigned int size);
94
95 #ifdef __cplusplus
96 }
97 #endif
98
99 #endif /* __AM7XXX_H */