Implemented M155 and M156, a generic TWI/I2C interface for Marlin
This commit is contained in:
@@ -77,6 +77,10 @@
|
||||
#include "stepper_dac.h"
|
||||
#endif
|
||||
|
||||
#if ENABLED(EXPERIMENTAL_I2CBUS)
|
||||
#include "twibus.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Look here for descriptions of G-codes:
|
||||
* - http://linuxcnc.org/handbook/gcode/g-code.html
|
||||
@@ -248,6 +252,10 @@
|
||||
CardReader card;
|
||||
#endif
|
||||
|
||||
#if ENABLED(EXPERIMENTAL_I2CBUS)
|
||||
TWIBus i2c;
|
||||
#endif
|
||||
|
||||
bool Running = true;
|
||||
|
||||
uint8_t marlin_debug_flags = DEBUG_NONE;
|
||||
@@ -4771,6 +4779,57 @@ inline void gcode_M121() { enable_endstops_globally(false); }
|
||||
|
||||
#endif // BLINKM
|
||||
|
||||
#if ENABLED(EXPERIMENTAL_I2CBUS)
|
||||
|
||||
/**
|
||||
* M155: Send data to a I2C slave device
|
||||
*
|
||||
* This is a PoC, the formating and arguments for the GCODE will
|
||||
* change to be more compatible, the current proposal is:
|
||||
*
|
||||
* M155 A<slave device address base 10> ; Sets the I2C slave address the data will be sent to
|
||||
*
|
||||
* M155 B<byte-1 value in base 10>
|
||||
* M155 B<byte-2 value in base 10>
|
||||
* M155 B<byte-3 value in base 10>
|
||||
*
|
||||
* M155 S1 ; Send the buffered data and reset the buffer
|
||||
* M155 R1 ; Reset the buffer without sending data
|
||||
*
|
||||
*/
|
||||
inline void gcode_M155() {
|
||||
// Set the target address
|
||||
if (code_seen('A'))
|
||||
i2c.address((uint8_t) code_value_short());
|
||||
|
||||
// Add a new byte to the buffer
|
||||
else if (code_seen('B'))
|
||||
i2c.addbyte((int) code_value_short());
|
||||
|
||||
// Flush the buffer to the bus
|
||||
else if (code_seen('S')) i2c.send();
|
||||
|
||||
// Reset and rewind the buffer
|
||||
else if (code_seen('R')) i2c.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* M156: Request X bytes from I2C slave device
|
||||
*
|
||||
* Usage: M156 A<slave device address base 10> B<number of bytes>
|
||||
*/
|
||||
inline void gcode_M156() {
|
||||
uint8_t addr = code_seen('A') ? code_value_short() : 0;
|
||||
int bytes = code_seen('B') ? code_value_short() : 0;
|
||||
|
||||
if (addr && bytes) {
|
||||
i2c.address(addr);
|
||||
i2c.reqbytes(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
#endif //EXPERIMENTAL_I2CBUS
|
||||
|
||||
/**
|
||||
* M200: Set filament diameter and set E axis units to cubic millimeters
|
||||
*
|
||||
@@ -6439,6 +6498,18 @@ void process_next_command() {
|
||||
|
||||
#endif //BLINKM
|
||||
|
||||
#if ENABLED(EXPERIMENTAL_I2CBUS)
|
||||
|
||||
case 155:
|
||||
gcode_M155();
|
||||
break;
|
||||
|
||||
case 156:
|
||||
gcode_M156();
|
||||
break;
|
||||
|
||||
#endif //EXPERIMENTAL_I2CBUS
|
||||
|
||||
case 200: // M200 D<millimeters> set filament diameter and set E axis units to cubic millimeters (use S0 to set back to millimeters).
|
||||
gcode_M200();
|
||||
break;
|
||||
|
Reference in New Issue
Block a user