summaryrefslogtreecommitdiff
path: root/src/drivers/include/digital_pot.hpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-06-07 09:50:25 +1000
committerjacqueline <me@jacqueline.id.au>2023-06-07 09:50:25 +1000
commit610991455d335663de1dd6c0c6a3e0247ffd46df (patch)
tree8022526de2d30ca39386cf72d6fb5752d0c22803 /src/drivers/include/digital_pot.hpp
parentd2e5d2ab3cff0723cd995b0fca62aeb2a681d32d (diff)
downloadtangara-fw-610991455d335663de1dd6c0c6a3e0247ffd46df.tar.gz
R4 pre-emptive bringup
Includes stripping out the IC-specific I2S stuff, and doing more manual volume control using pots
Diffstat (limited to 'src/drivers/include/digital_pot.hpp')
-rw-r--r--src/drivers/include/digital_pot.hpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/drivers/include/digital_pot.hpp b/src/drivers/include/digital_pot.hpp
new file mode 100644
index 00000000..e2ca00b1
--- /dev/null
+++ b/src/drivers/include/digital_pot.hpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2023 jacqueline <me@jacqueline.id.au>
+ *
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+#pragma once
+
+#include <stdint.h>
+#include <functional>
+
+#include "esp_err.h"
+#include "result.hpp"
+
+#include "gpio_expander.hpp"
+
+namespace drivers {
+
+/*
+ * Driver for a two-channel digital potentiometer, with steps measured in
+ * decibels.
+ */
+class DigitalPot {
+ public:
+ explicit DigitalPot(GpioExpander* gpios);
+ ~DigitalPot() {}
+
+ // Not copyable or movable.
+ DigitalPot(const DigitalPot&) = delete;
+ DigitalPot& operator=(const DigitalPot&) = delete;
+
+ enum class Channel {
+ kLeft,
+ kRight,
+ };
+
+ auto SetRelative(int_fast8_t change) -> void;
+ auto SetRelative(Channel ch, int_fast8_t change) -> void;
+
+ auto SetZeroCrossDetect(bool enabled) -> void;
+
+ auto GetMaxAttenuation() -> int_fast8_t;
+ auto GetMinAttenuation() -> int_fast8_t;
+
+ private:
+ GpioExpander* gpios_;
+};
+
+} // namespace drivers