Team Riedel - display
Dependencies: LCD_fonts SPI_TFT_ILI9341 CMSIS_DSP_401_without_cm4 mbed-src SDFileSystem wavfile
main.cpp
00001 #include "main.h" //FROM DFSDM CORE 00002 #include <math.h> 00003 #include "stdio.h" 00004 #include "mbed.h" 00005 #include "SPI_TFT_ILI9341.h" 00006 #include "string" 00007 #include "Arial12x12.h" 00008 #include "Arial24x23.h" 00009 #include "arm_math.h" 00010 #include "SDFileSystem.h" 00011 //#include "main.h" 00012 #define samplenum 1024 00013 //FROM DFSDM CORE 00014 extern void RECORD(void); 00015 extern void MSE(void); 00016 extern void COMPARE(void); 00017 00018 extern float32_t CONTROLPWR[1024]; //CONTROL 0 PWR 00019 extern float32_t CONTROLPHS[1024]; //CTONROL 0 PHS 00020 extern float32_t CONTROLPWRMSE;//CONTROL PWR MSE 00021 extern float32_t CONTROLPHSMSE;//CONTROL PHS MSE 00022 extern float32_t POWER[1024]; 00023 extern float32_t PHS[1024]; 00024 extern float32_t PWRMSE; 00025 extern float32_t PHSMSE; 00026 00027 Serial pc(SERIAL_TX, SERIAL_RX); 00028 //DigitalIn mybutton(USER_BUTTON); 00029 //DigitalOut myled(LED1); 00030 //SDFileSystem sd(PC_12, PC_11, PC_10, PD_2, "sd"); 00031 // 00032 00033 DigitalIn ain1(PC_9); 00034 DigitalIn ain2(PB_15); 00035 DigitalIn ain3(PC_7); 00036 DigitalIn ain4(PC_6); 00037 DigitalIn ain5(PC_8); 00038 00039 uint32_t ifftFlag = 0; 00040 uint32_t doBitReverse = 1; 00041 00042 /* Reference index at which max energy of bin ocuurs */ 00043 uint32_t refIndex = 213, testIndex = 0; 00044 00045 const float32_t a[samplenum] = { -0.865129623056441, -2.655020678073846, 0.600664612949661, 0.080378093886515, -2.899160484012034, 2.563004262857762, 3.078328403304206, 0.505906778385130, 0.048366940168201, -0.545696461188734, -0.023417155362879, 2.127729174988954, -1.176633086028377, 3.690223557991855, -0.622791766173194, 0.722837373872203, 2.739754205367484, -0.062610410524552, -0.891296810967338, -1.845872258871811, 1.195039415434387, -2.177388969045026, 1.078649103637905, 2.570976050490193, -1.383551403404574, 2.392141424058873, 2.858002843205065, -3.682433899725536, -3.488146646451150, 1.323468578888120, -0.099771155430726, 1.561168082500454, 00046 1.025026795103179, 0.928841900171200, 2.930499509864950, 2.013349089766430, 2.381676148486737, -3.081062307950236, -0.389579115537544, 0.581540149166620, -2.601953341353208, 0.333435137781238, -2.812945856162965, 2.649109640172910, -1.003963025744654, 1.552460768755035, 0.088641345335247, -2.519951327113426, -4.341348988610527, 0.557772429359965, -1.671267412948494, 0.733951350960387, 0.409263788034864, 3.566033071952806, 1.882565173848352, -1.106017073793287, 0.554456720778718, -2.513205795512153, 0.310978660939421, 0.579706500111723, 0.000086383683251, -1.311866980897721, 1.840007477574986, -3.253005768451345, 00047 1.462584328739432, 1.610103610851738, 0.761914676858907, 0.974541361089834, 0.686845845885983, 1.849153122025191, 0.787800410401453, -1.187438909666279, -0.754937911044720, 0.084373858395232, -2.600269011710521, -0.962982842142644, -0.369328108540868, 0.810791418361879, 3.587016488699641, -0.520776145083723, 0.640249919627884, 1.103122489464969, 2.231779881455556, -1.308035392685241, 0.424070304330106, -0.200383932651189, -2.365526783356541, -0.989114757436628, 2.770807688959777, -0.444172737462307, 0.079760979374078, -0.005199118412183, -0.664712668309527, -0.624171857561896, 0.537306979007338, -2.575955675497642, 00048 1.562363235756780, 1.814069369848895, -1.293428583392509, -1.026188449495686, -2.981771815588717, -4.223468103075124, 2.672674782004045, -0.856096801117735, 0.048517345512563, -0.026860721136225, 0.392932277758187, -1.331740855093099, -1.894292129477081, -1.425006468460681, -2.721772427617057, -1.616831100216806, 3.551177651488947, -0.069685667896087, -3.134634907409102, -0.263627598944639, -1.650469945991350, -2.203580339374399, -0.872203246123242, 1.230782812607287, 0.257288860093291, 1.989083106173137, -1.985638729453261, -1.416385105842892, -1.131097688325772, -2.245130805416057, -1.938873996219074, 2.043608361562645, 00049 -0.865129623056441, -2.655020678073846, 0.600664612949661, 0.080378093886515, -2.899160484012034, 2.563004262857762, 3.078328403304206, 0.505906778385130, 0.048366940168201, -0.545696461188734, -0.023417155362879, 2.127729174988954, -1.176633086028377, 3.690223557991855, -0.622791766173194, 0.722837373872203, 2.739754205367484, -0.062610410524552, -0.891296810967338, -1.845872258871811, 1.195039415434387, -2.177388969045026, 1.078649103637905, 2.570976050490193, -1.383551403404574, 2.392141424058873, 2.858002843205065, -3.682433899725536, -3.488146646451150, 1.323468578888120, -0.099771155430726, 1.561168082500454, 00050 1.025026795103179, 0.928841900171200, 2.930499509864950, 2.013349089766430, 2.381676148486737, -3.081062307950236, -0.389579115537544, 0.581540149166620, -2.601953341353208, 0.333435137781238, -2.812945856162965, 2.649109640172910, -1.003963025744654, 1.552460768755035, 0.088641345335247, -2.519951327113426, -4.341348988610527, 0.557772429359965, -1.671267412948494, 0.733951350960387, 0.409263788034864, 3.566033071952806, 1.882565173848352, -1.106017073793287, 0.554456720778718, -2.513205795512153, 0.310978660939421, 0.579706500111723, 0.000086383683251, -1.311866980897721, 1.840007477574986, -3.253005768451345, 00051 1.462584328739432, 1.610103610851738, 0.761914676858907, 0.974541361089834, 0.686845845885983, 1.849153122025191, 0.787800410401453, -1.187438909666279, -0.754937911044720, 0.084373858395232, -2.600269011710521, -0.962982842142644, -0.369328108540868, 0.810791418361879, 3.587016488699641, -0.520776145083723, 0.640249919627884, 1.103122489464969, 2.231779881455556, -1.308035392685241, 0.424070304330106, -0.200383932651189, -2.365526783356541, -0.989114757436628, 2.770807688959777, -0.444172737462307, 0.079760979374078, -0.005199118412183, -0.664712668309527, -0.624171857561896, 0.537306979007338, -2.575955675497642, 00052 1.562363235756780, 1.814069369848895, -1.293428583392509, -1.026188449495686, -2.981771815588717, -4.223468103075124, 2.672674782004045, -0.856096801117735, 0.048517345512563, -0.026860721136225, 0.392932277758187, -1.331740855093099, -1.894292129477081, -1.425006468460681, -2.721772427617057, -1.616831100216806, 3.551177651488947, -0.069685667896087, -3.134634907409102, -0.263627598944639, -1.650469945991350, -2.203580339374399, -0.872203246123242, 1.230782812607287, 0.257288860093291, 1.989083106173137, -1.985638729453261, -1.416385105842892, -1.131097688325772, -2.245130805416057, -1.938873996219074, 2.043608361562645, 00053 -0.865129623056441, -2.655020678073846, 0.600664612949661, 0.080378093886515, -2.899160484012034, 2.563004262857762, 3.078328403304206, 0.505906778385130, 0.048366940168201, -0.545696461188734, -0.023417155362879, 2.127729174988954, -1.176633086028377, 3.690223557991855, -0.622791766173194, 0.722837373872203, 2.739754205367484, -0.062610410524552, -0.891296810967338, -1.845872258871811, 1.195039415434387, -2.177388969045026, 1.078649103637905, 2.570976050490193, -1.383551403404574, 2.392141424058873, 2.858002843205065, -3.682433899725536, -3.488146646451150, 1.323468578888120, -0.099771155430726, 1.561168082500454, 00054 1.025026795103179, 0.928841900171200, 2.930499509864950, 2.013349089766430, 2.381676148486737, -3.081062307950236, -0.389579115537544, 0.581540149166620, -2.601953341353208, 0.333435137781238, -2.812945856162965, 2.649109640172910, -1.003963025744654, 1.552460768755035, 0.088641345335247, -2.519951327113426, -4.341348988610527, 0.557772429359965, -1.671267412948494, 0.733951350960387, 0.409263788034864, 3.566033071952806, 1.882565173848352, -1.106017073793287, 0.554456720778718, -2.513205795512153, 0.310978660939421, 0.579706500111723, 0.000086383683251, -1.311866980897721, 1.840007477574986, -3.253005768451345, 00055 1.462584328739432, 1.610103610851738, 0.761914676858907, 0.974541361089834, 0.686845845885983, 1.849153122025191, 0.787800410401453, -1.187438909666279, -0.754937911044720, 0.084373858395232, -2.600269011710521, -0.962982842142644, -0.369328108540868, 0.810791418361879, 3.587016488699641, -0.520776145083723, 0.640249919627884, 1.103122489464969, 2.231779881455556, -1.308035392685241, 0.424070304330106, -0.200383932651189, -2.365526783356541, -0.989114757436628, 2.770807688959777, -0.444172737462307, 0.079760979374078, -0.005199118412183, -0.664712668309527, -0.624171857561896, 0.537306979007338, -2.575955675497642, 00056 1.562363235756780, 1.814069369848895, -1.293428583392509, -1.026188449495686, -2.981771815588717, -4.223468103075124, 2.672674782004045, -0.856096801117735, 0.048517345512563, -0.026860721136225, 0.392932277758187, -1.331740855093099, -1.894292129477081, -1.425006468460681, -2.721772427617057, -1.616831100216806, 3.551177651488947, -0.069685667896087, -3.134634907409102, -0.263627598944639, -1.650469945991350, -2.203580339374399, -0.872203246123242, 1.230782812607287, 0.257288860093291, 1.989083106173137, -1.985638729453261, -1.416385105842892, -1.131097688325772, -2.245130805416057, -1.938873996219074, 2.043608361562645, 00057 -0.865129623056441, -2.655020678073846, 0.600664612949661, 0.080378093886515, -2.899160484012034, 2.563004262857762, 3.078328403304206, 0.505906778385130, 0.048366940168201, -0.545696461188734, -0.023417155362879, 2.127729174988954, -1.176633086028377, 3.690223557991855, -0.622791766173194, 0.722837373872203, 2.739754205367484, -0.062610410524552, -0.891296810967338, -1.845872258871811, 1.195039415434387, -2.177388969045026, 1.078649103637905, 2.570976050490193, -1.383551403404574, 2.392141424058873, 2.858002843205065, -3.682433899725536, -3.488146646451150, 1.323468578888120, -0.099771155430726, 1.561168082500454, 00058 1.025026795103179, 0.928841900171200, 2.930499509864950, 2.013349089766430, 2.381676148486737, -3.081062307950236, -0.389579115537544, 0.581540149166620, -2.601953341353208, 0.333435137781238, -2.812945856162965, 2.649109640172910, -1.003963025744654, 1.552460768755035, 0.088641345335247, -2.519951327113426, -4.341348988610527, 0.557772429359965, -1.671267412948494, 0.733951350960387, 0.409263788034864, 3.566033071952806, 1.882565173848352, -1.106017073793287, 0.554456720778718, -2.513205795512153, 0.310978660939421, 0.579706500111723, 0.000086383683251, -1.311866980897721, 1.840007477574986, -3.253005768451345, 00059 1.462584328739432, 1.610103610851738, 0.761914676858907, 0.974541361089834, 0.686845845885983, 1.849153122025191, 0.787800410401453, -1.187438909666279, -0.754937911044720, 0.084373858395232, -2.600269011710521, -0.962982842142644, -0.369328108540868, 0.810791418361879, 3.587016488699641, -0.520776145083723, 0.640249919627884, 1.103122489464969, 2.231779881455556, -1.308035392685241, 0.424070304330106, -0.200383932651189, -2.365526783356541, -0.989114757436628, 2.770807688959777, -0.444172737462307, 0.079760979374078, -0.005199118412183, -0.664712668309527, -0.624171857561896, 0.537306979007338, -2.575955675497642, 00060 1.562363235756780, 1.814069369848895, -1.293428583392509, -1.026188449495686, -2.981771815588717, -4.223468103075124, 2.672674782004045, -0.856096801117735, 0.048517345512563, -0.026860721136225, 0.392932277758187, -1.331740855093099, -1.894292129477081, -1.425006468460681, -2.721772427617057, -1.616831100216806, 3.551177651488947, -0.069685667896087, -3.134634907409102, -0.263627598944639, -1.650469945991350, -2.203580339374399, -0.872203246123242, 1.230782812607287, 0.257288860093291, 1.989083106173137, -1.985638729453261, -1.416385105842892, -1.131097688325772, -2.245130805416057, -1.938873996219074, 2.043608361562645, 00061 -0.865129623056441, -2.655020678073846, 0.600664612949661, 0.080378093886515, -2.899160484012034, 2.563004262857762, 3.078328403304206, 0.505906778385130, 0.048366940168201, -0.545696461188734, -0.023417155362879, 2.127729174988954, -1.176633086028377, 3.690223557991855, -0.622791766173194, 0.722837373872203, 2.739754205367484, -0.062610410524552, -0.891296810967338, -1.845872258871811, 1.195039415434387, -2.177388969045026, 1.078649103637905, 2.570976050490193, -1.383551403404574, 2.392141424058873, 2.858002843205065, -3.682433899725536, -3.488146646451150, 1.323468578888120, -0.099771155430726, 1.561168082500454, 00062 1.025026795103179, 0.928841900171200, 2.930499509864950, 2.013349089766430, 2.381676148486737, -3.081062307950236, -0.389579115537544, 0.581540149166620, -2.601953341353208, 0.333435137781238, -2.812945856162965, 2.649109640172910, -1.003963025744654, 1.552460768755035, 0.088641345335247, -2.519951327113426, -4.341348988610527, 0.557772429359965, -1.671267412948494, 0.733951350960387, 0.409263788034864, 3.566033071952806, 1.882565173848352, -1.106017073793287, 0.554456720778718, -2.513205795512153, 0.310978660939421, 0.579706500111723, 0.000086383683251, -1.311866980897721, 1.840007477574986, -3.253005768451345, 00063 1.462584328739432, 1.610103610851738, 0.761914676858907, 0.974541361089834, 0.686845845885983, 1.849153122025191, 0.787800410401453, -1.187438909666279, -0.754937911044720, 0.084373858395232, -2.600269011710521, -0.962982842142644, -0.369328108540868, 0.810791418361879, 3.587016488699641, -0.520776145083723, 0.640249919627884, 1.103122489464969, 2.231779881455556, -1.308035392685241, 0.424070304330106, -0.200383932651189, -2.365526783356541, -0.989114757436628, 2.770807688959777, -0.444172737462307, 0.079760979374078, -0.005199118412183, -0.664712668309527, -0.624171857561896, 0.537306979007338, -2.575955675497642, 00064 1.562363235756780, 1.814069369848895, -1.293428583392509, -1.026188449495686, -2.981771815588717, -4.223468103075124, 2.672674782004045, -0.856096801117735, 0.048517345512563, -0.026860721136225, 0.392932277758187, -1.331740855093099, -1.894292129477081, -1.425006468460681, -2.721772427617057, -1.616831100216806, 3.551177651488947, -0.069685667896087, -3.134634907409102, -0.263627598944639, -1.650469945991350, -2.203580339374399, -0.872203246123242, 1.230782812607287, 0.257288860093291, 1.989083106173137, -1.985638729453261, -1.416385105842892, -1.131097688325772, -2.245130805416057, -1.938873996219074, 2.043608361562645, 00065 -0.865129623056441, -2.655020678073846, 0.600664612949661, 0.080378093886515, -2.899160484012034, 2.563004262857762, 3.078328403304206, 0.505906778385130, 0.048366940168201, -0.545696461188734, -0.023417155362879, 2.127729174988954, -1.176633086028377, 3.690223557991855, -0.622791766173194, 0.722837373872203, 2.739754205367484, -0.062610410524552, -0.891296810967338, -1.845872258871811, 1.195039415434387, -2.177388969045026, 1.078649103637905, 2.570976050490193, -1.383551403404574, 2.392141424058873, 2.858002843205065, -3.682433899725536, -3.488146646451150, 1.323468578888120, -0.099771155430726, 1.561168082500454, 00066 1.025026795103179, 0.928841900171200, 2.930499509864950, 2.013349089766430, 2.381676148486737, -3.081062307950236, -0.389579115537544, 0.581540149166620, -2.601953341353208, 0.333435137781238, -2.812945856162965, 2.649109640172910, -1.003963025744654, 1.552460768755035, 0.088641345335247, -2.519951327113426, -4.341348988610527, 0.557772429359965, -1.671267412948494, 0.733951350960387, 0.409263788034864, 3.566033071952806, 1.882565173848352, -1.106017073793287, 0.554456720778718, -2.513205795512153, 0.310978660939421, 0.579706500111723, 0.000086383683251, -1.311866980897721, 1.840007477574986, -3.253005768451345, 00067 1.462584328739432, 1.610103610851738, 0.761914676858907, 0.974541361089834, 0.686845845885983, 1.849153122025191, 0.787800410401453, -1.187438909666279, -0.754937911044720, 0.084373858395232, -2.600269011710521, -0.962982842142644, -0.369328108540868, 0.810791418361879, 3.587016488699641, -0.520776145083723, 0.640249919627884, 1.103122489464969, 2.231779881455556, -1.308035392685241, 0.424070304330106, -0.200383932651189, -2.365526783356541, -0.989114757436628, 2.770807688959777, -0.444172737462307, 0.079760979374078, -0.005199118412183, -0.664712668309527, -0.624171857561896, 0.537306979007338, -2.575955675497642, 00068 1.562363235756780, 1.814069369848895, -1.293428583392509, -1.026188449495686, -2.981771815588717, -4.223468103075124, 2.672674782004045, -0.856096801117735, 0.048517345512563, -0.026860721136225, 0.392932277758187, -1.331740855093099, -1.894292129477081, -1.425006468460681, -2.721772427617057, -1.616831100216806, 3.551177651488947, -0.069685667896087, -3.134634907409102, -0.263627598944639, -1.650469945991350, -2.203580339374399, -0.872203246123242, 1.230782812607287, 0.257288860093291, 1.989083106173137, -1.985638729453261, -1.416385105842892, -1.131097688325772, -2.245130805416057, -1.938873996219074, 2.043608361562645, 00069 -0.865129623056441, -2.655020678073846, 0.600664612949661, 0.080378093886515, -2.899160484012034, 2.563004262857762, 3.078328403304206, 0.505906778385130, 0.048366940168201, -0.545696461188734, -0.023417155362879, 2.127729174988954, -1.176633086028377, 3.690223557991855, -0.622791766173194, 0.722837373872203, 2.739754205367484, -0.062610410524552, -0.891296810967338, -1.845872258871811, 1.195039415434387, -2.177388969045026, 1.078649103637905, 2.570976050490193, -1.383551403404574, 2.392141424058873, 2.858002843205065, -3.682433899725536, -3.488146646451150, 1.323468578888120, -0.099771155430726, 1.561168082500454, 00070 1.025026795103179, 0.928841900171200, 2.930499509864950, 2.013349089766430, 2.381676148486737, -3.081062307950236, -0.389579115537544, 0.581540149166620, -2.601953341353208, 0.333435137781238, -2.812945856162965, 2.649109640172910, -1.003963025744654, 1.552460768755035, 0.088641345335247, -2.519951327113426, -4.341348988610527, 0.557772429359965, -1.671267412948494, 0.733951350960387, 0.409263788034864, 3.566033071952806, 1.882565173848352, -1.106017073793287, 0.554456720778718, -2.513205795512153, 0.310978660939421, 0.579706500111723, 0.000086383683251, -1.311866980897721, 1.840007477574986, -3.253005768451345, 00071 1.462584328739432, 1.610103610851738, 0.761914676858907, 0.974541361089834, 0.686845845885983, 1.849153122025191, 0.787800410401453, -1.187438909666279, -0.754937911044720, 0.084373858395232, -2.600269011710521, -0.962982842142644, -0.369328108540868, 0.810791418361879, 3.587016488699641, -0.520776145083723, 0.640249919627884, 1.103122489464969, 2.231779881455556, -1.308035392685241, 0.424070304330106, -0.200383932651189, -2.365526783356541, -0.989114757436628, 2.770807688959777, -0.444172737462307, 0.079760979374078, -0.005199118412183, -0.664712668309527, -0.624171857561896, 0.537306979007338, -2.575955675497642, 00072 1.562363235756780, 1.814069369848895, -1.293428583392509, -1.026188449495686, -2.981771815588717, -4.223468103075124, 2.672674782004045, -0.856096801117735, 0.048517345512563, -0.026860721136225, 0.392932277758187, -1.331740855093099, -1.894292129477081, -1.425006468460681, -2.721772427617057, -1.616831100216806, 3.551177651488947, -0.069685667896087, -3.134634907409102, -0.263627598944639, -1.650469945991350, -2.203580339374399, -0.872203246123242, 1.230782812607287, 0.257288860093291, 1.989083106173137, -1.985638729453261, -1.416385105842892, -1.131097688325772, -2.245130805416057, -1.938873996219074, 2.043608361562645, 00073 -0.865129623056441, -2.655020678073846, 0.600664612949661, 0.080378093886515, -2.899160484012034, 2.563004262857762, 3.078328403304206, 0.505906778385130, 0.048366940168201, -0.545696461188734, -0.023417155362879, 2.127729174988954, -1.176633086028377, 3.690223557991855, -0.622791766173194, 0.722837373872203, 2.739754205367484, -0.062610410524552, -0.891296810967338, -1.845872258871811, 1.195039415434387, -2.177388969045026, 1.078649103637905, 2.570976050490193, -1.383551403404574, 2.392141424058873, 2.858002843205065, -3.682433899725536, -3.488146646451150, 1.323468578888120, -0.099771155430726, 1.561168082500454, 00074 1.025026795103179, 0.928841900171200, 2.930499509864950, 2.013349089766430, 2.381676148486737, -3.081062307950236, -0.389579115537544, 0.581540149166620, -2.601953341353208, 0.333435137781238, -2.812945856162965, 2.649109640172910, -1.003963025744654, 1.552460768755035, 0.088641345335247, -2.519951327113426, -4.341348988610527, 0.557772429359965, -1.671267412948494, 0.733951350960387, 0.409263788034864, 3.566033071952806, 1.882565173848352, -1.106017073793287, 0.554456720778718, -2.513205795512153, 0.310978660939421, 0.579706500111723, 0.000086383683251, -1.311866980897721, 1.840007477574986, -3.253005768451345, 00075 1.462584328739432, 1.610103610851738, 0.761914676858907, 0.974541361089834, 0.686845845885983, 1.849153122025191, 0.787800410401453, -1.187438909666279, -0.754937911044720, 0.084373858395232, -2.600269011710521, -0.962982842142644, -0.369328108540868, 0.810791418361879, 3.587016488699641, -0.520776145083723, 0.640249919627884, 1.103122489464969, 2.231779881455556, -1.308035392685241, 0.424070304330106, -0.200383932651189, -2.365526783356541, -0.989114757436628, 2.770807688959777, -0.444172737462307, 0.079760979374078, -0.005199118412183, -0.664712668309527, -0.624171857561896, 0.537306979007338, -2.575955675497642, 1.562363235756780, 1.814069369848895, -1.293428583392509, -1.026188449495686, -2.981771815588717, -4.223468103075124, 2.672674782004045, -0.856096801117735, 0.048517345512563, -0.026860721136225, 0.392932277758187, -1.331740855093099, -1.894292129477081, -1.425006468460681, -2.721772427617057, -1.616831100216806, 3.551177651488947, -0.069685667896087, -3.134634907409102, -0.263627598944639, -1.650469945991350, -2.203580339374399, -0.872203246123242, 1.230782812607287, 0.257288860093291, 1.989083106173137, -1.985638729453261, -1.416385105842892, -1.131097688325772, -2.245130805416057, -1.938873996219074, 2.043608361562645, 00076 }; 00077 const float32_t b[samplenum] = { }; 00078 float32_t a1, b1; 00079 float32_t SubOutMSE, SquareOutMSE, SubOutST, SquareOutST; 00080 int h=0; // 321 h = hr, m = min, for interval 00081 int m=0; 00082 int i=h; 00083 int j=m; 00084 00085 //SPI_TFT_ILI9341 TFT(D11, D12, D13, D10, D8, D9, "TFT"); // mosi, miso, sclk, cs, reset, dc 00086 SPI_TFT_ILI9341 TFT(PC_3, PC_2, PB_10, PB_12, PA_8, PA_11, "TFT"); // mosi, miso, sclk, cs, reset, dc 00087 SDFileSystem sd(PB_5, PB_4, PB_3, PA_10, "sd"); // mosi, miso, sclk, cs 00088 00089 DigitalOut skywire_en(PA_6); 00090 //DigitalOut skywire_rts(PA_7); 00091 Serial skywire(PA_0,PA_1); 00092 00093 volatile int rx_in=0; 00094 volatile int rx_out=0; 00095 const int buffer_size = 255; 00096 char rx_buffer[buffer_size+1]; 00097 char rx_line[buffer_size]; 00098 00099 void read_line() 00100 { 00101 int i; 00102 i = 0; 00103 // Start Critical Section - don't interrupt while changing global buffer variables 00104 __disable_irq(); 00105 // Loop reading rx buffer characters until end of line character 00106 while ((i==0) || ((rx_line[i-1] != '\r') && (rx_line[i-1] != '\n'))) { 00107 // Wait if buffer empty 00108 if (rx_in == rx_out) { 00109 // End Critical Section - need to allow rx interrupt to get new characters for buffer 00110 __enable_irq(); 00111 while (rx_in == rx_out) { 00112 } 00113 // Start Critical Section - don't interrupt while changing global buffer variables 00114 __disable_irq(); 00115 } 00116 rx_line[i] = rx_buffer[rx_out]; 00117 i++; 00118 rx_out = (rx_out + 1) % buffer_size; 00119 } 00120 // End Critical Section 00121 __enable_irq(); 00122 rx_line[i-1] = 0; 00123 return; 00124 } 00125 00126 int WaitForResponse(char* response) 00127 { 00128 do { 00129 do { 00130 read_line(); 00131 } while ((unsigned char)rx_line[0] <= 32); 00132 // debug_pc.printf("Waiting for: %s, Received: %s\r\n", response, rx_line); 00133 } while (strncmp(rx_line, response, strlen(response))); 00134 return 0; 00135 } 00136 00137 void Skywire_Rx_interrupt() 00138 { 00139 // Loop just in case more than one character is in UART's receive FIFO buffer 00140 // Stop if buffer full 00141 while ((skywire.readable()) && (((rx_in + 1) % buffer_size) != rx_out)) { 00142 rx_buffer[rx_in] = skywire.getc(); 00143 rx_in = (rx_in + 1) % buffer_size; 00144 } 00145 return; 00146 } 00147 00148 int main() 00149 { 00150 int stage=0; 00151 int menu=0; 00152 int config=0; 00153 int set=0; 00154 int comp=0; 00155 float32_t stmean=0; 00156 float32_t stmse=0; 00157 float32_t stst=0; 00158 char log[10][32]; 00159 float32_t mselog[10] = {NULL}; 00160 // set_time(1448935737); // Set RTC time to Dec 01 2015 02:09 AM 00161 int pu, pd, ps; // LL left & right 00162 TFT.claim(stdout); // send stdout to the TFT display 00163 TFT.claim(stderr); // send stderr to the TFT display 00164 TFT.set_orientation(2); 00165 TFT.background(Black); // set background to black 00166 TFT.foreground(White); // set chars to white 00167 TFT.cls(); // clear the screen 00168 00169 00170 while(1) 00171 { 00172 if (stage==0) { //menu 00173 TFT.set_font((unsigned char*) Arial24x23); 00174 TFT.locate(19,60); 00175 TFT.foreground(White); 00176 printf("Configuration"); 00177 TFT.locate(50,110); 00178 TFT.printf("Waveform"); 00179 TFT.locate(95,160); 00180 TFT.printf("Log"); 00181 // wait_LowPow(3); // Wait 3s in low power mode, seems just hold display 00182 if (set==0) { 00183 TFT.locate(70,260); 00184 TFT.foreground(DarkGrey); 00185 printf("START"); 00186 } 00187 if (set==1) { 00188 TFT.locate(70,260); 00189 TFT.foreground(White); 00190 printf("START"); 00191 TFT.set_font((unsigned char*) Arial12x12); 00192 TFT.locate(30, 240); 00193 printf("interval: %i hr %i min", h, m); 00194 } 00195 00196 if (menu==0) { //Configuration 00197 TFT.rect(13,55,225,85,Green); 00198 TFT.rect(13,105,225,135,Black); 00199 pu = ain1.read(); 00200 pd = ain2.read(); 00201 ps = ain3.read(); 00202 if (pd==1) { wait(0.3); menu=1; } 00203 if (ps==1) { wait(0.3); TFT.cls(); stage=1; } 00204 } 00205 00206 if (menu==1) { //waveform 00207 TFT.rect(13,55,225,85,Black); 00208 TFT.rect(13,105,225,135,Green); 00209 TFT.rect(13,155,225,185,Black); 00210 pu = ain1.read(); 00211 pd = ain2.read(); 00212 ps = ain3.read(); 00213 if (pu==1) { wait(0.3); menu=0; } 00214 if (pd==1) { wait(0.3); menu=2; } 00215 if (ps==1) { wait(0.3); TFT.cls(); stage=2; } 00216 } 00217 00218 if (menu==2) { //log 00219 TFT.rect(13,105,225,135,Black); 00220 TFT.rect(13,155,225,185,Green); 00221 TFT.rect(13,255,225,285,Black); 00222 pu = ain1.read(); 00223 pd = ain2.read(); 00224 ps = ain3.read(); 00225 if (pu==1) { wait(0.3); menu=1; } 00226 if ((pd==1)&&(set==1)) { wait(0.3); menu=3; } 00227 if (ps==1) { wait(0.3); TFT.cls(); stage=3; } 00228 } 00229 00230 if (menu==3) { //START 00231 TFT.rect(13,155,225,185,Black); 00232 TFT.rect(13,255,225,285,Green); 00233 pu = ain1.read(); 00234 pd = ain2.read(); 00235 ps = ain3.read(); 00236 if (pu==1) { wait(0.3); menu=2; } 00237 if (ps==1) { wait(0.3); TFT.cls(); stage=5; } 00238 } 00239 } 00240 00241 if (stage==1) { //Configuration 00242 int ia, ib, ja, jb; 00243 00244 TFT.set_font((unsigned char*) Arial24x23); 00245 TFT.locate(20,55); 00246 TFT.foreground(White); 00247 printf("SET PERIOD"); 00248 TFT.rect(15,50, 220,80,Red); 00249 TFT.locate(70,120); 00250 TFT.printf("Hr Min"); 00251 TFT.locate(10,200); 00252 printf("Record Control"); 00253 TFT.set_font((unsigned char*) Arial12x12); 00254 if (comp==1) { 00255 TFT.locate(50,233); 00256 printf("comparison saved"); 00257 } 00258 00259 TFT.set_font((unsigned char*) Arial12x12); 00260 TFT.locate(40,300); 00261 printf("Set"); 00262 TFT.locate(165,300); 00263 printf("Return"); 00264 TFT.rect(22,115, 68,145,Olive); 00265 TFT.rect(117,115,163,145,Olive); 00266 TFT.rect(5,195, 230,225,Olive); 00267 TFT.rect(15,295,85,315,Olive); 00268 TFT.rect(150,295,220,315,Olive); 00269 00270 while (stage==1) { 00271 ia=i-1; if (i==0) ia=23; 00272 ib=i+1; if (i==23) ib=0; 00273 ja=j-1; if (j==0) ja=59; 00274 jb=j+1; if (j==59) jb=00; 00275 00276 TFT.set_font((unsigned char*) Arial24x23); 00277 TFT.locate(26,120); 00278 if (i<10) TFT.printf("0%i", i); 00279 else if (i>=10) TFT.printf("%i", i); 00280 TFT.locate(120,120); 00281 if (j<10) TFT.printf("0%i", j); 00282 else if (j>=10) TFT.printf("%i", j); 00283 00284 TFT.set_font((unsigned char*) Arial12x12); 00285 TFT.locate(40,100); 00286 if (ia<10) TFT.printf("0%i", ia); 00287 else if (ia>=10) TFT.printf("%i", ia); 00288 TFT.locate(40,150); 00289 if (ib<10) TFT.printf("0%i", ib); 00290 else if (ib>=10) TFT.printf("%i", ib); 00291 TFT.locate(135,100); 00292 if (ja<10) TFT.printf("0%i", ja); 00293 else if (ja>=10) TFT.printf("%i", ja); 00294 TFT.locate(135,150); 00295 if (jb<10) TFT.printf("0%i", jb); 00296 else if (jb>=10) TFT.printf("%i", jb); 00297 00298 if (config==0) { //hour 00299 TFT.rect(22,115, 68,145,Green); 00300 TFT.rect(117,115,163,145,Olive); 00301 TFT.rect(5,195, 230,225,Olive); 00302 pu = ain1.read(); 00303 pd = ain2.read(); 00304 ps = ain3.read(); 00305 if (pu==1) { wait(0.3); i=ib; } 00306 if (pd==1) { wait(0.3); i=ia; } 00307 if (ps==1) { wait(0.3); config=1; } 00308 } 00309 if (config==1) { //min 00310 TFT.rect(22,115, 68,145,Olive); 00311 TFT.rect(117,115,163,145,Green); 00312 TFT.rect(5,195, 230,225,Olive); 00313 pu = ain1.read(); 00314 pd = ain2.read(); 00315 ps = ain3.read(); 00316 if (pu==1) { wait(0.3); j=jb; } 00317 if (pd==1) { wait(0.3); j=ja; } 00318 if (ps==1) { wait(0.3); config=2; } 00319 } 00320 if (config==2) { //Record Control 00321 TFT.rect(22,115, 68,145,Olive); 00322 TFT.rect(117,115,163,145,Olive); 00323 TFT.rect(5,195, 230,225,Green); 00324 TFT.rect(15,295,85,315,Olive); 00325 TFT.rect(150,295,220,315,Olive); 00326 pu = ain1.read(); 00327 pd = ain2.read(); 00328 ps = ain3.read(); 00329 if (pu==1) { wait(0.3); config=0; } 00330 if (pd==1) { wait(0.3); config=3; } 00331 if (ps==1) { wait(0.3); TFT.cls(); stage=4; } 00332 } 00333 if (config==3) { //set 00334 TFT.rect(5,195, 230,225,Olive); 00335 TFT.rect(15,295,85,315,Green); 00336 TFT.rect(150,295,220,315,Olive); 00337 pu = ain1.read(); 00338 pd = ain2.read(); 00339 ps = ain3.read(); 00340 if (pu==1) { wait(0.3); config=2; } 00341 if (pd==1) { wait(0.3); config=4; } 00342 if (ps==1) { wait(0.3); TFT.cls(); 00343 if ((i!=0) || (j!=0)) 00344 { h=i; m=j; set=1; } 00345 stage=0; 00346 } 00347 } 00348 if (config==4) { //return 00349 TFT.rect(5,195, 230,225,Olive); 00350 TFT.rect(15,295,85,315,Olive); 00351 TFT.rect(150,295,220,315,Green); 00352 pu = ain1.read(); 00353 pd = ain2.read(); 00354 ps = ain3.read(); 00355 if (pu==1) { wait(0.3); config=3; } 00356 if (pd==1) { wait(0.3); config=4; } 00357 if (ps==1) { wait(0.3); TFT.cls(); stage=0; } 00358 } 00359 } 00360 } 00361 00362 00363 if (stage==2) { //waveform 00364 int abc, x2, y2; 00365 int x1 = 0; 00366 int y1 = 80; 00367 00368 for(abc=0; abc<samplenum; abc=abc+1) // waveform 00369 { a1 = a[abc]; 00370 x2 = abc*2; 00371 y2 = 80+a1*10; 00372 TFT.line(x1,y1,x2,y2,Green); 00373 x1 = x2; y1 = y2; 00374 } 00375 00376 TFT.set_font((unsigned char*) Arial12x12); 00377 TFT.foreground(White); 00378 TFT.locate(10,130); 00379 TFT.printf("Samples number: \n %i", samplenum); 00380 TFT.locate(10,160); 00381 TFT.printf("Sample Mean Value: \n %f", stmean); 00382 TFT.locate(10,190); 00383 TFT.printf("Standard Deviation: \n %f", stst); 00384 TFT.locate(10,220); 00385 TFT.printf("Mean Square Error: \n %f", stmse); 00386 00387 TFT.locate(165,270); 00388 printf("Return"); 00389 TFT.rect(150,265,220,285,Green); 00390 ps = ain3.read(); 00391 if (ps==1) { wait(0.3); TFT.cls(); stage=0; } 00392 } 00393 00394 if (stage==3) { //log 00395 TFT.set_font((unsigned char*) Arial12x12); 00396 TFT.locate(0,10); 00397 TFT.foreground(White); 00398 00399 00400 //Configure CRC, large frames, and write validation for SD Card 00401 sd.crc(true); 00402 sd.large_frames(true); 00403 sd.write_validation(true); 00404 00405 //Try to mount the SD card 00406 int row = 50; 00407 TFT.locate(10,row); TFT.printf("Mounting SD card..."); row+=10; 00408 if (sd.mount() != 0) { 00409 TFT.locate(10,row); TFT.printf("failed!"); row+=10; 00410 } else { 00411 TFT.locate(10,row); TFT.printf("mounted successfully"); row+=10; 00412 00413 // write event to log 00414 TFT.locate(10,70); 00415 FILE *fp = fopen("/sd/event_log.txt", "a"); 00416 if (fp != NULL) { 00417 fprintf(fp, "eureka!\r\n"); 00418 fclose(fp); 00419 TFT.locate(10,row); TFT.printf("success"); row+=10; 00420 } else { 00421 TFT.locate(10,row); TFT.printf("failed to write"); row+=10; 00422 } 00423 sd.unmount(); 00424 } 00425 00426 TFT.locate(10,row); TFT.printf("Configuring Skywire"); row+=10; 00427 skywire.baud(115200); 00428 skywire.attach(&Skywire_Rx_interrupt, Serial::RxIrq); 00429 00430 //Turn off echo 00431 skywire.printf("ATE0\r\n"); 00432 WaitForResponse("OK"); 00433 TFT.locate(10,row); TFT.printf("Connecting to the Network"); row+=10; 00434 // get IP address 00435 skywire.printf("AT#SGACT=1,1\r\n"); // context activation (returns with IP address) 00436 WaitForResponse("#SGACT"); 00437 WaitForResponse("OK"); 00438 TFT.locate(10,row); TFT.printf("Connected to the Network"); row+=10; 00439 00440 /* float32_t m[6] = { 6.025026, 9.928841, 8.930499, 7.013349, 6.081062, 5.389579}; 00441 int k; 00442 int l[6] = { 1448934757, 1448935757, 1448935837, 1448938857, 1448940757, 1448945757}; 00443 00444 for (k=0; k<6; k++) 00445 { set_time(l[k]); 00446 time_t seconds = time(NULL); 00447 strftime(log[k], 32, "%b %d %Y %I:%M %p\n", localtime(&seconds)); 00448 TFT.printf("%s MSE: %f\n\n", log[k], m[k]); 00449 }*/ 00450 00451 TFT.locate(165,270); 00452 printf("Return"); 00453 TFT.rect(150,265,220,285,Green); 00454 while(1) 00455 { ps = ain3.read(); 00456 if (ps==1) { wait(0.3); TFT.cls(); stage=0; break; } 00457 } 00458 } 00459 00460 if (stage==4) //recording... for comparison 00461 { TFT.set_font((unsigned char*) Arial24x23); 00462 TFT.foreground(White); 00463 TFT.locate(40, 240); 00464 printf(" recording\n comparison..."); 00465 TFT.set_font((unsigned char*) Arial12x12); 00466 //DFSDM CORE 00467 pc.printf("\r\n\r\nEntering AudioRecord_demo()...\r\n"); 00468 RECORD(); // RECORD CONTROL 0 00469 uint32_t n; 00470 for(n=0;n<1024;n++) 00471 {CONTROLPWR[n]=POWER[n];} 00472 for(n=0;n<1024;n++) 00473 {CONTROLPHS[n]=PHS[n];} 00474 RECORD(); //RECORD CONTROL 1 00475 MSE(); //MSE BETWEEN CONTROLS 00476 CONTROLPWRMSE=PWRMSE; 00477 CONTROLPHSMSE=PHSMSE; 00478 // 00479 TFT.cls(); 00480 comp=1; 00481 menu=0; 00482 config=2; 00483 stage=1; 00484 } 00485 00486 if (stage==5) //recording... with interval 00487 { int t = 4*(h*60+m); 00488 int t1, abc; 00489 float32_t sum, sum_mse, sum_st; 00490 TFT.set_font((unsigned char*) Arial24x23); 00491 TFT.locate(20,60); 00492 TFT.foreground(DarkGrey); 00493 printf("Configuration"); 00494 TFT.locate(50,110); 00495 TFT.printf("Waveform"); 00496 TFT.locate(95,160); 00497 TFT.printf("Log"); 00498 TFT.set_font((unsigned char*) Arial12x12); 00499 TFT.foreground(White); 00500 TFT.locate(30, 240); 00501 printf("recording, are you sure?"); 00502 TFT.set_font((unsigned char*) Arial24x23); 00503 TFT.locate(35,260); 00504 printf(" STOP "); 00505 TFT.rect(13,255,225,285,Green); 00506 00507 while (stage==5) 00508 { sum=0; sum_mse=0; sum_st=0; t1=0; 00509 00510 RECORD(); 00511 MSE(); 00512 COMPARE(); 00513 00514 for(abc=0; abc<samplenum; abc++) 00515 { a1 = a[abc]; b1 = b[abc]; sum = sum+a[abc]; 00516 arm_sub_f32(&a1, &stmean, &SubOutST, 1); 00517 arm_mult_f32(&SubOutST, &SubOutST, &SquareOutST, 1); 00518 sum_st = sum_st+SquareOutST; 00519 arm_sub_f32(&a1, &b1, &SubOutMSE, 1); 00520 arm_mult_f32(&SubOutMSE, &SubOutMSE, &SquareOutMSE, 1); 00521 sum_mse = sum_mse+SquareOutMSE; 00522 } 00523 stmean = sum/samplenum; 00524 stst = sqrt(sum_st/samplenum); 00525 stmse = sum_mse/samplenum; 00526 00527 // if (stmse>0) // if error, send to user, and store MSE to log 00528 // { if (mselog[0]==NULL) 00529 // { time_t seconds = time(NULL); 00530 // strftime(log[0], 32, "%b %d %Y %I:%M %p\n", localtime(&seconds)); 00531 // mselog[0] = stmse; 00532 // } 00533 // } 00534 00535 while(t1<t) 00536 { ps = ain3.read(); 00537 if (ps==0) { t1++; wait(0.2); } 00538 else if (ps==1) { wait(0.3); TFT.cls(); stage=0; break; } 00539 } 00540 } 00541 } 00542 } 00543 } 00544
Generated on Tue Jul 12 2022 15:34:17 by 1.7.2