My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

msc_sd.cpp 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * Marlin 3D Printer Firmware
  3. *
  4. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  5. * Copyright (c) 2019 BigTreeTech [https://github.com/bigtreetech]
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. *
  15. */
  16. #ifdef USE_USB_COMPOSITE
  17. #include "msc_sd.h"
  18. #include "SPI.h"
  19. #define PRODUCT_ID 0x29
  20. USBMassStorage MarlinMSC;
  21. USBCompositeSerial MarlinCompositeSerial;
  22. #include "../../inc/MarlinConfig.h"
  23. #ifdef HAS_ONBOARD_SD
  24. #include "onboard_sd.h"
  25. static bool MSC_Write(const uint8_t *writebuff, uint32_t startSector, uint16_t numSectors) {
  26. return (disk_write(0, writebuff, startSector, numSectors) == RES_OK);
  27. }
  28. static bool MSC_Read(uint8_t *readbuff, uint32_t startSector, uint16_t numSectors) {
  29. return (disk_read(0, readbuff, startSector, numSectors) == RES_OK);
  30. }
  31. #endif
  32. void MSC_SD_init() {
  33. USBComposite.setProductId(PRODUCT_ID);
  34. // Just set MarlinCompositeSerial enabled to true
  35. // because when MarlinCompositeSerial.begin() is used in setup()
  36. // it clears all USBComposite devices.
  37. MarlinCompositeSerial.begin();
  38. USBComposite.end();
  39. USBComposite.clear();
  40. // Set api and register mass storage
  41. #ifdef HAS_ONBOARD_SD
  42. uint32_t cardSize;
  43. if (disk_initialize(0) == RES_OK) {
  44. if (disk_ioctl(0, GET_SECTOR_COUNT, (void *)(&cardSize)) == RES_OK) {
  45. MarlinMSC.setDriveData(0, cardSize, MSC_Read, MSC_Write);
  46. MarlinMSC.registerComponent();
  47. }
  48. }
  49. #endif
  50. // Register composite Serial
  51. MarlinCompositeSerial.registerComponent();
  52. USBComposite.begin();
  53. }
  54. #endif // USE_USB_COMPOSITE