0.2.0 PT2314

This commit is contained in:
Rob Tillaart 2023-12-08 17:20:42 +01:00
parent b0736c59be
commit d717db36a0
10 changed files with 166 additions and 61 deletions

View File

@ -6,11 +6,19 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/). and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.2.0] - 2023-12-08
- refactor API, begin()
- update readme.md
- added **void setAttn(uint8_t attn)**
- removed setAttn(left, right).
- minor edits
----
## [0.1.2] - 2023-09-24 ## [0.1.2] - 2023-09-24
- add Wire1 support for ESP32 - add Wire1 support for ESP32
- update readme.md - update readme.md
## [0.1.1] - 2023-08-01 ## [0.1.1] - 2023-08-01
- add **PT7313** derived class - add **PT7313** derived class
- 3 input 2 output version - 3 input 2 output version

View File

@ -2,7 +2,7 @@
// FILE: PT2314.cpp // FILE: PT2314.cpp
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// DATE: 2023-07-30 // DATE: 2023-07-30
// VERSION: 0.1.2 // VERSION: 0.2.0
// PURPOSE: Arduino library for PT2314 i2C 4 channel audio processor. // PURPOSE: Arduino library for PT2314 i2C 4 channel audio processor.
// URL: https://github.com/RobTillaart/PT2314 // URL: https://github.com/RobTillaart/PT2314
@ -16,32 +16,8 @@ PT2314::PT2314(TwoWire *wire)
} }
#if defined (ESP8266) || defined(ESP32)
bool PT2314::begin(int dataPin, int clockPin)
{
if ((dataPin < 255) && (clockPin < 255))
{
_wire->begin(dataPin, clockPin);
} else {
_wire->begin();
}
if (! isConnected()) return false;
setChannel();
setMute();
setLoudness();
setVolume();
setBass();
setTreble();
setGain();
// setAttn(31,31); // already muted
return true;
}
#endif
bool PT2314::begin() bool PT2314::begin()
{ {
_wire->begin();
if (! isConnected()) return false; if (! isConnected()) return false;
setChannel(); setChannel();
setMute(); setMute();
@ -50,7 +26,7 @@ bool PT2314::begin()
setBass(); setBass();
setTreble(); setTreble();
setGain(); setGain();
// setAttn(31,31); // already muted // setAttn(31, 31); // already muted
return true; return true;
} }
@ -206,14 +182,15 @@ uint8_t PT2314::getAttnRight()
} }
void PT2314::setAttn(uint8_t attnLeft, uint8_t attnRight) void PT2314::setAttn(uint8_t attn)
{ {
setAttnLeft(attnLeft); setAttnLeft(attn);
setAttnRight(attnRight); setAttnRight(attn);
} }
/////////////////////////////////////////////////// ///////////////////////////////////////////////////
// //
// PROTECTED // PROTECTED
@ -330,5 +307,14 @@ uint8_t PT7313::getAttnRightFront()
} }
void PT7313::setAttn(uint8_t attn)
{
setAttnLeft(attn);
setAttnRight(attn);
setAttnLeftFront(attn);
setAttnRightFront(attn);
}
// -- END OF FILE -- // -- END OF FILE --

View File

@ -3,7 +3,7 @@
// FILE: PT2314.h // FILE: PT2314.h
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// DATE: 2023-07-30 // DATE: 2023-07-30
// VERSION: 0.1.2 // VERSION: 0.2.0
// PURPOSE: Arduino library for PT2314 i2C 4 channel audio processor. // PURPOSE: Arduino library for PT2314 i2C 4 channel audio processor.
// URL: https://github.com/RobTillaart/PT2314 // URL: https://github.com/RobTillaart/PT2314
@ -12,7 +12,7 @@
#include "Wire.h" #include "Wire.h"
#define PT2314_LIB_VERSION (F("0.1.2")) #define PT2314_LIB_VERSION (F("0.2.0"))
class PT2314 class PT2314
@ -20,9 +20,6 @@ class PT2314
public: public:
PT2314(TwoWire *wire = &Wire); PT2314(TwoWire *wire = &Wire);
#if defined (ESP8266) || defined(ESP32)
bool begin(int sda, int scl);
#endif
bool begin(); bool begin();
bool isConnected(); bool isConnected();
@ -42,14 +39,18 @@ public:
void setTreble(int8_t treble = 0); // -14..14 void setTreble(int8_t treble = 0); // -14..14
int8_t getTreble(); int8_t getTreble();
// GAIN
void setGain(uint8_t gain = 0); // 0..3 void setGain(uint8_t gain = 0); // 0..3
uint8_t getGain(); uint8_t getGain();
// ATTENUATION
void setAttnLeft(uint8_t value = 31); // 0..31 void setAttnLeft(uint8_t value = 31); // 0..31
uint8_t getAttnLeft(); uint8_t getAttnLeft();
void setAttnRight(uint8_t value = 31); // 0..31 void setAttnRight(uint8_t value = 31); // 0..31
uint8_t getAttnRight(); uint8_t getAttnRight();
void setAttn(uint8_t attnLeft, uint8_t attnRight);
// set all to same level
void setAttn(uint8_t attn);
protected: protected:
@ -72,6 +73,7 @@ protected:
int _error = 0; int _error = 0;
}; };
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// //
// DERIVED // DERIVED
@ -92,15 +94,21 @@ public:
void setMute(bool on); void setMute(bool on);
void setChannel(uint8_t channel = 0); // 0..2 void setChannel(uint8_t channel = 0); // 0..2
// BACK
void setAttnLeftBack(uint8_t value = 31); // 0..31 void setAttnLeftBack(uint8_t value = 31); // 0..31
uint8_t getAttnLeftBack(); uint8_t getAttnLeftBack();
void setAttnRightBack(uint8_t value = 31); // 0..31 void setAttnRightBack(uint8_t value = 31); // 0..31
uint8_t getAttnRightBack(); uint8_t getAttnRightBack();
// FRONT
void setAttnLeftFront(uint8_t value = 31); // 0..31 void setAttnLeftFront(uint8_t value = 31); // 0..31
uint8_t getAttnLeftFront(); uint8_t getAttnLeftFront();
void setAttnRightFront(uint8_t value = 31); // 0..31 void setAttnRightFront(uint8_t value = 31); // 0..31
uint8_t getAttnRightFront(); uint8_t getAttnRightFront();
// ALL
void setAttn(uint8_t attn);
protected: protected:
uint8_t _attnLeftFront = 0; uint8_t _attnLeftFront = 0;
uint8_t _attnRightFront = 0; uint8_t _attnRightFront = 0;

View File

@ -35,9 +35,24 @@ It is used in automotive to control front and back speakers.
| PT7314 | 4 | 1 | V1.0 Jan, 2010 | | PT7314 | 4 | 1 | V1.0 Jan, 2010 |
| PT7313 | 3 | 2 | V1.0 feb, 2010 | | PT7313 | 3 | 2 | V1.0 feb, 2010 |
| processor | volume | attn | gain | bass | treble |
|:-----------:|:--------:|:-------:|:------:|:---------:|:---------:|
| PT2314 | 0..63 | 0..31 | 0..3 | -14..14 | -14..14 |
| PT7314 | 0..63 | 0..31 | 0..3 | -14..14 | -14..14 |
| PT7313 | 0..63 | 0..31 | 0..3 | -14..14 | -14..14 |
Feedback as always, is welcome. Feedback as always, is welcome.
The library is based upon Datasheet: PT2314 V1.4 July, 2005
#### 0.2.0 Breaking change
Version 0.2.0 introduced a breaking change.
You cannot set the pins in **begin()** any more.
This reduces the dependency of processor dependent Wire implementations.
The user has to call **Wire.begin()** and can optionally set the Wire pins
before calling **begin()**.
#### I2C #### I2C
@ -50,8 +65,24 @@ The library is based upon Datasheet: PT2314 V1.4 July, 2005
Note: Datasheet PT7314 states that the device needs at least 50 ms Note: Datasheet PT7314 states that the device needs at least 50 ms
to wake up before it can process I2C commands. So one might need to wake up before it can process I2C commands.
to give it some time to get started. So one might need to give it some time to get started.
#### Multiplexing
If you want to put more than one PT2314 on an I2C bus you need an
I2C multiplexer as the device has a fixed address.
See https://github.com/RobTillaart/TCA9548
(not tested, feedback welcome).
#### Related
- https://github.com/RobTillaart/HC4052 (multiplexer for more inputs)
- https://github.com/RobTillaart/TCA9548 (I2C multiplexer)
## Interface PT2314 PT7314 ## Interface PT2314 PT7314
@ -63,10 +94,11 @@ to give it some time to get started.
#### Constructors #### Constructors
- **PT2314(TwoWire \*wire = &Wire)** constructor, optional set Wire interface. - **PT2314(TwoWire \*wire = &Wire)** constructor, optional set Wire interface.
- **PT7313(TwoWire \*wire = &Wire)** constructor, optional set Wire interface.
- **PT7314(TwoWire \*wire = &Wire)** constructor, optional set Wire interface. - **PT7314(TwoWire \*wire = &Wire)** constructor, optional set Wire interface.
- **bool begin(int sda, int scl)** for ESP32 et al. - **bool begin()** initialized library.
- **bool begin()** other platforms. Returns true if device can be seen on the I2C bus.
- **bool isConnected()** device (0x44) can be seen on I2C bus. - **bool isConnected()** returns true if device (0x44) can be seen on I2C bus.
#### Channel #### Channel
@ -111,27 +143,30 @@ CHeck datasheet for mapping.
- **uint8_t getAttnLeft()** get current left attenuation level. - **uint8_t getAttnLeft()** get current left attenuation level.
- **void setAttnRight(uint8_t value = 31)** set the right attenuation from 0..31. - **void setAttnRight(uint8_t value = 31)** set the right attenuation from 0..31.
- **uint8_t getAttnRight()** get current right attenuation level. - **uint8_t getAttnRight()** get current right attenuation level.
- **void setAttn(uint8_t attnLeft, uint8_t attnRight)** set both in one call. - **void setAttn(uint8_t attn)** set all channels in one call.
Convenience function.
Formula attenuation: Formula attenuation:
```cpp ```cpp
Attn = value * -1.25; // dB 0..-37.50, 31 ==> MUTE. Attn = value * -1.25; // dB 0..-37.50, 31 ==> MUTE.
``` ```
----
## Interface PT7313 ## Interface PT7313
```cpp ```cpp
#include "PT2314.h" #include "PT2314.h"
``` ```
Additional constructor: #### Additional
- **PT7313(TwoWire \*wire = &Wire)** constructor.
- **PT7313(TwoWire \*wire = &Wire)** constructor.
- **void setMute(bool on)** idem, four channel version. - **void setMute(bool on)** idem, four channel version.
- **void setChannel(uint8_t channel = 0)** idem, 0..2. - **void setChannel(uint8_t channel = 0)** idem, 0..2.
Additional attenuation: #### PT7313 attenuation
- **void setAttnLeftBack(uint8_t value = 31)** idem, 0..31. - **void setAttnLeftBack(uint8_t value = 31)** idem, 0..31.
- **uint8_t getAttnLeftBack()** get current level. - **uint8_t getAttnLeftBack()** get current level.
- **void setAttnRightBack(uint8_t value = 31)** idem, 0..31 - **void setAttnRightBack(uint8_t value = 31)** idem, 0..31
@ -151,9 +186,6 @@ Additional attenuation:
#### Should #### Should
- investigate **setAttn(value)** function for all channels.
- better also for the 7313
- 0.2.0 ==> remove the setAttn(left, right) ?
- add more examples. - add more examples.
- check parameters range: 0..63 => -63..0? - check parameters range: 0..63 => -63..0?
- some are in dB others not. - some are in dB others not.

View File

@ -1,7 +1,7 @@
// //
// FILE: PT2314_demo.ino // FILE: PT2314_demo.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// PURPOSE: simple demo // PURPOSE: minimal demo
// URL: https://github.com/RobTillaart/PT2314 // URL: https://github.com/RobTillaart/PT2314
@ -18,11 +18,15 @@ void setup()
Serial.println(__FILE__); Serial.println(__FILE__);
delay(100); delay(100);
Wire.begin();
pt.begin(); pt.begin();
// do your settings // do your settings
pt.setVolume(20); pt.setVolume(20);
pt.setAttn(15, 24); // shift the balance // shift the balance
pt.setAttnLeft(15);
pt.setAttnRight(24);
pt.setLoudness(true); pt.setLoudness(true);
} }
@ -31,4 +35,5 @@ void loop()
{ {
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -0,0 +1,65 @@
//
// FILE: PT7313_demo.ino
// AUTHOR: Rob Tillaart
// PURPOSE: move sound around
// URL: https://github.com/RobTillaart/PT2314
#include "PT2314.h"
// PT2413 pt;
// PT7314 pt;
PT7313 pt;
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
delay(100);
Wire.begin();
pt.begin();
// do your settings
pt.setVolume(20);
pt.setAttnLeft(0);
pt.setAttnRight(31);
pt.setAttnLeftBack(31);
pt.setAttnRightBack(31);
pt.setLoudness(true);
}
void loop()
{
for (int i = 0; i < 32; i++)
{
pt.setAttnLeft(31 - i);
pt.setAttnRight(i);
delay(100);
}
for (int i = 0; i < 32; i++)
{
pt.setAttnRight(31 - i);
pt.setAttnRightBack(i);
delay(100);
}
for (int i = 0; i < 32; i++)
{
pt.setAttnRightBack(31 - i);
pt.setAttnLeftBack(i);
delay(100);
}
for (int i = 0; i < 32; i++)
{
pt.setAttnLeftBack(31 - i);
pt.setAttnLeft(i);
delay(100);
}
}
// -- END OF FILE --

View File

@ -2,8 +2,8 @@
# Data types (KEYWORD1) # Data types (KEYWORD1)
PT2314 KEYWORD1 PT2314 KEYWORD1
PT7314 KEYWORD1
PT7313 KEYWORD1 PT7313 KEYWORD1
PT7314 KEYWORD1
# Methods and Functions (KEYWORD2) # Methods and Functions (KEYWORD2)

View File

@ -15,7 +15,7 @@
"type": "git", "type": "git",
"url": "https://github.com/RobTillaart/PT2314.git" "url": "https://github.com/RobTillaart/PT2314.git"
}, },
"version": "0.1.2", "version": "0.2.0",
"license": "MIT", "license": "MIT",
"frameworks": "*", "frameworks": "*",
"platforms": "*", "platforms": "*",

View File

@ -1,5 +1,5 @@
name=PT2314 name=PT2314
version=0.1.2 version=0.2.0
author=Rob Tillaart <rob.tillaart@gmail.com> author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com> maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for PT2314 i2C 4 channel audio processor, sentence=Arduino library for PT2314 i2C 4 channel audio processor,

View File

@ -57,13 +57,14 @@ unittest_teardown()
{ {
} }
// not testable withour proper mock-up
unittest(test_constructor) unittest(test_constructor)
{ {
PT2314 pt2; PT2314 pt2;
PT7313 pt3;
PT7314 pt7; PT7314 pt7;
assertEqual(1,1); assertEqual(1, 1);
} }