Merge pull request #4595 from thinkyhead/rc_i2c_slave

Add support for i2c slave address
This commit is contained in:
Scott Lahteine
2016-08-11 12:39:26 -07:00
committed by GitHub
22 changed files with 121 additions and 63 deletions

View File

@@ -835,6 +835,14 @@ void servo_init() {
void enableStepperDrivers() { pinMode(STEPPER_RESET_PIN, INPUT); } // set to input, which allows it to be pulled high by pullups
#endif
#if ENABLED(EXPERIMENTAL_I2CBUS) && I2C_SLAVE_ADDRESS > 0
void i2c_listener(int bytes) {
i2c.receive(bytes); // just echo all bytes received to serial
}
#endif
/**
* Marlin entry-point: Set up before the program loop
* - Set up the kill pin, filament runout, power hold
@@ -981,6 +989,10 @@ void setup() {
for (uint8_t i = 0; i < MIXING_STEPPERS; i++)
mixing_virtual_tool_mix[t][i] = mixing_factor[i];
#endif
#if ENABLED(EXPERIMENTAL_I2CBUS) && I2C_SLAVE_ADDRESS > 0
i2c.onReceive(i2c_listener);
#endif
}
/**
@@ -5246,15 +5258,13 @@ inline void gcode_M121() { endstops.enable_globally(false); }
*/
inline void gcode_M155() {
// Set the target address
if (code_seen('A'))
i2c.address(code_value_byte());
if (code_seen('A')) i2c.address(code_value_byte());
// Add a new byte to the buffer
else if (code_seen('B'))
i2c.addbyte(code_value_int());
if (code_seen('B')) i2c.addbyte(code_value_byte());
// Flush the buffer to the bus
else if (code_seen('S')) i2c.send();
if (code_seen('S')) i2c.send();
// Reset and rewind the buffer
else if (code_seen('R')) i2c.reset();
@@ -5266,11 +5276,11 @@ inline void gcode_M121() { endstops.enable_globally(false); }
* Usage: M156 A<slave device address base 10> B<number of bytes>
*/
inline void gcode_M156() {
uint8_t addr = code_seen('A') ? code_value_byte() : 0;
int bytes = code_seen('B') ? code_value_int() : 1;
if (code_seen('A')) i2c.address(code_value_byte());
if (addr && bytes > 0 && bytes <= 32) {
i2c.address(addr);
uint8_t bytes = code_seen('B') ? code_value_byte() : 1;
if (i2c.addr > 0 && bytes > 0 && bytes <= 32) {
i2c.reqbytes(bytes);
}
else {