-struct am7xxx_generic_header {
- uint32_t field0;
- uint32_t field1;
- uint32_t field2;
- uint32_t field3;
-};
-
-struct am7xxx_devinfo_header {
- uint32_t native_width;
- uint32_t native_height;
- uint32_t unknown0;
- uint32_t unknown1;
-};
-
-struct am7xxx_image_header {
- uint32_t format;
- uint32_t width;
- uint32_t height;
- uint32_t image_size;
-};
-
-struct am7xxx_power_header {
- uint32_t bit2;
- uint32_t bit1;
- uint32_t bit0;
-};
-
-/*
- * Examples of packet headers:
- *
- * Image header:
- * 02 00 00 00 00 10 3e 10 01 00 00 00 20 03 00 00 e0 01 00 00 53 E8 00 00
- *
- * Power header:
- * 04 00 00 00 00 0c ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
- */
-
-/* The header size on the wire is known to be always 24 bytes, regardless of
- * the memory configuration enforced by different architechtures or compilers
- * for struct am7xxx_header
- */
-#define AM7XXX_HEADER_WIRE_SIZE 24
-
-struct am7xxx_header {
- uint32_t packet_type;
- uint8_t unknown0;
- uint8_t header_data_len;
- uint8_t unknown2;
- uint8_t unknown3;
- union {
- struct am7xxx_generic_header data;
- struct am7xxx_devinfo_header devinfo;
- struct am7xxx_image_header image;
- struct am7xxx_power_header power;
- } header_data;
-};
-
-am7xxx_device am7xxx_init(void);
-
-void am7xxx_shutdown(am7xxx_device dev);
-
-int am7xxx_get_device_info(am7xxx_device dev,
- unsigned int *native_width,
- unsigned int *native_height,
- unsigned int *unknown0,
- unsigned int *unknown1);
-
-int am7xxx_send_image(am7xxx_device dev,
+/**
+ * The display zoom modes.
+ *
+ * An am7xxx device can display images using several zoom modes.
+ *
+ * @note Changing the zoom mode can change the aspect ratio of the displayed
+ * image.
+ *
+ * @note On the zoom test screen the version of the firmware running on the
+ * device is shown as well (e.g SPI_V21.0.0_2011.03.18).
+ *
+ * @note The Tele mode is available only on some PicoPix models, when using it
+ * the image is distorted like if a different lens was used, but the global
+ * aspect ratio of the image does not change.
+ */
+typedef enum {
+ AM7XXX_ZOOM_ORIGINAL = 0, /**< Original Size, as retrieved via #am7xxx_device_info. */
+ AM7XXX_ZOOM_H = 1, /**< Zoom 1: H Scale (changes aspect ratio). */
+ AM7XXX_ZOOM_H_V = 2, /**< Zoom 2: H/V Scale (changes aspect ratio). */
+ AM7XXX_ZOOM_TEST = 3, /**< Zoom test screen, the firmware version is shown as well. */
+ AM7XXX_ZOOM_TELE = 4, /**< Zoom Tele: available on some PicoPix models. */
+} am7xxx_zoom_mode;
+
+/**
+ * Initialize the library context and data structures, and scan for devices.
+ *
+ * @param[out] ctx A pointer to the context the library will be used in.
+ *
+ * @return 0 on success, a negative value on error
+ */
+int am7xxx_init(am7xxx_context **ctx);
+
+/**
+ * Cleanup the library data structures and free the context.
+ *
+ * @param[in,out] ctx The context to free.
+ */
+void am7xxx_shutdown(am7xxx_context *ctx);
+
+/**
+ * Set verbosity level of log messages.
+ *
+ * @note The level is per-context.
+ *
+ * @note Messages of level AM7XXX_LOG_FATAL are always shown, regardless
+ * of the value of the log_level parameter.
+ *
+ * @param[in] ctx The context to set the log level for
+ * @param[in] log_level The verbosity level to use in the context (see @link am7xxx_log_level @endlink)
+ */
+void am7xxx_set_log_level(am7xxx_context *ctx, am7xxx_log_level log_level);
+
+/**
+ * Open an am7xxx_device according to a index.
+ *
+ * The semantics of the 'device_index' argument follows the order
+ * of the devices as found when scanning the bus at am7xxx_init() time.
+ *
+ * @note When the user tries to open a device already opened the function
+ * returns -EBUSY and the device is left open.
+ *
+ * @param[in] ctx The context to open the device in
+ * @param[out] dev A pointer to the structure representing the device to open
+ * @param[in] device_index The index of the device on the bus
+ *
+ * @return 0 on success, a negative value on error
+ */
+int am7xxx_open_device(am7xxx_context *ctx,
+ am7xxx_device **dev,
+ unsigned int device_index);
+
+/**
+ * Close an am7xxx_device.
+ *
+ * Close an am7xxx_device so that it becomes available for some other
+ * user/process to open it.
+ *
+ * @param[in] dev A pointer to the structure representing the device to close
+ *
+ * @return 0 on success, a negative value on error
+ */
+int am7xxx_close_device(am7xxx_device *dev);
+
+/**
+ * Get info about an am7xxx device.
+ *
+ * Get information about a device, in the form of a
+ * @link am7xxx_device_info @endlink structure.
+ *
+ * @param[in] dev A pointer to the structure representing the device to get info of
+ * @param[out] device_info A pointer to the structure where to store the device info (see @link am7xxx_device_info @endlink)
+ *
+ * @return 0 on success, a negative value on error
+ */
+int am7xxx_get_device_info(am7xxx_device *dev,
+ am7xxx_device_info *device_info);
+
+/**
+ * Calculate the dimensions of an image to be shown on an am7xxx device.
+ *
+ * Before sending images bigger than the device native dimensions the user
+ * needs to rescale them, this utility function does the calculation in a way
+ * that the original image aspect ratio is preserved.
+ *
+ * @param[in] dev A pointer to the structure representing the device to get info of
+ * @param[in] upscale Whether to calculate scaled dimensions for images smaller than the native dimensions
+ * @param[in] original_width The width of the original image
+ * @param[in] original_height The height of the original image
+ * @param[out] scaled_width The width the rescaled image should have
+ * @param[out] scaled_height The height the rescaled image should have
+ *
+ * @return 0 on success, a negative value on error
+ */
+int am7xxx_calc_scaled_image_dimensions(am7xxx_device *dev,
+ unsigned int upscale,
+ unsigned int original_width,
+ unsigned int original_height,
+ unsigned int *scaled_width,
+ unsigned int *scaled_height);
+/**
+ * Send an image for display on an am7xxx device.
+ *
+ * This is the function that actually makes the device display something.
+ * Static pictures can be sent just once and the device will keep showing them
+ * until another image get sent or some command resets or turns off the display.
+ *
+ * @param[in] dev A pointer to the structure representing the device to get info of
+ * @param[in] format The format the image is in (see @link am7xxx_image_format @endlink enum)
+ * @param[in] width The width of the image
+ * @param[in] height The height of the image
+ * @param[in] image A buffer holding data in the format specified by the format parameter
+ * @param[in] image_size The size in bytes of the image buffer
+ *
+ * @return 0 on success, a negative value on error
+ */
+int am7xxx_send_image(am7xxx_device *dev,