sensor_epsonG364.c
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // sensor_epsonG364.c - Epson IMU sensor protocol specific code for
4 // G364
5 //
6 //
7 // THE SOFTWARE IS RELEASED INTO THE PUBLIC DOMAIN.
8 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
9 // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT,
10 // SECURITY, SATISFACTORY QUALITY, AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
11 // SHALL EPSON BE LIABLE FOR ANY LOSS, DAMAGE OR CLAIM, ARISING FROM OR IN CONNECTION
12 // WITH THE SOFTWARE OR THE USE OF THE SOFTWARE.
13 //
14 //==============================================================================
15 #include "sensor_epsonCommon.h"
16 #include "hcl.h"
17 #include "hcl_gpio.h"
18 
19 int sensorInitOptions(struct EpsonOptions options){
20  unsigned short rxData;
21  unsigned int debug = FALSE;
22  unsigned short retryCount = 3000;
23 
24  // Safety Measure, Incase Device is in Sampling Mode, goto Config Mode
25  /*do
26  {
27  registerWriteByte(CMD_WINDOW0, ADDR_MODE_CTRL_HI, CMD_END_SAMPLING, debug);
28  rxData = registerRead16(CMD_WINDOW0, ADDR_MODE_CTRL_LO, debug);
29  seDelayMicroSecs(1000);
30  retryCount--;
31  } while((rxData & 0x0400) == 0x0000 && (retryCount != 0));
32 
33  if (retryCount == 0)
34  {
35  printf("\r\n...Error: Stuck in Sampling Mode.");
36  return FALSE;
37  }*/
38 
39  // SIG_CTRL
40  int SIG_CTRL_LO = (options.enable_zgyro_delta & 0x01) << 2 |
41  (options.enable_ygyro_delta & 0x01) << 3 |
42  (options.enable_xgyro_delta & 0x01) << 4 |
43  (options.enable_zaccel_delta & 0x01) << 5 |
44  (options.enable_yaccel_delta & 0x01) << 6 |
45  (options.enable_xaccel_delta & 0x01) << 7;
46 
47  int SIG_CTRL_HI = (options.enable_zaccel & 0x01) << 1 |
48  (options.enable_yaccel & 0x01) << 2 |
49  (options.enable_xaccel & 0x01) << 3 |
50  (options.enable_zgyro & 0x01) << 4 |
51  (options.enable_ygyro & 0x01) << 5 |
52  (options.enable_xgyro & 0x01) << 6 |
53  (options.enable_temp & 0x01) << 7;
54 
55  // MSC_CTRL
56  int MSC_CTRL_LO = (options.drdy_pol & 0x01) << 1 |
57  (options.drdy_on & 0x01) << 2 |
58  (options.ext_pol & 0x01) << 5 |
59  (options.ext_sel & 0x03) << 6;
60 
61  int MSC_CTRL_HI = (options.self_test & 0x01) << 2 |
62  (options.flash_test & 0x01) << 3;
63 
64  // SMPL_CTRL
65  int SMPL_CTRL_HI = options.dout_rate & 0xFF;
66 
67  // FILTER_CTRL
68  int FILTER_CTRL_LO = (options.filter_sel & 0x1F);
69 
70  // UART_CTRL
71  int UART_CTRL_LO = (options.uart_auto & 0x01) |
72  (options.auto_start & 0x01) << 1;
73 
74  int UART_CTRL_HI = options.baud_rate & 0x01;
75 
76  // BURST_CTRL1
77  int BURST_CTRL1_LO = (options.checksum_out & 0x1) |
78  (options.count_out & 0x1) << 1 |
79  (options.gpio_out & 0x01) << 2;
80 
81  int BURST_CTRL1_HI = (options.gyro_delta_out & 0x1) << 2 |
82  (options.accel_delta_out & 0x01) << 3 |
83  (options.accel_out & 0x01) << 4 |
84  (options.gyro_out & 0x01) << 5 |
85  (options.temp_out & 0x01) << 6 |
86  (options.flag_out & 0x01) << 7;
87 
88  // BURST_CTRL2
89  int BURST_CTRL2_HI = (options.gyro_delta_bit & 0x01) << 2 |
90  (options.accel_delta_bit & 0x01) << 3 |
91  (options.accel_bit & 0x01) << 4 |
92  (options.gyro_bit & 0x01) << 5 |
93  (options.temp_bit & 0x01) << 6;
94 
95  // POL_CTRL
96  int POL_CTRL_LO = (options.invert_zaccel & 0x01) << 1 |
97  (options.invert_yaccel & 0x01) << 2 |
98  (options.invert_xaccel & 0x01) << 3 |
99  (options.invert_zgyro & 0x01) << 4 |
100  (options.invert_ygyro & 0x01) << 5 |
101  (options.invert_xgyro & 0x01) << 6;
102 
103  // DLT_CTRL
104  int DLT_CTRL_HI = (options.dlt_ovf_en & 0x01) << 1;
105  int DLT_CTRL_LO = (options.dlt_range_ctrl & 0x0F);
106 
107  printf("%d: %d\n%d: %d\n%d: %d\n%d: %d\n%d: %d\n%d: %d\n%d: %d\n%d: %d\n%d: %d\n",
108  ADDR_SIG_CTRL_HI, SIG_CTRL_HI,
109  ADDR_MSC_CTRL_LO, MSC_CTRL_LO,
110  ADDR_SMPL_CTRL_HI, SMPL_CTRL_HI,
111  ADDR_POL_CTRL_LO, POL_CTRL_LO,
112  ADDR_FILTER_CTRL_LO, FILTER_CTRL_LO,
113  ADDR_UART_CTRL_LO, UART_CTRL_LO,
114  ADDR_BURST_CTRL1_LO, BURST_CTRL1_LO,
115  ADDR_BURST_CTRL1_HI, BURST_CTRL1_HI,
116  ADDR_BURST_CTRL2_HI, BURST_CTRL2_HI);
117 
118  registerWriteByte(CMD_WINDOW1, ADDR_SIG_CTRL_HI, SIG_CTRL_HI, debug);
119 
120  registerWriteByte(CMD_WINDOW1, ADDR_MSC_CTRL_LO, MSC_CTRL_LO, debug);
121 
122  registerWriteByte(CMD_WINDOW1, ADDR_SMPL_CTRL_HI, SMPL_CTRL_HI, debug);
123 
124  registerWriteByte(CMD_WINDOW1, ADDR_POL_CTRL_LO, POL_CTRL_LO, debug);
125 
126  registerWriteByte(CMD_WINDOW1, ADDR_FILTER_CTRL_LO, FILTER_CTRL_LO, debug);
127 
128  // Delay for filter config
130 
131  retryCount = 3000;
132  do{
134  retryCount--;
135  } while((rxData & 0x0020) == 0x0020 && (retryCount != 0));
136 
137  if (retryCount == 0){
138  printf("\r\n...Error: Filter busy bit did not return to 0b.");
139  return FALSE;
140  }
141 
142  registerWriteByte(CMD_WINDOW1, ADDR_UART_CTRL_LO, UART_CTRL_LO, debug);
143 
144  registerWriteByte(CMD_WINDOW1, ADDR_BURST_CTRL1_LO, BURST_CTRL1_LO, debug);
145 
146  registerWriteByte(CMD_WINDOW1, ADDR_BURST_CTRL1_HI, BURST_CTRL1_HI, debug);
147 
148  registerWriteByte(CMD_WINDOW1, ADDR_BURST_CTRL2_HI, BURST_CTRL2_HI, debug);
149 
150  registerWriteByte(CMD_WINDOW1, ADDR_DLT_CTRL_HI, DLT_CTRL_HI, debug);
151 
152  registerWriteByte(CMD_WINDOW1, ADDR_DLT_CTRL_LO, DLT_CTRL_LO, debug);
153 
154  return TRUE; /* success */
155 }
156 
157 /*****************************************************************************
158 ** Function name: sensorInit
159 ** Description: Initialize the sensor hardware to desired settings
160 ** Data Output Rate, Filter Setting, Burst Read Sensor Data
161 ** Parameters: None
162 ** Return value: 1=success, 0=fail
163 *****************************************************************************/
164 int sensorInit(void)
165 {
166  unsigned short rxData;
167  unsigned int debug = FALSE;
168  unsigned short retryCount = 3000;
169 
170  printf("%d: %d\n%d: %d\n%d: %d\n%d: %d\n%d: %d\n%d: %d\n%d: %d\n%d: %d\n%d: %d\n",
174  ADDR_POL_CTRL_LO, 0x00,
176  ADDR_UART_CTRL_LO, 0x01,
180  return FALSE;
181  // Safety Measure, Incase Device is in Sampling Mode, goto Config Mode
182  do
183  {
185  rxData = registerRead16(CMD_WINDOW0, ADDR_MODE_CTRL_LO, debug);
186  seDelayMicroSecs(1000);
187  retryCount--;
188  } while((rxData & 0x0400) == 0x0000 && (retryCount != 0));
189 
190  if (retryCount == 0)
191  {
192  printf("\r\n...Error: Stuck in Sampling Mode.");
193  return FALSE;
194  }
195 
196  // POL_CTRL = Not Inverted
198 
199  // Enable new data flags for gyros and accls
201 
202  // EXT=Reset Counter, EXT_POL=Positive Logic, DRDY_ON=Data_Ready, DRDY_POL = Active Low
204 
205  // Set samples per second to 125
207 
208  // Filter TAP = 16
210 
211  // Delay for filter config
213 
214  retryCount = 3000;
215  do{
217  retryCount--;
218  } while((rxData & 0x0020) == 0x0020 && (retryCount != 0));
219 
220  if (retryCount == 0){
221  printf("\r\n...Error: Filter busy bit did not return to 0b.");
222  return FALSE;
223  }
224 
225  // AUTO_START=Disable, UART_AUTO=Enable (For UART Interface)
227 
228  // Enable COUNT and CHKSM data for burst mode
230 
231  // Enable GYRO and ACCL data for burst mode
233 
234  // Enable 32-bit Output for Gyro & Accel
236 
237  return TRUE; /* success */
238 }
239 
240 
241 /*****************************************************************************
242 ** Function name: registerDump
243 ** Description: Read all registers for debug purpose
244 ** Parameters: None
245 ** Return value: None
246 *****************************************************************************/
247 void registerDump(void)
248 {
249  unsigned int debug = TRUE;
250  printf("\r\nRegister Dump:\r\n");
251  registerRead16(0x00, 0x02, debug);
252  registerRead16(0x00, 0x04, debug);
253  registerRead16(0x00, 0x06, debug);
254  printf("\r\n");
255  registerRead16(0x00, 0x08, debug);
256  registerRead16(0x00, 0x0A, debug);
257  registerRead16(0x00, 0x0E, debug);
258  printf("\r\n");
259  registerRead16(0x00, 0x10, debug);
260  registerRead16(0x00, 0x12, debug);
261  registerRead16(0x00, 0x14, debug);
262  printf("\r\n");
263  registerRead16(0x00, 0x16, debug);
264  registerRead16(0x00, 0x18, debug);
265  registerRead16(0x00, 0x1A, debug);
266  printf("\r\n");
267  registerRead16(0x00, 0x1C, debug);
268  registerRead16(0x00, 0x1E, debug);
269  registerRead16(0x00, 0x20, debug);
270  printf("\r\n");
271  registerRead16(0x00, 0x22, debug);
272  registerRead16(0x00, 0x24, debug);
273  registerRead16(0x00, 0x26, debug);
274  printf("\r\n");
275  registerRead16(0x00, 0x28, debug);
276  registerRead16(0x00, 0x64, debug);
277  registerRead16(0x00, 0x68, debug);
278  printf("\r\n");
279  registerRead16(0x00, 0x6C, debug);
280  registerRead16(0x00, 0x6E, debug);
281  registerRead16(0x00, 0x70, debug);
282  printf("\r\n");
283  registerRead16(0x00, 0x72, debug);
284  registerRead16(0x00, 0x74, debug);
285  registerRead16(0x00, 0x76, debug);
286  printf("\r\n");
287  registerRead16(0x00, 0x78, debug);
288  registerRead16(0x00, 0x7A, debug);
289  printf("\r\n");
290  registerRead16(0x01, 0x00, debug);
291  registerRead16(0x01, 0x02, debug);
292  printf("\r\n");
293  registerRead16(0x01, 0x04, debug);
294  registerRead16(0x01, 0x06, debug);
295  registerRead16(0x01, 0x08, debug);
296  printf("\r\n");
297  registerRead16(0x01, 0x0A, debug);
298  registerRead16(0x01, 0x0C, debug);
299  registerRead16(0x01, 0x0E, debug);
300  printf("\r\n");
301  registerRead16(0x01, 0x6A, debug);
302  registerRead16(0x01, 0x6C, debug);
303  registerRead16(0x01, 0x6E, debug);
304  printf("\r\n");
305  registerRead16(0x01, 0x70, debug);
306  registerRead16(0x01, 0x72, debug);
307  registerRead16(0x01, 0x74, debug);
308  printf("\r\n");
309  registerRead16(0x01, 0x76, debug);
310  registerRead16(0x01, 0x78, debug);
311  registerRead16(0x01, 0x7A, debug);
312  printf("\r\n");
313  registerRead16(0x01, 0x7E, debug);
314  printf("\r\n");
315 }
void registerDump(void)
#define ADDR_BURST_CTRL2_HI
#define ADDR_DLT_CTRL_HI
#define ADDR_SIG_CTRL_HI
#define ADDR_MSC_CTRL_LO
#define CMD_EN_BRSTDATA_HI
#define EPSON_FILTER_DELAY
#define CMD_EN_NDFLAGS
int sensorInitOptions(struct EpsonOptions options)
#define CMD_RSTCNTR_DRDY
#define ADDR_BURST_CTRL1_HI
#define CMD_RATE125
#define CMD_WINDOW1
#define FALSE
Definition: hcl_uart.c:32
#define ADDR_SMPL_CTRL_HI
#define TRUE
Definition: hcl_uart.c:31
#define CMD_EN_BRSTDATA_LO
#define ADDR_DLT_CTRL_LO
#define CMD_WINDOW0
#define ADDR_MODE_CTRL_HI
#define ADDR_MODE_CTRL_LO
void seDelayMicroSecs(uint32_t micros)
Definition: hcl_linux.c:67
unsigned short registerRead16(unsigned char, unsigned char, unsigned int)
void registerWriteByte(unsigned char, unsigned char, unsigned char, unsigned int)
#define CMD_END_SAMPLING
int sensorInit(void)
#define CMD_FLTAP16
#define ADDR_UART_CTRL_LO
#define ADDR_FILTER_CTRL_LO
void seDelayMS(uint32_t millis)
Definition: hcl_linux.c:54
#define ADDR_POL_CTRL_LO
#define CMD_32BIT
#define ADDR_BURST_CTRL1_LO


epson_g364_imu_driver
Author(s):
autogenerated on Mon Jun 10 2019 13:12:32