Skip to content

Commit

Permalink
clang and add #13
Browse files Browse the repository at this point in the history
  • Loading branch information
ladyada committed Jun 1, 2020
1 parent 47adab4 commit df5c601
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 41 deletions.
43 changes: 20 additions & 23 deletions Adafruit_MCP4725.cpp
@@ -1,19 +1,19 @@
/**************************************************************************/
/*!
/*!
@file Adafruit_MCP4725.cpp
@author K.Townsend (Adafruit Industries)
@license BSD (see license.txt)
I2C Driver for Microchip's MCP4725 I2C DAC
@license BSD (see license.txt)
This is a library for the Adafruit MCP4725 breakout
----> http://www.adafruit.com/products/935
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
I2C Driver for Microchip's MCP4725 I2C DAC
@section HISTORY
This is a library for the Adafruit MCP4725 breakout
----> http://www.adafruit.com/products/935
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
@section HISTORY
v1.0 - First release
*/
Expand All @@ -22,15 +22,14 @@
#include "Adafruit_MCP4725.h"

/**************************************************************************/
/*!
/*!
@brief Instantiates a new MCP4725 class
*/
/**************************************************************************/
Adafruit_MCP4725::Adafruit_MCP4725() {
}
Adafruit_MCP4725::Adafruit_MCP4725() {}

/**************************************************************************/
/*!
/*!
@brief Setups the hardware and checks the DAC was found
@param i2c_address The I2C address of the DAC, defaults to 0x62
@param wire The I2C TwoWire object to use, defaults to &Wire
Expand All @@ -51,9 +50,8 @@ bool Adafruit_MCP4725::begin(uint8_t i2c_address, TwoWire *wire) {
return true;
}


/**************************************************************************/
/*!
/*!
@brief Sets the output voltage to a fraction of source vref. (Value
can be 0..4095)
Expand All @@ -70,9 +68,8 @@ bool Adafruit_MCP4725::begin(uint8_t i2c_address, TwoWire *wire) {
@returns True if able to write the value over I2C
*/
/**************************************************************************/
bool Adafruit_MCP4725::setVoltage(uint16_t output, bool writeEEPROM,
uint32_t i2c_frequency)
{
bool Adafruit_MCP4725::setVoltage(uint16_t output, bool writeEEPROM,
uint32_t i2c_frequency) {
i2c_dev->setSpeed(i2c_frequency); // Set I2C frequency to desired speed

uint8_t packet[3];
Expand All @@ -82,10 +79,10 @@ bool Adafruit_MCP4725::setVoltage(uint16_t output, bool writeEEPROM,
} else {
packet[0] = MCP4725_CMD_WRITEDAC;
}
packet[1] = output / 16; // Upper data bits (D11.D10.D9.D8.D7.D6.D5.D4)
packet[2] = (output % 16) << 4; // Lower data bits (D3.D2.D1.D0.x.x.x.x)
packet[1] = output / 16; // Upper data bits (D11.D10.D9.D8.D7.D6.D5.D4)
packet[2] = (output % 16) << 4; // Lower data bits (D3.D2.D1.D0.x.x.x.x)

if (! i2c_dev->write(packet, 3)) {
if (!i2c_dev->write(packet, 3)) {
return false;
}

Expand Down
43 changes: 25 additions & 18 deletions Adafruit_MCP4725.h
@@ -1,38 +1,45 @@
/**************************************************************************/
/*!
/*!
@file Adafruit_MCP4725.h
@author K. Townsend (Adafruit Industries)
@license BSD (see license.txt)
This is a library for the Adafruit MCP4725 breakout board
----> http://www.adafruit.com/products/935
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
@license BSD (see license.txt)
@section HISTORY
This is a library for the Adafruit MCP4725 breakout board
----> http://www.adafruit.com/products/935
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
@section HISTORY
v1.0 - First release
*/
/**************************************************************************/

#ifndef _ADAFRUIT_MCP4725_H_
#define _ADAFRUIT_MCP4725_H_

#include <Adafruit_BusIO_Register.h>
#include <Adafruit_I2CDevice.h>
#include <Wire.h>

#define MCP4725_I2CADDR_DEFAULT (0x62) // Default i2c address
#define MCP4725_CMD_WRITEDAC (0x40) // Writes data to the DAC
#define MCP4725_CMD_WRITEDACEEPROM (0x60) // Writes data to the DAC and the EEPROM (persisting the assigned value after reset)
#define MCP4725_I2CADDR_DEFAULT (0x62) // Default i2c address
#define MCP4725_CMD_WRITEDAC (0x40) // Writes data to the DAC
#define MCP4725_CMD_WRITEDACEEPROM \
(0x60) // Writes data to the DAC and the EEPROM (persisting the assigned value
// after reset)

class Adafruit_MCP4725{
public:
class Adafruit_MCP4725 {
public:
Adafruit_MCP4725();
bool begin(uint8_t i2c_address = MCP4725_I2CADDR_DEFAULT,
TwoWire *wire = &Wire);
bool setVoltage(uint16_t output, bool writeEEPROM,
uint32_t dac_frequency=400000);
bool setVoltage(uint16_t output, bool writeEEPROM,
uint32_t dac_frequency = 400000);

private:
private:
Adafruit_I2CDevice *i2c_dev = NULL;
};

#endif

0 comments on commit df5c601

Please sign in to comment.