Marlin_Firmware/Marlin/src/feature/dac/dac_mcp4728.h

83 lines
2.6 KiB
C
Raw Normal View History

/**
2016-03-24 13:01:20 -05:00
* Marlin 3D Printer Firmware
2020-02-03 08:00:57 -06:00
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
2016-03-24 13:01:20 -05:00
*
* Based on Sprinter and grbl.
2019-06-27 23:57:50 -05:00
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
2016-03-24 13:01:20 -05:00
*
* 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
2020-07-22 22:20:14 -05:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2016-03-24 13:01:20 -05:00
*
*/
#pragma once
2016-03-24 13:01:20 -05:00
/**
2016-03-24 13:01:20 -05:00
* Arduino library for MicroChip MCP4728 I2C D/A converter.
*/
2019-09-29 04:25:39 -05:00
#include "../../core/types.h"
2017-09-06 06:28:32 -05:00
#include <Wire.h>
/**
* The following three macros are only used in this piece of code related to mcp4728.
* They are defined in the standard Arduino framework but could be undefined in 32 bits Arduino frameworks.
* (For instance not defined in Arduino lpc176x framework)
* So we have to define them if needed.
*/
#ifndef word
#define word(h, l) ((uint8_t) ((h << 8) | l))
#endif
#ifndef lowByte
2020-10-09 16:50:17 -05:00
#define lowByte(w) ((uint8_t) ((w) & 0xFF))
#endif
#ifndef highByte
#define highByte(w) ((uint8_t) ((w) >> 8))
#endif
2016-10-03 17:15:29 -05:00
#define defaultVDD DAC_STEPPER_MAX //was 5000 but differs with internal Vref
2016-07-16 19:59:13 -05:00
#define BASE_ADDR 0x60
#define RESET 0b00000110
#define WAKE 0b00001001
#define UPDATE 0b00001000
#define MULTIWRITE 0b01000000
#define SINGLEWRITE 0b01011000
#define SEQWRITE 0b01010000
#define VREFWRITE 0b10000000
#define GAINWRITE 0b11000000
#define POWERDOWNWRITE 0b10100000
#define GENERALCALL 0b00000000
#define GAINWRITE 0b11000000
// This is taken from the original lib, makes it easy to edit if needed
// DAC_OR_ADDRESS defined in pins_BOARD.h file
#define DAC_DEV_ADDRESS (BASE_ADDR | DAC_OR_ADDRESS)
2020-10-11 14:58:35 -05:00
class MCP4728 {
public:
static void init();
static uint8_t analogWrite(const uint8_t channel, const uint16_t value);
static uint8_t eepromWrite();
static uint8_t setVref_all(const uint8_t value);
static uint8_t setGain_all(const uint8_t value);
static uint16_t getValue(const uint8_t channel);
static uint8_t fastWrite();
static uint8_t simpleCommand(const byte simpleCommand);
static uint8_t getDrvPct(const uint8_t channel);
2020-11-19 18:08:21 -06:00
static void setDrvPct(xyze_uint_t &pct);
2020-10-11 14:58:35 -05:00
};
extern MCP4728 mcp4728;