/* **************************************************************************** * stream/usb_stream.c -- open a “serial” USB stream using bulk reads and * writes (as used in Protocol 7). * Copyright (C) 2019 Thomas "Cakeisalie5" Touhey * * This file is part of libcasio. * libcasio is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3.0 of the License, * or (at your option) any later version. * * libcasio is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with libcasio; if not, see . * ************************************************************************* */ #include "stream.h" TIO_HOOK(void) serial_usb_close(void *cookie) { /* Nothing. */ } TIO_HOOK(int) serial_usb_read(void *cookie, unsigned char *buffer, size_t size) { /* Nothing. */ } TIO_HOOK(int) serial_usb_write(void *cookie, unsigned char const *buffer, size_t size) { /* Nothing. */ } CASIO_LOCAL tio_functions_t const serial_usb_funcs = { (tio_close_t *)&serial_usb_close, (tio_read_t *)&serial_usb_read, (tio_write_t *)&serial_usb_write, NULL }; int CASIO_EXPORT casio_open_serial_usb_stream(tio_stream_t **streamp, tio_stream_t *original) { int terr; if (tio_get_type(original) != TIO_TYPE_USB) { msg((ll_error, "original stream wasn't a usb stream")); return (casio_error_arg); } terr = tio_open(streamp, original, NULL, TIO_OPENFLAG_READ | TIO_OPENFLAG_WRITE, &serial_usb_funcs, 0); if (terr) { msg((ll_error, "tio_open failed with error %s: %s", tio_error_name(terr), tio_error_desc(terr))); return (casio_error_unknown); } return (0); }