sensor_epsonG370.c
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // sensor_epsonG370.c - Epson IMU sensor protocol specific code for G370
4 //
5 //
6 // THE SOFTWARE IS RELEASED INTO THE PUBLIC DOMAIN.
7 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
8 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9 // NONINFRINGEMENT, SECURITY, SATISFACTORY QUALITY, AND FITNESS FOR A
10 // PARTICULAR PURPOSE. IN NO EVENT SHALL EPSON BE LIABLE FOR ANY LOSS, DAMAGE
11 // OR CLAIM, ARISING FROM OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF THE
12 // SOFTWARE.
13 //
14 //==============================================================================
15 #include "hcl.h"
16 #include "hcl_gpio.h"
17 #include "sensor_epsonCommon.h"
18 
19 /*****************************************************************************
20 ** Function name: sensorInitOptions
21 ** Description: Initialize the sensor hardware to desired settings
22 ** based on EpsonOptions
23 ** Parameters: struct EpsonOptions
24 ** Return value: OK or NG
25 **
26 *****************************************************************************/
27 int sensorInitOptions(struct EpsonOptions options) {
28  unsigned int debug = FALSE;
29 
30  // SIG_CTRL
31  // ND flags for gyro_delta_out X,Y,Z are enabled if gyro_delta_out is enabled
32  // ND flags for accel_delta_out X,Y,Z are enabled if accel_delta_out is
33  // enabled
34 
35  int sig_ctrl_lo = (options.gyro_delta_out & 0x01) << 2 |
36  (options.gyro_delta_out & 0x01) << 3 |
37  (options.gyro_delta_out & 0x01) << 4 |
38  (options.accel_delta_out & 0x01) << 5 |
39  (options.accel_delta_out & 0x01) << 6 |
40  (options.accel_delta_out & 0x01) << 7;
41 
42  // ND flags for gyro_out X,Y,Z are enabled if gyro_out is enabled
43  // ND flags for accel_out X,Y,Z are enabled if accel_out is enabled
44  // ND flag for temp_out is enabled if temp_out is enabled
45 
46  int sig_ctrl_hi =
47  (options.accel_out & 0x01) << 1 | (options.accel_out & 0x01) << 2 |
48  (options.accel_out & 0x01) << 3 | (options.gyro_out & 0x01) << 4 |
49  (options.gyro_out & 0x01) << 5 | (options.gyro_out & 0x01) << 6 |
50  (options.temp_out & 0x01) << 7;
51 
52  // MSC_CTRL
53  // Configure DRDY function (if needed) & EXT pin function on GPIO2 (if needed)
54  // External Counter Reset is typically used when GPIO2 is connected to a
55  // PPS-like signal
56 
57  int msc_ctrl_lo =
58  (options.drdy_pol & 0x01) << 1 | (options.drdy_on & 0x01) << 2 |
59  (options.ext_pol & 0x01) << 5 | (options.ext_sel & 0x03) << 6;
60 
61  // SMPL_CTRL
62  // Configures the Data Output Rate of the IMU.
63  // Refer to Datasheet for valid Data Output Rate & Filter Setting combinations
64 
65  int smpl_ctrl_hi = (options.dout_rate & 0x0F);
66 
67  // FILTER_CTRL
68  // Configures the FIR filter of the IMU.
69  // Refer to Datasheet for valid Data Output Rate & Filter Setting combinations
70  // If External Trigger is enabled on GPIO2, then it is recommended to set the
71  // the FILTER_SEL=0. And program the GYRO_LPF_FC & ACCL_LPF_FC to meet Nyquist
72  // based on the Trigger Frequency.
73 
74  int filter_ctrl_lo = (options.filter_sel & 0x1F);
75 
76  // BURST_CTRL1
77  // These enable or disable certain data fields in the burst read packet
78 
79  int burst_ctrl1_lo = (options.checksum_out & 0x1) |
80  (options.count_out & 0x1) << 1 |
81  (options.gpio_out & 0x01) << 2;
82 
83  int burst_ctrl1_hi =
84  (options.gyro_delta_out & 0x1) << 2 |
85  (options.accel_delta_out & 0x01) << 3 | (options.accel_out & 0x01) << 4 |
86  (options.gyro_out & 0x01) << 5 | (options.temp_out & 0x01) << 6 |
87  (options.flag_out & 0x01) << 7;
88 
89  // BURST_CTRL2
90  // If certain data fields are enabled, these bits determine if the
91  // data fields are 16 or 32 bit
92 
93  int burst_ctrl2_hi =
94  (options.gyro_delta_bit & 0x01) << 2 |
95  (options.accel_delta_bit & 0x01) << 3 | (options.accel_bit & 0x01) << 4 |
96  (options.gyro_bit & 0x01) << 5 | (options.temp_bit & 0x01) << 6;
97 
98  // DLT_CTRL
99  // Enable or disable Delta Angle/Velocity overflow flag in DIAG_STAT
100  // Set A_RANGE_CTRL to 1, if macro defined
101  // Set the Delta Angle/Velocity Scale Factor
102 
103 #ifdef ACCL_RANGE_16G
104  int dlt_ctrl_hi = (options.dlt_ovf_en & 0x01) << 1 | 1;
105 #else
106  int dlt_ctrl_hi = (options.dlt_ovf_en & 0x01) << 1;
107 #endif // ACCL_RANGE_16G
108  int dlt_ctrl_lo =
109  (options.dlt_range_ctrl & 0x0F) << 4 | (options.dlt_range_ctrl & 0x0F);
110 
111  // ATTI_CTRL
112  // For G370, Attitude Output is not supported.
113  // This is only for Delta Angle/Velocity function if enabled.
114 
115  int atti_ctrl_hi = (options.gyro_delta_out & 0x01) << 1;
116 
117  // POL_CTRL
118  // If these bits are set, then the axis values are reverse polarity
119 
120  int pol_ctrl_lo =
121  (options.invert_zaccel & 0x01) << 1 |
122  (options.invert_yaccel & 0x01) << 2 |
123  (options.invert_xaccel & 0x01) << 3 | (options.invert_zgyro & 0x01) << 4 |
124  (options.invert_ygyro & 0x01) << 5 | (options.invert_xgyro & 0x01) << 6;
125 
126  registerWriteByte(CMD_WINDOW1, ADDR_SIG_CTRL_HI, sig_ctrl_hi, debug);
127  registerWriteByte(CMD_WINDOW1, ADDR_SIG_CTRL_LO, sig_ctrl_lo, debug);
128  registerWriteByte(CMD_WINDOW1, ADDR_MSC_CTRL_LO, msc_ctrl_lo, debug);
129  registerWriteByte(CMD_WINDOW1, ADDR_SMPL_CTRL_HI, smpl_ctrl_hi, debug);
130  registerWriteByte(CMD_WINDOW1, ADDR_POL_CTRL_LO, pol_ctrl_lo, debug);
131  registerWriteByte(CMD_WINDOW1, ADDR_FILTER_CTRL_LO, filter_ctrl_lo, debug);
132 
133  // All models except V340
134  // Delay for filter config
136 
137  // Check that the FILTER_BUSY bit returns 0
138  unsigned short rxData;
139  unsigned short retryCount = 3000;
140  do {
142  retryCount--;
143  } while ((rxData & 0x0020) == 0x0020 && (retryCount != 0));
144 
145  if (retryCount == 0) {
146  printf("\r\n...Error: Filter busy bit did not return to 0b.");
147  return NG;
148  }
149 
150 #ifdef SPI // Always disable UART_AUTO mode for burst reading when using SPI IF
152 #else
154 #endif
155 
156  registerWriteByte(CMD_WINDOW1, ADDR_BURST_CTRL1_LO, burst_ctrl1_lo, debug);
157  registerWriteByte(CMD_WINDOW1, ADDR_BURST_CTRL1_HI, burst_ctrl1_hi, debug);
158  registerWriteByte(CMD_WINDOW1, ADDR_BURST_CTRL2_HI, burst_ctrl2_hi, debug);
159  registerWriteByte(CMD_WINDOW1, ADDR_DLT_CTRL_HI, dlt_ctrl_hi, debug);
160  registerWriteByte(CMD_WINDOW1, ADDR_DLT_CTRL_LO, dlt_ctrl_lo, debug);
161  registerWriteByte(CMD_WINDOW1, ADDR_ATTI_CTRL_HI, atti_ctrl_hi, debug);
162 
163  return OK;
164 }
165 
166 /*****************************************************************************
167 ** Function name: registerDump
168 ** Description: Read all registers for debug purpose
169 ** Parameters: None
170 ** Return value: None
171 *****************************************************************************/
172 void registerDump(void) {
173  unsigned int debug = TRUE;
174  printf("\r\nRegister Dump:\r\n");
175  registerRead16(0x00, 0x02, debug);
176  registerRead16(0x00, 0x04, debug);
177  registerRead16(0x00, 0x06, debug);
178  printf("\r\n");
179  registerRead16(0x00, 0x08, debug);
180  registerRead16(0x00, 0x0A, debug);
181  registerRead16(0x00, 0x0C, debug);
182  printf("\r\n");
183  registerRead16(0x00, 0x0E, debug);
184  registerRead16(0x00, 0x10, debug);
185  registerRead16(0x00, 0x12, debug);
186  printf("\r\n");
187  registerRead16(0x00, 0x14, debug);
188  registerRead16(0x00, 0x16, debug);
189  registerRead16(0x00, 0x18, debug);
190  printf("\r\n");
191  registerRead16(0x00, 0x1A, debug);
192  registerRead16(0x00, 0x1C, debug);
193  registerRead16(0x00, 0x1E, debug);
194  printf("\r\n");
195  registerRead16(0x00, 0x20, debug);
196  registerRead16(0x00, 0x22, debug);
197  registerRead16(0x00, 0x24, debug);
198  printf("\r\n");
199  registerRead16(0x00, 0x26, debug);
200  registerRead16(0x00, 0x28, debug);
201 
202 #if defined G370PDF1 || defined G370PDS0
203  registerRead16(0x00, 0x2B, debug);
204  registerRead16(0x00, 0x4C, debug);
205 #endif // defined G370PDF1 || defined G370PDS0
206 
207  printf("\r\n");
208  registerRead16(0x00, 0x64, debug);
209  registerRead16(0x00, 0x66, debug);
210  registerRead16(0x00, 0x68, debug);
211  printf("\r\n");
212  registerRead16(0x00, 0x6A, debug);
213  registerRead16(0x00, 0x6C, debug);
214  registerRead16(0x00, 0x6E, debug);
215  printf("\r\n");
216  registerRead16(0x00, 0x70, debug);
217  registerRead16(0x00, 0x72, debug);
218  registerRead16(0x00, 0x74, debug);
219  printf("\r\n");
220  registerRead16(0x00, 0x76, debug);
221  registerRead16(0x00, 0x78, debug);
222  registerRead16(0x00, 0x7A, debug);
223  printf("\r\n");
224  registerRead16(0x01, 0x00, debug);
225  registerRead16(0x01, 0x02, debug);
226  registerRead16(0x01, 0x04, debug);
227  printf("\r\n");
228  registerRead16(0x01, 0x06, debug);
229  registerRead16(0x01, 0x08, debug);
230  registerRead16(0x01, 0x0A, debug);
231  printf("\r\n");
232  registerRead16(0x01, 0x0C, debug);
233  registerRead16(0x01, 0x0E, debug);
234  registerRead16(0x01, 0x10, debug);
235  printf("\r\n");
236  registerRead16(0x01, 0x12, debug);
237  registerRead16(0x01, 0x14, debug);
238  registerRead16(0x01, 0x16, debug);
239  printf("\r\n");
240 
241 #ifdef G370PDF0
242  registerRead16(0x01, 0x18, debug);
243  printf("\r\n");
244 #endif // G370PDF0
245 
246  registerRead16(0x01, 0x6A, debug);
247  registerRead16(0x01, 0x6C, debug);
248  registerRead16(0x01, 0x6E, debug);
249  printf("\r\n");
250  registerRead16(0x01, 0x70, debug);
251  registerRead16(0x01, 0x72, debug);
252  registerRead16(0x01, 0x74, debug);
253  printf("\r\n");
254  registerRead16(0x01, 0x76, debug);
255  registerRead16(0x01, 0x78, debug);
256  registerRead16(0x01, 0x7A, debug);
257  printf("\r\n");
258  registerRead16(0x01, 0x7E, debug);
259  printf("\r\n");
260 }
EpsonOptions::invert_xgyro
int invert_xgyro
Definition: sensor_epsonCommon.h:107
EpsonOptions::accel_delta_bit
int accel_delta_bit
Definition: sensor_epsonCommon.h:102
sensor_epsonCommon.h
TRUE
#define TRUE
Definition: sensor_epsonCommon.h:23
EpsonOptions::ext_pol
int ext_pol
Definition: sensor_epsonCommon.h:73
ADDR_BURST_CTRL2_HI
#define ADDR_BURST_CTRL2_HI
Definition: sensor_epsonG320.h:126
EpsonOptions::drdy_on
int drdy_on
Definition: sensor_epsonCommon.h:74
EpsonOptions::ext_sel
int ext_sel
Definition: sensor_epsonCommon.h:72
EpsonOptions::filter_sel
int filter_sel
Definition: sensor_epsonCommon.h:81
EpsonOptions::invert_ygyro
int invert_ygyro
Definition: sensor_epsonCommon.h:108
ADDR_SIG_CTRL_HI
#define ADDR_SIG_CTRL_HI
Definition: sensor_epsonG320.h:112
seDelayMS
void seDelayMS(uint32_t millis)
Definition: hcl_linux.c:46
registerRead16
unsigned short registerRead16(unsigned char, unsigned char, unsigned int)
Definition: sensor_epsonUart.c:167
registerWriteByte
void registerWriteByte(unsigned char, unsigned char, unsigned char, unsigned int)
Definition: sensor_epsonUart.c:105
EpsonOptions::temp_bit
int temp_bit
Definition: sensor_epsonCommon.h:98
hcl_gpio.h
EpsonOptions::drdy_pol
int drdy_pol
Definition: sensor_epsonCommon.h:75
EpsonOptions::gpio_out
int gpio_out
Definition: sensor_epsonCommon.h:93
EpsonOptions
Definition: sensor_epsonCommon.h:70
EpsonOptions::dout_rate
int dout_rate
Definition: sensor_epsonCommon.h:78
ADDR_POL_CTRL_LO
#define ADDR_POL_CTRL_LO
Definition: sensor_epsonG320.h:127
hcl.h
EpsonOptions::gyro_bit
int gyro_bit
Definition: sensor_epsonCommon.h:99
ADDR_BURST_CTRL1_LO
#define ADDR_BURST_CTRL1_LO
Definition: sensor_epsonG320.h:123
EpsonOptions::accel_out
int accel_out
Definition: sensor_epsonCommon.h:87
registerDump
void registerDump(void)
Definition: sensor_epsonG370.c:172
CMD_WINDOW1
#define CMD_WINDOW1
Definition: sensor_epsonG320.h:143
ADDR_BURST_CTRL1_HI
#define ADDR_BURST_CTRL1_HI
Definition: sensor_epsonG320.h:124
ADDR_DLT_CTRL_HI
#define ADDR_DLT_CTRL_HI
Definition: sensor_epsonG330PDG0.h:166
EpsonOptions::invert_yaccel
int invert_yaccel
Definition: sensor_epsonCommon.h:111
EpsonOptions::count_out
int count_out
Definition: sensor_epsonCommon.h:94
EpsonOptions::flag_out
int flag_out
Definition: sensor_epsonCommon.h:84
EpsonOptions::checksum_out
int checksum_out
Definition: sensor_epsonCommon.h:95
EpsonOptions::invert_zgyro
int invert_zgyro
Definition: sensor_epsonCommon.h:109
sensorInitOptions
int sensorInitOptions(struct EpsonOptions options)
Definition: sensor_epsonG370.c:27
ADDR_FILTER_CTRL_LO
#define ADDR_FILTER_CTRL_LO
Definition: sensor_epsonG320.h:117
ADDR_ATTI_CTRL_HI
#define ADDR_ATTI_CTRL_HI
Definition: sensor_epsonG330PDG0.h:168
EpsonOptions::gyro_delta_out
int gyro_delta_out
Definition: sensor_epsonCommon.h:88
EpsonOptions::dlt_ovf_en
int dlt_ovf_en
Definition: sensor_epsonCommon.h:115
EpsonOptions::gyro_out
int gyro_out
Definition: sensor_epsonCommon.h:86
FALSE
#define FALSE
Definition: sensor_epsonCommon.h:27
EpsonOptions::temp_out
int temp_out
Definition: sensor_epsonCommon.h:85
ADDR_MSC_CTRL_LO
#define ADDR_MSC_CTRL_LO
Definition: sensor_epsonG320.h:113
EpsonOptions::accel_bit
int accel_bit
Definition: sensor_epsonCommon.h:100
ADDR_DLT_CTRL_LO
#define ADDR_DLT_CTRL_LO
Definition: sensor_epsonG330PDG0.h:165
NG
#define NG
Definition: hcl.h:33
ADDR_SMPL_CTRL_HI
#define ADDR_SMPL_CTRL_HI
Definition: sensor_epsonG320.h:116
EPSON_FILTER_DELAY
#define EPSON_FILTER_DELAY
Definition: sensor_epsonCommon.h:64
ADDR_UART_CTRL_LO
#define ADDR_UART_CTRL_LO
Definition: sensor_epsonG320.h:119
EpsonOptions::invert_zaccel
int invert_zaccel
Definition: sensor_epsonCommon.h:112
EpsonOptions::accel_delta_out
int accel_delta_out
Definition: sensor_epsonCommon.h:89
OK
#define OK
Definition: hcl.h:29
EpsonOptions::invert_xaccel
int invert_xaccel
Definition: sensor_epsonCommon.h:110
EpsonOptions::gyro_delta_bit
int gyro_delta_bit
Definition: sensor_epsonCommon.h:101
EpsonOptions::dlt_range_ctrl
int dlt_range_ctrl
Definition: sensor_epsonCommon.h:116
ADDR_SIG_CTRL_LO
#define ADDR_SIG_CTRL_LO
Definition: sensor_epsonG320.h:111


ess_imu_ros1_uart_driver
Author(s):
autogenerated on Sun Dec 3 2023 03:11:33