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

73 lines
1.5 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-12 03:51:57 -05:00
// VERSION: 0.3.1
2021-01-29 06:31:58 -05:00
//
// HISTORY: See M62429.cpp
// 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-12 03:51:57 -05:00
#define M62429_VERSION (F("0.3.1"))
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
#define M62429_LEFT 2
#define M62429_RIGHT 3
#define M62429_BOTH 0
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);
// increment /decrement until max/min
void incr();
void decr();
void average();
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
};
// -- END OF FILE --
2022-01-05 10:44:57 -05:00