/** * @brief Main program * @param None * @retval None */ int main(void) { // uint8_t R; uint8_t buf[10]; uint8_t buf_1[10]; uint8_t buf_2[10]; float pdd[3]; /* STM32F4xx HAL library initialization: - Configure the Flash prefetch, instruction and Data caches - Configure the Systick to generate an interrupt each 1 msec - Set NVIC Group Priority to 4 - Low Level Initialization */ HAL_Init(); SystemClock_Config(); BSP_LCD_Init(); BSP_LCD_LayerDefaultInit(LCD_FOREGROUND_LAYER, (LCD_FRAME_BUFFER + BUFFER_OFFSET)); /* Configure the transparency for foreground : Increase the transprency */ BSP_LCD_SetTransparency(LCD_BACKGROUND_LAYER, 0); BSP_LCD_SelectLayer(LCD_FOREGROUND_LAYER); BSP_GYRO_Init(); //R=BSP_GYRO_ReadID(); /* Configure the System clock to have a frequency of 180 MHz */ SystemClock_Config(); Delaimes(20); BSP_GYRO_Init(); Delaimes(4); BSP_LCD_SetBackColor(LCD_COLOR_BLACK); BSP_LCD_Clear(LCD_COLOR_BLACK ); BSP_LCD_SetTextColor(LCD_COLOR_BLUE); Delaimes(4); /* Infinite loop */ while (1) { BSP_GYRO_GetXYZ(pdd); sprintf(buf,"%.3f",pdd[0]); sprintf(buf_1,"%.3f",pdd[1]); sprintf(buf_2,"%.3f",pdd[2]); BSP_LCD_DisplayStringAtLine(0,buf); BSP_LCD_DisplayStringAtLine(1,buf_1); BSP_LCD_DisplayStringAtLine(2,buf_2); Delaimes(200); } }
int main(int argc, char **argv) { uint32_t i; uint8_t accelRc, gyroRc; /* Configure the system clock */ SystemClock_Config(); HAL_Init(); TerminalInit(); /* Initialize UART and USB */ /* Configure the LEDs... */ for(i=0; i<numLEDs; i++) { BSP_LED_Init(LEDs[i]); } /* Initialize the pushbutton */ BSP_PB_Init(BUTTON_USER, BUTTON_MODE_GPIO); /* Initialize the Accelerometer */ accelRc = BSP_ACCELERO_Init(); if(accelRc != ACCELERO_OK) { printf("Failed to initialize acceleromter\n"); Error_Handler(); } /* Initialize the Gyroscope */ gyroRc = BSP_GYRO_Init(); if(gyroRc != GYRO_OK) { printf("Failed to initialize Gyroscope\n"); Error_Handler(); } HD44780_Init(); // lcd init HD44780_PutStr("Hello World!"); hd44780_wr_cmd(0xC0); // to change curser to next line HD44780_PutStr("Hello Test !"); //print text while(1) { TaskInput(); } return 0; }
/** * @brief USBD_HID_GetPos * @param None * @retval Pointer to report */ void USB_GetPointerData_Demo(uint8_t *pbuf) { static float Buffer[6] = {0}; BSP_GYRO_Init(); /* Read Gyro Angular data */ Demo_GyroReadAngRate(Buffer); pbuf[0] = 0; pbuf[1] = -(int8_t)(Buffer[2])/6; pbuf[2] = (int8_t)(Buffer[1])/6; pbuf[3] = 0; BSP_LED_Toggle(LED3); BSP_LED_Toggle(LED10); BSP_LED_Toggle(LED6); BSP_LED_Toggle(LED7); }
int main(int argc, char **argv) { uint32_t i; uint8_t accelRc, gyroRc; /* Configure the system clock */ SystemClock_Config(); HAL_Init(); TerminalInit(); /* Initialize UART and USB */ /* Configure the LEDs... */ for(i=0; i<numLEDs; i++) { BSP_LED_Init(LEDs[i]); } /* Initialize the pushbutton */ BSP_PB_Init(BUTTON_USER, BUTTON_MODE_GPIO); /* Initialize the Accelerometer */ accelRc = BSP_ACCELERO_Init(); if(accelRc != ACCELERO_OK) { printf("Failed to initialize acceleromter\n"); Error_Handler(); } /* Initialize the Gyroscope */ gyroRc = BSP_GYRO_Init(); if(gyroRc != GYRO_OK) { printf("Failed to initialize Gyroscope\n"); Error_Handler(); } while(1) { TaskInput(); taskcounter(); } return 0; }
/** * @brief Read Gyroscope Angular data. * @param None * @retval None */ static void GYRO_ReadAng(void) { /* Gyroscope variables */ float Buffer[3]; float Xval, Yval = 0x00; /* Init Gyroscope Mems */ if(BSP_GYRO_Init() != HAL_OK) { /* Initialization Error */ Error_Handler(); } /* Read Gyroscope Angular data */ BSP_GYRO_GetXYZ(Buffer); Xval = ABS((Buffer[0])); Yval = ABS((Buffer[1])); if(Xval>Yval) { if(Buffer[0] > 5000.0f) { /* LED5 On */ BSP_LED_On(LED5); HAL_Delay(10); } else if(Buffer[0] < -5000.0f) { /* LED4 On */ BSP_LED_On(LED4); HAL_Delay(10); } else { HAL_Delay(10); } } else { if(Buffer[1] < -5000.0f) { /* LED6 On */ BSP_LED_On(LED6); HAL_Delay(10); } else if(Buffer[1] > 5000.0f) { /* LED3 On */ BSP_LED_On(LED3); HAL_Delay(10); } else { HAL_Delay(10); } } BSP_LED_Off(LED3); BSP_LED_Off(LED4); BSP_LED_Off(LED5); BSP_LED_Off(LED6); }
/** * @brief MEMS demo * @param None * @retval None */ void MEMS_demo(void) { MEMS_SetHint(); if (BSP_GYRO_Init() != GYRO_OK) { BSP_LCD_SetBackColor(LCD_COLOR_WHITE); BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 95, (uint8_t*)"ERROR", CENTER_MODE); BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 80, (uint8_t*)"MEMS cannot be initialized", CENTER_MODE); } else { Gyroscope_DrawBackground(state); } BSP_GYRO_Reset(); while (1) { /* Read Gyro Angular data */ BSP_GYRO_GetXYZ(Buffer); /* Update autoreload and capture compare registers value */ Xval = ABS((Buffer[0])); Yval = ABS((Buffer[1])); Zval = ABS((Buffer[2])); if((Xval>Yval) && (Xval>Zval)) { if(Buffer[0] > 10000.0f) { if((state & 1) == 0) { Gyroscope_DrawBackground(1); state |= 1; HAL_Delay(1000); } } else if(Buffer[0] < -10000.0f) { if((state & 2) == 0) { Gyroscope_DrawBackground(2); state |= 2; HAL_Delay(1000); } } } else if ((Yval>Xval) && (Yval>Zval)) { if(Buffer[1] < -10000.0f) { if((state & 4) == 0) { Gyroscope_DrawBackground(4); state |= 4; HAL_Delay(1000); } } else if(Buffer[1] > 10000.0f) { if((state & 8) == 0) { Gyroscope_DrawBackground(8); state |= 8; HAL_Delay(1000); } } } else if ((Zval>Xval) && (Zval>Yval)) { if(Buffer[2] < -10000.0f) { if((state & 16) == 0) { Gyroscope_DrawBackground(16); state |= 16; HAL_Delay(1000); } } else if(Buffer[2] > 10000.0f) { if((state & 32) == 0) { Gyroscope_DrawBackground(32); state |= 32; HAL_Delay(1000); } } } if (state != 0x3F) { } else if (CheckForUserInput() > 0) { state = 0; return; } } }