From 12287ff0a55f929bf840dcb4780d3f77b862c434 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 2 Nov 2014 18:17:44 +0000 Subject: fish --- src/Makefile | 43 ---------------- src/dfu.c | 60 ----------------------- src/keyboard.c | 140 ---------------------------------------------------- src/kvm.c | 91 ---------------------------------- src/kvm.ld | 31 ------------ src/main.c | 55 --------------------- src/mouse.c | 115 ------------------------------------------- src/project.h | 23 --------- src/prototypes.h | 43 ---------------- src/ring.c | 61 ----------------------- src/ring.h | 9 ---- src/tablet.c | 122 ---------------------------------------------- src/usart.c | 104 --------------------------------------- src/usb.c | 146 ------------------------------------------------------- 14 files changed, 1043 deletions(-) delete mode 100644 src/Makefile delete mode 100644 src/dfu.c delete mode 100644 src/keyboard.c delete mode 100644 src/kvm.c delete mode 100644 src/kvm.ld delete mode 100644 src/main.c delete mode 100644 src/mouse.c delete mode 100644 src/project.h delete mode 100644 src/prototypes.h delete mode 100644 src/ring.c delete mode 100644 src/ring.h delete mode 100644 src/tablet.c delete mode 100644 src/usart.c delete mode 100644 src/usb.c (limited to 'src') diff --git a/src/Makefile b/src/Makefile deleted file mode 100644 index f7f445a..0000000 --- a/src/Makefile +++ /dev/null @@ -1,43 +0,0 @@ -## -## This file is part of the libopencm3 project. -## -## Copyright (C) 2009 Uwe Hermann -## -## This library 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 of the License, or -## (at your option) any later version. -## -## This library 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 this library. If not, see . -## - -CPROTO=cproto -PROG=kvm - -V=1 -default: ${PROG}.elf - -CSRCS=dfu.c mouse.c keyboard.c main.c usb.c tablet.c usart.c kvm.c ring.c - - -BINARY = ${PROG} -OBJS = ${CSRCS:%.c=%.o} - - -program: ${PROG}.elf - echo halt | nc -t localhost 4444 - echo flash write_image erase ${PWD}/$< | nc -t localhost 4444 - echo reset run | nc -t localhost 4444 - -protos: - echo -n > prototypes.h - ${CPROTO} $(INCLUDES) $(DEFINES) -e -v ${CSRCS} > prototypes.h.tmp - mv -f prototypes.h.tmp prototypes.h - -include ../Makefile.include diff --git a/src/dfu.c b/src/dfu.c deleted file mode 100644 index e9de46f..0000000 --- a/src/dfu.c +++ /dev/null @@ -1,60 +0,0 @@ -#include "project.h" - -#ifdef INCLUDE_DFU_INTERFACE - -const struct usb_dfu_descriptor dfu_function = { - .bLength = sizeof (struct usb_dfu_descriptor), - .bDescriptorType = DFU_FUNCTIONAL, - .bmAttributes = USB_DFU_CAN_DOWNLOAD | USB_DFU_WILL_DETACH, - .wDetachTimeout = 255, - .wTransferSize = 1024, - .bcdDFUVersion = 0x011A, -}; - -const struct usb_interface_descriptor dfu_iface = { - .bLength = USB_DT_INTERFACE_SIZE, - .bDescriptorType = USB_DT_INTERFACE, - .bInterfaceNumber = 3, - .bAlternateSetting = 0, - .bNumEndpoints = 0, - .bInterfaceClass = 0xFE, - .bInterfaceSubClass = 1, - .bInterfaceProtocol = 1, - .iInterface = 0, - - .extra = &dfu_function, - .extralen = sizeof (dfu_function), -}; - - -static void -dfu_detach_complete (usbd_device * usbd_dev, struct usb_setup_data *req) -{ - (void) req; - (void) usbd_dev; - - gpio_set_mode (GPIOA, GPIO_MODE_INPUT, 0, GPIO15); - gpio_set_mode (GPIOA, GPIO_MODE_OUTPUT_2_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, GPIO10); - gpio_set (GPIOA, GPIO10); - scb_reset_core (); -} - -int -dfu_control_request (usbd_device * usbd_dev, struct usb_setup_data *req, - uint8_t ** buf, uint16_t * len, - void (**complete) (usbd_device * usbd_dev, - struct usb_setup_data * req)) -{ - (void) buf; - (void) len; - (void) usbd_dev; - - if ((req->bmRequestType != 0x21) || (req->bRequest != DFU_DETACH)) - return 0; /* Only accept class request. */ - - *complete = dfu_detach_complete; - - return 1; -} -#endif diff --git a/src/keyboard.c b/src/keyboard.c deleted file mode 100644 index e9046a3..0000000 --- a/src/keyboard.c +++ /dev/null @@ -1,140 +0,0 @@ -#include "project.h" - -#if 0 -static const uint8_t keyboard_report_descriptor[] = { - 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ - 0x09, 0x01, /* USAGE (Keyboard */ - 0xa1, 0x01, /* COLLECTION (Application) */ - 0x05, 0x07, /* USAGE_PAGE (Key Codes) */ - 0x19, 0xe0, /* USAGE_MINIMUM (Control Left) */ - 0x29, 0xe7, /* USAGE_MAXIMUM (GUI Right) */ - 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ - 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ - 0x75, 0x01, /* REPORT_SIZE (1) */ - 0x95, 0x08, /* REPORT_COUNT (8) */ - 0x81, 0x02, /* INPUT (Data,Var,Abs) */ - 0x95, 0x01, /* REPORT_COUNT (1) */ - 0x75, 0x08, /* REPORT_SIZE (8) */ - 0x81, 0x01, /* INPUT (Cnst,Ary,Abs) */ - 0x95, 0x05, /* REPORT_COUNT (5) */ - 0x75, 0x01, /* REPORT_SIZE (1) */ -#if 0 - 0x05, 0x08, /* USAGE_PAGE (LEDs) */ - 0x19, 0x01, /* USAGE_MINIMUM (NumLock) */ - 0x29, 0x05, /* USAGE_MAXIMUM (Kana) */ - 0x ? ?, 0x02, /* OUTPUT (Data,Var,Abs) */ - 0x95, 0x01, /* REPORT_COUNT (1) */ - 0x75, 0x03, /* REPORT_SIZE (3) */ - 0x ? ?, 0x01, /* OUTPUT (Cnst,Ary,Abs) */ - 0x95, 0x06, /* REPORT_COUNT (6) */ - 0x75, 0x03, /* REPORT_SIZE (8) */ - 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ - 0x25, 0xff, 0x00, /*LOGICAL_MAXIMUM (255) */ -#endif - 0x05, 0x07, /* USAGE_PAGE (Key Codes) */ - 0x19, 0x00, /* USAGE_MINIMUM (?) */ - 0x29, 0x98, /* USAGE_MAXIMUM (LANG 9) */ - 0xc0 /* END_COLLECTION */ -}; -#endif - -static const uint8_t keyboard_report_descriptor[] = { - 0x05, 0x01, /* Usage Page (Generic Desktop) */ - 0x09, 0x06, /* Usage (Keyboard) */ - 0xA1, 0x01, /* Collection (Application) */ - 0x05, 0x07, /* Usage page (Key Codes) */ - 0x19, 0xE0, /* Usage minimum (224) */ - 0x29, 0xE7, /* Usage maximum (231) */ - 0x15, 0x00, /* Logical minimum (0) */ - 0x25, 0x01, /* Logical maximum (1) */ - 0x75, 0x01, /* Report size (1) */ - 0x95, 0x08, /* Report count (8) */ - 0x81, 0x02, /* Input (data, variable, absolute) */ - 0x95, 0x01, /* Report count (1) */ - 0x75, 0x08, /* Report size (8) */ - 0x81, 0x01, /* Input (constant) */ - 0x95, 0x06, /* Report count (6) */ - 0x75, 0x08, /* Report size (8) */ - 0x15, 0x00, /* Logical minimum (0) */ - 0x25, 0x65, /* Logical maximum (101) */ - 0x05, 0x07, /* Usage page (key codes) */ - 0x19, 0x00, /* Usage minimum (0) */ - 0x2A, 0xff, 0x00, /* Usage maximum (255) */ -// 0x29, 0x65, /* Usage maximum (101) */ -// 0x2A, 0xff, 0x03, /* Usage maximum (1023) */ - 0x81, 0x00, /* Input (data, array) */ - 0xC0 /* End Collection */ -}; - - -static const struct -{ - struct usb_hid_descriptor hid_descriptor; - struct - { - uint8_t bReportDescriptorType; - uint16_t wDescriptorLength; - } __attribute__ ((packed)) hid_report; -} __attribute__ ((packed)) keyboard_function = -{ - .hid_descriptor = - { - .bLength = sizeof (keyboard_function),.bDescriptorType = - USB_DT_HID,.bcdHID = 0x0100,.bCountryCode = 0,.bNumDescriptors = 1,} - ,.hid_report = - { - .bReportDescriptorType = USB_DT_REPORT,.wDescriptorLength = - sizeof (keyboard_report_descriptor),} -,}; - -const struct usb_endpoint_descriptor keyboard_endpoint = { - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 0x81, - .bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT, - .wMaxPacketSize = 8, - .bInterval = 0x20, -}; - -const struct usb_interface_descriptor keyboard_iface = { - .bLength = USB_DT_INTERFACE_SIZE, - .bDescriptorType = USB_DT_INTERFACE, - .bInterfaceNumber = 0, - .bAlternateSetting = 0, - .bNumEndpoints = 1, - .bInterfaceClass = USB_CLASS_HID, - .bInterfaceSubClass = 1, /* boot */ - .bInterfaceProtocol = 1, /* keyboard */ - .iInterface = 0, - - .endpoint = &keyboard_endpoint, - - .extra = &keyboard_function, - .extralen = sizeof (keyboard_function), -}; - - -void -keyboard_get_descriptor (uint8_t ** buf, uint16_t * len) -{ - - /* Handle the HID report descriptor. */ - *buf = (uint8_t *) keyboard_report_descriptor; - *len = sizeof (keyboard_report_descriptor); -} - -void -keyboard_test (void) -{ - static int c = 0; - uint8_t buf[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; - - - buf[0] = (c >> 1) & 7; - - buf[2] = (c & 1) ? 12 : 0; - - c++; - - usbd_ep_write_packet (usbd_dev, 0x81, buf, 8); -} diff --git a/src/kvm.c b/src/kvm.c deleted file mode 100644 index f5e65c8..0000000 --- a/src/kvm.c +++ /dev/null @@ -1,91 +0,0 @@ -#include "project.h" - - -static enum -{ - STATE_SYNC = 0, - STATE_ADDR = 1, - STATE_ENDPOINT = 2, - STATE_LEN = 3, - STATE_DATA = 4, -} state = STATE_SYNC; - - -static uint8_t buf[16]; -static int addr; -static int endpoint; -static unsigned int len; -static unsigned int ptr; - -void -kvm_dispatch (void) -{ -#if 0 - printf - ("Addr %d, Write to ep %x, %d bytes %02x %02x %02x %02x ...\r\n", - addr, endpoint, len, buf[0], buf[1], buf[2], buf[3]); -#endif - - if(len) - usbd_ep_write_packet (usbd_dev, endpoint, buf, len); -} - -void -kvm_recv (uint8_t d) -{ -// printf ("S%d V0x%02x\r\n", state, d); - - if (state == STATE_ADDR) - { - addr = d; - usart_queue (d - 1); - state = STATE_ENDPOINT; - return; - } - else - { - usart_queue (d); - } - - - switch (state) - { - case STATE_SYNC: - if (d != 0x5a) - break; - state = STATE_ADDR; - break; - case STATE_ENDPOINT: - endpoint = d; - if ((endpoint < 0x81) || (endpoint > 0x83)) - { - state = STATE_SYNC; - } - else - { - state = STATE_LEN; - } - break; - case STATE_LEN: - len = d; - ptr = 0; - if (len > sizeof (buf)) - { - state = STATE_SYNC; - } - else - { - state = STATE_DATA; - } - break; - case STATE_DATA: - buf[ptr++] = d; - if (ptr >= len) - { - if (!addr) - kvm_dispatch (); - state = STATE_SYNC; - } - break; - } -} diff --git a/src/kvm.ld b/src/kvm.ld deleted file mode 100644 index e15beca..0000000 --- a/src/kvm.ld +++ /dev/null @@ -1,31 +0,0 @@ -/* - * This file is part of the libopencm3 project. - * - * Copyright (C) 2009 Uwe Hermann - * - * This library 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 of the License, or - * (at your option) any later version. - * - * This library 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 this library. If not, see . - */ - -/* Linker script for Olimex STM32-H103 (STM32F103RBT6, 128K flash, 20K RAM). */ - -/* Define memory regions. */ -MEMORY -{ - rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K - ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K -} - -/* Include the common ld script. */ -INCLUDE libopencm3_stm32f1.ld - diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 3058108..0000000 --- a/src/main.c +++ /dev/null @@ -1,55 +0,0 @@ -#include "project.h" - -void -sys_tick_handler (void) -{ -#if 0 - printf ("fish\r\n"); - keyboard_test (); - mouse_test (); - tablet_test (); -#endif -} - -int -main (void) -{ - int i; - - - rcc_clock_setup_in_hsi_out_48mhz (); - rcc_periph_clock_enable (RCC_GPIOC); - rcc_periph_clock_enable (RCC_GPIOA); - rcc_periph_clock_enable (RCC_AFIO); - rcc_periph_clock_enable (RCC_USART1); - - - usart_init (); - - usb_init (); - - systick_set_clocksource (STK_CSR_CLKSOURCE_AHB_DIV8); - /* 48MHz / 8 = > 6Mhz */ - systick_set_reload (3000000); - /* 6MHz / 3000000 => 2Hz */ - - systick_interrupt_enable (); - systick_counter_enable (); - - gpio_set (GPIOC, GPIO11); - gpio_set_mode (GPIOC, GPIO_MODE_OUTPUT_2_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, GPIO11); - - - - for (i = 0; i < 0x80000; i++) - __asm__ ("nop"); - - gpio_clear (GPIOC, GPIO11); - - printf ("Hello world\r\n"); - - usb_run (); - - return 0; -} diff --git a/src/mouse.c b/src/mouse.c deleted file mode 100644 index 6e0a207..0000000 --- a/src/mouse.c +++ /dev/null @@ -1,115 +0,0 @@ -#include "project.h" - -static const uint8_t mouse_report_descriptor[] = { - 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ - 0x09, 0x02, /* USAGE (Mouse) */ - 0xa1, 0x01, /* COLLECTION (Application) */ - 0x09, 0x01, /* USAGE (Pointer) */ - 0xa1, 0x00, /* COLLECTION (Physical) */ - 0x05, 0x09, /* USAGE_PAGE (Button) */ - 0x19, 0x01, /* USAGE_MINIMUM (Button 1) */ - 0x29, 0x03, /* USAGE_MAXIMUM (Button 3) */ - 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ - 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ - 0x95, 0x03, /* REPORT_COUNT (3) */ - 0x75, 0x01, /* REPORT_SIZE (1) */ - 0x81, 0x02, /* INPUT (Data,Var,Abs) */ - 0x95, 0x01, /* REPORT_COUNT (1) */ - 0x75, 0x05, /* REPORT_SIZE (5) */ - 0x81, 0x01, /* INPUT (Cnst,Ary,Abs) */ - 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ - 0x09, 0x30, /* USAGE (X) */ - 0x09, 0x31, /* USAGE (Y) */ - 0x09, 0x38, /* USAGE (Wheel) */ - 0x15, 0x81, /* LOGICAL_MINIMUM (-127) */ - 0x25, 0x7f, /* LOGICAL_MAXIMUM (127) */ - 0x75, 0x08, /* REPORT_SIZE (8) */ - 0x95, 0x03, /* REPORT_COUNT (3) */ - 0x81, 0x06, /* INPUT (Data,Var,Rel) */ - 0xc0, /* END_COLLECTION */ - 0x09, 0x3c, /* USAGE (Motion Wakeup) */ - 0x05, 0xff, /* USAGE_PAGE (Vendor Defined Page 1) */ - 0x09, 0x01, /* USAGE (Vendor Usage 1) */ - 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ - 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ - 0x75, 0x01, /* REPORT_SIZE (1) */ - 0x95, 0x02, /* REPORT_COUNT (2) */ - 0xb1, 0x22, /* FEATURE (Data,Var,Abs,NPrf) */ - 0x75, 0x06, /* REPORT_SIZE (6) */ - 0x95, 0x01, /* REPORT_COUNT (1) */ - 0xb1, 0x01, /* FEATURE (Cnst,Ary,Abs) */ - 0xc0 /* END_COLLECTION */ -}; - -static const struct -{ - struct usb_hid_descriptor hid_descriptor; - struct - { - uint8_t bReportDescriptorType; - uint16_t wDescriptorLength; - } __attribute__ ((packed)) hid_report; -} __attribute__ ((packed)) mouse_function = -{ - .hid_descriptor = - { - .bLength = sizeof (mouse_function),.bDescriptorType = USB_DT_HID,.bcdHID = - 0x0100,.bCountryCode = 0,.bNumDescriptors = 1,} - ,.hid_report = - { - .bReportDescriptorType = USB_DT_REPORT,.wDescriptorLength = - sizeof (mouse_report_descriptor),} -,}; - -const struct usb_endpoint_descriptor mouse_endpoint = { - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 0x82, - .bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT, - .wMaxPacketSize = 4, - .bInterval = 0x20, -}; - -const struct usb_interface_descriptor mouse_iface = { - .bLength = USB_DT_INTERFACE_SIZE, - .bDescriptorType = USB_DT_INTERFACE, - .bInterfaceNumber = 1, - .bAlternateSetting = 0, - .bNumEndpoints = 1, - .bInterfaceClass = USB_CLASS_HID, - .bInterfaceSubClass = 1, /* boot */ - .bInterfaceProtocol = 2, /* mouse */ - .iInterface = 0, - - .endpoint = &mouse_endpoint, - - .extra = &mouse_function, - .extralen = sizeof (mouse_function), -}; - - -void -mouse_get_descriptor (uint8_t ** buf, uint16_t * len) -{ - - /* Handle the HID report descriptor. */ - *buf = (uint8_t *) mouse_report_descriptor; - *len = sizeof (mouse_report_descriptor); -} - -void -mouse_test (void) -{ - static int c = 1; - uint8_t buf[4] = { 0, 0, 0, 0 }; - - buf[0] = c & 7; - - buf[1] = c & 8 ? -1 : 1; - buf[2] = c & 16 ? -1 : 1; - buf[3] = c & 32 ? -1 : 1; - - c++; - - usbd_ep_write_packet (usbd_dev, 0x82, buf, 4); -} diff --git a/src/project.h b/src/project.h deleted file mode 100644 index 0323569..0000000 --- a/src/project.h +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -#define INCLUDE_DFU_INTERFACE - - -#ifdef INCLUDE_DFU_INTERFACE -#include -#include -#endif - -#include -#include - -#include "ring.h" - -#include "prototypes.h" diff --git a/src/prototypes.h b/src/prototypes.h deleted file mode 100644 index 0e971df..0000000 --- a/src/prototypes.h +++ /dev/null @@ -1,43 +0,0 @@ -/* dfu.c */ -extern const struct usb_dfu_descriptor dfu_function; -extern const struct usb_interface_descriptor dfu_iface; -extern int dfu_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req)); -/* mouse.c */ -extern const struct usb_endpoint_descriptor mouse_endpoint; -extern const struct usb_interface_descriptor mouse_iface; -extern void mouse_get_descriptor(uint8_t **buf, uint16_t *len); -extern void mouse_test(void); -/* keyboard.c */ -extern const struct usb_endpoint_descriptor keyboard_endpoint; -extern const struct usb_interface_descriptor keyboard_iface; -extern void keyboard_get_descriptor(uint8_t **buf, uint16_t *len); -extern void keyboard_test(void); -/* main.c */ -extern void sys_tick_handler(void); -extern int main(void); -/* usb.c */ -extern const struct usb_device_descriptor dev; -extern const struct usb_interface ifaces[]; -extern const struct usb_config_descriptor config; -extern usbd_device *usbd_dev; -extern void usb_set_config(usbd_device *usbd_dev, uint16_t wValue); -extern void usb_init(void); -extern void usb_run(void); -/* tablet.c */ -extern const struct usb_endpoint_descriptor tablet_endpoint; -extern const struct usb_interface_descriptor tablet_iface; -extern void tablet_get_descriptor(uint8_t **buf, uint16_t *len); -extern void tablet_test(void); -/* usart.c */ -extern void usart1_isr(void); -extern int _write(int file, char *ptr, int len); -extern void usart_queue(uint8_t d); -extern void usart_init(void); -/* kvm.c */ -extern void kvm_dispatch(void); -extern void kvm_recv(uint8_t d); -/* ring.c */ -extern void ring_init(ring_t *r, uint8_t *buf, size_t len); -extern int ring_write_byte(ring_t *r, uint8_t c); -extern int ring_read_byte(ring_t *r, uint8_t *c); -extern int ring_write(ring_t *r, uint8_t *buf, size_t len); diff --git a/src/ring.c b/src/ring.c deleted file mode 100644 index 4f38e44..0000000 --- a/src/ring.c +++ /dev/null @@ -1,61 +0,0 @@ -#include "project.h" - - -static inline size_t -ring_next (ring_t * r, size_t p) -{ - p++; - if (p >= r->size) - p -= r->size; - return p; -} - -void -ring_init (ring_t * r, uint8_t * buf, size_t len) -{ - r->data = buf; - r->size = len; - r->write = 0; - r->read = 0; -} - -int -ring_write_byte (ring_t * r, uint8_t c) -{ - size_t n = ring_next (r, r->write); - - if (n == r->read) - return -1; - - r->data[r->write] = c; - r->write = n; - - return 0; -} - - -int -ring_read_byte (ring_t * r, uint8_t * c) -{ - size_t n = ring_next (r, r->read); - - if (r->read == r->write) - return -1; - - *c = r->data[r->read]; - r->read = n; - - return 0; -} - -int -ring_write (ring_t * r, uint8_t * buf, size_t len) -{ - while (len--) - { - if (ring_write_byte (r, *(buf++))) - return -1; - } - - return 0; -} diff --git a/src/ring.h b/src/ring.h deleted file mode 100644 index 4e3a22c..0000000 --- a/src/ring.h +++ /dev/null @@ -1,9 +0,0 @@ -typedef struct ring -{ - uint8_t *data; - size_t size; - size_t write; - size_t read; -} ring_t; - - diff --git a/src/tablet.c b/src/tablet.c deleted file mode 100644 index 1073b37..0000000 --- a/src/tablet.c +++ /dev/null @@ -1,122 +0,0 @@ -#include "project.h" - -static const uint8_t tablet_report_descriptor[] = { - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) - 0x09, 0x02, // USAGE (Mouse) - 0xa1, 0x01, // COLLECTION (Application) - 0x09, 0x01, // USAGE (Pointer) - 0xa1, 0x00, // COLLECTION (Physical) - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) - 0x09, 0x30, // USAGE (X) - 0x09, 0x31, // USAGE (Y) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x26, 0xff, 0x7f, // LOGICAL_MAXIMUM (32767) - 0x75, 0x10, // REPORT_SIZE (16) - 0x95, 0x02, // REPORT_COUNT (2) - 0x81, 0x02, // INPUT (Data,Var,Abs) - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) - 0x09, 0x38, // USAGE (Wheel) - 0x15, 0x81, // LOGICAL_MINIMUM (-127) - 0x25, 0x7f, // LOGICAL_MAXIMUM (127) - 0x75, 0x08, // REPORT_SIZE (8) - 0x95, 0x01, // REPORT_COUNT (1) - 0x81, 0x06, // INPUT (Data,Var,Rel) - 0x05, 0x09, // USAGE_PAGE (Button) - 0x19, 0x01, // USAGE_MINIMUM (Button 1) - 0x29, 0x03, // USAGE_MAXIMUM (Button 3) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x01, // LOGICAL_MAXIMUM (1) - 0x95, 0x03, // REPORT_COUNT (3) - 0x75, 0x01, // REPORT_SIZE (1) - 0x81, 0x02, // INPUT (Data,Var,Abs) - 0x95, 0x01, // REPORT_COUNT (1) - 0x75, 0x05, // REPORT_SIZE (5) - 0x81, 0x01, // INPUT (Cnst,Ary,Abs) - 0xc0, // END_COLLECTION - 0x09, 0x3c, // USAGE (Button 60) - 0x06, 0x00, 0xff, // USAGE_PAGE (Vendor Defined Page 1) - 0x09, 0x01, // USAGE (Vendor Usage 1) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x01, // LOGICAL_MAXIMUM (1) - 0x75, 0x01, // REPORT_SIZE (1) - 0x95, 0x02, // REPORT_COUNT (2) - 0xb1, 0x22, // FEATURE (Data,Var,Abs,NPrf) - 0x75, 0x06, // REPORT_SIZE (6) - 0x95, 0x01, // REPORT_COUNT (1) - 0xb1, 0x01, // FEATURE (Cnst,Ary,Abs) - 0xc0 // END_COLLECTION -}; - -static const struct -{ - struct usb_hid_descriptor hid_descriptor; - struct - { - uint8_t bReportDescriptorType; - uint16_t wDescriptorLength; - } __attribute__ ((packed)) hid_report; -} __attribute__ ((packed)) tablet_function = -{ - .hid_descriptor = - { - .bLength = sizeof (tablet_function),.bDescriptorType = - USB_DT_HID,.bcdHID = 0x0100,.bCountryCode = 0,.bNumDescriptors = 1,} - ,.hid_report = - { - .bReportDescriptorType = USB_DT_REPORT,.wDescriptorLength = - sizeof (tablet_report_descriptor),} -,}; - -const struct usb_endpoint_descriptor tablet_endpoint = { - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 0x83, - .bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT, - .wMaxPacketSize = 6, - .bInterval = 0x20, -}; - -const struct usb_interface_descriptor tablet_iface = { - .bLength = USB_DT_INTERFACE_SIZE, - .bDescriptorType = USB_DT_INTERFACE, - .bInterfaceNumber = 2, - .bAlternateSetting = 0, - .bNumEndpoints = 1, - .bInterfaceClass = USB_CLASS_HID, - .bInterfaceSubClass = 1, /* boot */ - .bInterfaceProtocol = 2, /* tablet */ - .iInterface = 0, - - .endpoint = &tablet_endpoint, - - .extra = &tablet_function, - .extralen = sizeof (tablet_function), -}; - - -void -tablet_get_descriptor (uint8_t ** buf, uint16_t * len) -{ - - /* Handle the HID report descriptor. */ - *buf = (uint8_t *) tablet_report_descriptor; - *len = sizeof (tablet_report_descriptor); -} - -void -tablet_test (void) -{ - static int c = 0; - uint8_t buf[6] = { 0, 0, 0, 0, 0 }; - - buf[0] = c & 0xff; - buf[1] = (c & 0x7fff) >> 8; - buf[2] = (32767 - (c & 0x7fff)) & 0xff; - buf[3] = (32767 - (c & 0x7fff)) >> 8; - buf[4] = (c & 8) ? -1 : 1; - buf[5] = c; - - c++; - - usbd_ep_write_packet (usbd_dev, 0x83, buf, 6); -} diff --git a/src/usart.c b/src/usart.c deleted file mode 100644 index b0ea2a4..0000000 --- a/src/usart.c +++ /dev/null @@ -1,104 +0,0 @@ -#include "project.h" - -#define BUFFER_SIZE 256 - -static ring_t output_ring; -static uint8_t output_ring_buf[BUFFER_SIZE]; - -void -usart1_isr (void) -{ - uint8_t data; - - /* Check if we were called because of RXNE. */ - if (((USART_CR1 (USART1) & USART_CR1_RXNEIE) != 0) && - ((USART_SR (USART1) & USART_SR_RXNE) != 0)) - { - - /* Retrieve the data from the peripheral. */ - data = usart_recv (USART1); - - kvm_recv (data); - } - - /* Check if we were called because of TXE. */ - if (((USART_CR1 (USART1) & USART_CR1_TXEIE) != 0) && - ((USART_SR (USART1) & USART_SR_TXE) != 0)) - { - - if (ring_read_byte (&output_ring, &data)) - { - /*No more data, Disable the TXE interrupt, it's no longer needed. */ - USART_CR1 (USART1) &= ~USART_CR1_TXEIE; - } - else - { - usart_send (USART1, data); - } - } - -} - -int -_write (int file, char *ptr, int len) -{ - int ret; - - if (file == 1) - { - ret = ring_write (&output_ring, (uint8_t *) ptr, len); - - if (ret < 0) - ret = -ret; - - USART_CR1 (USART1) |= USART_CR1_TXEIE; - return ret; - } - - errno = EIO; - return -1; -} - -void -usart_queue (uint8_t d) -{ - ring_write_byte(&output_ring,d); - USART_CR1 (USART1) |= USART_CR1_TXEIE; - -#if 0 - printf ("0x%02x ", d); - fflush (stdout); -#endif -} - - -void -usart_init (void) -{ - ring_init (&output_ring, output_ring_buf, sizeof (output_ring_buf)); - - /* Enable the USART1 interrupt. */ - nvic_enable_irq (NVIC_USART1_IRQ); - - /* Setup GPIO pin GPIO_USART1_RE_TX on GPIO port B for transmit. */ - gpio_set_mode (GPIOA, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX); - - /* Setup GPIO pin GPIO_USART1_RE_RX on GPIO port B for receive. */ - gpio_set_mode (GPIOA, GPIO_MODE_INPUT, - GPIO_CNF_INPUT_FLOAT, GPIO_USART1_RX); - - /* Setup UART parameters. */ - usart_set_baudrate (USART1, 38400); - usart_set_databits (USART1, 8); - usart_set_stopbits (USART1, USART_STOPBITS_1); - usart_set_parity (USART1, USART_PARITY_NONE); - usart_set_flow_control (USART1, USART_FLOWCONTROL_NONE); - usart_set_mode (USART1, USART_MODE_TX_RX); - - /* Enable USART1 Receive interrupt. */ - USART_CR1 (USART1) |= USART_CR1_RXNEIE; - - /* Finally enable the USART. */ - usart_enable (USART1); -} diff --git a/src/usb.c b/src/usb.c deleted file mode 100644 index f796162..0000000 --- a/src/usb.c +++ /dev/null @@ -1,146 +0,0 @@ -#include "project.h" - -/* Define this to include the DFU APP interface. */ -const struct usb_device_descriptor dev = { - .bLength = USB_DT_DEVICE_SIZE, - .bDescriptorType = USB_DT_DEVICE, - .bcdUSB = 0x0200, - .bDeviceClass = 0, - .bDeviceSubClass = 0, - .bDeviceProtocol = 0, - .bMaxPacketSize0 = 64, - .idVendor = 0x1d6b, - .idProduct = 0x0ee3, - .bcdDevice = 0x0200, - .iManufacturer = 1, - .iProduct = 2, - .iSerialNumber = 3, - .bNumConfigurations = 1, -}; - -const struct usb_interface ifaces[] = { - { - .num_altsetting = 1, - .altsetting = &keyboard_iface, - }, - { - .num_altsetting = 1, - .altsetting = &mouse_iface, - }, - { - .num_altsetting = 1, - .altsetting = &tablet_iface, - }, -#ifdef INCLUDE_DFU_INTERFACE - { - .num_altsetting = 1, - .altsetting = &dfu_iface, -#endif - } -}; - -const struct usb_config_descriptor config = { - .bLength = USB_DT_CONFIGURATION_SIZE, - .bDescriptorType = USB_DT_CONFIGURATION, - .wTotalLength = 0, -#ifdef INCLUDE_DFU_INTERFACE - .bNumInterfaces = 4, -#else - .bNumInterfaces = 3, -#endif - .bConfigurationValue = 1, - .iConfiguration = 0, - .bmAttributes = 0xC0, - .bMaxPower = 0x32, - - .interface = ifaces, -}; - -static const char *usb_strings[] = { - "Cabbages are good for you", - "fish", - "soup", -}; - - - -usbd_device *usbd_dev; - - -static int -usb_control_request (usbd_device * usbd_dev, struct usb_setup_data *req, - uint8_t ** buf, uint16_t * len, - void (**complete) (usbd_device * usbd_dev, - struct usb_setup_data * req)) -{ - - (void) complete; - (void) usbd_dev; - - if ((req->bmRequestType != 0x81) || - (req->bRequest != USB_REQ_GET_DESCRIPTOR) || (req->wValue != 0x2200)) - return 0; - - switch (req->wIndex) - { - case 0: - keyboard_get_descriptor (buf, len); - return 1; - case 1: - mouse_get_descriptor (buf, len); - return 1; - case 2: - tablet_get_descriptor (buf, len); - return 1; - } - - *len = 0; - return 0; -} - - -void -usb_set_config (usbd_device * usbd_dev, uint16_t wValue) -{ - (void) wValue; - (void) usbd_dev; - - usbd_ep_setup (usbd_dev, 0x81, USB_ENDPOINT_ATTR_INTERRUPT, 4, NULL); - usbd_ep_setup (usbd_dev, 0x82, USB_ENDPOINT_ATTR_INTERRUPT, 4, NULL); - usbd_ep_setup (usbd_dev, 0x83, USB_ENDPOINT_ATTR_INTERRUPT, 4, NULL); - - usbd_register_control_callback (usbd_dev, - USB_REQ_TYPE_STANDARD | - USB_REQ_TYPE_INTERFACE, - USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT, - usb_control_request); - -#ifdef INCLUDE_DFU_INTERFACE - usbd_register_control_callback (usbd_dev, - USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE, - USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT, - dfu_control_request); -#endif -} - -/* Buffer to be used for control requests. */ -static uint8_t usbd_control_buffer[128]; - -void -usb_init (void) -{ - - usbd_dev = - usbd_init (&stm32f103_usb_driver, &dev, &config, usb_strings, 3, - usbd_control_buffer, sizeof (usbd_control_buffer)); - - usbd_register_set_config_callback (usbd_dev, usb_set_config); - -} - -void -usb_run (void) -{ - while (1) - usbd_poll (usbd_dev); -} -- cgit v1.2.3