16 #ifdef __MSP430_HAS_COMPB__
21 bool Comp_B_init(uint16_t baseAddress, Comp_B_initParam *param)
29 HWREG16(baseAddress + OFS_CBCTL0) &= 0x0000;
30 HWREG16(baseAddress + OFS_CBINT) &= 0x0000;
33 HWREG16(baseAddress + OFS_CBCTL2) &= ~(CBRS_3 | CBREFL_3);
36 if(COMP_B_VREF != param->positiveTerminalInput) {
38 HWREG16(baseAddress + OFS_CBCTL0) |= CBIPEN + param->positiveTerminalInput;
41 HWREG16(baseAddress + OFS_CBCTL3) |= (1 << param->positiveTerminalInput);
46 HWREG16(baseAddress + OFS_CBCTL2) &= ~(CBRSEL);
50 if (COMP_B_VREF != param->negativeTerminalInput) {
52 HWREG16(baseAddress + OFS_CBCTL0) |= CBIMEN + (param->negativeTerminalInput << 8);
55 HWREG16(baseAddress + OFS_CBCTL3) |= (1 << param->negativeTerminalInput);
60 HWREG16(baseAddress + OFS_CBCTL2) |= CBRSEL;
64 HWREG16(baseAddress + OFS_CBCTL1) =
65 param->powerModeSelect
66 + param->outputFilterEnableAndDelayLevel
67 + param->invertedOutputPolarity;
72 void Comp_B_configureReferenceVoltage(uint16_t baseAddress,
73 Comp_B_configureReferenceVoltageParam *param)
76 HWREG16(baseAddress + OFS_CBCTL1) &= ~(CBMRVS);
79 HWREG16(baseAddress + OFS_CBCTL2) &= CBRSEL;
82 if (COMP_B_VREFBASE_VCC == param->supplyVoltageReferenceBase) {
83 HWREG16(baseAddress + OFS_CBCTL2) |= CBRS_1;
85 else if (param->lowerLimitSupplyVoltageFractionOf32 == 32) {
90 HWREG16(baseAddress + OFS_CBCTL2) |= CBRS_3;
93 HWREG16(baseAddress + OFS_CBCTL2) |= CBRS_2;
97 HWREG16(baseAddress + OFS_CBCTL2) |=
98 param->supplyVoltageReferenceBase
99 + ((param->upperLimitSupplyVoltageFractionOf32 - 1) << 8)
100 + (param->lowerLimitSupplyVoltageFractionOf32 - 1);
102 HWREG16(baseAddress + OFS_CBCTL2) &= ~(CBREFACC);
103 HWREG16(baseAddress + OFS_CBCTL2) |= param->referenceAccuracy;
106 void Comp_B_enableInterrupt(uint16_t baseAddress,
107 uint16_t interruptMask)
110 HWREG16(baseAddress + OFS_CBINT) |= interruptMask;
113 void Comp_B_disableInterrupt(uint16_t baseAddress,
114 uint16_t interruptMask)
116 HWREG16(baseAddress + OFS_CBINT) &= ~(interruptMask);
119 void Comp_B_clearInterrupt(uint16_t baseAddress,
120 uint16_t interruptFlagMask)
122 HWREG16(baseAddress + OFS_CBINT) &= ~(interruptFlagMask);
125 uint8_t Comp_B_getInterruptStatus(uint16_t baseAddress,
126 uint16_t interruptFlagMask)
128 return(
HWREG16(baseAddress + OFS_CBINT) & interruptFlagMask);
131 void Comp_B_setInterruptEdgeDirection(uint16_t baseAddress,
132 uint16_t edgeDirection)
135 if(COMP_B_RISINGEDGE == edgeDirection) {
136 HWREG16(baseAddress + OFS_CBCTL1) &= ~(CBIES);
138 else if(COMP_B_FALLINGEDGE == edgeDirection) {
139 HWREG16(baseAddress + OFS_CBCTL1) |= CBIES;
143 void Comp_B_toggleInterruptEdgeDirection(uint16_t baseAddress)
145 HWREG16(baseAddress + OFS_CBCTL1) ^= CBIES;
148 void Comp_B_enable(uint16_t baseAddress)
150 HWREG16(baseAddress + OFS_CBCTL1) |= CBON;
153 void Comp_B_disable(uint16_t baseAddress)
155 HWREG16(baseAddress + OFS_CBCTL1) &= ~(CBON);
158 void Comp_B_shortInputs(uint16_t baseAddress)
160 HWREG16(baseAddress + OFS_CBCTL1) |= CBSHORT;
163 void Comp_B_unshortInputs(uint16_t baseAddress)
165 HWREG16(baseAddress + OFS_CBCTL1) &= ~(CBSHORT);
168 void Comp_B_disableInputBuffer(uint16_t baseAddress,
171 HWREG16(baseAddress + OFS_CBCTL3) |= (1 << inputPort);
174 void Comp_B_enableInputBuffer(uint16_t baseAddress,
177 HWREG16(baseAddress + OFS_CBCTL3) &= ~(1 << inputPort);
180 void Comp_B_swapIO(uint16_t baseAddress)
182 HWREG16(baseAddress + OFS_CBCTL1) ^= CBEX;
185 uint16_t Comp_B_outputValue(uint16_t baseAddress)
187 return (
HWREG16(baseAddress + OFS_CBCTL1) & CBOUT);
191 void Comp_B_selectReferenceVoltage(uint16_t baseAddress, uint16_t selectType,
194 HWREG16(baseAddress + OFS_CBCTL1) &= ~(CBMRVS | CBMRVL);
195 if(selectType == COMP_B_VREF_MANUAL_SELECT) {
196 HWREG16(baseAddress + OFS_CBCTL1) |= CBMRVS;
197 if(selectVRef == COMP_B_SELECT_VREF1) {
198 HWREG16(baseAddress + OFS_CBCTL1) |= CBMRVL;