Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MAX17055 MAX32620FTHR MAX77650 SerialGPS
main.cpp
00001 00002 #include "mbed.h" 00003 #include <math.h> 00004 #include <stdlib.h> 00005 00006 #include "SerialGPS.h" 00007 #include "LCD_Driver.h" 00008 #include "LCD_GUI.h" 00009 #include "MAX32620FTHR.h" 00010 #include "MAX77650.h" 00011 #include "MAX17055.h" 00012 00013 #include "GPSimg.h" 00014 #include "BatteryImg.h" 00015 00016 00017 #define POWER_HOLD_OFF 0 00018 #define POWER_HOLD_ON 1 00019 00020 // Configure GPIO voltage 00021 MAX32620FTHR max32620fthr(MAX32620FTHR::VIO_3V3); 00022 00023 #define BACKGROUND BLACK 00024 #define FOREGROUND YELLOW 00025 #define DELAY 1000 00026 00027 I2C i2c(I2C2_SDA, I2C2_SCL); 00028 DigitalOut myled(LED1); 00029 SerialGPS gps(P3_1, P3_0,9600); 00030 00031 MAX17055 max17055(i2c); // Fuel gauge 00032 MAX77650 max77650(i2c); // MAX77650 PMIC and Charger 00033 00034 // Configure PMIC to drive green LED 00035 static const char ledGreen[] = { 00036 MAX77650::CNFG_LED0_A, 00037 0x04, 0x44, 0x04, 00038 0x0F, 0x0F, 0x0F, 00039 0x01, 00040 }; 00041 00042 DigitalOut pw_Hold(P2_2, POWER_HOLD_ON); 00043 //SDFileSystem sd(P0_5, P0_6, P0_4, P1_3, "sd"); // the pinout on the mbed Cool Components workshop board 00044 00045 00046 int main() { 00047 00048 // Configure TFT display 00049 LCD_SCAN_DIR LCD_ScanDir = SCAN_DIR_DFT;//SCAN_DIR_DFT = D2U_L2R 00050 LCD_Init(LCD_ScanDir ); 00051 00052 wait_ms(1000); 00053 00054 LCD_Clear(BLACK); 00055 GUI_DrawRectangle(0,0,156,127,RED,DRAW_EMPTY,DOT_PIXEL_2X2); 00056 myled = !myled; // toggle a led 00057 00058 char sats[16] = {}; 00059 char longitude[16] = {}; 00060 char latitude[16] = {}; 00061 char geoid[16] = {}; 00062 char altitude[16] = {}; 00063 char time[16] = {}; 00064 00065 char voltage[16] = {}; 00066 char avgVoltage[16] = {}; 00067 char current[16] = {}; 00068 00069 ///int status; 00070 float f_value; 00071 00072 // Configure fuel gauge 00073 // Set sense resistor value 00074 max17055.init(0.05f); 00075 00076 // Turn off Low-Dropout Linear Regulator (LDO); unused on MAX32620FTHR platform 00077 max77650.disableLDO(); 00078 00079 // Set SIMO Buck-Boost Regulator 2 target voltage; provides VDDIOH 00080 max77650.setSBB2Voltage(3.3f); 00081 00082 // Turn PMIC green LED on, red and blue off 00083 max77650.writeReg(ledGreen, sizeof(ledGreen)); 00084 00085 00086 while(1) { 00087 00088 wait(0.5f); // wait a small period of time 00089 00090 if (gps.sample()) { 00091 myled = myled ? 0 : 1; 00092 //pc.printf("sats %d, long %f, lat %f, alt %f, geoid %f, time %f\n\r", gps.sats, gps.longitude, gps.latitude, gps.alt, gps.geoid, gps.time); 00093 00094 sprintf(sats, "SAT: %d ", gps.sats); 00095 sprintf(longitude, "LONG: %2.2f ", gps.longitude); 00096 sprintf(latitude, "LAT: %2.2f ", gps.latitude); 00097 sprintf(altitude, "ALT: %2.2f ", gps.alt); 00098 sprintf(geoid, "GEOID: %2.2f ", gps.geoid); 00099 sprintf(time, "TIME: %2.2f ", gps.time); 00100 00101 LCD_Clear(BLACK); 00102 GUI_DisplayImage(50,10,gps_lock,50,50); 00103 GUI_DrawRectangle(0,0,156,127,YELLOW,DRAW_EMPTY,DOT_PIXEL_2X2); 00104 00105 GUI_DisString_EN(10,80,sats,&Font12,GUI_BACKGROUND,YELLOW); 00106 GUI_DisString_EN(10,90,longitude,&Font12,GUI_BACKGROUND,YELLOW); 00107 GUI_DisString_EN(10,100,latitude,&Font12,GUI_BACKGROUND,YELLOW); 00108 GUI_DisString_EN(10,110,altitude,&Font12,GUI_BACKGROUND,CYAN); 00109 //GUI_DisString_EN(10,90,geoid,&Font12,GUI_BACKGROUND,CYAN); 00110 //GUI_DisString_EN(10,110,time,&Font12,GUI_BACKGROUND,CYAN); 00111 00112 wait(2); 00113 LCD_Clear(BLACK); 00114 00115 // Print formatted voltage, and battery current 00116 max17055.v_cell(&f_value); 00117 sprintf(voltage,"V=%6.2fV", f_value); 00118 //max17055.avg_v_cell(&f_value); 00119 //sprintf(avgVoltage,"Vavg = %6.3f", f_value); 00120 max17055.current(&f_value); 00121 sprintf(current,"I=%6.2fmA", f_value); 00122 //max17055.avg_current(&f_value); 00123 00124 GUI_DisplayImage(50,10,batt_full,50,50); 00125 GUI_DisString_EN(10,70,voltage,&Font20,GUI_BACKGROUND,YELLOW); 00126 //GUI_DisString_EN(10,90,avgVoltage,&Font12,GUI_BACKGROUND,YELLOW); 00127 GUI_DisString_EN(10,100,current,&Font20,GUI_BACKGROUND,CYAN); 00128 00129 wait(2); 00130 00131 00132 } 00133 myled = !myled; // toggle a led 00134 } 00135 } 00136 00137
Generated on Thu Jul 14 2022 11:13:12 by
1.7.2