mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.3.5 M62429
This commit is contained in:
parent
ccf3ca20da
commit
8d4f41738a
@ -2,7 +2,7 @@
|
||||
// FILE: M62429.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: Arduino library for M62429 volume control IC
|
||||
// VERSION: 0.3.4
|
||||
// VERSION: 0.3.5
|
||||
// HISTORY: See M62429.cpp2
|
||||
// URL: https://github.com/RobTillaart/M62429
|
||||
|
||||
@ -20,6 +20,7 @@
|
||||
// 0.3.3 2022-02-12 fix #10 add channel parameter to incr() and decr()
|
||||
// improve muteOn() + muteOff()
|
||||
// 0.3.4 2022-02-15 improve conditional delayMicroseconds()
|
||||
// 0.3.5 2022-02-21 add minimal M62429_RAW class
|
||||
|
||||
|
||||
#include "M62429.h"
|
||||
@ -184,5 +185,82 @@ void M62429::_setAttn(uint8_t channel, uint8_t attn)
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// M62429_RAW
|
||||
//
|
||||
void M62429_RAW::begin(uint8_t dataPin, uint8_t clockPin)
|
||||
{
|
||||
_data = dataPin;
|
||||
_clock = clockPin;
|
||||
pinMode(_data, OUTPUT);
|
||||
pinMode(_clock, OUTPUT);
|
||||
digitalWrite(_data, LOW);
|
||||
digitalWrite(_clock, LOW);
|
||||
|
||||
setAttn(2, 0);
|
||||
}
|
||||
|
||||
|
||||
int M62429_RAW::getAttn(uint8_t channel)
|
||||
{
|
||||
return _attn[channel & 1];
|
||||
}
|
||||
|
||||
|
||||
void M62429_RAW::setAttn(uint8_t channel, uint8_t attn)
|
||||
{
|
||||
uint16_t databits = 0x0200; // D9 latch bit
|
||||
databits |= ((attn & 0x03) << 7); // D8 - D7
|
||||
databits |= (attn & 0x7C); // D6 - D2
|
||||
// channel == 2 -> both 0x00 is default
|
||||
if (channel == 0) databits |= 0x03; // D0 - D1
|
||||
if (channel == 1) databits |= 0x02; // D0 - D1
|
||||
|
||||
// write D0 - D9
|
||||
for (uint8_t i = 0; i < 10; i++)
|
||||
{
|
||||
digitalWrite(_data, databits & 0x01);
|
||||
databits >>= 1;
|
||||
digitalWrite(_clock, HIGH);
|
||||
// Note if _clock pulses are long enough, _data pulses are too.
|
||||
#if M62429_CLOCK_DELAY > 0
|
||||
delayMicroseconds(M62429_CLOCK_DELAY);
|
||||
#endif
|
||||
|
||||
digitalWrite(_data, LOW);
|
||||
digitalWrite(_clock, LOW);
|
||||
#if M62429_CLOCK_DELAY > 0
|
||||
delayMicroseconds(M62429_CLOCK_DELAY);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Send D10 HIGH bit (Latch signal)
|
||||
digitalWrite(_data, HIGH);
|
||||
digitalWrite(_clock, HIGH);
|
||||
#if M62429_CLOCK_DELAY > 0
|
||||
delayMicroseconds(M62429_CLOCK_DELAY);
|
||||
#endif
|
||||
|
||||
// latch D10 signal requires _clock low before _data
|
||||
// make _data dummy write to keep timing constant
|
||||
digitalWrite(_data, HIGH);
|
||||
digitalWrite(_clock, LOW);
|
||||
#if M62429_CLOCK_DELAY > 0
|
||||
delayMicroseconds(M62429_CLOCK_DELAY);
|
||||
#endif
|
||||
|
||||
digitalWrite(_data, LOW);
|
||||
#if M62429_CLOCK_DELAY > 0
|
||||
delayMicroseconds(M62429_CLOCK_DELAY);
|
||||
#endif
|
||||
|
||||
// update cached values
|
||||
if (channel == 0) _attn[0] = attn;
|
||||
else if (channel == 1) _attn[1] = attn;
|
||||
else _attn[0] = _attn[1] = attn;
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -3,14 +3,14 @@
|
||||
// FILE: M62429.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: Arduino library for M62429 volume control IC
|
||||
// VERSION: 0.3.4
|
||||
// VERSION: 0.3.5
|
||||
// URL: https://github.com/RobTillaart/M62429
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
|
||||
#define M62429_VERSION (F("0.3.4"))
|
||||
#define M62429_VERSION (F("0.3.5"))
|
||||
|
||||
|
||||
// minimum pulse width CLOCK = 1.6 us (datasheet);
|
||||
@ -67,5 +67,23 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class M62429_RAW
|
||||
{
|
||||
public:
|
||||
|
||||
void begin(uint8_t dataPin, uint8_t clockPin);
|
||||
|
||||
// channel = { 0, 1 }
|
||||
int getAttn(uint8_t channel);
|
||||
// channel = { 0, 1, 2 = both; attn = {0 .. 87 }
|
||||
void setAttn(uint8_t channel, uint8_t attn);
|
||||
|
||||
private:
|
||||
uint8_t _attn[2] = { 0, 0 };
|
||||
uint8_t _data = 0;
|
||||
uint8_t _clock = 0;
|
||||
};
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -13,6 +13,8 @@ Arduino library for M62429 volume control IC.
|
||||
|
||||
## Description
|
||||
|
||||
#### M62429
|
||||
|
||||
This library is used to set the attenuation (volume) of the
|
||||
M62429 IC a.k.a. FM62429.
|
||||
|
||||
@ -24,8 +26,12 @@ takes time enough.
|
||||
For faster processors this define can be overruled runtime by setting it
|
||||
before including "M62429.h" or by defining it as command line parameter.
|
||||
|
||||
#### M62429_RAW
|
||||
|
||||
## Interface
|
||||
The library also implements a M62429_RAW class which has a minimalistic interface.
|
||||
|
||||
|
||||
## Interface M62429
|
||||
|
||||
The interface is straightforward
|
||||
|
||||
@ -78,6 +84,23 @@ can return one of the error codes.
|
||||
See examples
|
||||
|
||||
|
||||
|
||||
## Interface M62429_RAW
|
||||
|
||||
The interface is minimalistic.
|
||||
No parameter or other checks are made.
|
||||
|
||||
Use **\#include "M62429.h"**
|
||||
|
||||
- **void begin(uint8_t dataPin, uint8_t clockPin)** defines the clock and data pin.
|
||||
One has to create one object per IC.
|
||||
- **int getAttn(uint8_t channel)** channel is 0, 1 or 2 (both).
|
||||
In the latter case the attenuation of channel 0 is used as attenuation of both channels.
|
||||
- **void setAttn(uint8_t channel, uint8_t attn)**
|
||||
- channel = 0, 1, 2 = both
|
||||
- attenuation = 0 .. 87
|
||||
|
||||
|
||||
## Future
|
||||
|
||||
#### Mixer
|
||||
|
@ -0,0 +1,69 @@
|
||||
//
|
||||
// FILE: M62429_RAW_performance.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo M62429_RAW class for IC FM62429
|
||||
|
||||
|
||||
#include "M62429.h"
|
||||
|
||||
uint32_t start, stop;
|
||||
|
||||
M62429_RAW AMP;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.println();
|
||||
Serial.print("M62429_VERSION: ");
|
||||
Serial.println(M62429_VERSION);
|
||||
|
||||
AMP.begin(4, 5);
|
||||
delay(100);
|
||||
|
||||
start = micros();
|
||||
AMP.setAttn(0, 10);
|
||||
stop = micros();
|
||||
Serial.print("setAttn: \t");
|
||||
Serial.println(stop - start);
|
||||
delay(100);
|
||||
|
||||
start = micros();
|
||||
AMP.setAttn(0, 10);
|
||||
stop = micros();
|
||||
Serial.print("setAttn: \t");
|
||||
Serial.println(stop - start);
|
||||
delay(100);
|
||||
|
||||
start = micros();
|
||||
AMP.setAttn(0, 100);
|
||||
stop = micros();
|
||||
Serial.print("setAttn: \t");
|
||||
Serial.println(stop - start);
|
||||
delay(100);
|
||||
|
||||
start = micros();
|
||||
AMP.setAttn(0, 100);
|
||||
stop = micros();
|
||||
Serial.print("setAttn: \t");
|
||||
Serial.println(stop - start);
|
||||
delay(100);
|
||||
|
||||
start = micros();
|
||||
volatile uint8_t x = AMP.getAttn(0);
|
||||
stop = micros();
|
||||
Serial.print("getAttn: \t");
|
||||
Serial.println(stop - start);
|
||||
delay(100);
|
||||
|
||||
Serial.println("\nDone...");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
@ -0,0 +1,14 @@
|
||||
...\M62429_performance.ino
|
||||
UNO
|
||||
IDE 1.18.19
|
||||
|
||||
...\M62429_RAW_performance.ino
|
||||
|
||||
M62429_VERSION: 0.3.5
|
||||
setAttn: 192
|
||||
setAttn: 192
|
||||
setAttn: 200
|
||||
setAttn: 200
|
||||
getAttn: 0
|
||||
|
||||
Done...
|
@ -2,6 +2,7 @@
|
||||
|
||||
# Data types (KEYWORD1)
|
||||
M62429 KEYWORD1
|
||||
M62429_RAW KEYWORD1
|
||||
|
||||
|
||||
# Methods and Functions (KEYWORD2)
|
||||
@ -17,6 +18,11 @@ muteOff KEYWORD2
|
||||
isMuted KEYWORD2
|
||||
|
||||
|
||||
# M62429_RAW
|
||||
getAttn KEYWORD2
|
||||
setAttn KEYWORD2
|
||||
|
||||
|
||||
# Constants (LITERAL1)
|
||||
M62429_VERSION LITERAL2
|
||||
M62429_MUTED LITERAL2
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/M62429.git"
|
||||
},
|
||||
"version": "0.3.4",
|
||||
"version": "0.3.5",
|
||||
"license": "MIT",
|
||||
"frameworks": "*",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=M62429
|
||||
version=0.3.4
|
||||
version=0.3.5
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for M62429 volume control IC
|
||||
|
Loading…
Reference in New Issue
Block a user