Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.69 KB | None | 0 0
  1. #include "Board_GLCD.h"
  2. #include "Board_LED.h"
  3. #include "stm32f2xx_hal.h"
  4. #include "GLCD_Config.h"
  5. #include "JOY.h"
  6. #include "Serial.h"
  7. #include "string.h"
  8.  
  9. extern GLCD_FONT GLCD_Font_16x24;
  10. uint32_t fw,fh,dx,dy;
  11. bool ready;
  12. const char ASCII[] = {' ','!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/',
  13.                 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
  14.                 '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  15.                 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
  16.                 '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n' , 'o',
  17.                 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~'};
  18.  
  19.  
  20.  
  21. /**Initialize the peripherals: Already Done**/
  22. void setup(void){
  23.     GLCD_Initialize();
  24.     LED_Initialize();
  25.     JOY_Init();
  26.     SER_Init(115200);
  27.     GLCD_SetFont(&GLCD_Font_16x24);
  28.     GLCD_SetBackgroundColor(GLCD_COLOR_PURPLE);
  29.     fw = GLCD_Font_16x24.width;// font width
  30.     fh = GLCD_Font_16x24.height; //font height
  31.     //minimum x position on the screen. Corresponds to column 0
  32.     dx = (GLCD_WIDTH - 16*fw)>>1;
  33.     //minimum y position on the screen. Corresponds to row 0
  34.     dy = (GLCD_HEIGHT - 6*fh)>>1;
  35.     //use to prevent Joy stick sampling when the joy stick has not be initialized
  36.     ready = true;
  37. }
  38.  
  39. /**Checks if the direction of the joy stick and move the cursor in the joy stick's direction. If the cursor is at the bounds, cursor will not be moved**/
  40. void sampleJoystick(void){
  41.    
  42.         if(!ready)return;   //initialization has not completed, abort
  43.             uint32_t key = JOY_GetKeys();
  44.  
  45. // Put code here //
  46.        
  47. }
  48.  
  49. int32_t* convertChar(int32_t* array){
  50.     int arraySize = (sizeof(ASCII)/sizeof(ASCII[0]));
  51.     int arrayIndex = 0;
  52.     for(arrayIndex = 0; arrayIndex < arraySize; arrayIndex++){
  53.         memcpy(&array[arrayIndex], &ASCII[arrayIndex] + (arrayIndex * 4), sizeof(int32_t));
  54.     }
  55.     return array;
  56. }
  57.  
  58.  
  59. /**Convert row and column to actual x y position: p[0] = column p[1] = row **/
  60. uint32_t toPosition(int* p){
  61.  
  62. char position[6][12];
  63.  
  64. }
  65.  
  66.  
  67. /**Draw ascii characters on the screen**/
  68. void draw(void){
  69.     int arraySize = (sizeof(ASCII)/sizeof(ASCII[0]));
  70.         int32_t int32_tASCII[arraySize];
  71.     int32_t* ASCIIArray = convertChar(int32_tASCII);
  72.     int arrayIndex = 0;
  73.         int* x;
  74.     for(arrayIndex = 0; arrayIndex < arraySize; arrayIndex++){
  75.         GLCD_DrawChar(toPosition(x), 0, ASCIIArray[arrayIndex]);
  76.     }
  77. }
  78.  
  79.  
  80.  
  81. int main(void){
  82.                 SystemCoreClockUpdate();
  83.         HAL_Init();
  84.         SysTick_Config(SystemCoreClock/1000);
  85.         setup();
  86.         GLCD_ClearScreen();
  87.         draw();
  88.    
  89.  
  90. // Add Additional lines of code if required //
  91.  
  92.         while(1){}
  93. }
  94.  
  95.  
  96. /*SysTick ISR*/
  97. void SysTick_Handler(void){
  98.     //increment HAL tick variable; this is required for LCD Display Config.
  99.     HAL_IncTick();
  100.     //check for joy stick movement to configure Joystick Sampling
  101.     sampleJoystick();
  102. }
  103.  
  104.  
  105.  
  106.  
  107. /**Highlight the character c in the 16x6 grid **/
  108. void highlightText(uint32_t c){
  109.  
  110. // Put code here //
  111.    
  112. }
  113.  
  114.  
  115.  
  116. /**Fill the array p with the row and column number of the character ch: p[0] column p[1] = row **/
  117. void getPos(uint32_t ch,int *p){
  118.    
  119. // Put code here //
  120.  
  121. }
  122.  
  123.  
  124. /**Toggle the LED based on the bits of the character c.
  125. 1 LED will be turned on
  126. 0 LED will be turned off **/
  127. void LED (uint32_t c){
  128.    
  129. // Put code here //
  130.            
  131. }
  132.  
  133.  
  134.  
  135.  
  136.  
  137. /** Clear any previous highlight and highlight c **/
  138. void ClearHighlight(uint32_t c){
  139.  
  140. // Put code here //
  141.    
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement