summaryrefslogtreecommitdiff
path: root/src/drivers/include/nvs.hpp
blob: 46a3d1544ecedb8b58fbc4cb75e65586449c5543 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * Copyright 2023 jacqueline <me@jacqueline.id.au>
 *
 * SPDX-License-Identifier: GPL-3.0-only
 */

#pragma once

#include <stdint.h>
#include <memory>
#include <optional>

#include "esp_err.h"
#include "nvs.h"

#include "bluetooth_types.hpp"
#include "tasks.hpp"

namespace drivers {

class NvsStorage {
 public:
  static auto OpenSync() -> NvsStorage*;

  auto PreferredBluetoothDevice() -> std::optional<bluetooth::mac_addr_t>;
  auto PreferredBluetoothDevice(std::optional<bluetooth::mac_addr_t>) -> bool;

  enum class Output : uint8_t {
    kHeadphones = 0,
    kBluetooth = 1,
  };
  auto OutputMode() -> Output;
  auto OutputMode(Output) -> bool;

  auto ScreenBrightness() -> uint_fast8_t;
  auto ScreenBrightness(uint_fast8_t) -> bool;

  auto AmpMaxVolume() -> uint16_t;
  auto AmpMaxVolume(uint16_t) -> bool;

  auto AmpCurrentVolume() -> uint16_t;
  auto AmpCurrentVolume(uint16_t) -> bool;

  auto HasShownOnboarding() -> bool;
  auto HasShownOnboarding(bool) -> bool;

  enum class InputModes : uint8_t {
    kButtonsOnly = 0,
    kButtonsWithWheel = 1,
    kDirectionalWheel = 2,
    kRotatingWheel = 3,
  };

  auto PrimaryInput() -> InputModes;
  auto PrimaryInput(InputModes) -> bool;

  explicit NvsStorage(nvs_handle_t);
  ~NvsStorage();

 private:
  auto DowngradeSchemaSync() -> bool;
  auto SchemaVersionSync() -> uint8_t;

  nvs_handle_t handle_;
};

}  // namespace drivers