@@ -7,6 +7,9 @@ char family[32] = {0};
77hal_platform plat = HAL_PLATFORM_UNK ;
88int series = 0 ;
99
10+ unsigned long long lastMillisTemp = 0 ;
11+ float lastReadTemp = 0.0 / 0.0 ;
12+
1013void hal_identify (void ) {
1114 unsigned int val = 0 ;
1215 FILE * file ;
@@ -96,7 +99,7 @@ void hal_identify(void) {
9699 }
97100#endif
98101
99- #if defined(__ARM_PCS )
102+ #if defined(__arm__ ) && !defined( __ARM_PCS_VFP )
100103 if (file = fopen ("/proc/iomem" , "r" )) {
101104 while (fgets (line , 200 , file ))
102105 if (strstr (line , "uart" )) {
@@ -181,4 +184,47 @@ void hal_identify(void) {
181184 strcpy (family , "hisi-gen4" );
182185 chnCount = V4_VENC_CHN_NUM ;
183186#endif
187+ }
188+
189+ float hal_temperature_read (void ) {
190+ if (lastReadTemp != (0.0 / 0.0 ) && (millis () - lastMillisTemp < 5000 ))
191+ return lastReadTemp ;
192+
193+ lastMillisTemp = millis ();
194+
195+ switch (plat ) {
196+ #if defined(__ARM_PCS_VFP )
197+ case HAL_PLATFORM_I6 :
198+ case HAL_PLATFORM_I6C :
199+ case HAL_PLATFORM_M6 :
200+ {
201+ FILE * file ;
202+ char line [20 ] = {0 };
203+ if (file = fopen ("/sys/class/mstar/msys/TEMP_R" , "r" )) {
204+ fgets (line , 20 , file );
205+ char * remain , * parsed = strstr (line , "Temperature " );
206+ lastReadTemp = strtof (parsed + 12 , & remain );
207+ fclose (file );
208+ }
209+ break ;
210+ }
211+ #elif defined(__arm__ ) && !defined(__ARM_PCS_VFP )
212+ case HAL_PLATFORM_V2 : lastReadTemp = v2_system_readtemp (); break ;
213+ case HAL_PLATFORM_V3 : lastReadTemp = v3_system_readtemp (); break ;
214+ case HAL_PLATFORM_V4 : lastReadTemp = v4_system_readtemp (); break ;
215+ #endif
216+ default :
217+ if (!access ("/sys/class/thermal/thermal_zone0/temp" , F_OK )) {
218+ FILE * file ;
219+ char line [10 ] = {0 };
220+ if (file = fopen ("/sys/class/thermal/thermal_zone0/temp" , "r" )) {
221+ fgets (line , 10 , file );
222+ lastReadTemp = strtof (line , NULL ) / 1000.0 ;
223+ fclose (file );
224+ }
225+ } else lastMillisTemp = UINT64_MAX ;
226+ break ;
227+ }
228+
229+ return lastReadTemp ;
184230}
0 commit comments