Typing Tutor
Total Page:16
File Type:pdf, Size:1020Kb
Typing Tutor Design Documentation Courtney Adams Jonathan Corretjer December 16, 2016 USU 3710 Contents 1 Introduction 2 2 Scope 2 3 Design Overview 2 3.1 Requirements . .2 3.2 Dependencies . .2 3.3 Theory of Operation . .3 4 Design Details 5 4.1 Hardware Design . .5 4.2 Software Design . .5 4.2.1 LCD Keyboard Display . .5 4.2.2 Key Stroke Input . .7 4.2.3 Menu Layout . .8 4.2.4 Level and Test Design . .9 4.2.5 Correctness Logic . 11 4.2.6 Buzzer Implementation . 11 4.2.7 Calculations . 12 5 Testing 12 5.0.1 SSI Output to LCD . 12 5.0.2 Keyboard Data Input . 13 5.0.3 Buzzer Frequency . 14 5.0.4 Buzzer Length . 15 5.0.5 Trial Testing . 15 5.0.6 Calculations . 16 6 Conclusion 16 7 Appendix 18 7.1 Code.................................................. 18 7.1.1 LCD.h . 19 7.1.2 LCD.c . 20 7.1.3 main.c . 22 7.1.4 TypingLib.h . 24 7.1.5 TypingMenu.h . 27 7.1.6 TypingMenu.c . 28 7.1.7 Keys.h . 31 1 7.1.8 Keys.c . 32 7.1.9 Speaker.h . 37 7.1.10 Speaker.c . 38 2 1 Introduction The goal of the Typing Tutor is to enable users to practice and develop their typing skills using an interactive interface that encourages improvement. Composed of various levels, the Typing Tutor provides a challenging medium for both beginners and experienced, alike. At any time during the tutoring process, users can take a typing test to measure their progress in speed and accuracy. The Typing Tutor is implemented on the Tiva TM C series TM4C123GH6PM Microcontroller and includes the ability to monitor key stroke inputs from a PS/2 keyboard and display the correct key input on an LCD screen as an additional aid to users. The Typing Tutor also includes a buzzer that indicates when an incorrect key has been inputted by the user. 2 Scope This document describes the hardware and software design of the Typing Tutor project. It includes the requirements, dependencies, design, implementation, and testing of the project. The complete code is located in the Appendix at the end. 3 Design Overview 3.1 Requirements The following is a list of requirements for the Typing Tutor: 1. Monitor key stroke input 2. Verify correctness of input 3. Display a small keyboard to an LCD screen that highlights the next key 4. Implement a feedback buzzer to indicate incorrect input 5. Transmit a menu interface to a terminal emulator for the user to interact with 6. Provide levels of varying difficulty that target specific sets of keys 7. Generate a random variety of words and phrases in each level to properly test the user's reaction speed 8. Calculate the user's accuracy after every level 9. Provide a typing test that calculates the typing speed and accuracy of the user 3.2 Dependencies The following is a list of hardware dependencies for the Typing Tutor: • A 5 volt DC power supply • A 3.3 volt DC power supply • 16 MHz crystal oscillator • ER-TFTM032 LCD Touchscreen • MCP4724 DAC • Analog Test Board (Speaker) • PS/2 keyboard 3 3.3 Theory of Operation At startup, the menu interface will be transmitted to the terminal emulator and a blank keyboard will display on the LCD screen. The user will be able to navigate the menu screen using the arrow keys and select the level they want to begin. There will be 6 total levels, with each level targeting a specific set of keys, and a typing speed test that measures the user's words per minute (WPM) rate. Figure 1 shows a software diagram of the program levels and what each level will consist of. Refer to Figures 2 and 3 for the initial designs of the menu screen and LCD keyboard layout. Figure 1: Software Diagram of Program Figure 2: Design of Menu Screen 4 Figure 3: LCD Keyboard Layout A level will begin by prompting the user to practice typing single letters of the target key-set. Then, it will generate words that consist of mostly the target key-set for the user to type out. Finally, it will concatenate a random sample of those words to form sentences for the user to type. After the user finishes the level, the terminal will display the user's accuracy based on the number of errors he or she made throughout the level. Figure 4 is the design of the terminal interface for a example level. Figure 4: Design of Example Level The typing test will randomly choose one of three possible paragraph-length passages and display it for the user to type. Once finished, the program will calculate the words per minute (WPM) rate of the user as well as display his or her accuracy. At the completion of a level or test, the interface will return to the starting menu, but the accuracy and WPM rate of the finished level/test will remain displayed to the user until he or she begins another level/test. During the course of a level or test, the keyboard inputs of the user will be monitored by the software to verify correctness. The small keyboard displayed on the LCD keyboard will highlight the level's target keys grey and the next key green as an additional aid to the user. If the user types the wrong key, the buzzer will generate a brief audio tone to indicate error to the user. Additionally, the incorrect key that the user pressed will be highlighted red on the LCD keyboard. Figure 5: Example Keyboard Layout 5 4 Design Details 4.1 Hardware Design Each required component of the project is connected to pins on the TM4C123GH6PM microcontroller as shown in Table 1, and the peripherals used for the design of this project are shown in Table 2. Table 1: Pins µC pin Function A2 SSI0 CLK A3 SSI0 FFS A4 SSI0 RX A5 SSI0 TX B0 LCD instruction control B2 I2C0 SCL B3 I2C0 SDA D0 PS/2 CLK D1 PS/2 Data Table 2: Peripherals Peripheral Use UART0 Transmit to terminal emulator SSI0 Transmit to LCD I2C0 Transmit to DAC Systick Random generator 16/32-bit Timer0 Buzzer length 16/32-bit Timer1 Buzzer frequency 16/32-bit Timer2 Test timer Figure 6 shows a hardware schematic of how the components connect together and to the microcontroller. 4.2 Software Design The software aspect of the design is accomplished in a series of steps centered around these six re- quirements of the project: displaying the LCD keyboard, displaying the menu, monitoring keyboard input, verifying correctness of the input, implementing the buzzer, and calculating typing speed and accuracy. The details of the steps taken to meet these requirements will be discussed in detail in this section. Initialization and configuration of the necessary peripherals will also be discussed. 4.2.1 LCD Keyboard Display SSI Configuration SSI0 is used as the peripheral to communicate with the ER-TFTM032 LCD screen. The TM4C123GH6PM microcontroller is configured as the master device, and SSI as the slave. The SSI clock source is set as the 16 MHz System clock and the SSI is configured with a Freescale SPI frame format and 8-bit data. Drawing the Keyboard: The method used to draw the keyboard is as follows: 6 Figure 6: Hardware Schematic 1. Color the entire screen black 2. Store the coordinates of every key into four parallel arrays (left, right, top, and bottom bounds) 3. At startup, draw a white box at the location of every key's coordinates 4. Whenever a key needs to update its color, find the key's index in the parallel arrays to obtain its coordinates and re-draw the box with the new color Dimensions: The coordinates for each of the keys are calculated by measuring the dimensions of the keyboard on the LCD screen, which are determined by the following method: Given that the LCD screen has dimensions of 320x240 pixels, and that there should be a 10 pixel buffer on each side of the keyboard, that gives the keyboard a length of 300 pixels. The top row of of the keyboard has 14 keys, with the backspace key twice as long as the rest, which results in 15 total equal-spaced boxes needed for the top row. This means that each box is 300=5 = 20 pixels long. Assuming the boxes are square, and that there are 5 rows of keys, this means that the keyboard has a width of 20 · 5 = 100 pixels. So the dimensions of the keyboard are 300x100 pixels. Assuming that the top-right corner of the LCD is the point of origin on the LCD coordinate system, the corner coordinates of the keyboard are calculated accordingly. Figure 7 is a visual of how the keyboard dimensions map to the LCD coordinate system. To draw the individual boxes, the coordinates for the left, right, top, and bottom sides of each key are recorded in four respective parallel arrays stored in the TypingLib.h header file. Figure 8 is a photo taken of the resulting keyboard printed to the LCD screen. 7 Figure 7: Dimensions of Keyboard Figure 8: Drawing of Keyboard on LCD Screen 4.2.2 Key Stroke Input When a key is pressed on the keyboard, the PS/2 clock line is brought low, and a one-byte key code for the key is transmitted serially through the PS/2 data line, bit by bit.