uart

Dependencies:   MAX32620FTHR USBDevice

Committer:
rsjawale24
Date:
Sun Oct 16 15:35:01 2022 +0000
Revision:
0:c62425b2f286
ok

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rsjawale24 0:c62425b2f286 1 /*******************************************************************************
rsjawale24 0:c62425b2f286 2 * Copyright (C) Maxim Integrated Products, Inc., All rights Reserved.
rsjawale24 0:c62425b2f286 3 *
rsjawale24 0:c62425b2f286 4 * This software is protected by copyright laws of the United States and
rsjawale24 0:c62425b2f286 5 * of foreign countries. This material may also be protected by patent laws
rsjawale24 0:c62425b2f286 6 * and technology transfer regulations of the United States and of foreign
rsjawale24 0:c62425b2f286 7 * countries. This software is furnished under a license agreement and/or a
rsjawale24 0:c62425b2f286 8 * nondisclosure agreement and may only be used or reproduced in accordance
rsjawale24 0:c62425b2f286 9 * with the terms of those agreements. Dissemination of this information to
rsjawale24 0:c62425b2f286 10 * any party or parties not specified in the license agreement and/or
rsjawale24 0:c62425b2f286 11 * nondisclosure agreement is expressly prohibited.
rsjawale24 0:c62425b2f286 12 *
rsjawale24 0:c62425b2f286 13 * The above copyright notice and this permission notice shall be included
rsjawale24 0:c62425b2f286 14 * in all copies or substantial portions of the Software.
rsjawale24 0:c62425b2f286 15 *
rsjawale24 0:c62425b2f286 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
rsjawale24 0:c62425b2f286 17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
rsjawale24 0:c62425b2f286 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
rsjawale24 0:c62425b2f286 19 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
rsjawale24 0:c62425b2f286 20 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
rsjawale24 0:c62425b2f286 21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
rsjawale24 0:c62425b2f286 22 * OTHER DEALINGS IN THE SOFTWARE.
rsjawale24 0:c62425b2f286 23 *
rsjawale24 0:c62425b2f286 24 * Except as contained in this notice, the name of Maxim Integrated
rsjawale24 0:c62425b2f286 25 * Products, Inc. shall not be used except as stated in the Maxim Integrated
rsjawale24 0:c62425b2f286 26 * Products, Inc. Branding Policy.
rsjawale24 0:c62425b2f286 27 *
rsjawale24 0:c62425b2f286 28 * The mere transfer of this software does not imply any licenses
rsjawale24 0:c62425b2f286 29 * of trade secrets, proprietary technology, copyrights, patents,
rsjawale24 0:c62425b2f286 30 * trademarks, maskwork rights, or any other form of intellectual
rsjawale24 0:c62425b2f286 31 * property whatsoever. Maxim Integrated Products, Inc. retains all
rsjawale24 0:c62425b2f286 32 * ownership rights.
rsjawale24 0:c62425b2f286 33 *******************************************************************************
rsjawale24 0:c62425b2f286 34 */
rsjawale24 0:c62425b2f286 35
rsjawale24 0:c62425b2f286 36 #ifndef GESTURE_LIB_H_INCLUDED
rsjawale24 0:c62425b2f286 37 #define GESTURE_LIB_H_INCLUDED
rsjawale24 0:c62425b2f286 38
rsjawale24 0:c62425b2f286 39 #include <stdint.h>
rsjawale24 0:c62425b2f286 40
rsjawale24 0:c62425b2f286 41 #ifdef __cplusplus
rsjawale24 0:c62425b2f286 42 extern "C"
rsjawale24 0:c62425b2f286 43 {
rsjawale24 0:c62425b2f286 44 #endif
rsjawale24 0:c62425b2f286 45
rsjawale24 0:c62425b2f286 46 /*
rsjawale24 0:c62425b2f286 47 * Enumerate gesture events here
rsjawale24 0:c62425b2f286 48 */
rsjawale24 0:c62425b2f286 49 typedef enum {
rsjawale24 0:c62425b2f286 50 GEST_NONE,
rsjawale24 0:c62425b2f286 51 GEST_PLACEHOLDER
rsjawale24 0:c62425b2f286 52 } GestureEvent;
rsjawale24 0:c62425b2f286 53
rsjawale24 0:c62425b2f286 54 /*
rsjawale24 0:c62425b2f286 55 * Structure to store gesture results.
rsjawale24 0:c62425b2f286 56 */
rsjawale24 0:c62425b2f286 57 typedef struct {
rsjawale24 0:c62425b2f286 58 GestureEvent gesture; // Gesture event reported for this processed frame
rsjawale24 0:c62425b2f286 59 uint32_t state; // 0: inactive; 1: object detected; 2: rotation in progress
rsjawale24 0:c62425b2f286 60 uint32_t n_sample; // The current sample number of the gesture in progress
rsjawale24 0:c62425b2f286 61 int maxpixel; // Maximum pixel value for this frame
rsjawale24 0:c62425b2f286 62 float x; // Object x-position. Only accurate if TRACKING_ENABLE mask is set.
rsjawale24 0:c62425b2f286 63 float y; // Object y-position. Only accurate if TRACKING_ENABLE mask is set.
rsjawale24 0:c62425b2f286 64 float float_placeholder;
rsjawale24 0:c62425b2f286 65 uint32_t int_placeholder;
rsjawale24 0:c62425b2f286 66
rsjawale24 0:c62425b2f286 67 } GestureResult;
rsjawale24 0:c62425b2f286 68
rsjawale24 0:c62425b2f286 69
rsjawale24 0:c62425b2f286 70 /*
rsjawale24 0:c62425b2f286 71 * Structure for configuration parameters that apply to tracking mode, region selection, and linger-to-click.
rsjawale24 0:c62425b2f286 72 * An instance of this structure is a member of the GestureConfig stucture.
rsjawale24 0:c62425b2f286 73 */
rsjawale24 0:c62425b2f286 74 typedef struct {
rsjawale24 0:c62425b2f286 75 uint32_t enable_auto_bias_calibration; // Enable automatic bias calibration
rsjawale24 0:c62425b2f286 76 uint32_t static_state_bias_ms; // How many milliseconds of static condition before performing an automoatic bias calibration
rsjawale24 0:c62425b2f286 77 float low_pass_filter_alpha; // Smoothing factor for low pass filter. The lower the value, the more low pass filtering
rsjawale24 0:c62425b2f286 78 int zero_clamp_threshold; // Any pixel below this value is clamped to zero. Must be less than detection thresholds
rsjawale24 0:c62425b2f286 79 float zero_clamp_threshold_factor; // Any pixel below maxpixel divided by this factor is clamped to zero. This is to reduce optical clutter and background noise
rsjawale24 0:c62425b2f286 80 int start_detection_threshold; // Pixel activation (bias corrected) to start gesture tracking
rsjawale24 0:c62425b2f286 81 int end_detection_threshold; // Pixel activation (bias corrected) to stop gesture tracking
rsjawale24 0:c62425b2f286 82 uint32_t static_state_bias_delta_max; // Max current pixel to reference delta to be considered static state for bias calibration
rsjawale24 0:c62425b2f286 83 uint32_t bias_fullscale_factor_max; // Only calibrate if raw pixel range below this factor of ADC FS
rsjawale24 0:c62425b2f286 84 float track_width; // Width (in pixels) of sensor array over which to scale tracking cursor (thereby ignoring edge pixels)
rsjawale24 0:c62425b2f286 85 float track_height; // Height (in pixels) of sensor array over which to scale tracking cursor (thereby ignoring edge pixels)
rsjawale24 0:c62425b2f286 86 uint32_t enable_gain_correction; // Enable pixel gain correction
rsjawale24 0:c62425b2f286 87 float gain_factor_0; // Inner gain factor
rsjawale24 0:c62425b2f286 88 float gain_factor_1; // Mid gain factor
rsjawale24 0:c62425b2f286 89 float gain_factor_2; // Outer gain factor
rsjawale24 0:c62425b2f286 90 } TrackingConfig;
rsjawale24 0:c62425b2f286 91
rsjawale24 0:c62425b2f286 92 /*
rsjawale24 0:c62425b2f286 93 * Struture for gesture configuration parameters
rsjawale24 0:c62425b2f286 94 * An instance of this structure can be modified by the application and passed to the configGesture function
rsjawale24 0:c62425b2f286 95 */
rsjawale24 0:c62425b2f286 96 typedef struct {
rsjawale24 0:c62425b2f286 97 uint32_t flip_sensor_pixels; // Set true to if device is mounted upside-down
rsjawale24 0:c62425b2f286 98 uint32_t pixel_data_mode; // Set to 0 for raw data, 1 for bias-compensated pixels, 2 for background subtracted (gesture) pixels
rsjawale24 0:c62425b2f286 99 float sample_period_ms; // Sample period of sensor in milliseconds
rsjawale24 0:c62425b2f286 100 uint32_t adc_full_scale; // ADC full scale of sensor for current register configuration
rsjawale24 0:c62425b2f286 101 float background_filter_alpha; // Smoothing factor for dynamic background cancellation. Larger value results in more aggressive high pass filtering
rsjawale24 0:c62425b2f286 102 float low_pass_filter_alpha; // Smoothing factor for low pass filter. Set to 1 for no filtering
rsjawale24 0:c62425b2f286 103 int zero_clamp_threshold; // Any pixel below this value (background corrected) is clamped to zero. Must be less than detection thresholds
rsjawale24 0:c62425b2f286 104 float zero_clamp_threshold_factor; // Any pixel below maxpixel/x is clamped to zero. This is to reduce optical clutter and background noise
rsjawale24 0:c62425b2f286 105 uint32_t enable_window_filter;
rsjawale24 0:c62425b2f286 106 float window_filter_alpha;
rsjawale24 0:c62425b2f286 107 int start_detection_threshold; // Pixel activation level (background corrected) to start gesture tracking
rsjawale24 0:c62425b2f286 108 int end_detection_threshold; // Pixel threshold (background corrected) to end gesture tracking
rsjawale24 0:c62425b2f286 109 TrackingConfig trackingConfig;
rsjawale24 0:c62425b2f286 110 } GestureConfig;
rsjawale24 0:c62425b2f286 111
rsjawale24 0:c62425b2f286 112
rsjawale24 0:c62425b2f286 113 /**
rsjawale24 0:c62425b2f286 114 * This function obtains a copy of the GestureConfig structure.
rsjawale24 0:c62425b2f286 115 * Obtain a copy in order to modify parameters and then pass the struct back using configGesture.
rsjawale24 0:c62425b2f286 116 *
rsjawale24 0:c62425b2f286 117 * Parameters
rsjawale24 0:c62425b2f286 118 * cfg: A pointer to a GestureConfig structure
rsjawale24 0:c62425b2f286 119 *
rsjawale24 0:c62425b2f286 120 * Return Value
rsjawale24 0:c62425b2f286 121 * None
rsjawale24 0:c62425b2f286 122 */
rsjawale24 0:c62425b2f286 123 void getGestureConfig(GestureConfig *_cfg);
rsjawale24 0:c62425b2f286 124
rsjawale24 0:c62425b2f286 125 /**
rsjawale24 0:c62425b2f286 126 * This function obtains a pointer to the GestureConfig structure.
rsjawale24 0:c62425b2f286 127 * Obtain a pointer to use the VALUE of specific parameter. Parameters should never be SET directly using the pointer
rsjawale24 0:c62425b2f286 128 * to the Config struct. Instead use getGestureConfig() above.
rsjawale24 0:c62425b2f286 129 *
rsjawale24 0:c62425b2f286 130 * Parameters
rsjawale24 0:c62425b2f286 131 * none
rsjawale24 0:c62425b2f286 132 *
rsjawale24 0:c62425b2f286 133 * Return Value
rsjawale24 0:c62425b2f286 134 * cfg: A pointer to the GestureConfig structure contained in the gesture library
rsjawale24 0:c62425b2f286 135 */
rsjawale24 0:c62425b2f286 136
rsjawale24 0:c62425b2f286 137 GestureConfig * getGestureConfigPtr();
rsjawale24 0:c62425b2f286 138
rsjawale24 0:c62425b2f286 139
rsjawale24 0:c62425b2f286 140 /**
rsjawale24 0:c62425b2f286 141 * This function initializes the gesture algorithm with the parameters defined in the GestureConfig structure.
rsjawale24 0:c62425b2f286 142 *
rsjawale24 0:c62425b2f286 143 * Parameters
rsjawale24 0:c62425b2f286 144 * cfg: A pointer to the GestureConfig structure. If the pointer is NULL, the algorithm will be configured with default values.
rsjawale24 0:c62425b2f286 145 *
rsjawale24 0:c62425b2f286 146 * Return Value
rsjawale24 0:c62425b2f286 147 * None
rsjawale24 0:c62425b2f286 148 */
rsjawale24 0:c62425b2f286 149 void configGesture(const GestureConfig *cfg);
rsjawale24 0:c62425b2f286 150
rsjawale24 0:c62425b2f286 151
rsjawale24 0:c62425b2f286 152 /**
rsjawale24 0:c62425b2f286 153 * This function initializes an instance of a GestureConfig structure to the default values.
rsjawale24 0:c62425b2f286 154 * After calling this function, the structure instance can then be modified selectively by the application
rsjawale24 0:c62425b2f286 155 * and passed into the configGesture function to implement a custom configuration.
rsjawale24 0:c62425b2f286 156 *
rsjawale24 0:c62425b2f286 157 * Parameters
rsjawale24 0:c62425b2f286 158 * cfg: A pointer to the GestureConfig structure
rsjawale24 0:c62425b2f286 159 *
rsjawale24 0:c62425b2f286 160 * Return Value
rsjawale24 0:c62425b2f286 161 * None
rsjawale24 0:c62425b2f286 162 */
rsjawale24 0:c62425b2f286 163 void initConfigStructToDefaults(GestureConfig *cfg);
rsjawale24 0:c62425b2f286 164
rsjawale24 0:c62425b2f286 165
rsjawale24 0:c62425b2f286 166 /**
rsjawale24 0:c62425b2f286 167 * This function executes the algorithm for a single frame. This function should be called for every sample period of the sensor.
rsjawale24 0:c62425b2f286 168 *
rsjawale24 0:c62425b2f286 169 * Parameters
rsjawale24 0:c62425b2f286 170 * pixels: An integer array of sensor pixel data; length is determined by the sensor resolution defined in gesture_common.h
rsjawale24 0:c62425b2f286 171 * gesResult: A pointer to a GestureResult struct instance; this instance will be populated with results by the algorithm.
rsjawale24 0:c62425b2f286 172 *
rsjawale24 0:c62425b2f286 173 * Return Value
rsjawale24 0:c62425b2f286 174 * None
rsjawale24 0:c62425b2f286 175 */
rsjawale24 0:c62425b2f286 176 void runGesture(int pixels[], GestureResult *gesResult);
rsjawale24 0:c62425b2f286 177
rsjawale24 0:c62425b2f286 178
rsjawale24 0:c62425b2f286 179 /**
rsjawale24 0:c62425b2f286 180 * This function resets the gesture algorithm by resetting the state machine and clearing filters.
rsjawale24 0:c62425b2f286 181 * Note that the initialization parameters are not changed
rsjawale24 0:c62425b2f286 182 *
rsjawale24 0:c62425b2f286 183 * Parameters
rsjawale24 0:c62425b2f286 184 * None
rsjawale24 0:c62425b2f286 185 *
rsjawale24 0:c62425b2f286 186 * Return Value
rsjawale24 0:c62425b2f286 187 * None
rsjawale24 0:c62425b2f286 188 */
rsjawale24 0:c62425b2f286 189 void resetGesture();
rsjawale24 0:c62425b2f286 190
rsjawale24 0:c62425b2f286 191
rsjawale24 0:c62425b2f286 192 /**
rsjawale24 0:c62425b2f286 193 * This function forces a tracking mode calibration.
rsjawale24 0:c62425b2f286 194 * Note that the calibration only applies to tracking mode (region selection and linger to click); it is not used
rsjawale24 0:c62425b2f286 195 * for dynamic gesture mode.
rsjawale24 0:c62425b2f286 196 *
rsjawale24 0:c62425b2f286 197 * Parameters
rsjawale24 0:c62425b2f286 198 * None
rsjawale24 0:c62425b2f286 199 *
rsjawale24 0:c62425b2f286 200 * Return Value
rsjawale24 0:c62425b2f286 201 * None
rsjawale24 0:c62425b2f286 202 */
rsjawale24 0:c62425b2f286 203 void forceTrackingCalibration();
rsjawale24 0:c62425b2f286 204
rsjawale24 0:c62425b2f286 205 #ifdef __cplusplus
rsjawale24 0:c62425b2f286 206 } // extern "C"
rsjawale24 0:c62425b2f286 207 #endif
rsjawale24 0:c62425b2f286 208
rsjawale24 0:c62425b2f286 209 #endif