Treehopper C++ API
L3gd20Registers.h
Go to the documentation of this file.
1 #pragma once
3 #include "SMBusDevice.h"
6 #include "Libraries/Register.h"
7 
8 using namespace Treehopper::Libraries;
9 
10 namespace Treehopper { namespace Libraries { namespace Sensors { namespace Inertial {
11 
12  enum class DataRates
13  {
14  Hz_95 = 0,
15  Hz_190 = 1,
16  Hz_380 = 2,
17  Hz_760 = 3
18  };
19 
20  enum class FifoModes
21  {
22  Bypass = 0,
23  Fifo = 1,
24  Stream = 2,
25  StreamToFifo = 3,
26  BypassToStream = 4
27  };
28 
29 
30  class L3gd20Registers : public RegisterManager
31  {
32  public:
33  class WhoAmIRegister : public Register
34  {
35  public:
36  WhoAmIRegister(RegisterManager& regManager) : Register(regManager,0x0f, 1, false) { }
37  int value;
38 
39  long getValue() { return ((value & 0xFF) << 0); }
40  void setValue(long val)
41  {
42  value = (int)((val >> 0) & 0xFF);
43  }
44  };
45 
46  class CtrlReg1Register : public Register
47  {
48  public:
49  CtrlReg1Register(RegisterManager& regManager) : Register(regManager,0x20, 1, false) { }
50  int yEn;
51  int xEn;
52  int zEn;
53  int pd;
54  int bandwidth;
55  int dataRate;
56  DataRates getDataRate() { return (DataRates)dataRate; }
57  void setDataRate(DataRates enumVal) { dataRate = (int)enumVal; }
58 
59  long getValue() { return ((yEn & 0x1) << 0) | ((xEn & 0x1) << 1) | ((zEn & 0x1) << 2) | ((pd & 0x1) << 3) | ((bandwidth & 0x3) << 4) | ((dataRate & 0x3) << 6); }
60  void setValue(long val)
61  {
62  yEn = (int)((val >> 0) & 0x1);
63  xEn = (int)((val >> 1) & 0x1);
64  zEn = (int)((val >> 2) & 0x1);
65  pd = (int)((val >> 3) & 0x1);
66  bandwidth = (int)((val >> 4) & 0x3);
67  dataRate = (int)((val >> 6) & 0x3);
68  }
69  };
70 
71  class CtrlReg2Register : public Register
72  {
73  public:
74  CtrlReg2Register(RegisterManager& regManager) : Register(regManager,0x21, 1, false) { }
75  int hpFilterCutoff;
76  int hpFilterMode;
77 
78  long getValue() { return ((hpFilterCutoff & 0xF) << 0) | ((hpFilterMode & 0x3) << 4); }
79  void setValue(long val)
80  {
81  hpFilterCutoff = (int)((val >> 0) & 0xF);
82  hpFilterMode = (int)((val >> 4) & 0x3);
83  }
84  };
85 
86  class CtrlReg3Register : public Register
87  {
88  public:
89  CtrlReg3Register(RegisterManager& regManager) : Register(regManager,0x22, 1, false) { }
90  int i2Empty;
91  int i2ORun;
92  int i2Wtm;
93  int i2Drdy;
94  int ppOd;
95  int hLactive;
96  int i1boot;
97  int i1Int1;
98 
99  long getValue() { return ((i2Empty & 0x1) << 0) | ((i2ORun & 0x1) << 1) | ((i2Wtm & 0x1) << 2) | ((i2Drdy & 0x1) << 3) | ((ppOd & 0x1) << 4) | ((hLactive & 0x1) << 5) | ((i1boot & 0x1) << 6) | ((i1Int1 & 0x1) << 7); }
100  void setValue(long val)
101  {
102  i2Empty = (int)((val >> 0) & 0x1);
103  i2ORun = (int)((val >> 1) & 0x1);
104  i2Wtm = (int)((val >> 2) & 0x1);
105  i2Drdy = (int)((val >> 3) & 0x1);
106  ppOd = (int)((val >> 4) & 0x1);
107  hLactive = (int)((val >> 5) & 0x1);
108  i1boot = (int)((val >> 6) & 0x1);
109  i1Int1 = (int)((val >> 7) & 0x1);
110  }
111  };
112 
113  class CtrlReg4Register : public Register
114  {
115  public:
116  CtrlReg4Register(RegisterManager& regManager) : Register(regManager,0x23, 1, false) { }
117  int sim;
118  int fullScale;
119  int bigLittleEndian;
120  int blockDataUpdate;
121 
122  long getValue() { return ((sim & 0x1) << 0) | ((fullScale & 0x3) << 4) | ((bigLittleEndian & 0x1) << 6) | ((blockDataUpdate & 0x1) << 7); }
123  void setValue(long val)
124  {
125  sim = (int)((val >> 0) & 0x1);
126  fullScale = (int)((val >> 4) & 0x3);
127  bigLittleEndian = (int)((val >> 6) & 0x1);
128  blockDataUpdate = (int)((val >> 7) & 0x1);
129  }
130  };
131 
132  class CtrlReg5Register : public Register
133  {
134  public:
135  CtrlReg5Register(RegisterManager& regManager) : Register(regManager,0x24, 1, false) { }
136  int outSel;
137  int int1Sel;
138  int hPen;
139  int fifoEn;
140  int boot;
141 
142  long getValue() { return ((outSel & 0x3) << 0) | ((int1Sel & 0x3) << 2) | ((hPen & 0x1) << 4) | ((fifoEn & 0x1) << 6) | ((boot & 0x1) << 7); }
143  void setValue(long val)
144  {
145  outSel = (int)((val >> 0) & 0x3);
146  int1Sel = (int)((val >> 2) & 0x3);
147  hPen = (int)((val >> 4) & 0x1);
148  fifoEn = (int)((val >> 6) & 0x1);
149  boot = (int)((val >> 7) & 0x1);
150  }
151  };
152 
153  class ReferenceDataCaptureRegister : public Register
154  {
155  public:
156  ReferenceDataCaptureRegister(RegisterManager& regManager) : Register(regManager,0x25, 1, false) { }
157  int value;
158 
159  long getValue() { return ((value & 0xFF) << 0); }
160  void setValue(long val)
161  {
162  value = (int)((val >> 0) & 0xFF);
163  }
164  };
165 
166  class OutTempRegister : public Register
167  {
168  public:
169  OutTempRegister(RegisterManager& regManager) : Register(regManager,0x26, 1, false) { }
170  int value;
171 
172  long getValue() { return ((value & 0xFF) << 0); }
173  void setValue(long val)
174  {
175  value = (int)((val >> 0) & 0xFF);
176  }
177  };
178 
179  class StatusRegister : public Register
180  {
181  public:
182  StatusRegister(RegisterManager& regManager) : Register(regManager,0x27, 1, false) { }
183  int xDataAvailable;
184  int yDataAvailable;
185  int zDataAvailable;
186  int zyxDataAvailable;
187  int xDataOverrun;
188  int yDataOverrun;
189  int zDataOverrun;
190  int zyxDataOverrun;
191 
192  long getValue() { return ((xDataAvailable & 0x1) << 0) | ((yDataAvailable & 0x1) << 1) | ((zDataAvailable & 0x1) << 2) | ((zyxDataAvailable & 0x1) << 3) | ((xDataOverrun & 0x1) << 4) | ((yDataOverrun & 0x1) << 5) | ((zDataOverrun & 0x1) << 6) | ((zyxDataOverrun & 0x1) << 7); }
193  void setValue(long val)
194  {
195  xDataAvailable = (int)((val >> 0) & 0x1);
196  yDataAvailable = (int)((val >> 1) & 0x1);
197  zDataAvailable = (int)((val >> 2) & 0x1);
198  zyxDataAvailable = (int)((val >> 3) & 0x1);
199  xDataOverrun = (int)((val >> 4) & 0x1);
200  yDataOverrun = (int)((val >> 5) & 0x1);
201  zDataOverrun = (int)((val >> 6) & 0x1);
202  zyxDataOverrun = (int)((val >> 7) & 0x1);
203  }
204  };
205 
206  class FifoCtrlRegister : public Register
207  {
208  public:
209  FifoCtrlRegister(RegisterManager& regManager) : Register(regManager,0x2e, 1, false) { }
210  int watermarkLevelSetting;
211  int fifoMode;
212  FifoModes getFifoMode() { return (FifoModes)fifoMode; }
213  void setFifoMode(FifoModes enumVal) { fifoMode = (int)enumVal; }
214 
215  long getValue() { return ((watermarkLevelSetting & 0x1F) << 0) | ((fifoMode & 0x7) << 5); }
216  void setValue(long val)
217  {
218  watermarkLevelSetting = (int)((val >> 0) & 0x1F);
219  fifoMode = (int)((val >> 5) & 0x7);
220  }
221  };
222 
223  class FifoSrcRegister : public Register
224  {
225  public:
226  FifoSrcRegister(RegisterManager& regManager) : Register(regManager,0x2f, 1, false) { }
227  int fifoStoredDataLevel;
228  int empty;
229  int overrun;
230  int watermarkStatus;
231 
232  long getValue() { return ((fifoStoredDataLevel & 0x1F) << 0) | ((empty & 0x1) << 5) | ((overrun & 0x1) << 6) | ((watermarkStatus & 0x1) << 7); }
233  void setValue(long val)
234  {
235  fifoStoredDataLevel = (int)((val >> 0) & 0x1F);
236  empty = (int)((val >> 5) & 0x1);
237  overrun = (int)((val >> 6) & 0x1);
238  watermarkStatus = (int)((val >> 7) & 0x1);
239  }
240  };
241 
242  class IntConfigRegister : public Register
243  {
244  public:
245  IntConfigRegister(RegisterManager& regManager) : Register(regManager,0x30, 1, false) { }
246  int xLowInterruptEnable;
247  int xHighInterruptEnable;
248  int yLowInterruptEnable;
249  int yHighInterruptEnable;
250  int zLowInterruptEvent;
251  int zHighInterruptEnable;
252  int latchInterruptRequest;
253  int andOr;
254 
255  long getValue() { return ((xLowInterruptEnable & 0x1) << 0) | ((xHighInterruptEnable & 0x1) << 1) | ((yLowInterruptEnable & 0x1) << 2) | ((yHighInterruptEnable & 0x1) << 3) | ((zLowInterruptEvent & 0x1) << 4) | ((zHighInterruptEnable & 0x1) << 5) | ((latchInterruptRequest & 0x1) << 6) | ((andOr & 0x1) << 7); }
256  void setValue(long val)
257  {
258  xLowInterruptEnable = (int)((val >> 0) & 0x1);
259  xHighInterruptEnable = (int)((val >> 1) & 0x1);
260  yLowInterruptEnable = (int)((val >> 2) & 0x1);
261  yHighInterruptEnable = (int)((val >> 3) & 0x1);
262  zLowInterruptEvent = (int)((val >> 4) & 0x1);
263  zHighInterruptEnable = (int)((val >> 5) & 0x1);
264  latchInterruptRequest = (int)((val >> 6) & 0x1);
265  andOr = (int)((val >> 7) & 0x1);
266  }
267  };
268 
269  class Int1SrcRegister : public Register
270  {
271  public:
272  Int1SrcRegister(RegisterManager& regManager) : Register(regManager,0x31, 1, false) { }
273  int xLow;
274  int xHigh;
275  int yLow;
276  int yHigh;
277  int zLow;
278  int zHigh;
279  int interruptActive;
280 
281  long getValue() { return ((xLow & 0x1) << 0) | ((xHigh & 0x1) << 1) | ((yLow & 0x1) << 2) | ((yHigh & 0x1) << 3) | ((zLow & 0x1) << 4) | ((zHigh & 0x1) << 5) | ((interruptActive & 0x1) << 6); }
282  void setValue(long val)
283  {
284  xLow = (int)((val >> 0) & 0x1);
285  xHigh = (int)((val >> 1) & 0x1);
286  yLow = (int)((val >> 2) & 0x1);
287  yHigh = (int)((val >> 3) & 0x1);
288  zLow = (int)((val >> 4) & 0x1);
289  zHigh = (int)((val >> 5) & 0x1);
290  interruptActive = (int)((val >> 6) & 0x1);
291  }
292  };
293 
294  class Int1ThresholdXRegister : public Register
295  {
296  public:
297  Int1ThresholdXRegister(RegisterManager& regManager) : Register(regManager,0x32, 2, true) { }
298  int value;
299 
300  long getValue() { return ((value & 0xFFFF) << 0); }
301  void setValue(long val)
302  {
303  value = (int)(((val >> 0) & 0xFFFF) << (32 - 16)) >> (32 - 16);
304  }
305  };
306 
307  class Int1ThresholdYRegister : public Register
308  {
309  public:
310  Int1ThresholdYRegister(RegisterManager& regManager) : Register(regManager,0x34, 2, true) { }
311  int value;
312 
313  long getValue() { return ((value & 0xFFFF) << 0); }
314  void setValue(long val)
315  {
316  value = (int)(((val >> 0) & 0xFFFF) << (32 - 16)) >> (32 - 16);
317  }
318  };
319 
320  class Int1ThresholdZRegister : public Register
321  {
322  public:
323  Int1ThresholdZRegister(RegisterManager& regManager) : Register(regManager,0x36, 2, true) { }
324  int value;
325 
326  long getValue() { return ((value & 0xFFFF) << 0); }
327  void setValue(long val)
328  {
329  value = (int)(((val >> 0) & 0xFFFF) << (32 - 16)) >> (32 - 16);
330  }
331  };
332 
333  class Int1DurationRegister : public Register
334  {
335  public:
336  Int1DurationRegister(RegisterManager& regManager) : Register(regManager,0x38, 1, false) { }
337  int duration;
338  int wait;
339 
340  long getValue() { return ((duration & 0x7F) << 0) | ((wait & 0x1) << 7); }
341  void setValue(long val)
342  {
343  duration = (int)((val >> 0) & 0x7F);
344  wait = (int)((val >> 7) & 0x1);
345  }
346  };
347 
348  class OutXRegister : public Register
349  {
350  public:
351  OutXRegister(RegisterManager& regManager) : Register(regManager,0xA8, 2, false) { }
352  int value;
353 
354  long getValue() { return ((value & 0xFFFF) << 0); }
355  void setValue(long val)
356  {
357  value = (int)(((val >> 0) & 0xFFFF) << (32 - 16)) >> (32 - 16);
358  }
359  };
360 
361  class OutYRegister : public Register
362  {
363  public:
364  OutYRegister(RegisterManager& regManager) : Register(regManager,0xAA, 2, false) { }
365  int value;
366 
367  long getValue() { return ((value & 0xFFFF) << 0); }
368  void setValue(long val)
369  {
370  value = (int)(((val >> 0) & 0xFFFF) << (32 - 16)) >> (32 - 16);
371  }
372  };
373 
374  class OutZRegister : public Register
375  {
376  public:
377  OutZRegister(RegisterManager& regManager) : Register(regManager,0xAC, 2, false) { }
378  int value;
379 
380  long getValue() { return ((value & 0xFFFF) << 0); }
381  void setValue(long val)
382  {
383  value = (int)(((val >> 0) & 0xFFFF) << (32 - 16)) >> (32 - 16);
384  }
385  };
386 
387  WhoAmIRegister whoAmI;
388  CtrlReg1Register ctrlReg1;
389  CtrlReg2Register ctrlReg2;
390  CtrlReg3Register ctrlReg3;
391  CtrlReg4Register ctrlReg4;
392  CtrlReg5Register ctrlReg5;
393  ReferenceDataCaptureRegister referenceDataCapture;
394  OutTempRegister outTemp;
395  StatusRegister status;
396  FifoCtrlRegister fifoCtrl;
397  FifoSrcRegister fifoSrc;
398  IntConfigRegister intConfig;
399  Int1SrcRegister int1Src;
400  Int1ThresholdXRegister int1ThresholdX;
401  Int1ThresholdYRegister int1ThresholdY;
402  Int1ThresholdZRegister int1ThresholdZ;
403  Int1DurationRegister int1Duration;
404  OutXRegister outX;
405  OutYRegister outY;
406  OutZRegister outZ;
407 
408  L3gd20Registers(SMBusDevice& device) : RegisterManager(device, true), whoAmI(*this), ctrlReg1(*this), ctrlReg2(*this), ctrlReg3(*this), ctrlReg4(*this), ctrlReg5(*this), referenceDataCapture(*this), outTemp(*this), status(*this), fifoCtrl(*this), fifoSrc(*this), intConfig(*this), int1Src(*this), int1ThresholdX(*this), int1ThresholdY(*this), int1ThresholdZ(*this), int1Duration(*this), outX(*this), outY(*this), outZ(*this)
409  {
410  registers.push_back(&whoAmI);
411  registers.push_back(&ctrlReg1);
412  registers.push_back(&ctrlReg2);
413  registers.push_back(&ctrlReg3);
414  registers.push_back(&ctrlReg4);
415  registers.push_back(&ctrlReg5);
416  registers.push_back(&referenceDataCapture);
417  registers.push_back(&outTemp);
418  registers.push_back(&status);
419  registers.push_back(&fifoCtrl);
420  registers.push_back(&fifoSrc);
421  registers.push_back(&intConfig);
422  registers.push_back(&int1Src);
423  registers.push_back(&int1ThresholdX);
424  registers.push_back(&int1ThresholdY);
425  registers.push_back(&int1ThresholdZ);
426  registers.push_back(&int1Duration);
427  registers.push_back(&outX);
428  registers.push_back(&outY);
429  registers.push_back(&outZ);
430  }
431  };
432  } } } }
Definition: Dm632.h:9
Definition: Register.h:11
Definition: RegisterManager.h:10
FifoModes
Definition: L3gd20Registers.h:20
Definition: AdcPin.h:3
DataRates
Definition: L3gd20Registers.h:12