-
Notifications
You must be signed in to change notification settings - Fork 23
/
ISZ2510.c
817 lines (691 loc) · 21.1 KB
/
ISZ2510.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
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
// ###########################################################################
//
// Copyright (C) 2015 GenId SPRL
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
///
/// \file ISZ2510.c
/// \author Jean-Sebastien Gonsette
/// \date 17/10/2014
///
/// ISZ2510 device driver (Digital Gyroscope)
// ###########################################################################
#include "ISZ2510.h"
// ===========================================================================
// I S Z R E G I S T E R S
// ===========================================================================
#define REG_XG_OFFS_TC_H 0x04
#define REG_XG_OFFS_TC_L 0x05
#define REG_YG_OFFS_TC_H 0x07
#define REG_YG_OFFS_TC_L 0x08
#define REG_ZG_OFFS_TC_H 0x0A
#define REG_ZG_OFFS_TC_L 0x0B
#define REG_XG_OFFS_USRH 0x13
#define REG_XG_OFFS_USRL 0x14
#define REG_YG_OFFS_USRH 0x15
#define REG_YG_OFFS_USRL 0x16
#define REG_ZG_OFFS_USRH 0x17
#define REG_ZG_OFFS_USRL 0x18
#define REG_SMPLRT_DIV 0x19
#define REG_CONFIG 0x1A
#define REG_GYRO_CONFIG 0x1B
#define REG_FIFO_EN 0x23
#define REG_INT_PIN_CFG 0x37
#define REG_INT_ENABLE 0x38
#define REG_INT_STATUS 0x3A
#define REG_TEMP_OUT_H 0x41
#define REG_TEMP_OUT_L 0x42
#define REG_GYRO_XOUT_H 0x43
#define REG_GYRO_XOUT_L 0x44
#define REG_GYRO_YOUT_H 0x45
#define REG_GYRO_YOUT_L 0x46
#define REG_GYRO_ZOUT_H 0x47
#define REG_GYRO_ZOUT_L 0x48
#define REG_USER_CTRL 0x6A
#define REG_PWR_MGMT_1 0x6B
#define REG_PWR_MGMT_2 0x6C
#define REG_FIFO_COUNTH 0x72
#define REG_FIFO_COUNTL 0x73
#define REG_FIFO_R_W 0x74
#define REG_WHO_AM_I 0x75
// ===========================================================================
// I S Z I R Q
// ===========================================================================
// INT_ENABLE/STATUS register
#define IRQ_FIFO_OVFL 0x10
#define IRQ_FSYNC_INT 0x04
#define IRQ_DATA_RDY 0x01
// ===========================================================================
// D E F I N E
// ===========================================================================
// INT_PIN_CFG register
#define INT_LEVEL 0x80
#define INT_OPEN 0x40
#define LATCH_INT_EN 0x20
#define INT_RD_CLEAR 0x10
#define FSYNC_INT_LEVEL 0x08
#define FSYNC_INT_MODE_EN 0x04
// ===========================================================================
// T Y P E S
// ===========================================================================
// ===========================================================================
// P R I V A T E
// ===========================================================================
/// Driver ISZ2510
static HANDLE gs_driverISZ2510 = INVALID_HANDLE;
// ===========================================================================
// P R I V A T E P R O T O
// ===========================================================================
/// \name Internal functions
//@{
static void KernelCallbackKER (HANDLE device);
static void GetSpi (ISZ2510_DCB* pDevice);
static void ReleaseSpi (ISZ2510_DCB* pDevice);
static void Write (ISZ2510_DCB* pDevice, Byte reg, Byte data);
static Byte Read (ISZ2510_DCB* pDevice, Byte reg);
static void ReadVector (ISZ2510_DCB* pDevice, Byte reg, Byte* pBuffer, Byte len);
//@}
// ###########################################################################
//
// P U B L I C
//
// ###########################################################################
// ===========================================================================
// <ISZ2510_OpenDriver>
///
/// \brief Record "ISZ2510" driver to the system
///
/// \return Driver handle
/// INVALID_HANDLE in case of failure
// ===========================================================================
HANDLE ISZ2510_OpenDriver ()
{
// Register driver at OS level
gs_driverISZ2510 = Drv_OpenDriver (0, "Ivensense_ISZ2510", "1.0.0", KernelCallbackKER);
return gs_driverISZ2510;
}
// ===========================================================================
// <ISZ2510_CreateDevice>
///
/// \brief Create a ISZ2510 device
///
/// \param[in] name Device name
/// \param[in] pConfig Configuration structure
///
/// \return Device HANDLE
/// INVALID_HANDLE in case of failure
// ===========================================================================
HANDLE ISZ2510_CreateDevice (const char* name, ISZ2510_Config* pConfig)
{
HANDLE h;
Word size;
ISZ2510_DCB* pDevice;
if (gs_driverISZ2510 == INVALID_HANDLE) return INVALID_HANDLE;
// Device registration
size = AlignUp (sizeof (ISZ2510_DCB), sizeof (int));
h = Drv_OpenDevice (gs_driverISZ2510, size, name, False);
// Get back our data structure
if (h != INVALID_HANDLE)
pDevice = (ISZ2510_DCB*) Drv_HandleToDevice (h);
else
{
ThrowError (ERR_DEVICE_NOMEM);
return INVALID_HANDLE;
}
// Configuration
pDevice->spi = pConfig->spi;
pDevice->fCS = pConfig->fCS;
// Default scale = 250°/s
pDevice->scale = ISZ2510_SCALE_250;
// Default scaler = x1
pDevice->scaler = 0x8000;
return h;
}
// ===========================================================================
// <ISZ2510_CloseDevice>
///
/// \brief Close a ISZ2510 device
///
/// \param[in] device Device to close
// ===========================================================================
void ISZ2510_CloseDevice (HANDLE device)
{
ISZ2510_DCB* pDevice;
pDevice = (ISZ2510_DCB*) Drv_HandleToDevice (device);
EnterCritical ();
{
Drv_CloseDevice (device);
}
LeaveCritical ();
}
// ===========================================================================
// <ISZ2510_Init>
///
/// \brief Initialize the device
///
/// \param[in] device Device to initialize
///
/// \return 0 if initialization is successful
// ===========================================================================
int ISZ2510_Init (HANDLE device)
{
Byte id;
ISZ2510_DCB* pDevice;
pDevice = (ISZ2510_DCB*) Drv_HandleToDevice (device);
GetSpi (pDevice);
{
// Get Who Am I ID
id = Read (pDevice, REG_WHO_AM_I);
// Disable interrupts
Write (pDevice, REG_INT_ENABLE, 0);
// Configure interrupt usage:
// Interrupt active low, push pull, held until cleared, cleared by reading status
Write (pDevice, REG_INT_PIN_CFG, INT_LEVEL | LATCH_INT_EN);
// Clear interrupt status
Read (pDevice, REG_INT_STATUS);
//
//Write (pDevice, REG_INT_ENABLE, IRQ_DATA_RDY);
}
ReleaseSpi (pDevice);
// Check ID
if (id == 0x68) return 0;
return -1;
}
// ===========================================================================
// <ISZ2510_Reset>
///
/// \brief Reset the device
///
/// \param[in] device Device to reset
// ===========================================================================
void ISZ2510_Reset (HANDLE device)
{
Byte pwmg1;
ISZ2510_DCB* pDevice;
pDevice = (ISZ2510_DCB*) Drv_HandleToDevice (device);
GetSpi (pDevice);
{
// Set the Reset bit
pwmg1 = Read (pDevice, REG_PWR_MGMT_1);
pwmg1 |= 0x80;
Write (pDevice, REG_PWR_MGMT_1, pwmg1);
}
ReleaseSpi (pDevice);
}
// ===========================================================================
// <ISZ2510_Selftest>
///
/// \brief Perform gyro selftest measurement and return the status
///
/// \param[in] device Device to selftest
///
/// \return True if the selftest is successful
// ===========================================================================
Bool ISZ2510_Selftest (HANDLE device)
{
/// \todo
return False;
}
// ===========================================================================
// <ISZ2510_SetMode>
///
/// \brief Select the device power mode
///
/// \param[in] device Device to initialize
/// \param[in] mode Power mode: sleep, idle, normal
// ===========================================================================
void ISZ2510_SetMode (HANDLE device, ISZ2510_Mode mode)
{
Byte pwmg1, pwmg2;
ISZ2510_DCB* pDevice;
pDevice = (ISZ2510_DCB*) Drv_HandleToDevice (device);
GetSpi (pDevice);
{
// Get power management configuration
pwmg1 = Read (pDevice, REG_PWR_MGMT_1);
pwmg2 = Read (pDevice, REG_PWR_MGMT_2);
if (mode == ISZ2510_MODE_SLEEP) pwmg1 |= 0x40;
else if (mode == ISZ2510_MODE_STANDBY)
{
// No sleep, select internal clock, Gyros in standby
pwmg1 &= ~0x40;
pwmg1 &= ~0x07;
pwmg2 |= 0x07;
}
else if (mode == ISZ2510_MODE_MEASURE)
{
// No sleep, select PLL clock, Gyro on
pwmg2 = 0;
pwmg1 &= ~0x40;
pwmg1 |= 0x01;
}
// Write power management configuration.
// If going in standby, change the clock first
if (mode == ISZ2510_MODE_STANDBY)
{
Write (pDevice, REG_PWR_MGMT_1, pwmg1);
Write (pDevice, REG_PWR_MGMT_2, pwmg2);
}
else
{
Write (pDevice, REG_PWR_MGMT_2, pwmg2);
Write (pDevice, REG_PWR_MGMT_1, pwmg1);
}
}
ReleaseSpi (pDevice);
}
// ===========================================================================
// <ISZ2510_SetScale>
///
/// \brief Select the gyro scale/sensitivity
///
/// \param[in] device Device to configure
/// \param[in] scale Full scale: 250, 500, 1000 or 2000 °/s
// ===========================================================================
void ISZ2510_SetScale (HANDLE device, ISZ2510_Scale scale)
{
Byte gyroConfig;
ISZ2510_DCB* pDevice;
pDevice = (ISZ2510_DCB*) Drv_HandleToDevice (device);
GetSpi (pDevice);
{
// Get configuration
gyroConfig = Read (pDevice, REG_GYRO_CONFIG);
// Change scale
gyroConfig &= ~0x18;
gyroConfig |= (Byte) (scale << 3);
pDevice->scale = scale;
// Write configuration
Write (pDevice, REG_GYRO_CONFIG, gyroConfig);
}
ReleaseSpi (pDevice);
}
// ===========================================================================
// <ISZ2510_GetTemperature>
///
/// \brief Return the device internal temperature
///
/// \param[in] device Target device
///
/// \return Temperature in 1/100 °
// ===========================================================================
Short ISZ2510_GetTemperature (HANDLE device)
{
Word raw;
Long temp;
ISZ2510_DCB* pDevice;
pDevice = (ISZ2510_DCB*) Drv_HandleToDevice (device);
GetSpi (pDevice);
{
// Get raw temperature
ReadVector (pDevice, REG_TEMP_OUT_H, (Byte*) &raw, 2);
raw = BigEndian16 (raw);
}
ReleaseSpi (pDevice);
// 321.4 LSB/°C
temp = (Long)((Short)raw) * 20391;
temp >>= 16;
return (Short)temp;
}
// ===========================================================================
// <ISZ2510_SetBandwidth>
///
/// \brief Select the internal lowpass filter bandwidth
///
/// \param[in] device Target device
/// \param[in] bw Lpf bandwidth
// ===========================================================================
void ISZ2510_SetBandwidth (HANDLE device, ISZ2510_Bandwidth bw)
{
Byte dlpf;
Byte fchoice;
ISZ2510_DCB* pDevice;
pDevice = (ISZ2510_DCB*) Drv_HandleToDevice (device);
GetSpi (pDevice);
{
// Get configuration
dlpf = Read (pDevice, REG_CONFIG);
fchoice = Read (pDevice, REG_GYRO_CONFIG);
// Select bandwidth
if (bw <= ISZ2510_BW_5 && bw >= ISZ2510_BW_250)
{
dlpf &= ~0x07;
dlpf |= (bw & 0x07);
fchoice &= ~0x03;
}
else if (bw == ISZ2510_BW_3600)
{
if ((fchoice & 0x03) == 0) dlpf = ISZ2510_BW_3600;
else
{
fchoice &= ~0x03;
fchoice |= 0x02;
}
}
else if (bw == ISZ2510_BW_8800)
{
fchoice &= ~0x03;
fchoice |= 0x01;
}
// Set configuration
Write (pDevice, REG_CONFIG, dlpf);
Write (pDevice, REG_GYRO_CONFIG, fchoice);
}
ReleaseSpi (pDevice);
}
// ===========================================================================
// <ISZ2510_SetBaudrate>
///
/// \brief Select the output data rate
///
/// Achievable baudrate is closely related to the selected bandwdith (see datasheet).
/// Therefore, bandwidth must be selected first.
/// If BW = 3600, BR is either 8k or 32k
/// If BW = 8800, BR is only 32k
/// If BW = 250, BR is only 8k
/// For other BW, BR must be less or equal to 1k
///
/// \param[in] device Target device
/// \param[in] br Desired baudrate in Hz
///
/// \return Actual baudrate programmed in the device
// ===========================================================================
Word ISZ2510_SetBaudrate (HANDLE device, Word br)
{
Byte config, gyroConfig;
Byte dlpf, fchoice;
Word temp;
ISZ2510_DCB* pDevice;
pDevice = (ISZ2510_DCB*) Drv_HandleToDevice (device);
GetSpi (pDevice);
{
// Get configuration
config = Read (pDevice, REG_CONFIG);
gyroConfig = Read (pDevice, REG_GYRO_CONFIG);
// Extract dlpf and fchoice fields
dlpf = config & 0x07;
fchoice = gyroConfig & 0x03;
// Erase dlpf and fchoice
config &= ~0x07;
gyroConfig &= ~0x03;
// Configurable output data rate
if (fchoice == 0 && dlpf != ISZ2510_BW_250 && dlpf != ISZ2510_BW_3600)
{
if (br > 1000) br = 1000;
// Compute and program divider
temp = 1000/br;
temp --;
if (temp > 0xFF) temp = 0xFF;
Write (pDevice, REG_SMPLRT_DIV, (Byte) temp);
// Compute actual br
br = 1000/(temp+1);
}
// Not configurable output data rate
else
{
if (fchoice == 0 && dlpf == ISZ2510_BW_250) br = 8000;
else if (fchoice == 1 || fchoice == 3) br = 32000;
else
{
if (br == 32000) fchoice = 2;
else
{
br = 8000;
fchoice = 0;
dlpf = ISZ2510_BW_3600;
}
}
}
// Set configuration
config |= dlpf;
gyroConfig |= fchoice;
Write (pDevice, REG_CONFIG, config);
Write (pDevice, REG_GYRO_CONFIG, gyroConfig);
}
ReleaseSpi (pDevice);
return br;
}
// ===========================================================================
// <ISZ2510_GetAngularSpeed>
///
/// \brief Return the gryo output value
///
/// \param[in] device Target device
///
/// \return Gyro output [1/1000 °/s]
// ===========================================================================
Long ISZ2510_GetAngularSpeed (HANDLE device)
{
Short data;
Long temp;
ISZ2510_DCB* pDevice;
pDevice = (ISZ2510_DCB*) Drv_HandleToDevice (device);
GetSpi (pDevice);
{
// Read the gyro Z output
ReadVector (pDevice, REG_GYRO_ZOUT_H, (Byte*) &data, 2);
data = BigEndian16 (data);
}
ReleaseSpi (pDevice);
// Extend value on 4 Bytes
temp = (Long) ((Short) data);
// Scaling (correction)
temp = (temp * pDevice->scaler) >> 15;
// Scaling (nominal coeff. depends on scale)
switch (pDevice->scale)
{
case (ISZ2510_SCALE_250): temp = (temp * 10000) / 1310; break;
case (ISZ2510_SCALE_500): temp = (temp * 10000) / 655; break;
case (ISZ2510_SCALE_1000): temp = (temp * 10000) / 328; break;
case (ISZ2510_SCALE_2000): temp = (temp * 10000) / 164; break;
default: temp = 0; break;
}
return temp;
}
// ===========================================================================
// <ISZ2510_SetCalibrationOffset>
///
/// \brief Specify the gyro bias measured by an external calibration process
///
/// \param[in] device Device to calibrate
/// \param[in] offset Measured bias [1/1000 °/s]
// ===========================================================================
void ISZ2510_SetCalibrationOffset (HANDLE device, Long offset)
{
Short offC;
ISZ2510_DCB* pDevice;
pDevice = (ISZ2510_DCB*) Drv_HandleToDevice (device);
GetSpi (pDevice);
{
// Scale bias
offC = (Short) ((-offset * 328) / 10000);
Write (pDevice, REG_ZG_OFFS_USRH, (Byte) (offC >> 8));
Write (pDevice, REG_ZG_OFFS_USRL, (Byte) (offC & 0xFF));
}
ReleaseSpi (pDevice);
}
// ===========================================================================
// <ISZ2510_GetCalibrationValues>
///
/// \brief Get calibration values for backup purpose
///
/// \param[in] device Target device
/// \param[out] calib Calibration values
// ===========================================================================
void ISZ2510_GetCalibrationValues (HANDLE device, ISZ2510_CalibValues* calib)
{
Word offset;
ISZ2510_DCB* pDevice;
pDevice = (ISZ2510_DCB*) Drv_HandleToDevice (device);
// Get offset correction stored in the device
GetSpi (pDevice);
{
ReadVector (pDevice, REG_ZG_OFFS_USRH, (Byte*) &offset, 2);
offset = BigEndian16 (offset);
}
ReleaseSpi (pDevice);
// Fill the calibration structure
calib->scaler = pDevice->scaler;
calib->offset = offset;
}
// ===========================================================================
// <ISZ2510_SetCalibrationValues>
///
/// \brief Set/restore calibration values.
///
/// \param[in] device Target device
/// \param[in] calib Calibration values
// ===========================================================================
void ISZ2510_SetCalibrationValues (HANDLE device, ISZ2510_CalibValues calib)
{
ISZ2510_DCB* pDevice;
pDevice = (ISZ2510_DCB*) Drv_HandleToDevice (device);
// Get scalers
pDevice->scaler = calib.scaler;
// Write offset correction into the device
GetSpi (pDevice);
{
Write (pDevice, REG_ZG_OFFS_USRH, (Byte) (calib.offset >> 8));
Write (pDevice, REG_ZG_OFFS_USRL, (Byte) (calib.offset & 0xFF));
}
ReleaseSpi (pDevice);
}
// ###########################################################################
//
// P R I V A T E
//
// ###########################################################################
// ===========================================================================
// <KernelCallbackKER>
///
/// \brief Callback called by the Kernel when the device rise an IRQ
///
/// \param[in] device Target device
// ===========================================================================
static void KernelCallbackKER (HANDLE device)
{
// Interruptions not used
return;
}
// ###########################################################################
//
// P R I V A T E - S P I
//
// ###########################################################################
// ===========================================================================
// <GetSpi>
///
/// \brief SPI bus reservation
///
/// \param[in] pDevice Target device
// ===========================================================================
static void GetSpi (ISZ2510_DCB* pDevice)
{
// Lock the SPI for our usage
// DeviceGetLock (pDevice->spi);
// Configuration
// Mode 0, 8 bits, 1MHz
SPI_SetMode (pDevice->spi, 0);
SPI_SetDataWidth (pDevice->spi, 8);
SPI_SetBaudRate (pDevice->spi, 1000000);
}
// ===========================================================================
// <ReleaseSpi>
///
/// \brief SPI bus release
///
/// \param[in] pDevice Target device
// ===========================================================================
static void ReleaseSpi (ISZ2510_DCB* pDevice)
{
// Release lock on the SPI device
// DeviceReleaseLock (pDevice->spi);
}
// ===========================================================================
// <Write>
///
/// \brief Elementary writing on the ISZ2510
///
/// \param[in] pDevice Target device
/// \param[in] reg Register address
/// \param[in] data Data to write
// ===========================================================================
static void Write (ISZ2510_DCB* pDevice, Byte reg, Byte data)
{
// MSB bit clear for writing
reg &= ~0x80;
pDevice->fCS (1);
{
// Register address
SPI_Write (pDevice->spi, (unsigned int*) ®, 1);
while (SPI_GetStatus (pDevice->spi) != SPI_ST_IDLE);
// Set data
SPI_Write (pDevice->spi, (unsigned int*) &data, 1);
while (SPI_GetStatus (pDevice->spi) != SPI_ST_IDLE);
}
pDevice->fCS (0);
}
// ===========================================================================
// <Read>
///
/// \brief Elementary reading on the ISZ2510
///
/// \param[in] pDevice Target device
/// \param[in] reg Register address
///
/// \return Value
// ===========================================================================
static Byte Read (ISZ2510_DCB* pDevice, Byte reg)
{
Byte data;
// MSB bit set for reading
reg |= 0x80;
pDevice->fCS (1);
{
// Register address
SPI_Write (pDevice->spi, (unsigned int*) ®, 1);
while (SPI_GetStatus (pDevice->spi) != SPI_ST_IDLE);
// Get response
SPI_Read (pDevice->spi, (unsigned int*) &data, 1);
while (SPI_GetStatus (pDevice->spi) != SPI_ST_IDLE);
}
pDevice->fCS (0);
return data;
}
// ===========================================================================
// <ReadVector>
///
/// \brief Multiple reading on the ISZ2510
///
/// \param[in] pDevice Target device
/// \param[in] reg Register address
/// \param[out] pBuffer Values
/// \param[in] len Number of registers to read
// ===========================================================================
static void ReadVector (ISZ2510_DCB* pDevice, Byte reg, Byte* pBuffer, Byte len)
{
// MSB bit set for reading
reg |= 0x80;
pDevice->fCS (1);
{
// Register address
SPI_Write (pDevice->spi, (unsigned int*) ®, 1);
while (SPI_GetStatus (pDevice->spi) != SPI_ST_IDLE);
// Get response
SPI_Read (pDevice->spi, (unsigned int*) pBuffer, len);
while (SPI_GetStatus (pDevice->spi) != SPI_ST_IDLE);
}
pDevice->fCS (0);
}
// END