Skip to content

Commit fd5d2d4

Browse files
committed
Add utility cm108_set_gpio to set CM108 GPIO pin for troubleshooting.
Also clarify why we write 5 bytes for a 4 byte HID output report in the comment in cm108.c
1 parent 74a5c34 commit fd5d2d4

File tree

3 files changed

+77
-4
lines changed

3 files changed

+77
-4
lines changed

src/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,24 @@ if(UDEV_FOUND)
420420
endif()
421421

422422

423+
# Utility for setting the CM108 GPIO pins.
424+
if(UDEV_FOUND)
425+
list(APPEND cm108_set_gpio_SOURCES
426+
cm108_set_gpio.c
427+
${cm108_SOURCES}
428+
)
429+
430+
add_executable(cm108_set_gpio
431+
${cm108_set_gpio_SOURCES}
432+
)
433+
434+
target_link_libraries(cm108_set_gpio
435+
${MISC_LIBRARIES}
436+
${UDEV_LIBRARIES}
437+
)
438+
endif()
439+
440+
423441
# Touch Tone to Speech sample application.
424442
# ttcalc
425443
list(APPEND ttcalc_SOURCES

src/cm108.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -836,10 +836,11 @@ static int cm108_write (char *name, int iomask, int iodata)
836836
io[3] = iomask;
837837
io[4] = 0;
838838

839-
// Writing 4 bytes fails with errno 32, EPIPE, "broken pipe."
840-
// Hamlib writes 5 bytes which I don't understand.
841-
// Writing 5 bytes works.
842-
// I have no idea why. From the CMedia datasheet it looks like we need 4.
839+
// Per https://www.kernel.org/doc/Documentation/hid/hidraw.txt, the
840+
// first byte is the report number, which is always 0 since the device
841+
// only has 1 report per the datasheet. The remaining 4 bytes follow the
842+
// structure specified in the datasheet, although we only care about the
843+
// GPIO bytes here.
843844

844845
n = write (fd, io, sizeof(io));
845846
if (n != sizeof(io)) {

src/cm108_set_gpio.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//
2+
// This file is part of Dire Wolf, an amateur radio packet TNC.
3+
//
4+
// Copyright (C) 2014, 2016, 2017 John Langner, WB2OSZ
5+
//
6+
// This program is free software: you can redistribute it and/or modify
7+
// it under the terms of the GNU General Public License as published by
8+
// the Free Software Foundation, either version 2 of the License, or
9+
// (at your option) any later version.
10+
//
11+
// This program is distributed in the hope that it will be useful,
12+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
// GNU General Public License for more details.
15+
//
16+
// You should have received a copy of the GNU General Public License
17+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
19+
20+
21+
/*------------------------------------------------------------------
22+
*
23+
* Module: cm108_set_gpio.c
24+
*
25+
* Purpose: Utility to set GPIO pins on a CM108.
26+
*
27+
* Description: Test utility to set the GPIO pins on a CM108 USB sound device.
28+
*
29+
*---------------------------------------------------------------*/
30+
31+
#include <stdlib.h>
32+
33+
#include "cm108.h"
34+
#include "textcolor.h"
35+
36+
void usage() {
37+
text_color_set(DW_COLOR_INFO);
38+
dw_printf("\n");
39+
dw_printf("cm108_set_gpio - Utility to set a CM108 GPIO pin.\n");
40+
dw_printf("\n");
41+
dw_printf("Usage: cm108_set_gpio /dev/hidrawN PIN_NUMBER <0|1>\n");
42+
dw_printf("\n");
43+
}
44+
45+
int main (int argc, char **argv) {
46+
if (argc != 4) {
47+
usage();
48+
return 1;
49+
}
50+
char* hidraw_filename = argv[1];
51+
int pin_num = atoi(argv[2]);
52+
int state = atoi(argv[3]);
53+
return cm108_set_gpio_pin(hidraw_filename, pin_num, state);
54+
}

0 commit comments

Comments
 (0)