@@ -46,6 +46,24 @@ static const struct pin_index pins[] =
4646 __NRF5X_PIN (29 , 0 , 29 ),
4747 __NRF5X_PIN (30 , 0 , 30 ),
4848 __NRF5X_PIN (31 , 0 , 31 ),
49+ #ifdef SOC_NRF52840
50+ __NRF5X_PIN (32 , 1 , 0 ),
51+ __NRF5X_PIN (33 , 1 , 1 ),
52+ __NRF5X_PIN (34 , 1 , 2 ),
53+ __NRF5X_PIN (35 , 1 , 3 ),
54+ __NRF5X_PIN (36 , 1 , 4 ),
55+ __NRF5X_PIN (37 , 1 , 5 ),
56+ __NRF5X_PIN (38 , 1 , 6 ),
57+ __NRF5X_PIN (39 , 1 , 7 ),
58+ __NRF5X_PIN (40 , 1 , 8 ),
59+ __NRF5X_PIN (41 , 1 , 9 ),
60+ __NRF5X_PIN (42 , 1 , 10 ),
61+ __NRF5X_PIN (43 , 1 , 11 ),
62+ __NRF5X_PIN (44 , 1 , 12 ),
63+ __NRF5X_PIN (45 , 1 , 13 ),
64+ __NRF5X_PIN (46 , 1 , 14 ),
65+ __NRF5X_PIN (47 , 1 , 15 ),
66+ #endif /* SOC_NRF52840 */
4967};
5068
5169/* EVENTS_IN[n](n=0..7) and EVENTS_PORT */
@@ -356,4 +374,105 @@ int rt_hw_pin_init(void)
356374
357375}
358376INIT_BOARD_EXPORT (rt_hw_pin_init );
377+
378+ /* test GPIO write, read, input interrupt */
379+ #define DK_BOARD_LED_1 13
380+ #define DK_BOARD_LED_2 14
381+ #define DK_BOARD_LED_3 15
382+ #define DK_BOARD_LED_4 16
383+
384+ #define DK_BOARD_BUTTON_1 11
385+ #define DK_BOARD_BUTTON_2 12
386+ #define DK_BOARD_BUTTON_3 24
387+ #define DK_BOARD_BUTTON_4 25
388+
389+ void button_1_callback (void * args )
390+ {
391+ static int flag1 = 0 ;
392+ if (flag1 == 0 )
393+ {
394+ flag1 = 1 ;
395+ rt_pin_write (DK_BOARD_LED_1 , PIN_LOW );
396+ }
397+ else
398+ {
399+ flag1 = 0 ;
400+ rt_pin_write (DK_BOARD_LED_1 , PIN_HIGH );
401+ }
402+ }
403+ void button_2_callback (void * args )
404+ {
405+ static int flag2 = 0 ;
406+ if (flag2 == 0 )
407+ {
408+ flag2 = 1 ;
409+ rt_pin_write (DK_BOARD_LED_2 , PIN_LOW );
410+ }
411+ else
412+ {
413+ flag2 = 0 ;
414+ rt_pin_write (DK_BOARD_LED_2 , PIN_HIGH );
415+ }
416+ }
417+ void button_3_callback (void * args )
418+ {
419+ static int flag3 = 0 ;
420+ if (flag3 == 0 )
421+ {
422+ flag3 = 1 ;
423+ rt_pin_write (DK_BOARD_LED_3 , PIN_LOW );
424+ }
425+ else
426+ {
427+ flag3 = 0 ;
428+ rt_pin_write (DK_BOARD_LED_3 , PIN_HIGH );
429+ }
430+ }
431+ void button_4_callback (void * args )
432+ {
433+ static int flag4 = 0 ;
434+ if (flag4 == 0 )
435+ {
436+ flag4 = 1 ;
437+ rt_pin_write (DK_BOARD_LED_4 , PIN_LOW );
438+ }
439+ else
440+ {
441+ flag4 = 0 ;
442+ rt_pin_write (DK_BOARD_LED_4 , PIN_HIGH );
443+ }
444+ }
445+
446+ void gpio_sample (void )
447+ {
448+ rt_err_t err_code ;
449+
450+ rt_pin_mode (DK_BOARD_LED_1 , PIN_MODE_OUTPUT );
451+ rt_pin_mode (DK_BOARD_LED_2 , PIN_MODE_OUTPUT );
452+ rt_pin_mode (DK_BOARD_LED_3 , PIN_MODE_OUTPUT );
453+ rt_pin_mode (DK_BOARD_LED_4 , PIN_MODE_OUTPUT );
454+
455+ rt_pin_write (DK_BOARD_LED_1 , PIN_HIGH );
456+ rt_pin_write (DK_BOARD_LED_2 , PIN_HIGH );
457+ rt_pin_write (DK_BOARD_LED_3 , PIN_HIGH );
458+ rt_pin_write (DK_BOARD_LED_4 , PIN_HIGH );
459+
460+ err_code = rt_pin_attach_irq (DK_BOARD_BUTTON_1 , PIN_IRQ_MODE_FALLING ,
461+ button_1_callback , (void * ) true); //true: hi_accuracy(IN_EVENT),false: lo_accuracy(PORT_EVENT)
462+ rt_pin_irq_enable (DK_BOARD_BUTTON_1 , PIN_IRQ_ENABLE );
463+
464+ err_code = rt_pin_attach_irq (DK_BOARD_BUTTON_2 , PIN_IRQ_MODE_FALLING ,
465+ button_2_callback , (void * ) true); //true: hi_accuracy(IN_EVENT),false: lo_accuracy(PORT_EVENT)
466+ rt_pin_irq_enable (DK_BOARD_BUTTON_2 , PIN_IRQ_ENABLE );
467+
468+ err_code = rt_pin_attach_irq (DK_BOARD_BUTTON_3 , PIN_IRQ_MODE_FALLING ,
469+ button_3_callback , (void * ) true); //true: hi_accuracy(IN_EVENT),false: lo_accuracy(PORT_EVENT)
470+ rt_pin_irq_enable (DK_BOARD_BUTTON_3 , PIN_IRQ_ENABLE );
471+
472+ err_code = rt_pin_attach_irq (DK_BOARD_BUTTON_4 , PIN_IRQ_MODE_FALLING ,
473+ button_4_callback , (void * ) false); //true: hi_accuracy(IN_EVENT),false: lo_accuracy(PORT_EVENT)
474+ rt_pin_irq_enable (DK_BOARD_BUTTON_4 , PIN_IRQ_ENABLE );
475+ }
476+ MSH_CMD_EXPORT (gpio_sample , gpio sample );
477+
359478#endif /* RT_USING_PIN */
0 commit comments