summaryrefslogtreecommitdiff
path: root/src/drivers/include/samd.hpp
blob: 230cb06978a464cb1e4a403c75631dfa3a4b17aa (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
/*
 * Copyright 2023 jacqueline <me@jacqueline.id.au>
 *
 * SPDX-License-Identifier: GPL-3.0-only
 */

#pragma once

#include <optional>

namespace drivers {

class Samd {
 public:
  static auto Create() -> Samd* { return new Samd(); }

  Samd();
  ~Samd();

  enum class ChargeStatus {
    // There is no battery plugged into the device.
    kNoBattery,
    // The battery is discharging, and the current voltage level is very low.
    kBatteryCritical,
    // The battery is discharging.
    kDischarging,
    // The battery is charging over a low-current USB connection
    kChargingRegular,
    // The battery is charging over a high-current USB connection
    kChargingFast,
    // The battery is full charged, and we are still plugged in.
    kFullCharge,
  };

  auto ReadChargeStatus() -> std::optional<ChargeStatus>;

  enum class UsbMscStatus {
    // There is no compatible usb host attached.
    kDetached,
    // There is a compatible usb host attached, but USB MSC is not currently
    // in use by the SAMD.
    kAttachedIdle,
    // The SAMD is currently exposing the SD card via USB MSC.
    kAttachedMounted,
  };

  auto WriteAllowUsbMsc(bool is_allowed) -> void;
  auto ReadUsbMscStatus() -> UsbMscStatus;

  auto ReadFlashingEnabled() -> bool;
  auto WriteFlashingEnabled(bool) -> void;
};

}  // namespace drivers