Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi Volume Support - LVGL Media Select Screen #21344

Merged
merged 22 commits into from
Apr 13, 2021
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,15 @@
// Enable if SD detect is rendered useless (e.g., by using an SD extender)
//#define NO_SD_DETECT

// Multiple volume support - EXPERIMENTAL.
//#define MULTI_VOLUME
#if ENABLED(MULTI_VOLUME)
#define VOLUME_SD_ONBOARD
#define VOLUME_USB_FLASH_DRIVE
#define DEFAULT_VOLUME SD_ONBOARD
#define DEFAULT_SHARED_VOLUME USB_FLASH_DRIVE
#endif

#endif // SDSUPPORT

/**
Expand Down
18 changes: 9 additions & 9 deletions Marlin/src/HAL/DUE/usb/sd_mmc_spi_mem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Ctrl_status sd_mmc_spi_test_unit_ready() {
Ctrl_status sd_mmc_spi_read_capacity(uint32_t *nb_sector) {
if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isMounted())
return CTRL_NO_PRESENT;
*nb_sector = card.getSd2Card().cardSize() - 1;
*nb_sector = card.getSd2Card()->cardSize() - 1;
return CTRL_GOOD;
}

Expand Down Expand Up @@ -74,24 +74,24 @@ Ctrl_status sd_mmc_spi_usb_read_10(uint32_t addr, uint16_t nb_sector) {
#endif

// Start reading
if (!card.getSd2Card().readStart(addr))
if (!card.getSd2Card()->readStart(addr))
return CTRL_FAIL;

// For each specified sector
while (nb_sector--) {

// Read a sector
card.getSd2Card().readData(sector_buf);
card.getSd2Card()->readData(sector_buf);

// RAM -> USB
if (!udi_msc_trans_block(true, sector_buf, SD_MMC_BLOCK_SIZE, nullptr)) {
card.getSd2Card().readStop();
card.getSd2Card()->readStop();
return CTRL_FAIL;
}
}

// Stop reading
card.getSd2Card().readStop();
card.getSd2Card()->readStop();

// Done
return CTRL_GOOD;
Expand All @@ -113,24 +113,24 @@ Ctrl_status sd_mmc_spi_usb_write_10(uint32_t addr, uint16_t nb_sector) {
}
#endif

if (!card.getSd2Card().writeStart(addr, nb_sector))
if (!card.getSd2Card()->writeStart(addr, nb_sector))
return CTRL_FAIL;

// For each specified sector
while (nb_sector--) {

// USB -> RAM
if (!udi_msc_trans_block(false, sector_buf, SD_MMC_BLOCK_SIZE, nullptr)) {
card.getSd2Card().writeStop();
card.getSd2Card()->writeStop();
return CTRL_FAIL;
}

// Write a sector
card.getSd2Card().writeData(sector_buf);
card.getSd2Card()->writeData(sector_buf);
}

// Stop writing
card.getSd2Card().writeStop();
card.getSd2Card()->writeStop();

// Done
return CTRL_GOOD;
Expand Down
38 changes: 25 additions & 13 deletions Marlin/src/HAL/STM32/msc_sd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,54 +30,66 @@

class Sd2CardUSBMscHandler : public USBMscHandler {
public:
DiskIODriver* getDiskIODriver() {
#if ENABLED(MULTI_VOLUME)
#if SHARED_VOLUME_IS(SD_ONBOARD)
return &card.sd2card_sd_spi;
#elif SHARED_VOLUME_IS(USB_FLASH_DRIVE)
return &card.sd2card_UsbFlashDrive;
#endif
#else
return getDiskIODriver();
#endif
}

bool GetCapacity(uint32_t *pBlockNum, uint16_t *pBlockSize) {
*pBlockNum = card.getSd2Card().cardSize();
*pBlockNum = getDiskIODriver()->cardSize();
*pBlockSize = BLOCK_SIZE;
return true;
}

bool Write(uint8_t *pBuf, uint32_t blkAddr, uint16_t blkLen) {
auto sd2card = card.getSd2Card();
auto sd2card = getDiskIODriver();
// single block
if (blkLen == 1) {
watchdog_refresh();
sd2card.writeBlock(blkAddr, pBuf);
sd2card->writeBlock(blkAddr, pBuf);
return true;
}

// multi block optmization
sd2card.writeStart(blkAddr, blkLen);
sd2card->writeStart(blkAddr, blkLen);
while (blkLen--) {
watchdog_refresh();
sd2card.writeData(pBuf);
sd2card->writeData(pBuf);
pBuf += BLOCK_SIZE;
}
sd2card.writeStop();
sd2card->writeStop();
return true;
}

bool Read(uint8_t *pBuf, uint32_t blkAddr, uint16_t blkLen) {
auto sd2card = card.getSd2Card();
auto sd2card = getDiskIODriver();
// single block
if (blkLen == 1) {
watchdog_refresh();
sd2card.readBlock(blkAddr, pBuf);
sd2card->readBlock(blkAddr, pBuf);
return true;
}

// multi block optmization
sd2card.readStart(blkAddr);
sd2card->readStart(blkAddr);
while (blkLen--) {
watchdog_refresh();
sd2card.readData(pBuf);
sd2card->readData(pBuf);
pBuf += BLOCK_SIZE;
}
sd2card.readStop();
sd2card->readStop();
return true;
}

bool IsReady() {
return card.isMounted();
return getDiskIODriver()->isReady();
}
};

Expand Down Expand Up @@ -105,8 +117,8 @@ USBMscHandler *pSingleMscHandler = &usbMscHandler;
void MSC_SD_init() {
USBDevice.end();
delay(200);
USBDevice.begin();
USBDevice.registerMscHandlers(1, &pSingleMscHandler, Marlin_STORAGE_Inquirydata);
USBDevice.begin();
}

#endif // __STM32F1__ && HAS_SD_HOST_DRIVE
36 changes: 24 additions & 12 deletions Marlin/src/HAL/STM32F1/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,27 @@
#define MYSERIAL1 UsbSerial
#elif WITHIN(SERIAL_PORT, 1, NUM_UARTS)
#define MYSERIAL1 MSERIAL(SERIAL_PORT)
#elif NUM_UARTS == 5
#error "SERIAL_PORT must be -1 or from 1 to 5. Please update your configuration."
#else
#error "SERIAL_PORT must be -1 or from 1 to 3. Please update your configuration."
#define MYSERIAL1 MSERIAL(1) // dummy port
#if NUM_UARTS == 5
#error "SERIAL_PORT must be -1 or from 1 to 5. Please update your configuration."
#else
#error "SERIAL_PORT must be -1 or from 1 to 3. Please update your configuration."
#endif
#endif

#ifdef SERIAL_PORT_2
#if SERIAL_PORT_2 == -1
#define MYSERIAL2 UsbSerial
#elif WITHIN(SERIAL_PORT_2, 1, NUM_UARTS)
#define MYSERIAL2 MSERIAL(SERIAL_PORT_2)
#elif NUM_UARTS == 5
#error "SERIAL_PORT_2 must be -1 or from 1 to 5. Please update your configuration."
#else
#error "SERIAL_PORT_2 must be -1 or from 1 to 3. Please update your configuration."
#define MYSERIAL2 MSERIAL(1) // dummy port
#if NUM_UARTS == 5
#error "SERIAL_PORT_2 must be -1 or from 1 to 5. Please update your configuration."
#else
#error "SERIAL_PORT_2 must be -1 or from 1 to 3. Please update your configuration."
#endif
#endif
#endif

Expand All @@ -107,10 +113,13 @@
#define MMU2_SERIAL UsbSerial
#elif WITHIN(MMU2_SERIAL_PORT, 1, NUM_UARTS)
#define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
#elif NUM_UARTS == 5
#error "MMU2_SERIAL_PORT must be -1 or from 1 to 5. Please update your configuration."
#else
#error "MMU2_SERIAL_PORT must be -1 or from 1 to 3. Please update your configuration."
#define MMU2_SERIAL MSERIAL(1) // dummy port
#if NUM_UARTS == 5
#error "MMU2_SERIAL_PORT must be -1 or from 1 to 5. Please update your configuration."
#else
#error "MMU2_SERIAL_PORT must be -1 or from 1 to 3. Please update your configuration."
#endif
#endif
#endif

Expand All @@ -119,10 +128,13 @@
#define LCD_SERIAL UsbSerial
#elif WITHIN(LCD_SERIAL_PORT, 1, NUM_UARTS)
#define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
#elif NUM_UARTS == 5
#error "LCD_SERIAL_PORT must be -1 or from 1 to 5. Please update your configuration."
#else
#error "LCD_SERIAL_PORT must be -1 or from 1 to 3. Please update your configuration."
#define LCD_SERIAL MSERIAL(1) // dummy port
#if NUM_UARTS == 5
#error "LCD_SERIAL_PORT must be -1 or from 1 to 5. Please update your configuration."
#else
#error "LCD_SERIAL_PORT must be -1 or from 1 to 3. Please update your configuration."
#endif
#endif
#if HAS_DGUS_LCD
#define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.availableForWrite()
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ void idle(TERN_(ADVANCED_PAUSE_FEATURE, bool no_stepper_sleep/*=false*/)) {
TERN_(SDSUPPORT, card.manage_media());

// Handle USB Flash Drive insert / remove
TERN_(USB_FLASH_DRIVE_SUPPORT, Sd2Card::idle());
TERN_(USB_FLASH_DRIVE_SUPPORT, DiskIODriver_USBFlash::idle());

// Announce Host Keepalive state (if any)
TERN_(HOST_KEEPALIVE_FEATURE, gcode.host_keepalive());
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/feature/encoder_i2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void I2CPositionEncoder::init(const uint8_t address, const AxisEnum axis) {
encoderAxis = axis;
i2cAddress = address;

initialized++;
initialized = true;

SERIAL_ECHOLNPAIR("Setting up encoder on ", AS_CHAR(axis_codes[encoderAxis]), " axis, addr = ", address);

Expand Down Expand Up @@ -209,8 +209,8 @@ void I2CPositionEncoder::set_homed() {
delay(10);

zeroOffset = get_raw_count();
homed++;
trusted++;
homed = true;
trusted = true;

#ifdef I2CPE_DEBUG
SERIAL_CHAR(axis_codes[encoderAxis]);
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/inc/Conditionals_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@
#define _CUTTER_POWER_PERCENT 2
#define _CUTTER_POWER_RPM 3
#define _CUTTER_POWER(V) _CAT(_CUTTER_POWER_, V)
#define CUTTER_UNIT_IS(V) (_CUTTER_POWER(CUTTER_POWER_UNIT) == _CUTTER_POWER(V))
#define CUTTER_UNIT_IS(V) (_CUTTER_POWER(CUTTER_POWER_UNIT) == _CUTTER_POWER(V))
#endif

// Add features that need hardware PWM here
Expand Down
9 changes: 9 additions & 0 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,15 @@
#define SD_DETECT_STATE LOW
#endif
#endif

#if DISABLED(USB_FLASH_DRIVE_SUPPORT) || BOTH(MULTI_VOLUME, VOLUME_SD_ONBOARD)
#if ENABLED(SDIO_SUPPORT)
#define NEED_SD2CARD_SDIO 1
#else
#define NEED_SD2CARD_SPI 1
#endif
#endif

#endif

#if ANY(HAS_GRAPHICAL_TFT, LCD_USE_DMA_FSMC, HAS_FSMC_GRAPHICAL_TFT, HAS_SPI_GRAPHICAL_TFT) || !PIN_EXISTS(SD_DETECT)
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/extui/lib/mks_ui/draw_keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ static void lv_kb_event_cb(lv_obj_t *kb, lv_event_t event) {
public_buf_l[6] = 0x00;
raw_send_to_wifi((uint8_t*)public_buf_l, 6);

last_disp_state = KEY_BOARD_UI;
last_disp_state = KEYBOARD_UI;
lv_clear_keyboard();
wifi_tips_type = TIPS_TYPE_JOINING;
lv_draw_wifi_tips();
Expand Down Expand Up @@ -216,7 +216,7 @@ static void lv_kb_event_cb(lv_obj_t *kb, lv_event_t event) {
}

void lv_draw_keyboard() {
scr = lv_screen_create(KEY_BOARD_UI, "");
scr = lv_screen_create(KEYBOARD_UI, "");

// Create styles for the keyboard
static lv_style_t rel_style, pr_style;
Expand Down
73 changes: 73 additions & 0 deletions Marlin/src/lcd/extui/lib/mks_ui/draw_media_select.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#include "../../../../inc/MarlinConfigPre.h"

#if BOTH(HAS_TFT_LVGL_UI, MULTI_VOLUME)

#include "draw_ui.h"
#include <lv_conf.h>

#include "../../../../inc/MarlinConfig.h"
#include "../../../../sd/cardreader.h"

extern lv_group_t *g;
static lv_obj_t *scr;

enum {
ID_T_USB_DISK = 1,
ID_T_SD_DISK,
ID_T_RETURN
};

#if ENABLED(MKS_TEST)
extern uint8_t curent_disp_ui;
#endif

static void event_handler(lv_obj_t *obj, lv_event_t event) {
if (event != LV_EVENT_RELEASED) return;
lv_clear_media_select();
switch (obj->mks_obj_id) {
case ID_T_USB_DISK: card.changeMedia(&card.sd2card_UsbFlashDrive); break;
case ID_T_SD_DISK: card.changeMedia(&card.sd2card_sd_spi); break;
case ID_T_RETURN:
TERN_(MKS_TEST, curent_disp_ui = 1);
lv_draw_ready_print();
return;
}
lv_draw_print_file();
}

void lv_draw_media_select() {
scr = lv_screen_create(MEDIA_SELECT_UI);
lv_big_button_create(scr, "F:/bmp_sd.bin", media_select_menu.sd_disk, INTERVAL_V, titleHeight, event_handler, ID_T_SD_DISK);
lv_big_button_create(scr, "F:/bmp_usb_disk.bin", media_select_menu.usb_disk, BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_T_USB_DISK);
lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_T_RETURN);
}

void lv_clear_media_select() {
#if HAS_ROTARY_ENCODER
if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
#endif
lv_obj_del(scr);
}

#endif // HAS_TFT_LVGL_UI
Loading