1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2  *
3  * Copyright (C) 2011-2015 Richard Hughes <richard@hughsie.com>
4  *
5  * Licensed under the GNU General Public License Version 2
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 #if !defined (__COLORHUG_H_INSIDE__) && !defined (CH_COMPILATION)
23 #error "Only <colorhug.h> can be included directly."
24 #endif
25 
26 #ifndef CH_COMMON_H
27 #define CH_COMMON_H
28 
29 #include <glib.h>
30 #include <gusb.h>
31 
32 G_BEGIN_DECLS
33 
34 /* device constants */
35 #define	CH_USB_VID				0x273f
36 #define	CH_USB_PID_BOOTLOADER			0x1000
37 #define	CH_USB_PID_BOOTLOADER2			0x1005
38 #define	CH_USB_PID_BOOTLOADER_ALS		0x1006	/* since 1.2.9 */
39 #define	CH_USB_PID_BOOTLOADER_PLUS		0x1003
40 #define	CH_USB_PID_FIRMWARE			0x1001
41 #define	CH_USB_PID_FIRMWARE2			0x1004
42 #define	CH_USB_PID_FIRMWARE_ALS			0x1007	/* since 1.2.9 */
43 #define	CH_USB_PID_FIRMWARE_ALS_SENSOR_HID	0x1008	/* since 1.2.11 */
44 #define	CH_USB_PID_FIRMWARE_PLUS		0x1002
45 #define	CH_USB_CONFIG				0x0001
46 #define	CH_USB_INTERFACE			0x0000
47 #define	CH_USB_HID_EP				0x01
48 #define	CH_USB_HID_EP_IN			(CH_USB_HID_EP | 0x80)
49 #define	CH_USB_HID_EP_OUT			(CH_USB_HID_EP | 0x00)
50 #define	CH_USB_HID_EP_SIZE			64
51 
52 /* old device constants */
53 #define	CH_USB_VID_LEGACY			0x04d8
54 #define	CH_USB_PID_LEGACY			0xf8da
55 
56 /* the default timeout in client tools */
57 #define CH_DEVICE_USB_TIMEOUT			10000 /* ms */
58 
59 /* constants for ownership tags */
60 #define CH_OWNER_LENGTH_MAX			60
61 
62 /**
63  * CH_CMD_GET_COLOR_SELECT:
64  *
65  * Get the color select state.
66  *
67  * IN:  [1:cmd]
68  * OUT: [1:retval][1:cmd][1:color_select]
69  *
70  * This command is available under these conditions:
71  *
72  *                |  Bootloader  |  Firmware
73  * ---------------+--------------+-----------
74  * ColorHug       |      ×       |      ✓
75  * ColorHug2      |      ×       |      ×
76  * ColorHug+      |      ×       |      ×
77  * ColorHugALS    |      ×       |      ✓
78  *
79  * Since: 0.1.29
80  **/
81 #define	CH_CMD_GET_COLOR_SELECT			0x01
82 
83 /**
84  * CH_CMD_SET_COLOR_SELECT:
85  *
86  * Set the color select state.
87  *
88  * IN:  [1:cmd][1:color_select]
89  * OUT: [1:retval][1:cmd]
90  *
91  * This command is available under these conditions:
92  *
93  *                |  Bootloader  |  Firmware
94  * ---------------+--------------+-----------
95  * ColorHug       |      ×       |      ✓
96  * ColorHug2      |      ×       |      ×
97  * ColorHug+      |      ×       |      ×
98  * ColorHugALS    |      ×       |      ✓
99  *
100  * Since: 0.1.29
101  **/
102 #define	CH_CMD_SET_COLOR_SELECT			0x02
103 
104 /**
105  * CH_CMD_GET_MULTIPLIER:
106  *
107  * Gets the multiplier value.
108  *
109  * IN:  [1:cmd]
110  * OUT: [1:retval][1:cmd][1:multiplier_value]
111  *
112  * This command is available under these conditions:
113  *
114  *                |  Bootloader  |  Firmware
115  * ---------------+--------------+-----------
116  * ColorHug       |      ×       |      ✓
117  * ColorHug2      |      ×       |      ×
118  * ColorHug+      |      ×       |      ×
119  * ColorHugALS    |      ×       |      ✓
120  *
121  * Since: 0.1.29
122  **/
123 #define	CH_CMD_GET_MULTIPLIER			0x03
124 
125 /**
126  * CH_CMD_SET_MULTIPLIER:
127  *
128  * Sets the multiplier value.
129  *
130  * IN:  [1:cmd][1:multiplier_value]
131  * OUT: [1:retval][1:cmd]
132  *
133  * This command is available under these conditions:
134  *
135  *                |  Bootloader  |  Firmware
136  * ---------------+--------------+-----------
137  * ColorHug       |      ×       |      ✓
138  * ColorHug2      |      ×       |      ×
139  * ColorHug+      |      ×       |      ×
140  * ColorHugALS    |      ×       |      ✓
141  *
142  * Since: 0.1.29
143  **/
144 #define	CH_CMD_SET_MULTIPLIER			0x04
145 
146 /**
147  * CH_CMD_GET_INTEGRAL_TIME:
148  *
149  * Gets the integral time.
150  *
151  * IN:  [1:cmd]
152  * OUT: [1:retval][1:cmd][2:integral_time]
153  *
154  * This command is available under these conditions:
155  *
156  *                |  Bootloader  |  Firmware
157  * ---------------+--------------+-----------
158  * ColorHug       |      ×       |      ✓
159  * ColorHug2      |      ×       |      ×
160  * ColorHug+      |      ×       |      ✓
161  * ColorHugALS    |      ×       |      ✓
162  *
163  * Since: 0.1.29
164  **/
165 #define	CH_CMD_GET_INTEGRAL_TIME		0x05
166 
167 /**
168  * CH_CMD_SET_INTEGRAL_TIME:
169  *
170  * Sets the integral time.
171  *
172  * IN:  [1:cmd][2:integral_time]
173  * OUT: [1:retval][1:cmd]
174  *
175  * This command is available under these conditions:
176  *
177  *                |  Bootloader  |  Firmware
178  * ---------------+--------------+-----------
179  * ColorHug       |      ×       |      ✓
180  * ColorHug2      |      ×       |      ×
181  * ColorHug+      |      ×       |      ✓
182  * ColorHugALS    |      ×       |      ✓
183  *
184  * Since: 0.1.29
185  **/
186 #define	CH_CMD_SET_INTEGRAL_TIME		0x06
187 
188 /**
189  * CH_CMD_GET_FIRMWARE_VERSION:
190  *
191  * Gets the firmware version.
192  *
193  * IN:  [1:cmd]
194  * OUT: [1:retval][1:cmd][2:major][2:minor][2:micro]
195  *
196  * This command is available under these conditions:
197  *
198  *                |  Bootloader  |  Firmware
199  * ---------------+--------------+-----------
200  * ColorHug       |      ✓       |      ✓
201  * ColorHug2      |      ✓       |      ✓
202  * ColorHug+      |      ✓       |      ✓
203  * ColorHugALS    |      ✓       |      ✓
204  *
205  * Since: 0.1.29
206  **/
207 #define	CH_CMD_GET_FIRMWARE_VERSION		0x07
208 
209 /**
210  * CH_CMD_GET_CALIBRATION:
211  *
212  * Gets the calibration matrix. The description does not have to be NULL
213  * terminated.
214  *
215  * @types is a bitmask which corresponds to:
216  *
217  * bit:
218  *  0     Can be used with LCD panels
219  *  1     Can be used with CRT monitors
220  *  2     Can be used with projectors
221  *  3     Can be used with LED panels
222  *  4-7   Reserved for future use
223  *
224  * IN:  [1:cmd][2:index]
225  * OUT: [1:retval][1:cmd][2*9:matrix_value][1:types][23:description]
226  *
227  * This command is available under these conditions:
228  *
229  *                |  Bootloader  |  Firmware
230  * ---------------+--------------+-----------
231  * ColorHug       |      ×       |      ✓
232  * ColorHug2      |      ×       |      ✓
233  * ColorHug+      |      ×       |      ×
234  * ColorHugALS    |      ×       |      ×
235  *
236  * Since: 0.1.29
237  **/
238 #define	CH_CMD_GET_CALIBRATION			0x09
239 
240 /**
241  * CH_CMD_SET_CALIBRATION:
242  *
243  * Sets the calibration matrix.
244  *
245  * IN:  [1:cmd][2:index][4*9:matrix_value][1:types][23:description]
246  * OUT: [1:retval][1:cmd]
247  *
248  * This command is available under these conditions:
249  *
250  *                |  Bootloader  |  Firmware
251  * ---------------+--------------+-----------
252  * ColorHug       |      ×       |      ✓
253  * ColorHug2      |      ×       |      ✓
254  * ColorHug+      |      ×       |      ×
255  * ColorHugALS    |      ×       |      ×
256  *
257  * Since: 0.1.29
258  **/
259 #define	CH_CMD_SET_CALIBRATION			0x0a
260 
261 /**
262  * CH_CMD_GET_SERIAL_NUMBER:
263  *
264  * Gets the device serial number.
265  *
266  * IN:  [1:cmd]
267  * OUT: [1:retval][1:cmd][4:serial_number]
268  *
269  * This command is available under these conditions:
270  *
271  *                |  Bootloader  |  Firmware
272  * ---------------+--------------+-----------
273  * ColorHug       |      ×       |      ✓
274  * ColorHug2      |      ×       |      ✓
275  * ColorHug+      |      ×       |      ✓
276  * ColorHugALS    |      ×       |      ✓
277  *
278  * Since: 0.1.29
279  **/
280 #define	CH_CMD_GET_SERIAL_NUMBER		0x0b
281 
282 /**
283  * CH_CMD_SET_SERIAL_NUMBER:
284  *
285  * Sets the device serial number.
286  *
287  * IN:  [1:cmd][4:serial_number]
288  * OUT: [1:retval][1:cmd]
289  *
290  * This command is available under these conditions:
291  *
292  *                |  Bootloader  |  Firmware
293  * ---------------+--------------+-----------
294  * ColorHug       |      ×       |      ✓
295  * ColorHug2      |      ×       |      ✓
296  * ColorHug+      |      ×       |      ✓
297  * ColorHugALS    |      ×       |      ×
298  *
299  * Since: 0.1.29
300  **/
301 #define	CH_CMD_SET_SERIAL_NUMBER		0x0c
302 
303 /**
304  * CH_CMD_GET_LEDS:
305  *
306  * Get the LED state.
307  *
308  * IN:  [1:cmd]
309  * OUT: [1:retval][1:cmd][1:led_state]
310  *
311  * This command is available under these conditions:
312  *
313  *                |  Bootloader  |  Firmware
314  * ---------------+--------------+-----------
315  * ColorHug       |      ×       |      ✓
316  * ColorHug2      |      ×       |      ✓
317  * ColorHug+      |      ×       |      ✓
318  * ColorHugALS    |      ✓       |      ✓
319  *
320  * Since: 0.1.29
321  **/
322 #define	CH_CMD_GET_LEDS				0x0d
323 
324 /**
325  * CH_CMD_SET_LEDS:
326  *
327  * Set the LED state. Using a @repeat value of anything other than
328  * 0 will block the processor for the duration of the command.
329  *
330  * If @repeat is not 0, then the LEDs are reset to all off at the end
331  * of the sequence.
332  *
333  * IN:  [1:cmd][1:led_state][1:repeat][1:on-time][1:off-time]
334  * OUT: [1:retval][1:cmd]
335  *
336  * This command is available under these conditions:
337  *
338  *                |  Bootloader  |  Firmware
339  * ---------------+--------------+-----------
340  * ColorHug       |      ×       |      ✓
341  * ColorHug2      |      ×       |      ✓
342  * ColorHug+      |      ×       |      ✓
343  * ColorHugALS    |      ×       |      ✓
344  *
345  * Since: 0.1.29
346  **/
347 #define	CH_CMD_SET_LEDS				0x0e
348 
349 /**
350  * CH_CMD_GET_ILLUMINANTS:
351  *
352  * Get the illuminant state.
353  *
354  * IN:  [1:cmd]
355  * OUT: [1:retval][1:cmd][1:illuminants]
356  *
357  * This command is available under these conditions:
358  *
359  *                |  Bootloader  |  Firmware
360  * ---------------+--------------+-----------
361  * ColorHug       |      ×       |      ×
362  * ColorHug2      |      ×       |      ×
363  * ColorHug+      |      ×       |      ✓
364  * ColorHugALS    |      ×       |      ×
365  *
366  * Since: 1.3.4
367  **/
368 #define	CH_CMD_GET_ILLUMINANTS			0x15
369 
370 /**
371  * CH_CMD_SET_ILLUMINANTS:
372  *
373  * Set the illuminants.
374  *
375  * IN:  [1:cmd][1:illuminant]
376  * OUT: [1:retval][1:cmd]
377  *
378  * This command is available under these conditions:
379  *
380  *                |  Bootloader  |  Firmware
381  * ---------------+--------------+-----------
382  * ColorHug       |      ×       |      ×
383  * ColorHug2      |      ×       |      ×
384  * ColorHug+      |      ×       |      ✓
385  * ColorHugALS    |      ×       |      ×
386  *
387  * Since: 1.3.4
388  **/
389 #define	CH_CMD_SET_ILLUMINANTS			0x16
390 
391 /**
392  * CH_CMD_GET_DARK_OFFSETS:
393  *
394  * Get the dark offsets.
395  *
396  * IN:  [1:cmd]
397  * OUT: [1:retval][1:cmd][2:red][2:green][2:blue]
398  *
399  * This command is available under these conditions:
400  *
401  *                |  Bootloader  |  Firmware
402  * ---------------+--------------+-----------
403  * ColorHug       |      ×       |      ✓
404  * ColorHug2      |      ×       |      ×
405  * ColorHug+      |      ×       |      ✓
406  * ColorHugALS    |      ×       |      ×
407  *
408  * Since: 0.1.29
409  **/
410 #define	CH_CMD_GET_DARK_OFFSETS			0x0f
411 
412 /**
413  * CH_CMD_SET_DARK_OFFSETS:
414  *
415  * Set the dark offsets for use when taking samples when the measure
416  * mode is FREQUENCY. When the measure mode is DURATION these values
417  * have no effect.
418  *
419  * IN:  [1:cmd][2:red][2:green][2:blue]
420  * OUT: [1:retval][1:cmd]
421  *
422  * This command is available under these conditions:
423  *
424  *                |  Bootloader  |  Firmware
425  * ---------------+--------------+-----------
426  * ColorHug       |      ×       |      ✓
427  * ColorHug2      |      ×       |      ×
428  * ColorHug+      |      ×       |      ✓
429  * ColorHugALS    |      ×       |      ×
430  *
431  * Since: 0.1.29
432  **/
433 #define	CH_CMD_SET_DARK_OFFSETS			0x10
434 
435 /**
436  * CH_CMD_GET_OWNER_NAME:
437  *
438  * Get User's Name
439  *
440  * IN:  [1:cmd]
441  * OUT: [1:retval][1:cmd][60:owner-name]
442  *
443  * This command is available under these conditions:
444  *
445  *                |  Bootloader  |  Firmware
446  * ---------------+--------------+-----------
447  * ColorHug       |      ×       |      ✓
448  * ColorHug2      |      ×       |      ✓
449  * ColorHug+      |      ×       |      ✓
450  * ColorHugALS    |      ×       |      ×
451  *
452  * Since: 0.1.29
453  **/
454 #define	CH_CMD_GET_OWNER_NAME			0x11
455 
456 /**
457  * CH_CMD_SET_OWNER_NAME:
458  *
459  * Set User's Name
460  *
461  * IN:  [1:cmd][60:owner-name]
462  * OUT: [1:retval][1:cmd]
463  *
464  * This command is available under these conditions:
465  *
466  *                |  Bootloader  |  Firmware
467  * ---------------+--------------+-----------
468  * ColorHug       |      ×       |      ✓
469  * ColorHug2      |      ×       |      ✓
470  * ColorHug+      |      ×       |      ✓
471  * ColorHugALS    |      ×       |      ×
472  *
473  * Since: 0.1.29
474  **/
475 #define	CH_CMD_SET_OWNER_NAME			0x12
476 
477 /**
478  * CH_CMD_GET_OWNER_EMAIL:
479  *
480  * Get User's Email Address
481  *
482  * IN:  [1:cmd]
483  * OUT: [1:retval][1:cmd][60:owner-email]
484  *
485  * This command is available under these conditions:
486  *
487  *                |  Bootloader  |  Firmware
488  * ---------------+--------------+-----------
489  * ColorHug       |      ×       |      ✓
490  * ColorHug2      |      ×       |      ✓
491  * ColorHug+      |      ×       |      ✓
492  * ColorHugALS    |      ×       |      ×
493  *
494  * Since: 0.1.29
495  **/
496 #define	CH_CMD_GET_OWNER_EMAIL			0x13
497 
498 /**
499  * CH_CMD_SET_OWNER_EMAIL:
500  *
501  * Set User's Email Address
502  *
503  * IN:  [1:cmd][60:owner-email]
504  * OUT: [1:retval][1:cmd]
505  *
506  * This command is available under these conditions:
507  *
508  *                |  Bootloader  |  Firmware
509  * ---------------+--------------+-----------
510  * ColorHug       |      ×       |      ✓
511  * ColorHug2      |      ×       |      ✓
512  * ColorHug+      |      ×       |      ✓
513  * ColorHugALS    |      ×       |      ×
514  *
515  * Since: 0.1.29
516  **/
517 #define	CH_CMD_SET_OWNER_EMAIL			0x14
518 
519 /**
520  * CH_CMD_WRITE_EEPROM:
521  *
522  * Write values to EEPROM.
523  *
524  * IN:  [1:cmd][8:eeprom_magic]
525  * OUT: [1:retval][1:cmd]
526  *
527  * This command is available under these conditions:
528  *
529  *                |  Bootloader  |  Firmware
530  * ---------------+--------------+-----------
531  * ColorHug       |      ×       |      ✓
532  * ColorHug2      |      ×       |      ✓
533  * ColorHug+      |      ×       |      ✓
534  * ColorHugALS    |      ×       |      ×
535  *
536  * Since: 0.1.29
537  **/
538 #define	CH_CMD_WRITE_EEPROM			0x20
539 
540 /**
541  * CH_CMD_TAKE_READING_RAW:
542  *
543  * Take a raw reading.
544  *
545  * IN:  [1:cmd]
546  * OUT: [1:retval][1:cmd][4:count]
547  *
548  * This command is available under these conditions:
549  *
550  *                |  Bootloader  |  Firmware
551  * ---------------+--------------+-----------
552  * ColorHug       |      ×       |      ✓
553  * ColorHug2      |      ×       |      ×
554  * ColorHug+      |      ×       |      ✓
555  * ColorHugALS    |      ×       |      ✓
556  *
557  * Since: 0.1.29
558  **/
559 #define	CH_CMD_TAKE_READING_RAW			0x21
560 
561 /**
562  * CH_CMD_TAKE_READINGS:
563  *
564  * Take a reading taking into account just dark offsets.
565  * All of @red, @green and @blue are packed float values.
566  *
567  * This command is useful if you want to do an ambient reading.
568  *
569  * IN:  [1:cmd]
570  * OUT: [1:retval][1:cmd][4:red][4:green][4:blue]
571  *
572  * This command is available under these conditions:
573  *
574  *                |  Bootloader  |  Firmware
575  * ---------------+--------------+-----------
576  * ColorHug       |      ×       |      ✓
577  * ColorHug2      |      ×       |      ✓
578  * ColorHug+      |      ×       |      ✓
579  * ColorHugALS    |      ×       |      ×
580  *
581  * Since: 0.1.29
582  **/
583 #define	CH_CMD_TAKE_READINGS			0x22
584 
585 /**
586  * CH_CMD_TAKE_READING_XYZ:
587  *
588  * Take a reading taking into account:
589  *  1. dark offsets
590  *  2. the calibration matrix
591  *
592  * If the calibration index > %CH_CALIBRATION_MAX then the calibration
593  * map is used to find the default calibration index to use.
594  *
595  * If the calibration index is set to %CH_CALIBRATION_SPECTRAL then the
596  * spectral hardware is used if it is available. The CIE 1931 luminosity
597  * function data is used by default.
598  *
599  * IN:  [1:cmd][2:calibration-index]
600  * OUT: [1:retval][1:cmd][4:red][4:green][4:blue]
601  *
602  * This command is available under these conditions:
603  *
604  *                |  Bootloader  |  Firmware
605  * ---------------+--------------+-----------
606  * ColorHug       |      ×       |      ✓
607  * ColorHug2      |      ×       |      ✓
608  * ColorHug+      |      ×       |      ✓
609  * ColorHugALS    |      ×       |      ×
610  *
611  * Since: 0.1.29
612  **/
613 #define	CH_CMD_TAKE_READING_XYZ			0x23
614 
615 /**
616  * CH_CMD_TAKE_READING_SPECTRAL:
617  *
618  * Takes a spectral reading putting %CH_CCD_SPECTRAL_RESOLUTION uint16_t values
619  * (typically 7296 bytes) in SRAM.
620  * The values are scaled from 0x0000 to 0x03ff and correspond to the actual
621  * signal amplitude once Vref- and Vref+ have been taken into account.
622  *
623  * IN:  [1:cmd]
624  * OUT: [1:retval][1:cmd][4:addr]
625  *
626  * This command is available under these conditions:
627  *
628  *                |  Bootloader  |  Firmware
629  * ---------------+--------------+-----------
630  * ColorHug       |      ×       |      ×
631  * ColorHug2      |      ×       |      ×
632  * ColorHug+      |      ×       |      ✓
633  * ColorHugALS    |      ×       |      ×
634  *
635  * Since: 0.1.31
636  **/
637 #define	CH_CMD_TAKE_READING_SPECTRAL		0x55
638 
639 /**
640  * CH_CMD_GET_ADC_CALIBRATION_POS:
641  *
642  * Gets the value of the Vref+ ADC adjustment.
643  * @vref is a packed float.
644  *
645  * IN:  [1:cmd]
646  * OUT: [1:retval][1:cmd][4:vref]
647  *
648  * This command is available under these conditions:
649  *
650  *                |  Bootloader  |  Firmware
651  * ---------------+--------------+-----------
652  * ColorHug       |      ×       |      ×
653  * ColorHug2      |      ×       |      ×
654  * ColorHug+      |      ×       |      ✓
655  * ColorHugALS    |      ×       |      ×
656  *
657  * Since: 0.1.31
658  **/
659 #define	CH_CMD_GET_ADC_CALIBRATION_POS		0x51
660 
661 /**
662  * CH_CMD_GET_ADC_CALIBRATION_NEG:
663  *
664  * Gets the value of the Vref- ADC adjustment.
665  * @vref is a packed float.
666  *
667  * IN:  [1:cmd]
668  * OUT: [1:retval][1:cmd][4:vref]
669  *
670  * This command is available under these conditions:
671  *
672  *                |  Bootloader  |  Firmware
673  * ---------------+--------------+-----------
674  * ColorHug       |      ×       |      ×
675  * ColorHug2      |      ×       |      ×
676  * ColorHug+      |      ×       |      ✓
677  * ColorHugALS    |      ×       |      ×
678  *
679  * Since: 0.1.31
680  **/
681 #define	CH_CMD_GET_ADC_CALIBRATION_NEG		0x52
682 
683 /**
684  * CH_CMD_GET_CCD_CALIBRATION:
685  *
686  * Gets the spectral indexes for the RGB calibration which are values between 0
687  * and %CH_CCD_SPECTRAL_RESOLUTION pointing to the dominant peak for the color.
688  * Red is nominally 625nm, green 520nm and blue 465nm.
689  *
690  * IN:  [1:cmd]
691  * OUT: [1:retval][1:cmd][2:red-idx][2:green-idx][2:blue-idx]
692  *
693  * This command is available under these conditions:
694  *
695  *                |  Bootloader  |  Firmware
696  * ---------------+--------------+-----------
697  * ColorHug       |      ×       |      ×
698  * ColorHug2      |      ×       |      ×
699  * ColorHug+      |      ×       |      ✓
700  * ColorHugALS    |      ×       |      ×
701  *
702  * Since: 0.1.31
703  **/
704 #define	CH_CMD_GET_CCD_CALIBRATION		0x53
705 
706 /**
707  * CH_CMD_SET_CCD_CALIBRATION:
708  *
709  * Sets the spectral indexes for the RGB calibration.
710  *
711  * IN:  [1:cmd][2:red-idx][2:green-idx][2:blue-idx]
712  * OUT: [1:retval][1:cmd]
713  *
714  * This command is available under these conditions:
715  *
716  *                |  Bootloader  |  Firmware
717  * ---------------+--------------+-----------
718  * ColorHug       |      ×       |      ×
719  * ColorHug2      |      ×       |      ×
720  * ColorHug+      |      ×       |      ✓
721  * ColorHugALS    |      ×       |      ×
722  *
723  * Since: 0.1.31
724  **/
725 #define	CH_CMD_SET_CCD_CALIBRATION		0x54
726 
727 /**
728  * CH_CMD_RESET:
729  *
730  * Reset the processor.
731  *
732  * IN:  [1:cmd]
733  * OUT: [1:retval][1:cmd] (but with success the device will disconnect)
734  *
735  * This command is available under these conditions:
736  *
737  *                |  Bootloader  |  Firmware
738  * ---------------+--------------+-----------
739  * ColorHug       |      ✓       |      ✓
740  * ColorHug2      |      ✓       |      ✓
741  * ColorHug+      |      ✓       |      ✓
742  * ColorHugALS    |      ✓       |      ✓
743  *
744  * Since: 0.1.29
745  **/
746 #define	CH_CMD_RESET				0x24
747 
748 /**
749  * CH_CMD_READ_FLASH:
750  *
751  * Read in raw data from the flash memory.
752  *
753  * IN:  [1:cmd][2:address][1:length]
754  * OUT: [1:retval][1:cmd][1:checksum][1-60:data]
755  *
756  * This command is available under these conditions:
757  *
758  *                |  Bootloader  |  Firmware
759  * ---------------+--------------+-----------
760  * ColorHug       |      ✓       |      ×
761  * ColorHug2      |      ✓       |      ×
762  * ColorHug+      |      ✓       |      ×
763  * ColorHugALS    |      ✓       |      ×
764  *
765  * Since: 0.1.29
766  **/
767 #define	CH_CMD_READ_FLASH			0x25
768 
769 /**
770  * CH_CMD_ERASE_FLASH:
771  *
772  * Erases flash memory before a write is done.
773  * Erasing flash can only be done in 1k byte chunks and should be
774  * aligned to 1k.
775  *
776  * IN:  [1:cmd][2:address][2:length]
777  * OUT: [1:retval][1:cmd]
778  *
779  * This command is available under these conditions:
780  *
781  *                |  Bootloader  |  Firmware
782  * ---------------+--------------+-----------
783  * ColorHug       |      ✓       |      ×
784  * ColorHug2      |      ✓       |      ×
785  * ColorHug+      |      ✓       |      ×
786  * ColorHugALS    |      ✓       |      ×
787  *
788  * Since: 0.1.29
789  **/
790 #define	CH_CMD_ERASE_FLASH			0x29
791 
792 /**
793  * CH_CMD_WRITE_FLASH:
794  *
795  * Write raw data to the flash memory. You can only write aligned to
796  * a 32 byte boundary, and you must flush any incomplete 64 byte block.
797  *
798  * IN:  [1:cmd][2:address][1:length][1:checksum][1-32:data]
799  * OUT: [1:retval][1:cmd]
800  *
801  * This command is available under these conditions:
802  *
803  *                |  Bootloader  |  Firmware
804  * ---------------+--------------+-----------
805  * ColorHug       |      ✓       |      ×
806  * ColorHug2      |      ✓       |      ×
807  * ColorHug+      |      ✓       |      ×
808  * ColorHugALS    |      ✓       |      ×
809  *
810  * Since: 0.1.29
811  **/
812 #define	CH_CMD_WRITE_FLASH			0x26
813 
814 /**
815  * CH_CMD_BOOT_FLASH:
816  *
817  * Boot into to the flash memory.
818  *
819  * IN:  [1:cmd]
820  * OUT: [1:retval][1:cmd]
821  *
822  * This command is available under these conditions:
823  *
824  *                |  Bootloader  |  Firmware
825  * ---------------+--------------+-----------
826  * ColorHug       |      ✓       |      ×
827  * ColorHug2      |      ✓       |      ×
828  * ColorHug+      |      ✓       |      ×
829  * ColorHugALS    |      ✓       |      ×
830  *
831  * Since: 0.1.29
832  **/
833 #define	CH_CMD_BOOT_FLASH			0x27
834 
835 /**
836  * CH_CMD_SET_FLASH_SUCCESS:
837  *
838  * Sets the result of the firmware flashing. The idea of this command
839  * is that the flashing interaction is thus:
840  *
841  * 1.	Reset()			device goes to bootloader mode
842  * 2.	SetFlashSuccess(FALSE)
843  * 3.	WriteFlash($data)
844  * 4.	ReadFlash($data)	to verify
845  * 5.	BootFlash()		switch to program mode
846  * 6.	SetFlashSuccess(TRUE)
847  *
848  * The idea is that we only set the success FALSE from the bootoloader
849  * to indicate that on booting we should not boot into the program.
850  * We can only set the success true from the *new* program code so as
851  * to verify that the new program boots, and can accept HID commands.
852  *
853  * IN:  [1:cmd][1:success]
854  * OUT: [1:retval][1:cmd]
855  *
856  * This command is available under these conditions:
857  *
858  *                |  Bootloader  |  Firmware
859  * ---------------+--------------+-----------
860  * ColorHug       |      ✓       |      ✓
861  * ColorHug2      |      ✓       |      ✓
862  * ColorHug+      |      ✓       |      ✓
863  * ColorHugALS    |      ✓       |      ✓
864  *
865  * Different values of @success are permitted in each mode.
866  *
867  * Since: 0.1.29
868  **/
869 #define	CH_CMD_SET_FLASH_SUCCESS		0x28
870 
871 /**
872  * CH_CMD_GET_PRE_SCALE:
873  *
874  * Get the pre XYZ scaling constant. @scale is a packed float.
875  *
876  * IN:  [1:cmd]
877  * OUT: [1:retval][1:cmd][4:scale]
878  *
879  * This command is available under these conditions:
880  *
881  *                |  Bootloader  |  Firmware
882  * ---------------+--------------+-----------
883  * ColorHug       |      ×       |      ✓
884  * ColorHug2      |      ×       |      ×
885  * ColorHug+      |      ×       |      ×
886  * ColorHugALS    |      ×       |      ×
887  *
888  * Since: 0.1.29
889  **/
890 #define	CH_CMD_GET_PRE_SCALE			0x2c
891 
892 /**
893  * CH_CMD_SET_PRE_SCALE:
894  *
895  * Set the pre XYZ scaling constant. @scale is a packed float.
896  *
897  * IN:  [1:cmd][4:scale]
898  * OUT: [1:retval][1:cmd]
899  *
900  * This command is available under these conditions:
901  *
902  *                |  Bootloader  |  Firmware
903  * ---------------+--------------+-----------
904  * ColorHug       |      ×       |      ✓
905  * ColorHug2      |      ×       |      ×
906  * ColorHug+      |      ×       |      ×
907  * ColorHugALS    |      ×       |      ×
908  *
909  * Since: 0.1.29
910  **/
911 #define	CH_CMD_SET_PRE_SCALE			0x2d
912 
913 /**
914  * CH_CMD_GET_POST_SCALE:
915  *
916  * Get the post XYZ scaling constant. @scale is a packed float.
917  *
918  * IN:  [1:cmd]
919  * OUT: [1:retval][1:cmd][4:scale]
920  *
921  * This command is available under these conditions:
922  *
923  *                |  Bootloader  |  Firmware
924  * ---------------+--------------+-----------
925  * ColorHug       |      ×       |      ✓
926  * ColorHug2      |      ×       |      ×
927  * ColorHug+      |      ×       |      ×
928  * ColorHugALS    |      ×       |      ×
929  *
930  * Since: 0.1.29
931  **/
932 #define	CH_CMD_GET_POST_SCALE			0x2a
933 
934 /**
935  * CH_CMD_SET_POST_SCALE:
936  *
937  * Set the post XYZ scaling constant. @scale is a packed float.
938  *
939  * IN:  [1:cmd][4:scale]
940  * OUT: [1:retval][1:cmd]
941  *
942  * This command is available under these conditions:
943  *
944  *                |  Bootloader  |  Firmware
945  * ---------------+--------------+-----------
946  * ColorHug       |      ×       |      ✓
947  * ColorHug2      |      ×       |      ×
948  * ColorHug+      |      ×       |      ×
949  * ColorHugALS    |      ×       |      ×
950  *
951  * Since: 0.1.29
952  **/
953 #define	CH_CMD_SET_POST_SCALE			0x2b
954 
955 /**
956  * CH_CMD_GET_CALIBRATION_MAP:
957  *
958  * Get the mappings from default calibration type to calibration
959  * indexes.
960  *
961  * The calibration types are as follows:
962  * LCD		= 0
963  * CRT		= 1
964  * Projector	= 2
965  * LED		= 3
966  * Custom1	= 4
967  * Custom2	= 5
968  *
969  * In the future CustomX may be renamed to another display technology,
970  * e.g. e-ink.
971  *
972  * IN:  [1:cmd]
973  * OUT: [1:retval][1:cmd][6*2:types]
974  *
975  * This command is available under these conditions:
976  *
977  *                |  Bootloader  |  Firmware
978  * ---------------+--------------+-----------
979  * ColorHug       |      ×       |      ✓
980  * ColorHug2      |      ×       |      ✓
981  * ColorHug+      |      ×       |      ×
982  * ColorHugALS    |      ×       |      ×
983  *
984  * Since: 0.1.29
985  **/
986 #define	CH_CMD_GET_CALIBRATION_MAP		0x2e
987 
988 /**
989  * CH_CMD_SET_CALIBRATION_MAP:
990  *
991  * Set the calibration type to index map.
992  *
993  * IN:  [1:cmd][6*2:types]
994  * OUT: [1:retval][1:cmd]
995  *
996  * This command is available under these conditions:
997  *
998  *                |  Bootloader  |  Firmware
999  * ---------------+--------------+-----------
1000  * ColorHug       |      ×       |      ✓
1001  * ColorHug2      |      ×       |      ✓
1002  * ColorHug+      |      ×       |      ×
1003  * ColorHugALS    |      ×       |      ×
1004  *
1005  * Since: 0.1.29
1006  **/
1007 #define	CH_CMD_SET_CALIBRATION_MAP		0x2f
1008 
1009 /**
1010  * CH_CMD_GET_HARDWARE_VERSION:
1011  *
1012  * Get the hardware version.
1013  *
1014  * The hardware versions are as follows:
1015  * 0x00		= Pre-production hardware
1016  * 0x01		= ColorHug
1017  * 0x02		= ColorHug2
1018  * 0x03		= ColorHug+
1019  * 0x04		= ColorHugALS
1020  * 0x05-0x0f	= Reserved for future use
1021  *
1022  * IN:  [1:cmd]
1023  * OUT: [1:retval][1:cmd][1:hw_version]
1024  *
1025  * This command is available under these conditions:
1026  *
1027  *                |  Bootloader  |  Firmware
1028  * ---------------+--------------+-----------
1029  * ColorHug       |      ✓       |      ✓
1030  * ColorHug2      |      ✓       |      ✓
1031  * ColorHug+      |      ✓       |      ✓
1032  * ColorHugALS    |      ✓       |      ✓
1033  *
1034  * Since: 0.1.29
1035  **/
1036 #define	CH_CMD_GET_HARDWARE_VERSION		0x30
1037 
1038 /**
1039  * CH_CMD_TAKE_READING_ARRAY:
1040  *
1041  * Takes 30 raw samples and returns them in an array.
1042  *
1043  * This command can be used to find the optimum delay between patches
1044  * by showing a black sample area, then white, and then using this
1045  * command to find out how long the actual hardware delay is.
1046  *
1047  * It can also be used to find out how stable the device or output is
1048  * over a small amount of time, typically ~2.5 seconds for the maximum
1049  * integral time.
1050  *
1051  * IN:  [1:cmd]
1052  * OUT: [1:retval][1:cmd][30:reading_array]
1053  *
1054  * This command is available under these conditions:
1055  *
1056  *                |  Bootloader  |  Firmware
1057  * ---------------+--------------+-----------
1058  * ColorHug       |      ×       |      ✓
1059  * ColorHug2      |      ×       |      ×
1060  * ColorHug+      |      ×       |      ×
1061  * ColorHugALS    |      ×       |      ×
1062  *
1063  * Since: 0.1.29
1064  **/
1065 #define	CH_CMD_TAKE_READING_ARRAY		0x31
1066 
1067 /**
1068  * CH_CMD_SET_PCB_ERRATA:
1069  *
1070  * Sets the board errata value. Board errata is used to correct swapped
1071  * LEDs and any future problems discovered that only affect some batches
1072  * of hardware version 1.
1073  *
1074  * The errata bitmask is as follows:
1075  * 0x00		= No errata for this PCB
1076  * 0x01		= Leds are swapped
1077  * 0x02-0xffff	= Reserved for future use
1078  *
1079  * IN:  [1:cmd][2:pcb_errata]
1080  * OUT: [1:retval][1:cmd]
1081  *
1082  * This command is available under these conditions:
1083  *
1084  *                |  Bootloader  |  Firmware
1085  * ---------------+--------------+-----------
1086  * ColorHug       |      ×       |      ✓
1087  * ColorHug2      |      ×       |      ✓
1088  * ColorHug+      |      ×       |      ✓
1089  * ColorHugALS    |      ×       |      ×
1090  *
1091  * Since: 0.1.29
1092  **/
1093 #define	CH_CMD_SET_PCB_ERRATA			0x32
1094 
1095 /**
1096  * CH_CMD_GET_PCB_ERRATA:
1097  *
1098  * Gets the board errata value.
1099  *
1100  * IN:  [1:cmd]
1101  * OUT: [1:retval][1:cmd][2:pcb_errata]
1102  *
1103  * This command is available under these conditions:
1104  *
1105  *                |  Bootloader  |  Firmware
1106  * ---------------+--------------+-----------
1107  * ColorHug       |      ×       |      ✓
1108  * ColorHug2      |      ×       |      ✓
1109  * ColorHug+      |      ×       |      ✓
1110  * ColorHugALS    |      ×       |      ×
1111  *
1112  * Since: 0.1.29
1113  **/
1114 #define	CH_CMD_GET_PCB_ERRATA			0x33
1115 
1116 /**
1117  * CH_CMD_SET_REMOTE_HASH:
1118  *
1119  * Sets the remote SHA1 hash of the profile. This is designed to
1120  * be used by the calibration program to indicate the key which allows
1121  * the completed profile to be found from a public web service.
1122  *
1123  * IN:  [1:cmd][20:sha1_hash]
1124  * OUT: [1:retval][1:cmd]
1125  *
1126  * This command is available under these conditions:
1127  *
1128  *                |  Bootloader  |  Firmware
1129  * ---------------+--------------+-----------
1130  * ColorHug       |      ×       |      ✓
1131  * ColorHug2      |      ×       |      ✓
1132  * ColorHug+      |      ×       |      ✓
1133  * ColorHugALS    |      ×       |      ×
1134  *
1135  * Since: 0.1.29
1136  **/
1137 #define	CH_CMD_SET_REMOTE_HASH			0x34
1138 
1139 /**
1140  * CH_CMD_GET_REMOTE_HASH:
1141  *
1142  * Gets the remote hash which is used to get the last profile saved
1143  * to a public web service.
1144  *
1145  * IN:  [1:cmd]
1146  * OUT: [1:retval][1:cmd][20:sha1_hash]
1147  *
1148  * This command is available under these conditions:
1149  *
1150  *                |  Bootloader  |  Firmware
1151  * ---------------+--------------+-----------
1152  * ColorHug       |      ×       |      ✓
1153  * ColorHug2      |      ×       |      ✓
1154  * ColorHug+      |      ×       |      ✓
1155  * ColorHugALS    |      ×       |      ×
1156  *
1157  * Since: 0.1.29
1158  **/
1159 #define	CH_CMD_GET_REMOTE_HASH			0x35
1160 
1161 /**
1162  * CH_CMD_SET_MEASURE_MODE:
1163  *
1164  * Sets the measurement mode. The mode can either be frequency or pulse
1165  * duration. The former is well tested, but the latter is much more
1166  * precise.
1167  *
1168  * IN:  [1:cmd][1:measure_mode]
1169  * OUT: [1:retval][1:cmd]
1170  *
1171  * This command is available under these conditions:
1172  *
1173  *                |  Bootloader  |  Firmware
1174  * ---------------+--------------+-----------
1175  * ColorHug       |      ×       |      ✓
1176  * ColorHug2      |      ×       |      ×
1177  * ColorHug+      |      ×       |      ×
1178  * ColorHugALS    |      ×       |      ×
1179  *
1180  * Since: 0.1.29
1181  **/
1182 #define	CH_CMD_SET_MEASURE_MODE			0x36
1183 
1184 /**
1185  * CH_CMD_GET_MEASURE_MODE:
1186  *
1187  * Gets the measurement mode.
1188  *
1189  * IN:  [1:cmd]
1190  * OUT: [1:retval][1:cmd][1:measure_mode]
1191  *
1192  * This command is available under these conditions:
1193  *
1194  *                |  Bootloader  |  Firmware
1195  * ---------------+--------------+-----------
1196  * ColorHug       |      ×       |      ✓
1197  * ColorHug2      |      ×       |      ×
1198  * ColorHug+      |      ×       |      ×
1199  * ColorHugALS    |      ×       |      ×
1200  *
1201  * Since: 0.1.29
1202  **/
1203 #define	CH_CMD_GET_MEASURE_MODE			0x37
1204 
1205 /**
1206  * CH_CMD_READ_SRAM:
1207  *
1208  * Read in raw data from the SRAM memory.
1209  *
1210  * PROTOCOLv1:
1211  * IN:  [1:cmd][2:address][1:length]
1212  * OUT: [1:retval][1:cmd][1-60:data]
1213  *
1214  * PROTOCOLv2:
1215  * bRequest:   [cmd]
1216  * wValue:     [address-index/64]
1217  * wIndex:     interface
1218  * wLength:    0x64
1219  * Direction:  DEVICE->HOST
1220  * Data:       [64:DATA]
1221  *
1222  * This command is available under these conditions:
1223  *
1224  *                |  Bootloader  |  Firmware
1225  * ---------------+--------------+-----------
1226  * ColorHug       |      ×       |      ×
1227  * ColorHug2      |      ×       |      ✓
1228  * ColorHug+      |      ×       |      ✓
1229  * ColorHugALS    |      ×       |      ×
1230  *
1231  * Since: 0.1.29
1232  **/
1233 #define	CH_CMD_READ_SRAM			0x38
1234 
1235 /**
1236  * CH_CMD_WRITE_SRAM:
1237  *
1238  * Write raw data to the SRAM memory.
1239  *
1240  * IN:  [1:cmd][2:address][1:length][1-60:data]
1241  * OUT: [1:retval][1:cmd]
1242  *
1243  * This command is available under these conditions:
1244  *
1245  *                |  Bootloader  |  Firmware
1246  * ---------------+--------------+-----------
1247  * ColorHug       |      ×       |      ×
1248  * ColorHug2      |      ×       |      ✓
1249  * ColorHug+      |      ×       |      ✓
1250  * ColorHugALS    |      ×       |      ×
1251  *
1252  * Since: 0.1.29
1253  **/
1254 #define	CH_CMD_WRITE_SRAM			0x39
1255 
1256 /**
1257  * CH_CMD_GET_TEMPERATURE:
1258  *
1259  * Gets the temperature of the sensor in degrees celsius
1260  *
1261  * IN:  [1:cmd]
1262  * OUT: [1:retval][1:cmd][4:temperature]
1263  *
1264  * This command is available under these conditions:
1265  *
1266  *                |  Bootloader  |  Firmware
1267  * ---------------+--------------+-----------
1268  * ColorHug       |      ×       |      ×
1269  * ColorHug2      |      ×       |      ✓
1270  * ColorHug+      |      ×       |      ✓
1271  * ColorHugALS    |      ×       |      ×
1272  *
1273  * Since: 0.1.29
1274  **/
1275 #define	CH_CMD_GET_TEMPERATURE			0x3b
1276 
1277 /**
1278  * CH_CMD_GET_DAC_VALUE:
1279  *
1280  * Get the DAC value. @scale is a packed float, where 1.0f is 3.3V
1281  *
1282  * IN:  [1:cmd]
1283  * OUT: [1:retval][1:cmd][4:value]
1284  *
1285  * This command is available under these conditions:
1286  *
1287  *                |  Bootloader  |  Firmware
1288  * ---------------+--------------+-----------
1289  * ColorHug       |      ×       |      ×
1290  * ColorHug2      |      ×       |      ×
1291  * ColorHug+      |      ×       |      ✓
1292  * ColorHugALS    |      ×       |      ×
1293  *
1294  * Since: 1.1.6
1295  **/
1296 #define	CH_CMD_GET_DAC_VALUE			0x3c
1297 
1298 /**
1299  * CH_CMD_SET_DAC_VALUE:
1300  *
1301  * Set the DAC value. @scale is a packed float, where 1.0f is 3.3V
1302  *
1303  * IN:  [1:cmd][4:value]
1304  * OUT: [1:retval][1:cmd]
1305  *
1306  * This command is available under these conditions:
1307  *
1308  *                |  Bootloader  |  Firmware
1309  * ---------------+--------------+-----------
1310  * ColorHug       |      ×       |      ×
1311  * ColorHug2      |      ×       |      ×
1312  * ColorHug+      |      ×       |      ✓
1313  * ColorHugALS    |      ×       |      ×
1314  *
1315  * Since: 1.1.6
1316  **/
1317 #define	CH_CMD_SET_DAC_VALUE			0x3d
1318 
1319 /**
1320  * CH_CMD_SELF_TEST:
1321  *
1322  * Tests the device by trying to get a non-zero reading from each
1323  * color channel.
1324  *
1325  * IN:  [1:cmd]
1326  * OUT: [1:retval][1:cmd]
1327  *
1328  * This command is available under these conditions:
1329  *
1330  *                |  Bootloader  |  Firmware
1331  * ---------------+--------------+-----------
1332  * ColorHug       |      ✓       |      ✓
1333  * ColorHug2      |      ✓       |      ✓
1334  * ColorHug+      |      ✓       |      ✓
1335  * ColorHugALS    |      ✓       |      ×
1336  *
1337  * Since: 0.1.29
1338  **/
1339 #define	CH_CMD_SELF_TEST			0x40
1340 
1341 /**
1342  * CH_CMD_LOAD_SRAM:
1343  *
1344  * Load the SRAM from the EEPROM.
1345  *
1346  * PROTOCOLv2:
1347  * bRequest:   [cmd]
1348  * wValue:     0x00
1349  * wIndex:     interface
1350  * wLength:    0x00
1351  * Direction:  DEVICE->HOST
1352  * Data:       [1:error][1:cmd]
1353  *
1354  * This command is available under these conditions:
1355  *
1356  *                |  Bootloader  |  Firmware
1357  * ---------------+--------------+-----------
1358  * ColorHug       |      ×       |      ×
1359  * ColorHug2      |      ×       |      ×
1360  * ColorHug+      |      ×       |      ✓
1361  * ColorHugALS    |      ×       |      ×
1362  *
1363  * Since: 0.1.29
1364  **/
1365 #define	CH_CMD_LOAD_SRAM			0x41
1366 
1367 /**
1368  * CH_CMD_SAVE_SRAM:
1369  *
1370  * Save the SRAM to the EEPROM.
1371  *
1372  * PROTOCOLv2:
1373  * bRequest:   [cmd]
1374  * wValue:     0x00
1375  * wIndex:     interface
1376  * wLength:    0x00
1377  * Direction:  DEVICE->HOST
1378  * Data:       [1:error][1:cmd]
1379  *
1380  * This command is available under these conditions:
1381  *
1382  *                |  Bootloader  |  Firmware
1383  * ---------------+--------------+-----------
1384  * ColorHug       |      ×       |      ×
1385  * ColorHug2      |      ×       |      ×
1386  * ColorHug+      |      ×       |      ✓
1387  * ColorHugALS    |      ×       |      ×
1388  *
1389  * Since: 0.1.29
1390  **/
1391 #define	CH_CMD_SAVE_SRAM			0x42
1392 
1393 /**
1394  * CH_CMD_GET_ERROR:
1395  *
1396  * Gets any recorded error from the device.
1397  *
1398  * PROTOCOLv2:
1399  * bRequest:   [cmd]
1400  * wValue:     0x00
1401  * wIndex:     interface
1402  * wLength:    0x00
1403  * Direction:  DEVICE->HOST
1404  * Data:       [1:error][1:cmd]
1405  *
1406  * This command is available under these conditions:
1407  *
1408  *                |  Bootloader  |  Firmware
1409  * ---------------+--------------+-----------
1410  * ColorHug       |      ×       |      ×
1411  * ColorHug2      |      ×       |      ×
1412  * ColorHug+      |      ×       |      ✓
1413  * ColorHugALS    |      ×       |      ×
1414  *
1415  * Since: 1.3.1
1416  **/
1417 #define	CH_CMD_GET_ERROR			0x60
1418 
1419 /**
1420  * CH_CMD_CLEAR_ERROR:
1421  *
1422  * Clears any recorded error on the device.
1423  *
1424  * PROTOCOLv2:
1425  * bRequest:   [cmd]
1426  * wValue:     0x00
1427  * wIndex:     interface
1428  * wLength:    0x00
1429  * Direction:  DEVICE->HOST
1430  * Data:       []
1431  *
1432  * This command is available under these conditions:
1433  *
1434  *                |  Bootloader  |  Firmware
1435  * ---------------+--------------+-----------
1436  * ColorHug       |      ×       |      ×
1437  * ColorHug2      |      ×       |      ×
1438  * ColorHug+      |      ×       |      ✓
1439  * ColorHugALS    |      ×       |      ×
1440  *
1441  * Since: 1.3.1
1442  **/
1443 #define	CH_CMD_CLEAR_ERROR			0x61
1444 
1445 /**
1446  * CH_CMD_SET_CRYPTO_KEY:
1447  *
1448  * Sets the 128 bit encyption key for the device.
1449  *
1450  * PROTOCOLv2:
1451  * bRequest:   [cmd]
1452  * wValue:     0x00
1453  * wIndex:     interface
1454  * wLength:    0x00
1455  * Direction:  DEVICE->HOST
1456  * Data:       [4:key0][4:key1][4:key2][4:key3]
1457  *
1458  * This command is available under these conditions:
1459  *
1460  *                |  Bootloader  |  Firmware
1461  * ---------------+--------------+-----------
1462  * ColorHug       |      ×       |      ×
1463  * ColorHug2      |      ×       |      ×
1464  * ColorHug+      |      ×       |      ✓
1465  * ColorHugALS    |      ×       |      ×
1466  *
1467  * Since: 1.3.1
1468  **/
1469 #define	CH_CMD_SET_CRYPTO_KEY			0x70
1470 
1471 /* the values here are not really API */
1472 #define	CH_EP0_TRANSFER_SIZE			64
1473 #define	CH_EP0_TRANSFER_SIZE_V2			0x400	/* since 1.3.4 */
1474 
1475 /* secret code */
1476 #define	CH_WRITE_EEPROM_MAGIC			"Un1c0rn2"
1477 #define	CH_FIRMWARE_ID_TOKEN1			"40338ceb"
1478 #define	CH_FIRMWARE_ID_TOKEN2			"2082b5e0"
1479 #define	CH_FIRMWARE_ID_TOKEN_ALS		"84f40464"	/* since 1.2.9 */
1480 #define	CH_FIRMWARE_ID_TOKEN_PLUS		"6d6f05a9"
1481 
1482 #define CH_DEVICE_GUID_COLORHUG			"40338ceb-b966-4eae-adae-9c32edfcc484"	/* since 1.2.9 */
1483 #define CH_DEVICE_GUID_COLORHUG2		"2082b5e0-7a64-478a-b1b2-e3404fab6dad"	/* since 1.2.9 */
1484 #define CH_DEVICE_GUID_COLORHUG_ALS		"84f40464-9272-4ef7-9399-cd95f12da696"	/* since 1.2.9 */
1485 #define CH_DEVICE_GUID_COLORHUG_PLUS		"6d6f05a9-3ecb-43a2-bcbb-3844f1825366"	/* since 1.2.9 */
1486 
1487 /* input and output buffer offsets */
1488 #define	CH_BUFFER_INPUT_CMD			0x00
1489 #define	CH_BUFFER_INPUT_DATA			0x01
1490 #define	CH_BUFFER_OUTPUT_RETVAL			0x00
1491 #define	CH_BUFFER_OUTPUT_CMD			0x01
1492 #define	CH_BUFFER_OUTPUT_DATA			0x02
1493 
1494 /* where the custom firmware is stored */
1495 #define CH_EEPROM_ADDR_RUNCODE			0x4000
1496 #define CH_EEPROM_ADDR_RUNCODE_ALS		0x2000		/* since 1.2.9 */
1497 
1498 /* the number of useful samples from the the CCD */
1499 #define CH_CCD_SPECTRAL_RESOLUTION		1024
1500 
1501 /* although each calibration can be stored in 60 bytes,
1502  * we use a full 64 byte block */
1503 #define	CH_CALIBRATION_MAX			64	/* so finishes at device params */
1504 #define	CH_CALIBRATION_SPECTRAL			0xffff
1505 #define	CH_CALIBRATION_DESCRIPTION_LEN		23	/* 60 - (9*4) - 1 */
1506 
1507 /* the supported calibration types bitfield */
1508 #define	CH_CALIBRATION_TYPE_LCD			0x01
1509 #define	CH_CALIBRATION_TYPE_CRT			0x02
1510 #define	CH_CALIBRATION_TYPE_PROJECTOR		0x04
1511 #define	CH_CALIBRATION_TYPE_LED			0x08
1512 #define	CH_CALIBRATION_TYPE_ALL			0xff
1513 
1514 /* approximate sample times */
1515 #define CH_INTEGRAL_TIME_VALUE_5MS		0x0300
1516 #define CH_INTEGRAL_TIME_VALUE_50MS		0x1f00
1517 #define CH_INTEGRAL_TIME_VALUE_100MS		0x3a00
1518 #define CH_INTEGRAL_TIME_VALUE_200MS		0x7500
1519 #define CH_INTEGRAL_TIME_VALUE_MAX		0xffff
1520 
1521 /* flash constants */
1522 #define	CH_FLASH_ERASE_BLOCK_SIZE		0x400	/* 1024 */
1523 #define	CH_FLASH_WRITE_BLOCK_SIZE		0x040	/* 64 */
1524 #define	CH_FLASH_TRANSFER_BLOCK_SIZE		0x020	/* 32 */
1525 #define	CH_FLASH_RECONNECT_TIMEOUT		5000	/* ms */
1526 
1527 /* calibration remapping contants */
1528 #define	CH_CALIBRATION_INDEX_FACTORY_ONLY	0x00
1529 #define	CH_CALIBRATION_INDEX_LCD		(CH_CALIBRATION_MAX + 0)
1530 #define	CH_CALIBRATION_INDEX_CRT		(CH_CALIBRATION_MAX + 1)
1531 #define	CH_CALIBRATION_INDEX_PROJECTOR		(CH_CALIBRATION_MAX + 2)
1532 #define	CH_CALIBRATION_INDEX_LED		(CH_CALIBRATION_MAX + 3)
1533 #define	CH_CALIBRATION_INDEX_MAX		0x06
1534 
1535 /* which color to select */
1536 typedef enum {
1537 	CH_COLOR_SELECT_RED,
1538 	CH_COLOR_SELECT_WHITE,
1539 	CH_COLOR_SELECT_BLUE,
1540 	CH_COLOR_SELECT_GREEN
1541 } ChColorSelect;
1542 
1543 /* Led colors: possible bitfield values */
1544 typedef enum {
1545 	CH_STATUS_LED_GREEN	= 1 << 0,
1546 	CH_STATUS_LED_RED	= 1 << 1,
1547 	CH_STATUS_LED_BLUE	= 1 << 2	/* Since: 0.1.29 */
1548 } ChStatusLed;
1549 
1550 /* Illuminants: possible bitfield values */
1551 typedef enum {
1552 	CH_ILLUMINANT_NONE	= 0,		/* Since: 1.3.4 */
1553 	CH_ILLUMINANT_A		= 1 << 0,	/* Since: 1.3.4 */
1554 	CH_ILLUMINANT_UV	= 1 << 1,	/* Since: 1.3.4 */
1555 	/*< private >*/
1556 	CH_ILLUMINANT_LAST
1557 } ChIlluminant;
1558 
1559 /* what frequency divider to use */
1560 typedef enum {
1561 	CH_FREQ_SCALE_0,
1562 	CH_FREQ_SCALE_20,
1563 	CH_FREQ_SCALE_2,
1564 	CH_FREQ_SCALE_100
1565 } ChFreqScale;
1566 
1567 /* fatal error morse code */
1568 typedef enum {
1569 	CH_ERROR_NONE,
1570 	CH_ERROR_UNKNOWN_CMD,
1571 	CH_ERROR_WRONG_UNLOCK_CODE,
1572 	CH_ERROR_NOT_IMPLEMENTED,
1573 	CH_ERROR_UNDERFLOW_SENSOR,
1574 	CH_ERROR_NO_SERIAL,
1575 	CH_ERROR_WATCHDOG,
1576 	CH_ERROR_INVALID_ADDRESS,
1577 	CH_ERROR_INVALID_LENGTH,
1578 	CH_ERROR_INVALID_CHECKSUM,
1579 	CH_ERROR_INVALID_VALUE,
1580 	CH_ERROR_UNKNOWN_CMD_FOR_BOOTLOADER,
1581 	CH_ERROR_NO_CALIBRATION,
1582 	CH_ERROR_OVERFLOW_MULTIPLY,
1583 	CH_ERROR_OVERFLOW_ADDITION,
1584 	CH_ERROR_OVERFLOW_SENSOR,
1585 	CH_ERROR_OVERFLOW_STACK,
1586 	CH_ERROR_DEVICE_DEACTIVATED,
1587 	CH_ERROR_INCOMPLETE_REQUEST,
1588 	CH_ERROR_SELF_TEST_SENSOR,
1589 	CH_ERROR_SELF_TEST_RED,
1590 	CH_ERROR_SELF_TEST_GREEN,
1591 	CH_ERROR_SELF_TEST_BLUE,
1592 	CH_ERROR_SELF_TEST_COLOR_SELECT,
1593 	CH_ERROR_SELF_TEST_MULTIPLIER,
1594 	CH_ERROR_INVALID_CALIBRATION,
1595 	CH_ERROR_SRAM_FAILED,
1596 	CH_ERROR_OUT_OF_MEMORY,
1597 	CH_ERROR_SELF_TEST_TEMPERATURE,
1598 	CH_ERROR_SELF_TEST_I2C,
1599 	CH_ERROR_SELF_TEST_ADC_VDD,
1600 	CH_ERROR_SELF_TEST_ADC_VSS,
1601 	CH_ERROR_SELF_TEST_ADC_VREF,
1602 	CH_ERROR_I2C_SLAVE_ADDRESS,
1603 	CH_ERROR_I2C_SLAVE_CONFIG,
1604 	CH_ERROR_SELF_TEST_EEPROM,	/* since 1.2.9 */
1605 	/*< private >*/
1606 	CH_ERROR_LAST
1607 } ChError;
1608 
1609 /* the measure mode */
1610 typedef enum {
1611 	CH_MEASURE_MODE_FREQUENCY,
1612 	CH_MEASURE_MODE_DURATION
1613 } ChMeasureMode;
1614 
1615 /* any problems with the PCB */
1616 typedef enum {
1617 	CH_PCB_ERRATA_NONE		= 0,
1618 	CH_PCB_ERRATA_SWAPPED_LEDS	= 1 << 0,
1619 	CH_PCB_ERRATA_NO_WELCOME	= 1 << 1,
1620 	/*< private >*/
1621 	CH_PCB_ERRATA_LAST		= 1 << 2
1622 } ChPcbErrata;
1623 
1624 typedef enum {
1625 	CH_DEVICE_MODE_UNKNOWN,
1626 	CH_DEVICE_MODE_LEGACY,
1627 	CH_DEVICE_MODE_BOOTLOADER,
1628 	CH_DEVICE_MODE_FIRMWARE,
1629 	CH_DEVICE_MODE_BOOTLOADER_PLUS,
1630 	CH_DEVICE_MODE_FIRMWARE_PLUS,
1631 	CH_DEVICE_MODE_FIRMWARE2,	/* since 1.2.2 */
1632 	CH_DEVICE_MODE_BOOTLOADER2,	/* since 1.2.3 */
1633 	CH_DEVICE_MODE_BOOTLOADER_ALS,	/* since 1.2.9 */
1634 	CH_DEVICE_MODE_FIRMWARE_ALS,	/* since 1.2.9 */
1635 	/*< private >*/
1636 	CH_DEVICE_MODE_LAST
1637 } ChDeviceMode;
1638 
1639 typedef enum {
1640 	CH_SPECTRUM_KIND_RAW		= 0x00,	/* since 1.3.4 */
1641 	CH_SPECTRUM_KIND_DARK_CAL	= 0x01,	/* since 1.3.4 */
1642 	CH_SPECTRUM_KIND_TEMP_CAL	= 0x02,	/* since 1.3.4 */
1643 	CH_SPECTRUM_KIND_IRRADIANCE_CAL	= 0x03,	/* since 1.3.4 */
1644 	CH_SPECTRUM_KIND_LAST
1645 } ChSpectrumKind;
1646 
1647 typedef guint8 ChCmd;
1648 
1649 /* prototypes */
1650 const gchar	*ch_strerror			(ChError	 error_enum);
1651 const gchar	*ch_command_to_string		(ChCmd		 cmd);
1652 const gchar	*ch_multiplier_to_string	(ChFreqScale	 multiplier);
1653 const gchar	*ch_color_select_to_string	(ChColorSelect	 color_select);
1654 const gchar	*ch_measure_mode_to_string	(ChMeasureMode	 measure_mode);
1655 const gchar	*ch_device_mode_to_string	(ChDeviceMode	 device_mode);
1656 ChDeviceMode	 ch_device_mode_from_firmware	(const guint8	*data,
1657 						 gsize		 data_len);
1658 
1659 G_END_DECLS
1660 
1661 #endif
1662