0.1.0 PT2314

This commit is contained in:
Rob Tillaart 2023-07-31 19:23:13 +02:00
parent e4ed8d6b4c
commit 83c7c1a070
15 changed files with 734 additions and 0 deletions

View File

@ -0,0 +1,27 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:
packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
# - due
# - zero
# - leonardo
- m4
- esp32
# - esp8266
# - mega2560
- rpipico

4
libraries/PT2314/.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1,4 @@
# These are supported funding model platforms
github: RobTillaart

View File

@ -0,0 +1,13 @@
name: Arduino-lint
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update
compliance: strict

View File

@ -0,0 +1,17 @@
---
name: Arduino CI
on: [push, pull_request]
jobs:
runTest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- run: |
gem install arduino_ci
arduino_ci.rb

View File

@ -0,0 +1,18 @@
name: JSON check
on:
push:
paths:
- '**.json'
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: json-syntax-check
uses: limitusus/json-syntax-check@v1
with:
pattern: "\\.json$"

View File

@ -0,0 +1,11 @@
# Change Log PT2314
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.1.0] - 2023-07-30
- initial version.

21
libraries/PT2314/LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023-2023 Rob Tillaart
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

249
libraries/PT2314/PT2314.cpp Normal file
View File

@ -0,0 +1,249 @@
//
// FILE: PT2314.cpp
// AUTHOR: Rob Tillaart
// DATE: 2023-07-30
// VERSION: 0.1.0
// PURPOSE: Arduino library for PT2314 i2C 4 channel audio processor.
// URL: https://github.com/RobTillaart/PT2314
#include "PT2314.h"
PT2314::PT2314(TwoWire *wire)
{
_wire = wire;
}
#if defined (ESP8266) || defined(ESP32)
bool PT2314::begin(int dataPin, int clockPin)
{
_wire = &Wire;
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()
{
_wire->begin();
if (! isConnected()) return false;
setChannel();
setMute();
setLoudness();
setVolume();
setBass();
setTreble();
setGain();
// setAttn(31,31); // already muted
return true;
}
bool PT2314::isConnected()
{
_wire->beginTransmission(_address);
return ( _wire->endTransmission() == 0);
}
void PT2314::setChannel(uint8_t channel)
{
if (channel > 3) channel = 3;
_channel = channel;
updateAudioRegister();
}
uint8_t PT2314::getChannel()
{
return _channel;
}
///////////////////////////////////////////////////
//
// AUDIO
//
void PT2314::setMute(bool on)
{
_mute = on;
if (_mute)
{
write(0xDF); // left
write(0xFF); // right
}
else
{
write(0xC0 | _attnLeft);
write(0xE0 | _attnRight);
}
}
bool PT2314::getMute()
{
return _mute;
}
void PT2314::setLoudness(bool on)
{
_loudness = on;
updateAudioRegister();
}
bool PT2314::getLoudness()
{
return _loudness;
}
void PT2314::setVolume(uint8_t volume)
{
if (volume > 63) volume = 63;
_volume = volume;
write(_volume);
}
uint8_t PT2314::getVolume()
{
return _volume;
}
void PT2314::setBass(int8_t bass)
{
if (bass < -14) bass = -14;
if (bass > 14) bass = 14;
_bass = bass;
uint8_t value;
if (_bass <= 0) value = 7 + (_bass / 2);
else value = 15 - (_bass / 2);
write(0x60 | value);
}
int8_t PT2314::getBass()
{
return _bass;
}
void PT2314::setTreble(int8_t treble)
{
if (treble < -14) treble = -14;
if (treble > 14) treble = 14;
_treble = treble;
uint8_t value;
if (_treble <= 0) value = 7 + (_treble / 2);
else value = 15 - (_treble / 2);
write(0x70 | value);
}
int8_t PT2314::getTreble()
{
return _treble;
}
void PT2314::setGain(uint8_t gain)
{
if (gain > 3) gain = 3;
_gain = gain << 3;
updateAudioRegister();
}
uint8_t PT2314::getGain()
{
return _gain >> 3;
}
void PT2314::setAttnLeft(uint8_t attnLeft)
{
if (attnLeft > 31) attnLeft = 31;
_attnLeft = attnLeft;
write(0xC0 | _attnLeft);
}
uint8_t PT2314::getAttnLeft()
{
return _attnLeft;
}
void PT2314::setAttnRight(uint8_t attnRight)
{
if (attnRight > 31) attnRight = 31;
_attnRight = attnRight;
write(0xE0 | _attnRight);
}
uint8_t PT2314::getAttnRight()
{
return _attnRight;
}
void PT2314::setAttn(uint8_t attnLeft, uint8_t attnRight)
{
setAttnLeft(attnLeft);
setAttnRight(attnRight);
}
///////////////////////////////////////////////////
//
// PROTECTED
//
void PT2314::write(const uint8_t value)
{
_wire->beginTransmission(_address);
_wire->write(value);
_error = _wire->endTransmission();
}
void PT2314::updateAudioRegister()
{
uint8_t value = 0x40;
value |= _channel;
if (_loudness == false) value |= 0x04;
value |= _gain;
write(value);
}
///////////////////////////////////////////////////
//
// DERIVED CLASS
//
PT7314::PT7314(TwoWire *wire) : PT2314(wire)
{
};
// -- END OF FILE --

86
libraries/PT2314/PT2314.h Normal file
View File

@ -0,0 +1,86 @@
#pragma once
//
// FILE: PT2314.h
// AUTHOR: Rob Tillaart
// DATE: 2023-07-30
// VERSION: 0.1.0
// PURPOSE: Arduino library for PT2314 i2C 4 channel audio processor.
// URL: https://github.com/RobTillaart/PT2314
#include "Arduino.h"
#include "Wire.h"
#define PT2314_LIB_VERSION (F("0.1.0"))
class PT2314
{
public:
PT2314(TwoWire *wire = &Wire);
#if defined (ESP8266) || defined(ESP32)
bool begin(int sda, int scl);
#endif
bool begin();
bool isConnected();
// AUDIO
void setChannel(uint8_t channel = 0); // 0..3
uint8_t getChannel();
void setMute(bool on = true);
bool getMute();
void setLoudness(bool on = true);
bool getLoudness();
void setVolume(uint8_t volume = 0); // 0..63
uint8_t getVolume();
void setBass(int8_t bass = 0); // -14..14
int8_t getBass();
void setTreble(int8_t treble = 0); // -14..14
int8_t getTreble();
void setGain(uint8_t gain = 0); // 0..3
uint8_t getGain();
void setAttnLeft(uint8_t value = 31); // 0..31
uint8_t getAttnLeft();
void setAttnRight(uint8_t value = 31); // 0..31
uint8_t getAttnRight();
void setAttn(uint8_t attnLeft, uint8_t attnRight);
protected:
void write(const uint8_t value);
void updateAudioRegister();
TwoWire *_wire;
uint8_t _address = 0x44;
uint8_t _channel = 0;
bool _mute = false;
bool _loudness = false;
uint8_t _volume = 0;
int8_t _bass = 0;
int8_t _treble = 0;
uint8_t _gain = 0;
uint8_t _attnLeft = 0;
uint8_t _attnRight = 0;
// to be elaborated.
int _error = 0;
};
///////////////////////////////////////////////////////////////
//
// DERIVED
//
class PT7314 : public PT2314
{
public:
PT7314(TwoWire *wire = &Wire);
};
// -- END OF FILE --

104
libraries/PT2314/README.md Normal file
View File

@ -0,0 +1,104 @@
[![Arduino CI](https://github.com/RobTillaart/PT2314/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![JSON check](https://github.com/RobTillaart/PT2314/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/PT2314/actions/workflows/jsoncheck.yml)
[![Arduino-lint](https://github.com/RobTillaart/PT2314/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/PT2314/actions/workflows/arduino-lint.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/PT2314/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/PT2314.svg?maxAge=3600)](https://github.com/RobTillaart/PT2314/releases)
# PT2314
Arduino library for PT2314 i2C 4 channel audio processor.
## Description
The PT2314 library is experimental as it is not tested with hardware.
The library should also work with the PT7314, a separate constructor
exist for it.
Feedback is welcome.
The library is based upon Datasheet: PT2314 V1.4 July, 2005
#### I2C
According to the datasheet:
- PT2314 only work on 100 KHz.
- PT7314 can support 400 KHz.
- check if higher speeds work?
Datasheet PT7314 states that the device needs 50 ms to wake up
before it can process I2C commands.
The datasheet of the PT2314 does not mention such timeout.
## Interface
```cpp
#include "PT2314.h"
```
#### Constructors
- **PT2314(TwoWire \*wire = &Wire)** constructor.
- **PT7314(TwoWire \*wire = &Wire)** constructor.
- **bool begin(int sda, int scl)** for ESP32 et al.
- **bool begin()** other
- **bool isConnected()** device address can be seen on I2C bus.
#### Channel
- **void setChannel(uint8_t channel = 0)** 0..3
- **uint8_t getChannel()**
#### Volume
- **void setMute(bool on = true)**
- **bool getMute()**
- **void setLoudness(bool on = true)**
- **bool getLoudness()**
- **void setVolume(uint8_t volume = 0)** 0..63
- **uint8_t getVolume()**
#### Bass Treble
- **void setBass(int8_t bass = 0)** -14..14 dB
- **int8_t getBass()**
- **void setTreble(int8_t treble = 0)** -14..14 dB
- **int8_t getTreble()**
#### Gain
- **void setGain(uint8_t gain = 0)** 0..3
- **uint8_t getGain()**
#### Attenuation
- **void setAttnLeft(uint8_t value = 31)** 0..31
- **uint8_t getAttnLeft()**
- **void setAttnRight(uint8_t value = 31)** 0..31
- **uint8_t getAttnRight()**
- **void setAttn(uint8_t attnLeft, uint8_t attnRight)**
## Future
#### Must
- improve documentation
- test with hardware
#### Should
- error handling
- add more examples.
- check parameters range (0..63 => -63..0?
- some are in dB others not.
#### Could
- replace magic numbers with defines.
- extend unit test
#### Wont (unless on request)

View File

@ -0,0 +1,32 @@
//
// FILE: PT2314_demo.ino
// AUTHOR: Rob Tillaart
// PURPOSE: simple demo
// URL: https://github.com/RobTillaart/PT2314
#include "PT2314.h"
PT7314 pt;
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
delay(100);
pt.begin();
// do your settings
pt.setVolume(20);
pt.setAttn(15, 24); // shift the balance
pt.setLoudness(true);
}
void loop()
{
}
// -- END OF FILE --

View File

@ -0,0 +1,42 @@
# Syntax Colouring Map For PT2314
# Data types (KEYWORD1)
PT2314 KEYWORD1
PT7314 KEYWORD1
# Methods and Functions (KEYWORD2)
begin KEYWORD2
isConnected KEYWORD2
setChannel KEYWORD2
getChannel KEYWORD2
setMute KEYWORD2
getMute KEYWORD2
setLoudness KEYWORD2
getLoudness KEYWORD2
setVolume KEYWORD2
getVolume KEYWORD2
setBass KEYWORD2
getBass KEYWORD2
setTreble KEYWORD2
getTreble KEYWORD2
setGain KEYWORD2
getGain KEYWORD2
setAttnLeft KEYWORD2
getAttnLeft KEYWORD2
setAttnRight KEYWORD2
getAttnRight KEYWORD2
setAttn KEYWORD2
# Constants (LITERAL1)
PT2314_LIB_VERSION LITERAL1

View File

@ -0,0 +1,23 @@
{
"name": "PT2314",
"keywords": "PT2314, PT7314, I2C",
"description": "Arduino library for PT2314 i2C 4 channel audio processor.",
"authors":
[
{
"name": "Rob Tillaart",
"email": "Rob.Tillaart@gmail.com",
"maintainer": true
}
],
"repository":
{
"type": "git",
"url": "https://github.com/RobTillaart/PT2314.git"
},
"version": "0.1.0",
"license": "MIT",
"frameworks": "*",
"platforms": "*",
"headers": "PT2314.h"
}

View File

@ -0,0 +1,12 @@
name=PT2314
version=0.1.0
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for PT2314 i2C 4 channel audio processor,
paragraph=PT7314
category=Sensors
url=https://github.com/RobTillaart/PT2314
architectures=*
includes=PT2314.h
depends=

View File

@ -0,0 +1,75 @@
//
// FILE: unit_test_001.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// DATE: 2023-07-30
// PURPOSE: unit tests for the PT2314
// https://github.com/RobTillaart/PT2314
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
//
// supported assertions
// https://github.com/Arduino-CI/arduino_ci/blob/master/cpp/unittest/Assertion.h#L33-L42
// ----------------------------
// assertEqual(expected, actual); // a == b
// assertNotEqual(unwanted, actual); // a != b
// assertComparativeEquivalent(expected, actual); // abs(a - b) == 0 or (!(a > b) && !(a < b))
// assertComparativeNotEquivalent(unwanted, actual); // abs(a - b) > 0 or ((a > b) || (a < b))
// assertLess(upperBound, actual); // a < b
// assertMore(lowerBound, actual); // a > b
// assertLessOrEqual(upperBound, actual); // a <= b
// assertMoreOrEqual(lowerBound, actual); // a >= b
// assertTrue(actual);
// assertFalse(actual);
// assertNull(actual);
// // special cases for floats
// assertEqualFloat(expected, actual, epsilon); // fabs(a - b) <= epsilon
// assertNotEqualFloat(unwanted, actual, epsilon); // fabs(a - b) >= epsilon
// assertInfinity(actual); // isinf(a)
// assertNotInfinity(actual); // !isinf(a)
// assertNAN(arg); // isnan(a)
// assertNotNAN(arg); // !isnan(a)
////////////////////////////////////
//
// MANY TESTS WILL BLOCK AS BUILD CI HAS NO GOOD TIMEOUT
// ALL FAILING TESTS ARE COMMENTED
//
// USE GODMODE SERIAL TO IMPROVE THESE TESTS
//
#include <ArduinoUnitTests.h>
#include "Arduino.h"
#include "PT2314.h"
unittest_setup()
{
fprintf(stderr, "PT2314_LIB_VERSION:\t%s\n", (char *) PT2314_LIB_VERSION);
}
unittest_teardown()
{
}
unittest(test_constructor)
{
PT2314 pt2;
PT7314 pt7;
assertEqual(1,1);
}
unittest_main()
// -- END OF FILE --