sensor_epsonG320.c
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // sensor_epsonG320.c - Epson IMU sensor protocol specific code for
4 // G320
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
9 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 // NONINFRINGEMENT, SECURITY, SATISFACTORY QUALITY, AND FITNESS FOR A
11 // PARTICULAR PURPOSE. IN NO EVENT SHALL EPSON BE LIABLE FOR ANY LOSS, DAMAGE
12 // OR CLAIM, ARISING FROM OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF THE
13 // SOFTWARE.
14 //
15 //==============================================================================
16 #include "hcl.h"
17 #include "hcl_gpio.h"
18 #include "sensor_epsonCommon.h"
19 
20 /*****************************************************************************
21 ** Function name: sensorInitOptions
22 ** Description: Initialize the sensor hardware to desired settings
23 ** based on EpsonOptions
24 ** Parameters: struct EpsonOptions
25 ** Return value: OK or NG
26 **
27 *****************************************************************************/
28 int sensorInitOptions(struct EpsonOptions options) {
29  unsigned int debug = FALSE;
30 
31  // SIG_CTRL
32  // ND flags for gyro_out X,Y,Z are enabled if gyro_out is enabled
33  // ND flags for accel_out X,Y,Z are enabled if accel_out is enabled
34  // ND flag for temp_out is enabled if temp_out is enabled
35 
36  int sig_ctrl_hi =
37  (options.accel_out & 0x01) << 1 | (options.accel_out & 0x01) << 2 |
38  (options.accel_out & 0x01) << 3 | (options.gyro_out & 0x01) << 4 |
39  (options.gyro_out & 0x01) << 5 | (options.gyro_out & 0x01) << 6 |
40  (options.temp_out & 0x01) << 7;
41 
42  // MSC_CTRL
43  // Configure DRDY function (if needed) & EXT pin function on GPIO2 (if needed)
44  // External Counter Reset is typically used when GPIO2 is connected to a
45  // PPS-like signal
46 
47  int msc_ctrl_lo =
48  (options.drdy_pol & 0x01) << 1 | (options.drdy_on & 0x01) << 2 |
49  (options.ext_pol & 0x01) << 5 | (options.ext_sel & 0x03) << 6;
50 
51  // SMPL_CTRL
52  // Configures the Data Output Rate of the IMU.
53  // Refer to Datasheet for valid Data Output Rate & Filter Setting combinations
54 
55  int smpl_ctrl_hi = (options.dout_rate & 0x0F);
56 
57  // FILTER_CTRL
58  // Configures the FIR filter of the IMU.
59  // Refer to Datasheet for valid Data Output Rate & Filter Setting combinations
60  // If External Trigger is enabled on GPIO2, then it is recommended to set the
61  // the FILTER_SEL=0. And program the GYRO_LPF_FC & ACCL_LPF_FC to meet Nyquist
62  // based on the Trigger Frequency.
63 
64  int filter_ctrl_lo = (options.filter_sel & 0x1F);
65 
66  // G354/G364/G320
67  // BURST_CTRL1
68  // These enable or disable certain data fields in the burst read packet
69 
70  int burst_ctrl1_lo = (options.checksum_out & 0x1) |
71  (options.count_out & 0x1) << 1 |
72  (options.gpio_out & 0x01) << 2;
73 
74  int burst_ctrl1_hi =
75  (options.accel_out & 0x01) << 4 | (options.gyro_out & 0x01) << 5 |
76  (options.temp_out & 0x01) << 6 | (options.flag_out & 0x01) << 7;
77 
78  // BURST_CTRL2
79  // If certain data fields are enabled, these bits determine if the
80  // data fields are 16 or 32 bit
81 
82  int burst_ctrl2_hi = (options.accel_bit & 0x01) << 4 |
83  (options.gyro_bit & 0x01) << 5 |
84  (options.temp_bit & 0x01) << 6;
85 
86  // POL_CTRL
87  // If these bits are set, then the axis values are reverse polarity
88 
89  int pol_ctrl_lo =
90  (options.invert_zaccel & 0x01) << 1 |
91  (options.invert_yaccel & 0x01) << 2 |
92  (options.invert_xaccel & 0x01) << 3 | (options.invert_zgyro & 0x01) << 4 |
93  (options.invert_ygyro & 0x01) << 5 | (options.invert_xgyro & 0x01) << 6;
94 
95  registerWriteByte(CMD_WINDOW1, ADDR_SIG_CTRL_HI, sig_ctrl_hi, debug);
96  registerWriteByte(CMD_WINDOW1, ADDR_MSC_CTRL_LO, msc_ctrl_lo, debug);
97  registerWriteByte(CMD_WINDOW1, ADDR_SMPL_CTRL_HI, smpl_ctrl_hi, debug);
98  registerWriteByte(CMD_WINDOW1, ADDR_POL_CTRL_LO, pol_ctrl_lo, debug);
99  registerWriteByte(CMD_WINDOW1, ADDR_FILTER_CTRL_LO, filter_ctrl_lo, debug);
100 
101  // All models except V340
102  // Delay for filter config
104 
105  // Check that the FILTER_BUSY bit returns 0
106  unsigned short rxData;
107  unsigned short retryCount = 3000;
108  do {
110  retryCount--;
111  } while ((rxData & 0x0020) == 0x0020 && (retryCount != 0));
112 
113  if (retryCount == 0) {
114  printf("\r\n...Error: Filter busy bit did not return to 0b.");
115  return NG;
116  }
117 
118 #ifdef SPI // Always disable UART_AUTO mode for burst reading when using SPI IF
120 #else
122 #endif
123 
124  registerWriteByte(CMD_WINDOW1, ADDR_BURST_CTRL1_LO, burst_ctrl1_lo, debug);
125  registerWriteByte(CMD_WINDOW1, ADDR_BURST_CTRL1_HI, burst_ctrl1_hi, debug);
126  registerWriteByte(CMD_WINDOW1, ADDR_BURST_CTRL2_HI, burst_ctrl2_hi, debug);
127 
128  return OK;
129 }
130 
131 /*****************************************************************************
132 ** Function name: registerDump
133 ** Description: Read all registers for debug purpose
134 ** Parameters: None
135 ** Return value: None
136 *****************************************************************************/
137 void registerDump(void) {
138  unsigned int debug = TRUE;
139  printf("\r\nRegister Dump:\r\n");
140  registerRead16(0x00, 0x02, debug);
141  registerRead16(0x00, 0x04, debug);
142  registerRead16(0x00, 0x06, debug);
143  printf("\r\n");
144  registerRead16(0x00, 0x08, debug);
145  registerRead16(0x00, 0x0A, debug);
146  registerRead16(0x00, 0x0E, debug);
147  printf("\r\n");
148  registerRead16(0x00, 0x10, debug);
149  registerRead16(0x00, 0x12, debug);
150  registerRead16(0x00, 0x14, debug);
151  printf("\r\n");
152  registerRead16(0x00, 0x16, debug);
153  registerRead16(0x00, 0x18, debug);
154  registerRead16(0x00, 0x1A, debug);
155  printf("\r\n");
156  registerRead16(0x00, 0x1C, debug);
157  registerRead16(0x00, 0x1E, debug);
158  registerRead16(0x00, 0x20, debug);
159  printf("\r\n");
160  registerRead16(0x00, 0x22, debug);
161  registerRead16(0x00, 0x24, debug);
162  registerRead16(0x00, 0x26, debug);
163  printf("\r\n");
164  registerRead16(0x00, 0x28, debug);
165  registerRead16(0x01, 0x00, debug);
166  registerRead16(0x01, 0x02, debug);
167  printf("\r\n");
168  registerRead16(0x01, 0x04, debug);
169  registerRead16(0x01, 0x06, debug);
170  registerRead16(0x01, 0x08, debug);
171  printf("\r\n");
172  registerRead16(0x01, 0x0A, debug);
173  registerRead16(0x01, 0x0C, debug);
174  registerRead16(0x01, 0x0E, debug);
175  printf("\r\n");
176  registerRead16(0x01, 0x10, debug);
177  registerRead16(0x01, 0x6A, debug);
178  registerRead16(0x01, 0x6C, debug);
179  printf("\r\n");
180  registerRead16(0x01, 0x6E, debug);
181  registerRead16(0x01, 0x70, debug);
182  registerRead16(0x01, 0x72, debug);
183  printf("\r\n");
184  registerRead16(0x01, 0x74, debug);
185  registerRead16(0x01, 0x76, debug);
186  registerRead16(0x01, 0x78, debug);
187  printf("\r\n");
188  registerRead16(0x01, 0x7A, debug);
189  registerRead16(0x01, 0x7E, debug);
190  printf("\r\n");
191 }
int sensorInitOptions(struct EpsonOptions options)
#define ADDR_BURST_CTRL2_HI
#define ADDR_SIG_CTRL_HI
#define ADDR_MSC_CTRL_LO
#define EPSON_FILTER_DELAY
#define ADDR_BURST_CTRL1_HI
#define CMD_WINDOW1
#define ADDR_SMPL_CTRL_HI
#define OK
Definition: hcl.h:29
#define NG
Definition: hcl.h:33
void registerDump(void)
#define FALSE
#define TRUE
unsigned short registerRead16(unsigned char, unsigned char, unsigned int)
void registerWriteByte(unsigned char, unsigned char, unsigned char, unsigned int)
#define ADDR_UART_CTRL_LO
#define ADDR_FILTER_CTRL_LO
void seDelayMS(uint32_t millis)
Definition: hcl_linux.c:46
#define ADDR_POL_CTRL_LO
#define ADDR_BURST_CTRL1_LO


ess_imu_ros1_uart_driver
Author(s):
autogenerated on Sun Jun 4 2023 02:59:29