From e7b97eb910cbaa9d6906aedd31d1ac49e1487059 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 15 Jun 2020 16:50:51 +0100 Subject: fish --- Makefile.include | 3 ++- app/gauge.c | 40 ++++++++++++++++++++++++++++------------ app/led.c | 2 +- app/oled1.c | 2 +- app/oled2.c | 2 +- app/project.h | 5 +++++ app/prototypes.h | 2 +- app/ticker.c | 10 ++++++---- 8 files changed, 45 insertions(+), 21 deletions(-) diff --git a/Makefile.include b/Makefile.include index 4f5cbd9..e33adb3 100644 --- a/Makefile.include +++ b/Makefile.include @@ -29,7 +29,8 @@ ARCH_FLAGS = -mthumb -mcpu=cortex-m3 $(FP_FLAGS) -mfix-cortex-m3-ldrd OOCD ?= openocd OOCD_INTERFACE ?= interface/stlink-v2.cfg -OOCD_BOARD ?= target/stm32f1x.cfg +OOCD_BOARD = ../target/stm32f103.cfg +#OOCD_BOARD ?= target/stm32f1x.cfg ################################################################################ # Black Magic Probe specific variables diff --git a/app/gauge.c b/app/gauge.c index c71d8d9..8632379 100644 --- a/app/gauge.c +++ b/app/gauge.c @@ -10,15 +10,16 @@ #define P2_P_PORT GPIOB -unsigned gauge_target; -static unsigned gauge_current; +int gauge_target; +static int gauge_current; +static unsigned zeroing = 1000; #define GUAGE_N_STATE 6 static unsigned gauge_state; static inline unsigned -ccw (unsigned v) +cw (unsigned v) { v += GUAGE_N_STATE - 1; @@ -30,7 +31,7 @@ ccw (unsigned v) static inline unsigned -cw (unsigned v) +ccw (unsigned v) { v += 1; @@ -71,19 +72,26 @@ p2 (int i) } - void gauge_ticker (void) { - if (gauge_current < gauge_target) { - gauge_state = cw (gauge_state); - gauge_current++; - } else if (gauge_current > gauge_target) { + if (zeroing) { + zeroing--; gauge_state = ccw (gauge_state); - gauge_current--; + gauge_current = -10; + } else { + + if (gauge_current < gauge_target) { + gauge_state = cw (gauge_state); + gauge_current++; + } else if (gauge_current > gauge_target) { + gauge_state = ccw (gauge_state); + gauge_current--; + } } + switch (gauge_state) { case 0: p1 (1); @@ -121,15 +129,23 @@ void gauge_test (void) { char buf[8]; +#if 0 uint32_t now = dwt_read_cycle_counter(); /*This wraps every 59.9 seconds or so */ now &= 0x3fffffff; /* now wraps every 15s */ now = now / (0x3fffffff / 810); gauge_target = now; +#else + + if (gauge_target == gauge_current) + gauge_target ^= 900; + +#endif + - sprintf (buf, "%3d", gauge_target); - font8x8_put_str (vram_1, buf, 90, 24); + sprintf (buf, "%6d", gauge_current); + font8x8_put_str (vram_1, buf, 80, 24); } diff --git a/app/led.c b/app/led.c index 4f5c084..57baa17 100644 --- a/app/led.c +++ b/app/led.c @@ -26,7 +26,7 @@ void led_set (void) { CLEAR (LED); - led = 200; + led = MS_TO_TICKS (200); } void diff --git a/app/oled1.c b/app/oled1.c index cb1767d..0798568 100644 --- a/app/oled1.c +++ b/app/oled1.c @@ -64,7 +64,7 @@ oled1_ticker (void) refresh_wdt++; - if ((refresh_wdt < 1000) && (!oled_sad)) + if ((refresh_wdt < MS_TO_TICKS (1000)) && (!oled_sad)) return; refresh_wdt = 0; diff --git a/app/oled2.c b/app/oled2.c index 93b9d0d..bccb4ba 100644 --- a/app/oled2.c +++ b/app/oled2.c @@ -64,7 +64,7 @@ oled2_ticker (void) refresh_wdt++; - if ((refresh_wdt < 1000) && (!oled_sad)) + if ((refresh_wdt < MS_TO_TICKS (1000)) && (!oled_sad)) return; refresh_wdt = 0; diff --git a/app/project.h b/app/project.h index e2e10c7..8c729d8 100644 --- a/app/project.h +++ b/app/project.h @@ -17,6 +17,11 @@ #include #include +#define TICK_BASE 9000 +#define TICK_DIV 12000 +#define TICKS_TO_US(a) (((a)*TICK_DIV*1000)/TICK_BASE) +#define MS_TO_TICKS(a) (((a)*1000)/TICKS_TO_US(1)) + #include "pins.h" #include "i2c.h" diff --git a/app/prototypes.h b/app/prototypes.h index 4eb3605..b7633ba 100644 --- a/app/prototypes.h +++ b/app/prototypes.h @@ -86,7 +86,7 @@ extern void oled2_shutdown(void); extern void font21x32_put_ch(uint8_t *vram, unsigned ch, unsigned x); extern void font21x32_put_str(uint8_t *vram, char *str, unsigned x); /* gauge.c */ -extern unsigned gauge_target; +extern int gauge_target; extern void gauge_ticker(void); extern void gauge_test(void); extern void gauge_init(void); diff --git a/app/ticker.c b/app/ticker.c index 8df4d38..eb7dfe5 100644 --- a/app/ticker.c +++ b/app/ticker.c @@ -1,10 +1,13 @@ #include "project.h" + + static volatile uint32_t ticks; static volatile uint32_t delay_ms_count; static uint32_t scale = 7; + void delay_us (uint32_t d) { @@ -34,7 +37,7 @@ sys_tick_handler (void) void delay_ms (uint32_t d) { - delay_ms_count = d; + delay_ms_count = MS_TO_TICKS (d); while (delay_ms_count); } @@ -49,8 +52,7 @@ ticker_init (void) systick_set_clocksource (STK_CSR_CLKSOURCE_AHB_DIV8); /* 72MHz / 8 = > 9Mhz */ - systick_set_reload (9000); - /* 9MHz / 9000 => 1kHz */ + systick_set_reload (TICK_DIV); systick_interrupt_enable(); systick_counter_enable(); @@ -63,7 +65,7 @@ ticker_init (void) while (v == ticks); - delay_us (1000); + delay_us (TICKS_TO_US (1)); w = ticks; v++; w -= v; -- cgit v1.2.3