@mchp-mcc/scf-pic8-opamp-v2 1.0.0

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.
@@ -0,0 +1,149 @@
1
+ /**
2
+ * ${moduleNameUpperCase} Generated Driver File
3
+ *
4
+ * @file ${moduleNameLowerCase}.c
5
+ *
6
+ * @ingroup ${moduleNameLowerCase}
7
+ *
8
+ * @brief This is the generated driver implementation file for the ${moduleNameUpperCase} driver.
9
+ *
10
+ * @version ${moduleNameUpperCase} Driver Version 1.0.0
11
+ */
12
+ ${disclaimer}
13
+
14
+ /**
15
+ Section: Included Files
16
+ */
17
+
18
+ #include <xc.h>
19
+ #include "${header.path}${header.name}"
20
+
21
+ /**
22
+ Section: ${moduleNameUpperCase} Module APIs
23
+ */
24
+
25
+ void ${moduleNameUpperCase}_Initialize(void)
26
+ {
27
+ <#if OPACON1??>
28
+ //${OPACON1.comment}
29
+ ${OPACON1.name} = ${OPACON1.valueAsHex};
30
+ </#if>
31
+
32
+ <#if OPACON2??>
33
+ //${OPACON2.comment}
34
+ ${OPACON2.name} = ${OPACON2.valueAsHex};
35
+ </#if>
36
+
37
+ <#if OPACON3??>
38
+ //${OPACON3.comment}
39
+ ${OPACON3.name} = ${OPACON3.valueAsHex};
40
+ </#if>
41
+
42
+ <#if OPACON4??>
43
+ //${OPACON4.comment}
44
+ ${OPACON4.name} = ${OPACON4.valueAsHex};
45
+ </#if>
46
+
47
+ <#if OPAHWC??>
48
+ //${OPAHWC.comment}
49
+ ${OPAHWC.name} = ${OPAHWC.valueAsHex};
50
+ </#if>
51
+
52
+ <#if OPAORS??>
53
+ //${OPAORS.comment}
54
+ ${OPAORS.name} = ${OPAORS.valueAsHex};
55
+ </#if>
56
+
57
+ <#if OPACON0??>
58
+ //${OPACON0.comment}
59
+ ${OPACON0.name} = ${OPACON0.valueAsHex};
60
+ </#if>
61
+ }
62
+
63
+ inline void ${moduleNameUpperCase}_EnableChargePump(void)
64
+ {
65
+ ${OPACON0.name}bits.${OPACON0.settings.CPON.alias} = 1;
66
+ }
67
+
68
+ inline void ${moduleNameUpperCase}_DisableChargePump(void)
69
+ {
70
+ ${OPACON0.name}bits.${OPACON0.settings.CPON.alias} = 0;
71
+ }
72
+
73
+ inline void ${moduleNameUpperCase}_EnableSoftwareUnityGain(void)
74
+ {
75
+ ${OPACON0.name}bits.${OPACON0.settings.UG.alias} = 1;
76
+ }
77
+
78
+ inline void ${moduleNameUpperCase}_DisableSoftwareUnityGain(void)
79
+ {
80
+ ${OPACON0.name}bits.${OPACON0.settings.UG.alias} = 0;
81
+ }
82
+
83
+ inline void ${moduleNameUpperCase}_SetPositiveChannel(${moduleNameUpperCase}_posChannel_select posChannel)
84
+ {
85
+ ${OPACON2.name}bits.${OPACON2.settings.PCH.alias} = posChannel;
86
+ }
87
+
88
+ inline void ${moduleNameUpperCase}_SetPositiveSource(${moduleNameUpperCase}_posSource_select posSource)
89
+ {
90
+ ${OPACON3.name}bits.${OPACON3.settings.PSS.alias} = posSource;
91
+ }
92
+
93
+ inline void ${moduleNameUpperCase}_SetNegativeChannel(${moduleNameUpperCase}_negChannel_select negChannel)
94
+ {
95
+ ${OPACON2.name}bits.${OPACON2.settings.NCH.alias} = negChannel;
96
+ }
97
+
98
+ inline void ${moduleNameUpperCase}_SetNegativeSource(${moduleNameUpperCase}_negSource_select negSource)
99
+ {
100
+ ${OPACON1.name}bits.${OPACON1.settings.NSS.alias} = negSource;
101
+ }
102
+
103
+ void ${moduleNameUpperCase}_SetResistorLadder(${moduleNameUpperCase}_resistor_select resistorSelection)
104
+ {
105
+ ${OPACON1.name}bits.${OPACON1.settings.RESON.alias} = 1;
106
+ ${OPACON1.name}bits.${OPACON1.settings.GSEL.alias} = resistorSelection;
107
+ }
108
+
109
+ inline void ${moduleNameUpperCase}_EnableHardwareOverride(void)
110
+ {
111
+ ${OPAHWC.name}bits.${OPAHWC.settings.OREN.alias} = 1;
112
+ }
113
+
114
+ void ${moduleNameUpperCase}_SetHardwareOverrideSource(uint8_t overrideSource, uint8_t polarity)
115
+ {
116
+ ${OPAORS.name} = overrideSource;
117
+ ${OPAHWC.name}bits.${OPAHWC.settings.ORPOL.alias} = polarity;
118
+ }
119
+
120
+ inline void ${moduleNameUpperCase}_DisableHardwareOverride(void)
121
+ {
122
+ ${OPAHWC.name}bits.${OPAHWC.settings.OREN.alias} = 0;
123
+ }
124
+
125
+ inline void ${moduleNameUpperCase}_ManualInputOffsetCalibration(uint8_t offset)
126
+ {
127
+ ${OPAOFFSET.name} = offset;
128
+ }
129
+
130
+ void ${moduleNameUpperCase}_StartAutomaticOffsetCalibration(void)
131
+ {
132
+ ${OPACON4.name}bits.${OPACON4.settings.OFCSEL.alias} = 2;
133
+ ${OPACON4.name}bits.${OPACON4.settings.OFCST.alias} = 1;
134
+ }
135
+
136
+ inline bool ${moduleNameUpperCase}_isAutomaticOffsetCalibrationDone(void)
137
+ {
138
+ return (${OPACON4.name}bits.${OPACON4.settings.OFCST.alias});
139
+ }
140
+
141
+ inline void ${moduleNameUpperCase}_StartPeakTroughReset(void)
142
+ {
143
+ ${OPACON4.name}bits.${OPACON4.settings.PTRES.alias} = 1;
144
+ }
145
+
146
+ inline void ${moduleNameUpperCase}_StopPeakTroughReset(void)
147
+ {
148
+ ${OPACON4.name}bits.${OPACON4.settings.PTRES.alias} = 0;
149
+ }
package/package.json ADDED
@@ -0,0 +1,172 @@
1
+ {
2
+ "name": "@mchp-mcc/scf-pic8-opamp-v2",
3
+ "version": "1.0.0",
4
+ "scf": {
5
+ "reducer": "output/reducer.js",
6
+ "creator": "output/creator.js",
7
+ "processor": "output/processor.js",
8
+ "nullPrototype": "output/nullPrototype.json",
9
+ "views": {
10
+ "main": "auto"
11
+ },
12
+ "displayName": "OPA",
13
+ "category": "Drivers/OPAMP",
14
+ "autoProcessor": "output/autoProcessor.js",
15
+ "autoCreator": "output/autoCreator.js"
16
+ },
17
+ "jenkinsPipeline": "MCU8_DS_PIPELINE_2XY",
18
+ "scf-automodule": {
19
+ "peripheral": {
20
+ "deviceName": "PIC18F56Q71",
21
+ "interfaceId": {
22
+ "name": "scf-pic8-opamp-v2",
23
+ "version": "1.0.0"
24
+ },
25
+ "instance": "OPA"
26
+ },
27
+ "shouldNotifyOnDeploy": false,
28
+ "mode": "standard",
29
+ "hookPaths": {
30
+ "processor": "generated_module/src/processor.ts",
31
+ "creator": "generated_module/src/creator.ts",
32
+ "reducer": "src/reducer.ts"
33
+ }
34
+ },
35
+ "license": "SEE LICENSE IN LICENSE.txt",
36
+ "scripts": {
37
+ "build": "gulp build --gulpfile config/gulpfile.js --cwd .",
38
+ "build-dev": "gulp build --gulpfile config/gulpfile.js --buildDev --cwd .",
39
+ "build-prod": "gulp build --gulpfile config/gulpfile.js --production --cwd .",
40
+ "start": "gulp start --gulpfile config/gulpfile.js --cwd .",
41
+ "test": "jest",
42
+ "test:itf:all": "node ./node_modules/@microchip/ccl-itf/lib/index.js --sp=tests/itf --rd=run --sf=opamp.major.test.ts --df=\"PIC18F.*Q71\"",
43
+ "test:itf:dev": "node ./node_modules/@microchip/ccl-itf/lib/index.js --sp=tests/itf --rd=run --sf=opamp.major.test.ts --df=\"PIC18F56Q71\"",
44
+ "test:itf:interface": "node ./node_modules/@microchip/ccl-itf/lib/index.js --sp=tests/itf --rd=run --intf=scf-pic8-opamp-v2 --intV=1.0.0",
45
+ "create-auto-module": "gulp create-auto-module --gulpfile config/gulpfile.js --cwd .",
46
+ "build-run-dir": "node config/extract-run-directory.js",
47
+ "build-latest-run-dir": "yarn add @microchip/run-directory && yarn build-run-dir",
48
+ "dist": "gulp dist --gulpfile config/gulpfile.js --cwd .",
49
+ "lint:nofix": "eslint \"./src/**/*.{ts,tsx}\" --quiet",
50
+ "lint": "tsc --noEmit && yarn lint:nofix --fix",
51
+ "updateProject": "node config/create-auto-module.js --updateProject=true",
52
+ "update-auto-module": "yarn add @microchip/scf-automodule -D && yarn updateProject",
53
+ "profile": "jest profile",
54
+ "release": "yarn build && yarn test && node -e 'require(\"./config/scf-project-scripts\").releaseProject()'",
55
+ "postprocess": "node config/appendPrototype.js"
56
+ },
57
+ "husky": {
58
+ "hooks": {
59
+ "pre-commit": "tsc --noEmit && lint-staged"
60
+ }
61
+ },
62
+ "lint-staged": {
63
+ "./src/**/*.{ts,tsx}": [
64
+ "eslint --fix"
65
+ ]
66
+ },
67
+ "files": [
68
+ "output/**/*",
69
+ "config.json",
70
+ "src/**/*"
71
+ ],
72
+ "jest": {
73
+ "testPathIgnorePatterns": [
74
+ "/node_modules/",
75
+ "/run/",
76
+ "/generated_module/examples/",
77
+ "/lib/",
78
+ "/tests/itf/"
79
+ ],
80
+ "modulePathIgnorePatterns": [
81
+ "<rootDir>/run"
82
+ ],
83
+ "preset": "ts-jest",
84
+ "collectCoverage": true,
85
+ "coverageThreshold": {
86
+ "./src": {
87
+ "branches": 80,
88
+ "functions": 80,
89
+ "lines": 80,
90
+ "statements": 80
91
+ }
92
+ }
93
+ },
94
+ "dependencies": {
95
+ "@microchip/api-prefix-registration": "^0.1.0",
96
+ "@microchip/fosc-hz": "^0.1.2",
97
+ "@microchip/pin-standard": "^0.4.1",
98
+ "@microchip/scf-autoview-impl": "^3.7.1",
99
+ "@microchip/scf-common": "^3.17.0",
100
+ "@microchip/scf-device": "^8.5.0",
101
+ "@microchip/scf-integration-test": "^1.0.0",
102
+ "@microchip/scf-interface": "^1.4.0",
103
+ "@microchip/scf-register-view-helper": "^2.5.0",
104
+ "babel-jest": "^27.5.1"
105
+ },
106
+ "devDependencies": {
107
+ "@babel/core": "^7.9.6",
108
+ "@babel/plugin-proposal-class-properties": "^7.8.3",
109
+ "@microchip/ccl-itf": "^1.3.0",
110
+ "@babel/preset-env": "^7.9.6",
111
+ "@babel/preset-react": "^7.9.4",
112
+ "@babel/preset-typescript": "^7.9.0",
113
+ "@mchp-mcc/pic-8bit": "^5.10.0-dev.2",
114
+ "@mchp-mcc/pic-8bit-types": "^5.10.0-dev.2",
115
+ "@microchip/initializer-system": "^0.5.3",
116
+ "@microchip/melody-automodule-interface": "^1.6.3",
117
+ "@microchip/run-directory": "^4.2.1",
118
+ "@microchip/scf-automodule": "^5.6.5",
119
+ "@microchip/scf-automodule-impl": "^1.8.3",
120
+ "@microchip/scf-autoview": "^3.26.1",
121
+ "@microchip/scf-project-scripts": "^1.0.0",
122
+ "@types/core-js": "^2.5.1",
123
+ "@types/enzyme": "^3.9.3",
124
+ "@types/jest": "^24.0.14",
125
+ "@types/lodash.filter": "^4.6.6",
126
+ "@types/lodash.find": "^4.6.6",
127
+ "@types/lodash.map": "^4.6.13",
128
+ "@types/node": "^12.0.10",
129
+ "@types/properties-reader": "^0.0.1",
130
+ "@types/semver": "^7.1.0",
131
+ "@typescript-eslint/eslint-plugin": "^3.2.0",
132
+ "@typescript-eslint/parser": "^3.6.0",
133
+ "babel-eslint": "^10.1.0",
134
+ "babel-loader": "^8.0.6",
135
+ "babel-plugin-named-asset-import": "^0.3.2",
136
+ "babel-preset-react-app": "^9.0.0",
137
+ "del": "^4.1.1",
138
+ "eslint": "^7.4.0",
139
+ "eslint-config-prettier": "^6.11.0",
140
+ "eslint-friendly-formatter": "^4.0.1",
141
+ "eslint-loader": "^4.0.2",
142
+ "eslint-plugin-prettier": "^3.1.3",
143
+ "eslint-plugin-react": "^7.20.0",
144
+ "fork-ts-checker-webpack-plugin": "^1.3.7",
145
+ "fs": "^0.0.1-security",
146
+ "gulp": "^4.0.2",
147
+ "gulp-changed": "^4.0.2",
148
+ "gulp-cli": "^2.2.0",
149
+ "gulp-if": "^3.0.0",
150
+ "gulp-typescript": "^5.0.1",
151
+ "hard-source-webpack-plugin": "^0.13.1",
152
+ "husky": "^4.2.4",
153
+ "is-wsl": "^2.1.0",
154
+ "jest": "^24.8.0",
155
+ "jest-html-reporter": "^2.5.0",
156
+ "jest-pnp-resolver": "^1.2.1",
157
+ "lint-staged": "^10.1.3",
158
+ "pnp-webpack-plugin": "^1.5.0",
159
+ "prettier": "^2.0.5",
160
+ "ts-jest": "^24.0.2",
161
+ "ts-pnp": "^1.1.2",
162
+ "typescript": "~4.5.5",
163
+ "webpack": "^4.34.0",
164
+ "webpack-cli": "^3.3.4",
165
+ "webpack-merge": "^4.2.2",
166
+ "webpack-stream": "^5.2.1",
167
+ "yargs": "^13.2.4"
168
+ },
169
+ "description": "- Download & Install [nodejs](https://nodejs.org/en/download/)\r - Download & Install npm\r - Setup node & npm in enviroment path",
170
+ "main": "lib/generated_module/src/index.js",
171
+ "author": ""
172
+ }
@@ -0,0 +1,83 @@
1
+ import { Calculations } from "./Calculations";
2
+
3
+ describe("Testing the calculated Non-inverting Gain values", () => {
4
+ test("Test with Register selection R1 = 15R and R2 = 1R", () => {
5
+ const calc: Calculations = new Calculations();
6
+ expect(calc.calcNonInvGain("R1 = 15R and R2 = 1R, R2/R1 = 0.07")).toEqual("1.07");
7
+ });
8
+
9
+ test("Test with Register selection R1 = 8R and R2 = 8R", () => {
10
+ const calc: Calculations = new Calculations();
11
+ expect(calc.calcNonInvGain("R1 = 8R and R2 = 8R, R2/R1 = 1")).toEqual("2.00");
12
+ });
13
+
14
+ test("Test with Register selection R1 = 1R and R2 = 15R", () => {
15
+ const calc: Calculations = new Calculations();
16
+ expect(calc.calcNonInvGain("R1 = 1R and R2 = 15R, R2/R1 = 15")).toEqual("16.00");
17
+ });
18
+
19
+ test("Test with Register selection R1 = 15r and R2 = 1r", () => {
20
+ const calc: Calculations = new Calculations();
21
+ expect(calc.calcNonInvGain("R1 = 15r and R2 = 1r, R2/R1 = 0.07")).toEqual("1.07");
22
+ });
23
+
24
+ test("Test with Register selection is undefined", () => {
25
+ const calc: Calculations = new Calculations();
26
+ expect(calc.calcNonInvGain(undefined)).toEqual("0");
27
+ });
28
+
29
+ test("Test with Register selection R1 = 1 and R2 = 15", () => {
30
+ const calc: Calculations = new Calculations();
31
+ expect(calc.calcNonInvGain("R1 = 1 and R2 = 15, R2/R1 = 15")).toEqual("0");
32
+ });
33
+
34
+ test("Test with Register selection R1 = 1R and R2 = 15R", () => {
35
+ const calc: Calculations = new Calculations();
36
+ expect(calc.calcNonInvGain("R1 = 1R and R2 = 15R")).toEqual("0");
37
+ });
38
+ });
39
+
40
+ describe("Testing the calculated Inverting Gain values", () => {
41
+ test("Test with Register selection R1 = 15R and R2 = 1R", () => {
42
+ const calc: Calculations = new Calculations();
43
+ expect(calc.calcInvGain("R1 = 15R and R2 = 1R, R2/R1 = 0.07")).toEqual(
44
+ "1.07(Vref/Vin) - 0.07",
45
+ );
46
+ });
47
+
48
+ test("Test with Register selection R1 = 8R and R2 = 8R", () => {
49
+ const calc: Calculations = new Calculations();
50
+ expect(calc.calcInvGain("R1 = 8R and R2 = 8R, R2/R1 = 1")).toEqual(
51
+ "2.00(Vref/Vin) - 1",
52
+ );
53
+ });
54
+
55
+ test("Test with Register selection R1 = 15R and R2 = 1R", () => {
56
+ const calc: Calculations = new Calculations();
57
+ expect(calc.calcInvGain("R1 = 15R and R2 = 1R, R2/R1 = 15")).toEqual(
58
+ "16.00(Vref/Vin) - 15",
59
+ );
60
+ });
61
+
62
+ test("Test with Register selection R1 = 15r and R2 = 1r", () => {
63
+ const calc: Calculations = new Calculations();
64
+ expect(calc.calcInvGain("R1 = 15r and R2 = 1r, R2/R1 = 0.07")).toEqual(
65
+ "1.07(Vref/Vin) - 0.07",
66
+ );
67
+ });
68
+
69
+ test("Test with Register selection is undefined", () => {
70
+ const calc: Calculations = new Calculations();
71
+ expect(calc.calcInvGain(undefined)).toEqual("0");
72
+ });
73
+
74
+ test("Test with Register selection R1 = 1 and R2 = 15", () => {
75
+ const calc: Calculations = new Calculations();
76
+ expect(calc.calcInvGain("R1 = 1 and R2 = 15, R2/R1 = 15")).toEqual("0");
77
+ });
78
+
79
+ test("Test with Register selection R1 = 1R and R2 = 15R", () => {
80
+ const calc: Calculations = new Calculations();
81
+ expect(calc.calcInvGain("R1 = 1R and R2 = 15R")).toEqual("0");
82
+ });
83
+ });
@@ -0,0 +1,20 @@
1
+ export class Calculations {
2
+ public calcNonInvGain = (resSelect: string | undefined): string => {
3
+ if (resSelect == undefined) return "0";
4
+ const regExp = /^([Rr]1 = [0-9]{0,2}[rR] and [Rr]2 = [0-9]{0,2}[Rr], [Rr]2\/[Rr]1 = )(.*)$/;
5
+ const ratio = resSelect.match(regExp)?.[2];
6
+ if (ratio == undefined) return "0";
7
+ const gain = (parseFloat(ratio) + 1).toFixed(2);
8
+ return gain;
9
+ };
10
+
11
+ public calcInvGain = (resSelect: string | undefined): string => {
12
+ if (resSelect == undefined) return "0";
13
+ const regExp = /^([Rr]1 = [0-9]{0,2}[rR] and [Rr]2 = [0-9]{0,2}[Rr], [Rr]2\/[Rr]1 = )(.*)$/;
14
+ const ratio = resSelect.match(regExp)?.[2];
15
+ if (ratio == undefined) return "0";
16
+ const constValue = "(Vref/Vin) - ";
17
+ const gain = (parseFloat(ratio) + 1).toFixed(2) + constValue + ratio;
18
+ return gain;
19
+ };
20
+ }
@@ -0,0 +1,214 @@
1
+ import { getCreatorFunctions } from "./CreatorFunctions";
2
+ import { mockState } from "../generated_module/tests/AppModel.test";
3
+
4
+ describe("Test for shouldImport", () => {
5
+ const state = mockState();
6
+
7
+ test("Testing TMR0 shouldImport", () => {
8
+ expect(getCreatorFunctions?.()?.shouldImport?.("TMR0", state)).toEqual(false);
9
+ });
10
+
11
+ test("Testing TMR1 shouldImport", () => {
12
+ expect(getCreatorFunctions?.()?.shouldImport?.("TMR1", state)).toEqual(false);
13
+ });
14
+
15
+ test("Testing TMR2 shouldImport", () => {
16
+ expect(getCreatorFunctions?.()?.shouldImport?.("TMR2", state)).toEqual(false);
17
+ });
18
+
19
+ test("Testing CCP shouldImport", () => {
20
+ expect(getCreatorFunctions?.()?.shouldImport?.("CCP", state)).toEqual(false);
21
+ });
22
+
23
+ test("Testing PWM shouldImport", () => {
24
+ expect(getCreatorFunctions?.()?.shouldImport?.("PWM", state)).toEqual(false);
25
+ });
26
+
27
+ test("Testing NCO shouldImport", () => {
28
+ expect(getCreatorFunctions?.()?.shouldImport?.("NCO", state)).toEqual(false);
29
+ });
30
+
31
+ test("Testing CMP shouldImport", () => {
32
+ expect(getCreatorFunctions?.()?.shouldImport?.("CMP", state)).toEqual(false);
33
+ });
34
+
35
+ test("Testing ZCD shouldImport", () => {
36
+ expect(getCreatorFunctions?.()?.shouldImport?.("ZCD", state)).toEqual(false);
37
+ });
38
+
39
+ test("Testing CLC shouldImport", () => {
40
+ expect(getCreatorFunctions?.()?.shouldImport?.("CLC", state)).toEqual(false);
41
+ });
42
+
43
+ test("Testing System shouldImport", () => {
44
+ expect(
45
+ getCreatorFunctions?.()?.shouldImport?.("initializer_system", state),
46
+ ).toEqual(true);
47
+ });
48
+ });
49
+
50
+ describe("Test for shouldImport for TMR0 and Hardware Override", () => {
51
+ let state = mockState();
52
+ state = {
53
+ ...state,
54
+ main: {
55
+ overrideSel: {
56
+ orsOpaors: "TMR0_OUT",
57
+ },
58
+ },
59
+ };
60
+
61
+ test("Testing TMR0 shouldImport", () => {
62
+ expect(getCreatorFunctions?.()?.shouldImport?.("TMR0", state)).toEqual(true);
63
+ });
64
+ });
65
+
66
+ describe("Test for shouldImport for TMR1", () => {
67
+ let state = mockState();
68
+ state = {
69
+ ...state,
70
+ main: {
71
+ overrideSel: {
72
+ orsOpaors: "TMR1_OUT",
73
+ },
74
+ },
75
+ };
76
+
77
+ test("Testing TMR1 shouldImport", () => {
78
+ expect(getCreatorFunctions?.()?.shouldImport?.("TMR1", state)).toEqual(true);
79
+ });
80
+ });
81
+
82
+ describe("Test for shouldImport for TMR2", () => {
83
+ let state = mockState();
84
+ state = {
85
+ ...state,
86
+ main: {
87
+ overrideSel: {
88
+ orsOpaors: "TMR2_OUT",
89
+ },
90
+ },
91
+ };
92
+
93
+ test("Testing TMR2 shouldImport", () => {
94
+ expect(getCreatorFunctions?.()?.shouldImport?.("TMR2", state)).toEqual(true);
95
+ });
96
+ });
97
+
98
+ describe("Test for shouldImport for CCP", () => {
99
+ let state = mockState();
100
+ state = {
101
+ ...state,
102
+ main: {
103
+ overrideSel: {
104
+ orsOpaors: "CCP_OUT",
105
+ },
106
+ },
107
+ };
108
+
109
+ test("Testing CCP1 shouldImport", () => {
110
+ expect(getCreatorFunctions?.()?.shouldImport?.("CCP", state)).toEqual(true);
111
+ });
112
+ });
113
+
114
+ describe("Test for shouldImport for PWM", () => {
115
+ let state = mockState();
116
+ state = {
117
+ ...state,
118
+ main: {
119
+ overrideSel: {
120
+ orsOpaors: "PWM1_S1P2",
121
+ },
122
+ },
123
+ };
124
+
125
+ test("Testing PWM1_S1P2 shouldImport", () => {
126
+ expect(getCreatorFunctions?.()?.shouldImport?.("PWM", state)).toEqual(true);
127
+ });
128
+ });
129
+
130
+ describe("Test for shouldImport for NCO", () => {
131
+ let state = mockState();
132
+ state = {
133
+ ...state,
134
+ main: {
135
+ overrideSel: {
136
+ orsOpaors: "NCO1_OUT",
137
+ },
138
+ },
139
+ };
140
+
141
+ test("Testing NCO1 shouldImport", () => {
142
+ expect(getCreatorFunctions?.()?.shouldImport?.("NCO", state)).toEqual(true);
143
+ });
144
+ });
145
+
146
+ describe("Test for shouldImport for CMP", () => {
147
+ let state = mockState();
148
+ state = {
149
+ ...state,
150
+ main: {
151
+ overrideSel: {
152
+ orsOpaors: "CM1_OUT",
153
+ },
154
+ },
155
+ };
156
+
157
+ test("Testing CMP1 shouldImport", () => {
158
+ expect(getCreatorFunctions?.()?.shouldImport?.("CMP", state)).toEqual(true);
159
+ });
160
+ });
161
+
162
+ describe("Test for shouldImport for ZCD", () => {
163
+ let state = mockState();
164
+ state = {
165
+ ...state,
166
+ main: {
167
+ overrideSel: {
168
+ orsOpaors: "ZCD_OUT",
169
+ },
170
+ },
171
+ };
172
+
173
+ test("Testing ZCD shouldImport", () => {
174
+ expect(getCreatorFunctions?.()?.shouldImport?.("ZCD", state)).toEqual(true);
175
+ });
176
+ });
177
+
178
+ describe("Test for shouldImport for CLC", () => {
179
+ let state = mockState();
180
+ state = {
181
+ ...state,
182
+ main: {
183
+ overrideSel: {
184
+ orsOpaors: "CLC1_OUT",
185
+ },
186
+ },
187
+ };
188
+
189
+ test("Testing CLC1 shouldImport", () => {
190
+ expect(getCreatorFunctions?.()?.shouldImport?.("CLC", state)).toEqual(true);
191
+ });
192
+ });
193
+
194
+ describe("Test for undefined state", () => {
195
+ test("Testing CLC shouldImport", () => {
196
+ expect(getCreatorFunctions?.()?.shouldImport?.("CLC", undefined)).toEqual(false);
197
+ });
198
+
199
+ test("Testing System shouldImport", () => {
200
+ expect(
201
+ getCreatorFunctions?.()?.shouldImport?.("initializer_system", undefined),
202
+ ).toEqual(true);
203
+ });
204
+ });
205
+
206
+ describe("Test for getCreatorImportArgs", () => {
207
+ const state = mockState();
208
+
209
+ test("Testing TMR0 getCreatorImportArgs", () => {
210
+ expect(
211
+ getCreatorFunctions?.()?.getCreatorImportArgs?.("TMR0", state),
212
+ ).toBeUndefined();
213
+ });
214
+ });
@@ -0,0 +1,48 @@
1
+ import { CreatorFunctions } from "@microchip/melody-automodule-interface";
2
+ import { MyState } from "../generated_module/src/types/AutoModuleTypes";
3
+
4
+ export const getCreatorFunctions = (): CreatorFunctions => {
5
+ return {
6
+ shouldImport: shouldImport,
7
+ getCreatorImportArgs: getCreatorImportArgs,
8
+ };
9
+ };
10
+
11
+ const shouldImport = (importKey: string, state: MyState | undefined): boolean => {
12
+ const hwOverrideSrc = state?.main?.overrideSel?.orsOpaors ?? "LFINTOSC";
13
+
14
+ switch (importKey) {
15
+ case "TMR0":
16
+ return hwOverrideSrc.indexOf("TMR0") != -1 ? true : false;
17
+ case "TMR1":
18
+ return hwOverrideSrc.indexOf(
19
+ hwOverrideSrc.match(/(TMR[135])_OUT/)?.[1] ?? "TMR1",
20
+ ) != -1
21
+ ? true
22
+ : false;
23
+ case "TMR2":
24
+ return hwOverrideSrc.indexOf(
25
+ hwOverrideSrc.match(/(TMR[246])_OUT/)?.[1] ?? "TMR2",
26
+ ) != -1
27
+ ? true
28
+ : false;
29
+ case "CCP":
30
+ return hwOverrideSrc.indexOf("CCP") != -1 ? true : false;
31
+ case "PWM":
32
+ return hwOverrideSrc.indexOf("PWM") != -1 ? true : false;
33
+ case "NCO":
34
+ return hwOverrideSrc.indexOf("NCO") != -1 ? true : false;
35
+ case "CMP":
36
+ return hwOverrideSrc.indexOf("CM") != -1 ? true : false;
37
+ case "ZCD":
38
+ return hwOverrideSrc.indexOf("ZCD") != -1 ? true : false;
39
+ case "CLC":
40
+ return hwOverrideSrc.indexOf("CLC") != -1 ? true : false;
41
+ default:
42
+ return true;
43
+ }
44
+ };
45
+
46
+ const getCreatorImportArgs = (importKey: string, state: MyState): any | undefined => {
47
+ return undefined;
48
+ };