Thundersoft
/
A8491_for_TT_Mxx
Creating a project about A8491 for TT_Mxx
main.cpp@1:da8c10bb7386, 2019-04-26 (annotated)
- Committer:
- ThunderSoft
- Date:
- Fri Apr 26 09:41:23 2019 +0000
- Revision:
- 1:da8c10bb7386
- Parent:
- 0:6fc4594bc1db
"Update the mbed-os code to support TT_M4G9"
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ThunderSoft | 0:6fc4594bc1db | 1 | /* mbed Microcontroller Library |
ThunderSoft | 0:6fc4594bc1db | 2 | * Copyright (c) 2018 ARM Limited |
ThunderSoft | 0:6fc4594bc1db | 3 | * SPDX-License-Identifier: Apache-2.0 |
ThunderSoft | 0:6fc4594bc1db | 4 | */ |
ThunderSoft | 0:6fc4594bc1db | 5 | |
ThunderSoft | 0:6fc4594bc1db | 6 | #include "mbed.h" |
ThunderSoft | 0:6fc4594bc1db | 7 | #include "MMA8491.h" |
ThunderSoft | 0:6fc4594bc1db | 8 | |
ThunderSoft | 0:6fc4594bc1db | 9 | |
ThunderSoft | 0:6fc4594bc1db | 10 | |
ThunderSoft | 0:6fc4594bc1db | 11 | #ifdef TEST_LCD |
ThunderSoft | 0:6fc4594bc1db | 12 | LCD tft(LCD_SPI_CS,LCD_SPI_DC, LCD_MOSI_PIN, LCD_MISO_PIN, LCD_SPI_CL_PIN,LCD_BL_PIN); |
ThunderSoft | 0:6fc4594bc1db | 13 | #else |
ThunderSoft | 0:6fc4594bc1db | 14 | #define LCD int |
ThunderSoft | 0:6fc4594bc1db | 15 | LCD tft; |
ThunderSoft | 0:6fc4594bc1db | 16 | #endif |
ThunderSoft | 0:6fc4594bc1db | 17 | |
ThunderSoft | 0:6fc4594bc1db | 18 | |
ThunderSoft | 1:da8c10bb7386 | 19 | #if __TT_M3HQ__ |
ThunderSoft | 0:6fc4594bc1db | 20 | #define DISPLAY_TMPM_STRING "Welcome to Thundersoft TT_M3HQ" |
ThunderSoft | 1:da8c10bb7386 | 21 | #endif |
ThunderSoft | 1:da8c10bb7386 | 22 | |
ThunderSoft | 1:da8c10bb7386 | 23 | |
ThunderSoft | 1:da8c10bb7386 | 24 | #if __TT_M4G9__ |
ThunderSoft | 1:da8c10bb7386 | 25 | #define DISPLAY_TMPM_STRING "Welcome to Thundersoft TT_M4G9" |
ThunderSoft | 1:da8c10bb7386 | 26 | #endif |
ThunderSoft | 0:6fc4594bc1db | 27 | |
ThunderSoft | 0:6fc4594bc1db | 28 | /*macros for A8491 board*/ |
ThunderSoft | 0:6fc4594bc1db | 29 | #define DISPLAY_A8491_STRING "A8491 board:" |
ThunderSoft | 0:6fc4594bc1db | 30 | #define DISPLAY_A8491_STRING_HIGH 16 |
ThunderSoft | 0:6fc4594bc1db | 31 | #define DISPLAY_A8491_VALUE_STRING "A8491 value:" |
ThunderSoft | 0:6fc4594bc1db | 32 | #define DISPLAY_A8491_VALUE_STRING_HIGH 32 |
ThunderSoft | 0:6fc4594bc1db | 33 | #define DISPLAY_A8491_VALUE_HIGH 48 |
ThunderSoft | 0:6fc4594bc1db | 34 | |
ThunderSoft | 0:6fc4594bc1db | 35 | |
ThunderSoft | 0:6fc4594bc1db | 36 | |
ThunderSoft | 0:6fc4594bc1db | 37 | static void displayForA8491(LCD &lcd) |
ThunderSoft | 0:6fc4594bc1db | 38 | { |
ThunderSoft | 0:6fc4594bc1db | 39 | #ifdef TEST_LCD |
ThunderSoft | 0:6fc4594bc1db | 40 | lcd.drawString(0,0,DISPLAY_TMPM_STRING,RED); |
ThunderSoft | 0:6fc4594bc1db | 41 | lcd.drawString(0,DISPLAY_A8491_STRING_HIGH,DISPLAY_A8491_STRING,RED); |
ThunderSoft | 0:6fc4594bc1db | 42 | lcd.drawString(0,DISPLAY_A8491_VALUE_STRING_HIGH,DISPLAY_A8491_VALUE_STRING,RED); |
ThunderSoft | 0:6fc4594bc1db | 43 | #endif |
ThunderSoft | 0:6fc4594bc1db | 44 | } |
ThunderSoft | 0:6fc4594bc1db | 45 | |
ThunderSoft | 0:6fc4594bc1db | 46 | static void handleLCDForA8491(LCD &lcd,MMA8491 &accel) |
ThunderSoft | 0:6fc4594bc1db | 47 | { |
ThunderSoft | 0:6fc4594bc1db | 48 | float accel_data[3]; float accel_rms=0.0; |
ThunderSoft | 0:6fc4594bc1db | 49 | char temp_buffer[50]; |
ThunderSoft | 0:6fc4594bc1db | 50 | while(1) |
ThunderSoft | 0:6fc4594bc1db | 51 | { |
ThunderSoft | 0:6fc4594bc1db | 52 | #ifdef TEST_LCD |
ThunderSoft | 0:6fc4594bc1db | 53 | accel.acquire_MMA8491_data_g(accel_data); |
ThunderSoft | 0:6fc4594bc1db | 54 | sprintf(temp_buffer,"%4.2f,%4.2f,%4.2f",accel_data[0],accel_data[1],accel_data[2]); |
ThunderSoft | 0:6fc4594bc1db | 55 | lcd.drawString(0,DISPLAY_A8491_VALUE_HIGH,temp_buffer,RED); |
ThunderSoft | 0:6fc4594bc1db | 56 | #endif |
ThunderSoft | 0:6fc4594bc1db | 57 | printf("%4.2f,%4.2f,%4.2f,\r\n",accel_data[0],accel_data[1],accel_data[2]); |
ThunderSoft | 0:6fc4594bc1db | 58 | #ifdef TEST_LCD |
ThunderSoft | 0:6fc4594bc1db | 59 | wait_ms(1000); |
ThunderSoft | 0:6fc4594bc1db | 60 | lcd.clearScreenArea(0,DISPLAY_A8491_VALUE_HIGH,WHITE); |
ThunderSoft | 0:6fc4594bc1db | 61 | #endif |
ThunderSoft | 0:6fc4594bc1db | 62 | } |
ThunderSoft | 0:6fc4594bc1db | 63 | } |
ThunderSoft | 0:6fc4594bc1db | 64 | |
ThunderSoft | 0:6fc4594bc1db | 65 | |
ThunderSoft | 0:6fc4594bc1db | 66 | |
ThunderSoft | 0:6fc4594bc1db | 67 | int main() |
ThunderSoft | 0:6fc4594bc1db | 68 | { |
ThunderSoft | 0:6fc4594bc1db | 69 | MMA8491 accel(D14,D15,A1); |
ThunderSoft | 0:6fc4594bc1db | 70 | float accel_data[3]; float accel_rms=0.0; |
ThunderSoft | 0:6fc4594bc1db | 71 | #ifdef TEST_LCD |
ThunderSoft | 0:6fc4594bc1db | 72 | tft.init(); |
ThunderSoft | 0:6fc4594bc1db | 73 | displayForA8491(tft); |
ThunderSoft | 0:6fc4594bc1db | 74 | #endif |
ThunderSoft | 0:6fc4594bc1db | 75 | printf("%s\r\n",DISPLAY_TMPM_STRING); |
ThunderSoft | 0:6fc4594bc1db | 76 | handleLCDForA8491(tft,accel); |
ThunderSoft | 0:6fc4594bc1db | 77 | while(1) |
ThunderSoft | 0:6fc4594bc1db | 78 | { |
ThunderSoft | 0:6fc4594bc1db | 79 | } |
ThunderSoft | 0:6fc4594bc1db | 80 | } |