5959/* Try to detect nrfx version if not configured with CFG_TUD_NRF_NRFX_VERSION
6060 * nrfx v1 and v2 are concurrently developed. There is no NRFX_VERSION only MDK VERSION which is as follows:
6161 * - v3.0.0: 8.53.1 (conflict with v2.11.0), v3.1.0: 8.55.0 ...
62- * - v2.11.0: 8.53.1, v2.6.0: 8.44.1, v2.5.0: 8.40.2, v2.4.0: 8.37.0, v2.3.0: 8.35.0, v2.2.0: 8.32.1, v2.1.0: 8.30.2, v2.0.0: 8.29.0
62+ * - v2.11.0: 8.53.1, v2.6.0: 8.44.1, v2.5.0: 8.40.2, v2.4.0: 8.37.0, v2.3.0: 8.35.0, v2.2.0: 8.32.1, v2.1.0: 8.30.2,
63+ * v2.0.0: 8.29.0
6364 * - v1.9.0: 8.40.3, v1.8.6: 8.35.0 (conflict with v2.3.0), v1.8.5: 8.32.3, v1.8.4: 8.32.1 (conflict with v2.2.0),
6465 * v1.8.2: 8.32.1 (conflict with v2.2.0), v1.8.1: 8.27.1
6566 * Therefore the check for v1 would be:
6667 * - MDK < 8.29.0 (v2.0), MDK == 8.32.3, 8.40.3
6768 * - in case of conflict User of those version must upgrade to other 1.x version or set CFG_TUD_NRF_NRFX_VERSION
68- */
69+ */
6970#ifndef CFG_TUD_NRF_NRFX_VERSION
70- #define _MDK_VERSION (10000* MDK_MAJOR_VERSION + 100* MDK_MINOR_VERSION + MDK_MICRO_VERSION)
71+ #define MDK_VERSION (10000 * MDK_MAJOR_VERSION + 100 * MDK_MINOR_VERSION + MDK_MICRO_VERSION)
7172
72- #if _MDK_VERSION < 82900 || _MDK_VERSION == 83203 || _MDK_VERSION == 84003
73+ #if MDK_VERSION < 82900 || MDK_VERSION == 83203 || MDK_VERSION == 84003
7374 // nrfx <= 1.8.1, or 1.8.5 or 1.9.0
7475 #define CFG_TUD_NRF_NRFX_VERSION 1
75- #else
76+ #elif MDK_VERSION < 85301
7677 #define CFG_TUD_NRF_NRFX_VERSION 2
78+ #elif MDK_VERSION < 87300
79+ #define CFG_TUD_NRF_NRFX_VERSION 3
80+ #else
81+ #define CFG_TUD_NRF_NRFX_VERSION 4
7782 #endif
7883#endif
7984
@@ -845,19 +850,19 @@ TU_ATTR_ALWAYS_INLINE static inline bool is_sd_enabled(void) {
845850#endif
846851
847852static bool hfclk_running (void ) {
848- #ifdef SOFTDEVICE_PRESENT
849- if ( is_sd_enabled () ) {
853+ #ifdef SOFTDEVICE_PRESENT
854+ if (is_sd_enabled ()) {
850855 uint32_t is_running = 0 ;
851- (void ) sd_clock_hfclk_is_running (& is_running );
856+ (void )sd_clock_hfclk_is_running (& is_running );
852857 return (is_running ? true : false);
853858 }
854- #endif
859+ #endif
855860
856- #if CFG_TUD_NRF_NRFX_VERSION == 1
861+ #if CFG_TUD_NRF_NRFX_VERSION == 1
857862 return nrf_clock_hf_is_running (NRF_CLOCK_HFCLK_HIGH_ACCURACY );
858- #else
859- return nrf_clock_hf_is_running (NRF_CLOCK , NRF_CLOCK_HFCLK_HIGH_ACCURACY );
860- #endif
863+ #else
864+ return nrf_clock_is_running (NRF_CLOCK , NRF_CLOCK_DOMAIN_HFCLK , NULL );
865+ #endif
861866}
862867
863868static void hfclk_enable (void ) {
@@ -867,22 +872,24 @@ static void hfclk_enable(void) {
867872#else
868873
869874 // already running, nothing to do
870- if (hfclk_running ()) return ;
875+ if (hfclk_running ()) {
876+ return ;
877+ }
871878
872- #ifdef SOFTDEVICE_PRESENT
873- if ( is_sd_enabled () ) {
879+ #ifdef SOFTDEVICE_PRESENT
880+ if (is_sd_enabled ()) {
874881 (void )sd_clock_hfclk_request ();
875882 return ;
876883 }
877- #endif
884+ #endif
878885
879- #if CFG_TUD_NRF_NRFX_VERSION == 1
886+ #if CFG_TUD_NRF_NRFX_VERSION == 1
880887 nrf_clock_event_clear (NRF_CLOCK_EVENT_HFCLKSTARTED );
881888 nrf_clock_task_trigger (NRF_CLOCK_TASK_HFCLKSTART );
882- #else
889+ #else
883890 nrf_clock_event_clear (NRF_CLOCK , NRF_CLOCK_EVENT_HFCLKSTARTED );
884891 nrf_clock_task_trigger (NRF_CLOCK , NRF_CLOCK_TASK_HFCLKSTART );
885- #endif
892+ #endif
886893#endif
887894}
888895
0 commit comments