diff options
author | Jack Rosenthal <jrosenth@chromium.org> | 2022-06-27 15:06:42 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-07-01 19:04:47 +0000 |
commit | e97100030afd5798b479a0f421f86d99bd6d721f (patch) | |
tree | 8bb5e6fa281a4b3c0b1f5b698d5f1e846e802ceb /extra | |
parent | 5e5a814493b5daf1df85c23548389b483bb9f8ea (diff) | |
download | chrome-ec-e97100030afd5798b479a0f421f86d99bd6d721f.tar.gz |
extra/usb_gpio/usb_gpio.c: Format with clang-format
BUG=b:236386294
BRANCH=none
TEST=none
Change-Id: I00976ca4b072d2b63fc123b9aa28859caa6412b3
Signed-off-by: Jack Rosenthal <jrosenth@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3730188
Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
Diffstat (limited to 'extra')
-rw-r--r-- | extra/usb_gpio/usb_gpio.c | 94 |
1 files changed, 37 insertions, 57 deletions
diff --git a/extra/usb_gpio/usb_gpio.c b/extra/usb_gpio/usb_gpio.c index 8973f3d304..40db84dd10 100644 --- a/extra/usb_gpio/usb_gpio.c +++ b/extra/usb_gpio/usb_gpio.c @@ -11,54 +11,46 @@ #include <string.h> #include <unistd.h> -#define CHECK(expression) \ - ({ \ - int error__ = (expression); \ - \ - if (error__ != 0) { \ - fprintf(stderr, \ - "libusb error: %s:%d %s\n", \ - __FILE__, \ - __LINE__, \ - libusb_error_name(error__)); \ - return error__; \ - } \ - \ - error__; \ +#define CHECK(expression) \ + ({ \ + int error__ = (expression); \ + \ + if (error__ != 0) { \ + fprintf(stderr, "libusb error: %s:%d %s\n", __FILE__, \ + __LINE__, libusb_error_name(error__)); \ + return error__; \ + } \ + \ + error__; \ }) #define TRANSFER_TIMEOUT_MS 100 -static int gpio_write(libusb_device_handle *device, - uint32_t set_mask, +static int gpio_write(libusb_device_handle *device, uint32_t set_mask, uint32_t clear_mask) { uint8_t command[8]; - int transferred; + int transferred; - command[0] = (set_mask >> 0) & 0xff; - command[1] = (set_mask >> 8) & 0xff; + command[0] = (set_mask >> 0) & 0xff; + command[1] = (set_mask >> 8) & 0xff; command[2] = (set_mask >> 16) & 0xff; command[3] = (set_mask >> 24) & 0xff; - command[4] = (clear_mask >> 0) & 0xff; - command[5] = (clear_mask >> 8) & 0xff; + command[4] = (clear_mask >> 0) & 0xff; + command[5] = (clear_mask >> 8) & 0xff; command[6] = (clear_mask >> 16) & 0xff; command[7] = (clear_mask >> 24) & 0xff; - CHECK(libusb_bulk_transfer(device, - LIBUSB_ENDPOINT_OUT | 2, - command, - sizeof(command), - &transferred, + CHECK(libusb_bulk_transfer(device, LIBUSB_ENDPOINT_OUT | 2, command, + sizeof(command), &transferred, TRANSFER_TIMEOUT_MS)); if (transferred != sizeof(command)) { fprintf(stderr, "Failed to transfer full command " "(sent %d of %d bytes)\n", - transferred, - (int)sizeof(command)); + transferred, (int)sizeof(command)); return LIBUSB_ERROR_OTHER; } @@ -68,38 +60,29 @@ static int gpio_write(libusb_device_handle *device, static int gpio_read(libusb_device_handle *device, uint32_t *mask) { uint8_t response[4]; - int transferred; + int transferred; /* * The first query does triggers the sampling of the GPIO values, the * second query reads them back. */ - CHECK(libusb_bulk_transfer(device, - LIBUSB_ENDPOINT_IN | 2, - response, - sizeof(response), - &transferred, + CHECK(libusb_bulk_transfer(device, LIBUSB_ENDPOINT_IN | 2, response, + sizeof(response), &transferred, TRANSFER_TIMEOUT_MS)); - CHECK(libusb_bulk_transfer(device, - LIBUSB_ENDPOINT_IN | 2, - response, - sizeof(response), - &transferred, + CHECK(libusb_bulk_transfer(device, LIBUSB_ENDPOINT_IN | 2, response, + sizeof(response), &transferred, TRANSFER_TIMEOUT_MS)); if (transferred != sizeof(response)) { fprintf(stderr, "Failed to transfer full response " "(read %d of %d bytes)\n", - transferred, - (int)sizeof(response)); + transferred, (int)sizeof(response)); return LIBUSB_ERROR_OTHER; } - *mask = (response[0] << 0 | - response[1] << 8 | - response[2] << 16 | + *mask = (response[0] << 0 | response[1] << 8 | response[2] << 16 | response[3] << 24); return 0; @@ -107,13 +90,13 @@ static int gpio_read(libusb_device_handle *device, uint32_t *mask) int main(int argc, char **argv) { - libusb_context *context; + libusb_context *context; libusb_device_handle *device; - uint16_t vendor_id = 0x18d1; /* Google */ - uint16_t product_id = 0x500f; /* discovery-stm32f072 */ - int interface = 1; /* gpio interface */ + uint16_t vendor_id = 0x18d1; /* Google */ + uint16_t product_id = 0x500f; /* discovery-stm32f072 */ + int interface = 1; /* gpio interface */ - if (!(argc == 2 && strcmp(argv[1], "read") == 0) && + if (!(argc == 2 && strcmp(argv[1], "read") == 0) && !(argc == 4 && strcmp(argv[1], "write") == 0)) { puts("Usage: usb_gpio read\n" " usb_gpio write <set_mask> <clear_mask>\n"); @@ -122,15 +105,12 @@ int main(int argc, char **argv) CHECK(libusb_init(&context)); - device = libusb_open_device_with_vid_pid(context, - vendor_id, - product_id); + device = + libusb_open_device_with_vid_pid(context, vendor_id, product_id); if (device == NULL) { - fprintf(stderr, - "Unable to find device 0x%04x:0x%04x\n", - vendor_id, - product_id); + fprintf(stderr, "Unable to find device 0x%04x:0x%04x\n", + vendor_id, product_id); return 1; } @@ -146,7 +126,7 @@ int main(int argc, char **argv) } if (argc == 4 && strcmp(argv[1], "write") == 0) { - uint32_t set_mask = strtol(argv[2], NULL, 0); + uint32_t set_mask = strtol(argv[2], NULL, 0); uint32_t clear_mask = strtol(argv[3], NULL, 0); CHECK(gpio_write(device, set_mask, clear_mask)); |