LCD LIB
Fork of RA8875 by
Diff: RA8875.h
- Revision:
- 124:1690a7ae871c
- Parent:
- 123:2f45e80fec5f
- Child:
- 125:7a0b70f56550
--- a/RA8875.h Mon Jul 25 10:55:58 2016 +0000 +++ b/RA8875.h Sun Jul 31 20:59:01 2016 +0000 @@ -113,6 +113,98 @@ #define max(a,b) ((a>b)?a:b) +/// FT5206 definitions follow +#define FT5206_I2C_FREQUENCY 400000 + +#define FT5206_I2C_ADDRESS 0x38 +#define FT5206_NUMBER_OF_REGISTERS 31 // there are more registers, but this + // is enough to get all 5 touch coordinates. + +#define FT5206_NUMBER_OF_TOTAL_REGISTERS 0xFE + +#define FT5206_DEVICE_MODE 0x00 // Normal, test, etc. +#define FT5206_GEST_ID 0x01 // Gesture detected +#define FT5206_TD_STATUS 0x02 // How many points detected (3:0). 1-5 is valid. + +#define FT5206_TOUCH1_XH 0x03 // Event Flag, Touch X Position +#define FT5206_TOUCH1_XL 0x04 +#define FT5206_TOUCH1_YH 0x05 // Touch ID, Touch Y Position +#define FT5206_TOUCH1_YL 0x06 + +#define FT5206_TOUCH2_XH 0x09 // Event Flag, Touch X Position +#define FT5206_TOUCH2_XL 0x0a +#define FT5206_TOUCH2_YH 0x0b // Touch ID, Touch Y Position +#define FT5206_TOUCH2_YL 0x0c + +#define FT5206_TOUCH3_XH 0x0f // Event Flag, Touch X Position +#define FT5206_TOUCH3_XL 0x10 +#define FT5206_TOUCH3_YH 0x11 // Touch ID, Touch Y Position +#define FT5206_TOUCH3_YL 0x12 + +#define FT5206_TOUCH4_XH 0x15 // Event Flag, Touch X Position +#define FT5206_TOUCH4_XL 0x16 +#define FT5206_TOUCH4_YH 0x17 // Touch ID, Touch Y Position +#define FT5206_TOUCH4_YL 0x18 + +#define FT5206_TOUCH5_XH 0x1b // Event Flag, Touch X Position +#define FT5206_TOUCH5_XL 0x1c +#define FT5206_TOUCH5_YH 0x1d // Touch ID, Touch Y Position +#define FT5206_TOUCH5_YL 0x1e + +// For typical usage, the registers listed below are not used. +#define FT5206_ID_G_THGROUP 0x80 // Valid touching detect threshold +#define FT5206_ID_G_THPEAK 0x81 // Valid touching peak detect threshold +#define FT5206_ID_G_THCAL 0x82 // The threshold when calculating the focus of touching +#define FT5206_ID_G_THWATER 0x83 // The threshold when there is surface water +#define FT5206_ID_G_THTEMP 0x84 // The threshold of temperature compensation +#define FT5206_ID_G_CTRL 0x86 // Power control mode +#define FT5206_ID_G_TIME_ENTER_MONITOR 0x87 // The timer of entering monitor status +#define FT5206_ID_G_PERIODACTIVE 0x88 // Period Active +#define FT5206_ID_G_PERIODMONITOR 0x89 // The timer of entering idle while in monitor status +#define FT5206_ID_G_AUTO_CLB_MODE 0xA0 // Auto calibration mode + +#define FT5206_TOUCH_LIB_VERSION_H 0xA1 // Firmware Library Version H byte +#define FT5206_TOUCH_LIB_VERSION_L 0xA2 // Firmware Library Version L byte +#define FT5206_ID_G_CIPHER 0xA3 // Chip vendor ID +#define FT5206_G_MODE 0xA4 // The interrupt status to host +#define FT5206_ID_G_PMODE 0xA5 // Power Consume Mode +#define FT5206_FIRMID 0xA6 // Firmware ID +#define FT5206_ID_G_STATE 0xA7 // Running State +#define FT5206_ID_G_FT5201ID 0xA8 // CTPM Vendor ID +#define FT5206_ID_G_ERR 0xA9 // Error Code +#define FT5206_ID_G_CLB 0xAA // Configure TP module during calibration in Test Mode +#define FT5206_ID_G_B_AREA_TH 0xAE // The threshold of big area +#define FT5206_LOG_MSG_CNT 0xFE // The log MSG count +#define FT5206_LOG_CUR_CHA 0xFF // Current character of log message, will point to the next + // character when one character is read. +#define FT5206_GEST_ID_MOVE_UP 0x10 +#define FT5206_GEST_ID_MOVE_LEFT 0x14 +#define FT5206_GEST_ID_MOVE_DOWN 0x18 +#define FT5206_GEST_ID_MOVE_RIGHT 0x1c +#define FT5206_GEST_ID_ZOOM_IN 0x48 +#define FT5206_GEST_ID_ZOOM_OUT 0x49 +#define FT5206_GEST_ID_NO_GESTURE 0x00 + +#define FT5206_EVENT_FLAG_PUT_DOWN 0x00 +#define FT5206_EVENT_FLAG_PUT_UP 0x01 +#define FT5206_EVENT_FLAG_CONTACT 0x02 +#define FT5206_EVENT_FLAG_RESERVED 0x03 + +#define FT5206_ID_G_POLLING_MODE 0x00 +#define FT5206_ID_G_TRIGGER_MODE 0x01 + +#define FT5206_ID_G_PMODE_ACTIVE 0x00 +#define FT5206_ID_G_PMODE_MONITOR 0x01 +#define FT5206_ID_G_PMODE_HIBERNATE 0x03 + +#define FT5206_ID_G_STATE_CONFIGURE 0x00 +#define FT5206_ID_G_STATE_WORK 0x01 +#define FT5206_ID_G_STATE_CALIBRATION 0x02 +#define FT5206_ID_G_STATE_FACTORY 0x03 +#define FT5206_ID_G_STATE_AUTO_CALIBRATION 0x04 +/// end of FT5206 definitions + + //namespace SW_graphics //{ @@ -301,7 +393,11 @@ typedef RetCode_t (* IdleCallback_T)(IdleReason_T info); /// Constructor for a display based on the RAiO RA8875 - /// display controller. + /// display controller (use for TouchScreen: Resistive or none) + /// + /// This constructor differs from the alternate by supportting + /// either No Touch Screen, or the RA8875 built-in resistive + /// touch screen. /// /// This configures the registers and calls the @ref init method. /// @@ -328,7 +424,33 @@ /// @param[in] name is a text name for this object, which will permit /// capturing stdout to puts() and printf() directly to it. /// - RA8875(PinName mosi, PinName miso, PinName sclk, PinName csel, PinName reset, const char * name = "lcd"); + RA8875(PinName mosi, PinName miso, PinName sclk, PinName csel, PinName reset, + const char * name = "lcd"); + + + /// Constructor for a display based on the RAiO RA8875 + /// display controller (use for TouchScreen: Capacitive only) + /// + /// This constructor differs from the alternate by including support + /// for the Capactive Touch screen. + /// + /// @param[in] mosi is the SPI master out slave in pin on the mbed. + /// @param[in] miso is the SPI master in slave out pin on the mbed. + /// @param[in] sclk is the SPI shift clock pin on the mbed. + /// @param[in] csel is the DigitalOut pin on the mbed to use as the + /// active low chip select for the display controller. + /// @param[in] reset is the DigitalOut pin on the mbed to use as the + /// active low reset input on the display controller - + /// but this is not currently used. + /// @param[in] sda is the I2C Serial Data pin you are wiring to the FT5206. + /// @param[in] scl is the I2C Serial Clock pin you are wiring to the FT5206. + /// @param[in] irq is the Interrupt Request pin you are wiring to the FT5206. + /// @param[in] name is a text name for this object, which will permit + /// capturing stdout to puts() and printf() directly to it. + /// + RA8875(PinName mosi, PinName miso, PinName sclk, PinName csel, PinName reset, + PinName sda, PinName scl, PinName irq, const char * name = "lcd"); + // Destructor doesn't have much to do as this would typically be created // at startup, and not at runtime. @@ -353,13 +475,17 @@ /// and the default is true (on). See @ref Power. /// @param[in] keypadon defines if the keypad support should be enabled. This parameter is optional /// and the default is true (enabled). See @ref KeypadInit. - /// @param[in] touchscreeenon defines if the keypad support should be enabled. This parameter is optional - /// and the default is true (enabled). See @ref TouchPanelInit. + /// @param[in] touchscreeenon defines if the touchscreen support should be enabled. + /// This parameter is optional and the default is true (enabled). See @ref TouchPanelInit.\\ + /// - If the constructor was called with support for the capacitive driver, this + /// parameter causes the driver to initialize. + /// - If the constructor was called without support for the capacitive driver, this + /// parameter is used to enable and initialize the resistive touchscreen driver. /// @returns success/failure code. See @ref RetCode_t. /// RetCode_t init(int width = 480, int height = 272, int color_bpp = 16, bool poweron = true, bool keypadon = true, bool touchscreeenon = true); - + /// Get a pointer to the error code. /// /// This method returns a pointer to a text string that matches the @@ -495,7 +621,7 @@ /// /// This activates the simplified touch panel init, which may work for /// most uses. The alternate API is available if fine-grained control - /// is needed for the numerous settings. + /// of the numerous settings of the resistive panel is needed. /// /// @returns success/failure code. See @ref RetCode_t. /// @@ -504,7 +630,10 @@ /// Initialize the Touch Panel controller with detailed settings. /// /// This is the detailed touch panel init, which provides the ability - /// to set nearly every possible option. + /// to set nearly every option. + /// + /// @note If the capacitive touch panel was constructed, this behaves + /// the same as the simplified version. /// /// @param[in] bTpEnable Touch Panel enable/disable control: /// - TP_ENABLE: enable the touch panel @@ -574,7 +703,84 @@ /// TouchCode_t TouchPanelReadable(point_t * TouchPoint = NULL); + /// Get the reported touch gesture, if any. + /// + /// If it could detect a gesture, it will return a value based on + /// the interpreted gesture.\\ + /// + /// Valid gesture values are: + /// @li 0x00 No gesture + /// @li 0x10 Move up + /// @li 0x14 Move left + /// @li 0x18 Move down + /// @li 0x1C Move right + /// @li 0x48 Zoom in + /// @li 0x49 Zoom out + /// + /// @returns gesture information. + /// + uint8_t TouchGesture(void) { return gesture; } + + /// Get the count of registered touches. + /// + /// @returns count of touch points to communicate; 0 to 5. + /// + int TouchCount(void) { return numberOfTouchPoints; } + + /// Get the count of possible touch channels. + /// + /// @returns count of touch channels supported by the hardware. + /// + int TouchChannels(void); + + /// Get the Touch ID value for a specified touch channel. + /// + /// Touch ID is a tracking number based on the order of the touch + /// detections. The first touch is ID 0, the next is ID 1, and + /// so on. If the first touch is lifted (no touch), the touch count + /// decrements, and the remaining touch is communicated on + /// touch channel zero, even as the Touch ID remains as originally + /// reported (1 in this example). In this way, it is easy to track + /// a specific touch.\\ + /// + /// It is possible to query the data for a channel that is not + /// presently reported as touched. + /// + /// @param[in] channel is the touch channel, from 0 to 4, or 0 to getTouchCount()-1 + /// It defaults to 0, in case the user is not interested in multi-touch. + /// @returns the touch ID, or 15 if you get the ID for an untouched channel. + /// @returns 0 if an invalid channel is queried. + /// + uint8_t TouchID(uint8_t channel = 0) { return (channel < 5) ? touchInfo[channel].touchID : touchInfo[0].touchID; } + + /// Get the Touch Code for a touch channel. + /// + /// It is possible to query the data for a channel that is not + /// presently reported as touched. + /// + /// @param[in] channel is the touch channel, from 0 to 4, or 0 to getTouchCount()-1 + /// It defaults to 0, in case the user is not interested in multi-touch. + /// @returns the touch code (@ref TouchCode_t). + /// @returns channel 0 information if an invalid channel is queried. + /// + TouchCode_t TouchCode(uint8_t channel = 0) { return (channel < 5) ? touchInfo[channel].touchCode : touchInfo[0].touchCode; } + + /// Get the coordinates for a touch channel. + /// + /// This returns the (X,Y) coordinates for a touch channel. + ///\\ + /// + /// It is possible to query the data for a channel that is not + /// presently reported as touched. + /// + /// @param[in] channel is an optional touch channel, from 0 to 4, or 0 to getTouchCount()-1. + /// It defaults to 0, in case the user is not interested in multi-touch. + /// @returns the coordinates as a point_t structure. + /// @returns channel 0 information if an invalid channel is queried. + /// + point_t TouchCoordinates(uint8_t channel = 0) { return (channel < 5) ? touchInfo[channel].coordinates : touchInfo[0].coordinates; } + /// Poll the TouchPanel and on a touch event return the a to d filtered x, y coordinates. /// /// This method reads the touch controller, which has a 10-bit range for each the @@ -2123,7 +2329,51 @@ private: - /// Touch Panel register name definitions + /// Touch panel parameters - common to both resistive and capacitive + + /// Data type to indicate which TP, if any, is in use. + typedef enum { + TP_NONE, ///< no touch panel in use + TP_RES, ///< resistive touch panel using RA8875 + TP_CAP, ///< capacitive touch panel using FT5206 + } WhichTP_T; + + /// boolean flag set true when using Capacitive touch panel, and false + /// for resistive. + WhichTP_T useTouchPanel; ///< Indicates which TP is selected for use. + + /// Touch State used by TouchPanelReadable. See @ref TouchCode_t. + TouchCode_t touchState; + + ////////////////// Start of Capacitive Touch Panel parameters + + uint8_t getTouchPositions(void); + void TouchPanelISR(void); + uint16_t numberOfTouchPoints; + uint8_t gesture; ///< Holds the reported gesture information. + + /// Touch Information data structure + typedef struct { + uint8_t touchID; ///< Contains the touch ID, which is the "order" of touch, from 0 to n-1 + TouchCode_t touchCode; ///< Contains the touch code; no_touch, touch, held, release + point_t coordinates; ///< Contains the X,Y coordinate of the touch + } touchInfo_T; + + touchInfo_T touchInfo[5]; /// Contains the actual touch information in an array from 0 to n-1 + + InterruptIn * m_irq; + I2C * m_i2c; + int m_addr; + uint8_t data[2]; + + bool panelTouched; + void writeRegister8(uint8_t reg, uint8_t val); + uint8_t readRegister8(uint8_t reg); + + + ////////////////// Start of Resistive Touch Panel parameters + + /// Resistive Touch Panel register name definitions #define TPCR0 0x70 #define TPCR1 0x71 #define TPXH 0x72 @@ -2148,9 +2398,6 @@ // a touch, and if so, it then clears the sample counter so it doesn't get partial old // and partial new. - /// Touch State used by TouchPanelReadable. See @ref TouchCode_t. - TouchCode_t touchState; - /// Touch Panel ticker Ticker touchTicker; @@ -2166,6 +2413,9 @@ /// Touch Panel calibration matrix. tpMatrix_t tpMatrix; + ////////////////// End of Touch Panel parameters + + /// Internal function to put a character using the built-in (internal) font engine /// /// @param[in] c is the character to put to the screen. @@ -2320,7 +2570,6 @@ RetCode_t (* c_callback)(filecmd_t cmd, uint8_t * buffer, uint16_t size); FPointerDummy *obj_callback; RetCode_t (FPointerDummy::*method_callback)(filecmd_t cmd, uint8_t * buffer, uint16_t size); - RetCode_t (* idle_callback)(IdleReason_T reason); };