-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcr_cmd.c
579 lines (469 loc) · 14.5 KB
/
lcr_cmd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
/*****************************************************************************
** TEXAS INSTRUMENTS PROPRIETARY INFORMATION
**
** (c) Copyright, Texas Instruments Incorporated, 2012-2013.
** All Rights Reserved.
**
** Property of Texas Instruments Incorporated. Restricted Rights -
** Use, duplication, or disclosure is subject to restrictions set
** forth in TI's program license agreement and associated documentation.
******************************************************************************/
/**
*
* @file lcr_cmd.c
*
* @brief This file contatins DM365 Command Interfaces implementation.
* As per the command definition the the command packets will be
* created.
**/
/*****************************************************************************/
#include "common.h"
#include "error.h"
#include "lcr_packetizer.h"
#include "lcr_cmd.h"
/* Connects to the DLP LightCrafter(TM) Hardware */
ErrorCode_t LCR_CMD_Open(void)
{
/* Open tcp connection with LCr */
return LCR_CMD_PKT_ConnectToLCR();
}
/*Close the TCP Connection*/
ErrorCode_t LCR_CMD_Close(void)
{
LCR_CMD_PKT_DisconnectLCR();
return SUCCESS;
}
/* Read revision of MSP430, DM365 and FPGA */
ErrorCode_t LCR_CMD_GetRevision(LCR_Revision_t Which, char *VersionStr)
{
//Frame the packet
LCR_CMD_PKT_CommandInit(LCR_CMD_PKT_TYPE_READ, 0x0100);
if(Which != REV_DM365 && Which != REV_FPGA && Which != REV_MSP430)
{
return FAIL;
}
LCR_CMD_PKT_PutInt(Which,1);
if(LCR_CMD_PKT_SendCommand())
return FAIL;
LCR_CMD_PKT_GetData((uint8*)VersionStr,LCR_CMD_VERSION_STR_LEN);
return SUCCESS;
}
/* Change the Display Mode */
ErrorCode_t LCR_CMD_SetDisplayMode(LCR_DisplayMode_t Mode)
{
if(Mode > DISP_MODE_PTN_SEQ)
return FAIL;
/* Generate packet */
LCR_CMD_PKT_CommandInit(LCR_CMD_PKT_TYPE_WRITE, 0x0101);
LCR_CMD_PKT_PutInt((int)Mode,1);
if(LCR_CMD_PKT_SendCommand())
return FAIL;
return SUCCESS;
}
/* Returns the Display Mode */
LCR_DisplayMode_t LCR_CMD_GetDisplayMode(void)
{
uint8 data;
/* Read display mode */
LCR_CMD_PKT_CommandInit(LCR_CMD_PKT_TYPE_READ, 0x0101);
LCR_CMD_PKT_SendCommand();
LCR_CMD_PKT_GetData((uint8*)&data,1);
return (LCR_DisplayMode_t)data;
}
/* Change the Power Mode from/to STANDBY or NORMAL */
ErrorCode_t LCR_CMD_SetPowerMode(LCR_PowerMode_t Mode)
{
//TBD
return SUCCESS;
}
/* Read the current system power mode */
LCR_PowerMode_t LCR_CMD_GetPowerMode(void)
{
uint8 data = 0;
//TBD
return (LCR_PowerMode_t) data;
}
/* Set the Tespattern as defined in LCR_TestPattern_t list */
ErrorCode_t LCR_CMD_SetTestPattern(LCR_TestPattern_t TestPtn)
{
if(TestPtn > TEST_PTN_ANXI_CHECKER)
return FAIL;
/* Generate packet */
LCR_CMD_PKT_CommandInit(LCR_CMD_PKT_TYPE_WRITE, 0x0103);
LCR_CMD_PKT_PutInt((int)TestPtn,1);
if(LCR_CMD_PKT_SendCommand())
return FAIL;
return SUCCESS;
}
/* Returned set test pattern */
LCR_TestPattern_t LCR_CMD_GetTestPattern(void)
{
uint8 data;
/* Read Test Pattern set */
LCR_CMD_PKT_CommandInit(LCR_CMD_PKT_TYPE_READ, 0x0103);
LCR_CMD_PKT_SendCommand();
LCR_CMD_PKT_GetData((uint8*)&data,1);
return (LCR_TestPattern_t)data;
}
/* Set the R,G,B LED current */
ErrorCode_t LCR_CMD_SetLEDCurrent(LCR_LEDCurrent_t *LEDSetting)
{
/* Write LED current */
LCR_CMD_PKT_CommandInit(LCR_CMD_PKT_TYPE_WRITE, 0x0104);
LCR_CMD_PKT_PutInt(LEDSetting->Red, 2);
LCR_CMD_PKT_PutInt(LEDSetting->Green, 2);
LCR_CMD_PKT_PutInt(LEDSetting->Blue, 2);
if(LCR_CMD_PKT_SendCommand())
return FAIL;
return SUCCESS;
}
/* Read the R,G,B LED current */
ErrorCode_t LCR_CMD_GetLEDCurrent(LCR_LEDCurrent_t *LEDSetting)
{
/* Read LED current */
LCR_CMD_PKT_CommandInit(LCR_CMD_PKT_TYPE_READ, 0x0104);
LCR_CMD_PKT_SendCommand();
LEDSetting->Red = LCR_CMD_PKT_GetInt(2);
LEDSetting->Green = LCR_CMD_PKT_GetInt(2);
LEDSetting->Blue = LCR_CMD_PKT_GetInt(2);
return SUCCESS;
}
/* Download a 24bpp .BMP image */
ErrorCode_t LCR_CMD_DisplayStaticImage(char const *fileNameWithPath)
{
/* Generate packet */
LCR_CMD_PKT_CommandInit(LCR_CMD_PKT_TYPE_WRITE, 0x0105);
/*TBD - Check for return error*/
LCR_CMD_PKT_PutFile(fileNameWithPath);
if(LCR_CMD_PKT_SendCommand())
return FAIL;
return SUCCESS;
}
/* Displays solid filed color image */
ErrorCode_t LCR_CMD_DisplayStaticColor(uint32 Color)
{
/* Generate packet */
LCR_CMD_PKT_CommandInit(LCR_CMD_PKT_TYPE_WRITE, 0x0106);
LCR_CMD_PKT_PutInt((uint32)Color,4);
if(LCR_CMD_PKT_SendCommand())
return FAIL;
return SUCCESS;
}
/* Configures the displayed image on the DMD*/
ErrorCode_t LCR_CMD_SetDisplaySetting(LCR_DisplaySetting_t const *Setting)
{
/* Generate packet */
LCR_CMD_PKT_CommandInit(LCR_CMD_PKT_TYPE_WRITE, 0x0107);
LCR_CMD_PKT_PutInt((int)Setting->LongAxisFlip,1);
LCR_CMD_PKT_PutInt((int)Setting->ShortAxisFlip,1);
LCR_CMD_PKT_PutInt((int)Setting->Rotate,1);
if(LCR_CMD_PKT_SendCommand())
return FAIL;
return SUCCESS;
}
/* Returns the existing display settings */
ErrorCode_t LCR_CMD_GetDisplaySetting(LCR_DisplaySetting_t *Setting)
{
uint8 data;
/* Display Settings */
LCR_CMD_PKT_CommandInit(LCR_CMD_PKT_TYPE_READ, 0x0107);
LCR_CMD_PKT_SendCommand();
LCR_CMD_PKT_GetData(&data,1);
Setting->LongAxisFlip = data;
LCR_CMD_PKT_GetData(&data,1);
Setting->ShortAxisFlip = data;
LCR_CMD_PKT_GetData(&data,1);
Setting->Rotate = data;
return SUCCESS;
}
/* Configures the input video source settings */
ErrorCode_t LCR_CMD_SetVideoSetting(LCR_VideoSetting_t const *Setting)
{
LCR_CMD_PKT_CommandInit(LCR_CMD_PKT_TYPE_WRITE, 0x0200);
LCR_CMD_PKT_PutInt(Setting->ResolutionX,2);
LCR_CMD_PKT_PutInt(Setting->ResolutionY,2);
LCR_CMD_PKT_PutInt(Setting->FirstPix,2);
LCR_CMD_PKT_PutInt(Setting->FirstLine,2);
LCR_CMD_PKT_PutInt(Setting->ActiveWidth,2);
LCR_CMD_PKT_PutInt(Setting->ActiveHeight,2);
if(LCR_CMD_PKT_SendCommand())
return FAIL;
return SUCCESS;
}
/* Returns currently set video settings */
ErrorCode_t LCR_CMD_GetVideoSetting(LCR_VideoSetting_t *Setting)
{
LCR_CMD_PKT_CommandInit(LCR_CMD_PKT_TYPE_READ, 0x0200);
LCR_CMD_PKT_SendCommand();
//Assign to the structures
Setting->ResolutionX = LCR_CMD_PKT_GetInt(2);
Setting->ResolutionY = LCR_CMD_PKT_GetInt(2);
Setting->FirstPix = LCR_CMD_PKT_GetInt(2);
Setting->FirstLine = LCR_CMD_PKT_GetInt(2);
Setting->ActiveWidth = LCR_CMD_PKT_GetInt(2);
Setting->ActiveHeight = LCR_CMD_PKT_GetInt(2);
return SUCCESS;
}
/* Set Video Mode */
ErrorCode_t LCR_CMD_SetVideoMode(LCR_VideoModeSetting_t *Setting)
{
/*Frame the packet*/
LCR_CMD_PKT_CommandInit(LCR_CMD_PKT_TYPE_WRITE, 0x0201);
LCR_CMD_PKT_PutInt((int)Setting->FrameRate,1);
LCR_CMD_PKT_PutInt((int)Setting->BitDepth,1);
LCR_CMD_PKT_PutInt((int)Setting->RGB,1);
if(LCR_CMD_PKT_SendCommand())
return FAIL;
return SUCCESS;
}
/* Return current video mode settings */
ErrorCode_t LCR_CMD_GetVideoMode(LCR_VideoModeSetting_t *Setting)
{
uint8 data;
LCR_CMD_PKT_CommandInit(LCR_CMD_PKT_TYPE_READ, 0x0201);
LCR_CMD_PKT_SendCommand();
LCR_CMD_PKT_GetData(&data,1);
Setting->FrameRate = data;
LCR_CMD_PKT_GetData(&data,1);
Setting->BitDepth = data;
LCR_CMD_PKT_GetData(&data,1);
Setting->RGB = data;
return SUCCESS;
}
/* Configures pattern interleaving */
ErrorCode_t LCR_CMD_SetInterleavePatternOrder(uint8 NumPatterns, uint8 const *PatternOrder)
{
/*TBD*/
return SUCCESS;
}
/* Returns pattern interleave order */
ErrorCode_t LCR_CMD_GetInterleavePatternOrder(uint8 *NumPatterns, uint8 *PatternOrder)
{
/*TBD*/
return SUCCESS;
}
/* Defines pattern sequence */
ErrorCode_t LCR_CMD_SetPatternSeqSetting(LCR_PatternSeqSetting_t const *Setting)
{
LCR_CMD_PKT_CommandInit(LCR_CMD_PKT_TYPE_WRITE, 0x0480); //The old cmd 0x0400 is kept for backward compatibility only use the new one
LCR_CMD_PKT_PutInt((int)Setting->BitDepth,1);
LCR_CMD_PKT_PutInt((int)Setting->NumPatterns,2);
LCR_CMD_PKT_PutInt((int)Setting->PatternType,1);
LCR_CMD_PKT_PutInt((int)Setting->InputTriggerType,1);
LCR_CMD_PKT_PutInt((uint32)Setting->InputTriggerDelay,4);
LCR_CMD_PKT_PutInt((uint32)Setting->AutoTriggerPeriod,4);
LCR_CMD_PKT_PutInt((uint32)Setting->ExposureTime,4);
LCR_CMD_PKT_PutInt((int)Setting->LEDSelect,1);
LCR_CMD_PKT_PutInt((int)Setting->Repeat,1);
if(LCR_CMD_PKT_SendCommand())
return FAIL;
return SUCCESS;
}
/* Return currently set pattern sequence */
ErrorCode_t LCR_CMD_GetPatternSeqSetting(LCR_PatternSeqSetting_t *Setting)
{
uint8 data;
uint32 data32;
LCR_CMD_PKT_CommandInit(LCR_CMD_PKT_TYPE_READ, 0x0480);
if(LCR_CMD_PKT_SendCommand())
return FAIL;
LCR_CMD_PKT_GetData(&data,1);
Setting->BitDepth = data;
Setting->NumPatterns = LCR_CMD_PKT_GetInt(2);
LCR_CMD_PKT_GetData(&data,1);
Setting->PatternType = (LCR_PatternType_t) data;
LCR_CMD_PKT_GetData(&data,1);
Setting->InputTriggerType = (LCR_TriggerType_t)data;
LCR_CMD_PKT_GetData((uint8*)&data32,4);
Setting->InputTriggerDelay = data32;
LCR_CMD_PKT_GetData((uint8*)&data32,4);
Setting->AutoTriggerPeriod = data32;
LCR_CMD_PKT_GetData((uint8*)&data32,4);
Setting->ExposureTime = data32;
LCR_CMD_PKT_GetData(&data,1);
Setting->LEDSelect = (LCR_LEDSelect_t) data;
LCR_CMD_PKT_GetData(&data,1);
Setting->Repeat = data;
return SUCCESS;
}
/* Downloads a bmp file in pattern sequence mode */
ErrorCode_t LCR_CMD_DefinePatternBMP(LCR_PatternCount_t PatternNum, char const *fileNameWithPath)
{
/* Generate packet */
LCR_CMD_PKT_CommandInit(LCR_CMD_PKT_TYPE_WRITE, 0x0401);
LCR_CMD_PKT_PutInt((int)PatternNum, 1);
LCR_CMD_PKT_PutFile(fileNameWithPath);
if(LCR_CMD_PKT_SendCommand())
return FAIL;
return SUCCESS;
}
/* Reads and stores a pattern from the DLP LightCrafter(TM) in the .bmp format with <file_name>*/
ErrorCode_t LCR_CMD_ReadPattern(LCR_PatternCount_t PatternNum, char *fileName)
{
unsigned long int numbytes;
//Determine the bit depth
LCR_PatternSeqSetting_t Setting;
LCR_CMD_GetPatternSeqSetting(&Setting);
switch(Setting.BitDepth)
{
case 1:
numbytes = ONE_BPP_PTN_SIZE;
break;
case 2:
numbytes = TWO_BPP_PTN_SIZE;
break;
case 3:
numbytes = THREE_BPP_PTN_SIZE;
break;
case 4:
numbytes = FOUR_BPP_PTN_SIZE;
break;
case 5:
numbytes = FIVE_BPP_PTN_SIZE;
break;
case 6:
numbytes = SIX_BPP_PTN_SIZE;
break;
case 7:
numbytes = SEVEN_BPP_PTN_SIZE;
break;
case 8:
numbytes = EIGHT_BPP_PTN_SIZE;
break;
default:
return FAIL;
}
/* Generate packet */
LCR_CMD_PKT_CommandInit(LCR_CMD_PKT_TYPE_READ, 0x0401);
LCR_CMD_PKT_PutData((uint8*) &PatternNum, 1);
LCR_CMD_PKT_SendCommand();
LCR_CMD_PKT_GetFile(fileName,numbytes);
return SUCCESS;
}
/* Starts/Stop of pattern sequence */
ErrorCode_t LCR_CMD_StartPatternSeq(uint8 Start)
{
/* Generate packet */
LCR_CMD_PKT_CommandInit(LCR_CMD_PKT_TYPE_WRITE, 0x0402);
LCR_CMD_PKT_PutInt(Start,1);
if(LCR_CMD_PKT_SendCommand())
return FAIL;
return SUCCESS;
}
/* Displays next pattern in pattern sequence applicable only if Input Trigger Type = Command Trigger (0x00) */
ErrorCode_t LCR_CMD_AdvancePatternSeq(void)
{
/* Generate packet */
LCR_CMD_PKT_CommandInit(LCR_CMD_PKT_TYPE_WRITE, 0x0403);
if(LCR_CMD_PKT_SendCommand())
return FAIL;
return SUCCESS;
}
/* Returns the configuration of the CameraTrigger signal */
ErrorCode_t LCR_CMD_GetCamTriggerSetting(LCR_CamTriggerSetting_t *Setting)
{
uint8 data;
uint32 data32;
LCR_CMD_PKT_CommandInit(LCR_CMD_PKT_TYPE_READ, 0x0404);
LCR_CMD_PKT_SendCommand();
LCR_CMD_PKT_GetData(&data,1);
Setting->Enable = data;
LCR_CMD_PKT_GetData(&data,1);
Setting->Source = data;
LCR_CMD_PKT_GetData(&data,1);
Setting->Polarity = data;
LCR_CMD_PKT_GetData((uint8*)&data32,4);
Setting->Delay = data32;
LCR_CMD_PKT_GetData((uint8*)&data32,4);
Setting->PulseWidth = data32;
return SUCCESS;
}
/* Updates the camera trigger configuration */
ErrorCode_t LCR_CMD_SetCamTriggerSetting(LCR_CamTriggerSetting_t *Setting)
{
LCR_CMD_PKT_CommandInit(LCR_CMD_PKT_TYPE_WRITE, 0x0404);
LCR_CMD_PKT_PutInt((int)Setting->Enable,1);
LCR_CMD_PKT_PutInt((int)Setting->Source,1);
LCR_CMD_PKT_PutInt((int)Setting->Polarity,1);
LCR_CMD_PKT_PutInt((uint32)Setting->Delay,4);
LCR_CMD_PKT_PutInt((uint32)Setting->PulseWidth,4);
if(LCR_CMD_PKT_SendCommand())
return FAIL;
return SUCCESS;
}
/*Send the HW Pattern Sequence Definition information */
ErrorCode_t LCR_CMD_DefineHWPatSequence(LCR_HWPatternSeqDef_t *hwPatSeqDef)
{
int i;
LCR_CMD_PKT_CommandInit(LCR_CMD_PKT_TYPE_WRITE, 0x0406);
LCR_CMD_PKT_PutInt((int)hwPatSeqDef->index,1);
LCR_CMD_PKT_PutInt((int)hwPatSeqDef->numOfPatn,1);
for(i=0; i<hwPatSeqDef->numOfPatn;i++)
{
LCR_CMD_PKT_PutInt((int)hwPatSeqDef->hwPatArray[i].Number,1);
LCR_CMD_PKT_PutInt((int)hwPatSeqDef->hwPatArray[i].Invert,1);
}
if(LCR_CMD_PKT_SendCommand())
return FAIL;
return SUCCESS;
}
/* Save current setting and Display mode as solution */
ErrorCode_t LCR_CMD_SaveSolution(char *SolutionName)
{
uint8 tempName[LCR_CMD_SOLUTION_NAME_LEN];
//copy the string into temporary buffer
strcpy((char*)&tempName[0],SolutionName);
//Frame the packet
LCR_CMD_PKT_CommandInit(LCR_CMD_PKT_TYPE_WRITE, 0x0600);
LCR_CMD_PKT_PutData((uint8*)&tempName[0],LCR_CMD_SOLUTION_NAME_LEN);
if(LCR_CMD_PKT_SendCommand())
return FAIL;
return SUCCESS;
}
/* Retrieve the details of the solution stored */
ErrorCode_t LCR_CMD_GetSolutionNames(uint8 *Count, uint8 *DefaultSolution, char *SolutionName)
{
//Frame the packet
LCR_CMD_PKT_CommandInit(LCR_CMD_PKT_TYPE_READ, 0x0600);
LCR_CMD_PKT_SendCommand();
LCR_CMD_PKT_GetData(Count,1);
LCR_CMD_PKT_GetData(DefaultSolution,1);
LCR_CMD_PKT_GetData((uint8*)SolutionName,((*Count)*LCR_CMD_SOLUTION_NAME_LEN));
return SUCCESS;
}
/* Allows Loading, Deleting and Setting an exisitng solution in the system */
ErrorCode_t LCR_CMD_ManageSolution(LCR_SolutionCommand_t Cmd, char *SolutionName)
{
uint8 tempName[LCR_CMD_SOLUTION_NAME_LEN];
//copy the string into temporary buffer
strcpy((char*)&tempName[0],SolutionName);
//Frame the packet
LCR_CMD_PKT_CommandInit(LCR_CMD_PKT_TYPE_WRITE, 0x0601);
LCR_CMD_PKT_PutData((uint8*)&Cmd,1);
LCR_CMD_PKT_PutData((uint8*)&tempName[0],LCR_CMD_SOLUTION_NAME_LEN);
if(LCR_CMD_PKT_SendCommand())
return FAIL;
return SUCCESS;
}
/*Downloads the new Sequence LUT into the DLPC300 controller*/
ErrorCode_t LCR_CMD_LoadCustomSequence(char *seqBinFileName)
{
/* Generate packet */
LCR_CMD_PKT_CommandInit(LCR_CMD_PKT_TYPE_WRITE, 0x0A00);
/*TBD - Check for return error*/
LCR_CMD_PKT_PutFile(seqBinFileName);
if(LCR_CMD_PKT_SendCommand())
return FAIL;
return SUCCESS;
}
/*Setup the vectors*/
ErrorCode_t LCR_CMD_SetupCustomSequencevectors(uint8 startVector, uint8 numOfvectors)
{
/* Generate packet */
LCR_CMD_PKT_CommandInit(LCR_CMD_PKT_TYPE_WRITE, 0x0A01);
LCR_CMD_PKT_PutData((uint8*)&startVector,1);
LCR_CMD_PKT_PutData((uint8*)&numOfvectors,1);
if(LCR_CMD_PKT_SendCommand())
return FAIL;
return SUCCESS;
}