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.

M260_M261.cpp 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../../../inc/MarlinConfig.h"
  23. #if ENABLED(EXPERIMENTAL_I2CBUS)
  24. #include "../../gcode.h"
  25. #include "../../../MarlinCore.h" // for i2c
  26. /**
  27. * M260: Send data to a I2C slave device
  28. *
  29. * This is a PoC, the formatting and arguments for the GCODE will
  30. * change to be more compatible, the current proposal is:
  31. *
  32. * M260 A<slave device address base 10> ; Sets the I2C slave address the data will be sent to
  33. *
  34. * M260 B<byte-1 value in base 10>
  35. * M260 B<byte-2 value in base 10>
  36. * M260 B<byte-3 value in base 10>
  37. *
  38. * M260 S1 ; Send the buffered data and reset the buffer
  39. * M260 R1 ; Reset the buffer without sending data
  40. *
  41. */
  42. void GcodeSuite::M260() {
  43. // Set the target address
  44. if (parser.seen('A')) i2c.address(parser.value_byte());
  45. // Add a new byte to the buffer
  46. if (parser.seen('B')) i2c.addbyte(parser.value_byte());
  47. // Flush the buffer to the bus
  48. if (parser.seen('S')) i2c.send();
  49. // Reset and rewind the buffer
  50. else if (parser.seen('R')) i2c.reset();
  51. }
  52. /**
  53. * M261: Request X bytes from I2C slave device
  54. *
  55. * Usage: M261 A<slave device address base 10> B<number of bytes>
  56. */
  57. void GcodeSuite::M261() {
  58. if (parser.seen('A')) i2c.address(parser.value_byte());
  59. uint8_t bytes = parser.byteval('B', 1);
  60. if (i2c.addr && bytes && bytes <= TWIBUS_BUFFER_SIZE)
  61. i2c.relay(bytes);
  62. else
  63. SERIAL_ERROR_MSG("Bad i2c request");
  64. }
  65. #endif