-
Notifications
You must be signed in to change notification settings - Fork 1
/
eFlexPwmPin.cpp
66 lines (49 loc) · 1.59 KB
/
eFlexPwmPin.cpp
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
/*
Copyright (c) 2023, epsilonrt
All rights reserved.
SPDX-License-Identifier: BSD-3-Clause
*/
#include "component/eFlexPwmPin.h"
#include <imxrt.h>
#include <core_pins.h>
struct pwm_pin_info_struct {
uint8_t type; // 0=no pwm, 1=flexpwm, 2=quad
uint8_t module; // 0-3, 0-3
uint8_t channel; // 0=X, 1=A, 2=B
uint8_t muxval; //
};
extern const struct pwm_pin_info_struct pwm_pin_info[];
namespace eFlex {
//-----------------------------------------------------------------------------
const struct pwm_pin_info_struct *pinInfo (uint8_t pin) {
if (pin < CORE_NUM_DIGITAL) {
const struct pwm_pin_info_struct *info = &pwm_pin_info[pin];
if ( (info->type == 1) && (info->channel != 0)) {
return info;
}
}
return nullptr;
}
//-----------------------------------------------------------------------------
// Pin class
//-----------------------------------------------------------------------------
Pin::Pin (int number) : m_number (number) {
if (number != -1) {
const struct pwm_pin_info_struct *info = pinInfo (number);
if (info) {
if (info->channel != 0) {
m_channel = (info->channel == 1 ? ChanA : ChanB);
m_module = info->module;
m_muxval = info->muxval;
}
}
}
}
//-----------------------------------------------------------------------------
bool Pin::begin() {
if (isValid()) {
* (portConfigRegister (m_number)) = m_muxval;
}
return isValid();
}
}