picoproj: make the -f option mandatory
[libam7xxx.git] / src / am7xxx.h
1 /* am7xxx - communication with AM7XXX based USB Pico Projectors and DPFs
2  *
3  * Copyright (C) 2012  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 2 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_NV12 = 2,
41 } am7xxx_image_format;
42
43 typedef enum {
44         AM7XXX_POWER_OFF    = 0,
45         AM7XXX_POWER_LOW    = 1,
46         AM7XXX_POWER_MIDDLE = 2,
47         AM7XXX_POWER_HIGH   = 3,
48         AM7XXX_POWER_TURBO  = 4,
49 } am7xxx_power_mode;
50
51 struct am7xxx_generic_header {
52         uint32_t field0;
53         uint32_t field1;
54         uint32_t field2;
55         uint32_t field3;
56 };
57
58 struct am7xxx_image_header {
59         uint32_t format;
60         uint32_t width;
61         uint32_t height;
62         uint32_t image_size;
63 };
64
65 struct am7xxx_power_header {
66         uint32_t bit2;
67         uint32_t bit1;
68         uint32_t bit0;
69 };
70
71 /*
72  * Examples of packet headers:
73  *
74  * Image header:
75  * 02 00 00 00 00 10 3e 10 01 00 00 00 20 03 00 00 e0 01 00 00 53 E8 00 00
76  *
77  * Power header:
78  * 04 00 00 00 00 0c ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
79  */
80
81 /* The header size on the wire is known to be always 24 bytes, regardless of
82  * the memory configuration enforced by different architechtures or compilers
83  * for struct am7xxx_header
84  */
85 #define AM7XXX_HEADER_WIRE_SIZE 24
86
87 struct am7xxx_header {
88         uint32_t packet_type;
89         uint8_t unknown0;
90         uint8_t header_data_len;
91         uint8_t unknown2;
92         uint8_t unknown3;
93         union {
94                 struct am7xxx_generic_header data;
95                 struct am7xxx_image_header image;
96                 struct am7xxx_power_header power;
97         } header_data;
98 };
99
100 am7xxx_device am7xxx_init(void);
101
102 void am7xxx_shutdown(am7xxx_device dev);
103
104 int am7xxx_send_image(am7xxx_device dev,
105                       am7xxx_image_format format,
106                       unsigned int width,
107                       unsigned int height,
108                       uint8_t *image,
109                       unsigned int size);
110
111 /*
112  * NOTE: if we set the mode to AM7XXX_POWER_OFF we can't turn the
113  * display on again by using only am7xxx_set_power_mode().
114  *
115  * Remember to mention that when writing the API doc.
116  */
117 int am7xxx_set_power_mode(am7xxx_device dev, am7xxx_power_mode mode);
118
119 #ifdef __cplusplus
120 }
121 #endif
122
123 #endif /* __AM7XXX_H */