arduino-audio-driver
Loading...
Searching...
No Matches
LyratMini.h
Go to the documentation of this file.
1#pragma once
2#include "AudioBoard.h"
3
4namespace audio_driver {
5
12 public:
14#if defined(IS_ZEPHYR)
15 // sd pins: CLK, MISO, MOSI, CS: the SD is not working, so this is commented
16 // out addSPI(ESP32PinsSD); add i2c codec pins: scl, sda, port, frequency
17 addI2C(PinFunction::CODEC, DEVICE_DT_GET(DT_ALIAS(i2c_1)));
18 // add i2s pins: mclk, bck, ws,data_out, data_in ,(port)
19 addI2S(PinFunction::CODEC, DEVICE_DT_GET(DT_ALIAS(i2s_1)));
20 addI2S(PinFunction::CODEC_ADC, DEVICE_DT_GET(DT_ALIAS(i2s_2)));
21
22 addPin(PinFunction::HEADPHONE_DETECT, GPIO_DT_SPEC_GET(DT_ALIAS(headphone_detect), gpios), PinLogic::InputActiveHigh);
23 addPin(PinFunction::PA, GPIO_DT_SPEC_GET(DT_ALIAS(pa), gpios), PinLogic::Output);
24 addPin(PinFunction::LED, GPIO_DT_SPEC_GET(DT_ALIAS(led1), gpios), PinLogic::Output, 1);
25 addPin(PinFunction::LED, GPIO_DT_SPEC_GET(DT_ALIAS(led2), gpios), PinLogic::Output, 2);
26 //addPin(PinFunction::MCLK_SOURCE, 0, PinLogic::Inactive);
27 // adc pin must be defuubed for readubg key values
28
29#else
30 // sd pins: CLK, MISO, MOSI, CS: the SD is not working, so this is commented
31 // out addSPI(ESP32PinsSD); add i2c codec pins: scl, sda, port, frequency
33 // add i2s pins: mclk, bck, ws,data_out, data_in ,(port)
34 addI2S(PinFunction::CODEC, 0, 5, 25, 26, 35, 0);
35 addI2S(PinFunction::CODEC_ADC, 0, 32, 33, -1, 36, 1);
36
42 // adc pin
44#endif
45 }
46
47
48 void setRange(int value) { range = value; }
49
50
51#if defined(IS_ZEPHYR)
52
54 bool isKeyPressed(uint8_t key) override {
55 adc_dt_spec adc = DEVICE_DT_GET(DT_ALIAS(adc_pins));
56 int analog_value = gpio.analogRead(key_adc);
57 return inRange(analog_value, analog_values[key]);
58 }
59
60#else
61
62 // Key is key index 0-5 for rec, mute, play, set, vol-, vol+
63 bool isKeyPressed(uint8_t key) override {
64 int pin = getPinID(PinFunction::KEY);
65 if (pin == GPIO_UNDEFINED) {
66 AD_LOGE("PinFunction::KEY not defined");
67 return false;
68 }
69 int analog_value = gpio.analogRead(pin);
70 return inRange(analog_value, analog_values[key]);
71 }
72
73#endif
74
75 protected:
76 // analog values for rec, mute, play, set, vol-, vol+
77 int analog_values[6]{2802, 2270, 1754, 1284, 827, 304};
79
80 bool inRange(int in, int toBe) {
81 return in >= (toBe - range) && in <= (toBe + range);
82 }
83};
84
89
90} // namespace audio_driver
#define LYRAT_MINI_RANGE
Definition DriverCommon.h:63
#define GPIO_UNDEFINED
Definition DriverCommon.h:131
#define AD_LOGE(...)
Definition Logger.h:15
Defitintion for audio board pins and an audio driver.
Definition AudioBoard.h:13
All pins for i2s, spi, i2c and other pins.
Definition DriverDeviceInfo.h:20
GpioPin getPinID(PinFunction function, int pos=0)
Definition DriverDeviceInfo.h:149
GPIOExt gpio
Definition DriverDeviceInfo.h:271
bool addI2C(InfoI2C pin)
Definition DriverDeviceInfo.h:56
bool addI2S(InfoI2S pin)
Definition DriverDeviceInfo.h:26
bool addPin(InfoGPIO pin)
Definition DriverDeviceInfo.h:86
int analogRead(ADCPin pin) override
Returns the raw ADC value for the given pin, or -1 if not supported.
Definition GPIOExt.h:58
Pins for Lyrat Mini - use the PinsLyratMini object!
Definition LyratMini.h:11
int range
Definition LyratMini.h:78
PinsLyratMiniClass()
Definition LyratMini.h:13
void setRange(int value)
Definition LyratMini.h:48
int analog_values[6]
Definition LyratMini.h:77
bool inRange(int in, int toBe)
Definition LyratMini.h:80
bool isKeyPressed(uint8_t key) override
returns true if pressed
Definition LyratMini.h:63
static PinsLyratMiniClass PinsLyratMini
Definition LyratMini.h:86
static AudioDriverLyratMiniClass AudioDriverLyratMini
Definition AudioDriver.h:2182
static AudioBoard LyratMini
Definition LyratMini.h:88
Namespace for audio driver components.
Definition AudioBoard.h:5