sensor_epsonV340.c
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // sensor_epsonV340.c - Epson IMU sensor protocol specific code for V340
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_out X,Y,Z are enabled if gyro_out is enabled
32  // ND flags for accel_out X,Y,Z are enabled if accel_out is enabled
33  // ND flag for temp_out is enabled if temp_out is enabled
34 
35  int sig_ctrl_hi =
36  (options.accel_out & 0x01) << 1 | (options.accel_out & 0x01) << 2 |
37  (options.accel_out & 0x01) << 3 | (options.gyro_out & 0x01) << 4 |
38  (options.gyro_out & 0x01) << 5 | (options.gyro_out & 0x01) << 6 |
39  (options.temp_out & 0x01) << 7;
40 
41  // MSC_CTRL
42  // Configure DRDY function (if needed) & EXT pin function on GPIO2 (if needed)
43  // External Counter Reset is typically used when GPIO2 is connected to a
44  // PPS-like signal
45 
46  int msc_ctrl_lo =
47  (options.drdy_pol & 0x01) << 1 | (options.drdy_on & 0x01) << 2 |
48  (options.ext_pol & 0x01) << 5 | (options.ext_sel & 0x03) << 6;
49 
50  // SMPL_CTRL
51  // Configures the Data Output Rate of the IMU.
52  // Refer to Datasheet for valid Data Output Rate & Filter Setting combinations
53 
54  int smpl_ctrl_hi = (options.dout_rate & 0x0F);
55 
56  // FILTER_CTRL
57  // Configures the FIR filter of the IMU.
58  // Refer to Datasheet for valid Data Output Rate & Filter Setting combinations
59  // If External Trigger is enabled on GPIO2, then it is recommended to set the
60  // the FILTER_SEL=0. And program the GYRO_LPF_FC & ACCL_LPF_FC to meet Nyquist
61  // based on the Trigger Frequency.
62 
63  int filter_ctrl_lo = (options.filter_sel & 0x1F);
64 
65  // COUNT_CTRL
66  // V340 only has option to enable or disable counter with burst read packets
67  // Otherwise the packet format and data fields are fixed
68 
69  int count_ctrl_lo = (options.count_out & 0x1);
70 
71  // POL_CTRL
72  // If these bits are set, then the axis values are reverse polarity
73 
74  int pol_ctrl_lo =
75  (options.invert_zaccel & 0x01) << 1 |
76  (options.invert_yaccel & 0x01) << 2 |
77  (options.invert_xaccel & 0x01) << 3 | (options.invert_zgyro & 0x01) << 4 |
78  (options.invert_ygyro & 0x01) << 5 | (options.invert_xgyro & 0x01) << 6;
79 
80  registerWriteByte(CMD_WINDOW1, ADDR_SIG_CTRL_HI, sig_ctrl_hi, debug);
81  registerWriteByte(CMD_WINDOW1, ADDR_MSC_CTRL_LO, msc_ctrl_lo, debug);
82  registerWriteByte(CMD_WINDOW1, ADDR_SMPL_CTRL_HI, smpl_ctrl_hi, debug);
83  registerWriteByte(CMD_WINDOW1, ADDR_POL_CTRL_LO, pol_ctrl_lo, debug);
84  registerWriteByte(CMD_WINDOW1, ADDR_FILTER_CTRL_LO, filter_ctrl_lo, debug);
85 
86 #ifdef SPI // Always disable UART_AUTO mode for burst reading when using SPI IF
88 #else
90 #endif
91 
92  registerWriteByte(CMD_WINDOW1, ADDR_COUNT_CTRL_LO, count_ctrl_lo, debug);
93 
94  return OK;
95 }
96 
97 /*****************************************************************************
98 ** Function name: registerDump
99 ** Description: Read all registers for debug purpose
100 ** Parameters: None
101 ** Return value: None
102 *****************************************************************************/
103 void registerDump(void) {
104  unsigned int debug = TRUE;
105  printf("\r\nRegister Dump:\r\n");
106  registerRead16(0x00, 0x00, debug);
107  registerRead16(0x00, 0x02, debug);
108  registerRead16(0x00, 0x04, debug);
109  printf("\r\n");
110  registerRead16(0x00, 0x06, debug);
111  registerRead16(0x00, 0x08, debug);
112  registerRead16(0x00, 0x0A, debug);
113  printf("\r\n");
114  registerRead16(0x00, 0x0C, debug);
115  registerRead16(0x00, 0x0E, debug);
116  registerRead16(0x00, 0x10, debug);
117  printf("\r\n");
118  registerRead16(0x00, 0x12, debug);
119  registerRead16(0x00, 0x32, debug);
120  registerRead16(0x00, 0x34, debug);
121  printf("\r\n");
122  registerRead16(0x00, 0x36, debug);
123  registerRead16(0x00, 0x38, debug);
124  registerRead16(0x00, 0x3A, debug);
125  printf("\r\n");
126  registerRead16(0x00, 0x3C, debug);
127  registerRead16(0x00, 0x3E, debug);
128  registerRead16(0x00, 0x50, debug);
129  printf("\r\n");
130  registerRead16(0x00, 0x6A, debug);
131  registerRead16(0x00, 0x6C, debug);
132  registerRead16(0x00, 0x6E, debug);
133  printf("\r\n");
134  registerRead16(0x00, 0x70, debug);
135  registerRead16(0x00, 0x72, debug);
136  registerRead16(0x00, 0x74, debug);
137  printf("\r\n");
138  registerRead16(0x00, 0x76, debug);
139  registerRead16(0x00, 0x78, debug);
140  registerRead16(0x00, 0x7A, debug);
141  printf("\r\n");
142 }
#define ADDR_SIG_CTRL_HI
#define ADDR_MSC_CTRL_LO
#define CMD_WINDOW1
#define ADDR_SMPL_CTRL_HI
#define OK
Definition: hcl.h:29
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
#define ADDR_POL_CTRL_LO
#define ADDR_COUNT_CTRL_LO
int sensorInitOptions(struct EpsonOptions options)


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