@@ -270,8 +270,14 @@ static bool gpio_init(void)
270270 err_code = nrf_drv_gpiote_init ();
271271 APP_ERROR_CHECK (err_code );
272272
273+ #ifdef MOTOR_TSDZ2
273274 bootloader_pin_pressed = check_pin_and_enable_interrupt (PLUS__PIN );
274275 bootloader_pin_pressed |= check_pin_and_enable_interrupt (MINUS__PIN );
276+ #elif defined(MOTOR_BAFANG )
277+ bootloader_pin_pressed = check_pin_and_enable_interrupt (PLUS__PIN );
278+ #else
279+ #error MOTOR_TSDZ2 or MOTOR_BAFANG must be defined
280+ #endif
275281
276282 return bootloader_pin_pressed ;
277283}
@@ -280,8 +286,12 @@ static void rtc_handler(nrf_drv_rtc_int_type_t int_type)
280286{
281287 if (int_type == NRF_DRV_RTC_INT_COMPARE0 )
282288 {
289+ #ifdef MOTOR_TSDZ2
283290 if ((read_pin (PLUS__PIN ) == 0 ) &&
284291 (read_pin (MINUS__PIN ) == 0 ))
292+ #elif defined(MOTOR_BAFANG )
293+ if (read_pin (PLUS__PIN ) == 0 )
294+ #endif
285295 {
286296 g_start_bootloader = true;
287297 }
@@ -308,7 +318,12 @@ static void rtc_config(void)
308318 APP_ERROR_CHECK (err_code );
309319
310320 //Set compare channel to trigger interrupt after COMPARE_COUNTERTIME seconds
321+ #ifdef MOTOR_TSDZ2
311322 err_code = nrf_drv_rtc_cc_set (& rtc , 0 , 10 * 8 , true);
323+ #elif defined(MOTOR_BAFANG )
324+ err_code = nrf_drv_rtc_cc_set (& rtc , 0 , 10 * 3 , true);
325+ #endif
326+
312327 APP_ERROR_CHECK (err_code );
313328
314329 //Power on RTC instance
@@ -363,10 +378,15 @@ int main(void)
363378 lfclk_config ();
364379
365380 // disable buttons
381+ #ifdef MOTOR_TSDZ2
366382 nrf_drv_gpiote_in_uninit (PLUS__PIN );
367383 nrf_drv_gpiote_in_event_disable (PLUS__PIN );
368384 nrf_drv_gpiote_in_uninit (MINUS__PIN );
369385 nrf_drv_gpiote_in_event_disable (MINUS__PIN );
386+ #elif defined(MOTOR_BAFANG )
387+ nrf_drv_gpiote_in_uninit (PLUS__PIN );
388+ nrf_drv_gpiote_in_event_disable (PLUS__PIN );
389+ #endif
370390
371391 // RTC uninit because it will be used by the softdevice
372392 rtc_uninit ();
0 commit comments