Merge pull request #1025 from XPila/MK3-new_lang

MMU2 communication - connection after reset, fw versions, state machine
This commit is contained in:
XPila 2018-08-09 17:45:08 +02:00 committed by GitHub
commit b2d734e93c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 124 additions and 88 deletions

View File

@ -1157,7 +1157,9 @@ void list_sec_lang_from_external_flash()
// are initialized by the main() routine provided by the Arduino framework.
void setup()
{
ultralcd_init();
mmu_init();
ultralcd_init();
spi_init();
@ -1777,11 +1779,6 @@ void setup()
wdt_enable(WDTO_4S);
#endif //WATCHDOG
puts_P(_N("Checking MMU unit..."));
if (mmu_init())
printf_P(_N("MMU ENABLED, finda=%hhd, version=%d\n"), mmu_finda, mmu_version);
else
puts_P(_N("MMU DISABLED"));
}
@ -2015,7 +2012,7 @@ void loop()
}
}
#endif //TMC2130
mmu_loop();
}
#define DEFINE_PGM_READ_ANY(type, reader) \
@ -3478,14 +3475,6 @@ void process_commands()
{
mmu_reset();
}
else if (code_seen("MMUFIN"))
{
mmu_read_finda();
}
else if (code_seen("MMUVER"))
{
mmu_read_version();
}
else if (code_seen("RESET")) {
// careful!
if (farm_mode) {

View File

@ -116,7 +116,7 @@ uint8_t menu_item_ret(void)
}
/*
int menu_item_printf_P(char type_char, const char* format, ...)
int menu_draw_item_printf_P(char type_char, const char* format, ...)
{
va_list args;
va_start(args, format);
@ -134,12 +134,14 @@ int menu_item_printf_P(char type_char, const char* format, ...)
return ret;
}
*/
int menu_draw_item_puts_P(char type_char, const char* str)
{
lcd_set_cursor(0, menu_row);
int cnt = lcd_printf_P(PSTR("%c%-18S%c"), (lcd_encoder == menu_item)?'>':' ', str, type_char);
return cnt;
}
/*
int menu_draw_item_puts_P_int16(char type_char, const char* str, int16_t val, )
{
@ -148,6 +150,7 @@ int menu_draw_item_puts_P_int16(char type_char, const char* str, int16_t val, )
return cnt;
}
*/
void menu_item_dummy(void)
{
menu_item++;

View File

@ -63,7 +63,7 @@ extern void menu_submenu(menu_func_t submenu);
extern uint8_t menu_item_ret(void);
//int menu_item_printf_P(char type_char, const char* format, ...);
//extern int menu_draw_item_printf_P(char type_char, const char* format, ...);
extern int menu_draw_item_puts_P(char type_char, const char* str);

View File

@ -26,6 +26,8 @@ extern char choose_extruder_menu();
bool mmu_enabled = false;
int8_t mmu_state = -1;
uint8_t mmu_extruder = 0;
uint8_t tmp_extruder = 0;
@ -34,7 +36,7 @@ int8_t mmu_finda = -1;
int16_t mmu_version = -1;
int16_t mmu_build = -1;
int16_t mmu_buildnr = -1;
//clear rx buffer
@ -73,60 +75,81 @@ int8_t mmu_rx_start(void)
return uart2_rx_str_P(PSTR("start\n"));
}
//initialize mmu_unit
bool mmu_init(void)
//initialize mmu2 unit - first part - should be done at begining of startup process
void mmu_init(void)
{
digitalWrite(MMU_RST_PIN, HIGH);
pinMode(MMU_RST_PIN, OUTPUT); //setup reset pin
uart2_init(); //init uart2
_delay_ms(10); //wait 10ms for sure
if (mmu_reset()) //reset mmu
{
mmu_read_finda();
mmu_read_version();
return true;
}
return false;
mmu_reset(); //reset mmu (HW or SW), do not wait for response
mmu_state = -1;
}
bool mmu_reset(void)
//mmu main loop - state machine processing
void mmu_loop(void)
{
#ifdef MMU_HWRESET
// printf_P(PSTR("MMU loop, state=%d\n"), mmu_state);
switch (mmu_state)
{
case 0:
return;
case -1:
if (mmu_rx_start() > 0)
{
puts_P(PSTR("MMU => 'start'"));
puts_P(PSTR("MMU <= 'S1'"));
mmu_puts_P(PSTR("S1\n")); //send 'read version' request
mmu_state = -2;
}
else if (millis() > 30000) //30sec after reset disable mmu
{
puts_P(PSTR("MMU not responding - DISABLED"));
mmu_state = 0;
}
return;
case -2:
if (mmu_rx_ok() > 0)
{
fscanf_P(uart2io, PSTR("%u"), &mmu_version); //scan version from buffer
printf_P(PSTR("MMU => '%dok'\n"), mmu_version);
puts_P(PSTR("MMU <= 'S2'"));
mmu_puts_P(PSTR("S2\n")); //send 'read buildnr' request
mmu_state = -3;
}
return;
case -3:
if (mmu_rx_ok() > 0)
{
fscanf_P(uart2io, PSTR("%u"), &mmu_buildnr); //scan buildnr from buffer
printf_P(PSTR("MMU => '%dok'\n"), mmu_buildnr);
puts_P(PSTR("MMU <= 'P0'"));
mmu_puts_P(PSTR("P0\n")); //send 'read finda' request
mmu_state = -4;
}
return;
case -4:
if (mmu_rx_ok() > 0)
{
fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); //scan finda from buffer
printf_P(PSTR("MMU => '%dok'\n"), mmu_finda);
puts_P(PSTR("MMU - ENABLED"));
mmu_enabled = true;
mmu_state = 1;
}
return;
}
}
void mmu_reset(void)
{
#ifdef MMU_HWRESET //HW - pulse reset pin
digitalWrite(MMU_RST_PIN, LOW);
_delay_us(100);
digitalWrite(MMU_RST_PIN, HIGH);
#else
mmu_puts_P(PSTR("X0\n")); //send command
#else //SW - send X0 command
mmu_puts_P(PSTR("X0\n"));
#endif
unsigned char timeout = MMU_TIMEOUT; //timeout = 10x100ms
while ((mmu_rx_start() <= 0) && (--timeout))
delay_keep_alive(MMU_TODELAY);
mmu_enabled = timeout?true:false;
// mmu_enabled = true;
return mmu_enabled;
}
int8_t mmu_read_finda(void)
{
mmu_puts_P(PSTR("P0\n"));
unsigned char timeout = MMU_TIMEOUT; //10x100ms
while ((mmu_rx_ok() <= 0) && (--timeout))
delay_keep_alive(MMU_TODELAY);
mmu_finda = -1;
if (timeout)
fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda);
return mmu_finda;
}
int16_t mmu_read_version(void)
{
mmu_puts_P(PSTR("S1\n"));
unsigned char timeout = MMU_TIMEOUT; //10x100ms
while ((mmu_rx_ok() <= 0) && (--timeout))
delay_keep_alive(MMU_TODELAY);
if (timeout)
fscanf_P(uart2io, PSTR("%u"), &mmu_version);
return mmu_version;
}
int8_t mmu_set_filament_type(uint8_t extruder, uint8_t filament)

View File

@ -5,6 +5,8 @@
extern bool mmu_enabled;
extern int8_t mmu_state;
extern uint8_t mmu_extruder;
extern uint8_t tmp_extruder;
@ -12,6 +14,7 @@ extern uint8_t tmp_extruder;
extern int8_t mmu_finda;
extern int16_t mmu_version;
extern int16_t mmu_buildnr;
extern int mmu_puts_P(const char* str);
@ -21,13 +24,12 @@ extern int mmu_printf_P(const char* format, ...);
extern int8_t mmu_rx_ok(void);
extern bool mmu_init(void);
extern void mmu_init(void);
extern bool mmu_reset(void);
extern void mmu_loop(void);
extern int8_t mmu_read_finda(void);
extern int16_t mmu_read_version(void);
extern void mmu_reset(void);
extern int8_t mmu_set_filament_type(uint8_t extruder, uint8_t filament);

View File

@ -150,7 +150,7 @@ uint16_t __tcoolthrs(uint8_t axis)
void tmc2130_init()
{
DBG(_n("tmc2130_init(), mode=%S\n"), tmc2130_mode?_n("STEALTH"):_n("NORMAL"));
// DBG(_n("tmc2130_init(), mode=%S\n"), tmc2130_mode?_n("STEALTH"):_n("NORMAL"));
WRITE(X_TMC2130_CS, HIGH);
WRITE(Y_TMC2130_CS, HIGH);
WRITE(Z_TMC2130_CS, HIGH);
@ -442,8 +442,8 @@ void tmc2130_setup_chopper(uint8_t axis, uint8_t mres, uint8_t current_h, uint8_
// toff = TMC2130_TOFF_E; // toff = 3-5
// rndtf = 1;
}
DBG(_n("tmc2130_setup_chopper(axis=%hhd, mres=%hhd, curh=%hhd, curr=%hhd\n"), axis, mres, current_h, current_r);
DBG(_n(" toff=%hhd, hstr=%hhd, hend=%hhd, tbl=%hhd\n"), toff, hstrt, hend, tbl);
// DBG(_n("tmc2130_setup_chopper(axis=%hhd, mres=%hhd, curh=%hhd, curr=%hhd\n"), axis, mres, current_h, current_r);
// DBG(_n(" toff=%hhd, hstr=%hhd, hend=%hhd, tbl=%hhd\n"), toff, hstrt, hend, tbl);
if (current_r <= 31)
{
tmc2130_wr_CHOPCONF(axis, toff, hstrt, hend, fd3, 0, rndtf, chm, tbl, 1, 0, 0, 0, mres, intpol, 0, 0);
@ -458,31 +458,31 @@ void tmc2130_setup_chopper(uint8_t axis, uint8_t mres, uint8_t current_h, uint8_
void tmc2130_set_current_h(uint8_t axis, uint8_t current)
{
DBG(_n("tmc2130_set_current_h(axis=%d, current=%d\n"), axis, current);
// DBG(_n("tmc2130_set_current_h(axis=%d, current=%d\n"), axis, current);
tmc2130_current_h[axis] = current;
tmc2130_setup_chopper(axis, tmc2130_mres[axis], tmc2130_current_h[axis], tmc2130_current_r[axis]);
}
void tmc2130_set_current_r(uint8_t axis, uint8_t current)
{
DBG(_n("tmc2130_set_current_r(axis=%d, current=%d\n"), axis, current);
// DBG(_n("tmc2130_set_current_r(axis=%d, current=%d\n"), axis, current);
tmc2130_current_r[axis] = current;
tmc2130_setup_chopper(axis, tmc2130_mres[axis], tmc2130_current_h[axis], tmc2130_current_r[axis]);
}
void tmc2130_print_currents()
{
DBG(_n("tmc2130_print_currents()\n\tH\tR\nX\t%d\t%d\nY\t%d\t%d\nZ\t%d\t%d\nE\t%d\t%d\n"),
tmc2130_current_h[0], tmc2130_current_r[0],
tmc2130_current_h[1], tmc2130_current_r[1],
tmc2130_current_h[2], tmc2130_current_r[2],
tmc2130_current_h[3], tmc2130_current_r[3]
);
// DBG(_n("tmc2130_print_currents()\n\tH\tR\nX\t%d\t%d\nY\t%d\t%d\nZ\t%d\t%d\nE\t%d\t%d\n"),
// tmc2130_current_h[0], tmc2130_current_r[0],
// tmc2130_current_h[1], tmc2130_current_r[1],
// tmc2130_current_h[2], tmc2130_current_r[2],
// tmc2130_current_h[3], tmc2130_current_r[3]
// );
}
void tmc2130_set_pwm_ampl(uint8_t axis, uint8_t pwm_ampl)
{
DBG(_n("tmc2130_set_pwm_ampl(axis=%hhd, pwm_ampl=%hhd\n"), axis, pwm_ampl);
// DBG(_n("tmc2130_set_pwm_ampl(axis=%hhd, pwm_ampl=%hhd\n"), axis, pwm_ampl);
tmc2130_pwm_ampl[axis] = pwm_ampl;
if (((axis == 0) || (axis == 1)) && (tmc2130_mode == TMC2130_MODE_SILENT))
tmc2130_wr_PWMCONF(axis, tmc2130_pwm_ampl[axis], tmc2130_pwm_grad[axis], tmc2130_pwm_freq[axis], tmc2130_pwm_auto[axis], 0, 0);
@ -490,7 +490,7 @@ void tmc2130_set_pwm_ampl(uint8_t axis, uint8_t pwm_ampl)
void tmc2130_set_pwm_grad(uint8_t axis, uint8_t pwm_grad)
{
DBG(_n("tmc2130_set_pwm_grad(axis=%hhd, pwm_grad=%hhd\n"), axis, pwm_grad);
// DBG(_n("tmc2130_set_pwm_grad(axis=%hhd, pwm_grad=%hhd\n"), axis, pwm_grad);
tmc2130_pwm_grad[axis] = pwm_grad;
if (((axis == 0) || (axis == 1)) && (tmc2130_mode == TMC2130_MODE_SILENT))
tmc2130_wr_PWMCONF(axis, tmc2130_pwm_ampl[axis], tmc2130_pwm_grad[axis], tmc2130_pwm_freq[axis], tmc2130_pwm_auto[axis], 0, 0);
@ -852,12 +852,12 @@ void tmc2130_set_wave(uint8_t axis, uint8_t amp, uint8_t fac1000)
{
// TMC2130 wave compression algorithm
// optimized for minimal memory requirements
printf_P(PSTR("tmc2130_set_wave %hhd %hhd\n"), axis, fac1000);
// printf_P(PSTR("tmc2130_set_wave %hhd %hhd\n"), axis, fac1000);
if (fac1000 < TMC2130_WAVE_FAC1000_MIN) fac1000 = 0;
if (fac1000 > TMC2130_WAVE_FAC1000_MAX) fac1000 = TMC2130_WAVE_FAC1000_MAX;
float fac = 0;
if (fac1000) fac = ((float)((uint16_t)fac1000 + 1000) / 1000); //correction factor
printf_P(PSTR(" factor: %s\n"), ftostr43(fac));
// printf_P(PSTR(" factor: %s\n"), ftostr43(fac));
uint8_t vA = 0; //value of currentA
uint8_t va = 0; //previous vA
int8_t d0 = 0; //delta0

View File

@ -225,9 +225,7 @@ bool wait_for_unclick;
const char STR_SEPARATOR[] PROGMEM = "------------";
@ -2177,7 +2175,8 @@ static void lcd_preheat_menu()
static void lcd_support_menu()
{
if (menuData.supportMenu.status == 0 || lcd_draw_update == 2) {
if (menuData.supportMenu.status == 0 || lcd_draw_update == 2)
{
// Menu was entered or SD card status has changed (plugged in or removed).
// Initialize its status.
menuData.supportMenu.status = 1;
@ -2189,7 +2188,8 @@ static void lcd_support_menu()
} else if (menuData.supportMenu.is_flash_air &&
menuData.supportMenu.ip[0] == 0 && menuData.supportMenu.ip[1] == 0 &&
menuData.supportMenu.ip[2] == 0 && menuData.supportMenu.ip[3] == 0 &&
++ menuData.supportMenu.status == 16) {
++ menuData.supportMenu.status == 16)
{
// Waiting for the FlashAir card to get an IP address from a router. Force an update.
menuData.supportMenu.status = 0;
}
@ -2214,22 +2214,41 @@ static void lcd_support_menu()
MENU_ITEM_BACK_P(_i("prusa3d.com"));////MSG_PRUSA3D c=0 r=0
MENU_ITEM_BACK_P(_i("forum.prusa3d.com"));////MSG_PRUSA3D_FORUM c=0 r=0
MENU_ITEM_BACK_P(_i("howto.prusa3d.com"));////MSG_PRUSA3D_HOWTO c=0 r=0
MENU_ITEM_BACK_P(PSTR("------------"));
MENU_ITEM_BACK_P(STR_SEPARATOR);
MENU_ITEM_BACK_P(PSTR(FILAMENT_SIZE));
MENU_ITEM_BACK_P(PSTR(ELECTRONICS));
MENU_ITEM_BACK_P(PSTR(NOZZLE_TYPE));
MENU_ITEM_BACK_P(PSTR("------------"));
MENU_ITEM_BACK_P(STR_SEPARATOR);
MENU_ITEM_BACK_P(_i("Date:"));////MSG_DATE c=17 r=1
MENU_ITEM_BACK_P(PSTR(__DATE__));
MENU_ITEM_BACK_P(STR_SEPARATOR);
if (mmu_enabled)
{
MENU_ITEM_BACK_P(PSTR("MMU2 connected"));
MENU_ITEM_BACK_P(PSTR(" FW:"));
if (((menu_item - 1) == menu_line) && lcd_draw_update)
{
lcd_set_cursor(6, menu_row);
if ((mmu_version > 0) && (mmu_buildnr > 0))
lcd_printf_P(PSTR("%d.%d.%d-%d"), mmu_version/100, mmu_version%100/10, mmu_version%10, mmu_buildnr);
else
lcd_puts_P(PSTR("unknown"));
}
}
else
MENU_ITEM_BACK_P(PSTR("MMU2 N/A"));
// Show the FlashAir IP address, if the card is available.
if (menuData.supportMenu.is_flash_air) {
MENU_ITEM_BACK_P(PSTR("------------"));
MENU_ITEM_BACK_P(STR_SEPARATOR);
MENU_ITEM_BACK_P(PSTR("FlashAir IP Addr:"));
///! MENU_ITEM(back_RAM, menuData.supportMenu.ip_str, 0);
}
#ifndef MK1BP
MENU_ITEM_BACK_P(PSTR("------------"));
MENU_ITEM_BACK_P(STR_SEPARATOR);
MENU_ITEM_SUBMENU_P(_i("XYZ cal. details"), lcd_menu_xyz_y_min);////MSG_XYZ_DETAILS c=19 r=1
MENU_ITEM_SUBMENU_P(_i("Extruder info"), lcd_menu_extruder_info);////MSG_INFO_EXTRUDER c=15 r=1