@@ -147,22 +147,6 @@ void systemOff(uint32_t pin, uint8_t wake_logic)
147147
148148float readCPUTemperature ()
149149{
150- // These are defined simply to make the ensuing code easier to read. Ready and triggers are 0x01, and not ready is 0x00.
151- // Many other library functions use a literal 0x00 to reset flags and a literal 0x01 for triggers, and test "done"
152- // flags for nonzero. In this function, we used the defined constants. Using 0x00 and 0x01 would probably be fine
153- // because they're unlikely to ever change.
154- const uint32_t temp_ready = ( (TEMP_EVENTS_DATARDY_EVENTS_DATARDY_Generated << TEMP_EVENTS_DATARDY_EVENTS_DATARDY_Pos )
155- && TEMP_EVENTS_DATARDY_EVENTS_DATARDY_Msk );
156-
157- const uint32_t temp_not_ready = ( (TEMP_EVENTS_DATARDY_EVENTS_DATARDY_NotGenerated << TEMP_EVENTS_DATARDY_EVENTS_DATARDY_Pos )
158- && TEMP_EVENTS_DATARDY_EVENTS_DATARDY_Msk );
159-
160- const uint32_t temp_trigger = ( (TEMP_TASKS_START_TASKS_START_Trigger << TEMP_TASKS_STOP_TASKS_STOP_Pos )
161- && TEMP_TASKS_START_TASKS_START_Msk );
162-
163- const uint32_t temp_stop = ( (TEMP_TASKS_STOP_TASKS_STOP_Trigger << TEMP_TASKS_STOP_TASKS_STOP_Pos )
164- && TEMP_TASKS_STOP_TASKS_STOP_Msk );
165-
166150 uint8_t en ;
167151 int32_t temp ;
168152 (void ) sd_softdevice_is_enabled (& en );
@@ -172,15 +156,14 @@ float readCPUTemperature()
172156 }
173157 else
174158 {
175- NRF_TEMP -> EVENTS_DATARDY = temp_not_ready ; // Only needed in case another function is also looking at this event flag
176- NRF_TEMP -> TASKS_START = temp_trigger ;
159+ NRF_TEMP -> EVENTS_DATARDY = 0x00 ; // Only needed in case another function is also looking at this event flag
160+ NRF_TEMP -> TASKS_START = 0x01 ;
177161
178- bool done = false;
179- while (NRF_TEMP -> EVENTS_DATARDY != temp_ready );
162+ while (!NRF_TEMP -> EVENTS_DATARDY );
180163 temp = NRF_TEMP -> TEMP ; // Per anomaly 29 (unclear whether still applicable), TASKS_STOP will clear the TEMP register.
181164
182- NRF_TEMP -> TASKS_STOP = temp_stop ; // Per anomaly 30 (unclear whether still applicable), the temp peripheral needs to be shut down
183- NRF_TEMP -> EVENTS_DATARDY = temp_not_ready ;
165+ NRF_TEMP -> TASKS_STOP = 0x01 ; // Per anomaly 30 (unclear whether still applicable), the temp peripheral needs to be shut down
166+ NRF_TEMP -> EVENTS_DATARDY = 0x00 ;
184167 }
185168 return temp / 4.0F ;
186169}
0 commit comments