| Nano100BN Series BSP V3.03.002 The Board Support Package for Nano100BN Series

NuEdu-Basic01_Threshold_Knob.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include "NUC200Series.h"
3 #include "NuEdu-Basic01_Threshold_Knob.h"
4
5 void Open_Threshold_Knob(void)
6 {
7 //Initial ACMP0 Function Pin
8 SYS->GPC_MFP = (SYS->GPC_MFP & ~SYS_GPC_MFP_PC6_Msk) | SYS_GPC_MFP_PC6_CPP0;
9 SYS->ALT_MFP1 &= ~SYS_ALT_MFP1_PC6_Msk;
10 PC->OFFD |= GPIO_OFFD_ENABLE(6);
11
12 SYS->GPC_MFP = (SYS->GPC_MFP & ~SYS_GPC_MFP_PC7_Msk) | SYS_GPC_MFP_PC7_CPN0;
13 SYS->ALT_MFP1 &= ~SYS_ALT_MFP1_PC7_Msk;
14 PC->OFFD |= GPIO_OFFD_ENABLE(7);
15
16 /* SYS->GPB_MFP = (SYS->GPB_MFP & ~SYS_GPB_MFP_PB2_Msk) | SYS_GPB_MFP_PB2_CPO0;
17 SYS->ALT_MFP &= ~SYS_ALT_MFP_PB2_Msk;
18 // SYS->ALT_MFP2 &= ~SYS_ALT_MFP2_PB2_Msk;
19 // PB->OFFD |= GPIO_OFFD_ENABLE(2);
20 */
21
22 //Initial ACMP Clock Source
23 SYS_UnlockReg();
24 // SYS->IPRSTC2 |= SYS_IPRSTC2_ACMP_RST_Msk;
25 // SYS->IPRSTC2 &= ~SYS_IPRSTC2_ACMP_RST_Msk;
26 SYSCLK->APBCLK |= SYSCLK_APBCLK_ACMP_EN_Msk;
27 SYS_LockReg();
28
29 //Initial ACMP0 Peripheral
30 ACMP->CMPSR = ACMP_CMPSR_CMPF0_Msk; //Clear ACMP0 Flags
31 ACMP->CMPCR[0] = ACMP_CMPCR_CMP_HYSEN_Msk | ACMP_CMPCR_CMPEN_Msk;
32 }
33
34 void Close_Threshold_Knob(void)
35 {
36 //Close ACMP Function Pin
37 SYS->GPC_MFP &= ~SYS_GPC_MFP_PC6_Msk;
38 SYS->ALT_MFP1 &= ~SYS_ALT_MFP1_PC6_Msk;
39 PC->OFFD &= ~GPIO_OFFD_ENABLE(6);
40
41 SYS->GPC_MFP &= ~SYS_GPC_MFP_PC7_Msk;
42 SYS->ALT_MFP1 &= ~SYS_ALT_MFP1_PC7_Msk;
43 PC->OFFD &= ~GPIO_OFFD_ENABLE(7);
44
45 /* SYS->GPB_MFP &= ~SYS_GPB_MFP_PB2_Msk;
46 SYS->ALT_MFP &= ~SYS_ALT_MFP_PB2_Msk;
47 // SYS->ALT_MFP2 &= ~SYS_ALT_MFP2_PB2_Msk;
48 // PB->OFFD &= ~GPIO_OFFD_ENABLE(2);
49 */
50 //Close ACMP Clock Source
51 ACMP->CMPCR[0] &= ~ACMP_CMPCR_CMPEN_Msk;
52 if(!(ACMP->CMPCR[0]&ACMP_CMPCR_CMPEN_Msk) || !(ACMP->CMPCR[1]&ACMP_CMPCR_CMPEN_Msk)) //Donot Cloce ACMP, Safe for other unknown ACMP device
53 {
54 SYS_UnlockReg();
55 SYS->IPRSTC2 |= SYS_IPRSTC2_ACMP_RST_Msk;
56 SYS->IPRSTC2 &= ~SYS_IPRSTC2_ACMP_RST_Msk;
57 SYSCLK->APBCLK &= ~SYSCLK_APBCLK_ACMP_EN_Msk;
58 SYS_LockReg();
59 }
60 }
61
62 uint32_t Get_Threshold_Knob(void)
63 {
64 uint32_t ACMP0_Output_Level;
65
66 if(ACMP->CMPSR&ACMP_CMPSR_CO0_Msk)
67 ACMP0_Output_Level = 1;
68 else
69 ACMP0_Output_Level = 0;
70
71 ACMP->CMPSR |= ACMP_CMPSR_CMPF0_Msk; //Clear ACMP0 Flags
72
73 return ACMP0_Output_Level;
74 }
Open_Threshold_Knob
void Open_Threshold_Knob(void)
Definition: NuEdu-Basic01_Threshold_Knob.c:5
Close_Threshold_Knob
void Close_Threshold_Knob(void)
Definition: NuEdu-Basic01_Threshold_Knob.c:34
NuEdu-Basic01_Threshold_Knob.h
NuEdu-Basic01 threshold knob driver header file.
SYS_UnlockReg
__STATIC_INLINE void SYS_UnlockReg(void)
Disable register write-protection function.
Definition: sys.h:826
Get_Threshold_Knob
uint32_t Get_Threshold_Knob(void)
Definition: NuEdu-Basic01_Threshold_Knob.c:62
PC
#define PC
Pointer to GPIO port C register structure.
Definition: Nano100Series.h:11697
SYS_LockReg
__STATIC_INLINE void SYS_LockReg(void)
Enable register write-protection function.
Definition: sys.h:843
SYS
#define SYS
Pointer to SYS register structure.
Definition: Nano100Series.h:11692