ApraLinuxUtils 1.0.0
C++ utility library for embedded Linux systems
 
Loading...
Searching...
No Matches
PWM.h
Go to the documentation of this file.
1/*
2 * PWM.h
3 *
4 * Copyright (c) 2024 Apra Labs
5 *
6 * This file is part of ApraUtils.
7 *
8 * Licensed under the MIT License.
9 * See LICENSE file in the project root for full license information.
10 */
11
12#ifndef INCLUDES_APRA_UTILS_PWM_H_
13#define INCLUDES_APRA_UTILS_PWM_H_
14
15#include <stdint.h>
16#include <string>
17
18#define SYS_PWM_PATH "/sys/class/pwm"
19
20namespace apra
21{
22
23class PWM
24{
25public:
26 PWM(uint32_t pwmChipNo, uint32_t pwmPinNo, bool shouldPrint);
27 virtual ~PWM();
28 bool setup(uint64_t nSecPeriod, uint64_t nSecDutyCycle);
29 bool destroy();
30 bool start();
31 bool stop();
32 bool updateDutyCycle(uint64_t nSecDutyCycle);
33 bool changeDutyCycle(uint32_t percent);
34 uint32_t getDutyCyclePercent();
35 uint64_t getDutyCycleInNSec();
36private:
37 bool Export();
38 bool UnExport();
39 bool updatePWMParams(uint64_t value, std::string params);
40 std::string getPWMPinPath();
41
42 bool m_shouldPrint;
43 uint32_t m_chipNo;
44 uint32_t m_pinNo;
45 uint64_t m_nSecPeriod;
46 uint64_t m_nSecDutyCycle;
47 std::string m_chipPath;
48 bool m_isSetupComplete;
49 bool m_isPWMRunning;
50 uint32_t m_percentDutyCycle;
51};
52
53} /* namespace apra */
54
55#endif /* INCLUDES_APRA_UTILS_PWM_H_ */
virtual ~PWM()
Definition PWM.cpp:46
bool changeDutyCycle(uint32_t percent)
Definition PWM.cpp:167
bool stop()
Definition PWM.cpp:149
bool updateDutyCycle(uint64_t nSecDutyCycle)
Definition PWM.cpp:160
bool destroy()
Definition PWM.cpp:122
uint32_t getDutyCyclePercent()
Definition PWM.cpp:174
bool setup(uint64_t nSecPeriod, uint64_t nSecDutyCycle)
Definition PWM.cpp:51
bool start()
Definition PWM.cpp:138
uint64_t getDutyCycleInNSec()
Definition PWM.cpp:179