A feature complete driver for the MAX9723 headphone amplifier from Maxim.

Dependents:   MAX9723_HelloWorld

Committer:
neilt6
Date:
Fri May 30 19:46:37 2014 +0000
Revision:
0:99db25d6f38d
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
neilt6 0:99db25d6f38d 1 /* MAX9723 Driver Library
neilt6 0:99db25d6f38d 2 * Copyright (c) 2014 Neil Thiessen
neilt6 0:99db25d6f38d 3 *
neilt6 0:99db25d6f38d 4 * Licensed under the Apache License, Version 2.0 (the "License");
neilt6 0:99db25d6f38d 5 * you may not use this file except in compliance with the License.
neilt6 0:99db25d6f38d 6 * You may obtain a copy of the License at
neilt6 0:99db25d6f38d 7 *
neilt6 0:99db25d6f38d 8 * http://www.apache.org/licenses/LICENSE-2.0
neilt6 0:99db25d6f38d 9 *
neilt6 0:99db25d6f38d 10 * Unless required by applicable law or agreed to in writing, software
neilt6 0:99db25d6f38d 11 * distributed under the License is distributed on an "AS IS" BASIS,
neilt6 0:99db25d6f38d 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
neilt6 0:99db25d6f38d 13 * See the License for the specific language governing permissions and
neilt6 0:99db25d6f38d 14 * limitations under the License.
neilt6 0:99db25d6f38d 15 */
neilt6 0:99db25d6f38d 16
neilt6 0:99db25d6f38d 17 #ifndef MAX9723_H
neilt6 0:99db25d6f38d 18 #define MAX9723_H
neilt6 0:99db25d6f38d 19
neilt6 0:99db25d6f38d 20 #include "mbed.h"
neilt6 0:99db25d6f38d 21
neilt6 0:99db25d6f38d 22 /** MAX9723 class.
neilt6 0:99db25d6f38d 23 * Used for controlling a MAX9723 headphone amplifier connected via I2C (TODO: Redo Example!).
neilt6 0:99db25d6f38d 24 *
neilt6 0:99db25d6f38d 25 * Example:
neilt6 0:99db25d6f38d 26 * @code
neilt6 0:99db25d6f38d 27 * #include "mbed.h"
neilt6 0:99db25d6f38d 28 * #include "MAX9723.h"
neilt6 0:99db25d6f38d 29 *
neilt6 0:99db25d6f38d 30 * //Create a MAX9723 object at the default address (ADDRESS_0)
neilt6 0:99db25d6f38d 31 * MAX9723 amp(p28, p27);
neilt6 0:99db25d6f38d 32 *
neilt6 0:99db25d6f38d 33 * int main()
neilt6 0:99db25d6f38d 34 * {
neilt6 0:99db25d6f38d 35 * //Try to open the MAX9723
neilt6 0:99db25d6f38d 36 * if (amp.open()) {
neilt6 0:99db25d6f38d 37 * printf("Device detected!\n");
neilt6 0:99db25d6f38d 38 *
neilt6 0:99db25d6f38d 39 * //Configure the MAX9723 for no BassMax, and low gain
neilt6 0:99db25d6f38d 40 * amp.enabled(true);
neilt6 0:99db25d6f38d 41 * amp.bassMax(false);
neilt6 0:99db25d6f38d 42 * amp.maxGain(false);
neilt6 0:99db25d6f38d 43 *
neilt6 0:99db25d6f38d 44 * //Set the volume for 50%
neilt6 0:99db25d6f38d 45 * amp = 0.50;
neilt6 0:99db25d6f38d 46 * } else {
neilt6 0:99db25d6f38d 47 * error("Device not detected!\n");
neilt6 0:99db25d6f38d 48 * }
neilt6 0:99db25d6f38d 49 * }
neilt6 0:99db25d6f38d 50 * @endcode
neilt6 0:99db25d6f38d 51 */
neilt6 0:99db25d6f38d 52 class MAX9723
neilt6 0:99db25d6f38d 53 {
neilt6 0:99db25d6f38d 54 public:
neilt6 0:99db25d6f38d 55 /** Represents the different I2C address possibilities for the MAX9723
neilt6 0:99db25d6f38d 56 */
neilt6 0:99db25d6f38d 57 enum Address {
neilt6 0:99db25d6f38d 58 ADDRESS_0 = (0x4C << 1), /**< MAX9723A or MAX9723C */
neilt6 0:99db25d6f38d 59 ADDRESS_1 = (0x4D << 1) /**< MAX9723B or MAX9723D */
neilt6 0:99db25d6f38d 60 };
neilt6 0:99db25d6f38d 61
neilt6 0:99db25d6f38d 62 /** Create an MAX9723 object connected to the specified I2C pins with the specified I2C slave address
neilt6 0:99db25d6f38d 63 *
neilt6 0:99db25d6f38d 64 * @param sda The I2C data pin.
neilt6 0:99db25d6f38d 65 * @param scl The I2C clock pin.
neilt6 0:99db25d6f38d 66 * @param addr The I2C slave address (defaults to ADDRESS_0).
neilt6 0:99db25d6f38d 67 * @param hz The I2C bus frequency (defaults to 400kHz).
neilt6 0:99db25d6f38d 68 */
neilt6 0:99db25d6f38d 69 MAX9723(PinName sda, PinName scl, Address addr = ADDRESS_0, int hz = 400000);
neilt6 0:99db25d6f38d 70
neilt6 0:99db25d6f38d 71 /** Probe for the MAX9723 and set it to default values if present
neilt6 0:99db25d6f38d 72 *
neilt6 0:99db25d6f38d 73 * @returns
neilt6 0:99db25d6f38d 74 * 'true' if the device exists on the bus,
neilt6 0:99db25d6f38d 75 * 'false' if the device doesn't exist on the bus.
neilt6 0:99db25d6f38d 76 */
neilt6 0:99db25d6f38d 77 bool open();
neilt6 0:99db25d6f38d 78
neilt6 0:99db25d6f38d 79 /** Determine whether or not the MAX9723 is enabled
neilt6 0:99db25d6f38d 80 *
neilt6 0:99db25d6f38d 81 * @returns
neilt6 0:99db25d6f38d 82 * 'true' if the MAX9723 is enabled,
neilt6 0:99db25d6f38d 83 * 'false' if the MAX9723 is shutdown.
neilt6 0:99db25d6f38d 84 */
neilt6 0:99db25d6f38d 85 bool enabled();
neilt6 0:99db25d6f38d 86
neilt6 0:99db25d6f38d 87 /** Set whether or not the MAX9723 is enabled
neilt6 0:99db25d6f38d 88 *
neilt6 0:99db25d6f38d 89 * @param enabled Whether or not the MAX9723 is enabled.
neilt6 0:99db25d6f38d 90 */
neilt6 0:99db25d6f38d 91 void enabled(bool enabled);
neilt6 0:99db25d6f38d 92
neilt6 0:99db25d6f38d 93 /** Determine whether or not BassMax is enabled on the MAX9723
neilt6 0:99db25d6f38d 94 *
neilt6 0:99db25d6f38d 95 * @returns
neilt6 0:99db25d6f38d 96 * 'true' if BassMax is enabled,
neilt6 0:99db25d6f38d 97 * 'false' if BassMax is disabled.
neilt6 0:99db25d6f38d 98 */
neilt6 0:99db25d6f38d 99 bool bassMax();
neilt6 0:99db25d6f38d 100
neilt6 0:99db25d6f38d 101 /** Enable or disable BassMax on the MAX9723
neilt6 0:99db25d6f38d 102 *
neilt6 0:99db25d6f38d 103 * @param enabled Whether or not BassMax is enabled.
neilt6 0:99db25d6f38d 104 */
neilt6 0:99db25d6f38d 105 void bassMax(bool enabled);
neilt6 0:99db25d6f38d 106
neilt6 0:99db25d6f38d 107 /** Determine whether or not the MAX9723 gain is set to maximum
neilt6 0:99db25d6f38d 108 *
neilt6 0:99db25d6f38d 109 * @returns
neilt6 0:99db25d6f38d 110 * 'true' if the gain is set to 0dB on MAX9723A and MAX9723B, or +6dB on MAX9723C and MAX9723D,
neilt6 0:99db25d6f38d 111 * 'false' if the gain is set to -5dB on MAX9723A and MAX9723B, or +1dB on MAX9723C and MAX9723D.
neilt6 0:99db25d6f38d 112 */
neilt6 0:99db25d6f38d 113 bool maxGain();
neilt6 0:99db25d6f38d 114
neilt6 0:99db25d6f38d 115 /** Set whether or not the MAX9723 gain is set to maximum
neilt6 0:99db25d6f38d 116 *
neilt6 0:99db25d6f38d 117 * @param max Whether or not the gain is set to maximum.
neilt6 0:99db25d6f38d 118 */
neilt6 0:99db25d6f38d 119 void maxGain(bool max);
neilt6 0:99db25d6f38d 120
neilt6 0:99db25d6f38d 121 /** Get the current volume of the MAX9723 as a percentage
neilt6 0:99db25d6f38d 122 *
neilt6 0:99db25d6f38d 123 * @returns The current volume as a percentage (0.0 to 1.0).
neilt6 0:99db25d6f38d 124 */
neilt6 0:99db25d6f38d 125 float volume();
neilt6 0:99db25d6f38d 126
neilt6 0:99db25d6f38d 127 /** Set the volume of the MAX9723 from a percentage
neilt6 0:99db25d6f38d 128 *
neilt6 0:99db25d6f38d 129 * @param volume The new volume as a percentage (0.0 to 1.0).
neilt6 0:99db25d6f38d 130 */
neilt6 0:99db25d6f38d 131 void volume(float volume);
neilt6 0:99db25d6f38d 132
neilt6 0:99db25d6f38d 133 #ifdef MBED_OPERATORS
neilt6 0:99db25d6f38d 134 /** A shorthand for volume()
neilt6 0:99db25d6f38d 135 *
neilt6 0:99db25d6f38d 136 * @returns The current volume as a percentage (0.0 to 1.0).
neilt6 0:99db25d6f38d 137 */
neilt6 0:99db25d6f38d 138 operator float();
neilt6 0:99db25d6f38d 139
neilt6 0:99db25d6f38d 140 /** A shorthand for volume()
neilt6 0:99db25d6f38d 141 *
neilt6 0:99db25d6f38d 142 * @param value The new volume as a percentage (0.0 to 1.0).
neilt6 0:99db25d6f38d 143 */
neilt6 0:99db25d6f38d 144 MAX9723& operator=(float value);
neilt6 0:99db25d6f38d 145 #endif
neilt6 0:99db25d6f38d 146
neilt6 0:99db25d6f38d 147 private:
neilt6 0:99db25d6f38d 148 //I2C member variables
neilt6 0:99db25d6f38d 149 I2C m_I2C;
neilt6 0:99db25d6f38d 150 const int m_ADDR;
neilt6 0:99db25d6f38d 151
neilt6 0:99db25d6f38d 152 //Amplifier settings member variables
neilt6 0:99db25d6f38d 153 char m_AmpValue;
neilt6 0:99db25d6f38d 154 };
neilt6 0:99db25d6f38d 155
neilt6 0:99db25d6f38d 156 #endif