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_COMMON_H_INCLUDED
rsjawale24 0:c62425b2f286 37 #define GESTURE_COMMON_H_INCLUDED
rsjawale24 0:c62425b2f286 38
rsjawale24 0:c62425b2f286 39 #include "img_utils.h"
rsjawale24 0:c62425b2f286 40 #include "gesture_lib.h"
rsjawale24 0:c62425b2f286 41
rsjawale24 0:c62425b2f286 42 //#define USE_MBED
rsjawale24 0:c62425b2f286 43
rsjawale24 0:c62425b2f286 44 #ifdef USE_MBED
rsjawale24 0:c62425b2f286 45 #include "mbed.h"
rsjawale24 0:c62425b2f286 46 #else
rsjawale24 0:c62425b2f286 47 #include <math.h>
rsjawale24 0:c62425b2f286 48 #include <string.h>
rsjawale24 0:c62425b2f286 49 #include <stdlib.h>
rsjawale24 0:c62425b2f286 50 #define TRUE 1
rsjawale24 0:c62425b2f286 51 #define FALSE 0
rsjawale24 0:c62425b2f286 52 #endif
rsjawale24 0:c62425b2f286 53
rsjawale24 0:c62425b2f286 54 // Sensor constants. Declared as constants so arrays can be statically sized
rsjawale24 0:c62425b2f286 55 #define SENSOR_XRES 10
rsjawale24 0:c62425b2f286 56 #define SENSOR_YRES 6
rsjawale24 0:c62425b2f286 57 #define NUM_SENSOR_PIXELS (SENSOR_XRES * SENSOR_YRES)
rsjawale24 0:c62425b2f286 58
rsjawale24 0:c62425b2f286 59 // Interpolation used in gesture algorithm
rsjawale24 0:c62425b2f286 60 #define INTERP_FACTOR 4
rsjawale24 0:c62425b2f286 61 #define INTERP_XRES ((SENSOR_XRES-1)*INTERP_FACTOR+1)
rsjawale24 0:c62425b2f286 62 #define INTERP_YRES ((SENSOR_YRES-1)*INTERP_FACTOR+1)
rsjawale24 0:c62425b2f286 63 #define NUM_INTERP_PIXELS (INTERP_XRES*INTERP_YRES)
rsjawale24 0:c62425b2f286 64
rsjawale24 0:c62425b2f286 65 #define DY_PIXEL_SCALE 1.42857f /*10.0f/7.0f*/
rsjawale24 0:c62425b2f286 66
rsjawale24 0:c62425b2f286 67
rsjawale24 0:c62425b2f286 68 // Error condition constants
rsjawale24 0:c62425b2f286 69 static const float MAX_ABS_ACCUM_DX = SENSOR_XRES*2; // Total x motion should not exceed 2x the screen size
rsjawale24 0:c62425b2f286 70 static const float MAX_ABS_ACCUM_DY = SENSOR_YRES*2 * DY_PIXEL_SCALE; // Total x motion should not exceed 2x the screen size
rsjawale24 0:c62425b2f286 71
rsjawale24 0:c62425b2f286 72 // Structure to store tracking results
rsjawale24 0:c62425b2f286 73 typedef struct {
rsjawale24 0:c62425b2f286 74 uint32_t state; // 0: inactive; 1: object detected
rsjawale24 0:c62425b2f286 75 int maxpixel; // Maximum pixel value for this frame
rsjawale24 0:c62425b2f286 76 float x; // Object x-position
rsjawale24 0:c62425b2f286 77 float y; // Object y-position
rsjawale24 0:c62425b2f286 78 } TrackingResult;
rsjawale24 0:c62425b2f286 79
rsjawale24 0:c62425b2f286 80 // Functions in tracking.cpp
rsjawale24 0:c62425b2f286 81 void configTracking(const uint32_t _sampleT, const uint32_t _adc_full_scale, const TrackingConfig *cfg);
rsjawale24 0:c62425b2f286 82 void runTracking(const TrackingConfig *cfg, int in_pixels[], TrackingResult *gesResult);
rsjawale24 0:c62425b2f286 83 void resetTracking();
rsjawale24 0:c62425b2f286 84 void clearTrackingCalibration();
rsjawale24 0:c62425b2f286 85
rsjawale24 0:c62425b2f286 86 // Structure to store dynamic gesture results
rsjawale24 0:c62425b2f286 87 typedef struct {
rsjawale24 0:c62425b2f286 88 uint32_t state; // 0: inactive; 1: object detected; 2: rotation in progress
rsjawale24 0:c62425b2f286 89 uint32_t n_sample; // The current sample number of this gesture
rsjawale24 0:c62425b2f286 90 int maxpixel; // Maximum pixel value for this frame
rsjawale24 0:c62425b2f286 91 float x; // Object x-position
rsjawale24 0:c62425b2f286 92 float y; // Object y-position
rsjawale24 0:c62425b2f286 93 } DynamicGestureResult;
rsjawale24 0:c62425b2f286 94
rsjawale24 0:c62425b2f286 95 #endif