gpt4 book ai didi

c++ - 如何避免与制造商定义的寄存器名称相同的基类名称不明确

转载 作者:行者123 更新时间:2023-12-02 10:58:06 25 4
gpt4 key购买 nike

我正在派生一个名为 ( Class Adc ) 的基类。还有一个制造商的头文件,它有一个 结构用于名称为 的 ADC 寄存器ADC .

当我尝试在我的子类中使用 ADC 结构时,编译器将它与基类混淆。此外,基类是“symm”命名空间的一部分,而结构是全局命名空间的一部分。

有什么办法可以在不更改两个名称的情况下避免名称中的这种歧义。基类用于许多项目。更改基类名称会在其他项目中造成一些麻烦。我也不想触摸制造商的标题。

这是我正在谈论的 Manfacturer 的结构:

 /** \brief ADC hardware registers */
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
typedef struct {
__IO ADC_CTRLA_Type CTRLA; /**< \brief Offset: 0x00 (R/W 8) Control A */
__IO ADC_CTRLB_Type CTRLB; /**< \brief Offset: 0x01 (R/W 8) Control B */
__IO ADC_REFCTRL_Type REFCTRL; /**< \brief Offset: 0x02 (R/W 8) Reference Control */
__IO ADC_EVCTRL_Type EVCTRL; /**< \brief Offset: 0x03 (R/W 8) Event Control */
__IO ADC_INTENCLR_Type INTENCLR; /**< \brief Offset: 0x04 (R/W 8) Interrupt Enable Clear */
__IO ADC_INTENSET_Type INTENSET; /**< \brief Offset: 0x05 (R/W 8) Interrupt Enable Set */
__IO ADC_INTFLAG_Type INTFLAG; /**< \brief Offset: 0x06 (R/W 8) Interrupt Flag Status and Clear */
__I ADC_SEQSTATUS_Type SEQSTATUS; /**< \brief Offset: 0x07 (R/ 8) Sequence Status */
__IO ADC_INPUTCTRL_Type INPUTCTRL; /**< \brief Offset: 0x08 (R/W 16) Input Control */
__IO ADC_CTRLC_Type CTRLC; /**< \brief Offset: 0x0A (R/W 16) Control C */
__IO ADC_AVGCTRL_Type AVGCTRL; /**< \brief Offset: 0x0C (R/W 8) Average Control */
__IO ADC_SAMPCTRL_Type SAMPCTRL; /**< \brief Offset: 0x0D (R/W 8) Sample Time Control */
__IO ADC_WINLT_Type WINLT; /**< \brief Offset: 0x0E (R/W 16) Window Monitor Lower Threshold */
__IO ADC_WINUT_Type WINUT; /**< \brief Offset: 0x10 (R/W 16) Window Monitor Upper Threshold */
__IO ADC_GAINCORR_Type GAINCORR; /**< \brief Offset: 0x12 (R/W 16) Gain Correction */
__IO ADC_OFFSETCORR_Type OFFSETCORR; /**< \brief Offset: 0x14 (R/W 16) Offset Correction */
RoReg8 Reserved1[0x2];
__IO ADC_SWTRIG_Type SWTRIG; /**< \brief Offset: 0x18 (R/W 8) Software Trigger */
RoReg8 Reserved2[0x3];
__IO ADC_DBGCTRL_Type DBGCTRL; /**< \brief Offset: 0x1C (R/W 8) Debug Control */
RoReg8 Reserved3[0x3];
__I ADC_SYNCBUSY_Type SYNCBUSY; /**< \brief Offset: 0x20 (R/ 16) Synchronization Busy */
RoReg8 Reserved4[0x2];
__I ADC_RESULT_Type RESULT; /**< \brief Offset: 0x24 (R/ 16) Result */
RoReg8 Reserved5[0x2];
__IO ADC_SEQCTRL_Type SEQCTRL; /**< \brief Offset: 0x28 (R/W 32) Sequence Control */
__IO ADC_CALIB_Type CALIB; /**< \brief Offset: 0x2C (R/W 16) Calibration */
} Adc;
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */

这是我的子类定义:
class ADC_SAML21 : public Adc
{
public:

ADC_SAML21(bool interruptable = false);
}

谢谢你。

问候,
里希特

最佳答案

在编译器无法弄清楚的地方Adc您所指的是,您可以使用范围运算符来指定哪个。使用 symm::Adc对于基类(或可能是 ::symm::Adc )和 ::Adc对于全局结构。

关于c++ - 如何避免与制造商定义的寄存器名称相同的基类名称不明确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54334497/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com