summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroot <root@new-selene.erebei.org>2015-12-01 02:10:53 +0000
committerroot <root@new-selene.erebei.org>2015-12-01 02:10:53 +0000
commitb55240eb43a92c552003b8b324a385e041f84f12 (patch)
treeab932136ecfaa42e1e417e0253aebcc5b5f178aa
parent061430973e82995368d27ff9081391f9475da3c7 (diff)
downloadcandlestick-b55240eb43a92c552003b8b324a385e041f84f12.tar.gz
candlestick-b55240eb43a92c552003b8b324a385e041f84f12.tar.bz2
candlestick-b55240eb43a92c552003b8b324a385e041f84f12.zip
fish
-rw-r--r--Makefile5
-rw-r--r--Makefile.rules2
-rw-r--r--app/.Makefile.swobin12288 -> 0 bytes
-rw-r--r--app/.Makefile.swpbin4096 -> 0 bytes
-rw-r--r--app/.usart.c.swnbin4096 -> 0 bytes
-rw-r--r--app/.usart.c.swobin16384 -> 0 bytes
-rw-r--r--app/Makefile4
-rw-r--r--app/code.c95
-rw-r--r--app/crypto.c144
-rw-r--r--app/crypto.ld1
-rw-r--r--app/dfu.c2
-rw-r--r--app/i2c.c3
-rw-r--r--app/keypad.c155
-rw-r--r--app/lcd.c3
-rw-r--r--app/led.c40
-rw-r--r--app/main.c24
-rw-r--r--app/project.h10
-rw-r--r--app/prototypes.h62
-rw-r--r--app/ticker.c32
-rw-r--r--app/usb.c44
-rw-r--r--host/Makefile21
-rw-r--r--host/main.c17
22 files changed, 246 insertions, 418 deletions
diff --git a/Makefile b/Makefile
index db356c8..aca7ac3 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,7 @@
-default:app.dummy
+default:app.dummy host.dummy
+
+host.dummy:
+ make -C host
app.dummy: libopencm3.dummy
make -C app
diff --git a/Makefile.rules b/Makefile.rules
index 0e521e6..8d1cecb 100644
--- a/Makefile.rules
+++ b/Makefile.rules
@@ -98,7 +98,7 @@ CPPFLAGS += -MD
CPPFLAGS += -Wall -Wundef
INCLUDES = -I$(INCLUDE_DIR)
-DEFINES = $(DEFS)
+DEFINES += $(DEFS)
CPPFLAGS += $(INCLUDES) $(DEFINES)
diff --git a/app/.Makefile.swo b/app/.Makefile.swo
deleted file mode 100644
index c28d39f..0000000
--- a/app/.Makefile.swo
+++ /dev/null
Binary files differ
diff --git a/app/.Makefile.swp b/app/.Makefile.swp
deleted file mode 100644
index db8a3c3..0000000
--- a/app/.Makefile.swp
+++ /dev/null
Binary files differ
diff --git a/app/.usart.c.swn b/app/.usart.c.swn
deleted file mode 100644
index 88c369d..0000000
--- a/app/.usart.c.swn
+++ /dev/null
Binary files differ
diff --git a/app/.usart.c.swo b/app/.usart.c.swo
deleted file mode 100644
index e5985d3..0000000
--- a/app/.usart.c.swo
+++ /dev/null
Binary files differ
diff --git a/app/Makefile b/app/Makefile
index c875b94..b9606ca 100644
--- a/app/Makefile
+++ b/app/Makefile
@@ -21,14 +21,16 @@ CPROTO=cproto
PROG=crypto
+
V=1
default: ${PROG}.elf
-CSRCS=dfu.c crypto.c main.c usb.c led.c ticker.c i2c.c lcd.c keypad.c code.c
+CSRCS=dfu.c main.c usb.c led.c ticker.c i2c.c lcd.c adc.c state.c key.c keyboard.c crypto.c map.c
BINARY = ${PROG}
OBJS = ${CSRCS:%.c=%.o}
+DEFINES=-DSLIM
include ../Makefile.include
diff --git a/app/code.c b/app/code.c
index 4d32f7b..3f4862a 100644
--- a/app/code.c
+++ b/app/code.c
@@ -7,92 +7,65 @@ static int hide;
static int show;
-void code_display(void)
+void
+code_display (void)
{
-size_t i;
+ size_t i;
-#if 0
-lcd_erase_line(0,16);
+#if 1
+ lcd_erase_line (0, 16);
-if (code_len!=16)
- lcd_write("Enter code:",0,0);
-else
- lcd_write("Code entered:",0,0);
+ if (code_len != 16)
+ lcd_write ("Enter code:", 0, 0);
+ else
+ lcd_write ("Code entered:", 0, 0);
#endif
- for (i=0;i<sizeof(code);++i)
- lcd_write_char(hide ? '*': (code[i] ? code[i]:' '),i,1);
+ for (i = 0; i < sizeof (code); ++i)
+ lcd_write_char (hide ? '*' : (code[i] ? code[i] : ' '), i, 1);
lcd_backlight (!hide);
}
-int
-vendor_control_request (usbd_device * usbd_dev, struct usb_setup_data *req,
- uint8_t ** buf, uint16_t * len,
- int (**complete) (usbd_device * usbd_dev,
- struct usb_setup_data * req))
+void
+code_tick (void)
{
- (void) buf;
- (void) len;
- (void) usbd_dev;
-
- (void) complete;
-
- if ((req->bmRequestType & 0x7F) != 0x41)
- return 0; /* Only accept vendor request. */
-
- switch (req->bRequest)
+ if (!show)
+ return;
+ show--;
+ if (!show)
{
-
- case 0x34:
- (*buf)[0] = 0x1;
- (*buf)[1] = 0;
- (*buf)[2] = 0;
- (*buf)[3] = 0;
- (*buf)[4] = 0x2;
- (*buf)[5] = 0; /* iString not used here */
- *len = 6;
- return 1;
- }
-
- return 0;
-
-}
-
-
-void code_tick(void)
-{
-if (!show) return;
-show--;
- if (!show) {
- hide++;
- code_display();
- }
+ hide++;
+ code_display ();
+ }
}
-void key_event (uint8_t v, int ud)
+void
+key_event (uint8_t v, int ud)
{
- if (!ud) return;
+ if (!ud)
+ return;
+
+ if (code_len == sizeof (code))
+ {
+ code_len = 0;
+ memset (code, ' ', sizeof (code));
+ }
- if (code_len==sizeof(code)) {
- code_len=0;
- memset(code,' ',sizeof(code));
- }
+ show = 5000;
+ hide = 0;
- show=5000;
- hide=0;
+ code[code_len++] = v;
- code[code_len++]=v;
+ code_display ();
- code_display();
-
}
diff --git a/app/crypto.c b/app/crypto.c
index 4a0098d..494e5ab 100644
--- a/app/crypto.c
+++ b/app/crypto.c
@@ -1,116 +1,48 @@
#include "project.h"
+#include "../common/vendor_req.h"
-static const uint8_t crypto_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) */
- 0x26, 0xff, 0x00, /* Logical maximum (255) */
- //0x26, 0x7f, 0x00, /* Logical maximum (255) */
- 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) */
- 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
- 0x09, 0x80, /* USAGE (System Control) */
- 0xA1, 0x01, /* COLLECTION (Application) */
- 0x75, 0x02, /* REPORT_SIZE (2) */
- 0x95, 0x01, /* REPORT_COUNT (1) */
- 0x15, 0x01, /* LOGICAL_MIN (1) */
- 0x25, 0x03, /* LOGICAL_MAX (3) */
- 0x09, 0x82, /* USAGE (System Sleep) */
- 0x09, 0x81, /* USAGE (System Power Down) */
- 0x09, 0x83, /* USAGE (System Wake Up) */
- 0x81, 0x60, /* INPUT (Data Ary Abs NPrf Null) */
- 0x75, 0x06, /* REPORT_SIZE (6) */
- 0x81, 0x03, /* INPUT (Cnst Var Abs) */
- 0xc0, /* END COLLECTION */
- 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)) crypto_function =
+int
+crypto_control (uint8_t request, uint16_t value, uint16_t index, void *buf,
+ size_t len)
{
- .hid_descriptor =
- {
- .bLength = sizeof (crypto_function),.bDescriptorType =
- USB_DT_HID,.bcdHID = 0x0100,.bCountryCode = 0,.bNumDescriptors = 1,}
- ,.hid_report =
- {
- .bReportDescriptorType = USB_DT_REPORT,.wDescriptorLength =
- sizeof (crypto_report_descriptor),}
-,};
-
-const struct usb_endpoint_descriptor crypto_endpoint = {
- .bLength = USB_DT_ENDPOINT_SIZE,
- .bDescriptorType = USB_DT_ENDPOINT,
- .bEndpointAddress = 0x81,
- .bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT,
- .wMaxPacketSize = 9,
- .bInterval = 0x1 //0x20,
-};
-
-const struct usb_interface_descriptor crypto_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, /* crypto */
- .iInterface = 5,
- .endpoint = &crypto_endpoint,
- .extra = &crypto_function,
- .extralen = sizeof (crypto_function),
-};
-
-
-void
-crypto_get_descriptor (uint8_t ** buf, uint16_t * len)
-{
-
- /* Handle the HID report descriptor. */
- *buf = (uint8_t *) crypto_report_descriptor;
- *len = sizeof (crypto_report_descriptor);
+ (void) index;
+ (void) buf;
+ (void) len;
+
+
+ switch (request)
+ {
+
+ case VENDOR_REQ_KEYPRESS:
+ send_ascii (value);
+ return 1;
+ case VENDOR_REQ_SET_KEY:
+ key_set (buf, len);
+ return 1;
+ case VENDOR_REQ_SEND_KEY:
+ key_send ();
+ return 1;
+ case VENDOR_REQ_CLEAR_KEY:
+ key_wipe ();
+ return 1;
+ }
+
+ return 0;
}
-void
-crypto_test (void)
+int
+vendor_control_request (usbd_device * usbd_dev, struct usb_setup_data *req,
+ uint8_t ** buf, uint16_t * len,
+ int (**complete) (usbd_device * usbd_dev,
+ struct usb_setup_data * req))
{
- static int c = 0;
- uint8_t buf[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-
-
- buf[0] = (c >> 1) & 7;
-
- buf[2] = (c & 1) ? 12 : 0;
+ (void) usbd_dev;
+ (void) complete;
- c++;
+ if (req->bmRequestType !=
+ (USB_REQ_TYPE_OUT | USB_REQ_TYPE_VENDOR | USB_REQ_TYPE_DEVICE))
+ return 0;
- usbd_ep_write_packet (usbd_dev, 0x81, buf, 9);
+ return crypto_control (req->bRequest, req->wValue, req->wIndex, *buf, *len);
}
diff --git a/app/crypto.ld b/app/crypto.ld
index a2d5a9c..829da07 100644
--- a/app/crypto.ld
+++ b/app/crypto.ld
@@ -37,6 +37,7 @@ SECTIONS
{
.dfu_shared dfu_shared_location :{
dfu_flag = .;
+ bkp_moo = 4 + dfu_flag;
}
}
diff --git a/app/dfu.c b/app/dfu.c
index cc89d4e..8a4a3cc 100644
--- a/app/dfu.c
+++ b/app/dfu.c
@@ -21,7 +21,7 @@ const struct usb_interface_descriptor dfu_iface = {
.bInterfaceClass = 0xFE,
.bInterfaceSubClass = 1,
.bInterfaceProtocol = 1,
- .iInterface = 6,
+ .iInterface = 7,
.extra = &dfu_function,
.extralen = sizeof (dfu_function),
diff --git a/app/i2c.c b/app/i2c.c
index 89249d0..5e00f3d 100644
--- a/app/i2c.c
+++ b/app/i2c.c
@@ -1,6 +1,8 @@
#include "project.h"
+#ifndef SLIM
+
#define GPIO_SCL GPIOB
#define GPIO_SDA GPIOB
#define SCL GPIO13
@@ -130,3 +132,4 @@ i2c_bb_init (void)
}
+#endif
diff --git a/app/keypad.c b/app/keypad.c
deleted file mode 100644
index d4a82db..0000000
--- a/app/keypad.c
+++ /dev/null
@@ -1,155 +0,0 @@
-#include "project.h"
-
-#define GPIO_CLOCK GPIOA
-#define GPIO_DATA GPIOB
-#define CLOCK GPIO5
-#define DATA GPIO11
-
-#define KEYPAD_DELAY do { delay_us(1); } while (0)
-
-
-#define SCAN_INTERVAL 73
-#define DEBOUNCE_INTERVAL 1
-#define DEBOUNCE_COUNT 3
-
-static uint32_t next_scan;
-
-
-uint16_t
-keypad_raw_read (void)
-{
- uint16_t ret = 0;
- uint16_t c;
-
-/*Reset the state machine in the keypad */
-
- gpio_set (GPIO_DATA, DATA);
- KEYPAD_DELAY;
- gpio_clear (GPIO_DATA, DATA);
- KEYPAD_DELAY;
- gpio_set (GPIO_DATA, DATA);
- KEYPAD_DELAY;
-
- gpio_clear (GPIO_CLOCK, CLOCK);
- KEYPAD_DELAY;
-
- for (c = 0x8000; c; c >>= 1)
- {
- gpio_set (GPIO_CLOCK, CLOCK);
- KEYPAD_DELAY;
- if (!(gpio_get (GPIO_DATA, DATA) & DATA))
- ret |= c;
- gpio_clear (GPIO_CLOCK, CLOCK);
- KEYPAD_DELAY;
- }
-
- gpio_set (GPIO_CLOCK, CLOCK);
-
- return ret;
-}
-
-uint16_t
-keypad_read (void)
-{
- int c;
- const uint8_t lut[] = "cdef89ab45670123";
- uint8_t ret = 0;
-
-
-
-/*Reset the state machine in the keypad */
-
- gpio_set (GPIO_DATA, DATA);
- KEYPAD_DELAY;
- gpio_clear (GPIO_DATA, DATA);
- KEYPAD_DELAY;
- gpio_set (GPIO_DATA, DATA);
- KEYPAD_DELAY;
-
- gpio_clear (GPIO_CLOCK, CLOCK);
- KEYPAD_DELAY;
-
- for (c = 0; c < 16; ++c)
- {
- gpio_set (GPIO_CLOCK, CLOCK);
- KEYPAD_DELAY;
- if (!(gpio_get (GPIO_DATA, DATA) & DATA))
- ret = lut[c];
- gpio_clear (GPIO_CLOCK, CLOCK);
- KEYPAD_DELAY;
- }
-
- gpio_set (GPIO_CLOCK, CLOCK);
-
- return ret;
-}
-
-
-static void
-keypad_scan (void)
-{
- static uint8_t last_v;
- static uint8_t key_down;
- static int same;
- uint8_t v;
-
- v = keypad_read ();
-
- next_scan = DEBOUNCE_INTERVAL;
-
- if (v!=last_v) {
- last_v=v;
- same=0;
- return;
- } else {
- if (same<DEBOUNCE_COUNT) {
- same++;
- return;
- }
- }
-
- if (!v && !key_down) {
- next_scan = SCAN_INTERVAL;
- return;
- }
-
- if (key_down==v) {
- return;
- } else if (key_down!=v) {
- if (key_down)
- key_event (key_down, 0);
- key_down=v;
- if (key_down)
- key_event (key_down, 1);
- }
-}
-
-
-
-
-void
-keypad_tick (void)
-{
-
- if (!next_scan)
- keypad_scan ();
- else
- next_scan--;
-
-}
-
-
-
-
-void
-keypad_init (void)
-{
-
- gpio_set_mode (GPIO_CLOCK, GPIO_MODE_OUTPUT_50_MHZ,
- GPIO_CNF_OUTPUT_OPENDRAIN, CLOCK);
- gpio_set_mode (GPIO_DATA, GPIO_MODE_OUTPUT_50_MHZ,
- GPIO_CNF_OUTPUT_OPENDRAIN, DATA);
-
-
-
-}
diff --git a/app/lcd.c b/app/lcd.c
index 714e850..911b798 100644
--- a/app/lcd.c
+++ b/app/lcd.c
@@ -1,5 +1,7 @@
#include "project.h"
+#ifndef SLIM
+
#define FOO do { printf("lcd:%x\r\n",__LINE__); usart1_drain(); } while (0)
#define PCF8574_I2C_ADDRESS 0x27
@@ -342,3 +344,4 @@ lcd_shutdown (void)
lcd_backlight (0);
off ();
}
+#endif
diff --git a/app/led.c b/app/led.c
index ddbbc34..dfa343e 100644
--- a/app/led.c
+++ b/app/led.c
@@ -1,7 +1,10 @@
#include "project.h"
+#define LED_PERIOD 1000
+
+static int led_on = 0;
+static int led_cycle = 0;
-static int led = 0;
void
led_init (void)
@@ -17,34 +20,37 @@ void
led_blink (void)
{
gpio_set (GPIOA, GPIO9);
- led = 50;
+ led_on = 50;
}
void
led_tick (void)
{
-#if 0
- if (led)
+ if (led_on)
{
- led--;
- if (!led)
+ led_on--;
+ if (!led_on)
gpio_clear (GPIOA, GPIO9);
}
-#else
- static int c;
- c++;
- if (c > 1000)
+ led_cycle++;
+
+ if (led_cycle == LED_PERIOD)
{
- led ^= 1;
- if (led)
- gpio_set (GPIOA, GPIO9);
- else
- gpio_clear (GPIOA, GPIO9);
+ led_cycle = 0;
+
- c = 0;
+ if (have_key && locked)
+ led_on = 50;
+ if (have_key && !locked)
+ led_on = 500;
+ if (!have_key)
+ led_on = 1000;
+
+ gpio_set (GPIOA, GPIO9);
+
}
-#endif
+
}
diff --git a/app/main.c b/app/main.c
index d1c9b27..4f8f6f7 100644
--- a/app/main.c
+++ b/app/main.c
@@ -1,6 +1,9 @@
#include "project.h"
+
extern uint32_t dfu_flag;
+
+
int
main (void)
{
@@ -11,7 +14,7 @@ main (void)
rcc_clock_setup_in_hse_8mhz_out_48mhz ();
- /*turn on clocks to periferals */
+ /*turn on clocks to peripherals */
rcc_periph_clock_enable (RCC_GPIOA);
rcc_periph_clock_enable (RCC_GPIOB);
rcc_periph_clock_enable (RCC_GPIOC);
@@ -19,27 +22,16 @@ main (void)
ticker_init ();
led_init ();
+#ifndef SLIM
i2c_bb_init ();
lcd_init ();
- keypad_init ();
-
-
-
-#if 0
- {
- char buf[16];
- sprintf (buf, "%x", dfu_flag);
- lcd_write (buf, 0, 1);
- }
#endif
- lcd_write ("Booting...", 0, 0);
-
-
+ adc_init ();
+ key_init ();
+ state_init ();
usb_init ();
- code_display();
-
usb_run ();
return 0;
diff --git a/app/project.h b/app/project.h
index 19bb5b2..3b34853 100644
--- a/app/project.h
+++ b/app/project.h
@@ -1,7 +1,10 @@
#include <stdlib.h>
#include <libopencm3/stm32/rcc.h>
+#include <libopencm3/stm32/pwr.h>
+#include <libopencm3/stm32/f1/bkp.h>
#include <libopencm3/stm32/flash.h>
#include <libopencm3/stm32/gpio.h>
+#include <libopencm3/stm32/adc.h>
#include <libopencm3/stm32/usart.h>
#include <libopencm3/stm32/usb.h>
#include <libopencm3/cm3/systick.h>
@@ -20,7 +23,14 @@
#include <errno.h>
+#ifndef SLIM
#include "i2c.h"
+#endif
+#define RETENTION_TIME 10000
+
+#ifndef USB_REQ_TYPE_OUT
+#define USB_REQ_TYPE_OUT 0x0
+#endif
#include "prototypes.h"
diff --git a/app/prototypes.h b/app/prototypes.h
index 9a89a8c..72401f1 100644
--- a/app/prototypes.h
+++ b/app/prototypes.h
@@ -2,11 +2,6 @@
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, int (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req));
-/* crypto.c */
-extern const struct usb_endpoint_descriptor crypto_endpoint;
-extern const struct usb_interface_descriptor crypto_iface;
-extern void crypto_get_descriptor(uint8_t **buf, uint16_t *len);
-extern void crypto_test(void);
/* main.c */
extern int main(void);
/* usb.c */
@@ -15,6 +10,8 @@ extern const struct usb_interface ifaces[];
extern const struct usb_config_descriptor config;
extern usbd_device *usbd_dev;
extern int usb_is_suspended;
+extern int usb_running;
+extern void usb_tick(void);
extern int usb_wakeup_host(void);
extern void usb_set_config(usbd_device *usbd_dev, uint16_t wValue);
extern void usb_init(void);
@@ -31,33 +28,32 @@ extern void delay_ms(uint32_t d);
extern int timed_out(uint32_t then, unsigned int ms);
extern void ticker_init(void);
/* i2c.c */
-extern int i2c_bb(int scl, int sda);
-extern void i2c_bb_start(void);
-extern void i2c_bb_stop(void);
-extern int i2c_bb_send_data(uint8_t v);
-extern int i2c_bb_start_transaction(uint8_t a, int wnr);
-extern void i2c_bb_init(void);
/* lcd.c */
-extern uint8_t fb[2][16];
-extern uint8_t shadow[2][16];
-extern void lcd_refresh(void);
-extern void lcd_tick(void);
-extern void lcd_write_char(uint8_t c, int x, int y);
-extern void lcd_erase(int x, int y, int w);
-extern void lcd_erase_line(int w, int y);
-extern void lcd_erase_all(void);
-extern void lcd_write(char *c, int x, int y);
-extern void lcd_backlight(int i);
-extern void lcd_reset(void);
-extern void lcd_init(void);
-extern void lcd_shutdown(void);
-/* keypad.c */
-extern uint16_t keypad_raw_read(void);
-extern uint16_t keypad_read(void);
-extern void keypad_tick(void);
-extern void keypad_init(void);
-/* code.c */
-extern void code_display(void);
+/* adc.c */
+extern int host_has_power;
+extern void adc_tick(void);
+extern void adc_init(void);
+/* state.c */
+extern uint32_t up_time;
+extern uint32_t down_time;
+extern int locked;
+extern void state_show(void);
+extern void state_tick(void);
+extern void state_init(void);
+/* key.c */
+extern int have_key;
+extern void key_wipe(void);
+extern void key_set(char *in, size_t len);
+extern void key_send(void);
+extern void key_init(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_keypress(int m, int k);
+/* crypto.c */
+extern int crypto_control(uint8_t request, uint16_t value, uint16_t index, void *buf, size_t len);
extern int vendor_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, int (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req));
-extern void code_tick(void);
-extern void key_event(uint8_t v, int ud);
+/* map.c */
+extern void send_ascii(unsigned char a);
+extern void send_str(const char *c);
diff --git a/app/ticker.c b/app/ticker.c
index d054317..cdab461 100644
--- a/app/ticker.c
+++ b/app/ticker.c
@@ -6,6 +6,7 @@ volatile uint32_t ticks;
static uint32_t scale = 7;
+
void
delay_us (uint32_t d)
{
@@ -16,11 +17,17 @@ delay_us (uint32_t d)
}
}
+static void
+s_tick_handler (void)
+{
+ adc_tick ();
+ state_tick ();
+}
void
sys_tick_handler (void)
{
- //uint8_t d;
+ static int s_count;
if (delay_ms_count)
delay_ms_count--;
@@ -28,9 +35,22 @@ sys_tick_handler (void)
ticks++;
led_tick ();
+#ifndef SLIM
lcd_tick ();
- keypad_tick ();
- code_tick();
+#endif
+
+ usb_tick();
+
+#if 0
+ s_count++;
+ if (s_count >= 1000)
+ {
+ s_count = 0;
+ s_tick_handler ();
+ }
+#else
+ s_tick_handler ();
+#endif
}
@@ -60,9 +80,9 @@ ticker_init (void)
/*Start periodic timer */
systick_set_clocksource (STK_CSR_CLKSOURCE_AHB_DIV8);
- /* 48MHz / 8 = > 6Mhz */
- systick_set_reload (6000);
- /* 6MHz / 6000 => 1kHz */
+ /* 24MHz / 8 = > 3Mhz */
+ systick_set_reload (3000);
+ /* 3MHz / 3000 => 1kHz */
systick_interrupt_enable ();
systick_counter_enable ();
diff --git a/app/usb.c b/app/usb.c
index 2dfac76..d464ea4 100644
--- a/app/usb.c
+++ b/app/usb.c
@@ -21,7 +21,7 @@ const struct usb_device_descriptor dev = {
const struct usb_interface ifaces[] = {
{
.num_altsetting = 1,
- .altsetting = &crypto_iface,
+ .altsetting = &keyboard_iface,
},
{
.num_altsetting = 1,
@@ -47,7 +47,8 @@ static const char *usb_strings[] = {
"bootpad",
"bootpad",
"composite",
- "bootpad",
+ "bootpad keyboard",
+ "bootpad control",
"bootpad dfu device",
};
@@ -57,6 +58,34 @@ usbd_device *usbd_dev;
int usb_is_suspended = 0;
+int usb_running =0;
+
+static int time_since_sof;
+
+
+
+void usb_tick(void)
+{
+#ifndef SLIM
+char buf[16];
+#endif
+
+time_since_sof++;
+
+if (time_since_sof>100) usb_running=0;
+
+#ifndef SLIM
+sprintf(buf,"%d",time_since_sof);
+lcd_write(buf,0,0);
+#endif
+
+}
+
+static void usb_sof(void)
+{
+usb_running=1;
+time_since_sof=0;
+}
static void
usb_suspended (void)
@@ -107,14 +136,16 @@ usb_control_request (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))
+
+ if ((req->bmRequestType !=
+ (USB_REQ_TYPE_IN | USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_INTERFACE))
+ || (req->bRequest != USB_REQ_GET_DESCRIPTOR) || (req->wValue != 0x2200))
return 0;
switch (req->wIndex)
{
case 0:
- crypto_get_descriptor (buf, len);
+ keyboard_get_descriptor (buf, len);
return 1;
}
@@ -144,7 +175,7 @@ usb_set_config (usbd_device * usbd_dev, uint16_t wValue)
usbd_register_control_callback (usbd_dev,
- USB_REQ_TYPE_VENDOR | USB_REQ_TYPE_INTERFACE,
+ USB_REQ_TYPE_VENDOR | USB_REQ_TYPE_DEVICE,
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
vendor_control_request);
@@ -164,6 +195,7 @@ usb_init (void)
usbd_register_set_config_callback (usbd_dev, usb_set_config);
usbd_register_suspend_callback (usbd_dev, usb_suspended);
usbd_register_resume_callback (usbd_dev, usb_resumed);
+ usbd_register_sof_callback(usbd_dev, usb_sof);
}
diff --git a/host/Makefile b/host/Makefile
index 667d094..317bc59 100644
--- a/host/Makefile
+++ b/host/Makefile
@@ -1,17 +1,24 @@
INCLUDES=$(shell pkg-config --cflags libusb-1.0)
-LIBS=$(shell pkg-config --libs libusb-1.0)
+LIBS=-Bstatic $(shell pkg-config --libs libusb-1.0) -lpthread -Bdynamic -ludev
-PROG=cryptopad
-CSRCS=main.c hexdump.c
+LDFLAGS=-s
+PROGS=main set get
+LIBSRCS=hexdump.c
-OBJS=${CSRCS:%.c=%.o}
+LIBOBJS=${LIBSRCS:%.c=%.o}
CFLAGS=${OPT}
CPPFLAGS=${INCLUDES} ${DEFINES}
-${PROG}:${OBJS}
- ${CC} ${CPPFLAGS} ${CFLAGS} ${LDFLAGS} -o $@ ${OBJS} ${LIBS}
+default:${PROGS}
+
+
+${PROGS}: %:%.o ${LIBOBJS}
+ ${CC} ${CPPFLAGS} ${CFLAGS} ${LDFLAGS} -o $@ $@.o ${OBJS} ${LIBS}
+
+#${PROG}:${OBJS}
+# ${CC} ${CPPFLAGS} ${CFLAGS} ${LDFLAGS} -o $@ ${OBJS} ${LIBS}
clean:
- /bin/rm -f *~ *.d ${PROG} ${OBJS}
+ /bin/rm -f *~ *.d ${PROGS} ${OBJS}
diff --git a/host/main.c b/host/main.c
index a779cc1..5a61963 100644
--- a/host/main.c
+++ b/host/main.c
@@ -1,4 +1,5 @@
#include "project.h"
+#include "../common/vendor_req.h"
@@ -8,19 +9,21 @@ uint32_t timeout=4000;
char buf[128];
int len;
+
+
len= libusb_control_transfer( devh,
- /* bmRequestType */ LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_INTERFACE,
- /* bRequest */ 0x34,
- /* wValue */ 0x1234,
- /* wIndex */ 0x5678,
+ /* bmRequestType */ LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
+ /* bRequest */ VENDOR_REQ_KEYPRESS,
+ /* wValue */ 0x23,
+ /* wIndex */ 0,
/* Data */ buf,
/* wLength */ sizeof(buf), timeout );
-if (len>=0)
-hexdump(">",buf,len);
+//if (len>=0)
+//hexdump(">",buf,len);
}
@@ -87,7 +90,7 @@ int main(int argc,char *argv)
errx(EX_IOERR, "unable to initialize libusb: %i", ret);
- libusb_set_debug(ctx, 255);
+ //libusb_set_debug(ctx, 255);
probe_devices(ctx);