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/
main.cpp@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 | * Copyright (c) 2016, Freescale Semiconductor, Inc. |
jplunkett | 0:c107a6f8c368 | 3 | * Copyright 2016-2017 NXP |
jplunkett | 0:c107a6f8c368 | 4 | * |
jplunkett | 0:c107a6f8c368 | 5 | * Redistribution and use in source and binary forms, with or without modification, |
jplunkett | 0:c107a6f8c368 | 6 | * are permitted provided that the following conditions are met: |
jplunkett | 0:c107a6f8c368 | 7 | * |
jplunkett | 0:c107a6f8c368 | 8 | * o Redistributions of source code must retain the above copyright notice, this list |
jplunkett | 0:c107a6f8c368 | 9 | * of conditions and the following disclaimer. |
jplunkett | 0:c107a6f8c368 | 10 | * |
jplunkett | 0:c107a6f8c368 | 11 | * o Redistributions in binary form must reproduce the above copyright notice, this |
jplunkett | 0:c107a6f8c368 | 12 | * list of conditions and the following disclaimer in the documentation and/or |
jplunkett | 0:c107a6f8c368 | 13 | * other materials provided with the distribution. |
jplunkett | 0:c107a6f8c368 | 14 | * |
jplunkett | 0:c107a6f8c368 | 15 | * o Neither the name of the copyright holder nor the names of its |
jplunkett | 0:c107a6f8c368 | 16 | * contributors may be used to endorse or promote products derived from this |
jplunkett | 0:c107a6f8c368 | 17 | * software without specific prior written permission. |
jplunkett | 0:c107a6f8c368 | 18 | * |
jplunkett | 0:c107a6f8c368 | 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
jplunkett | 0:c107a6f8c368 | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
jplunkett | 0:c107a6f8c368 | 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
jplunkett | 0:c107a6f8c368 | 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
jplunkett | 0:c107a6f8c368 | 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
jplunkett | 0:c107a6f8c368 | 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
jplunkett | 0:c107a6f8c368 | 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
jplunkett | 0:c107a6f8c368 | 26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
jplunkett | 0:c107a6f8c368 | 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
jplunkett | 0:c107a6f8c368 | 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
jplunkett | 0:c107a6f8c368 | 29 | */ |
jplunkett | 0:c107a6f8c368 | 30 | |
jplunkett | 0:c107a6f8c368 | 31 | /* Standard C Included Files */ |
jplunkett | 0:c107a6f8c368 | 32 | #include "mbed.h" |
jplunkett | 0:c107a6f8c368 | 33 | #include <stdio.h> |
jplunkett | 0:c107a6f8c368 | 34 | #include <string.h> |
jplunkett | 0:c107a6f8c368 | 35 | #include "stdio_thread.h" |
jplunkett | 0:c107a6f8c368 | 36 | #include "fsl_lcdc.h" |
jplunkett | 0:c107a6f8c368 | 37 | #include "fsl_ft5406.h" |
jplunkett | 0:c107a6f8c368 | 38 | #include "fsl_sctimer.h" |
jplunkett | 0:c107a6f8c368 | 39 | #include "fsl_gpio.h" |
jplunkett | 0:c107a6f8c368 | 40 | #include "fsl_i2c.h" |
jplunkett | 0:c107a6f8c368 | 41 | #include "board.h" |
jplunkett | 0:c107a6f8c368 | 42 | #include "pin_mux.h" |
jplunkett | 0:c107a6f8c368 | 43 | #include "image.h" |
jplunkett | 0:c107a6f8c368 | 44 | |
jplunkett | 0:c107a6f8c368 | 45 | /******************************************************************************* |
jplunkett | 0:c107a6f8c368 | 46 | * Definitions |
jplunkett | 0:c107a6f8c368 | 47 | ******************************************************************************/ |
jplunkett | 0:c107a6f8c368 | 48 | #define APP_LCD LCD |
jplunkett | 0:c107a6f8c368 | 49 | #define LCD_PANEL_CLK 9000000 |
jplunkett | 0:c107a6f8c368 | 50 | #define LCD_PPL 480 |
jplunkett | 0:c107a6f8c368 | 51 | #define LCD_HSW 2 |
jplunkett | 0:c107a6f8c368 | 52 | #define LCD_HFP 8 |
jplunkett | 0:c107a6f8c368 | 53 | #define LCD_HBP 43 |
jplunkett | 0:c107a6f8c368 | 54 | #define LCD_LPP 272 |
jplunkett | 0:c107a6f8c368 | 55 | #define LCD_VSW 10 |
jplunkett | 0:c107a6f8c368 | 56 | #define LCD_VFP 4 |
jplunkett | 0:c107a6f8c368 | 57 | #define LCD_VBP 12 |
jplunkett | 0:c107a6f8c368 | 58 | #define LCD_POL_FLAGS kLCDC_InvertVsyncPolarity | kLCDC_InvertHsyncPolarity |
jplunkett | 0:c107a6f8c368 | 59 | #define IMG_HEIGHT 272 |
jplunkett | 0:c107a6f8c368 | 60 | #define IMG_WIDTH 480 |
jplunkett | 0:c107a6f8c368 | 61 | #define LCD_INPUT_CLK_FREQ CLOCK_GetFreq(kCLOCK_LCD) |
jplunkett | 0:c107a6f8c368 | 62 | #define APP_LCD_IRQHandler LCD_IRQHandler |
jplunkett | 0:c107a6f8c368 | 63 | #define APP_LCD_IRQn LCD_IRQn |
jplunkett | 0:c107a6f8c368 | 64 | #define EXAMPLE_I2C_MASTER_BASE (I2C2_BASE) |
jplunkett | 0:c107a6f8c368 | 65 | #define I2C_MASTER_CLOCK_FREQUENCY (12000000) |
jplunkett | 0:c107a6f8c368 | 66 | #define APP_PIXEL_PER_BYTE 8 |
jplunkett | 0:c107a6f8c368 | 67 | |
jplunkett | 0:c107a6f8c368 | 68 | #define EXAMPLE_I2C_MASTER ((I2C_Type *)EXAMPLE_I2C_MASTER_BASE) |
jplunkett | 0:c107a6f8c368 | 69 | #define I2C_MASTER_SLAVE_ADDR_7BIT 0x7EU |
jplunkett | 0:c107a6f8c368 | 70 | #define I2C_BAUDRATE 100000U |
jplunkett | 0:c107a6f8c368 | 71 | |
jplunkett | 0:c107a6f8c368 | 72 | /******************************************************************************* |
jplunkett | 0:c107a6f8c368 | 73 | * Prototypes |
jplunkett | 0:c107a6f8c368 | 74 | ******************************************************************************/ |
jplunkett | 0:c107a6f8c368 | 75 | |
jplunkett | 0:c107a6f8c368 | 76 | /******************************************************************************* |
jplunkett | 0:c107a6f8c368 | 77 | * Variables |
jplunkett | 0:c107a6f8c368 | 78 | ******************************************************************************/ |
jplunkett | 0:c107a6f8c368 | 79 | |
jplunkett | 0:c107a6f8c368 | 80 | #if (defined(__CC_ARM) || defined(__GNUC__)) |
jplunkett | 0:c107a6f8c368 | 81 | __attribute__((aligned(8))) |
jplunkett | 0:c107a6f8c368 | 82 | #elif defined(__ICCARM__) |
jplunkett | 0:c107a6f8c368 | 83 | #pragma data_alignment = 8 |
jplunkett | 0:c107a6f8c368 | 84 | #else |
jplunkett | 0:c107a6f8c368 | 85 | #error Toolchain not support. |
jplunkett | 0:c107a6f8c368 | 86 | #endif |
jplunkett | 0:c107a6f8c368 | 87 | |
jplunkett | 0:c107a6f8c368 | 88 | void *vram_ptr = s_frameBufs; |
jplunkett | 0:c107a6f8c368 | 89 | |
jplunkett | 0:c107a6f8c368 | 90 | /* Frame end flag. */ |
jplunkett | 0:c107a6f8c368 | 91 | static volatile bool s_frameEndFlag; |
jplunkett | 0:c107a6f8c368 | 92 | |
jplunkett | 0:c107a6f8c368 | 93 | /* Color palette. */ |
jplunkett | 0:c107a6f8c368 | 94 | static const uint32_t palette[] = { 0x001F00000 }; //{0x0000001F}; //{0x001F0000U, 0x7C0003E0U}; |
jplunkett | 0:c107a6f8c368 | 95 | |
jplunkett | 0:c107a6f8c368 | 96 | /* 32x32 pixel cursor image. */ |
jplunkett | 0:c107a6f8c368 | 97 | #if (defined(__CC_ARM) || defined(__GNUC__)) |
jplunkett | 0:c107a6f8c368 | 98 | __attribute__((aligned(4))) |
jplunkett | 0:c107a6f8c368 | 99 | #elif defined(__ICCARM__) |
jplunkett | 0:c107a6f8c368 | 100 | #pragma data_alignment = 4 |
jplunkett | 0:c107a6f8c368 | 101 | #else |
jplunkett | 0:c107a6f8c368 | 102 | #error Toolchain not support. |
jplunkett | 0:c107a6f8c368 | 103 | #endif |
jplunkett | 0:c107a6f8c368 | 104 | static const uint8_t cursor32Img0[] = { |
jplunkett | 0:c107a6f8c368 | 105 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
jplunkett | 0:c107a6f8c368 | 106 | 0xAA, 0xAA, 0xAA, /* Line 1. */ |
jplunkett | 0:c107a6f8c368 | 107 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
jplunkett | 0:c107a6f8c368 | 108 | 0xAA, 0xAA, 0xAA, /* Line 2. */ |
jplunkett | 0:c107a6f8c368 | 109 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
jplunkett | 0:c107a6f8c368 | 110 | 0xAA, 0xAA, 0xAA, /* Line 3. */ |
jplunkett | 0:c107a6f8c368 | 111 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
jplunkett | 0:c107a6f8c368 | 112 | 0xAA, 0xAA, 0xAA, /* Line 4. */ |
jplunkett | 0:c107a6f8c368 | 113 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
jplunkett | 0:c107a6f8c368 | 114 | 0xAA, 0xAA, 0xAA, /* Line 5. */ |
jplunkett | 0:c107a6f8c368 | 115 | 0xAA, 0xAA, 0xAA, 0xFA, 0xAA, |
jplunkett | 0:c107a6f8c368 | 116 | 0xAA, 0xAA, 0xAA, /* Line 6. */ |
jplunkett | 0:c107a6f8c368 | 117 | 0xAA, 0xAA, 0xAB, 0xFE, 0xAA, |
jplunkett | 0:c107a6f8c368 | 118 | 0xAA, 0xAA, 0xAA, /* Line 7. */ |
jplunkett | 0:c107a6f8c368 | 119 | 0xAA, 0xAA, 0xAB, 0xFE, 0xAA, |
jplunkett | 0:c107a6f8c368 | 120 | 0xAA, 0xAA, 0xAA, /* Line 8. */ |
jplunkett | 0:c107a6f8c368 | 121 | 0xAA, 0xAA, 0xAB, 0xFE, 0xAA, |
jplunkett | 0:c107a6f8c368 | 122 | 0xAA, 0xAA, 0xAA, /* Line 9. */ |
jplunkett | 0:c107a6f8c368 | 123 | 0xAA, 0xAA, 0xAB, 0xFE, 0xAA, |
jplunkett | 0:c107a6f8c368 | 124 | 0xAA, 0xAA, 0xAA, /* Line 10 */ |
jplunkett | 0:c107a6f8c368 | 125 | 0xAA, 0xAA, 0xAB, 0xFF, 0xEA, |
jplunkett | 0:c107a6f8c368 | 126 | 0xAA, 0xAA, 0xAA, /* Line 11. */ |
jplunkett | 0:c107a6f8c368 | 127 | 0xAA, 0xAA, 0xAB, 0xFF, 0xFF, |
jplunkett | 0:c107a6f8c368 | 128 | 0xAA, 0xAA, 0xAA, /* Line 12. */ |
jplunkett | 0:c107a6f8c368 | 129 | 0xAA, 0xAA, 0xAB, 0xFF, 0xFF, |
jplunkett | 0:c107a6f8c368 | 130 | 0xFA, 0xAA, 0xAA, /* Line 13. */ |
jplunkett | 0:c107a6f8c368 | 131 | 0xAA, 0xAA, 0xAB, 0xFF, 0xFF, |
jplunkett | 0:c107a6f8c368 | 132 | 0xFE, 0xAA, 0xAA, /* Line 14. */ |
jplunkett | 0:c107a6f8c368 | 133 | 0xAA, 0xAB, 0xFB, 0xFF, 0xFF, |
jplunkett | 0:c107a6f8c368 | 134 | 0xFF, 0xAA, 0xAA, /* Line 15. */ |
jplunkett | 0:c107a6f8c368 | 135 | 0xAA, 0xAB, 0xFF, 0xFF, 0xFF, |
jplunkett | 0:c107a6f8c368 | 136 | 0xFF, 0xAA, 0xAA, /* Line 16. */ |
jplunkett | 0:c107a6f8c368 | 137 | 0xAA, 0xAB, 0xFF, 0xFF, 0xFF, |
jplunkett | 0:c107a6f8c368 | 138 | 0xFF, 0xAA, 0xAA, /* Line 17. */ |
jplunkett | 0:c107a6f8c368 | 139 | 0xAA, 0xAA, 0xFF, 0xFF, 0xFF, |
jplunkett | 0:c107a6f8c368 | 140 | 0xFF, 0xAA, 0xAA, /* Line 18. */ |
jplunkett | 0:c107a6f8c368 | 141 | 0xAA, 0xAA, 0xBF, 0xFF, 0xFF, |
jplunkett | 0:c107a6f8c368 | 142 | 0xFF, 0xAA, 0xAA, /* Line 19. */ |
jplunkett | 0:c107a6f8c368 | 143 | 0xAA, 0xAA, 0xBF, 0xFF, 0xFF, |
jplunkett | 0:c107a6f8c368 | 144 | 0xFF, 0xAA, 0xAA, /* Line 20. */ |
jplunkett | 0:c107a6f8c368 | 145 | 0xAA, 0xAA, 0xAF, 0xFF, 0xFF, |
jplunkett | 0:c107a6f8c368 | 146 | 0xFF, 0xAA, 0xAA, /* Line 21. */ |
jplunkett | 0:c107a6f8c368 | 147 | 0xAA, 0xAA, 0xAF, 0xFF, 0xFF, |
jplunkett | 0:c107a6f8c368 | 148 | 0xFE, 0xAA, 0xAA, /* Line 22. */ |
jplunkett | 0:c107a6f8c368 | 149 | 0xAA, 0xAA, 0xAB, 0xFF, 0xFF, |
jplunkett | 0:c107a6f8c368 | 150 | 0xFE, 0xAA, 0xAA, /* Line 23. */ |
jplunkett | 0:c107a6f8c368 | 151 | 0xAA, 0xAA, 0xAB, 0xFF, 0xFF, |
jplunkett | 0:c107a6f8c368 | 152 | 0xFE, 0xAA, 0xAA, /* Line 24. */ |
jplunkett | 0:c107a6f8c368 | 153 | 0xAA, 0xAA, 0xAA, 0xFF, 0xFF, |
jplunkett | 0:c107a6f8c368 | 154 | 0xFA, 0xAA, 0xAA, /* Line 25. */ |
jplunkett | 0:c107a6f8c368 | 155 | 0xAA, 0xAA, 0xAA, 0xFF, 0xFF, |
jplunkett | 0:c107a6f8c368 | 156 | 0xFA, 0xAA, 0xAA, /* Line 26. */ |
jplunkett | 0:c107a6f8c368 | 157 | 0xAA, 0xAA, 0xAA, 0xFF, 0xFF, |
jplunkett | 0:c107a6f8c368 | 158 | 0xFA, 0xAA, 0xAA, /* Line 27. */ |
jplunkett | 0:c107a6f8c368 | 159 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
jplunkett | 0:c107a6f8c368 | 160 | 0xAA, 0xAA, 0xAA, /* Line 28. */ |
jplunkett | 0:c107a6f8c368 | 161 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
jplunkett | 0:c107a6f8c368 | 162 | 0xAA, 0xAA, 0xAA, /* Line 29. */ |
jplunkett | 0:c107a6f8c368 | 163 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
jplunkett | 0:c107a6f8c368 | 164 | 0xAA, 0xAA, 0xAA, /* Line 30. */ |
jplunkett | 0:c107a6f8c368 | 165 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
jplunkett | 0:c107a6f8c368 | 166 | 0xAA, 0xAA, 0xAA, /* Line 31. */ |
jplunkett | 0:c107a6f8c368 | 167 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
jplunkett | 0:c107a6f8c368 | 168 | 0xAA, 0xAA, 0xAA /* Line 32. */ |
jplunkett | 0:c107a6f8c368 | 169 | }; |
jplunkett | 0:c107a6f8c368 | 170 | |
jplunkett | 0:c107a6f8c368 | 171 | /******************************************************************************* |
jplunkett | 0:c107a6f8c368 | 172 | * Code |
jplunkett | 0:c107a6f8c368 | 173 | ******************************************************************************/ |
jplunkett | 0:c107a6f8c368 | 174 | static void BOARD_InitPWM(void) |
jplunkett | 0:c107a6f8c368 | 175 | { |
jplunkett | 0:c107a6f8c368 | 176 | sctimer_config_t config; |
jplunkett | 0:c107a6f8c368 | 177 | sctimer_pwm_signal_param_t pwmParam; |
jplunkett | 0:c107a6f8c368 | 178 | uint32_t event; |
jplunkett | 0:c107a6f8c368 | 179 | |
jplunkett | 0:c107a6f8c368 | 180 | CLOCK_AttachClk(kMCLK_to_SCT_CLK); |
jplunkett | 0:c107a6f8c368 | 181 | |
jplunkett | 0:c107a6f8c368 | 182 | CLOCK_SetClkDiv(kCLOCK_DivSctClk, 2, true); |
jplunkett | 0:c107a6f8c368 | 183 | |
jplunkett | 0:c107a6f8c368 | 184 | SCTIMER_GetDefaultConfig(&config); |
jplunkett | 0:c107a6f8c368 | 185 | |
jplunkett | 0:c107a6f8c368 | 186 | SCTIMER_Init(SCT0, &config); |
jplunkett | 0:c107a6f8c368 | 187 | |
jplunkett | 0:c107a6f8c368 | 188 | pwmParam.output = kSCTIMER_Out_5; |
jplunkett | 0:c107a6f8c368 | 189 | pwmParam.level = kSCTIMER_HighTrue; |
jplunkett | 0:c107a6f8c368 | 190 | pwmParam.dutyCyclePercent = 5; |
jplunkett | 0:c107a6f8c368 | 191 | |
jplunkett | 0:c107a6f8c368 | 192 | SCTIMER_SetupPwm(SCT0, &pwmParam, kSCTIMER_CenterAlignedPwm, 1000U, CLOCK_GetFreq(kCLOCK_Sct), &event); |
jplunkett | 0:c107a6f8c368 | 193 | } |
jplunkett | 0:c107a6f8c368 | 194 | |
jplunkett | 0:c107a6f8c368 | 195 | void APP_LCD_IRQHandler(void) |
jplunkett | 0:c107a6f8c368 | 196 | { |
jplunkett | 0:c107a6f8c368 | 197 | uint32_t intStatus = LCDC_GetEnabledInterruptsPendingStatus(APP_LCD); |
jplunkett | 0:c107a6f8c368 | 198 | |
jplunkett | 0:c107a6f8c368 | 199 | LCDC_ClearInterruptsStatus(APP_LCD, intStatus); |
jplunkett | 0:c107a6f8c368 | 200 | |
jplunkett | 0:c107a6f8c368 | 201 | if (intStatus & kLCDC_VerticalCompareInterrupt) |
jplunkett | 0:c107a6f8c368 | 202 | { |
jplunkett | 0:c107a6f8c368 | 203 | s_frameEndFlag = true; |
jplunkett | 0:c107a6f8c368 | 204 | } |
jplunkett | 0:c107a6f8c368 | 205 | __DSB(); |
jplunkett | 0:c107a6f8c368 | 206 | } |
jplunkett | 0:c107a6f8c368 | 207 | |
jplunkett | 0:c107a6f8c368 | 208 | status_t APP_LCDC_Init(void) |
jplunkett | 0:c107a6f8c368 | 209 | { |
jplunkett | 0:c107a6f8c368 | 210 | /* Initialize the display. */ |
jplunkett | 0:c107a6f8c368 | 211 | lcdc_config_t lcdConfig; |
jplunkett | 0:c107a6f8c368 | 212 | lcdc_cursor_config_t cursorConfig; |
jplunkett | 0:c107a6f8c368 | 213 | |
jplunkett | 0:c107a6f8c368 | 214 | LCDC_GetDefaultConfig(&lcdConfig); |
jplunkett | 0:c107a6f8c368 | 215 | |
jplunkett | 0:c107a6f8c368 | 216 | lcdConfig.panelClock_Hz = LCD_PANEL_CLK; |
jplunkett | 0:c107a6f8c368 | 217 | lcdConfig.ppl = LCD_PPL; |
jplunkett | 0:c107a6f8c368 | 218 | lcdConfig.hsw = LCD_HSW; |
jplunkett | 0:c107a6f8c368 | 219 | lcdConfig.hfp = LCD_HFP; |
jplunkett | 0:c107a6f8c368 | 220 | lcdConfig.hbp = LCD_HBP; |
jplunkett | 0:c107a6f8c368 | 221 | lcdConfig.lpp = LCD_LPP; |
jplunkett | 0:c107a6f8c368 | 222 | lcdConfig.vsw = LCD_VSW; |
jplunkett | 0:c107a6f8c368 | 223 | lcdConfig.vfp = LCD_VFP; |
jplunkett | 0:c107a6f8c368 | 224 | lcdConfig.vbp = LCD_VBP; |
jplunkett | 0:c107a6f8c368 | 225 | lcdConfig.polarityFlags = LCD_POL_FLAGS; |
jplunkett | 0:c107a6f8c368 | 226 | lcdConfig.upperPanelAddr = (uint32_t)s_frameBufs; |
jplunkett | 0:c107a6f8c368 | 227 | lcdConfig.bpp = kLCDC_1BPP; |
jplunkett | 0:c107a6f8c368 | 228 | lcdConfig.display = kLCDC_DisplayTFT; |
jplunkett | 0:c107a6f8c368 | 229 | lcdConfig.swapRedBlue = true; //false; |
jplunkett | 0:c107a6f8c368 | 230 | lcdConfig.dataFormat = kLCDC_WinCeMode; |
jplunkett | 0:c107a6f8c368 | 231 | |
jplunkett | 0:c107a6f8c368 | 232 | LCDC_Init(APP_LCD, &lcdConfig, LCD_INPUT_CLK_FREQ); |
jplunkett | 0:c107a6f8c368 | 233 | |
jplunkett | 0:c107a6f8c368 | 234 | LCDC_SetPalette(APP_LCD, palette, ARRAY_SIZE(palette)); |
jplunkett | 0:c107a6f8c368 | 235 | |
jplunkett | 0:c107a6f8c368 | 236 | /* Setup the Cursor. */ |
jplunkett | 0:c107a6f8c368 | 237 | LCDC_CursorGetDefaultConfig(&cursorConfig); |
jplunkett | 0:c107a6f8c368 | 238 | |
jplunkett | 0:c107a6f8c368 | 239 | cursorConfig.size = kLCDC_CursorSize32; |
jplunkett | 0:c107a6f8c368 | 240 | cursorConfig.syncMode = kLCDC_CursorSync; |
jplunkett | 0:c107a6f8c368 | 241 | cursorConfig.image[0] = (uint32_t *)cursor32Img0; |
jplunkett | 0:c107a6f8c368 | 242 | |
jplunkett | 0:c107a6f8c368 | 243 | LCDC_SetCursorConfig(APP_LCD, &cursorConfig); |
jplunkett | 0:c107a6f8c368 | 244 | LCDC_ChooseCursor(APP_LCD, 0); |
jplunkett | 0:c107a6f8c368 | 245 | |
jplunkett | 0:c107a6f8c368 | 246 | /* Trigger interrupt at start of every vertical back porch. */ |
jplunkett | 0:c107a6f8c368 | 247 | LCDC_SetVerticalInterruptMode(APP_LCD, kLCDC_StartOfBackPorch); |
jplunkett | 0:c107a6f8c368 | 248 | LCDC_EnableInterrupts(APP_LCD, kLCDC_VerticalCompareInterrupt); |
jplunkett | 0:c107a6f8c368 | 249 | // NVIC_EnableIRQ(APP_LCD_IRQn); |
jplunkett | 0:c107a6f8c368 | 250 | |
jplunkett | 0:c107a6f8c368 | 251 | LCDC_EnableCursor(APP_LCD, true); |
jplunkett | 0:c107a6f8c368 | 252 | |
jplunkett | 0:c107a6f8c368 | 253 | LCDC_Start(APP_LCD); |
jplunkett | 0:c107a6f8c368 | 254 | LCDC_PowerUp(APP_LCD); |
jplunkett | 0:c107a6f8c368 | 255 | |
jplunkett | 0:c107a6f8c368 | 256 | return kStatus_Success; |
jplunkett | 0:c107a6f8c368 | 257 | } |
jplunkett | 0:c107a6f8c368 | 258 | |
jplunkett | 0:c107a6f8c368 | 259 | status_t APP_I2C_Init(void) |
jplunkett | 0:c107a6f8c368 | 260 | { |
jplunkett | 0:c107a6f8c368 | 261 | i2c_master_config_t masterConfig; |
jplunkett | 0:c107a6f8c368 | 262 | |
jplunkett | 0:c107a6f8c368 | 263 | I2C_MasterGetDefaultConfig(&masterConfig); |
jplunkett | 0:c107a6f8c368 | 264 | |
jplunkett | 0:c107a6f8c368 | 265 | /* Change the default baudrate configuration */ |
jplunkett | 0:c107a6f8c368 | 266 | masterConfig.baudRate_Bps = I2C_BAUDRATE; |
jplunkett | 0:c107a6f8c368 | 267 | |
jplunkett | 0:c107a6f8c368 | 268 | /* Initialize the I2C master peripheral */ |
jplunkett | 0:c107a6f8c368 | 269 | I2C_MasterInit(EXAMPLE_I2C_MASTER, &masterConfig, I2C_MASTER_CLOCK_FREQUENCY); |
jplunkett | 0:c107a6f8c368 | 270 | |
jplunkett | 0:c107a6f8c368 | 271 | return kStatus_Success; |
jplunkett | 0:c107a6f8c368 | 272 | } |
jplunkett | 0:c107a6f8c368 | 273 | |
jplunkett | 0:c107a6f8c368 | 274 | void APP_SetCursorPosition(int posX, int posY) |
jplunkett | 0:c107a6f8c368 | 275 | { |
jplunkett | 0:c107a6f8c368 | 276 | posX -= 12; |
jplunkett | 0:c107a6f8c368 | 277 | posY -= 5; |
jplunkett | 0:c107a6f8c368 | 278 | |
jplunkett | 0:c107a6f8c368 | 279 | LCDC_SetCursorPosition(APP_LCD, posX, posY); |
jplunkett | 0:c107a6f8c368 | 280 | } |
jplunkett | 0:c107a6f8c368 | 281 | |
jplunkett | 0:c107a6f8c368 | 282 | int main(void) |
jplunkett | 0:c107a6f8c368 | 283 | { |
jplunkett | 0:c107a6f8c368 | 284 | int cursorPosX = 0U; |
jplunkett | 0:c107a6f8c368 | 285 | int cursorPosY = 0U; |
jplunkett | 0:c107a6f8c368 | 286 | |
jplunkett | 0:c107a6f8c368 | 287 | ft5406_handle_t touch_handle; |
jplunkett | 0:c107a6f8c368 | 288 | touch_event_t touch_event; |
jplunkett | 0:c107a6f8c368 | 289 | |
jplunkett | 0:c107a6f8c368 | 290 | status_t status; |
jplunkett | 0:c107a6f8c368 | 291 | |
jplunkett | 0:c107a6f8c368 | 292 | gpio_pin_config_t pin_config = { |
jplunkett | 0:c107a6f8c368 | 293 | kGPIO_DigitalOutput, 0, |
jplunkett | 0:c107a6f8c368 | 294 | }; |
jplunkett | 0:c107a6f8c368 | 295 | |
jplunkett | 0:c107a6f8c368 | 296 | /* Board pin, clock, debug console init */ |
jplunkett | 0:c107a6f8c368 | 297 | /* attach 12 MHz clock to FLEXCOMM0 (debug console) */ |
jplunkett | 0:c107a6f8c368 | 298 | CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH); |
jplunkett | 0:c107a6f8c368 | 299 | |
jplunkett | 0:c107a6f8c368 | 300 | /* Route Main clock to LCD. */ |
jplunkett | 0:c107a6f8c368 | 301 | CLOCK_AttachClk(kMCLK_to_LCD_CLK); |
jplunkett | 0:c107a6f8c368 | 302 | |
jplunkett | 0:c107a6f8c368 | 303 | /* attach 12 MHz clock to FLEXCOMM2 (I2C master for touch controller) */ |
jplunkett | 0:c107a6f8c368 | 304 | CLOCK_AttachClk(kFRO12M_to_FLEXCOMM2); |
jplunkett | 0:c107a6f8c368 | 305 | |
jplunkett | 0:c107a6f8c368 | 306 | CLOCK_EnableClock(kCLOCK_Gpio2); |
jplunkett | 0:c107a6f8c368 | 307 | |
jplunkett | 0:c107a6f8c368 | 308 | CLOCK_SetClkDiv(kCLOCK_DivLcdClk, 1, true); |
jplunkett | 0:c107a6f8c368 | 309 | |
jplunkett | 0:c107a6f8c368 | 310 | BOARD_InitPins(); |
jplunkett | 0:c107a6f8c368 | 311 | BOARD_BootClockFROHF48M(); |
jplunkett | 0:c107a6f8c368 | 312 | // BOARD_InitDebugConsole(); |
jplunkett | 0:c107a6f8c368 | 313 | |
jplunkett | 0:c107a6f8c368 | 314 | /* Set the back light PWM. */ |
jplunkett | 0:c107a6f8c368 | 315 | BOARD_InitPWM(); |
jplunkett | 0:c107a6f8c368 | 316 | |
jplunkett | 0:c107a6f8c368 | 317 | // APP_FillBuffer((void *)(s_frameBufs)); |
jplunkett | 0:c107a6f8c368 | 318 | |
jplunkett | 0:c107a6f8c368 | 319 | status = APP_LCDC_Init(); |
jplunkett | 0:c107a6f8c368 | 320 | if (status != kStatus_Success) |
jplunkett | 0:c107a6f8c368 | 321 | { |
jplunkett | 0:c107a6f8c368 | 322 | safe_printf("LCD init failed\n"); |
jplunkett | 0:c107a6f8c368 | 323 | } |
jplunkett | 0:c107a6f8c368 | 324 | assert(status == kStatus_Success); |
jplunkett | 0:c107a6f8c368 | 325 | |
jplunkett | 0:c107a6f8c368 | 326 | status = APP_I2C_Init(); |
jplunkett | 0:c107a6f8c368 | 327 | if (status != kStatus_Success) |
jplunkett | 0:c107a6f8c368 | 328 | { |
jplunkett | 0:c107a6f8c368 | 329 | safe_printf("I2C init failed\n"); |
jplunkett | 0:c107a6f8c368 | 330 | } |
jplunkett | 0:c107a6f8c368 | 331 | assert(status == kStatus_Success); |
jplunkett | 0:c107a6f8c368 | 332 | |
jplunkett | 0:c107a6f8c368 | 333 | GPIO_PinInit(GPIO, 2, 27, &pin_config); |
jplunkett | 0:c107a6f8c368 | 334 | // GPIO_WritePinOutput(GPIO, 2, 27, 1); |
jplunkett | 0:c107a6f8c368 | 335 | GPIO->B[2][27] = 1; |
jplunkett | 0:c107a6f8c368 | 336 | |
jplunkett | 0:c107a6f8c368 | 337 | status = FT5406_Init(&touch_handle, EXAMPLE_I2C_MASTER); |
jplunkett | 0:c107a6f8c368 | 338 | if (status != kStatus_Success) |
jplunkett | 0:c107a6f8c368 | 339 | { |
jplunkett | 0:c107a6f8c368 | 340 | safe_printf("Touch panel init failed\n"); |
jplunkett | 0:c107a6f8c368 | 341 | } |
jplunkett | 0:c107a6f8c368 | 342 | assert(status == kStatus_Success); |
jplunkett | 0:c107a6f8c368 | 343 | |
jplunkett | 0:c107a6f8c368 | 344 | uint32_t xMin = 0xbd; |
jplunkett | 0:c107a6f8c368 | 345 | uint32_t xMax = 0xea; |
jplunkett | 0:c107a6f8c368 | 346 | uint32_t yMin = 0xb7; |
jplunkett | 0:c107a6f8c368 | 347 | uint32_t yMax = 0x12f; |
jplunkett | 0:c107a6f8c368 | 348 | |
jplunkett | 0:c107a6f8c368 | 349 | for (;;) |
jplunkett | 0:c107a6f8c368 | 350 | { |
jplunkett | 0:c107a6f8c368 | 351 | if (kStatus_Success == FT5406_GetSingleTouch(&touch_handle, &touch_event, &cursorPosX, &cursorPosY)) |
jplunkett | 0:c107a6f8c368 | 352 | { |
jplunkett | 0:c107a6f8c368 | 353 | if ((touch_event == kTouch_Down) || (touch_event == kTouch_Contact)) |
jplunkett | 0:c107a6f8c368 | 354 | { |
jplunkett | 0:c107a6f8c368 | 355 | /* Update cursor position */ |
jplunkett | 0:c107a6f8c368 | 356 | APP_SetCursorPosition(cursorPosY, cursorPosX); |
jplunkett | 0:c107a6f8c368 | 357 | if (xMin < cursorPosX && cursorPosX < xMax && yMin < cursorPosY && cursorPosY < yMax) { |
jplunkett | 0:c107a6f8c368 | 358 | safe_printf("You've clicked the button! (0x%2x, 0x%2x)\r\n", cursorPosX, cursorPosY); |
jplunkett | 0:c107a6f8c368 | 359 | } |
jplunkett | 0:c107a6f8c368 | 360 | } |
jplunkett | 0:c107a6f8c368 | 361 | } |
jplunkett | 0:c107a6f8c368 | 362 | else |
jplunkett | 0:c107a6f8c368 | 363 | { |
jplunkett | 0:c107a6f8c368 | 364 | safe_printf("error reading touch controller\r\n"); |
jplunkett | 0:c107a6f8c368 | 365 | } |
jplunkett | 0:c107a6f8c368 | 366 | } |
jplunkett | 0:c107a6f8c368 | 367 | } |