Creating a project for TT_Mxx

Committer:
ThunderSoft
Date:
Fri Apr 26 09:46:22 2019 +0000
Revision:
1:05a211e75d38
Parent:
0:53c9fac03371
"update the mbed-os code to support TT_M4G9"

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ThunderSoft 0:53c9fac03371 1 #include "mbed.h"
ThunderSoft 0:53c9fac03371 2 #include "MPU6050.h"
ThunderSoft 0:53c9fac03371 3
ThunderSoft 0:53c9fac03371 4
ThunderSoft 0:53c9fac03371 5
ThunderSoft 0:53c9fac03371 6
ThunderSoft 0:53c9fac03371 7
ThunderSoft 0:53c9fac03371 8
ThunderSoft 0:53c9fac03371 9 #ifdef TEST_LCD
ThunderSoft 0:53c9fac03371 10 LCD tft(LCD_SPI_CS,LCD_SPI_DC, LCD_MOSI_PIN, LCD_MISO_PIN, LCD_SPI_CL_PIN,LCD_BL_PIN);
ThunderSoft 0:53c9fac03371 11 #else
ThunderSoft 0:53c9fac03371 12 #define LCD int
ThunderSoft 0:53c9fac03371 13 LCD tft;
ThunderSoft 0:53c9fac03371 14 #endif
ThunderSoft 0:53c9fac03371 15
ThunderSoft 0:53c9fac03371 16
ThunderSoft 0:53c9fac03371 17 #if __TT_M3HQ__
ThunderSoft 0:53c9fac03371 18 #define DISPLAY_TMPM_STRING "Welcome to Thundersoft TT_M3HQ"
ThunderSoft 0:53c9fac03371 19 #endif
ThunderSoft 0:53c9fac03371 20
ThunderSoft 0:53c9fac03371 21
ThunderSoft 0:53c9fac03371 22 #if __TT_M4G9__
ThunderSoft 0:53c9fac03371 23 #define DISPLAY_TMPM_STRING "Welcome to Thundersoft TT_M4G9"
ThunderSoft 0:53c9fac03371 24 #endif
ThunderSoft 0:53c9fac03371 25
ThunderSoft 0:53c9fac03371 26 /*macros for MPU6050 sensor*/
ThunderSoft 0:53c9fac03371 27 #define DISPLAY_MPU6050_ID_STRING "MPU6050 ID:"
ThunderSoft 0:53c9fac03371 28 #define DISPLAY_MPU6050_ID_STRING_HIGH 16
ThunderSoft 0:53c9fac03371 29 #define DISPLAY_MPU6050_ACC_STRING "MPU6050 ACC:"
ThunderSoft 0:53c9fac03371 30 #define DISPLAY_MPU6050_ACC_STRING_HIGH 32
ThunderSoft 0:53c9fac03371 31 #define DISPLAY_MPU6050_ACC_VALUE_HIGH 48
ThunderSoft 0:53c9fac03371 32 #define DISPLAY_MPU6050_MAG_STRING "MPU6050 MAG:"
ThunderSoft 0:53c9fac03371 33 #define DISPLAY_MPU6050_MAG_HIGH 64
ThunderSoft 0:53c9fac03371 34 #define DISPLAY_MPU6050_MAG_VALUE_HIGH 80
ThunderSoft 0:53c9fac03371 35
ThunderSoft 0:53c9fac03371 36
ThunderSoft 0:53c9fac03371 37 static void displayForMPU6050(LCD &lcd,MPU6050 &mpu6050)
ThunderSoft 0:53c9fac03371 38 {
ThunderSoft 0:53c9fac03371 39 #ifdef TEST_LCD
ThunderSoft 0:53c9fac03371 40 lcd.drawString(0,0,DISPLAY_TMPM_STRING,RED);
ThunderSoft 0:53c9fac03371 41 displayId(lcd,DISPLAY_MPU6050_ID_STRING,sizeof(DISPLAY_MPU6050_ID_STRING),DISPLAY_MPU6050_ID_STRING_HIGH,mpu6050.getDeviceID());
ThunderSoft 0:53c9fac03371 42 lcd.drawString(0,DISPLAY_MPU6050_ACC_STRING_HIGH,DISPLAY_MPU6050_ACC_STRING,RED);
ThunderSoft 0:53c9fac03371 43 lcd.drawString(0,DISPLAY_MPU6050_MAG_HIGH,DISPLAY_MPU6050_MAG_STRING,RED);
ThunderSoft 0:53c9fac03371 44 #endif
ThunderSoft 0:53c9fac03371 45 }
ThunderSoft 0:53c9fac03371 46
ThunderSoft 0:53c9fac03371 47 static void handleLCDForMPU6050(LCD &lcd,MPU6050 &mpu6050)
ThunderSoft 0:53c9fac03371 48 {
ThunderSoft 0:53c9fac03371 49 uint16_t acc[3];
ThunderSoft 0:53c9fac03371 50 uint16_t mag[3];
ThunderSoft 0:53c9fac03371 51 char temp_buffer[50];
ThunderSoft 0:53c9fac03371 52 while(1)
ThunderSoft 0:53c9fac03371 53 {
ThunderSoft 0:53c9fac03371 54
ThunderSoft 0:53c9fac03371 55 acc[0] = mpu6050.getX();
ThunderSoft 0:53c9fac03371 56 acc[1] = mpu6050.getY();
ThunderSoft 0:53c9fac03371 57 acc[2] = mpu6050.getZ();
ThunderSoft 0:53c9fac03371 58 mag[0] = mpu6050.getGX();
ThunderSoft 0:53c9fac03371 59 mag[1] = mpu6050.getGY();
ThunderSoft 0:53c9fac03371 60 mag[2] = mpu6050.getGZ();
ThunderSoft 0:53c9fac03371 61 memset(temp_buffer,0,sizeof(temp_buffer));
ThunderSoft 0:53c9fac03371 62 sprintf(temp_buffer,"%d,%d,%d",acc[0],acc[1],acc[2]);
ThunderSoft 0:53c9fac03371 63 #ifdef TEST_LCD
ThunderSoft 0:53c9fac03371 64 lcd.drawString(0,DISPLAY_MPU6050_ACC_VALUE_HIGH,temp_buffer,RED);
ThunderSoft 0:53c9fac03371 65 #endif
ThunderSoft 0:53c9fac03371 66 printf("MPU6050 ACC data = %d,%d,%d \r\n",acc[0],acc[1],acc[2]);
ThunderSoft 0:53c9fac03371 67 memset(temp_buffer,0,sizeof(temp_buffer));
ThunderSoft 0:53c9fac03371 68 sprintf(temp_buffer,"%d,%d,%d",mag[0],mag[1],mag[2]);
ThunderSoft 0:53c9fac03371 69 #ifdef TEST_LCD
ThunderSoft 0:53c9fac03371 70 lcd.drawString(0,DISPLAY_MPU6050_MAG_VALUE_HIGH,temp_buffer,RED);
ThunderSoft 0:53c9fac03371 71 #endif
ThunderSoft 0:53c9fac03371 72 printf("MPU6050 MAG data = %d,%d,%d \r\n",mag[0],mag[1],mag[2]);
ThunderSoft 0:53c9fac03371 73 wait_ms(1000);
ThunderSoft 0:53c9fac03371 74 #ifdef TEST_LCD
ThunderSoft 0:53c9fac03371 75 lcd.clearScreenArea(0,DISPLAY_MPU6050_ACC_VALUE_HIGH,WHITE);
ThunderSoft 0:53c9fac03371 76 lcd.clearScreenArea(0,DISPLAY_MPU6050_MAG_VALUE_HIGH,WHITE);
ThunderSoft 0:53c9fac03371 77 #endif
ThunderSoft 0:53c9fac03371 78 }
ThunderSoft 0:53c9fac03371 79 }
ThunderSoft 0:53c9fac03371 80
ThunderSoft 0:53c9fac03371 81
ThunderSoft 0:53c9fac03371 82 int main()
ThunderSoft 0:53c9fac03371 83 {
ThunderSoft 0:53c9fac03371 84 MPU6050 mp;
ThunderSoft 0:53c9fac03371 85 printf("%s\r\n",DISPLAY_TMPM_STRING);
ThunderSoft 0:53c9fac03371 86 printf("MPU6050 ID = 0x%x \r\n",mp.getDeviceID());
ThunderSoft 0:53c9fac03371 87 #ifdef TEST_LCD
ThunderSoft 0:53c9fac03371 88 tft.init();
ThunderSoft 0:53c9fac03371 89 #endif
ThunderSoft 0:53c9fac03371 90 displayForMPU6050(tft,mp);
ThunderSoft 0:53c9fac03371 91 handleLCDForMPU6050(tft,mp);
ThunderSoft 0:53c9fac03371 92 while(1)
ThunderSoft 0:53c9fac03371 93 {
ThunderSoft 0:53c9fac03371 94 }
ThunderSoft 0:53c9fac03371 95 }