Move M907-M910 to cpp

This commit is contained in:
Scott Lahteine
2017-09-17 18:45:21 -05:00
parent 2e89685154
commit 6e0503eab2
9 changed files with 101 additions and 58 deletions

View File

@ -0,0 +1,29 @@
/**
* Marlin 3D Printer Firmware
* Copyright (C) 2016 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 <http://www.gnu.org/licenses/>.
*
*/
#ifndef __DIGIPOT_H__
#define __DIGIPOT_H__
void digipot_i2c_set_current(const uint8_t channel, const float current);
void digipot_i2c_init();
#endif // __DIGIPOT_H__

View File

@ -20,11 +20,11 @@
*
*/
#include "../inc/MarlinConfig.h"
#include "../../inc/MarlinConfig.h"
#if ENABLED(DIGIPOT_I2C) && ENABLED(DIGIPOT_MCP4018)
#include "../core/enum.h"
#include "../../core/enum.h"
#include "Stream.h"
#include "utility/twi.h"
#include <SlowSoftI2CMaster.h> //https://github.com/stawel/SlowSoftI2CMaster
@ -88,7 +88,7 @@ static void i2c_send(const uint8_t channel, const byte v) {
}
// This is for the MCP4018 I2C based digipot
void digipot_i2c_set_current(uint8_t channel, float current) {
void digipot_i2c_set_current(const uint8_t channel, const float current) {
i2c_send(channel, current_to_wiper(min(max(current, 0.0f), float(DIGIPOT_A4988_MAX_CURRENT))));
}

View File

@ -20,13 +20,13 @@
*
*/
#include "../inc/MarlinConfig.h"
#include "../../inc/MarlinConfig.h"
#if ENABLED(DIGIPOT_I2C) && DISABLED(DIGIPOT_MCP4018)
#include "Stream.h"
#include "utility/twi.h"
#include "Wire.h"
#include <Wire.h>
// Settings for the I2C based DIGIPOT (MCP4451) on Azteeg X3 Pro
#if MB(5DPRINT)
@ -49,15 +49,10 @@ static void i2c_send(const byte addr, const byte a, const byte b) {
}
// This is for the MCP4451 I2C based digipot
void digipot_i2c_set_current(uint8_t channel, float current) {
current = min((float) max(current, 0.0f), DIGIPOT_I2C_MAX_CURRENT);
void digipot_i2c_set_current(const uint8_t channel, const float current) {
// these addresses are specific to Azteeg X3 Pro, can be set to others,
// In this case first digipot is at address A0=0, A1= 0, second one is at A0=0, A1= 1
byte addr = 0x2C; // channel 0-3
if (channel >= 4) {
addr = 0x2E; // channel 4-7
channel -= 4;
}
const byte addr = channel < 4 ? 0x2C : 0x2E; // channel 0-3 vs 4-7
// Initial setup
i2c_send(addr, 0x40, 0xFF);
@ -65,7 +60,7 @@ void digipot_i2c_set_current(uint8_t channel, float current) {
// Set actual wiper value
byte addresses[4] = { 0x00, 0x10, 0x60, 0x70 };
i2c_send(addr, addresses[channel], current_to_wiper(current));
i2c_send(addr, addresses[channel & 0x3], current_to_wiper(min((float) max(current, 0.0f), DIGIPOT_I2C_MAX_CURRENT)));
}
void digipot_i2c_init() {