@@ -653,28 +653,27 @@ void export_gpio(int ch, int ot, int invert, int direction)
653
653
}
654
654
655
655
#if defined(USE_GPIOD )
656
- int gpiod_probe (const char * chip_name , int line_number )
657
- {
658
- struct gpiod_chip * chip ;
659
- chip = gpiod_chip_open_by_name (chip_name );
660
- if (chip == NULL ) {
661
- text_color_set (DW_COLOR_ERROR );
662
- dw_printf ("Can't open GPIOD chip %s.\n" , chip_name );
663
- return -1 ;
664
- }
665
656
666
- struct gpiod_line * line ;
667
- line = gpiod_chip_get_line (chip , line_number );
668
- if (line == NULL ) {
657
+ int gpiod_set (struct gpiod_line * line , int ptt ){
658
+ int rc = 0 ;
659
+ bool owner = gpiod_line_is_requested (line );
660
+ if (owner ){
661
+ int rc2 = gpiod_line_set_value (line , ptt );
662
+ if (rc2 != 0 ) {
663
+ text_color_set (DW_COLOR_ERROR );
664
+ dw_printf ("Error: gpiod_line_set_value %s %d, errno=%d\n" , gpiod_chip_name (gpiod_line_get_chip (line )), gpiod_line_offset (line ),errno );
665
+ rc = rc - 2 ;
666
+ }
667
+ }else {
669
668
text_color_set (DW_COLOR_ERROR );
670
- dw_printf ("Can't get GPIOD line %d.\n" , line_number );
671
- return -1 ;
672
- }
673
- if (ptt_debug_level >= 2 ) {
674
- text_color_set (DW_COLOR_DEBUG );
675
- dw_printf ("GPIOD probe OK. Chip: %s line: %d\n" , chip_name , line_number );
669
+ dw_printf ("Error: didnot request %s %d,\n" , gpiod_chip_name (gpiod_line_get_chip (line )), gpiod_line_offset (line ));
670
+ rc = rc - 1 ;
676
671
}
677
- return 0 ;
672
+ if (ptt_debug_level >= 1 ) {
673
+ text_color_set (DW_COLOR_DEBUG );
674
+ dw_printf ("PTT_METHOD_GPIOD chip: %s line: %d ptt: %d rc: %d\n" , gpiod_chip_name (gpiod_line_get_chip (line )), gpiod_line_offset (line ), ptt , rc );
675
+ }
676
+ return rc ;
678
677
}
679
678
#endif /* USE_GPIOD */
680
679
#endif /* not __WIN32__ */
@@ -933,7 +932,34 @@ void ptt_init (struct audio_s *audio_config_p)
933
932
if (audio_config_p -> achan [ch ].octrl [ot ].ptt_method == PTT_METHOD_GPIOD ) {
934
933
const char * chip_name = audio_config_p -> achan [ch ].octrl [ot ].out_gpio_name ;
935
934
int line_number = audio_config_p -> achan [ch ].octrl [ot ].out_gpio_num ;
936
- int rc = gpiod_probe (chip_name , line_number );
935
+ int rc = 0 ;
936
+ struct gpiod_chip * chip ;
937
+ chip = gpiod_chip_open_by_name (chip_name );
938
+ if (chip == NULL ) {
939
+ text_color_set (DW_COLOR_ERROR );
940
+ dw_printf ("Can't open GPIOD chip %s.\n" , chip_name );
941
+ rc = rc - 1 ;
942
+ }
943
+ struct gpiod_line * line ;
944
+ line = gpiod_chip_get_line (chip , line_number );
945
+ if (line == NULL ) {
946
+ text_color_set (DW_COLOR_ERROR );
947
+ dw_printf ("Can't get GPIOD line %d.\n" , line_number );
948
+ rc = rc - 2 ;
949
+ }else {
950
+ audio_config_p -> achan [ch ].octrl [ot ].gpiod_line_handle = line ;
951
+ }
952
+ if ( gpiod_line_request_output (line , "direwolf" , 0 ) != 0 ) {
953
+ text_color_set (DW_COLOR_ERROR );
954
+ dw_printf ("Can't request GPIOD line %d.\n" , line_number );
955
+ rc = rc - 4 ;
956
+ }else {
957
+ dw_printf ("Request GPIOD line %d.\n" , line_number );
958
+ }
959
+ if (ptt_debug_level >= 2 ) {
960
+ text_color_set (DW_COLOR_DEBUG );
961
+ dw_printf ("GPIOD probe OK. Chip: %s line: %d\n" , chip_name , line_number );
962
+ }
937
963
if (rc < 0 ) {
938
964
text_color_set (DW_COLOR_ERROR );
939
965
dw_printf ("Disable PTT for channel %d\n" , ch );
@@ -1387,13 +1413,9 @@ void ptt_set (int ot, int chan, int ptt_signal)
1387
1413
1388
1414
#if defined(USE_GPIOD )
1389
1415
if (save_audio_config_p -> achan [chan ].octrl [ot ].ptt_method == PTT_METHOD_GPIOD ) {
1390
- const char * chip = save_audio_config_p -> achan [chan ].octrl [ot ].out_gpio_name ;
1391
- int line = save_audio_config_p -> achan [chan ].octrl [ot ].out_gpio_num ;
1392
- int rc = gpiod_ctxless_set_value (chip , line , ptt , false, "direwolf" , NULL , NULL );
1393
- if (ptt_debug_level >= 1 ) {
1394
- text_color_set (DW_COLOR_DEBUG );
1395
- dw_printf ("PTT_METHOD_GPIOD chip: %s line: %d ptt: %d rc: %d\n" , chip , line , ptt , rc );
1396
- }
1416
+ struct gpiod_line * line = save_audio_config_p -> achan [chan ].octrl [ot ].gpiod_line_handle ;
1417
+ gpiod_set (line , ptt );
1418
+
1397
1419
}
1398
1420
#endif /* USE_GPIOD */
1399
1421
#endif
@@ -1600,6 +1622,20 @@ void ptt_term (void)
1600
1622
}
1601
1623
}
1602
1624
#endif
1625
+ #if defined(USE_GPIOD )
1626
+ // GPIOD
1627
+ for (int ch = 0 ; ch < MAX_RADIO_CHANS ; ch ++ ) {
1628
+ if (save_audio_config_p -> chan_medium [ch ] == MEDIUM_RADIO ) {
1629
+ for (int ot = 0 ; ot < NUM_OCTYPES ; ot ++ ) {
1630
+ if (save_audio_config_p -> achan [ch ].octrl [ot ].ptt_method == PTT_METHOD_GPIOD ) {
1631
+ struct gpiod_line * line = save_audio_config_p -> achan [ch ].octrl [ot ].gpiod_line_handle ;
1632
+ gpiod_line_release (line );
1633
+ save_audio_config_p -> achan [ch ].octrl [ot ].gpiod_line_handle = NULL ;
1634
+ }
1635
+ }
1636
+ }
1637
+ }
1638
+ #endif /* USE_GPIOD */
1603
1639
}
1604
1640
1605
1641
0 commit comments