@mchp-mcc/scf-pic8-pwm-v2 4.2.9 → 4.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/PinsLogic.ts DELETED
@@ -1,213 +0,0 @@
1
- import { AppModel } from "../generated_module/src/types/AutoModuleTypes";
2
- import { pin_row, behaviour } from "@microchip/pin-standard";
3
-
4
- // provide complete dynamic data for all pin rows. It overrides static pindata.json
5
- export const getCompletePinData = (appModel: AppModel): any => {
6
- // way to programatically override the json data
7
- return {};
8
- };
9
-
10
- // overrides pin data for a particular row based on model.
11
- export function getRowData(appModel: AppModel, rowData: pin_row): pin_row | undefined {
12
- const pwminstancename = appModel.getHardware()?.getPeripheral()?.instance;
13
- const moduleName = appModel.getName() ?? "PWM";
14
- const allPinsData: any = appModel.getImportValue("pin_standard")?.allpins;
15
- const modulePins: string[] = getModulePins(allPinsData, moduleName);
16
- const pinName: string = getPinName(modulePins, rowData.filter.aliasReEx);
17
- const pinBehaviour: string = getpinBehaviour(allPinsData, moduleName, pinName);
18
- const isPPS = pinBehaviour === "pps";
19
- const isAPFCON = pinBehaviour === "apfcon";
20
-
21
- if (pinName === "") {
22
- return undefined;
23
- }
24
- if (rowData.name === "out") {
25
- rowData = {
26
- ...rowData,
27
- module: moduleName,
28
- function: moduleName + "OUT",
29
- filter: {
30
- module: moduleName,
31
- aliasReEx: `^PWM${pwminstancename}$`,
32
- },
33
- behaviour: isPPS
34
- ? behaviour.PPS
35
- : isAPFCON
36
- ? behaviour.APFCON
37
- : behaviour.LOCK_UNLOCK,
38
- };
39
- } else if (rowData.name === "pwmx0") {
40
- rowData = {
41
- ...rowData,
42
- module: moduleName,
43
- function: moduleName + "0OUT",
44
- filter: {
45
- ...rowData.filter,
46
- module: moduleName,
47
- },
48
- behaviour: isPPS
49
- ? behaviour.PPS
50
- : isAPFCON
51
- ? behaviour.APFCON
52
- : behaviour.LOCK_UNLOCK,
53
- };
54
- if (appModel.isComponentValue("pwmoe0Pwmaoe") === true) {
55
- rowData = {
56
- ...rowData,
57
- behaviourMeta: { lockPinRegEx: moduleName + "0" },
58
- };
59
- }
60
- } else if (rowData.name === "pwmx1") {
61
- rowData = {
62
- ...rowData,
63
- module: moduleName,
64
- function: moduleName + "1OUT",
65
- filter: {
66
- ...rowData.filter,
67
- module: moduleName,
68
- },
69
- behaviour: isPPS
70
- ? behaviour.PPS
71
- : isAPFCON
72
- ? behaviour.APFCON
73
- : behaviour.LOCK_UNLOCK,
74
- };
75
- if (appModel.isComponentValue("pwmoe1Pwmaoe") === true) {
76
- rowData = {
77
- ...rowData,
78
- behaviourMeta: { lockPinRegEx: moduleName + "1" },
79
- };
80
- }
81
- } else if (rowData.name === "pwmx2") {
82
- rowData = {
83
- ...rowData,
84
- module: moduleName,
85
- function: moduleName + "2OUT",
86
- filter: {
87
- ...rowData.filter,
88
- module: moduleName,
89
- },
90
- behaviour: isPPS
91
- ? behaviour.PPS
92
- : isAPFCON
93
- ? behaviour.APFCON
94
- : behaviour.LOCK_UNLOCK,
95
- };
96
- if (appModel.isComponentValue("pwmoe2Pwmaoe") === true) {
97
- rowData = {
98
- ...rowData,
99
- behaviourMeta: { lockPinRegEx: moduleName + "2" },
100
- };
101
- }
102
- } else if (rowData.name === "pwmx3") {
103
- rowData = {
104
- ...rowData,
105
- module: moduleName,
106
- function: moduleName + "3OUT",
107
- filter: {
108
- ...rowData.filter,
109
- module: moduleName,
110
- },
111
- behaviour: isPPS
112
- ? behaviour.PPS
113
- : isAPFCON
114
- ? behaviour.APFCON
115
- : behaviour.LOCK_UNLOCK,
116
- };
117
- if (appModel.isComponentValue("pwmoe3Pwmaoe") === true) {
118
- rowData = {
119
- ...rowData,
120
- behaviourMeta: { lockPinRegEx: moduleName + "3" },
121
- };
122
- }
123
- }
124
-
125
- let rowActions = [];
126
- const pwmx0Regcomponent = appModel.getComponent("pwmoe0Pwmaoe")?.component;
127
- const pwmx1Regcomponent = appModel.getComponent("pwmoe1Pwmaoe")?.component;
128
- const pwmx2Regcomponent = appModel.getComponent("pwmoe2Pwmaoe")?.component;
129
- const pwmx3Regcomponent = appModel.getComponent("pwmoe3Pwmaoe")?.component;
130
-
131
- if (pwmx0Regcomponent) {
132
- rowActions = rowActions.concat(
133
- appModel
134
- .getPCPHelper?.()
135
- .stateActionBuilder(rowData)
136
- .rowWithName("pwmx0")
137
- .forComponent(pwmx0Regcomponent)
138
- .addIfLockedSetValue(moduleName + "0", true)
139
- .addIfUnLockedSetValue(".*", false)
140
- .build(),
141
- );
142
- }
143
- if (pwmx1Regcomponent) {
144
- rowActions = rowActions.concat(
145
- appModel
146
- .getPCPHelper?.()
147
- .stateActionBuilder(rowData)
148
- .rowWithName("pwmx1")
149
- .forComponent(pwmx1Regcomponent)
150
- .addIfLockedSetValue(moduleName + "1", true)
151
- .addIfUnLockedSetValue(".*", false)
152
- .build(),
153
- );
154
- }
155
- if (pwmx2Regcomponent) {
156
- rowActions = rowActions.concat(
157
- appModel
158
- .getPCPHelper?.()
159
- .stateActionBuilder(rowData)
160
- .rowWithName("pwmx2")
161
- .forComponent(pwmx2Regcomponent)
162
- .addIfLockedSetValue(moduleName + "2", true)
163
- .addIfUnLockedSetValue(".*", false)
164
- .build(),
165
- );
166
- }
167
- if (pwmx3Regcomponent) {
168
- rowActions = rowActions.concat(
169
- appModel
170
- .getPCPHelper?.()
171
- .stateActionBuilder(rowData)
172
- .rowWithName("pwmx3")
173
- .forComponent(pwmx3Regcomponent)
174
- .addIfLockedSetValue(moduleName + "3", true)
175
- .addIfUnLockedSetValue(".*", false)
176
- .build(),
177
- );
178
- }
179
- rowData = { ...rowData, actions: rowActions };
180
- return rowData;
181
- }
182
- const getModulePins = (allPins: any, moduleName: string): string[] => {
183
- const pins: string[] = [];
184
- for (const portPin in allPins) {
185
- const modulePins: any = allPins[portPin]?.[moduleName];
186
- for (const modulePin in modulePins) {
187
- if (pins.indexOf(modulePin) === -1) {
188
- pins.push(modulePin);
189
- }
190
- }
191
- }
192
- return pins;
193
- };
194
- const getPinName = (modulePins: string[], regEx: string): string => {
195
- let pinName = "";
196
- modulePins.forEach((pin) => {
197
- if (pin.match(new RegExp(regEx, "g"))) {
198
- pinName = pin;
199
- }
200
- });
201
- return pinName;
202
- };
203
- const getpinBehaviour = (allPins: any, moduleName: string, pinName: string): string => {
204
- for (const portPin in allPins) {
205
- const pinData: any = allPins[portPin]?.[moduleName]?.[pinName];
206
- if (pinData?.["pps"]) {
207
- return "pps";
208
- } else if (pinData?.["apfcon"]) {
209
- return "apfcon";
210
- }
211
- }
212
- return "lock_unlock";
213
- };
@@ -1,113 +0,0 @@
1
- import { PwmCalculator } from "./PwmCalculator";
2
-
3
- describe("Pwm Calculations: PR = 0x7c, Prescaler = 0x4, fosc = 4M, DC = 75", () => {
4
- const pwmCalculator = new PwmCalculator(0x7c, 16, 4000000, 75);
5
-
6
- test("getPwmPeriod", () => {
7
- expect(pwmCalculator.getPwmPeriod()).toBe(0.002);
8
- });
9
-
10
- test("getPwmFrequency", () => {
11
- expect(pwmCalculator.getPwmFrequency()).toBe(500);
12
- });
13
-
14
- test("getPwmResolution", () => {
15
- expect(pwmCalculator.getPwmResolution()).toBe(8);
16
- });
17
-
18
- test("getCCPRValue", () => {
19
- expect(pwmCalculator.getCCPRValue()).toBe(374);
20
- });
21
-
22
- test("getActualDutyCycle", () => {
23
- expect(pwmCalculator.getActualDutyCycle()).toBe(75);
24
- });
25
-
26
- test("getActualPulseWidth", () => {
27
- expect(pwmCalculator.getActualPulseWidth()).toBe(0.001496);
28
- });
29
- });
30
-
31
- describe("Pwm Calculations: PR = 0x4d, Prescaler = 0x5, fosc = 1M, DC = 60", () => {
32
- const pwmCalculator2 = new PwmCalculator(0x4d, 32, 1000000, 60);
33
-
34
- test("getPwmPeriod", () => {
35
- expect(pwmCalculator2.getPwmPeriod()).toBe(0.009984);
36
- });
37
-
38
- test("getPwmFrequency", () => {
39
- expect(pwmCalculator2.getPwmFrequency()).toBe(100.16);
40
- });
41
-
42
- test("getPwmResolution", () => {
43
- expect(pwmCalculator2.getPwmResolution()).toBe(8);
44
- });
45
-
46
- test("getCCPRValue", () => {
47
- expect(pwmCalculator2.getCCPRValue()).toBe(186);
48
- });
49
-
50
- test("getActualDutyCycle", () => {
51
- expect(pwmCalculator2.getActualDutyCycle()).toBe(60);
52
- });
53
-
54
- test("getActualPulseWidth", () => {
55
- expect(pwmCalculator2.getActualPulseWidth()).toBe(0.005952);
56
- });
57
- });
58
-
59
- describe("Pwm Calculations: PR = 0x0, Prescaler = 0x0, fosc = 1M, DC = 0", () => {
60
- const pwmCalculator2 = new PwmCalculator(0x0, 0, 1000000, 0);
61
-
62
- test("getPwmPeriod", () => {
63
- expect(pwmCalculator2.getPwmPeriod()).toBe(0);
64
- });
65
-
66
- test("getPwmFrequency", () => {
67
- expect(pwmCalculator2.getPwmFrequency()).toBe(0);
68
- });
69
-
70
- test("getPwmResolution", () => {
71
- expect(pwmCalculator2.getPwmResolution()).toBe(2);
72
- });
73
-
74
- test("getCCPRValue", () => {
75
- expect(pwmCalculator2.getCCPRValue()).toBe(0);
76
- });
77
-
78
- test("getActualDutyCycle", () => {
79
- expect(pwmCalculator2.getActualDutyCycle()).toBe(0);
80
- });
81
-
82
- test("getActualPulseWidth", () => {
83
- expect(pwmCalculator2.getActualPulseWidth()).toBe(0);
84
- });
85
- });
86
-
87
- describe("Pwm Calculations: PR = 0x0, Prescaler = 0x0, fosc = 0, DC = 0", () => {
88
- const pwmCalculator2 = new PwmCalculator(0x0, 0, 0, 0);
89
-
90
- test("getPwmPeriod", () => {
91
- expect(pwmCalculator2.getPwmPeriod()).toBe(0);
92
- });
93
-
94
- test("getPwmFrequency", () => {
95
- expect(pwmCalculator2.getPwmFrequency()).toBe(0);
96
- });
97
-
98
- test("getPwmResolution", () => {
99
- expect(pwmCalculator2.getPwmResolution()).toBe(2);
100
- });
101
-
102
- test("getCCPRValue", () => {
103
- expect(pwmCalculator2.getCCPRValue()).toBe(0);
104
- });
105
-
106
- test("getActualDutyCycle", () => {
107
- expect(pwmCalculator2.getActualDutyCycle()).toBe(0);
108
- });
109
-
110
- test("getActualPulseWidth", () => {
111
- expect(pwmCalculator2.getActualPulseWidth()).toBe(0);
112
- });
113
- });
@@ -1,67 +0,0 @@
1
- // Reused from Q43 CCP calculator
2
- // TODO: delete this duplicate and add CCP calculator dependency
3
- import log10 from "core-js/features/math/log10";
4
-
5
- export class PwmCalculator {
6
- private prValue: number;
7
- private prescaler: number;
8
- private fosc: number;
9
- private dutyCycleRatio: number;
10
-
11
- constructor(prValue: number, prescaler: number, fosc: number, dutyCycle: number) {
12
- this.prValue = prValue;
13
- this.prescaler = prescaler;
14
- this.fosc = fosc;
15
- this.dutyCycleRatio = dutyCycle / 100;
16
- }
17
-
18
- public getPwmPeriod = (): number => {
19
- let pwmPeriod = (this.prValue + 1) * 4 * this.prescaler;
20
- if (this.fosc > 0) {
21
- pwmPeriod = pwmPeriod / this.fosc;
22
- } else {
23
- pwmPeriod = 0;
24
- }
25
- return pwmPeriod;
26
- };
27
-
28
- public getPwmFrequency = (): number => {
29
- let pwmFrequency = (this.prValue + 1) * 4 * this.prescaler;
30
- if (pwmFrequency > 0) {
31
- pwmFrequency = this.fosc / pwmFrequency;
32
- } else {
33
- pwmFrequency = 0;
34
- }
35
-
36
- pwmFrequency = Math.round(pwmFrequency * 100) / 100;
37
- return pwmFrequency;
38
- };
39
-
40
- public getPwmResolution = (): number => {
41
- const pwmResolution = log10(4 * (this.prValue + 1)) / log10(2);
42
- return Math.floor(pwmResolution);
43
- };
44
-
45
- public getCCPRValue = (): number => {
46
- const ccprValue = Math.round(this.dutyCycleRatio * 4 * (this.prValue + 1) - 1);
47
- if (ccprValue < 0) {
48
- return 0;
49
- }
50
- return ccprValue;
51
- };
52
-
53
- public getActualDutyCycle = (): number => {
54
- const dcRatio = this.getCCPRValue() / (4 * (this.prValue + 1));
55
- return Math.round(dcRatio * 100);
56
- };
57
-
58
- public getActualPulseWidth = (): number => {
59
- let pulseWidth = this.getCCPRValue() * this.prescaler;
60
- if (this.fosc > 0) {
61
- pulseWidth = pulseWidth / this.fosc;
62
- } else {
63
- pulseWidth = 0;
64
- }
65
- return pulseWidth;
66
- };
67
- }
package/src/catalog.json DELETED
@@ -1,23 +0,0 @@
1
- {
2
- "name": "@mchp-mcc/local-catalog",
3
- "version": "1.0.0",
4
- "content": [
5
- {
6
- "name": "@mchp-mcc/scf-pic8-pwm-v2",
7
- "version": "*",
8
- "meta": {
9
- "keywords": [
10
- "pic8",
11
- "pwm"
12
- ],
13
- "defaultSelection": "defaultRequired",
14
- "name": "PWM",
15
- "category": "Drivers/PWM",
16
- "description": "This module is a 16-bit Pulse-Width Modulator (PWM) with a compare feature and multiple outputs.",
17
- "deviceFilterRegEx": ".*",
18
- "releaseNotesLink": "https://onlinedocs.microchip.com/v2/keyword-lookup?keyword=MCC.MELODY.8BITPIC.RELEASENOTES&version=latest&redirect=true"
19
- }
20
- }
21
- ],
22
- "catalogs": []
23
- }
@@ -1,40 +0,0 @@
1
- import { ProcessedExportInterface, Interface } from "./pwm_general_parameters";
2
-
3
- describe("The pwm_general_parameters interface", () => {
4
- it("doesn't explode", () => {
5
- expect(Interface.getInterfaceId()).toBeDefined();
6
- expect(Interface.createPrototypeImport()).toBeDefined();
7
- expect(Interface.createPrototypeExport()).toBeDefined();
8
- expect(
9
- Interface.createFirmwareApi("MyModule", [
10
- { name: "mymodule.h", path: "include/" },
11
- ]),
12
- ).toBeDefined();
13
- expect(Interface.createMock()).toBeDefined();
14
- });
15
-
16
- it("Checks Interface ID", () => {
17
- expect(Interface.getInterfaceId().name).toBe("pwm_general_parameters");
18
- expect(Interface.getInterfaceId().version).toBe("0.1.0");
19
- });
20
-
21
- it("Create's api with name, headers, or custom API undefined", () => {
22
- expect(Interface.createFirmwareApi("", [{ name: "", path: "" }])).toBeDefined();
23
- });
24
- });
25
-
26
- export const createMock = (): ProcessedExportInterface => {
27
- return {
28
- interfaceId: Interface.getInterfaceId(),
29
- payload: {
30
- interfaceApi: Interface.createFirmwareApi("MyModule", [
31
- { name: "mymodule.h", path: "include/" },
32
- ]),
33
- },
34
- args: {
35
- requestId: {
36
- customName: "MyModule",
37
- },
38
- },
39
- };
40
- };
@@ -1,121 +0,0 @@
1
- import { InterfaceId } from "@microchip/scf-common/lib/InterfaceId";
2
- import * as Creator from "@microchip/scf-common/lib/Creator";
3
- import * as Processor from "@microchip/scf-common/lib/Processor";
4
- import * as InterfaceTypes from "@microchip/scf-interface";
5
-
6
- /** The arguments to be provided to the implementation. */
7
- export interface Arguments extends InterfaceTypes.Arguments {
8
- //Standard Interface
9
- customName?: string;
10
- }
11
-
12
- /** The payload to be passed back to the dependent module after the BasicUART has been processed. */
13
- export interface ProcessedPayload extends InterfaceTypes.ProcessedPayload {
14
- //Standard Interface
15
- interfaceApi: InterfaceTypes.FirmwareAPIPayload<API>;
16
- customName?: string;
17
- modulename?: string;
18
- isdriverisr?: boolean;
19
- ispwmi_enabled?: boolean;
20
- ispwmpi_enabled?: boolean;
21
- moduleName?: string;
22
- }
23
-
24
- export interface API extends InterfaceTypes.CFunctions {
25
- Initialize: InterfaceTypes.CFunction;
26
- LoadDutyValue: InterfaceTypes.CFunction;
27
- }
28
-
29
- /** The type of the processed export interface */
30
- export type ProcessedExportInterface = Processor.ProcessedInterface<
31
- ProcessedPayload,
32
- Arguments
33
- >;
34
-
35
- /** Used by implementations of this interface in their module's creator. */
36
- type CreatorExportInterface = Creator.Interface<ProcessedPayload>;
37
-
38
- const getInterfaceId = (): InterfaceId => {
39
- return {
40
- name: "pwm_general_parameters",
41
- version: "0.1.0",
42
- };
43
- };
44
-
45
- const createPrototypeImport = (): Creator.Import => {
46
- return {
47
- interfaceId: getInterfaceId(),
48
- };
49
- };
50
-
51
- const createPrototypeExport = (): Creator.Export<CreatorExportInterface[]> => {
52
- return {
53
- interfaces: [{ interfaceId: getInterfaceId() }],
54
- };
55
- };
56
-
57
- const createMock = (): ProcessedExportInterface => {
58
- return {
59
- interfaceId: getInterfaceId(),
60
- payload: {
61
- interfaceApi: Interface.createFirmwareApi("MyModule", [
62
- { name: "mymodule.h", path: "include/" },
63
- ]),
64
- },
65
- args: {
66
- requestId: {
67
- customName: "MyModule",
68
- },
69
- },
70
- };
71
- };
72
-
73
- const createFirmwareApi = (
74
- moduleName: string,
75
- headerFiles: InterfaceTypes.HeaderFile[],
76
- ): InterfaceTypes.FirmwareAPIPayload<API> => {
77
- const prefix: string = moduleName ? moduleName : "undefined";
78
- const api = createApi(prefix);
79
-
80
- return {
81
- api: api,
82
- simpleApi: InterfaceTypes.buildSimpleApi(api),
83
- headerFiles: headerFiles,
84
- };
85
- };
86
-
87
- const createApi = (prefix: string): API => {
88
- return {
89
- Initialize: {
90
- name: prefix + "_Initialize",
91
- returns: "void",
92
- },
93
- LoadDutyValue: {
94
- name: prefix + "_LoadDutyValue",
95
- arguments: [
96
- {
97
- name: "dutyValue",
98
- type: "uint16_t",
99
- },
100
- ],
101
- returns: "void",
102
- },
103
- };
104
- };
105
-
106
- interface Interface extends InterfaceTypes.Interface {
107
- createPrototypeImport: () => Creator.Import<Arguments>;
108
- createMock: () => ProcessedExportInterface;
109
- createFirmwareApi: (
110
- moduleName: string,
111
- headerFiles: InterfaceTypes.HeaderFile[],
112
- ) => InterfaceTypes.FirmwareAPIPayload<API>;
113
- }
114
-
115
- export const Interface: Interface = {
116
- createPrototypeExport: createPrototypeExport,
117
- createPrototypeImport: createPrototypeImport,
118
- getInterfaceId: getInterfaceId,
119
- createMock: createMock,
120
- createFirmwareApi: createFirmwareApi,
121
- };