summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroot <root@lamia.panaceas.james.local>2015-12-01 02:22:22 +0000
committerroot <root@lamia.panaceas.james.local>2015-12-01 02:22:22 +0000
commit15f6f34fe239b0b71cb2ef4fd16f278a23b52506 (patch)
treed825203b06c00556618504b0feb81b7520e618f6
parentb4775420082f46cac862c8c55f23a68a2e96019d (diff)
downloadcandlestick-15f6f34fe239b0b71cb2ef4fd16f278a23b52506.tar.gz
candlestick-15f6f34fe239b0b71cb2ef4fd16f278a23b52506.tar.bz2
candlestick-15f6f34fe239b0b71cb2ef4fd16f278a23b52506.zip
fish
-rw-r--r--app/project.h3
-rw-r--r--app/prototypes.h19
-rw-r--r--app/state.c27
-rw-r--r--app/ticker.c2
-rw-r--r--app/usb.c13
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)