1 /* am7xxx - communication with AM7XXX based USB Pico Projectors and DPFs
3 * Copyright (C) 2012 Antonio Ospite <ospite@studenti.unina.it>
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.
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.
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/>.
21 * Public libam7xxx API.
33 * @typedef am7xxx_context
35 * An opaque data type representing a context.
37 struct _am7xxx_context;
38 typedef struct _am7xxx_context am7xxx_context;
41 * @typedef am7xxx_device
43 * An opaque data type representing an am7xxx device.
45 struct _am7xxx_device;
46 typedef struct _am7xxx_device am7xxx_device;
49 * A struct describing device specific properties.
51 * A user program may want to inspect these before providing data to the
52 * device. For instance, when sending an image the user may want to rescale it
53 * to the device native width and height in order to be sure the image will be
54 * displayed in its entirety.
57 unsigned int native_width; /**< The device native width. */
58 unsigned int native_height; /**< The device native height. */
62 * The verbosity level of logging messages.
64 * This can be set with am7xxx_set_log_level() and the level will be used
65 * internally by libam7xxx to adjust the granularity of the information
66 * exposed to the user about the internal library operations.
69 AM7XXX_LOG_FATAL = 0, /**< Fatal messages, the user application should stop if it gets one of this. */
70 AM7XXX_LOG_ERROR = 1, /**< Error messages, typically they describe API functions failures. */
71 AM7XXX_LOG_WARNING = 2, /**< Warnings about conditions worth mentioning to the user. */
72 AM7XXX_LOG_INFO = 3, /**< Informations about the device operations. */
73 AM7XXX_LOG_DEBUG = 4, /**< Informations about the library internals. */
74 AM7XXX_LOG_TRACE = 5, /**< Verbose informations about the communication with the hardware. */
78 * The image formats accepted by the device.
81 AM7XXX_IMAGE_FORMAT_JPEG = 1, /**< JPEG format. */
82 AM7XXX_IMAGE_FORMAT_NV12 = 2, /**< Raw YUV in the NV12 variant. */
83 } am7xxx_image_format;
86 * The device power modes.
88 * An am7xxx device can operate in several power modes. A certain power mode
89 * may have effect on the display brightness or on the device power
92 * @note Most am7xxx devices come with a Y-shaped USB cable with a Master and
93 * a Slave connector, higher power modes may require that both connectors are
94 * plugged in to the host system for the device to work properly.
96 * @note At higher power modes some devices may use a fan to cool down the
97 * internal hardware components, and hence may be noisier in this case.
100 AM7XXX_POWER_OFF = 0, /**< Display is powered off, no image shown. */
101 AM7XXX_POWER_LOW = 1, /**< Low power consumption but also low brightness. */
102 AM7XXX_POWER_MIDDLE = 2, /**< Middle level of brightness. This and upper modes need both the Master and Slave USB connectors plugged. */
103 AM7XXX_POWER_HIGH = 3, /**< More brightness, but more power consumption. */
104 AM7XXX_POWER_TURBO = 4, /**< Max brightness and power consumption. */
108 * Initialize the library context and data structures, and scan for devices.
110 * @param[out] ctx A pointer to the context the library will be used in.
112 * @return 0 on success, a negative value on error
114 int am7xxx_init(am7xxx_context **ctx);
117 * Cleanup the library data structures and free the context.
119 * @param[in,out] ctx The context to free.
121 void am7xxx_shutdown(am7xxx_context *ctx);
124 * Set verbosity level of log messages.
126 * @note The level is per-context.
128 * @note Messages of level AM7XXX_LOG_FATAL are always shown, regardless
129 * of the value of the log_level parameter.
131 * @param[in] ctx The context to set the log level for
132 * @param[in] log_level The verbosity level to use in the context (see @link am7xxx_log_level @endlink)
134 void am7xxx_set_log_level(am7xxx_context *ctx, am7xxx_log_level log_level);
137 * Open an am7xxx_device according to a index.
139 * The semantics of the 'device_index' argument follows the order
140 * of the devices as found when scanning the bus at am7xxx_init() time.
142 * @note When the user tries to open a device already opened the function
143 * returns -EBUSY and the device is left open.
145 * @param[in] ctx The context to open the device in
146 * @param[out] dev A pointer to the structure representing the device to open
147 * @param[in] device_index The index of the device on the bus
149 * @return 0 on success, a negative value on error
151 int am7xxx_open_device(am7xxx_context *ctx,
153 unsigned int device_index);
156 * Close an am7xxx_device.
158 * Close an am7xxx_device so that it becomes available for some other
159 * user/process to open it.
161 * @param[in] dev A pointer to the structure representing the device to close
163 * @return 0 on success, a negative value on error
165 int am7xxx_close_device(am7xxx_device *dev);
168 * Get info about an am7xxx device.
170 * Get information about a device, in the form of a
171 * @link am7xxx_device_info @endlink structure.
173 * @param[in] dev A pointer to the structure representing the device to get info of
174 * @param[out] device_info A pointer to the structure where to store the device info (see @link am7xxx_device_info @endlink)
176 * @return 0 on success, a negative value on error
178 int am7xxx_get_device_info(am7xxx_device *dev,
179 am7xxx_device_info *device_info);
182 * Calculate the dimensions of an image to be shown on an am7xxx device.
184 * Before sending images bigger than the device native dimensions the user
185 * needs to rescale them, this utility function does the calculation in a way
186 * that the original image aspect ratio is preserved.
188 * @param[in] dev A pointer to the structure representing the device to get info of
189 * @param[in] upscale Whether to calculate scaled dimensions for images smaller than the native dimensions
190 * @param[in] original_width The width of the original image
191 * @param[in] original_height The height of the original image
192 * @param[out] scaled_width The width the rescaled image should have
193 * @param[out] scaled_height The height the rescaled image should have
195 * @return 0 on success, a negative value on error
197 int am7xxx_calc_scaled_image_dimensions(am7xxx_device *dev,
198 unsigned int upscale,
199 unsigned int original_width,
200 unsigned int original_height,
201 unsigned int *scaled_width,
202 unsigned int *scaled_height);
204 * Send an image for display on a am7xxx device.
206 * This is the function that actually makes the device display something.
207 * Static pictures can be sent just once and the device will keep showing them
208 * until another image get sent or some command resets or turns off the display.
210 * @param[in] dev A pointer to the structure representing the device to get info of
211 * @param[in] format The format the image is in (see @link am7xxx_image_format @endlink enum)
212 * @param[in] width The width of the image
213 * @param[in] height The height of the image
214 * @param[in] image A buffer holding data in the format specified by the format parameter
215 * @param[in] image_size The size in bytes of the image buffer
217 * @return 0 on success, a negative value on error
219 int am7xxx_send_image(am7xxx_device *dev,
220 am7xxx_image_format format,
223 unsigned char *image,
224 unsigned int image_size);
227 * Set the power mode of an am7xxx device.
229 * \note If we set the mode to AM7XXX_POWER_OFF we can't turn the
230 * display on again by using only am7xxx_set_power_mode(). This needs to be
231 * investigated, maybe some other command can reset the device.
233 * @param[in] dev A pointer to the structure representing the device to get info of
234 * @param[in] mode The power mode to put the device in (see @link am7xxx_power_mode @endlink enum)
236 * @return 0 on success, a negative value on error
239 int am7xxx_set_power_mode(am7xxx_device *dev, am7xxx_power_mode mode);
245 #endif /* __AM7XXX_H */