├── .github ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── githubci.yml ├── .gitignore ├── Adafruit_TPA2016.cpp ├── Adafruit_TPA2016.h ├── README.md ├── assets └── board.jpg ├── code-of-conduct.md ├── examples └── audioamptest │ └── audioamptest.ino ├── library.properties └── license.txt /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for opening an issue on an Adafruit Arduino library repository. To 2 | improve the speed of resolution please review the following guidelines and 3 | common troubleshooting steps below before creating the issue: 4 | 5 | - **Do not use GitHub issues for troubleshooting projects and issues.** Instead use 6 | the forums at http://forums.adafruit.com to ask questions and troubleshoot why 7 | something isn't working as expected. In many cases the problem is a common issue 8 | that you will more quickly receive help from the forum community. GitHub issues 9 | are meant for known defects in the code. If you don't know if there is a defect 10 | in the code then start with troubleshooting on the forum first. 11 | 12 | - **If following a tutorial or guide be sure you didn't miss a step.** Carefully 13 | check all of the steps and commands to run have been followed. Consult the 14 | forum if you're unsure or have questions about steps in a guide/tutorial. 15 | 16 | - **For Arduino projects check these very common issues to ensure they don't apply**: 17 | 18 | - For uploading sketches or communicating with the board make sure you're using 19 | a **USB data cable** and **not** a **USB charge-only cable**. It is sometimes 20 | very hard to tell the difference between a data and charge cable! Try using the 21 | cable with other devices or swapping to another cable to confirm it is not 22 | the problem. 23 | 24 | - **Be sure you are supplying adequate power to the board.** Check the specs of 25 | your board and plug in an external power supply. In many cases just 26 | plugging a board into your computer is not enough to power it and other 27 | peripherals. 28 | 29 | - **Double check all soldering joints and connections.** Flakey connections 30 | cause many mysterious problems. See the [guide to excellent soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) for examples of good solder joints. 31 | 32 | - **Ensure you are using an official Arduino or Adafruit board.** We can't 33 | guarantee a clone board will have the same functionality and work as expected 34 | with this code and don't support them. 35 | 36 | If you're sure this issue is a defect in the code and checked the steps above 37 | please fill in the following fields to provide enough troubleshooting information. 38 | You may delete the guideline and text above to just leave the following details: 39 | 40 | - Arduino board: **INSERT ARDUINO BOARD NAME/TYPE HERE** 41 | 42 | - Arduino IDE version (found in Arduino -> About Arduino menu): **INSERT ARDUINO 43 | VERSION HERE** 44 | 45 | - List the steps to reproduce the problem below (if possible attach a sketch or 46 | copy the sketch code in too): **LIST REPRO STEPS BELOW** 47 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for creating a pull request to contribute to Adafruit's GitHub code! 2 | Before you open the request please review the following guidelines and tips to 3 | help it be more easily integrated: 4 | 5 | - **Describe the scope of your change--i.e. what the change does and what parts 6 | of the code were modified.** This will help us understand any risks of integrating 7 | the code. 8 | 9 | - **Describe any known limitations with your change.** For example if the change 10 | doesn't apply to a supported platform of the library please mention it. 11 | 12 | - **Please run any tests or examples that can exercise your modified code.** We 13 | strive to not break users of the code and running tests/examples helps with this 14 | process. 15 | 16 | Thank you again for contributing! We will try to test and integrate the change 17 | as soon as we can, but be aware we have many GitHub repositories to manage and 18 | can't immediately respond to every request. There is no need to bump or check in 19 | on a pull request (it will clutter the discussion of the request). 20 | 21 | Also don't be worried if the request is closed or not integrated--sometimes the 22 | priorities of Adafruit's GitHub code (education, ease of use) might not match the 23 | priorities of the pull request. Don't fret, the open source community thrives on 24 | forks and GitHub makes it easy to keep your changes in a forked repo. 25 | 26 | After reviewing the guidelines above you can delete this text from the pull request. 27 | -------------------------------------------------------------------------------- /.github/workflows/githubci.yml: -------------------------------------------------------------------------------- 1 | name: Arduino Library CI 2 | 3 | on: [pull_request, push, repository_dispatch] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - uses: actions/setup-python@v4 11 | with: 12 | python-version: '3.x' 13 | - uses: actions/checkout@v3 14 | - uses: actions/checkout@v3 15 | with: 16 | repository: adafruit/ci-arduino 17 | path: ci 18 | 19 | - name: pre-install 20 | run: bash ci/actions_install.sh 21 | 22 | - name: test platforms 23 | run: python3 ci/build_platform.py main_platforms 24 | 25 | - name: clang 26 | run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r . 27 | 28 | - name: doxygen 29 | env: 30 | GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }} 31 | PRETTYNAME : "Adafruit TPA2016 Library" 32 | run: bash ci/doxy_gen_and_deploy.sh 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # osx 2 | .DS_Store 3 | 4 | # doxygen 5 | Doxyfile* 6 | doxygen_sqlite3.db 7 | html 8 | *.tmp 9 | -------------------------------------------------------------------------------- /Adafruit_TPA2016.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file Adafruit_TPA2016.cpp 3 | * 4 | * @mainpage Adafruit TPA2016D2 breakout 5 | * 6 | * @section intro_sec Introduction 7 | * 8 | * I2C Driver for Adafruit TPA2016D2 Class D Amplifier Breakout 9 | * 10 | * This is a library for the Adafruit TPA2016D2 breakout 11 | * http://www.adafruit.com/products/1712 12 | * 13 | * Adafruit invests time and resources providing this open source code, 14 | * please support Adafruit and open-source hardware by purchasing products from 15 | * Adafruit! 16 | * 17 | * @section author Author 18 | * 19 | * Limor Fried/Ladyada (Adafruit Industries). 20 | * 21 | * @section license License 22 | * 23 | * BSD (see license.txt) 24 | * 25 | * @section HISTORY 26 | * 27 | * v1.0 - First release 28 | */ 29 | 30 | #include 31 | 32 | Adafruit_TPA2016::Adafruit_TPA2016() {} 33 | 34 | /*! 35 | * @brief Setups the i2c and calls powerUp function. 36 | * @param addr 37 | * i2c address 38 | * @param theWire 39 | * wire object 40 | * @return True if initialization was successful, otherwise false. 41 | * 42 | */ 43 | boolean Adafruit_TPA2016::begin(uint8_t addr, TwoWire *theWire) { 44 | if (i2c_dev) 45 | delete i2c_dev; 46 | i2c_dev = new Adafruit_I2CDevice(addr, theWire); 47 | if (!i2c_dev->begin()) 48 | return false; 49 | 50 | return true; 51 | } 52 | 53 | /*! 54 | * @brief Set gain in dB by writing to TPA2016_GAIN. 55 | * @param g 56 | * value in dB (clamped between -28 to 30) 57 | */ 58 | void Adafruit_TPA2016::setGain(int8_t g) { 59 | if (g > 30) 60 | g = 30; 61 | if (g < -28) 62 | g = -28; 63 | 64 | write8(TPA2016_GAIN, g); 65 | } 66 | 67 | /*! 68 | * @brief Gets the gain value by readig from TPA2016_GAIN. 69 | * @return Returns gain value in dB 70 | */ 71 | int8_t Adafruit_TPA2016::getGain() { 72 | int8_t gain = int8_t(read8(TPA2016_GAIN)); 73 | gain = gain << 2; 74 | if ((gain & 0x80) > 0) 75 | gain = (gain >> 2) | 0xC0; // it's a negative value 76 | else 77 | gain = gain >> 2; // it's a positive value 78 | return gain; 79 | } 80 | 81 | /*! 82 | * @brief Turns on / off right and left channels by writing to 83 | * TPA2016_SETUP. 84 | * @param r 85 | * right channel 86 | * @param l 87 | * left channel 88 | * 89 | */ 90 | void Adafruit_TPA2016::enableChannel(boolean r, boolean l) { 91 | 92 | uint8_t setup = read8(TPA2016_SETUP); 93 | if (r) 94 | setup |= TPA2016_SETUP_R_EN; 95 | else 96 | setup &= ~TPA2016_SETUP_R_EN; 97 | if (l) 98 | setup |= TPA2016_SETUP_L_EN; 99 | else 100 | setup &= ~TPA2016_SETUP_L_EN; 101 | 102 | write8(TPA2016_SETUP, setup); 103 | } 104 | 105 | /*! 106 | * @brief Sets AGC Compression by writing to TPA2016_AGC 107 | * @param x 108 | * TPA2016_AGC_2 1:2 109 | * TPA2016_AGC_4 1:4 110 | * TPA2016_AGC_8 1:8 111 | */ 112 | void Adafruit_TPA2016::setAGCCompression(uint8_t x) { 113 | if (x > 3) 114 | return; // only 2 bits! 115 | 116 | uint8_t agc = read8(TPA2016_AGC); 117 | agc &= ~(0x03); // mask off bottom 2 bits 118 | agc |= x; // set the compression ratio. 119 | write8(TPA2016_AGC, agc); 120 | } 121 | 122 | /*! 123 | * @brief Sets AGC Release time by writing to TPA2016_REL. 124 | * @param release 125 | * release value (only 6 bits) 126 | */ 127 | void Adafruit_TPA2016::setReleaseControl(uint8_t release) { 128 | if (release > 0x3F) 129 | return; // only 6 bits! 130 | 131 | write8(TPA2016_REL, release); 132 | } 133 | 134 | /*! 135 | * @brief Sets AGC Attack time by writing to TPA2016_ATK. 136 | * @param attack 137 | * attack value (only 6 bits) 138 | */ 139 | void Adafruit_TPA2016::setAttackControl(uint8_t attack) { 140 | if (attack > 0x3F) 141 | return; // only 6 bits! 142 | 143 | write8(TPA2016_ATK, attack); 144 | } 145 | 146 | /*! 147 | * @brief Sets AGC Hold time by writing to TPA2016_HOLD. 148 | * @param hold 149 | * hold time value (only 6 bits) 150 | */ 151 | void Adafruit_TPA2016::setHoldControl(uint8_t hold) { 152 | if (hold > 0x3F) 153 | return; // only 6 bits! 154 | 155 | write8(TPA2016_HOLD, hold); 156 | } 157 | 158 | /*! 159 | * @brief Turns Power limiter on by writing to TPA2016_AGCLIMIT. 160 | */ 161 | void Adafruit_TPA2016::setLimitLevelOn() { 162 | uint8_t agc = read8(TPA2016_AGCLIMIT); 163 | agc &= ~(0x80); // mask off top bit 164 | write8(TPA2016_AGCLIMIT, agc); 165 | } 166 | 167 | /*! 168 | * @brief Turns Power limiter off by writing to TPA2016_AGCLIMIT. 169 | */ 170 | void Adafruit_TPA2016::setLimitLevelOff() { 171 | uint8_t agc = read8(TPA2016_AGCLIMIT); 172 | agc |= 0x80; // turn on top bit 173 | write8(TPA2016_AGCLIMIT, agc); 174 | } 175 | 176 | /*! 177 | * @brief Sets limit level by writing to TPA2016_AGCLIMIT. 178 | * @param limit 179 | * value (max 31) 180 | */ 181 | void Adafruit_TPA2016::setLimitLevel(uint8_t limit) { 182 | if (limit > 31) 183 | return; 184 | 185 | uint8_t agc = read8(TPA2016_AGCLIMIT); 186 | 187 | agc &= ~(0x1F); // mask off bottom 5 bits 188 | agc |= limit; // set the limit level. 189 | 190 | write8(TPA2016_AGCLIMIT, agc); 191 | } 192 | 193 | /*! 194 | * @brief Sets max gain by writing to TPA2016_AGC. 195 | * @param x 196 | * value (max 12) 197 | */ 198 | void Adafruit_TPA2016::setAGCMaxGain(uint8_t x) { 199 | if (x > 12) 200 | return; // max gain max is 12 (30dB) 201 | 202 | uint8_t agc = read8(TPA2016_AGC); 203 | agc &= ~(0xF0); // mask off top 4 bits 204 | agc |= (x << 4); // set the max gain 205 | write8(TPA2016_AGC, agc); 206 | } 207 | 208 | // Read 1 byte from the i2c bus at 'address' 209 | uint8_t Adafruit_TPA2016::read8(uint8_t address) { 210 | uint8_t buffer[1] = {address}; 211 | i2c_dev->write_then_read(buffer, 1, buffer, 1); 212 | return buffer[0]; 213 | } 214 | 215 | // write 1 byte 216 | void Adafruit_TPA2016::write8(uint8_t address, uint8_t data) { 217 | uint8_t buffer[2] = {address, data}; 218 | i2c_dev->write(buffer, 2); 219 | } 220 | -------------------------------------------------------------------------------- /Adafruit_TPA2016.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file Adafruit_TPA2016.h 3 | * 4 | * This is a library for the TPA2016D2 Class D Amplifier Breakout 5 | * 6 | * Designed specifically to work with the Adafruit TPA2016 Stereo 2.8W Class D 7 | * Audio Amplifier - I2C Control AGC 8 | * 9 | * Pick one up today in the adafruit shop! 10 | * ------> https://www.adafruit.com/product/1712 11 | * 12 | * This amplifier uses I2C to communicate, 2 pins are required to interface 13 | * 14 | * Adafruit invests time and resources providing this open source code, 15 | * please support Adafruit andopen-source hardware by purchasing products 16 | * from Adafruit! 17 | * 18 | * Limor Fried/Ladyada (Adafruit Industries). 19 | * 20 | * BSD license, all text above must be included in any redistribution 21 | */ 22 | 23 | #ifndef _ADAFRUIT_TPA2016_H 24 | #define _ADAFRUIT_TPA2016_H 25 | 26 | #include 27 | #include 28 | 29 | #define TPA2016_SETUP 0x1 ///< Function Control 30 | #define TPA2016_SETUP_R_EN 0x80 ///< Enables right amplifier 31 | #define TPA2016_SETUP_L_EN 0x40 ///< Enables left amplifier 32 | #define TPA2016_SETUP_SWS 0x20 ///< Shutdown IC when bit = 1 33 | #define TPA2016_SETUP_R_FAULT \ 34 | 0x10 ///< Changes to a 1 when there is a short on the right channel. Reset by 35 | ///< writing a 0. 36 | #define TPA2016_SETUP_L_FAULT \ 37 | 0x08 ///< Changes to a 1 when there is a short on the left channel. Reset by 38 | ///< writing a 0 39 | #define TPA2016_SETUP_THERMAL \ 40 | 0x04 ///< Changes to a 1 when die temperature is above 150°C 41 | #define TPA2016_SETUP_NOISEGATE 0x01 ///< Enables Noise Gate function 42 | 43 | #define TPA2016_ATK 0x2 ///< AGC Attack time (gain ramp down) 44 | #define TPA2016_REL 0x3 ///< AGC Release time (gain ramp down) 45 | #define TPA2016_HOLD 0x4 ///< AGC Hold time 46 | #define TPA2016_GAIN \ 47 | 0x5 ///< Sets the fixed gain of the amplifier: two's compliment 48 | #define TPA2016_AGCLIMIT \ 49 | 0x6 ///< Disables the output limiter function. Can only be disabled when the 50 | ///< AGC compression ratio is 1:1 (off) 51 | #define TPA2016_AGC 0x7 ///< Selects the maximum gain the AGC can achieve 52 | #define TPA2016_AGC_OFF 0x00 ///< Turn off AGC 53 | #define TPA2016_AGC_2 0x01 ///< AGC compression ratio 1:2 54 | #define TPA2016_AGC_4 0x02 ///< AGC compression ratio 1:4 55 | #define TPA2016_AGC_8 0x03 ///< AGC compression ratio 1:8 56 | 57 | #define TPA2016_I2CADDR 0x58 ///< Default TPA2016 i2c address 58 | 59 | /*! 60 | * @brief Class that stores state and functions for interacting with 61 | * TPA2016 breakout 62 | */ 63 | class Adafruit_TPA2016 { 64 | public: 65 | Adafruit_TPA2016(); 66 | 67 | boolean begin(uint8_t addr = TPA2016_I2CADDR, TwoWire *theWire = &Wire); 68 | 69 | void enableChannel(boolean r, boolean l); 70 | 71 | // Register #5 72 | void setGain(int8_t g); 73 | int8_t getGain(); 74 | 75 | // Register #3 76 | void setReleaseControl(uint8_t release); 77 | 78 | // Register #2 79 | void setAttackControl(uint8_t attack); 80 | 81 | // Register #4 82 | void setHoldControl(uint8_t hold); 83 | 84 | // Register #6 85 | void setLimitLevelOn(); 86 | void setLimitLevelOff(); 87 | void setLimitLevel(uint8_t limit); 88 | 89 | // Register #7 90 | void setAGCCompression(uint8_t x); 91 | void setAGCMaxGain(uint8_t x); 92 | 93 | private: 94 | Adafruit_I2CDevice *i2c_dev = NULL; ///< Pointer to I2C bus interface 95 | uint8_t read8(uint8_t a); 96 | void write8(uint8_t a, uint8_t d); 97 | }; 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Adafruit-TPA2016-Library [![Build Status](https://github.com/adafruit/Adafruit-TPA2016-Library/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/Adafruit-TPA2016-Library/actions)[![Documentation](https://github.com/adafruit/ci-arduino/blob/master/assets/doxygen_badge.svg)](http://adafruit.github.io/Adafruit-TPA2016-Library/html/index.html) 2 | 3 | 4 | 5 | This is the library for TPA2016D2 Class D Amplifier Breakout 6 | 7 | Tested and works great with the Adafruit TPA2016D2 Class D Amplifier Breakout 8 | * http://www.adafruit.com/products/1712 9 | 10 | These transmitters use I2C to communicate, plus reset pin, 3 pins are required to interface 11 | 12 | Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! 13 | 14 | Limor Fried/Ladyada (Adafruit Industries). 15 | BSD license, check license.txt for more information 16 | All text above must be included in any redistribution 17 | 18 | To install, use the Arduino Library Manager and search for "Adafruit TPA2016D2 Library" and install the library. 19 | 20 | -------------------------------------------------------------------------------- /assets/board.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/Adafruit-TPA2016-Library/17d1a6cf3f423952c0b07518e9ef46a2476bf8df/assets/board.jpg -------------------------------------------------------------------------------- /code-of-conduct.md: -------------------------------------------------------------------------------- 1 | # Adafruit Community Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and leaders pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level or type of 9 | experience, education, socio-economic status, nationality, personal appearance, 10 | race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | We are committed to providing a friendly, safe and welcoming environment for 15 | all. 16 | 17 | Examples of behavior that contributes to creating a positive environment 18 | include: 19 | 20 | * Be kind and courteous to others 21 | * Using welcoming and inclusive language 22 | * Being respectful of differing viewpoints and experiences 23 | * Collaborating with other community members 24 | * Gracefully accepting constructive criticism 25 | * Focusing on what is best for the community 26 | * Showing empathy towards other community members 27 | 28 | Examples of unacceptable behavior by participants include: 29 | 30 | * The use of sexualized language or imagery and sexual attention or advances 31 | * The use of inappropriate images, including in a community member's avatar 32 | * The use of inappropriate language, including in a community member's nickname 33 | * Any spamming, flaming, baiting or other attention-stealing behavior 34 | * Excessive or unwelcome helping; answering outside the scope of the question 35 | asked 36 | * Trolling, insulting/derogatory comments, and personal or political attacks 37 | * Public or private harassment 38 | * Publishing others' private information, such as a physical or electronic 39 | address, without explicit permission 40 | * Other conduct which could reasonably be considered inappropriate 41 | 42 | The goal of the standards and moderation guidelines outlined here is to build 43 | and maintain a respectful community. We ask that you don’t just aim to be 44 | "technically unimpeachable", but rather try to be your best self. 45 | 46 | We value many things beyond technical expertise, including collaboration and 47 | supporting others within our community. Providing a positive experience for 48 | other community members can have a much more significant impact than simply 49 | providing the correct answer. 50 | 51 | ## Our Responsibilities 52 | 53 | Project leaders are responsible for clarifying the standards of acceptable 54 | behavior and are expected to take appropriate and fair corrective action in 55 | response to any instances of unacceptable behavior. 56 | 57 | Project leaders have the right and responsibility to remove, edit, or 58 | reject messages, comments, commits, code, issues, and other contributions 59 | that are not aligned to this Code of Conduct, or to ban temporarily or 60 | permanently any community member for other behaviors that they deem 61 | inappropriate, threatening, offensive, or harmful. 62 | 63 | ## Moderation 64 | 65 | Instances of behaviors that violate the Adafruit Community Code of Conduct 66 | may be reported by any member of the community. Community members are 67 | encouraged to report these situations, including situations they witness 68 | involving other community members. 69 | 70 | You may report in the following ways: 71 | 72 | In any situation, you may send an email to . 73 | 74 | On the Adafruit Discord, you may send an open message from any channel 75 | to all Community Helpers by tagging @community helpers. You may also send an 76 | open message from any channel, or a direct message to @kattni#1507, 77 | @tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, or 78 | @Andon#8175. 79 | 80 | Email and direct message reports will be kept confidential. 81 | 82 | In situations on Discord where the issue is particularly egregious, possibly 83 | illegal, requires immediate action, or violates the Discord terms of service, 84 | you should also report the message directly to Discord. 85 | 86 | These are the steps for upholding our community’s standards of conduct. 87 | 88 | 1. Any member of the community may report any situation that violates the 89 | Adafruit Community Code of Conduct. All reports will be reviewed and 90 | investigated. 91 | 2. If the behavior is an egregious violation, the community member who 92 | committed the violation may be banned immediately, without warning. 93 | 3. Otherwise, moderators will first respond to such behavior with a warning. 94 | 4. Moderators follow a soft "three strikes" policy - the community member may 95 | be given another chance, if they are receptive to the warning and change their 96 | behavior. 97 | 5. If the community member is unreceptive or unreasonable when warned by a 98 | moderator, or the warning goes unheeded, they may be banned for a first or 99 | second offense. Repeated offenses will result in the community member being 100 | banned. 101 | 102 | ## Scope 103 | 104 | This Code of Conduct and the enforcement policies listed above apply to all 105 | Adafruit Community venues. This includes but is not limited to any community 106 | spaces (both public and private), the entire Adafruit Discord server, and 107 | Adafruit GitHub repositories. Examples of Adafruit Community spaces include 108 | but are not limited to meet-ups, audio chats on the Adafruit Discord, or 109 | interaction at a conference. 110 | 111 | This Code of Conduct applies both within project spaces and in public spaces 112 | when an individual is representing the project or its community. As a community 113 | member, you are representing our community, and are expected to behave 114 | accordingly. 115 | 116 | ## Attribution 117 | 118 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 119 | version 1.4, available at 120 | , 121 | and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html). 122 | 123 | For other projects adopting the Adafruit Community Code of 124 | Conduct, please contact the maintainers of those projects for enforcement. 125 | If you wish to use this code of conduct for your own project, consider 126 | explicitly mentioning your moderation policy or making a copy with your 127 | own moderation policy so as to avoid confusion. 128 | -------------------------------------------------------------------------------- /examples/audioamptest/audioamptest.ino: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is an example for our Adafruit TPA2016 Class D Amplifier Breakout 3 | 4 | Pick one up today in the adafruit shop! 5 | ------> http://www.adafruit.com/products/1712 6 | 7 | This amplifier uses I2C to communicate, 2 pins are required to 8 | interface 9 | 10 | Adafruit invests time and resources providing this open source code, 11 | please support Adafruit and open-source hardware by purchasing 12 | products from Adafruit! 13 | 14 | Written by Limor Fried/Ladyada for Adafruit Industries. 15 | BSD license, all text above must be included in any redistribution 16 | ****************************************************/ 17 | 18 | 19 | #include "Adafruit_TPA2016.h" 20 | 21 | Adafruit_TPA2016 audioamp = Adafruit_TPA2016(); 22 | 23 | void setup() { 24 | Serial.begin(9600); 25 | 26 | 27 | Serial.println("TPA2016 Audio Test"); 28 | audioamp.begin(); 29 | 30 | // Dump register map, for debugging purposes. 31 | /* 32 | for (uint8_t i=1; i<8; i++) { 33 | Serial.print("Register #"); Serial.print(i); 34 | Serial.print(": 0x"); 35 | Serial.println(audioamp.read8(i), HEX); 36 | } 37 | */ 38 | 39 | // Turn off AGC for the gain test 40 | audioamp.setAGCCompression(TPA2016_AGC_OFF); 41 | // we also have to turn off the release to really turn off AGC 42 | audioamp.setReleaseControl(0); 43 | 44 | // We can update the gain, from -28dB up to 30dB 45 | for (int8_t i=-28; i<=30; i++) { 46 | Serial.print("Gain = "); Serial.println(i); 47 | audioamp.setGain(i); 48 | delay(500); 49 | } 50 | 51 | // Each channel can be individually controlled 52 | Serial.println("Left off"); 53 | audioamp.enableChannel(true, false); 54 | delay(1000); 55 | Serial.println("Left On, Right off"); 56 | audioamp.enableChannel(false, true); 57 | delay(1000); 58 | Serial.println("Left On, Right On"); 59 | audioamp.enableChannel(true, true); 60 | delay(1000); 61 | 62 | // OK now we'll turn the AGC back on and mess with the settings :) 63 | 64 | // AGC can be TPA2016_AGC_OFF (no AGC) or 65 | // TPA2016_AGC_2 (1:2 compression) 66 | // TPA2016_AGC_4 (1:4 compression) 67 | // TPA2016_AGC_8 (1:8 compression) 68 | Serial.println("Setting AGC Compression"); 69 | audioamp.setAGCCompression(TPA2016_AGC_2); 70 | 71 | // See Datasheet page 22 for value -> dBV conversion table 72 | Serial.println("Setting Limit Level"); 73 | audioamp.setLimitLevelOn(); 74 | // or turn off with setLimitLevelOff() 75 | audioamp.setLimitLevel(25); // range from 0 (-6.5dBv) to 31 (9dBV) 76 | 77 | // See Datasheet page 23 for value -> ms conversion table 78 | Serial.println("Setting AGC Attack"); 79 | audioamp.setAttackControl(5); 80 | 81 | // See Datasheet page 24 for value -> ms conversion table 82 | Serial.println("Setting AGC Hold"); 83 | audioamp.setHoldControl(0); 84 | 85 | // See Datasheet page 24 for value -> ms conversion table 86 | Serial.println("Setting AGC Release"); 87 | audioamp.setReleaseControl(11); 88 | } 89 | 90 | 91 | void loop() { 92 | 93 | } -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Adafruit TPA2016 Library 2 | version=1.2.2 3 | author=Adafruit 4 | maintainer=Adafruit 5 | sentence=Arduino library for the Adafruit TPA2016(D2) I2C controlled AGC audio amplifier 6 | paragraph=Arduino library for the Adafruit TPA2016(D2) I2C controlled AGC audio amplifier 7 | category=Device Control 8 | url=https://github.com/adafruit/Adafruit-TPA2016-Library 9 | architectures=* 10 | depends=Adafruit BusIO 11 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Adafruit Industries 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | --------------------------------------------------------------------------------