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.

dac_mcp4728.h 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 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. #pragma once
  23. /**
  24. * Arduino library for MicroChip MCP4728 I2C D/A converter.
  25. */
  26. #include "../../core/types.h"
  27. #include <Wire.h>
  28. /**
  29. * The following three macros are only used in this piece of code related to mcp4728.
  30. * They are defined in the standard Arduino framework but could be undefined in 32 bits Arduino frameworks.
  31. * (For instance not defined in Arduino lpc176x framework)
  32. * So we have to define them if needed.
  33. */
  34. #ifndef word
  35. #define word(h, l) ((uint8_t) ((h << 8) | l))
  36. #endif
  37. #ifndef lowByte
  38. #define lowByte(w) ((uint8_t) ((w) & 0xff))
  39. #endif
  40. #ifndef highByte
  41. #define highByte(w) ((uint8_t) ((w) >> 8))
  42. #endif
  43. #define defaultVDD DAC_STEPPER_MAX //was 5000 but differs with internal Vref
  44. #define BASE_ADDR 0x60
  45. #define RESET 0b00000110
  46. #define WAKE 0b00001001
  47. #define UPDATE 0b00001000
  48. #define MULTIWRITE 0b01000000
  49. #define SINGLEWRITE 0b01011000
  50. #define SEQWRITE 0b01010000
  51. #define VREFWRITE 0b10000000
  52. #define GAINWRITE 0b11000000
  53. #define POWERDOWNWRITE 0b10100000
  54. #define GENERALCALL 0b00000000
  55. #define GAINWRITE 0b11000000
  56. // This is taken from the original lib, makes it easy to edit if needed
  57. // DAC_OR_ADDRESS defined in pins_BOARD.h file
  58. #define DAC_DEV_ADDRESS (BASE_ADDR | DAC_OR_ADDRESS)
  59. void mcp4728_init();
  60. uint8_t mcp4728_analogWrite(const uint8_t channel, const uint16_t value);
  61. uint8_t mcp4728_eepromWrite();
  62. uint8_t mcp4728_setVref_all(const uint8_t value);
  63. uint8_t mcp4728_setGain_all(const uint8_t value);
  64. uint16_t mcp4728_getValue(const uint8_t channel);
  65. uint8_t mcp4728_fastWrite();
  66. uint8_t mcp4728_simpleCommand(const byte simpleCommand);
  67. uint8_t mcp4728_getDrvPct(const uint8_t channel);
  68. void mcp4728_setDrvPct(xyze_uint8_t &pct);