From 5950acfb05fb3e172fa5710f1cda6ab347f51f2f Mon Sep 17 00:00:00 2001 From: root Date: Thu, 13 Nov 2014 17:39:18 +0000 Subject: leds --- app/Makefile | 13 ++++++++----- app/keyboard.c | 2 +- app/kvm.c | 11 +++++++++-- app/led.c | 26 ++++++++++++++++++++++++++ app/main.c | 38 ++++++++++++++++++++++++++++---------- app/mouse.c | 2 +- app/project.h | 2 ++ app/prototypes.h | 6 ++++++ app/ring.c | 1 + app/tablet.c | 2 +- app/usart.c | 19 ++++++++++++------- app/usb.c | 2 +- 12 files changed, 96 insertions(+), 28 deletions(-) create mode 100644 app/led.c (limited to 'app') diff --git a/app/Makefile b/app/Makefile index 08febc7..f2dd0fc 100644 --- a/app/Makefile +++ b/app/Makefile @@ -20,20 +20,24 @@ 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 +CSRCS=dfu.c mouse.c keyboard.c main.c usb.c tablet.c usart.c kvm.c ring.c led.c BINARY = ${PROG} OBJS = ${CSRCS:%.c=%.o} -${PROG}.dfu:${PROG}.elf - ${OBJCOPY} -Obinary $< $@ +include ../Makefile.include + +DID=$(shell printf '\#include "id.h"\nID_PRODUCT' | ${CC} -I.. -E - | grep -v ^\# ) + +INCLUDES += -I.. dfu:${PROG}.dfu - dfu-util -R -a 0 -d 1d6b:0ee3 -s 0x08002000:leave -D $< + dfu-util -R -a 0 -d 1d6b:${DID} -s 0x08002000:leave -D $< program: ${PROG}.elf echo halt | nc -t localhost 4444 @@ -45,4 +49,3 @@ protos: ${CPROTO} $(INCLUDES) $(DEFINES) -e -v ${CSRCS} > prototypes.h.tmp mv -f prototypes.h.tmp prototypes.h -include ../Makefile.include diff --git a/app/keyboard.c b/app/keyboard.c index e9046a3..9799629 100644 --- a/app/keyboard.c +++ b/app/keyboard.c @@ -93,7 +93,7 @@ const struct usb_endpoint_descriptor keyboard_endpoint = { .bEndpointAddress = 0x81, .bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT, .wMaxPacketSize = 8, - .bInterval = 0x20, + .bInterval = 0x1 //0x20, }; const struct usb_interface_descriptor keyboard_iface = { diff --git a/app/kvm.c b/app/kvm.c index 3c8a900..54346bb 100644 --- a/app/kvm.c +++ b/app/kvm.c @@ -26,8 +26,13 @@ kvm_dispatch (void) addr, endpoint, len, buf[0], buf[1], buf[2], buf[3]); #endif - if (len) + if (len) { + if (endpoint==0x81) + led_set(GPIO8); + else + led_set(GPIO9); usbd_ep_write_packet (usbd_dev, endpoint, buf, len); + } } void @@ -82,10 +87,12 @@ kvm_recv (uint8_t d) buf[ptr++] = d; if (ptr >= len) { - if (!addr) + if (addr==BUS_ID) kvm_dispatch (); state = STATE_SYNC; } break; + default: + break; } } diff --git a/app/led.c b/app/led.c new file mode 100644 index 0000000..9481b2e --- /dev/null +++ b/app/led.c @@ -0,0 +1,26 @@ +#include "project.h" + + +static int led=0; + +void led_clear(void) +{ + gpio_set(GPIOB,GPIO8); + gpio_set(GPIOB,GPIO9); +} + +void led_set(uint32_t v) +{ + gpio_clear(GPIOB,v); + led=50; +} + +void led_tick(void) +{ +if (led) { + led--; + if (!led) led_clear(); +} +} + + diff --git a/app/main.c b/app/main.c index 508580d..495d240 100644 --- a/app/main.c +++ b/app/main.c @@ -4,12 +4,12 @@ extern uint32_t dfu_flag; void sys_tick_handler (void) { -#if 0 - printf ("fish\r\n"); - keyboard_test (); - mouse_test (); - tablet_test (); -#endif +uint8_t d; + +while (!ring_read_byte(&rx_ring,&d)) + kvm_recv(d); + +led_tick(); } int @@ -18,9 +18,14 @@ main (void) int i; - rcc_clock_setup_in_hsi_out_48mhz (); - rcc_periph_clock_enable (RCC_GPIOC); +// rcc_clock_setup_in_hsi_out_48mhz (); + //nvic_set_priority_grouping(NVIC_PriorityGroup_4); + + rcc_clock_setup_in_hse_8mhz_out_72mhz(); + rcc_periph_clock_enable (RCC_GPIOA); + rcc_periph_clock_enable (RCC_GPIOB); + rcc_periph_clock_enable (RCC_GPIOC); rcc_periph_clock_enable (RCC_AFIO); rcc_periph_clock_enable (RCC_USART1); @@ -31,16 +36,29 @@ main (void) systick_set_clocksource (STK_CSR_CLKSOURCE_AHB_DIV8); /* 48MHz / 8 = > 6Mhz */ - systick_set_reload (3000000); - /* 6MHz / 3000000 => 2Hz */ + systick_set_reload (6000); + /* 6MHz / 6000 => 1kHz */ systick_interrupt_enable (); systick_counter_enable (); + nvic_set_priority(NVIC_USART1_IRQ, 0x40); + nvic_set_priority(NVIC_SYSTICK_IRQ, 0xff); + + //nvic_set_priority(SysTick_IRQn, NVIC_EncodePriority(4,0,0)); + //nvic_set_priority(USART1_IRQn, NVIC_EncodePriority(4,1,0)); + + gpio_set (GPIOC, GPIO11); gpio_set_mode (GPIOC, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO11); + gpio_set_mode (GPIOB, GPIO_MODE_OUTPUT_2_MHZ, + GPIO_CNF_OUTPUT_PUSHPULL, GPIO8); + gpio_set_mode (GPIOB, GPIO_MODE_OUTPUT_2_MHZ, + GPIO_CNF_OUTPUT_PUSHPULL, GPIO9); + + led_clear(); for (i = 0; i < 0x80000; i++) diff --git a/app/mouse.c b/app/mouse.c index 6e0a207..0431349 100644 --- a/app/mouse.c +++ b/app/mouse.c @@ -67,7 +67,7 @@ const struct usb_endpoint_descriptor mouse_endpoint = { .bEndpointAddress = 0x82, .bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT, .wMaxPacketSize = 4, - .bInterval = 0x20, + .bInterval = 0x1, //0x20, }; const struct usb_interface_descriptor mouse_iface = { diff --git a/app/project.h b/app/project.h index 0323569..27b793f 100644 --- a/app/project.h +++ b/app/project.h @@ -18,6 +18,8 @@ #include #include +#include "id.h" + #include "ring.h" #include "prototypes.h" diff --git a/app/prototypes.h b/app/prototypes.h index 0e971df..cbfcf78 100644 --- a/app/prototypes.h +++ b/app/prototypes.h @@ -29,6 +29,8 @@ 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 ring_t rx_ring; +extern ring_t tx_ring; extern void usart1_isr(void); extern int _write(int file, char *ptr, int len); extern void usart_queue(uint8_t d); @@ -41,3 +43,7 @@ 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); +/* led.c */ +extern void led_clear(void); +extern void led_set(uint32_t v); +extern void led_tick(void); diff --git a/app/ring.c b/app/ring.c index 4f38e44..8925791 100644 --- a/app/ring.c +++ b/app/ring.c @@ -28,6 +28,7 @@ ring_write_byte (ring_t * r, uint8_t c) return -1; r->data[r->write] = c; + r->write = n; return 0; diff --git a/app/tablet.c b/app/tablet.c index 1073b37..5445c29 100644 --- a/app/tablet.c +++ b/app/tablet.c @@ -73,7 +73,7 @@ const struct usb_endpoint_descriptor tablet_endpoint = { .bEndpointAddress = 0x83, .bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT, .wMaxPacketSize = 6, - .bInterval = 0x20, + .bInterval = 0x1 //0x20, }; const struct usb_interface_descriptor tablet_iface = { diff --git a/app/usart.c b/app/usart.c index f510682..273c3bc 100644 --- a/app/usart.c +++ b/app/usart.c @@ -2,8 +2,11 @@ #define BUFFER_SIZE 256 -static ring_t output_ring; -static uint8_t output_ring_buf[BUFFER_SIZE]; +ring_t rx_ring; +static uint8_t rx_ring_buf[BUFFER_SIZE]; + +ring_t tx_ring; +static uint8_t tx_ring_buf[BUFFER_SIZE]; void usart1_isr (void) @@ -18,7 +21,7 @@ usart1_isr (void) /* Retrieve the data from the peripheral. */ data = usart_recv (USART1); - kvm_recv (data); + ring_write_byte(&rx_ring,data); } /* Check if we were called because of TXE. */ @@ -26,7 +29,7 @@ usart1_isr (void) ((USART_SR (USART1) & USART_SR_TXE) != 0)) { - if (ring_read_byte (&output_ring, &data)) + if (ring_read_byte (&tx_ring, &data)) { /*No more data, Disable the TXE interrupt, it's no longer needed. */ USART_CR1 (USART1) &= ~USART_CR1_TXEIE; @@ -46,7 +49,7 @@ _write (int file, char *ptr, int len) if (file == 1) { - ret = ring_write (&output_ring, (uint8_t *) ptr, len); + ret = ring_write (&tx_ring, (uint8_t *) ptr, len); if (ret < 0) ret = -ret; @@ -62,7 +65,8 @@ _write (int file, char *ptr, int len) void usart_queue (uint8_t d) { - ring_write_byte (&output_ring, d); + + ring_write_byte (&tx_ring, d); USART_CR1 (USART1) |= USART_CR1_TXEIE; #if 0 @@ -75,7 +79,8 @@ usart_queue (uint8_t d) void usart_init (void) { - ring_init (&output_ring, output_ring_buf, sizeof (output_ring_buf)); + ring_init (&tx_ring, tx_ring_buf, sizeof (tx_ring_buf)); + ring_init (&rx_ring, rx_ring_buf, sizeof (rx_ring_buf)); /* Enable the USART1 interrupt. */ nvic_enable_irq (NVIC_USART1_IRQ); diff --git a/app/usb.c b/app/usb.c index f796162..10ecd68 100644 --- a/app/usb.c +++ b/app/usb.c @@ -10,7 +10,7 @@ const struct usb_device_descriptor dev = { .bDeviceProtocol = 0, .bMaxPacketSize0 = 64, .idVendor = 0x1d6b, - .idProduct = 0x0ee3, + .idProduct = ID_PRODUCT, .bcdDevice = 0x0200, .iManufacturer = 1, .iProduct = 2, -- cgit v1.2.3