X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/fnordlicht-mini/blobdiff_plain/24562c8a748c379de491019607921e5959459464..745723e4d1fee18fc31d79172fe8357a75628eea:/firmware/fnordlicht-controller/usb.c diff --git a/firmware/fnordlicht-controller/usb.c b/firmware/fnordlicht-controller/usb.c deleted file mode 100644 index bbfaace..0000000 --- a/firmware/fnordlicht-controller/usb.c +++ /dev/null @@ -1,159 +0,0 @@ -/* vim:ts=4 sts=4 et tw=80 - * - * fnordlicht firmware - * - * for additional information please - * see http://lochraster.org/fnordlichtmini - * - * (c) by Alexander Neumann - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3 as published by - * the Free Software Foundation. - * - * This program 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 General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -/* includes */ -#include "globals.h" -#include "../common/io.h" - -#include -#include - -#include "../common/common.h" -#include "usbdrv/usbdrv.h" -#include "timer.h" -#include "uart.h" -#include "ir.h" - -static bool usb_status; - - /* supply custom usbDeviceConnect() and usbDeviceDisconnect() macros - * which turn the interrupt on and off at the right times, - * and prevent the execution of an interrupt while the pullup resistor - * is switched off */ -#ifdef USB_CFG_PULLUP_IOPORTNAME -#undef usbDeviceConnect -#define usbDeviceConnect() do { \ - USB_PULLUP_DDR |= (1<bRequest == USBRQ_SEND && req->wLength.word > 0) { - usb.state = USB_STATE_SEND; - if (req->wLength.word < 256) { - usb.bytes_remaining = req->wLength.bytes[0]; - return USB_NO_MSG; - } else { - /* too long */ - buf[0] = 1; - len = 1; - } - } else if (req->bRequest == USBRQ_IR_STATE) { - /* read or set state? */ - if (req->bmRequestType & USBRQ_DIR_MASK) { - /* read */ - buf[0] = ir_global.mode; - len = 1; - } else { - /* write */ - uint8_t new_state = req->wValue.bytes[0]; - if (new_state <= IR_RECEIVE) - ir_set_mode(new_state); - } - } else if (req->bRequest == USBRQ_IR_READ) { - if (ir_global.mode == IR_DISABLED) { - usbMsgPtr = (void *)ir_global.time; - return 2*ir_global.pos; - } - } - - return len; -} - -uchar usbFunctionWrite(uchar *data, uchar len) -{ - if (len > usb.bytes_remaining) - len = usb.bytes_remaining; - - usb.bytes_remaining -= len; - - while (len--) { - /* ugly hack: busy wait until the fifo is ready for another byte... */ - while (fifo_full(&global_uart.tx)); - uart_putc(*data++); - } - - if (usb.bytes_remaining == 0) { - return true; - usb.state == USB_STATE_IDLE; - } else - return len; -} - -void usb_init(void) -{ - usbInit(); -} - -void usb_enable(void) -{ - usbDeviceConnect(); - usb_status = true; -} - -void usb_disable(void) -{ - usbDeviceDisconnect(); - usb_status = false; -} - -bool usb_enabled(void) -{ - return usb_status; -} - -void usb_poll(void) -{ - if (usb_status) - usbPoll(); -}