From: Joseph Coffland Date: Sat, 22 Jul 2017 08:42:23 +0000 (-0700) Subject: Moved boot splash to main AVR firmware X-Git-Url: https://git.buildbotics.com/?a=commitdiff_plain;h=2dbcf8d1cc6bb849d6e521b849da1da9be041cc1;p=bbctrl-firmware Moved boot splash to main AVR firmware --- 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/avr/src/lcd.c b/src/avr/src/lcd.c new file mode 100644 index 0000000..2050b94 --- /dev/null +++ b/src/avr/src/lcd.c @@ -0,0 +1,132 @@ +/******************************************************************************\ + + This file is part of the Buildbotics firmware. + + Copyright (c) 2015 - 2017 Buildbotics LLC + Copyright (c) 2010 Alex Forencich + All rights reserved. + + This file ("the software") is free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License, + version 2 as published by the Free Software Foundation. You should + have received a copy of the GNU General Public License, version 2 + along with the software. If not, see . + + The software is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the software. If not, see + . + + For information regarding this software email: + "Joseph Coffland" + +\******************************************************************************/ + +#include "lcd.h" +#include "rtc.h" +#include "command.h" + +#include +#include + +#include + + +void lcd_init(uint8_t addr) { + // Enable I2C master + TWIC.MASTER.BAUD = 0x9b; // 100 KHz with 32MHz clock + TWIC.MASTER.CTRLA = TWI_MASTER_ENABLE_bm; + TWIC.MASTER.CTRLB = TWI_MASTER_TIMEOUT_DISABLED_gc; + TWIC.MASTER.STATUS |= 1; // Force idle + + _delay_ms(50); + lcd_nibble(addr, 3 << 4); // Home + _delay_ms(50); + lcd_nibble(addr, 3 << 4); // Home + _delay_ms(50); + lcd_nibble(addr, 3 << 4); // Home + lcd_nibble(addr, 2 << 4); // 4-bit + + lcd_write(addr, + LCD_FUNCTION_SET | LCD_2_LINE | LCD_5x8_DOTS | LCD_4_BIT_MODE, 0); + lcd_write(addr, LCD_DISPLAY_CONTROL | LCD_DISPLAY_ON, 0); + lcd_write(addr, LCD_ENTRY_MODE_SET | LCD_ENTRY_SHIFT_INC, 0); + + lcd_write(addr, LCD_CLEAR_DISPLAY, 0); + lcd_write(addr, LCD_RETURN_HOME, 0); +} + + +static void _write_i2c(uint8_t addr, uint8_t data) { + data |= BACKLIGHT_BIT; + + TWIC.MASTER.ADDR = addr << 1; + while (!(TWIC.MASTER.STATUS & TWI_MASTER_WIF_bm)) continue; + + TWIC.MASTER.DATA = data; + while (!(TWIC.MASTER.STATUS & TWI_MASTER_WIF_bm)) continue; + + TWIC.MASTER.CTRLC = TWI_MASTER_CMD_STOP_gc; + + _delay_us(100); +} + + +void lcd_nibble(uint8_t addr, uint8_t data) { + _write_i2c(addr, data); + _write_i2c(addr, data | ENABLE_BIT); + _delay_us(500); + _write_i2c(addr, data & ~ENABLE_BIT); + _delay_us(100); +} + + +void lcd_write(uint8_t addr, uint8_t cmd, uint8_t flags) { + lcd_nibble(addr, flags | (cmd & 0xf0)); + lcd_nibble(addr, flags | ((cmd << 4) & 0xf0)); +} + + +void lcd_goto(uint8_t addr, uint8_t x, uint8_t y) { + static uint8_t row[] = {0, 64, 20, 84}; + lcd_write(addr, LCD_SET_DDRAM_ADDR | (row[y] + x), 0); +} + + +void lcd_putchar(uint8_t addr, uint8_t c) { + lcd_write(addr, c, REG_SELECT_BIT); +} + + +void lcd_pgmstr(uint8_t addr, const char *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/avr/src/lcd.h b/src/avr/src/lcd.h new file mode 100644 index 0000000..96826f0 --- /dev/null +++ b/src/avr/src/lcd.h @@ -0,0 +1,104 @@ +/******************************************************************************\ + + This file is part of the Buildbotics firmware. + + Copyright (c) 2015 - 2017 Buildbotics LLC + Copyright (c) 2010 Alex Forencich + All rights reserved. + + This file ("the software") is free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License, + version 2 as published by the Free Software Foundation. You should + have received a copy of the GNU General Public License, version 2 + along with the software. If not, see . + + The software is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the software. If not, see + . + + For information regarding this software email: + "Joseph Coffland" + +\******************************************************************************/ + +#pragma once + +#include + +#include + + +// Control flags +enum { + REG_SELECT_BIT = 1 << 0, + READ_BIT = 1 << 1, + ENABLE_BIT = 1 << 2, + BACKLIGHT_BIT = 1 << 3, +}; + + +// Commands +enum { + LCD_CLEAR_DISPLAY = 1 << 0, + LCD_RETURN_HOME = 1 << 1, + LCD_ENTRY_MODE_SET = 1 << 2, + LCD_DISPLAY_CONTROL = 1 << 3, + LCD_CURSOR_SHIFT = 1 << 4, + LCD_FUNCTION_SET = 1 << 5, + LCD_SET_CGRAM_ADDR = 1 << 6, + LCD_SET_DDRAM_ADDR = 1 << 7, +}; + + +// Entry Mode Set flags +#define LCD_ENTRY_SHIFT_DISPLAY (1 << 0) +#define LCD_ENTRY_SHIFT_INC (1 << 1) +#define LCD_ENTRY_SHIFT_DEC (0 << 1) + + +// Display Control flags +#define LCD_BLINK_ON (1 << 0) +#define LCD_BLINK_OFF (0 << 0) +#define LCD_CURSOR_ON (1 << 1) +#define LCD_CURSOR_OFF (0 << 1) +#define LCD_DISPLAY_ON (1 << 2) +#define LCD_DISPLAY_OFF (0 << 2) + + +// Cursor Shift flags +#define LCD_SHIFT_RIGHT (1 << 2) +#define LCD_SHIFT_LEFT (0 << 2) +#define LCD_SHIFT_DISPLAY (1 << 3) +#define LCD_SHIFT_CURSOR (0 << 3) + + +// Function Set flags +#define LCD_5x11_DOTS (1 << 2) +#define LCD_5x8_DOTS (0 << 2) +#define LCD_2_LINE (1 << 3) +#define LCD_1_LINE (0 << 3) +#define LCD_8_BIT_MODE (1 << 4) +#define LCD_4_BIT_MODE (0 << 4) + + +// Text justification flags +enum { + JUSTIFY_LEFT = 0, + JUSTIFY_RIGHT = 1, + JUSTIFY_CENTER = 2, +}; + + +void lcd_init(uint8_t addr); +void lcd_nibble(uint8_t addr, uint8_t data); +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/boot/src/lcd.c b/src/boot/src/lcd.c deleted file mode 100644 index 7379a2f..0000000 --- a/src/boot/src/lcd.c +++ /dev/null @@ -1,105 +0,0 @@ -/******************************************************************************\ - - This file is part of the Buildbotics firmware. - - Copyright (c) 2015 - 2017 Buildbotics LLC - Copyright (c) 2010 Alex Forencich - All rights reserved. - - This file ("the software") is free software: you can redistribute it - and/or modify it under the terms of the GNU General Public License, - version 2 as published by the Free Software Foundation. You should - have received a copy of the GNU General Public License, version 2 - along with the software. If not, see . - - The software is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the software. If not, see - . - - For information regarding this software email: - "Joseph Coffland" - -\******************************************************************************/ - -#include "lcd.h" - -#include -#include - -#include - - -void lcd_init(uint8_t addr) { - // Enable I2C master - TWIC.MASTER.BAUD = 0x9b; // 100 KHz with 32MHz clock - TWIC.MASTER.CTRLA = TWI_MASTER_ENABLE_bm; - TWIC.MASTER.CTRLB = TWI_MASTER_TIMEOUT_DISABLED_gc; - TWIC.MASTER.STATUS |= 1; // Force idle - - _delay_ms(50); - lcd_nibble(addr, 3 << 4); // Home - _delay_ms(50); - lcd_nibble(addr, 3 << 4); // Home - _delay_ms(50); - lcd_nibble(addr, 3 << 4); // Home - lcd_nibble(addr, 2 << 4); // 4-bit - - lcd_write(addr, - LCD_FUNCTION_SET | LCD_2_LINE | LCD_5x8_DOTS | LCD_4_BIT_MODE, 0); - lcd_write(addr, LCD_DISPLAY_CONTROL | LCD_DISPLAY_ON, 0); - lcd_write(addr, LCD_ENTRY_MODE_SET | LCD_ENTRY_SHIFT_INC, 0); - - lcd_write(addr, LCD_CLEAR_DISPLAY, 0); - lcd_write(addr, LCD_RETURN_HOME, 0); -} - - -static void _write_i2c(uint8_t addr, uint8_t data) { - data |= BACKLIGHT_BIT; - - TWIC.MASTER.ADDR = addr << 1; - while (!(TWIC.MASTER.STATUS & TWI_MASTER_WIF_bm)) continue; - - TWIC.MASTER.DATA = data; - while (!(TWIC.MASTER.STATUS & TWI_MASTER_WIF_bm)) continue; - - TWIC.MASTER.CTRLC = TWI_MASTER_CMD_STOP_gc; - - _delay_us(100); -} - - -void lcd_nibble(uint8_t addr, uint8_t data) { - _write_i2c(addr, data); - _write_i2c(addr, data | ENABLE_BIT); - _delay_us(500); - _write_i2c(addr, data & ~ENABLE_BIT); - _delay_us(100); -} - - -void lcd_write(uint8_t addr, uint8_t cmd, uint8_t flags) { - lcd_nibble(addr, flags | (cmd & 0xf0)); - lcd_nibble(addr, flags | ((cmd << 4) & 0xf0)); -} - - -void lcd_goto(uint8_t addr, uint8_t x, uint8_t y) { - static uint8_t row[] = {0, 64, 20, 84}; - lcd_write(addr, LCD_SET_DDRAM_ADDR | (row[y] + x), 0); -} - - -void lcd_putchar(uint8_t addr, uint8_t c) { - lcd_write(addr, c, REG_SELECT_BIT); -} - - -void lcd_pgmstr(uint8_t addr, const char *s) { - while (*s) lcd_putchar(addr, *s++); -} diff --git a/src/boot/src/lcd.h b/src/boot/src/lcd.h deleted file mode 100644 index 29fc616..0000000 --- a/src/boot/src/lcd.h +++ /dev/null @@ -1,102 +0,0 @@ -/******************************************************************************\ - - This file is part of the Buildbotics firmware. - - Copyright (c) 2015 - 2017 Buildbotics LLC - Copyright (c) 2010 Alex Forencich - All rights reserved. - - This file ("the software") is free software: you can redistribute it - and/or modify it under the terms of the GNU General Public License, - version 2 as published by the Free Software Foundation. You should - have received a copy of the GNU General Public License, version 2 - along with the software. If not, see . - - The software is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the software. If not, see - . - - For information regarding this software email: - "Joseph Coffland" - -\******************************************************************************/ - -#pragma once - -#include - -#include - - -// Control flags -enum { - REG_SELECT_BIT = 1 << 0, - READ_BIT = 1 << 1, - ENABLE_BIT = 1 << 2, - BACKLIGHT_BIT = 1 << 3, -}; - - -// Commands -enum { - LCD_CLEAR_DISPLAY = 1 << 0, - LCD_RETURN_HOME = 1 << 1, - LCD_ENTRY_MODE_SET = 1 << 2, - LCD_DISPLAY_CONTROL = 1 << 3, - LCD_CURSOR_SHIFT = 1 << 4, - LCD_FUNCTION_SET = 1 << 5, - LCD_SET_CGRAM_ADDR = 1 << 6, - LCD_SET_DDRAM_ADDR = 1 << 7, -}; - - -// Entry Mode Set flags -#define LCD_ENTRY_SHIFT_DISPLAY (1 << 0) -#define LCD_ENTRY_SHIFT_INC (1 << 1) -#define LCD_ENTRY_SHIFT_DEC (0 << 1) - - -// Display Control flags -#define LCD_BLINK_ON (1 << 0) -#define LCD_BLINK_OFF (0 << 0) -#define LCD_CURSOR_ON (1 << 1) -#define LCD_CURSOR_OFF (0 << 1) -#define LCD_DISPLAY_ON (1 << 2) -#define LCD_DISPLAY_OFF (0 << 2) - - -// Cursor Shift flags -#define LCD_SHIFT_RIGHT (1 << 2) -#define LCD_SHIFT_LEFT (0 << 2) -#define LCD_SHIFT_DISPLAY (1 << 3) -#define LCD_SHIFT_CURSOR (0 << 3) - - -// Function Set flags -#define LCD_5x11_DOTS (1 << 2) -#define LCD_5x8_DOTS (0 << 2) -#define LCD_2_LINE (1 << 3) -#define LCD_1_LINE (0 << 3) -#define LCD_8_BIT_MODE (1 << 4) -#define LCD_4_BIT_MODE (0 << 4) - - -// Text justification flags -enum { - JUSTIFY_LEFT = 0, - JUSTIFY_RIGHT = 1, - JUSTIFY_CENTER = 2, -}; - - -void lcd_init(uint8_t addr); -void lcd_nibble(uint8_t addr, uint8_t data); -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); 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)