pycoproc.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:pycom-libraries 作者: pycom 项目源码 文件源码
def __init__(self, i2c=None, sda='P22', scl='P21'):
        if i2c is not None:
            self.i2c = i2c
        else:
            self.i2c = I2C(0, mode=I2C.MASTER, pins=(sda, scl))

        self.sda = sda
        self.scl = scl
        self.clk_cal_factor = 1
        self.reg = bytearray(6)
        self.wake_int = False
        self.wake_int_pin = False
        self.wake_int_pin_rising_edge = True

        try:
            self.read_fw_version()
        except Exception:
            time.sleep_ms(2)
        try:
            # init the ADC for the battery measurements
            self.poke_memory(ANSELC_ADDR, 1 << 2)
            self.poke_memory(ADCON0_ADDR, (0x06 << _ADCON0_CHS_POSN) | _ADCON0_ADON_MASK)
            self.poke_memory(ADCON1_ADDR, (0x06 << _ADCON1_ADCS_POSN))
            # enable the pull-up on RA3
            self.poke_memory(WPUA_ADDR, (1 << 3))
            # make RC5 an input
            self.set_bits_in_memory(TRISC_ADDR, 1 << 5)
            # set RC6 and RC7 as outputs and enable power to the sensors and the GPS
            self.mask_bits_in_memory(TRISC_ADDR, ~(1 << 6))
            self.mask_bits_in_memory(TRISC_ADDR, ~(1 << 7))

            if self.read_fw_version() < 6:
                raise ValueError('Firmware out of date')

        except Exception:
            raise Exception('Board not detected')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号