From 15f6f34fe239b0b71cb2ef4fd16f278a23b52506 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 1 Dec 2015 02:22:22 +0000 Subject: fish --- app/project.h | 3 ++- app/prototypes.h | 19 +++++++++++++++++++ app/state.c | 27 +++++++++++++++++++++++---- app/ticker.c | 2 +- app/usb.c | 13 +------------ 5 files changed, 46 insertions(+), 18 deletions(-) diff --git a/app/project.h b/app/project.h index 3b34853..a8b773b 100644 --- a/app/project.h +++ b/app/project.h @@ -27,7 +27,8 @@ #include "i2c.h" #endif -#define RETENTION_TIME 10000 +#define POWER_RETENTION_TIME 10 +#define USB_RETENTION_TIME 60 #ifndef USB_REQ_TYPE_OUT #define USB_REQ_TYPE_OUT 0x0 diff --git a/app/prototypes.h b/app/prototypes.h index 72401f1..34d7863 100644 --- a/app/prototypes.h +++ b/app/prototypes.h @@ -28,7 +28,26 @@ 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); /* adc.c */ extern int host_has_power; extern void adc_tick(void); diff --git a/app/state.c b/app/state.c index 8ba1b3d..0c23260 100644 --- a/app/state.c +++ b/app/state.c @@ -1,6 +1,6 @@ #include "project.h" -uint32_t up_time, down_time; +uint32_t up_time, down_time,usb_up_time,usb_down_time; int locked; @@ -28,7 +28,7 @@ state_show (void) snprintf (buf, sizeof (buf), "%4s%3d %02d:%02d:%02d", up_time ? "up" : "down", d, h, m, s); - lcd_write (buf, 0, 0); + //lcd_write (buf, 0, 0); lcd_write (have_key ? " Key " : "No Key", 0, 1); @@ -42,7 +42,7 @@ void state_tick (void) { - if (host_has_power && usb_running) + if (host_has_power) { down_time = 0; up_time++; @@ -54,11 +54,30 @@ state_tick (void) locked = 0; } - if ((down_time > RETENTION_TIME) && have_key) + if ((down_time > POWER_RETENTION_TIME) && have_key) { key_wipe (); } + + if (usb_running) + { + usb_down_time = 0; + usb_up_time++; + } + else + { + usb_down_time++; + usb_up_time = 0; + locked = 0; + } + + if ((usb_down_time > USB_RETENTION_TIME) && have_key) + { + key_wipe (); + } + + state_show (); } diff --git a/app/ticker.c b/app/ticker.c index cdab461..3e25c12 100644 --- a/app/ticker.c +++ b/app/ticker.c @@ -41,7 +41,7 @@ sys_tick_handler (void) usb_tick(); -#if 0 +#if 1 s_count++; if (s_count >= 1000) { diff --git a/app/usb.c b/app/usb.c index d464ea4..3f5404a 100644 --- a/app/usb.c +++ b/app/usb.c @@ -66,19 +66,8 @@ 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 - +if (time_since_sof>3000) usb_running=0; } static void usb_sof(void) -- cgit v1.2.3