Skip to content

Commit

Permalink
Merge pull request #15 from adafruit/action
Browse files Browse the repository at this point in the history
Action
  • Loading branch information
ladyada committed Jun 1, 2020
2 parents 9a527de + a4fecc0 commit 0bb4326
Show file tree
Hide file tree
Showing 6 changed files with 239 additions and 75 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/githubci.yml
@@ -0,0 +1,32 @@
name: Arduino Library CI

on: [pull_request, push, repository_dispatch]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/setup-python@v1
with:
python-version: '3.x'
- uses: actions/checkout@v2
- uses: actions/checkout@v2
with:
repository: adafruit/ci-arduino
path: ci

- name: pre-install
run: bash ci/actions_install.sh

- name: test platforms
run: python3 ci/build_platform.py main_platforms

- name: clang
run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r .

- name: doxygen
env:
GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
PRETTYNAME : "Adafruit MCP4725 DAC Library"
run: bash ci/doxy_gen_and_deploy.sh
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
html/
Doxyfile
.vscode/
99 changes: 51 additions & 48 deletions Adafruit_MCP4725.cpp
@@ -1,54 +1,55 @@
/**************************************************************************/
/*!
/*!
@file Adafruit_MCP4725.cpp
@author K.Townsend (Adafruit Industries)
@license BSD (see license.txt)
I2C Driver for Microchip's MCP4725 I2C DAC
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
*/
/**************************************************************************/
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

#include <Wire.h>

#include "Adafruit_MCP4725.h"

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

/**************************************************************************/
/*!
@brief Setups the HW
/*!
@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
@returns True if DAC was found on the I2C address.
*/
/**************************************************************************/
void Adafruit_MCP4725::begin(uint8_t addr) {
_i2caddr = addr;
Wire.begin();
bool Adafruit_MCP4725::begin(uint8_t i2c_address, TwoWire *wire) {
if (i2c_dev) {
delete i2c_dev;
}

i2c_dev = new Adafruit_I2CDevice(i2c_address, wire);

if (!i2c_dev->begin()) {
return false;
}

return true;
}

/**************************************************************************/
/*!
/*!
@brief Sets the output voltage to a fraction of source vref. (Value
can be 0..4095)
Expand All @@ -60,27 +61,29 @@ void Adafruit_MCP4725::begin(uint8_t addr) {
to the MCP4725's internal non-volatile memory, meaning
that the DAC will retain the current voltage output
after power-down or reset.
@param i2c_frequency What we should set the I2C clock to when writing
to the DAC, defaults to 400 KHz
@returns True if able to write the value over I2C
*/
/**************************************************************************/
void Adafruit_MCP4725::setVoltage( uint16_t output, bool writeEEPROM )
{
#ifdef TWBR
uint8_t twbrback = TWBR;
TWBR = ((F_CPU / 400000L) - 16) / 2; // Set I2C frequency to 400kHz
#endif
Wire.beginTransmission(_i2caddr);
if (writeEEPROM)
{
Wire.write(MCP4726_CMD_WRITEDACEEPROM);
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];

if (writeEEPROM) {
packet[0] = MCP4725_CMD_WRITEDACEEPROM;
} else {
packet[0] = MCP4725_CMD_WRITEDAC;
}
else
{
Wire.write(MCP4726_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)

if (!i2c_dev->write(packet, 3)) {
return false;
}
Wire.write(output / 16); // Upper data bits (D11.D10.D9.D8.D7.D6.D5.D4)
Wire.write((output % 16) << 4); // Lower data bits (D3.D2.D1.D0.x.x.x.x)
Wire.endTransmission();
#ifdef TWBR
TWBR = twbrback;
#endif

i2c_dev->setSpeed(100000); // reset to arduino default
return true;
}
52 changes: 25 additions & 27 deletions Adafruit_MCP4725.h
@@ -1,39 +1,37 @@
/**************************************************************************/
/*!
/*!
@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!
@section HISTORY
v1.0 - First release
*/
/**************************************************************************/

#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#ifndef _ADAFRUIT_MCP4725_H_
#define _ADAFRUIT_MCP4725_H_

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

#define MCP4726_CMD_WRITEDAC (0x40) // Writes data to the DAC
#define MCP4726_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:
/**************************************************************************/
/*!
@brief Class for communicating with an MCP4725 DAC
*/
/**************************************************************************/
class Adafruit_MCP4725 {
public:
Adafruit_MCP4725();
void begin(uint8_t a);
void setVoltage( uint16_t output, bool writeEEPROM );
bool begin(uint8_t i2c_address = MCP4725_I2CADDR_DEFAULT,
TwoWire *wire = &Wire);
bool setVoltage(uint16_t output, bool writeEEPROM,
uint32_t dac_frequency = 400000);

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

#endif
127 changes: 127 additions & 0 deletions code-of-conduct.md
@@ -0,0 +1,127 @@
# Adafruit Community Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and leaders pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level or type of
experience, education, socio-economic status, nationality, personal appearance,
race, religion, or sexual identity and orientation.

## Our Standards

We are committed to providing a friendly, safe and welcoming environment for
all.

Examples of behavior that contributes to creating a positive environment
include:

* Be kind and courteous to others
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Collaborating with other community members
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and sexual attention or advances
* The use of inappropriate images, including in a community member's avatar
* The use of inappropriate language, including in a community member's nickname
* Any spamming, flaming, baiting or other attention-stealing behavior
* Excessive or unwelcome helping; answering outside the scope of the question
asked
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate

The goal of the standards and moderation guidelines outlined here is to build
and maintain a respectful community. We ask that you don’t just aim to be
"technically unimpeachable", but rather try to be your best self.

We value many things beyond technical expertise, including collaboration and
supporting others within our community. Providing a positive experience for
other community members can have a much more significant impact than simply
providing the correct answer.

## Our Responsibilities

Project leaders are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project leaders have the right and responsibility to remove, edit, or
reject messages, comments, commits, code, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any community member for other behaviors that they deem
inappropriate, threatening, offensive, or harmful.

## Moderation

Instances of behaviors that violate the Adafruit Community Code of Conduct
may be reported by any member of the community. Community members are
encouraged to report these situations, including situations they witness
involving other community members.

You may report in the following ways:

In any situation, you may send an email to <support@adafruit.com>.

On the Adafruit Discord, you may send an open message from any channel
to all Community Helpers by tagging @community helpers. You may also send an
open message from any channel, or a direct message to @kattni#1507,
@tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, or
@Andon#8175.

Email and direct message reports will be kept confidential.

In situations on Discord where the issue is particularly egregious, possibly
illegal, requires immediate action, or violates the Discord terms of service,
you should also report the message directly to Discord.

These are the steps for upholding our community’s standards of conduct.

1. Any member of the community may report any situation that violates the
Adafruit Community Code of Conduct. All reports will be reviewed and
investigated.
2. If the behavior is an egregious violation, the community member who
committed the violation may be banned immediately, without warning.
3. Otherwise, moderators will first respond to such behavior with a warning.
4. Moderators follow a soft "three strikes" policy - the community member may
be given another chance, if they are receptive to the warning and change their
behavior.
5. If the community member is unreceptive or unreasonable when warned by a
moderator, or the warning goes unheeded, they may be banned for a first or
second offense. Repeated offenses will result in the community member being
banned.

## Scope

This Code of Conduct and the enforcement policies listed above apply to all
Adafruit Community venues. This includes but is not limited to any community
spaces (both public and private), the entire Adafruit Discord server, and
Adafruit GitHub repositories. Examples of Adafruit Community spaces include
but are not limited to meet-ups, audio chats on the Adafruit Discord, or
interaction at a conference.

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. As a community
member, you are representing our community, and are expected to behave
accordingly.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 1.4, available at
<https://www.contributor-covenant.org/version/1/4/code-of-conduct.html>,
and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html).

For other projects adopting the Adafruit Community Code of
Conduct, please contact the maintainers of those projects for enforcement.
If you wish to use this code of conduct for your own project, consider
explicitly mentioning your moderation policy or making a copy with your
own moderation policy so as to avoid confusion.
1 change: 1 addition & 0 deletions library.properties
Expand Up @@ -7,3 +7,4 @@ paragraph=MCP4725 12-bit I2C DAC
category=Signal Input/Output
url=https://github.com/adafruit/Adafruit_MCP4725
architectures=*
depends=Adafruit BusIO

0 comments on commit 0bb4326

Please sign in to comment.