The following document contains information on Cypress products. AN702-00029-1v0-E 8-BIT MICROCONTROLLER New 8FX Family MB95870K/860K/850K series SAMPLE PROJECT AN702-00029-1v0-E All Rights Reserved. The contents of this document are subject to change without notice. Customers are advised to consult with FUJITSU sales representatives before ordering. The information, such as descriptions of function and application circuit examples, in this document are presented solely for the purpose of reference to show examples of operations and uses of Fujitsu semiconductor device; Fujitsu does not warrant proper operation of the device with respect to use based on such information. When you develop equipment incorporating the device based on such information, you must assume any responsibility arising out of such use of the information. Fujitsu assumes no liability for any damages whatsoever arising out of the use of the information. Any information in this document, including descriptions of function and schematic diagrams, shall not be construed as license of the use or exercise of any intellectual property right, such as patent right or copyright, or any other right of Fujitsu or any third party or does Fujitsu warrant non-infringement of any third-party’s intellectual property right or other right by using such information. Fujitsu assumes no liability for any infringement of the intellectual property rights or other rights of third parties which would result from the use of information contained herein. The products described in this document are designed, developed and manufactured as contemplated for general use, including without limitation, ordinary industrial use, general office use, personal use, and household use, but are not designed, developed and manufactured as contemplated (1) for use accompanying fatal risks or dangers that, unless extremely high safety is secured, could have a serious effect to the public, and could lead directly to death, personal injury, severe physical damage or other loss (i.e., nuclear reaction control in nuclear facility, aircraft flight control, air traffic control, mass transport control, medical life support system, missile launch control in weapon system), or (2) for use requiring extremely high reliability (i.e., submersible repeater and artificial satellite). Please note that Fujitsu will not be liable against you and/or any third party for any claims or damages arising in connection with above-mentioned uses of the products. Any semiconductor devices have an inherent chance of failure. You must protect against injury, damage or loss from such failures by incorporating safety design measures into your facility and equipment such as redundancy, fire protection, and prevention of over-current levels and other abnormal operating conditions. If any products described in this document represent goods or technologies subject to certain restrictions on export under the Foreign Exchange and Foreign Trade Law of Japan, the prior authorization by Japanese government will be required for export of those products from Japan. The company names and brand names herein are the trademarks or registered trademarks of their respective owners. Copyright© 2012 FUJITSU SEMICONDUCTOR LIMITED all rights reserved 1 AN702-00029-1v0-E Revision History Rev Date Remark 1.0 2012-11-06 First Edition 2 AN702-00029-1v0-E Table of Contents Revision History...................................................................................................................... 2 Table of Contents.................................................................................................................... 3 Target products ....................................................................................................................... 6 1 2 Introduction...................................................................................................................... 7 1.1 Purpose.................................................................................................................... 7 1.2 Definitions, Acronyms and Abbreviations ................................................................ 7 1.3 Document Overview ................................................................................................ 7 System Hardware Environment ...................................................................................... 8 2.1 MCU Information...................................................................................................... 8 2.2 EVB Information....................................................................................................... 8 3 Development Environment.............................................................................................. 9 4 Sample Project System ................................................................................................. 10 5 4.1 System Introduction ............................................................................................... 10 4.2 System Features.................................................................................................... 10 4.3 System Firmware Design ....................................................................................... 11 4.3.1 User Interface .................................................................................................. 11 4.3.2 System Module ............................................................................................... 12 4.3.3 System Main Loop.......................................................................................... 13 4.3.4 System Files ................................................................................................... 13 4.3.5 System Files Structure ................................................................................... 15 System Function ........................................................................................................... 16 5.1 Overview ................................................................................................................ 16 5.1.1 Function List ................................................................................................... 16 5.1.2 Macro and Constant List ................................................................................ 16 5.1.3 Data Structure and Type Definition ................................................................ 19 5.2 System Initialization ............................................................................................... 20 5.2.1 Machine Clock ................................................................................................ 20 5.2.2 Watchdog........................................................................................................ 20 5.2.3 System Initialization........................................................................................ 20 5.3 Module Initialization ............................................................................................... 21 5.3.1 TS Module ...................................................................................................... 21 5.3.2 Timer Module.................................................................................................. 21 5.3.3 LED Module .................................................................................................... 21 5.3.4 Beep Module .................................................................................................. 22 3 AN702-00029-1v0-E 5.3.5 UART Module ................................................................................................. 22 5.3.6 Control Switch ................................................................................................ 22 5.4 6 Module Drivers .............................................................................................................. 24 6.1 7 Function List ................................................................................................... 25 6.1.2 Macro and Constant List ................................................................................ 25 6.1.3 Data Structure and Type Define ..................................................................... 25 6.2 TS Module Driver ................................................................................................... 26 6.3 LED Module Driver ................................................................................................ 26 6.4 BEEP Module Driver .............................................................................................. 27 6.5 Control Switch Driver ............................................................................................. 28 Middleware .................................................................................................................... 29 Overview ................................................................................................................ 29 7.1.1 Function List ................................................................................................... 30 7.1.2 Macro and Constant List ................................................................................ 31 7.1.3 Data Structure and Type Define ..................................................................... 31 7.2 TS Middleware ....................................................................................................... 33 7.3 Timer Middleware .................................................................................................. 33 7.4 UART Middleware .................................................................................................. 35 7.5 LED Middleware .................................................................................................... 35 7.6 BEEP Middleware .................................................................................................. 37 Application Program ...................................................................................................... 39 8.1 Overview ................................................................................................................ 39 8.1.1 Function List ................................................................................................... 39 8.1.2 Macro and Constant List ................................................................................ 39 8.1.3 Data Structure and Type Define ..................................................................... 40 8.2 Key Service Application ......................................................................................... 42 8.2.1 Sync Mode...................................................................................................... 45 8.2.2 Func Mode...................................................................................................... 46 8.2.3 Hold Mode ...................................................................................................... 47 8.2.4 Waterproof Mode ............................................................................................ 47 8.3 9 Overview ................................................................................................................ 24 6.1.1 7.1 8 System Self-checking ............................................................................................ 23 TS Register Value Application ............................................................................... 48 Interrupt Service Routine .............................................................................................. 49 9.1 Overview ................................................................................................................ 49 9.1.1 Function List ................................................................................................... 49 4 AN702-00029-1v0-E 9.1.2 Macro and Constant List ................................................................................ 49 9.1.3 Data Structure and Type Define ..................................................................... 49 9.2 TINT ISR ................................................................................................................ 50 9.3 GINT ISR ............................................................................................................... 50 9.4 TBT ISR ................................................................................................................. 50 9.5 UART ISR .............................................................................................................. 50 10 Additional Information ................................................................................................... 51 11 Appendix ....................................................................................................................... 52 11.1 List of Figures and Tables ...................................................................................... 52 5 AN702-00029-1v0-E Target products This application note is described about below products; Series Product Number (not included Package suffix) MB95870K MB95F876K MB95860K MB95F866K MB95850K MB95F856K 6 AN702-00029-1v0-E 1 Introduction 1.1 Purpose This application note helps users to acquire a quick understand of the structure of TSCMCU EVB sample project The sample project includes basic initial function of system clock, system interrupt, TS, LEDs, timer and UART. After initialization function is completed, the key service is served as a primary function for the implementation of the flow, that is to get the key value, change the scan display mode, execute relative key operation based on the current mode, and to execute some operations when mode toggle happens. 1.2 Definitions, Acronyms and Abbreviations TSC Capacitance Touch Sensor TSCMCU MCU with TSC inside AIC TM APIS FW Automatic Impedance Calibration TM Adjacent Pattern Interference Suppression Firmware F-Touch F-Touch for SOFTUNE 1.3 Document Overview The rest of document is organized as follows: Chapter 2 explains System Hardware Environment Chapter 3 explains Development Environment Chapter 4 explains Sample Project System Chapter 5 explains System Function Chapter 6 explains Module Drivers Chapter 7 explains Middleware Chapter 8 explains Application Program Chapter 9 explains Interrupt Service Routine 7 AN702-00029-1v0-E 2 System Hardware Environment This chapter introduces the Hardware Environment. 2.1 MCU Information Below shows the brief information list of MCU used in this EVB. CPU chip: Fujitsu MB95F876KPMC CPU max main oscillation clock: up to 16.25 MHz Minimum instruction execution time : 61.5 ns (machine clock frequency = 16.25 MHz) 2.2 Interrupt processing time : 0.6 us (machine clock frequency = 16.25 MHz) RAM space: 1K Bytes; Code space: 36K Bytes; EVB Information There are 12 channels touch key and relative indication LEDs, 2 custom LEDs, 1 beep and UART port. Figure 2-1: Appearance of EVB 8 AN702-00029-1v0-E 3 Development Environment This chapter introduces the Development Environment. Table 3-1: MCU Development Environment Name Description Part Number Manufacture Remarks SOFTUNE Workbench supports software for Softune V3 2 developing programs for the F MC-8L/8FX FFMC-8L Fujitsu family of microprocessors / microcontrollers. BMGA TSCMCU EVB F-Touch for Softune Emulator MB2164-07-E EVB MB2146-540-E Fujitsu Developing Touch Fujitsu Fujitsu 9 V1.2.0 AN702-00029-1v0-E 4 Sample Project System This chapter introduces the system composition structure of sample project. 4.1 System Introduction This sample project is designed to quickly evaluate the TS module build up on MB95F870 series MCU. There are 4 different operation modes which are controlled by TSC key and 1 external control jumper. The Beep and LEDs build in EVB also be used to indicate the key action and the selected mode status. Additionally, there are UART ports transferring the interested register value such as impedance, strength and calibrated impedance. All the system features are listed in section 4.2. 4.2 System Features All 12 channels of touch keys 12 LEDs Touch Status Display 2 user custom LEDs 1 Direct Beep output UART port External control jumper Power selectable between 12V and 5V, as well as power indication LED 10 AN702-00029-1v0-E 4.3 4.3.1 System Firmware Design User Interface Figure 4-1: Demo system User Interface Block Diagram 11 AN702-00029-1v0-E 4.3.2 System Module Figure 4-2: Demo system Module Block Diagram 12 AN702-00029-1v0-E 4.3.3 System Main Loop Start Disable global interrupt Initialize system Configure interrupt level Enable global interrupt System self-check System service loop Figure 4-3: Demo system Main Loop flowchart 4.3.4 System Files This section introduces all c files used in sample project. There are 3 required files: _f2mc8fx.c, vectors.c and startup.asm. These files apply all the system necessary information, so make sure they are included in project correctly. And the main.c, as a special file, is also required in all projects. This file includes some system functions such as system initial function, system self check function, as well as the main function. Additionally, there are 5 kinds of files which sorted by modules. TS module: TSC_Init.c contains Initialization information of TS module. TSC.c contains API functions of TS module (for example, TSC_GetValueUnit). Key service module: Key_ServiceBase.c provides a frame for external input response and mode toggle. Key_ServiceFuncMode.c implements all functions in function show mode. Key_ServiceHoldMode.c implements all functions in hold mode. Key_ServiceSyncMode.c implements all functions in synchrony mode. Key_ServiceWaterproofMode.c implements all functions in waterproof mode. 13 AN702-00029-1v0-E Timer module: Timer.c contains Initialization information and API functions of Timer module. UART module: Uart.c contains Initialization information and API functions of UART module. LED module: LED.c contains Initialization information and API functions of LED module. Beep module: BEEP.c contains Initialization information and API functions of Beep module. 14 AN702-00029-1v0-E 4.3.5 System Files Structure Figure 4-4: Sample Project Files Structure 15 AN702-00029-1v0-E 5 System Function This chapter introduces the details of system function. 5.1 Overview Figure 4-3 shows the flow chart of system main loop. After power is turned on, MCU starts system initialization firstly, this initialization includes setup of clock and interrupt, used module initialization, and then, MCU goes into main loop handling API functions. 5.1.1 Function List Table 5-1: System Function List Prototype Description Section/Page Remark SYS_OscSetup () Initialize system machine clock. 5.2.1/20 N/A SYS_ResetWatchdog () Reset watchdog (feed dog signal). 5.2.2/20 Not Use SYS_Init() Called all initialization functions 5.2.3/20 N/A TSC_Init() TS module initialization 5.3.1/21 N/A TBT_Init() Timer module initialization 5.3.2/21 N/A CTRL_Init() Control switch initialization 5.3.6/22 N/A LED_DirectOut(LED_Port, Set the LED control pins direct to 5.3.3/21 N/A LED_Pin) output LED_Init() LED module initialization 5.3.3/21 N/A BEEP_Init() Beep module initialization 5.3.4/22 N/A UART_Init() UART module initialization 5.3.5/22 N/A SYS_SelfCheck () Relative 0/23 N/A module power on self-checking 5.1.2 Macro and Constant List Table 5-2: System Function Macro List Name Description Value EXCLK_USED Determine to use external clock or not FALSE PLL_USED Determine to use PLL or not TRUE LED_PORT1NUM Number of pins used in port1 for key display 8 LEDs LED_PORT2NUM Number of pins used in port2 for key display 4 LEDs LED_NUM Total number of pins for key display LEDs 16 LED_PORT1NUM+ AN702-00029-1v0-E LED_PORT2NUM LEDKEY_PORT1 Key display LED pin port 1 0x0000(Port 0) LEDKEY_PORT2 Key display LED pin port 2 0x0012(Port 4) LEDKEY_RSPORT Run and Status display LED pin port 0x0012(Port 4) LEDKEY_1 Address of key display LED pin 1 0x01(P00) LEDKEY_2 Address of key display LED pin 2 0x02(P01) LEDKEY_3 Address of key display LED pin 3 0x04(P02) LEDKEY_4 Address of key display LED pin 4 0x08(P03) LEDKEY_5 Address of key display LED pin 5 0x10(P04) LEDKEY_6 Address of key display LED pin 6 0x20(P05) 17 AN702-00029-1v0-E Table 5-3: System Function Macro List (continued) Name Description Value LEDKEY_7 Address of key display LED pin 7 0x80(P07) LEDKEY_8 Address of key display LED pin 8 0x40(P06) LEDKEY_9 Address of key display LED pin 9 0x02(P41) LEDKEY_10 Address of key display LED pin 10 0x01(P40) LEDKEY_11 Address of key display LED pin 11 0x08(P43) LEDKEY_12 Address of key display LED pin 12 0x04(P42) LEDKEY_RUN Address of system run display LED pin 0x80(P47) LEDKEY_STA Address of system status display LED pin 0x40(P46) UART_Dir_IN Set RXD pin to input of UART DDR1_P13 = 0 UART_Dir_OUT Set TXD pin to output of UART DDR1_P14 = 1 CTRL_DIR Set direct of control switch jumper DDR4_P44 CTRL_PIN Pin value register of control switch jumper PDR4_P44 Table 5-4: System Function Constant List Name Description Value LED_Key [LED_NUM] Constant array contains key display LED pin {LEDKEY_1, address LEDKEY_2, … LEDKEY_11, LEDKEY_12} 18 AN702-00029-1v0-E 5.1.3 5.1.3.1 Data Structure and Type Definition Data Structure There is no data structure in this part. 5.1.3.2 Type Definition 1. MSG_RESULT, enumerate the return status of function execution. typedef enum { MSG_OK = 0, /* 0 */ MSG_FAIL /* 1 */ } MSG_RESULT; 2. LED_STATUS, enumerate the LED on or off status. typedef enum { LED_ON = 0, LED_OFF /* 0 */ /* 1 */ }LED_STATUS; 19 AN702-00029-1v0-E 5.2 System Initialization 5.2.1 Machine Clock Table 5-5: System Machine Clock Setup Function Prototype void SYS_OscSetup (void) Parameter void Return void Description Select between external clock or internal clock; Determine if use PLL or not Remark 5.2.2 N/A Watchdog Table 5-6: System Watchdog Reset Function Prototype void SYS_ResetWatchdog (void) Parameter void Return void Description Hardware watchdog reset signal, as known as feed dog signal Remark Not used in this sample project 5.2.3 System Initialization Table 5-7: System Initialization Function Prototype void SYS_Init (void) Parameter void Return void Description All initialized functions are called by this function for centralizing initialization. Remark N/A 20 AN702-00029-1v0-E 5.3 Module Initialization 5.3.1 TS Module Table 5-8: TS Module Initialization Function Prototype void TSC_Init (void) Parameter void Return void Description This is a key function of this sample project. It includes all register’s configuration of TS module. It is recommended to call this function in any project which used TS module, since this function can be exported by Touchtune in one special c file. Remark 5.3.2 N/A Timer Module Table 5-9: Timer Module Initialization Function Prototype void TBT_Init (void) Parameter void Return void Description System use hard ware Time Base Timer as a source of time impulse. The relative parameters such as timer interval, are configured in this function Remark 5.3.3 N/A LED Module Table 5-10: LED Pin Direct Setting Function Prototype void LED_DirectOut(LED_Port, LED_Pin) Parameter LED_Port: Indicate the corresponding port of LED pins LED_Pin: Indicate the LED pin Return void Description Set the given pin in parameter list to output for LED control. Remark N/A Table 5-11: LED Module Initialization Function Prototype void LED_Init (void) Parameter void Return void Description There are up to 14 LEDs in demo board and it is driven by multiple pins. This function configures all the LED pins to Low level output. Remark N/A 21 AN702-00029-1v0-E 5.3.4 Beep Module Table 5-12: Beep Module Initialization Function Prototype void BEEP_Init (void) Parameter void Return void Description There is a programmable frequency output for BEEP drive in TSCMCU. It is controlled by TS module, this function is used to configure it to software control mode for some special application conditions. Remark 5.3.5 N/A UART Module Table 5-13: UART Module Initialization Function Prototype void UART_Init (void) Parameter void Return void Description There are TTL RS-232 interface in TSCMCU-EVB, through the level conversion chip, register data can be sent out to PC by UART. This function is used to configure UART pin, UART parameters, Baud rate and Interrupt. Remark 5.3.6 N/A Control Switch Table 5-14: Control Switch Initialization Function Prototype void CTRL_Init (void) Parameter void Return void Description Actually, the control switch is a GPIO pin, so this function is used to configure this pin to GPIO input. Remark N/A 22 AN702-00029-1v0-E 5.4 System Self-checking Table 5-15: System Self-checking Function Prototype void SYS_SelfCheck (void) Parameter void Return void Description This is a system level application function. It designs to check the working status of board build up modules include LEDs and Beep. Remark N/A 23 AN702-00029-1v0-E 6 Module Drivers This chapter provides driver function of each module used in system. 6.1 Overview Driver functions of each module implement data get and sent from target peripherals. There are 5 kinds of module used in this sample project, including: TS, Timer, UART, LED, BEEP and Control Switch. TS as input module processes data automatically and report the touch action to CPU directly. Timer as internal module generates time pulse to drive 4 derived software timers. UART as bidirectional module not only sent out data to PC, but also get commands from PC for transmission type switch. LED, use GPIO actually, as output module controls if lighting is performed or not of LEDs. There are several functions to implement various display effects. BEEP as output module transmits PWM signal with certain frequency to drive of BEEP. The frequency and beep period are programmable. Control Switch as input GPIO controls the toggle between waterproof mode and other modes Note that Timer, UART and part of TS driver are implemented by interrupt service routine, please refer to 9 Interrupt Service Routine for details. 24 AN702-00029-1v0-E 6.1.1 Function List Table 6-1: Module Drivers List Prototype LED_Display(LED_Port, LED_Pin, Description Section/Page Remark LED display control 6.3/26 N/A Beep frequency modify and 0/27 N/A Dis_Ctrl) BEEP_Control(beep_frq) make beep sounded. 6.1.2 Macro and Constant List Relative macro and constant of LED modules are listed above in Table 5-2 and Table 5-3. 6.1.3 6.1.3.1 Data Structure and Type Define Data Structure There is no data structure in this part. 6.1.3.2 Type Define typedef enum { BEEP_FRQ1 = 0x11, BEEP_FRQ2 = 0x12, BEEP_FRQ3 = 0x13, BEEP_FRQ4 = 0x14, BEEP_FRQ5 = 0x15, BEEP_FRQ6 = 0x16, BEEP_FRQ7 = 0x17, BEEP_OFF = 0x00 }BEEP_FRQ; BEEP_FRQ enumerates several beep status which is relative of frequency. Note that these frequencies are based on machine clock. 25 AN702-00029-1v0-E 6.2 TS Module Driver The touch action is reported to these 2 registers: TOUCHL and TOUCHH. Below is the relationship between register bits and touch channels. Table 6-2: Relationship between Touch Byte and Touch Channels Touch Byte TOUCHH 7 Touch Channels 6 5 4 Undefined bits TOUCHL 3 1 1 0 7 6 5 4 3 2 1 0 TS TS TS TS TS TS TS TS TS TS TS TS 11 10 09 08 07 06 05 04 03 02 01 00 These 2 registers are read only, and store the final touch status: Reading "0" Indicates that the touch pad of touch ch. n is not touched. Reading "1" Indicates that the touch pad of touch ch. n is touched. This sample project uses the reversed value of touch bytes as below by considering the consistency with other keys. touchByteL &= ~TOUCHL; touchByteH &= ~TOUCHH; This is the scan method of getting touch status. 6.3 LED Module Driver Table 6-3: LED Module Driver Function Prototype void LED_Display(LED_Port, LED_Pin, Dis_Ctrl) Parameter LED_Port: Indicate the corresponding port of LED pins LED_Pin: Indicate the LED pin Dis_Ctrl: LED status control LED_On: light LED, set GPIO pin to L output LED_Off: turn off LED, set GPIO pin to H output Return void Description The parameter LED_Port and LED_Pin contain the address of GPIO port and pin. The LED control implement by set H or L of GPIO output. Remark N/A 26 AN702-00029-1v0-E 6.4 BEEP Module Driver Table 6-4: BEEP Module Driver Function Prototype void BEEP_Control (beep_frq) Parameter beep_frq: Beep sound effect set frequency Return void Description There is hardware beep module, which transmits a certain frequency pulse. The beep module can be controlled by both software and TS module directly. This function is designed to use the software control. This frequency determines the sound effect based on MCLK. Remark N/A 27 AN702-00029-1v0-E 6.5 Control Switch Driver In jumper disconnect condition, the Control Switch relative GPIO pin value hold 1. After shorted by jumper, the pin value changes to 0. However, in this sample project, the short status is defined as default status. This sample project uses the reversed value of touch bytes as below by considering the consistency with other keys. keyValue = ((~CTRL_PIN) << 15) | ((touchByteH << 8) & 0x7F00) | touchByteL; 28 AN702-00029-1v0-E 7 Middleware This chapter provides middle ware functions of some modules used in system. 7.1 Overview Middleware implements several functions based on module driver. It provides buffer function between API and driver layer. A module always has many middleware. For instance, there are 7 functions provided for LED module. This chapter introduces all the modules’ relative middleware. 29 AN702-00029-1v0-E 7.1.1 Function List Table 7-1: Module Drivers List Prototype Description Section/Page Remark TSC_MatrixClear() Touch data save matrix reset function N/A TIMER_Max65535ms Derived software timer N/A (*timer, timeOutVal) Max value:65535; Unit: ms TIMER_Max255ms Derived software timer (*timer, timeOutVal) Max value:255; Unit: ms TIMER_Max65535s Derived software timer (*timer, timeOutVal) Max value:65535; Unit: s TIMER_Max255s Derived software timer (*timer, timeOutVal) Max value: 255; Unit: s UART_Transmit() Transmit touch data via UART N/A LED_KeyDisplay Key status indication LED control N/A LED_KeyRun(Dis_Ctrl) Run status indication LED control N/A LED_KeyStatus(Dis_Ctrl) System status indication LED control N/A LED_KeyAll(Dis_Ctrl) Light or turn off all LED N/A LED_LoopDispMode1(Dis_Loacl) Multiple LED display mode 1 N/A LED_LoopDispMode2(Dis_Loacl) Multiple LED display mode 2 N/A LED_LoopDispMode3(Dis_Loacl) Multiple LED display mode 3 N/A BEEP_SoundEft1(Beep_Eft) Multiple Beep sound effect mode 1 N/A BEEP_SoundEft1(Beep_Eft) Multiple Beep sound effect mode 2 N/A BEEP_SoundEft1(Beep_Eft) Multiple Beep sound effect mode 3 N/A BEEP_SoundEft1(Beep_Eft) Multiple Beep sound effect mode 4 N/A BEEP_SoundEftDouble Multiple Beep sound double effect N/A N/A N/A N/A (Led_Num, Dis_Ctrl) (Beep_Eft1, Beep_Eft2) combinational mode 30 AN702-00029-1v0-E 7.1.2 Macro and Constant List Table 7-2: Middleware Macro List Name Description Value TSCKEY_KEYNUM Number of touch keys 12 TSCKEY_MATRIX_COLLEN Length of data matrix column (TSCKEY_KEYNUM + 2) TSCKEY_MATRIX_RAWLEN Length of data raw 40 RESET_TIMER Timer out value is 0 means reset derived 0x00 timer VAL_1S 7.1.3 7.1.3.1 Define 1 second in software timer 1000 Data Structure and Type Define Data Structure There is no data structure in this part. 7.1.3.2 Type Definition 1. TSCKEY_MATRIX, contains 1 data matrix, get and put pointer of column and raw, and 1 bit field for indicating matrix empty status. typedef struct { /* data RX FIFO buffer */ unsigned char Matrix[TSCKEY_MATRIX_RAWLEN][TSCKEY_MATRIX_COLLEN]; unsigned char PutPtrCol; /* pointer for Col Matrix in */ unsigned char PutPtrRaw; /* pointer for Raw Matrix in */ unsigned char GetPtrCol; /* pointer for Col Matrix out */ unsigned char GetPtrRaw; /* pointer for Raw Matrix out */ unsigned FifoEmpty: 1; /* busy flag for data transmission */ }TSCKEY_MATRIX; 31 AN702-00029-1v0-E 2. TSCKEY_GETTYEP, enumerates supported data getting types. typedef enum { GET_IMP = 0, /* 0 */ GET_CALIMP, /* 1 */ GET_STR /* 2 */ }TSCKEY_GETTYEP; 3. TIMER_STA, enumerates the status of derived timer. typedef enum { TIME_OUT_FLAG = 0xFF, NO_TIME_OUT_FLAG = 0x00, } TIMER_STA; 4. LED_LOOPMODE, enumerates supported LED effect mode in this sample project. typedef enum { NULL = 0, MODE1, MODE2, MODE3 }LED_LOOPMODE; 32 AN702-00029-1v0-E 7.2 TS Middleware Table 7-3: TS Module Middleware Function Prototype MSG_RESULT TSC_MatrixClear(void) Parameter void Return MSG_OK: Clear TSC data matrix successful Description Reset matrix by fill 0, set the pointer and flag to 0. Remark N/A 7.3 Timer Middleware Table 7-4: Derived 65535 ms Timer Function Prototype TIMER_STA TIMER_Max65535ms(unsigned int *timer, unsigned int timeOutVal) Parameter timer: pointer of timer counter timeOutVal: timeout value, when timeout value is 0, reset timer Return TIME_OUT_FLAG: indicate the timer counter met time out value NO_TIME_OUT_FLAG: indicate the timer counter didn’t meet time out value Description Count step is 1 ms, and max counter value is 65535 ms. Note that this ms here is not accurate. Remark N/A Table 7-5: Derived 255 ms Timer Function Prototype TIMER_STA TIMER_Max255ms(unsigned char * timer, unsigned char timeOutVal) Parameter timer: pointer of timer counter timeOutVal: timeout value, when timeout value is 0, reset timer Return TIME_OUT_FLAG: indicate the timer counter met time out value NO_TIME_OUT_FLAG: indicate the timer counter didn’t meet time out value Description Count step is 1 ms, and max counter value is 255 ms. Note that this ms here is not accurate. Remark N/A 33 AN702-00029-1v0-E Table 7-6: Derived 65535 s Timer Function Prototype TIMER_STA TIMER_Max65535s(unsigned int *timer, unsigned int timeOutVal) Parameter timer: pointer of timer counter timeOutVal: timeout value, when timeout value is 0, reset timer Return TIME_OUT_FLAG: indicate the timer counter met time out value NO_TIME_OUT_FLAG: indicate the timer counter didn’t meet time out value Description Count step is 1 s, and max counter value is 65535 ms. Note that this ms here is not accurate. Remark N/A Table 7-7: Derived 255 s Timer Function Prototype TIMER_STA TIMER_Max255s(unsigned char * timer, unsigned char timeOutVal) Parameter timer: pointer of timer counter timeOutVal: timeout value, when timeout value is 0, reset timer Return TIME_OUT_FLAG: indicate the timer counter met time out value NO_TIME_OUT_FLAG: indicate the timer counter didn’t meet time out value Description Count step is 1 s, and max counter value is 255 ms. Note that this ms here is not accurate. Remark N/A 34 AN702-00029-1v0-E 7.4 UART Middleware Table 7-8: UART Middleware Function Prototype void UART_Transmit(void) Parameter void Return void Description Compare get pointer with put pointer. If get pointer is not equal to put pointer, transmit the data via UART. Remark 7.5 N/A LED Middleware Table 7-9: Key Indication LED Control Middleware Function Prototype void LED_KeyDisplay(unsigned char Led_Num, LED_STATUS Dis_Ctrl) Parameter Led_Num: Point out which LED to operate Dis_Ctrl: Point out light or not LED Return void Description Use light on/off of 12 LEDs to indicate the key status Remark N/A Table 7-10: Run Status Indication LED Control Middleware Function Prototype void LED_KeyRun(LED_STATUS Dis_Ctrl) Parameter Dis_Ctrl: Point out light or not LED Return void Description Use light on/off of RUN LED to indicate the operation status Remark N/A Table 7-11: System Status Indication LED Control Middleware Function Prototype void LED_KeyStatus(LED_STATUS Dis_Ctrl) Parameter Dis_Ctrl: Point out light or not LED Return void Description Use light on/off of STA LED to indicate the system status Remark N/A Table 7-12: Entire LEDs Control Middleware Function Prototype void LED_KeyAll(LED_STATUS Dis_Ctrl) Parameter Dis_Ctrl: Point out light or not LED Return void Description Overall control of 12 LEDs operation status. It is used during self-check mode and mode switching. Remark N/A 35 AN702-00029-1v0-E Table 7-13: LED Loop Display Mode 1 Function Prototype void LED_LoopDispMode1(unsigned char Dis_Loacl) Parameter Dis_Loacl: Location of LED operation in a display loop. Return void Description Implement the display effect: 3 adjacent LEDs are lighted from 12 LEDs pointed by argument Dis_Loacl; Dis_Loacl increasing makes the lighted LEDs set roll CW direct, while Dis_Loacl decreasing makes the lighted LEDs set roll CCW direct. Remark N/A Table 7-14: LED Loop Display Mode 2 Function Prototype void LED_LoopDispMode2(unsigned char Dis_Loacl) Parameter Dis_Loacl: Location of LED operation in a display loop. Return void Description Implement the display effect: 1 LED is lighted from 12 LEDs pointed by argument Dis_Loacl; Dis_Loacl increasing makes the lighted LED jump display. Remark N/A Table 7-15: LED Loop Display Mode 3 Function Prototype void LED_LoopDispMode3(unsigned char Dis_Loacl) Parameter Dis_Loacl: Location of LED operation in a display loop. Return void Description Implement the display effect: 2 LEDs are lighted each time pointed by argument Dis_Loacl; Dis_Loacl increasing makes all LED lighted and then turn off in reverse order. Remark N/A 36 AN702-00029-1v0-E 7.6 BEEP Middleware Table 7-16: Beep Sound Effect Mode 1 Function Prototype void BEEP_SoundEft1(unsigned char Beep_Eft) Parameter Beep_Eft: Beep sound effect control Return void Description List 6 kinds of support Beep sound effect, and can be controlled by argument Beep_Eft. Remark N/A Table 7-17: Beep Sound Effect Mode 2 Function Prototype void BEEP_SoundEft2(unsigned char Beep_Eft) Parameter Beep_Eft: Beep sound effect control Return void Description Support 2 kinds of Beep sound effect by argument Beep_Eft mod 2. Remark N/A Table 7-18: Beep Sound Effect Mode 3 Function Prototype void BEEP_SoundEft3(unsigned char Beep_Eft) Parameter Beep_Eft: Beep sound effect control Return void Description Support 3 kinds of Beep sound effect by argument Beep_Eft mod 3. Remark N/A Table 7-19: Beep Sound Effect Mode 4 Function Prototype void BEEP_SoundEft4(unsigned char Beep_Eft) Parameter Beep_Eft: Beep sound effect control Return void Description Support 4 kinds of Beep sound effect by argument Beep_Eft mod 4. Remark N/A 37 AN702-00029-1v0-E Table 7-20: Beep Sound Combinational Mode Function Prototype void BEEP_SoundEftDouble(unsigned char Beep_Eft1,unsigned char Beep_Eft2) Parameter Beep_Eft1: Beep sound effect 1 control Beep_Eft2: Beep sound effect 2 control Return void Description This beep is configured by 2 different sounds. The first sound effect is Beep_Eft1, and the second sound effect Beep_Eft2 is sent out after a certain period of time. This function is required to use BEEP_SoundEft4. Remark N/A 38 AN702-00029-1v0-E 8 Application Program This chapter introduces the implementation details of application program. 8.1 Overview Application program implements the design requirement by integration system resources. There are 2 categories of application program in this sample project: touch key service application and TS module register value read and send out application. For touch key service part, provide 4 kinds of demonstrate modes named as sync mode, function mode, hold mode and waterproof mode. Section 8.2 describes the details of this part. For TS register value part, there is a 14 × 40 data matrix act as data buffer. This buffer is FIFO structure. Section 8.3 introduces this matrix. 8.1.1 Function List Table 8-1: Application Program Function List Prototype Description Section/Page Remark TSC_ServiceBase(); Key service base function 8.2/42 N/A TSC_ModeLoad(*pForm); Load new mode 8.2/42 N/A TSC_ModeDispRefurbish(); LED display refurbish 8.2/42 N/A TSC_ClearTask(); Extra task reset function 8.2/42 N/A TSC_AddTask(void(*pSub)()); Extra task add function 8.2/42 N/A TSC_DelTask(void(*pSub)()); Extra task delete function 8.2/42 N/A TSC_GetValueUnit(get_type); Get 8.3/48 N/A TS module register value function Note: The sub functions of each mode not list in this table, and Section 8.2 explain the implement details. 8.1.2 Macro and Constant List Table 8-2: Middleware Macro List Name Description Value Setting_ModeCount Number of touch keys 4 TASKCOUNT Length of data matrix column 1 39 AN702-00029-1v0-E 8.1.3 8.1.3.1 Data Structure and Type Define Data Structure 1. FTouchMode contains common attributes of each mode. TimeCounter, pointer of timer used in this mode; TimeInterval, define the timer out interval; pInit, function pointer of initialization function of this mode; pDraw, function pointer of display redraw function of this mode; pKeyDown, function pointer of key press service function of this mode; pKeyUp, function pointer of key release service function of this mode; pTimer, function pointer of time driven processing function of this mode; pUnload, function pointer of mode unload processing function of this mode. struct FTouchMode { unsigned int *TimeCounter; unsigned int TimeInterval; void(*pInit)(); void(*pDraw)(); void(*pKeyDown)(unsigned int); void(*pKeyUp)(unsigned int); void(*pTimer)(); void(*pUnload)(); }; 40 AN702-00029-1v0-E 2. FTouchTask contains common attributes of extra task. Status, indicate the status of this task; pTask_Sub, function pointer of extra task sub. struct FTouchTask { TASK_STA Status; void(*pTask_Sub)(); }; 3. ModeIndex, enumerate mode index of supported modes. enum ModeIndex{ touchSyncMode_ModeIndex = 0, touchFuncMode_ModeIndex, touchHoldMode_ModeIndex, touchWtrprfMode_ModeIndex }; 8.1.3.2 Type Definition TASK_STA, enumerate extra task running status. typedef enum { TASKSTA_NONE = 0, /* 0 */ TASKSTA_RUN, /* 1 */ } TASK_STA; 41 AN702-00029-1v0-E 8.2 Key Service Application In key service application, it provides a sub system for mode toggle. The condition of mode toggle is to touch no less than 6 keys and hold at least 2 seconds. There are 2 concepts: active mode and load mode. Active mode means the current mode while load mode means the oncoming mode. In normal conditions, active mode and load mode are equivalent. However, when the mode is switched, load mode becomes the oncoming mode, which makes it not equivalent to active mode anymore. When the next program executes within the circle, the function switches the mode automatically once the above-mentioned difference is captured. There are 2 concepts in key service part too, which are the current key value and the previous key value. In normal condition, these 2 values are equivalent. However, when touch is occurred or released, the current key value changes. In this case, the function switches to key service automatically in next program execution within the circle. There are 2 derived timers used: local timer of each mode and common timer for refurbish. Key service base function flow chart has shown as below: Start Is mode changed? Y Mode change routine N Is key status changed? Y Key service N Is local timer matched? Y N Local timer routine Is refurbish timer matched? Y Refurbish timer routine N End Figure 8-1: Key Service Base Function Flowchart 42 AN702-00029-1v0-E The descriptions of key service functions have shown as below: Table 8-3: Key Service Base Function Prototype void TSC_ServiceBase(void) Parameter void Return void Description Monitor and capture status change of mode, key and timer; Execution of relative routine functions. Remark N/A Table 8-4: Mode Load Function Prototype void TSC_ModeLoad(struct FTouchMode *pForm) Parameter *pForm: Point out oncoming mode Return void Description Fix variable loadMode to oncoming mode Remark N/A Table 8-5: Mode Display Refurbish Function Prototype void TSC_ModeDispRefurbish(void) Parameter void Return void Description Execute display redraw function of active mode. Remark N/A Table 8-6: Extra Task Clear Function Prototype void TSC_ClearTask(void) Parameter void Return void Description Reset status of extra task. Remark N/A Table 8-7: Extra Task Addition Function Prototype unsigned char TSC_AddTask(void(*pSub)()) Parameter void(*pSub)(): point to extra task function pointer Return void Description Add one extra task into task list. Remark N/A 43 AN702-00029-1v0-E Table 8-8: Entire LEDs Control Middleware Function Prototype void TSC_DelTask(void(*pSub)()) Parameter void(*pSub)(): point to extra task function pointer Return void Description Delete pointed function from task list. Remark N/A The following text explains 4 operation modes. 44 AN702-00029-1v0-E 8.2.1 Sync Mode Sync Mode supports multi point touch. The LED status (light or not) follows the key touch action, and beep is directly driven by TS module. The below diagram shows the change of LED status: Turn Off No Touch Turn Off Lighted Touched No Touch Figure 8-2: Sync Mode LED Status Change Diagram 45 AN702-00029-1v0-E 8.2.2 Func Mode In Func Mode, 12 touch keys are categorized to 6 sets by columns. 3 LED demonstrate modes are defined. The below diagram shows the change of LED status: Figure 8-3: Func Mode LED Status Change Diagram 46 AN702-00029-1v0-E 8.2.3 Hold Mode In Hold Mode, beep sound is combined with 2 effects and controlled by software. For LED, it holds light status until the same key is touched again within a short period of time, or if there is no touch action of other keys within 3 seconds. Turn Off Lighted No Touch Lighted Touched No Touch Figure 8-4: Hold Mode LED Status Change Diagram 8.2.4 Waterproof Mode It demonstrates the function of waterproof performance, for details of waterproof design guide, please refer to MCU-AN-500141-E: TSCMCU-Waterproof_Guideline for more information. In waterproof mode, the APISTM mode 1 is used, that means it supports single-point touch. The touch effect is partially similar with sync mode. It beeps when the touch is detected and LED keeps turning ON until the touch key is released. 47 AN702-00029-1v0-E 8.3 TS Register Value Application Environment change is reflected in TS module register data. By getting these data, it enhances the digital signal processing. The relative data includes: Impedance, Cal_Impedance and Strength. Argument of TSC_GetValueUnit function points out the data type. A 14 × 40 data matrix is built up for data buffer. Below is the structure: Table 8-9: Structure of Data Matrix Col9 Col10 Col11 (CH.9) (CH.10) (CH.11) Data … Data Data Data 0xAA 0x55 Raw1 Data Data Data … Data Data Data 0xAA 0x55 Raw2 Data Data Data … Data Data Data 0xAA 0x55 … Data … Data … Raw0 End Flag … (CH.2) … (CH.1) … (CH.0) … … Col2 … Col1 … Col0 Raw37 Data Data Data … Data Data Data 0xAA 0x55 Raw38 Data Data Data … Data Data Data 0xAA 0x55 Raw39 Data Data Data … Data Data Data 0xAA 0x55 The description of TSC_GetValueUnit has shown as below: Table 8-10: TS Module Get Register Value Function Prototype void TSC_GetValueUnit(TSCKEY_GETTYEP get_type) Parameter get_type: point out get value type: GET_IMP - Get Impedance value GET_CALIMP - Get Cal_Impedance value GET_STR – Get Strength value Return void Description Get the register value according to argument and save to data matrix. Remark N/A 48 AN702-00029-1v0-E 9 Interrupt Service Routine This chapter introduces the ISR used in system. 9.1 Overview Interrupt Service Routine (ISR) enhances the ability and efficiency of real-time reponse ability. For the use of interrupt, there are 3 parts in Vectors.c file which require modification: 1. Modify interrupt level in InitIrqLevels() function; 2. Declare ISR prototypes; 3. Modify Vector definition TS module has TINT (Touch Interrupt) and GINT (General Interrupt). 9.1.1 Function List Table 9-1: Interrupt Service Routine List Prototype Description TINT_ISR(void) Touch interrupt Service Routine Not Use GINT_ISR(void) General interrupt Service Routine Not Use void TBT_ISR (void) Time base timer interrupt Service Routine N/A void UART_ISR (void) UART interrupt Service Routine N/A 9.1.2 Section/Page Macro and Constant List Relative macro and constant are introduced previously. 9.1.3 9.1.3.1 Data Structure and Type Define Data Structure There is no data structure in this part. 9.1.3.2 Type Definition 5. UART_CMD, enumerate UART command of PC side. typedef enum { CMD_GETIMP = 0x2F, CMD_GETCALIMP = 0x5F, CMD_GETSTR = 0x6F }UART_CMD; 49 Remark AN702-00029-1v0-E 9.2 TINT ISR Table 9-2: Touch Interrupt Service Routine Prototype __interrupt void TINT_ISR(void) Parameter void Return void Description Service function when touch interrupt occurs. Remark Not used in this sample project 9.3 GINT ISR Table 9-3: General Interrupt Service Routine Prototype __interrupt void GINT_ISR(void) Parameter void Return void Description Service function when general interrupt occurs. Remark Not used in this sample project 9.4 TBT ISR Table 9-4: Time Base Timer Interrupt Service Routine Prototype __interrupt void TBT_ISR (void) Parameter void Return void Description Accumulate counter and judgment conditions for derived timers Remark N/A 9.5 UART ISR Table 9-5: UART Interrupt Service Routine Prototype __interrupt void UART_ISR (void) Parameter void Return void Description Get command from PC by UART to modify sent out data type. Remark N/A 50 AN702-00029-1v0-E 10 Additional Information For more Information on FUJITSU semiconductor products, visit the following websites: http://www.fujitsu.com/global/services/microelectronics/documents/ 51 AN702-00029-1v0-E 11 Appendix 11.1 List of Figures and Tables Table 3-1: MCU Development Environment ....................................................................................................9 Table 5-1: System Function List ......................................................................................................................16 Table 5-2: System Function Macro List...........................................................................................................16 Table 5-3: System Function Macro List (continued) .......................................................................................18 Table 5-4: System Function Constant List.......................................................................................................18 Table 5-5: System Machine Clock Setup Function .........................................................................................20 Table 5-6: System Watchdog Reset Function .................................................................................................20 Table 5-7: System Initialization Function .......................................................................................................20 Table 5-8: TS Module Initialization Function ..................................................................................................21 Table 5-9: Timer Module Initialization Function ............................................................................................21 Table 5-10: LED Pin Direct Setting Function ...................................................................................................21 Table 5-11: LED Module Initialization Function .............................................................................................21 Table 5-12: Beep Module Initialization Function ...........................................................................................22 Table 5-13: UART Module Initialization Function ...........................................................................................22 Table 5-14: Control Switch Initialization Function .........................................................................................22 Table 5-15: System Self-checking Function ....................................................................................................23 Table 6-1: Module Drivers List........................................................................................................................25 Table 6-2: Relationship between Touch Byte and Touch Channels ................................................................26 Table 6-3: LED Module Driver Function .........................................................................................................26 Table 6-4: BEEP Module Driver Function .......................................................................................................27 Table 7-1: Module Drivers List........................................................................................................................30 Table 7-2: Middleware Macro List..................................................................................................................31 Table 7-3: TS Module Middleware Function ..................................................................................................33 Table 7-4: Derived 65535 ms Timer Function ................................................................................................33 Table 7-5: Derived 255 ms Timer Function ....................................................................................................33 Table 7-6: Derived 65535 s Timer Function ...................................................................................................34 Table 7-7: Derived 255 s Timer Function .......................................................................................................34 Table 7-8: UART Middleware Function...........................................................................................................35 Table 7-9: Key Indication LED Control Middleware Function .........................................................................35 Table 7-10: Run Status Indication LED Control Middleware Function ...........................................................35 Table 7-11: System Status Indication LED Control Middleware Function ......................................................35 Table 7-12: Entire LEDs Control Middleware Function ..................................................................................35 Table 7-13: LED Loop Display Mode 1 Function .............................................................................................36 52 AN702-00029-1v0-E Table 7-14: LED Loop Display Mode 2 Function .............................................................................................36 Table 7-15: LED Loop Display Mode 3 Function .............................................................................................36 Table 7-16: Beep Sound Effect Mode 1 Function ...........................................................................................37 Table 7-17: Beep Sound Effect Mode 2 Function ...........................................................................................37 Table 7-18: Beep Sound Effect Mode 3 Function ...........................................................................................37 Table 7-19: Beep Sound Effect Mode 4 Function ...........................................................................................37 Table 7-20: Beep Sound Combinational Mode Function ...............................................................................38 Table 8-1: Application Program Function List ................................................................................................39 Table 8-2: Middleware Macro List..................................................................................................................39 Table 8-3: Key Service Base Function .............................................................................................................43 Table 8-4: Mode Load Function .....................................................................................................................43 Table 8-5: Mode Display Refurbish Function .................................................................................................43 Table 8-6: Extra Task Clear Function...............................................................................................................43 Table 8-7: Extra Task Addition Function .........................................................................................................43 Table 8-8: Entire LEDs Control Middleware Function ....................................................................................44 Table 8-9: Structure of Data Matrix ...............................................................................................................48 Table 8-10: TS Module Get Register Value Function ......................................................................................48 Table 9-1: Interrupt Service Routine List ........................................................................................................49 Table 9-2: Touch Interrupt Service Routine ....................................................................................................50 Table 9-3: General Interrupt Service Routine.................................................................................................50 Table 9-4: Time Base Timer Interrupt Service Routine ..................................................................................50 Table 9-5: UART Interrupt Service Routine ....................................................................................................50 Figure 2-1: Appearance of EVB ........................................................................................................................8 Figure 4-1: Demo system User Interface Block Diagram................................................................................11 Figure 4-2: Demo system Module Block Diagram ..........................................................................................12 Figure 4-3: Demo system Main Loop flowchart .............................................................................................13 Figure 4-4: Sample Project Files Structure.....................................................................................................15 Figure 8-1: Key Service Base Function Flowchart ..........................................................................................42 Figure 8-2: Sync Mode LED Status Change Diagram ......................................................................................45 Figure 8-3: Func Mode LED Status Change Diagram ......................................................................................46 Figure 8-4: Hold Mode LED Status Change Diagram ......................................................................................47 53