NXP Touch Cursor example for LPCXpresso54608, modified for use with Mbed OS.
The tutorial for this example can be found here: https://os.mbed.com/blog/entry/How-to-LPCXpresso54608-touch-panel/
touchpanel/fsl_ft5406.h@0:c107a6f8c368, 2018-04-11 (annotated)
- Committer:
- jplunkett
- Date:
- Wed Apr 11 20:46:55 2018 +0000
- Revision:
- 0:c107a6f8c368
Init
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jplunkett | 0:c107a6f8c368 | 1 | /* |
jplunkett | 0:c107a6f8c368 | 2 | * The Clear BSD License |
jplunkett | 0:c107a6f8c368 | 3 | * Copyright (c) 2016, Freescale Semiconductor, Inc. |
jplunkett | 0:c107a6f8c368 | 4 | * Copyright 2016-2017 NXP |
jplunkett | 0:c107a6f8c368 | 5 | * All rights reserved. |
jplunkett | 0:c107a6f8c368 | 6 | * |
jplunkett | 0:c107a6f8c368 | 7 | * Redistribution and use in source and binary forms, with or without modification, |
jplunkett | 0:c107a6f8c368 | 8 | * are permitted (subject to the limitations in the disclaimer below) provided |
jplunkett | 0:c107a6f8c368 | 9 | * that the following conditions are met: |
jplunkett | 0:c107a6f8c368 | 10 | * |
jplunkett | 0:c107a6f8c368 | 11 | * o Redistributions of source code must retain the above copyright notice, this list |
jplunkett | 0:c107a6f8c368 | 12 | * of conditions and the following disclaimer. |
jplunkett | 0:c107a6f8c368 | 13 | * |
jplunkett | 0:c107a6f8c368 | 14 | * o Redistributions in binary form must reproduce the above copyright notice, this |
jplunkett | 0:c107a6f8c368 | 15 | * list of conditions and the following disclaimer in the documentation and/or |
jplunkett | 0:c107a6f8c368 | 16 | * other materials provided with the distribution. |
jplunkett | 0:c107a6f8c368 | 17 | * |
jplunkett | 0:c107a6f8c368 | 18 | * o Neither the name of the copyright holder nor the names of its |
jplunkett | 0:c107a6f8c368 | 19 | * contributors may be used to endorse or promote products derived from this |
jplunkett | 0:c107a6f8c368 | 20 | * software without specific prior written permission. |
jplunkett | 0:c107a6f8c368 | 21 | * |
jplunkett | 0:c107a6f8c368 | 22 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. |
jplunkett | 0:c107a6f8c368 | 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
jplunkett | 0:c107a6f8c368 | 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
jplunkett | 0:c107a6f8c368 | 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
jplunkett | 0:c107a6f8c368 | 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
jplunkett | 0:c107a6f8c368 | 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
jplunkett | 0:c107a6f8c368 | 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
jplunkett | 0:c107a6f8c368 | 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
jplunkett | 0:c107a6f8c368 | 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
jplunkett | 0:c107a6f8c368 | 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
jplunkett | 0:c107a6f8c368 | 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
jplunkett | 0:c107a6f8c368 | 33 | */ |
jplunkett | 0:c107a6f8c368 | 34 | |
jplunkett | 0:c107a6f8c368 | 35 | #ifndef _FSL_FT5406_H_ |
jplunkett | 0:c107a6f8c368 | 36 | #define _FSL_FT5406_H_ |
jplunkett | 0:c107a6f8c368 | 37 | |
jplunkett | 0:c107a6f8c368 | 38 | #include "fsl_common.h" |
jplunkett | 0:c107a6f8c368 | 39 | #include "fsl_i2c.h" |
jplunkett | 0:c107a6f8c368 | 40 | |
jplunkett | 0:c107a6f8c368 | 41 | /*! |
jplunkett | 0:c107a6f8c368 | 42 | * @addtogroup ft5406 |
jplunkett | 0:c107a6f8c368 | 43 | * @{ |
jplunkett | 0:c107a6f8c368 | 44 | */ |
jplunkett | 0:c107a6f8c368 | 45 | |
jplunkett | 0:c107a6f8c368 | 46 | /******************************************************************************* |
jplunkett | 0:c107a6f8c368 | 47 | * Definitions |
jplunkett | 0:c107a6f8c368 | 48 | ******************************************************************************/ |
jplunkett | 0:c107a6f8c368 | 49 | |
jplunkett | 0:c107a6f8c368 | 50 | /*! @brief FT5406 I2C address. */ |
jplunkett | 0:c107a6f8c368 | 51 | #define FT5406_I2C_ADDRESS (0x38) |
jplunkett | 0:c107a6f8c368 | 52 | |
jplunkett | 0:c107a6f8c368 | 53 | /*! @brief FT5406 maximum number of simultaneously detected touches. */ |
jplunkett | 0:c107a6f8c368 | 54 | #define FT5406_MAX_TOUCHES (5U) |
jplunkett | 0:c107a6f8c368 | 55 | |
jplunkett | 0:c107a6f8c368 | 56 | /*! @brief FT5406 register address where touch data begin. */ |
jplunkett | 0:c107a6f8c368 | 57 | #define FT5406_TOUCH_DATA_SUBADDR (1) |
jplunkett | 0:c107a6f8c368 | 58 | |
jplunkett | 0:c107a6f8c368 | 59 | /*! @brief FT5406 raw touch data length. */ |
jplunkett | 0:c107a6f8c368 | 60 | #define FT5406_TOUCH_DATA_LEN (0x20) |
jplunkett | 0:c107a6f8c368 | 61 | |
jplunkett | 0:c107a6f8c368 | 62 | typedef enum _touch_event |
jplunkett | 0:c107a6f8c368 | 63 | { |
jplunkett | 0:c107a6f8c368 | 64 | kTouch_Down = 0, /*!< The state changed to touched. */ |
jplunkett | 0:c107a6f8c368 | 65 | kTouch_Up = 1, /*!< The state changed to not touched. */ |
jplunkett | 0:c107a6f8c368 | 66 | kTouch_Contact = 2, /*!< There is a continuous touch being detected. */ |
jplunkett | 0:c107a6f8c368 | 67 | kTouch_Reserved = 3 /*!< No touch information available. */ |
jplunkett | 0:c107a6f8c368 | 68 | } touch_event_t; |
jplunkett | 0:c107a6f8c368 | 69 | |
jplunkett | 0:c107a6f8c368 | 70 | typedef struct _touch_point |
jplunkett | 0:c107a6f8c368 | 71 | { |
jplunkett | 0:c107a6f8c368 | 72 | touch_event_t TOUCH_EVENT; /*!< Indicates the state or event of the touch point. */ |
jplunkett | 0:c107a6f8c368 | 73 | uint8_t TOUCH_ID; /*!< Id of the touch point. This numeric value stays constant between down and up event. */ |
jplunkett | 0:c107a6f8c368 | 74 | uint16_t TOUCH_X; /*!< X coordinate of the touch point */ |
jplunkett | 0:c107a6f8c368 | 75 | uint16_t TOUCH_Y; /*!< Y coordinate of the touch point */ |
jplunkett | 0:c107a6f8c368 | 76 | } touch_point_t; |
jplunkett | 0:c107a6f8c368 | 77 | |
jplunkett | 0:c107a6f8c368 | 78 | typedef struct _ft5406_handle |
jplunkett | 0:c107a6f8c368 | 79 | { |
jplunkett | 0:c107a6f8c368 | 80 | I2C_Type *base; |
jplunkett | 0:c107a6f8c368 | 81 | i2c_master_transfer_t xfer; |
jplunkett | 0:c107a6f8c368 | 82 | uint8_t touch_buf[FT5406_TOUCH_DATA_LEN]; |
jplunkett | 0:c107a6f8c368 | 83 | } ft5406_handle_t; |
jplunkett | 0:c107a6f8c368 | 84 | |
jplunkett | 0:c107a6f8c368 | 85 | status_t FT5406_Init(ft5406_handle_t *handle, I2C_Type *base); |
jplunkett | 0:c107a6f8c368 | 86 | |
jplunkett | 0:c107a6f8c368 | 87 | status_t FT5406_Denit(ft5406_handle_t *handle); |
jplunkett | 0:c107a6f8c368 | 88 | |
jplunkett | 0:c107a6f8c368 | 89 | status_t FT5406_GetSingleTouch(ft5406_handle_t *handle, touch_event_t *touch_event, int *touch_x, int *touch_y); |
jplunkett | 0:c107a6f8c368 | 90 | |
jplunkett | 0:c107a6f8c368 | 91 | status_t FT5406_GetMultiTouch(ft5406_handle_t *handle, int *touch_count, touch_point_t touch_array[FT5406_MAX_TOUCHES]); |
jplunkett | 0:c107a6f8c368 | 92 | |
jplunkett | 0:c107a6f8c368 | 93 | #endif |