From 2dbcf8d1cc6bb849d6e521b849da1da9be041cc1 Mon Sep 17 00:00:00 2001 From: Joseph Coffland Date: Sat, 22 Jul 2017 01:42:23 -0700 Subject: [PATCH] Moved boot splash to main AVR firmware --- MANIFEST.in | 3 ++- Makefile | 7 ++++--- scripts/install.sh | 2 +- src/avr/src/command.c | 5 +++++ src/avr/src/command.h | 2 ++ src/{boot => avr}/src/lcd.c | 29 ++++++++++++++++++++++++++++- src/{boot => avr}/src/lcd.h | 2 ++ src/avr/src/main.c | 1 + src/avr/src/rtc.c | 2 ++ src/boot/src/boot.c | 13 ------------- src/py/lcd/__init__.py | 1 + 11 files changed, 48 insertions(+), 19 deletions(-) rename src/{boot => avr}/src/lcd.c (86%) rename src/{boot => avr}/src/lcd.h (98%) diff --git a/MANIFEST.in b/MANIFEST.in index 9dec892..16bff19 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,4 @@ recursive-include src/py/bbctrl/http * -include package.json README.md scripts/install.sh src/avr/bbctrl-avr-firmware.hex +include package.json README.md scripts/install.sh +include src/avr/bbctrl-avr-firmware.hex include scripts/avr109-flash.py diff --git a/Makefile b/Makefile index 167eeb6..a0f21e2 100644 --- a/Makefile +++ b/Makefile @@ -40,9 +40,10 @@ endif WATCH := src/jade src/jade/templates src/stylus src/js src/resources Makefile all: html css js static - @for SUB in $(SUBPROJECTS); do \ - $(MAKE) -C src/$$SUB; \ - done + @$(MAKE) -C src/avr + @$(MAKE) -C src/boot + @$(MAKE) -C src/pwr + @$(MAKE) -C src/jig copy: pkg rsync $(RSYNC_OPTS) pkg/$(PKG_NAME)/ $(DEST)/bbctrl/ diff --git a/scripts/install.sh b/scripts/install.sh index 1b27c96..7e09eae 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -19,7 +19,7 @@ if $UPDATE_PY; then fi if $UPDATE_AVR; then - ./scripts/avr109-flash.py avr/bbctrl-avr-firmware.hex + ./scripts/avr109-flash.py src/avr/bbctrl-avr-firmware.hex fi if $UPDATE_PY; then diff --git a/src/avr/src/command.c b/src/avr/src/command.c index 3939751..4104878 100644 --- a/src/avr/src/command.c +++ b/src/avr/src/command.c @@ -50,6 +50,7 @@ static char *_cmd = 0; +static bool _active = false; static void command_i2c_cb(i2c_cmd_t cmd, uint8_t *data, uint8_t length) { @@ -254,12 +255,16 @@ void command_callback() { } _cmd = 0; // Command consumed + _active = true; report_request(); if (status) status_error(status); } +bool command_is_active() {return _active;} + + // Command functions void static print_command_help(int i) { static const char fmt[] PROGMEM = " $%-12"PRPSTR" %"PRPSTR"\n"; diff --git a/src/avr/src/command.h b/src/avr/src/command.h index 67397ac..08dd468 100644 --- a/src/avr/src/command.h +++ b/src/avr/src/command.h @@ -29,6 +29,7 @@ #include +#include #define MAX_ARGS 16 @@ -48,3 +49,4 @@ void command_init(); int command_find(const char *name); int command_exec(int argc, char *argv[]); void command_callback(); +bool command_is_active(); diff --git a/src/boot/src/lcd.c b/src/avr/src/lcd.c similarity index 86% rename from src/boot/src/lcd.c rename to src/avr/src/lcd.c index 7379a2f..2050b94 100644 --- a/src/boot/src/lcd.c +++ b/src/avr/src/lcd.c @@ -27,6 +27,8 @@ \******************************************************************************/ #include "lcd.h" +#include "rtc.h" +#include "command.h" #include #include @@ -101,5 +103,30 @@ void lcd_putchar(uint8_t addr, uint8_t c) { void lcd_pgmstr(uint8_t addr, const char *s) { - while (*s) lcd_putchar(addr, *s++); + while (true) { + char c = pgm_read_byte(s++); + if (!c) break; + lcd_putchar(addr, c); + } +} + + +void _splash(uint8_t addr) { + lcd_init(addr); + lcd_goto(addr, 1, 1); + lcd_pgmstr(addr, PSTR("Controller booting")); + lcd_goto(addr, 3, 2); + lcd_pgmstr(addr, PSTR("Please wait...")); +} + + +void lcd_splash() { + _splash(0x27); + _splash(0x3f); +} + + +void lcd_rtc_callback() { + if (!command_is_active() && rtc_get_time() == 1000) + lcd_splash(); } diff --git a/src/boot/src/lcd.h b/src/avr/src/lcd.h similarity index 98% rename from src/boot/src/lcd.h rename to src/avr/src/lcd.h index 29fc616..96826f0 100644 --- a/src/boot/src/lcd.h +++ b/src/avr/src/lcd.h @@ -100,3 +100,5 @@ void lcd_write(uint8_t addr, uint8_t cmd, uint8_t flags); void lcd_goto(uint8_t addr, uint8_t x, uint8_t y); void lcd_putchar(uint8_t addr, uint8_t c); void lcd_pgmstr(uint8_t addr, const char *s); +void lcd_splash(); +void lcd_rtc_callback(); diff --git a/src/avr/src/main.c b/src/avr/src/main.c index 6250827..3668c55 100644 --- a/src/avr/src/main.c +++ b/src/avr/src/main.c @@ -42,6 +42,7 @@ #include "i2c.h" #include "pgmspace.h" #include "outputs.h" +#include "lcd.h" #include "plan/planner.h" #include "plan/arc.h" diff --git a/src/avr/src/rtc.c b/src/avr/src/rtc.c index e09c584..f3bc3f3 100644 --- a/src/avr/src/rtc.c +++ b/src/avr/src/rtc.c @@ -31,6 +31,7 @@ #include "switch.h" #include "huanyang.h" #include "motor.h" +#include "lcd.h" #include #include @@ -47,6 +48,7 @@ ISR(RTC_OVF_vect) { switch_rtc_callback(); huanyang_rtc_callback(); if (!(ticks & 255)) motor_rtc_callback(); + lcd_rtc_callback(); } diff --git a/src/boot/src/boot.c b/src/boot/src/boot.c index a2a6c5a..2b6c54d 100644 --- a/src/boot/src/boot.c +++ b/src/boot/src/boot.c @@ -28,7 +28,6 @@ #include "boot.h" #include "sp_driver.h" -#include "lcd.h" #include #include @@ -60,15 +59,6 @@ void clock_init() { } -void lcd_splash(uint8_t addr) { - lcd_init(addr); - lcd_goto(addr, 1, 1); - lcd_pgmstr(addr, "Controller booting"); - lcd_goto(addr, 3, 2); - lcd_pgmstr(addr, "Please wait..."); -} - - bool uart_has_char() {return UART_DEVICE.STATUS & USART_RXCIF_bm;} uint8_t uart_recv_char() {return UART_DEVICE.DATA;} @@ -458,9 +448,6 @@ int main() { // Disable further self programming until next reset SP_LockSPM(); - lcd_splash(0x27); - lcd_splash(0x3f); - // Jump to application code asm("jmp 0"); } diff --git a/src/py/lcd/__init__.py b/src/py/lcd/__init__.py index f8065f5..ab446ba 100755 --- a/src/py/lcd/__init__.py +++ b/src/py/lcd/__init__.py @@ -69,6 +69,7 @@ class LCD: def reset(self): + self.clear() time.sleep(0.050) self.write_nibble(3 << 4) # Home time.sleep(0.050) -- 2.27.0