~ubuntu-branches/ubuntu/quantal/colord/quantal-proposed

« back to all changes in this revision

Viewing changes to src/sensors/cd-sensor-colorhug-private.h

  • Committer: Package Import Robot
  • Author(s): Christopher James Halse Rogers
  • Date: 2012-03-01 17:33:00 UTC
  • mto: (1.1.4) (2.1.7 sid)
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: package-import@ubuntu.com-20120301173300-q1s2bs8yubnybln8
ImportĀ upstreamĀ versionĀ 0.1.18

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2
2
 *
3
 
 * Copyright (C) 2011 Richard Hughes <richard@hughsie.com>
 
3
 * Copyright (C) 2011-2012 Richard Hughes <richard@hughsie.com>
4
4
 *
5
5
 * Licensed under the GNU General Public License Version 2
6
6
 *
35
35
#define CH_USB_HID_EP_OUT                       (CH_USB_HID_EP | 0x00)
36
36
#define CH_USB_HID_EP_SIZE                      64
37
37
 
 
38
/* the default timeout in client tools */
 
39
#define CH_DEVICE_USB_TIMEOUT                   5000 /* ms */
 
40
 
 
41
/* constants for ownership tags */
 
42
#define CH_OWNER_LENGTH_MAX                     60
 
43
 
38
44
/**
39
45
 * CH_CMD_GET_COLOR_SELECT:
40
46
 *
42
48
 *
43
49
 * IN:  [1:cmd]
44
50
 * OUT: [1:retval][1:cmd][1:color_select]
 
51
 *
 
52
 * This command is only available in firmware mode.
45
53
 **/
46
54
#define CH_CMD_GET_COLOR_SELECT                 0x01
47
55
 
52
60
 *
53
61
 * IN:  [1:cmd][1:color_select]
54
62
 * OUT: [1:retval][1:cmd]
 
63
 *
 
64
 * This command is only available in firmware mode.
55
65
 **/
56
66
#define CH_CMD_SET_COLOR_SELECT                 0x02
57
67
 
62
72
 *
63
73
 * IN:  [1:cmd]
64
74
 * OUT: [1:retval][1:cmd][1:multiplier_value]
 
75
 *
 
76
 * This command is only available in firmware mode.
65
77
 **/
66
78
#define CH_CMD_GET_MULTIPLIER                   0x03
67
79
 
72
84
 *
73
85
 * IN:  [1:cmd][1:multiplier_value]
74
86
 * OUT: [1:retval][1:cmd]
 
87
 *
 
88
 * This command is only available in firmware mode.
75
89
 **/
76
90
#define CH_CMD_SET_MULTIPLIER                   0x04
77
91
 
82
96
 *
83
97
 * IN:  [1:cmd]
84
98
 * OUT: [1:retval][1:cmd][2:integral_time]
 
99
 *
 
100
 * This command is only available in firmware mode.
85
101
 **/
86
102
#define CH_CMD_GET_INTEGRAL_TIME                0x05
87
103
 
92
108
 *
93
109
 * IN:  [1:cmd][2:integral_time]
94
110
 * OUT: [1:retval][1:cmd]
 
111
 *
 
112
 * This command is only available in firmware mode.
95
113
 **/
96
114
#define CH_CMD_SET_INTEGRAL_TIME                0x06
97
115
 
102
120
 *
103
121
 * IN:  [1:cmd]
104
122
 * OUT: [1:retval][1:cmd][2:major][2:minor][2:micro]
 
123
 *
 
124
 * This command is available in bootloader and firmware mode.
105
125
 **/
106
126
#define CH_CMD_GET_FIRMWARE_VERSION             0x07
107
127
 
108
128
/**
109
129
 * CH_CMD_GET_CALIBRATION:
110
130
 *
111
 
 * Gets the calibration matrix. The description does not have to be NULL terminated.
 
131
 * Gets the calibration matrix. The description does not have to be NULL
 
132
 * terminated.
 
133
 *
 
134
 * @types is a bitmask which corresponds to:
 
135
 *
 
136
 * bit:
 
137
 *  0     Can be used with LCD panels
 
138
 *  1     Can be used with CRT monitors
 
139
 *  2     Can be used with projectors
 
140
 *  3     Can be used with LED panels
 
141
 *  4-7   Reserved for future use
112
142
 *
113
143
 * IN:  [1:cmd][2:index]
114
 
 * OUT: [1:retval][1:cmd][2*9:matrix_value][24:description]
 
144
 * OUT: [1:retval][1:cmd][2*9:matrix_value][1:types][23:description]
 
145
 *
 
146
 * This command is only available in firmware mode.
115
147
 **/
116
148
#define CH_CMD_GET_CALIBRATION                  0x09
117
149
 
118
150
/**
119
151
 * CH_CMD_SET_CALIBRATION:
120
152
 *
121
 
 * Sets the calibration matrix. The @matrix_value parameter is a 16 bit
122
 
 * _signed_ value that scales from -1.0 to +1.0.
 
153
 * Sets the calibration matrix.
123
154
 *
124
 
 * IN:  [1:cmd][2:index][4*9:matrix_value][24:description]
 
155
 * IN:  [1:cmd][2:index][4*9:matrix_value][1:types][23:description]
125
156
 * OUT: [1:retval][1:cmd]
 
157
 *
 
158
 * This command is only available in firmware mode.
126
159
 **/
127
160
#define CH_CMD_SET_CALIBRATION                  0x0a
128
161
 
133
166
 *
134
167
 * IN:  [1:cmd]
135
168
 * OUT: [1:retval][1:cmd][4:serial_number]
 
169
 *
 
170
 * This command is only available in firmware mode.
136
171
 **/
137
172
#define CH_CMD_GET_SERIAL_NUMBER                0x0b
138
173
 
143
178
 *
144
179
 * IN:  [1:cmd][4:serial_number]
145
180
 * OUT: [1:retval][1:cmd]
 
181
 *
 
182
 * This command is only available in firmware mode.
146
183
 **/
147
184
#define CH_CMD_SET_SERIAL_NUMBER                0x0c
148
185
 
153
190
 *
154
191
 * IN:  [1:cmd]
155
192
 * OUT: [1:retval][1:cmd][1:led_state]
 
193
 *
 
194
 * This command is only available in firmware mode.
156
195
 **/
157
196
#define CH_CMD_GET_LEDS                         0x0d
158
197
 
167
206
 *
168
207
 * IN:  [1:cmd][1:led_state][1:repeat][1:on-time][1:off-time]
169
208
 * OUT: [1:retval][1:cmd]
 
209
 *
 
210
 * This command is only available in firmware mode.
170
211
 **/
171
212
#define CH_CMD_SET_LEDS                         0x0e
172
213
 
177
218
 *
178
219
 * IN:  [1:cmd]
179
220
 * OUT: [1:retval][1:cmd][2:red][2:green][2:blue]
 
221
 *
 
222
 * This command is only available in firmware mode.
180
223
 **/
181
224
#define CH_CMD_GET_DARK_OFFSETS                 0x0f
182
225
 
187
230
 *
188
231
 * IN:  [1:cmd][2:red][2:green][2:blue]
189
232
 * OUT: [1:retval][1:cmd]
 
233
 *
 
234
 * This command is only available in firmware mode.
190
235
 **/
191
236
#define CH_CMD_SET_DARK_OFFSETS                 0x10
192
237
 
193
238
/**
 
239
 * CH_CMD_GET_OWNER_NAME:
 
240
 *
 
241
 * Get User's Name
 
242
 *
 
243
 * IN:  [1:cmd]
 
244
 * OUT: [1:retval][1:cmd][60:owner-name]
 
245
 *
 
246
 * This command is only available in firmware mode.
 
247
 **/
 
248
#define CH_CMD_GET_OWNER_NAME                   0x11
 
249
 
 
250
/**
 
251
 * CH_CMD_SET_OWNER_NAME:
 
252
 *
 
253
 * Set User's Name
 
254
 *
 
255
 * IN:  [1:cmd][60:owner-name]
 
256
 * OUT: [1:retval][1:cmd]
 
257
 *
 
258
 * This command is only available in firmware mode.
 
259
 **/
 
260
#define CH_CMD_SET_OWNER_NAME                   0x12
 
261
 
 
262
/**
 
263
 * CH_CMD_GET_OWNER_EMAIL:
 
264
 *
 
265
 * Get User's Email Address
 
266
 *
 
267
 * IN:  [1:cmd]
 
268
 * OUT: [1:retval][1:cmd][60:owner-email]
 
269
 *
 
270
 * This command is only available in firmware mode.
 
271
 **/
 
272
#define CH_CMD_GET_OWNER_EMAIL                  0x13
 
273
 
 
274
/**
 
275
 * CH_CMD_SET_OWNER_NAME:
 
276
 *
 
277
 * Set User's Email Address
 
278
 *
 
279
 * IN:  [1:cmd][60:owner-email]
 
280
 * OUT: [1:retval][1:cmd]
 
281
 *
 
282
 * This command is only available in firmware mode.
 
283
 **/
 
284
#define CH_CMD_SET_OWNER_EMAIL                  0x14
 
285
 
 
286
/**
194
287
 * CH_CMD_WRITE_EEPROM:
195
288
 *
196
289
 * Write values to EEPROM.
197
290
 *
198
291
 * IN:  [1:cmd][8:eeprom_magic]
199
292
 * OUT: [1:retval][1:cmd]
 
293
 *
 
294
 * This command is only available in firmware mode.
200
295
 **/
201
296
#define CH_CMD_WRITE_EEPROM                     0x20
202
297
 
207
302
 *
208
303
 * IN:  [1:cmd]
209
304
 * OUT: [1:retval][1:cmd][2:count]
 
305
 *
 
306
 * This command is only available in firmware mode.
210
307
 **/
211
308
#define CH_CMD_TAKE_READING_RAW                 0x21
212
309
 
220
317
 *
221
318
 * IN:  [1:cmd]
222
319
 * OUT: [1:retval][1:cmd][2:red][2:green][2:blue]
 
320
 *
 
321
 * This command is only available in firmware mode.
223
322
 **/
224
323
#define CH_CMD_TAKE_READINGS                    0x22
225
324
 
234
333
 * map is used to find the default calibration index to use.
235
334
 *
236
335
 * IN:  [1:cmd][2:calibration-index]
237
 
 * OUT: [1:retval][1:cmd][2:red][2:green][2:blue]
 
336
 * OUT: [1:retval][1:cmd][4:red][4:green][4:blue]
 
337
 *
 
338
 * This command is only available in firmware mode.
238
339
 **/
239
340
#define CH_CMD_TAKE_READING_XYZ                 0x23
240
341
 
245
346
 *
246
347
 * IN:  [1:cmd]
247
348
 * OUT: [1:retval][1:cmd] (but with success the device will disconnect)
 
349
 *
 
350
 * This command is available in bootloader and firmware mode.
248
351
 **/
249
352
#define CH_CMD_RESET                            0x24
250
353
 
255
358
 *
256
359
 * IN:  [1:cmd][2:address][1:length]
257
360
 * OUT: [1:retval][1:cmd][1:checksum][1-60:data]
 
361
 *
 
362
 * This command is only available in bootloader mode.
258
363
 **/
259
364
#define CH_CMD_READ_FLASH                       0x25
260
365
 
267
372
 *
268
373
 * IN:  [1:cmd][2:address][2:length]
269
374
 * OUT: [1:retval][1:cmd]
 
375
 *
 
376
 * This command is only available in bootloader mode.
270
377
 **/
271
378
#define CH_CMD_ERASE_FLASH                      0x29
272
379
 
278
385
 *
279
386
 * IN:  [1:cmd][2:address][1:length][1:checksum][1-32:data]
280
387
 * OUT: [1:retval][1:cmd]
 
388
 *
 
389
 * This command is only available in bootloader mode.
281
390
 **/
282
391
#define CH_CMD_WRITE_FLASH                      0x26
283
392
 
288
397
 *
289
398
 * IN:  [1:cmd]
290
399
 * OUT: [1:retval][1:cmd]
 
400
 *
 
401
 * This command is only available in bootloader mode.
291
402
 **/
292
403
#define CH_CMD_BOOT_FLASH                       0x27
293
404
 
311
422
 *
312
423
 * IN:  [1:cmd][1:success]
313
424
 * OUT: [1:retval][1:cmd]
 
425
 *
 
426
 * This command is available in bootloader and firmware mode, although
 
427
 * different values of @success are permitted in each.
314
428
 **/
315
429
#define CH_CMD_SET_FLASH_SUCCESS                0x28
316
430
 
321
435
 *
322
436
 * IN:  [1:cmd]
323
437
 * OUT: [1:retval][1:cmd][2:scale]
 
438
 *
 
439
 * This command is only available in firmware mode.
324
440
 **/
325
441
#define CH_CMD_GET_PRE_SCALE                    0x2c
326
442
 
331
447
 *
332
448
 * IN:  [1:cmd][2:scale]
333
449
 * OUT: [1:retval][1:cmd]
 
450
 *
 
451
 * This command is only available in firmware mode.
334
452
 **/
335
453
#define CH_CMD_SET_PRE_SCALE                    0x2d
336
454
 
341
459
 *
342
460
 * IN:  [1:cmd]
343
461
 * OUT: [1:retval][1:cmd][2:scale]
 
462
 *
 
463
 * This command is only available in firmware mode.
344
464
 **/
345
465
#define CH_CMD_GET_POST_SCALE                   0x2a
346
466
 
351
471
 *
352
472
 * IN:  [1:cmd][2:scale]
353
473
 * OUT: [1:retval][1:cmd]
 
474
 *
 
475
 * This command is only available in firmware mode.
354
476
 **/
355
477
#define CH_CMD_SET_POST_SCALE                   0x2b
356
478
 
364
486
 * LCD          = 0
365
487
 * CRT          = 1
366
488
 * Projector    = 2
367
 
 * Custom1      = 3
368
 
 * Custom2      = 4
369
 
 * Custom3      = 5
 
489
 * LED          = 3
 
490
 * Custom1      = 4
 
491
 * Custom2      = 5
370
492
 *
371
493
 * In the future CustomX may be renamed to another display technology,
372
 
 * e.g. LED or e-ink.
 
494
 * e.g. e-ink.
373
495
 *
374
496
 * IN:  [1:cmd]
375
497
 * OUT: [1:retval][1:cmd][6*2:types]
 
498
 *
 
499
 * This command is only available in firmware mode.
376
500
 **/
377
501
#define CH_CMD_GET_CALIBRATION_MAP              0x2e
378
502
 
383
507
 *
384
508
 * IN:  [1:cmd][6*2:types]
385
509
 * OUT: [1:retval][1:cmd]
 
510
 *
 
511
 * This command is only available in firmware mode.
386
512
 **/
387
513
#define CH_CMD_SET_CALIBRATION_MAP              0x2f
388
514
 
 
515
/**
 
516
 * CH_CMD_GET_HARDWARE_VERSION:
 
517
 *
 
518
 * Get the hardware version.
 
519
 *
 
520
 * The hardware versions are as follows:
 
521
 * 0x00         = Pre-production hardware
 
522
 * 0x01         = First generation hardware
 
523
 * 0x02-0x0f    = Reserved for future use
 
524
 *
 
525
 * IN:  [1:cmd]
 
526
 * OUT: [1:retval][1:cmd][1:hw_version]
 
527
 *
 
528
 * This command is available in bootloader and firmware mode.
 
529
 **/
 
530
#define CH_CMD_GET_HARDWARE_VERSION             0x30
 
531
 
 
532
/**
 
533
 * CH_CMD_TAKE_READING_ARRAY:
 
534
 *
 
535
 * Takes 30 raw samples and returns them in an array.
 
536
 *
 
537
 * This command can be used to find the optimum delay between patches
 
538
 * by showing a black sample area, then white, and then using this
 
539
 * command to find out how long the actual hardware delay is.
 
540
 *
 
541
 * It can also be used to find out how stable the device or output is
 
542
 * over a small amount of time, typically ~2.5 seconds for the maximum
 
543
 * integral time.
 
544
 *
 
545
 * IN:  [1:cmd]
 
546
 * OUT: [1:retval][1:cmd][30:reading_array]
 
547
 *
 
548
 * This command is available in firmware mode.
 
549
 **/
 
550
#define CH_CMD_TAKE_READING_ARRAY               0x31
 
551
 
 
552
/**
 
553
 * CH_CMD_SET_PCB_ERRATA:
 
554
 *
 
555
 * Sets the board errata value. Board errata is used to correct swapped
 
556
 * LEDs and any future problems discovered that only affect some batches
 
557
 * of hardware version 1.
 
558
 *
 
559
 * The errata bitmask is as follows:
 
560
 * 0x00         = No errata for this PCB
 
561
 * 0x01         = Leds are swapped
 
562
 * 0x02-0xffff  = Reserved for future use
 
563
 *
 
564
 * IN:  [1:cmd][2:pcb_errata]
 
565
 * OUT: [1:retval][1:cmd]
 
566
 *
 
567
 * This command is available in firmware mode.
 
568
 **/
 
569
#define CH_CMD_SET_PCB_ERRATA                   0x32
 
570
 
 
571
/**
 
572
 * CH_CMD_GET_PCB_ERRATA:
 
573
 *
 
574
 * Gets the board errata value.
 
575
 *
 
576
 * IN:  [1:cmd]
 
577
 * OUT: [1:retval][1:cmd][2:pcb_errata]
 
578
 *
 
579
 * This command is available in firmware mode.
 
580
 **/
 
581
#define CH_CMD_GET_PCB_ERRATA                   0x33
 
582
 
389
583
/* secret code */
390
584
#define CH_WRITE_EEPROM_MAGIC                   "Un1c0rn2"
391
585
 
402
596
/* although each calibration can be stored in 60 bytes,
403
597
 * we use a full 64 byte block */
404
598
#define CH_CALIBRATION_MAX                      64      /* so finishes at device params */
 
599
#define CH_CALIBRATION_DESCRIPTION_LEN          23      /* 60 - (9*4) - 1 */
 
600
 
 
601
/* the supported calibration types bitfield */
 
602
#define CH_CALIBRATION_TYPE_LCD                 0x01
 
603
#define CH_CALIBRATION_TYPE_CRT                 0x02
 
604
#define CH_CALIBRATION_TYPE_PROJECTOR           0x04
 
605
#define CH_CALIBRATION_TYPE_LED                 0x08
 
606
#define CH_CALIBRATION_TYPE_ALL                 0xff
405
607
 
406
608
/* approximate sample times */
407
609
#define CH_INTEGRAL_TIME_VALUE_5MS              0x0300
414
616
#define CH_FLASH_ERASE_BLOCK_SIZE               0x400   /* 1024 */
415
617
#define CH_FLASH_WRITE_BLOCK_SIZE               0x040   /* 64 */
416
618
#define CH_FLASH_TRANSFER_BLOCK_SIZE            0x020   /* 32 */
 
619
#define CH_FLASH_RECONNECT_TIMEOUT              2500    /* ms */
417
620
 
418
621
/* calibration remapping contants */
419
622
#define CH_CALIBRATION_INDEX_LCD                (CH_CALIBRATION_MAX + 0)
420
623
#define CH_CALIBRATION_INDEX_CRT                (CH_CALIBRATION_MAX + 1)
421
624
#define CH_CALIBRATION_INDEX_PROJECTOR          (CH_CALIBRATION_MAX + 2)
 
625
#define CH_CALIBRATION_INDEX_LED                (CH_CALIBRATION_MAX + 3)
422
626
 
423
627
/* which color to select */
424
628
typedef enum {
428
632
        CH_COLOR_SELECT_GREEN
429
633
} ChColorSelect;
430
634
 
 
635
/* Led colors: possible bitfield values */
 
636
typedef enum {
 
637
        CH_STATUS_LED_GREEN     = 1 << 0,
 
638
        CH_STATUS_LED_RED       = 1 << 1
 
639
} ChStatusLed;
 
640
 
431
641
/* what frequency divider to use */
432
642
typedef enum {
433
643
        CH_FREQ_SCALE_0,
455
665
        CH_ERROR_OVERFLOW_ADDITION,
456
666
        CH_ERROR_OVERFLOW_SENSOR,
457
667
        CH_ERROR_OVERFLOW_STACK,
 
668
        CH_ERROR_DEVICE_DEACTIVATED,
 
669
        CH_ERROR_INCOMPLETE_REQUEST,
458
670
        CH_ERROR_LAST
459
671
} ChError;
460
672
 
 
673
/* any problems with the PCB */
 
674
typedef enum {
 
675
        CH_PCB_ERRATA_NONE              = 0,
 
676
        CH_PCB_ERRATA_SWAPPED_LEDS      = 1 << 0,
 
677
        CH_PCB_ERRATA_LAST              = 1 << 1
 
678
} ChPcbErrata;
 
679
 
461
680
/* prototypes */
462
681
const gchar     *ch_strerror                    (ChError         error_enum);
463
682
const gchar     *ch_command_to_string           (guint8          cmd);