SENtral Simple Serial Host interface for PNI Sensor Corp SENtral-A2 motion coprocessor. For use with the RM3100RTI Arduino shield module on top of an STM4 serial mbed board. Will work with an PNI RM3100RTI module or M&M motion modules. Interaction with unit using built in USB serial serial port set for 115200 baud. Send '?' char for menu. Presently requires SENtral firmware to either be loaded in the RM3100RTI Arduino shield SD Card or preloaded in the RM3100RTI or M&M module's EEPROM. Firmware is typically preloaded on the module's EEPROM by PNI. PNI Sensor, 2019 www.pnicorp.com

Dependencies:   mbed SDFileSystemVSG

SENtral Simple Serial Host interface for PNI Sensor Corp SENtral-A2 motion coprocessor. For use with the RM3100RTI Arduino shield module on top of an STM4 serial mbed board. Will work with an PNI RM3100RTI module or M&M motion modules. Interaction with unit using built in USB serial serial port set for 115200 baud. Send '?' char for menu. Presently requires SENtral firmware to either be loaded in the RM3100RTI Arduino shield SD Card or preloaded in the RM3100RTI or M&M module's EEPROM. Firmware is typically preloaded on the module's EEPROM by PNI. PNI Sensor, 2019 www.pnicorp.com

Committer:
JoeMiller
Date:
Fri Jul 22 18:13:26 2016 +0000
Revision:
1:b0a205c9b958
Parent:
0:02c0c2cbc3df
Removed Nucleo RED LED. It interfered with SD Card Operation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JoeMiller 0:02c0c2cbc3df 1 /**
JoeMiller 0:02c0c2cbc3df 2 * @file em7186.h
JoeMiller 0:02c0c2cbc3df 3 *
JoeMiller 0:02c0c2cbc3df 4 * @brief Sample interface for the em7186.
JoeMiller 0:02c0c2cbc3df 5 *
JoeMiller 0:02c0c2cbc3df 6 * @authors David Vincent
JoeMiller 0:02c0c2cbc3df 7 * @date 04/01/2015
JoeMiller 0:02c0c2cbc3df 8 * @copyright (C) 2015 PNI Corp
JoeMiller 0:02c0c2cbc3df 9 *
JoeMiller 0:02c0c2cbc3df 10 * @copyright Disclosure to third parties or reproduction in any form
JoeMiller 0:02c0c2cbc3df 11 * whatsoever, without prior written consent, is strictly forbidden
JoeMiller 0:02c0c2cbc3df 12 *
JoeMiller 0:02c0c2cbc3df 13 */
JoeMiller 0:02c0c2cbc3df 14
JoeMiller 0:02c0c2cbc3df 15 #ifndef EM7186_H
JoeMiller 0:02c0c2cbc3df 16 #define EM7186_H
JoeMiller 0:02c0c2cbc3df 17
JoeMiller 0:02c0c2cbc3df 18 #include "main.h"
JoeMiller 0:02c0c2cbc3df 19
JoeMiller 0:02c0c2cbc3df 20 extern float em7186_sensor_scale[128];
JoeMiller 0:02c0c2cbc3df 21
JoeMiller 0:02c0c2cbc3df 22 extern u32 timestampNonWake;
JoeMiller 0:02c0c2cbc3df 23 extern u32 timestampWake;
JoeMiller 0:02c0c2cbc3df 24 extern u8 printData;
JoeMiller 0:02c0c2cbc3df 25 extern u8 logData;
JoeMiller 0:02c0c2cbc3df 26 extern u8 sensorEnabled[64];
JoeMiller 0:02c0c2cbc3df 27
JoeMiller 0:02c0c2cbc3df 28
JoeMiller 0:02c0c2cbc3df 29 //=============================================================================
JoeMiller 0:02c0c2cbc3df 30 // Hardware specific functions
JoeMiller 0:02c0c2cbc3df 31 //=============================================================================
JoeMiller 0:02c0c2cbc3df 32
JoeMiller 0:02c0c2cbc3df 33
JoeMiller 0:02c0c2cbc3df 34 /**
JoeMiller 0:02c0c2cbc3df 35 * Initialize the i2c interface. Implementation is hardware specific.
JoeMiller 0:02c0c2cbc3df 36 *
JoeMiller 0:02c0c2cbc3df 37 * @return 1 if initialization succeeded, 0 otherwise.
JoeMiller 0:02c0c2cbc3df 38 */
JoeMiller 0:02c0c2cbc3df 39 u32 em7186_i2c_init();
JoeMiller 0:02c0c2cbc3df 40 /**
JoeMiller 0:02c0c2cbc3df 41 * Initialize the i2c interface indicated by the device id. Implementation is hardware specific.
JoeMiller 0:02c0c2cbc3df 42 *
JoeMiller 0:02c0c2cbc3df 43 * @param deviceId the unique device id for the I2C interface hardware.
JoeMiller 0:02c0c2cbc3df 44 * @return 1 if initialization succeeded, 0 otherwise.
JoeMiller 0:02c0c2cbc3df 45 */
JoeMiller 0:02c0c2cbc3df 46 u32 em7186_i2c_init_by_id(s32 deviceId);
JoeMiller 0:02c0c2cbc3df 47 /**
JoeMiller 0:02c0c2cbc3df 48 * Read a block of data from the i2c bus. Implementation is hardware specific.
JoeMiller 0:02c0c2cbc3df 49 *
JoeMiller 0:02c0c2cbc3df 50 * @param registerAddress The address of the first register in the block.
JoeMiller 0:02c0c2cbc3df 51 * @param[out] buffer The data.
JoeMiller 0:02c0c2cbc3df 52 * @param length The number of bytes to read.
JoeMiller 0:02c0c2cbc3df 53 * @return The number of bytes read.
JoeMiller 0:02c0c2cbc3df 54 */
JoeMiller 0:02c0c2cbc3df 55 u32 em7186_i2c_read(u8 registerAddress, char* buffer, u16 length);
JoeMiller 0:02c0c2cbc3df 56 /**
JoeMiller 0:02c0c2cbc3df 57 * Write a block of data to the i2c bus. Implementation is hardware specific.
JoeMiller 0:02c0c2cbc3df 58 *
JoeMiller 0:02c0c2cbc3df 59 * @param registerAddress The address of the first register in the block.
JoeMiller 0:02c0c2cbc3df 60 * @param buffer The data to write.
JoeMiller 0:02c0c2cbc3df 61 * @param length The number of bytes to write.
JoeMiller 0:02c0c2cbc3df 62 * @return The number of bytes written.
JoeMiller 0:02c0c2cbc3df 63 */
JoeMiller 0:02c0c2cbc3df 64 u32 em7186_i2c_write(u8 registerAddress, char* buffer, u16 length);
JoeMiller 0:02c0c2cbc3df 65 /**
JoeMiller 0:02c0c2cbc3df 66 * Write a single byte to the i2c bus. Implementation is hardware specific.
JoeMiller 0:02c0c2cbc3df 67 *
JoeMiller 0:02c0c2cbc3df 68 * @param registerAddress The register to write.
JoeMiller 0:02c0c2cbc3df 69 * @param value The data to write.
JoeMiller 0:02c0c2cbc3df 70 * @return 1 if the write succeeded, 0 otherwise.
JoeMiller 0:02c0c2cbc3df 71 */
JoeMiller 0:02c0c2cbc3df 72 u32 em7186_i2c_write_value(u8 registerAddress, char value);
JoeMiller 0:02c0c2cbc3df 73 /**
JoeMiller 0:02c0c2cbc3df 74 * Check for an interrupt from the em7186. Implementation is hardware specific.
JoeMiller 0:02c0c2cbc3df 75 *
JoeMiller 0:02c0c2cbc3df 76 * @return 1 if the interrupt line is high, 0 otherwise.
JoeMiller 0:02c0c2cbc3df 77 */
JoeMiller 0:02c0c2cbc3df 78 u8 em7186_interrupt();
JoeMiller 0:02c0c2cbc3df 79 /**
JoeMiller 0:02c0c2cbc3df 80 * Set the sensor scale factors. Some of these values could change depending on
JoeMiller 0:02c0c2cbc3df 81 * the hardware being used.
JoeMiller 0:02c0c2cbc3df 82 *
JoeMiller 0:02c0c2cbc3df 83 * @return 1 on success, 0 on failure.
JoeMiller 0:02c0c2cbc3df 84 */
JoeMiller 0:02c0c2cbc3df 85 u8 em7186_set_scale_factors();
JoeMiller 0:02c0c2cbc3df 86 /**
JoeMiller 0:02c0c2cbc3df 87 * Save a set of warm-start coefficients to file.
JoeMiller 0:02c0c2cbc3df 88 *
JoeMiller 0:02c0c2cbc3df 89 * @see em7186_warm_start_load
JoeMiller 0:02c0c2cbc3df 90 * @param filename The name of the file to create.
JoeMiller 0:02c0c2cbc3df 91 * @return 1 on success, 0 on failure.
JoeMiller 0:02c0c2cbc3df 92 */
JoeMiller 0:02c0c2cbc3df 93 //u32 em7186_warm_start_save(const char *filename);
JoeMiller 0:02c0c2cbc3df 94 /**
JoeMiller 0:02c0c2cbc3df 95 * Load a set of warm-start coefficients from file.
JoeMiller 0:02c0c2cbc3df 96 *
JoeMiller 0:02c0c2cbc3df 97 * @see em7186_warm_start_save
JoeMiller 0:02c0c2cbc3df 98 * @param filename The name of the file to load.
JoeMiller 0:02c0c2cbc3df 99 * @return 1 on success, 0 on failure.
JoeMiller 0:02c0c2cbc3df 100 */
JoeMiller 0:02c0c2cbc3df 101 //u32 em7186_warm_start_load(const char *filename);
JoeMiller 0:02c0c2cbc3df 102
JoeMiller 0:02c0c2cbc3df 103 //=============================================================================
JoeMiller 0:02c0c2cbc3df 104 // Core functions
JoeMiller 0:02c0c2cbc3df 105 //=============================================================================
JoeMiller 0:02c0c2cbc3df 106 /**
JoeMiller 0:02c0c2cbc3df 107
JoeMiller 0:02c0c2cbc3df 108 * Upload firmware. Resets the CPU and uploads firmware.
JoeMiller 0:02c0c2cbc3df 109 *
JoeMiller 0:02c0c2cbc3df 110 * @param filename The name of the firmware file to upload.
JoeMiller 0:02c0c2cbc3df 111 * @return 1 on success, 0 otherwise.
JoeMiller 0:02c0c2cbc3df 112 */
JoeMiller 0:02c0c2cbc3df 113 u32 em7186_firmware_Transfer2RAM(const char *filename);
JoeMiller 0:02c0c2cbc3df 114 /**
JoeMiller 0:02c0c2cbc3df 115 * Read a set of parameters. Initiate the transfer of a set of
JoeMiller 0:02c0c2cbc3df 116 * parameters on the same parameter page.
JoeMiller 0:02c0c2cbc3df 117 *
JoeMiller 0:02c0c2cbc3df 118 * @param[out] values, The values of the parameters that have been read.
JoeMiller 0:02c0c2cbc3df 119 * @param page, The page to read values from.
JoeMiller 0:02c0c2cbc3df 120 * @param params, The list of parameters to read.
JoeMiller 0:02c0c2cbc3df 121 * @param numParams, The number of parameters to read.
JoeMiller 0:02c0c2cbc3df 122 * @return, The number of parameters that were read.
JoeMiller 0:02c0c2cbc3df 123 */
JoeMiller 0:02c0c2cbc3df 124 u32 em7186_param_read(char *values, u8 page, ParamInfo *params, u8 numParams);
JoeMiller 0:02c0c2cbc3df 125 /**
JoeMiller 0:02c0c2cbc3df 126 * Write a set of parameters. Initiate the transfer of a set of
JoeMiller 0:02c0c2cbc3df 127 * parameters on the same parameter page.
JoeMiller 0:02c0c2cbc3df 128 *
JoeMiller 0:02c0c2cbc3df 129 * @param values, The values to write to the specified parameters.
JoeMiller 0:02c0c2cbc3df 130 * @param page, The page to write values to.
JoeMiller 0:02c0c2cbc3df 131 * @param params, The list of parameters to write.
JoeMiller 0:02c0c2cbc3df 132 * @param numParams, The number of parameters to write.
JoeMiller 0:02c0c2cbc3df 133 * @return, The number of parameters that were written.
JoeMiller 0:02c0c2cbc3df 134 */
JoeMiller 0:02c0c2cbc3df 135 u32 em7186_param_write(char *values, u8 page, ParamInfo *params, u8 numParams);
JoeMiller 0:02c0c2cbc3df 136 /**
JoeMiller 0:02c0c2cbc3df 137 * Read the contents of the fifo. Note that the size of the buffer must be at
JoeMiller 0:02c0c2cbc3df 138 * least as large as the space available for the fifo.
JoeMiller 0:02c0c2cbc3df 139 *
JoeMiller 0:02c0c2cbc3df 140 * @param[out] buffer The contents of the fifo.
JoeMiller 0:02c0c2cbc3df 141 * @return The number of bytes read from the fifo.
JoeMiller 0:02c0c2cbc3df 142 */
JoeMiller 0:02c0c2cbc3df 143 u32 em7186_read_fifo(char *buffer);
JoeMiller 0:02c0c2cbc3df 144 /**
JoeMiller 0:02c0c2cbc3df 145 * Parse the fifo buffer.
JoeMiller 0:02c0c2cbc3df 146 *
JoeMiller 0:02c0c2cbc3df 147 * @param buffer The contents of the fifo.
JoeMiller 0:02c0c2cbc3df 148 * @param size The number of bytes in the fifo buffer.
JoeMiller 0:02c0c2cbc3df 149 * @return The number of bytes parsed.
JoeMiller 0:02c0c2cbc3df 150 */
JoeMiller 0:02c0c2cbc3df 151 u32 em7186_parse_fifo(char* buffer, u32 size);
JoeMiller 0:02c0c2cbc3df 152 /**
JoeMiller 0:02c0c2cbc3df 153 * Set a sensor output rate.
JoeMiller 0:02c0c2cbc3df 154 *
JoeMiller 0:02c0c2cbc3df 155 * @param sensorId The id of the sensor.
JoeMiller 0:02c0c2cbc3df 156 * @param rate The desired rate in Hz.
JoeMiller 0:02c0c2cbc3df 157 * @return 1 on success, 0 on failure.
JoeMiller 0:02c0c2cbc3df 158 */
JoeMiller 0:02c0c2cbc3df 159 u32 em7186_set_sensor_rate(u8 sensorId, u16 rate);
JoeMiller 0:02c0c2cbc3df 160 /**
JoeMiller 0:02c0c2cbc3df 161 * Set a sensor maximum report latency.
JoeMiller 0:02c0c2cbc3df 162 *
JoeMiller 0:02c0c2cbc3df 163 * @param sensorId The id of the sensor.
JoeMiller 0:02c0c2cbc3df 164 * @param rate The desired latency in milliseconds.
JoeMiller 0:02c0c2cbc3df 165 * @return 1 on success, 0 on failure.
JoeMiller 0:02c0c2cbc3df 166 */
JoeMiller 0:02c0c2cbc3df 167 u32 em7186_set_sensor_delay(u8 sensorId, u16 delay);
JoeMiller 0:02c0c2cbc3df 168
JoeMiller 0:02c0c2cbc3df 169 //=============================================================================
JoeMiller 0:02c0c2cbc3df 170 // Additional Control Functions
JoeMiller 0:02c0c2cbc3df 171 //=============================================================================
JoeMiller 0:02c0c2cbc3df 172 /**
JoeMiller 0:02c0c2cbc3df 173 * Set fifo watermark values. The fifo watermark can be used to wake the host
JoeMiller 0:02c0c2cbc3df 174 * before data is lost from the fifo. Default behavior is to allow the non-wake
JoeMiller 0:02c0c2cbc3df 175 * fifo to overflow while the host is in suspend mode and for the wake fifo to
JoeMiller 0:02c0c2cbc3df 176 * wake the host before data is lost. This function sets the minimum number of
JoeMiller 0:02c0c2cbc3df 177 * bytes remaining in the fifo before a host interrupt is issued.
JoeMiller 0:02c0c2cbc3df 178 *
JoeMiller 0:02c0c2cbc3df 179 * Note that the watermark values used in this function differ from those in
JoeMiller 0:02c0c2cbc3df 180 * the documentation.
JoeMiller 0:02c0c2cbc3df 181 *
JoeMiller 0:02c0c2cbc3df 182 * @param wakeFifoWatermark The minimum number of bytes remaining in the wake
JoeMiller 0:02c0c2cbc3df 183 * fifo before interrupting the host.
JoeMiller 0:02c0c2cbc3df 184 * @param nonWakeFifoWatermark The minimum number of bytes remaining in the
JoeMiller 0:02c0c2cbc3df 185 * non-wake fifo before interrupting the host.
JoeMiller 0:02c0c2cbc3df 186 * @return 1 on success, 0 on failure.
JoeMiller 0:02c0c2cbc3df 187 */
JoeMiller 0:02c0c2cbc3df 188 u32 em7186_set_fifo_watermarks(u16 wakeFifoWatermark, u16 nonWakeFifoWatermark);
JoeMiller 0:02c0c2cbc3df 189 /**
JoeMiller 0:02c0c2cbc3df 190 * Change meta-event settings. Enable or disable individual meta-events and
JoeMiller 0:02c0c2cbc3df 191 * their interrupts.
JoeMiller 0:02c0c2cbc3df 192 *
JoeMiller 0:02c0c2cbc3df 193 * @param eventId The id of the meta-event.
JoeMiller 0:02c0c2cbc3df 194 * @param enable True to enable the meta-event.
JoeMiller 0:02c0c2cbc3df 195 * @param enableInt True to cause meta-event to interrupt the host.
JoeMiller 0:02c0c2cbc3df 196 * @return 1 on success, 0 on failure.
JoeMiller 0:02c0c2cbc3df 197 */
JoeMiller 0:02c0c2cbc3df 198 u32 em7186_set_meta_event(u8 eventId, u8 enable, u8 enableInt);
JoeMiller 0:02c0c2cbc3df 199 /**
JoeMiller 0:02c0c2cbc3df 200 * Enter or exit ap suspend mode. AP suspend mode changes the interrupt behavior
JoeMiller 0:02c0c2cbc3df 201 * of the em7186. While in AP suspend mode only wake events will interrupt the
JoeMiller 0:02c0c2cbc3df 202 * host.
JoeMiller 0:02c0c2cbc3df 203 *
JoeMiller 0:02c0c2cbc3df 204 * @param suspend True to enter suspend mode, False to exit suspend mode.
JoeMiller 0:02c0c2cbc3df 205 * @return 1 on success, 0 on failure.
JoeMiller 0:02c0c2cbc3df 206 */
JoeMiller 0:02c0c2cbc3df 207 u32 em7186_ap_suspend(u8 suspend);
JoeMiller 0:02c0c2cbc3df 208 /**
JoeMiller 0:02c0c2cbc3df 209 * Flush data from a fifo. Flush can be for an individual sensor or an entire
JoeMiller 0:02c0c2cbc3df 210 * fifo.
JoeMiller 0:02c0c2cbc3df 211 *
JoeMiller 0:02c0c2cbc3df 212 * @see FIFO_FLUSH_DISCARD_NON_WAKE
JoeMiller 0:02c0c2cbc3df 213 * @see FIFO_FLUSH_DISCARD_WAKE
JoeMiller 0:02c0c2cbc3df 214 * @see FIFO_FLUSH_TRANSFER_NON_WAKE
JoeMiller 0:02c0c2cbc3df 215 * @see FIFO_FLUSH_TRANSFER_WAKE
JoeMiller 0:02c0c2cbc3df 216 * @see FIFO_FLUSH_DISCARD_ALL
JoeMiller 0:02c0c2cbc3df 217 * @see FIFO_FLUSH_TRANSFER_ALL
JoeMiller 0:02c0c2cbc3df 218 *
JoeMiller 0:02c0c2cbc3df 219 * @param sensorId The id of the sensor to flush, or a special flush command.
JoeMiller 0:02c0c2cbc3df 220 * @return 1 on success, 0 on failure.
JoeMiller 0:02c0c2cbc3df 221 */
JoeMiller 0:02c0c2cbc3df 222 u32 em7186_flush_sensor(u8 sensorId);
JoeMiller 0:02c0c2cbc3df 223 /**
JoeMiller 0:02c0c2cbc3df 224 * Enable raw sensor data for calibration or debugging.
JoeMiller 0:02c0c2cbc3df 225 *
JoeMiller 0:02c0c2cbc3df 226 * @param emableMag True to enable the magnetometer debug output.
JoeMiller 0:02c0c2cbc3df 227 * @param emableAccel True to enable the accelerometer debug output.
JoeMiller 0:02c0c2cbc3df 228 * @param emableGyro True to enable the gyroscope debug output.
JoeMiller 0:02c0c2cbc3df 229 * @return 1 on success, 0 on failure.
JoeMiller 0:02c0c2cbc3df 230 */
JoeMiller 0:02c0c2cbc3df 231 u32 em7186_enable_raw_sensors(u8 enableMag, u8 enableAccel, u8 enableGyro);
JoeMiller 0:02c0c2cbc3df 232
JoeMiller 0:02c0c2cbc3df 233 void displayParams(u8 paramPage, ParamInfo *paramList, u8 numParams);
JoeMiller 0:02c0c2cbc3df 234 //void warmStart();
JoeMiller 0:02c0c2cbc3df 235 void displayStatusRegisters();
JoeMiller 0:02c0c2cbc3df 236 void displaySensorStatus();
JoeMiller 0:02c0c2cbc3df 237 void displayPhysicalSensorInformation();
JoeMiller 0:02c0c2cbc3df 238 void displayPhysicalSensorStatus();
JoeMiller 0:02c0c2cbc3df 239 void getSensorInformation();
JoeMiller 0:02c0c2cbc3df 240 void getSensorConfiguration();
JoeMiller 0:02c0c2cbc3df 241 void displaySensorConfiguration();
JoeMiller 0:02c0c2cbc3df 242 void displaySensorInformation();
JoeMiller 0:02c0c2cbc3df 243 void firmwareTransfer(char srcDestCode);
JoeMiller 0:02c0c2cbc3df 244 u32 em7186_firmware_Transfer2EE(const u8 *firmwareName);
JoeMiller 0:02c0c2cbc3df 245 u32 EE_Write(u8 I2C_Addr, u16 EE_MemAddr, u8*buffer, u16 length);
JoeMiller 0:02c0c2cbc3df 246 void executeSerialFunction(unsigned char key);
JoeMiller 0:02c0c2cbc3df 247
JoeMiller 0:02c0c2cbc3df 248
JoeMiller 0:02c0c2cbc3df 249
JoeMiller 0:02c0c2cbc3df 250 #endif //EM7186_H