~aleteoryx/muditaos

ref: 7eebea8698aabbdd04bde5be492d12535ac40ccc muditaos/module-bsp/bsp/battery-charger/battery_charger.hpp -rw-r--r-- 1.4 KiB
7eebea86 — Marek Niepieklo [EGD-5377] Add USB charger detection 5 years ago
                                                                                
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
68
69
70
71
72
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <cstdint>
extern "C"
{
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
}

#include <array>

namespace bsp::battery_charger
{
	using StateOfCharge = std::uint8_t;

	enum class batteryRetval{
		OK,
		ChargerError,
		ChargerNotCharging,
		ChargerCharging
	};

	enum class batteryIRQSource{
		INTB = 0x01,
		INOKB = 0x02
	};

	enum class batteryINTBSource{
		minSOCAlert = 1 << 10,
		minVAlert = 1 << 8,
		SOCOnePercentChange = 1 << 7
	};

	enum class batteryChargerType{
		DcdTimeOut = 0x00U,     /*!< Dcd detect result is timeout */
		DcdUnknownType,         /*!< Dcd detect result is unknown type */
		DcdError,               /*!< Dcd detect result is error*/
		DcdSDP,                 /*!< The SDP facility is detected */
		DcdCDP,                 /*!< The CDP facility is detected */
		DcdDCP,                 /*!< The DCP facility is detected */
	};

	int init(xQueueHandle irqQueueHandle, xQueueHandle dcdQueueHandle);

	void deinit();

	StateOfCharge getBatteryLevel();

	bool getChargeStatus();

	void clearAllIRQs();

	void clearFuelGuageIRQ();

	std::uint16_t getStatusRegister();

	BaseType_t INOKB_IRQHandler();

	BaseType_t INTB_IRQHandler();

	extern "C"
	{
	void USB_ChargerDetectedCB(std::uint8_t detectedType);
	}
} // bsp::battery_charger