GY-63_MS5611/libraries/M62429/M62429.h

90 lines
1.8 KiB
C
Raw Normal View History

2021-01-29 06:31:58 -05:00
#pragma once
//
// FILE: M62429.h
// AUTHOR: Rob Tillaart
// PURPOSE: Arduino library for M62429 volume control IC
2022-02-21 13:21:27 -05:00
// VERSION: 0.3.5
2021-01-29 06:31:58 -05:00
// URL: https://github.com/RobTillaart/M62429
2021-05-28 07:36:28 -04:00
2021-01-29 06:31:58 -05:00
#include "Arduino.h"
2021-05-28 07:36:28 -04:00
2022-02-21 13:21:27 -05:00
#define M62429_VERSION (F("0.3.5"))
2021-05-28 07:36:28 -04:00
2021-01-29 06:31:58 -05:00
2021-12-21 06:50:11 -05:00
// minimum pulse width CLOCK = 1.6 us (datasheet);
2021-01-29 06:31:58 -05:00
// digitalWrite takes enough time on UNO / AVR so clock_delay == 0
// Note that if clock pulses are long enough the data pulses are too.
#ifndef M62429_CLOCK_DELAY
#ifdef __AVR__
2022-01-05 10:44:57 -05:00
#define M62429_CLOCK_DELAY 0
2021-01-29 06:31:58 -05:00
#else
2022-01-05 10:44:57 -05:00
#define M62429_CLOCK_DELAY 2
2021-01-29 06:31:58 -05:00
#endif
#endif
2021-05-28 07:36:28 -04:00
2021-01-29 06:31:58 -05:00
// ERROR CODES
2022-01-05 10:44:57 -05:00
#define M62429_OK 0
#define M62429_MUTED -1
#define M62429_CHANNEL_ERROR -10
2021-01-29 06:31:58 -05:00
2022-02-12 03:23:23 -05:00
// CHANNELS
2022-02-12 08:33:18 -05:00
#define M62429_LEFT 0
#define M62429_RIGHT 1
#define M62429_BOTH 2
2022-02-12 03:23:23 -05:00
2021-01-29 06:31:58 -05:00
class M62429
{
public:
void begin(uint8_t dataPin, uint8_t clockPin);
// channel = { 0, 1 }
int getVolume(uint8_t channel);
// channel = { 0, 1, 2 = both; volume = {0 .. 255 }
int setVolume(uint8_t channel, uint8_t volume);
2022-02-12 08:33:18 -05:00
// increment /decrement until min/max = 0..255
2022-02-13 09:58:42 -05:00
int incr(uint8_t channel = 2);
int decr(uint8_t channel = 2);
2022-02-12 08:33:18 -05:00
int average();
2021-01-29 06:31:58 -05:00
void muteOn();
void muteOff();
bool isMuted() { return _muted; };
2022-02-12 03:23:23 -05:00
2021-01-29 06:31:58 -05:00
private:
uint8_t _vol[2] = { 0, 0 };
uint8_t _data = 0;
uint8_t _clock = 0;
bool _muted = false;
2022-02-12 03:23:23 -05:00
void _setAttn(uint8_t channel, uint8_t attn);
2021-01-29 06:31:58 -05:00
};
2022-02-21 13:21:27 -05:00
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;
};
2021-01-29 06:31:58 -05:00
// -- END OF FILE --
2022-01-05 10:44:57 -05:00