11#!/usr/bin/env python
22#
3- # Copyright (c) 2019 , Pycom Limited.
3+ # Copyright (c) 2020 , Pycom Limited.
44#
55# This software is licensed under the GNU GPL version 3 or any
66# later version, with permitted additional terms. For more information
77# see the Pycom Licence v1.0 document supplied with this file, or
88# available at https://www.pycom.io/opensource/licensing
99#
1010
11+ # See https://docs.pycom.io for more information regarding library specifics
12+
1113from machine import Pin
1214from machine import I2C
1315import time
@@ -26,6 +28,12 @@ class Pycoproc:
2628
2729 I2C_SLAVE_ADDR = const (8 )
2830
31+ PYSENSE = const (1 )
32+ PYTRACK = const (2 )
33+ PYSCAN = const (3 )
34+
35+ BOARD_TYPE_SET = (PYSENSE , PYTRACK , PYSCAN )
36+
2937 CMD_PEEK = const (0x0 )
3038 CMD_POKE = const (0x01 )
3139 CMD_MAGIC = const (0x02 )
@@ -81,14 +89,18 @@ class Pycoproc:
8189
8290 EXP_RTC_PERIOD = const (7000 )
8391
84- def __init__ (self , i2c = None , sda = 'P22' , scl = 'P21' ):
92+ def __init__ (self , board_type , i2c = None , sda = 'P22' , scl = 'P21' ):
8593 if i2c is not None :
8694 self .i2c = i2c
8795 else :
88- self .i2c = I2C (0 , mode = I2C .MASTER , pins = (sda , scl ), baudrate = 100000 )
96+ self .i2c = I2C (0 , mode = I2C .MASTER , pins = (sda , scl ))
97+
98+ if board_type not in self .BOARD_TYPE_SET :
99+ raise Exception ('Board type not in the set {}' .format (self .BOARD_TYPE_SET ))
89100
90101 self .sda = sda
91102 self .scl = scl
103+ self .board_type = board_type
92104 self .clk_cal_factor = 1
93105 self .reg = bytearray (6 )
94106 self .wake_int = False
@@ -202,11 +214,14 @@ def setup_sleep(self, time_s):
202214 self ._write (bytes ([CMD_SETUP_SLEEP , time_s & 0xFF , (time_s >> 8 ) & 0xFF , (time_s >> 16 ) & 0xFF ]))
203215
204216 def go_to_sleep (self , gps = True ):
205- # enable or disable back-up power to the GPS receiver
206- if gps :
217+ # if we have a Pytrack then enable or disable back-up power to the GPS receiver
218+ if self .board_type == self .PYTRACK and gps :
219+ # disable GPS only if Pytrack
207220 self .set_bits_in_memory (PORTC_ADDR , 1 << 7 )
208221 else :
222+ # Pysense or Pyscan or no GPS
209223 self .mask_bits_in_memory (PORTC_ADDR , ~ (1 << 7 ))
224+
210225 # disable the ADC
211226 self .poke_memory (ADCON0_ADDR , 0 )
212227
@@ -245,7 +260,7 @@ def calibrate_rtc(self):
245260 self .i2c .deinit ()
246261 Pin ('P21' , mode = Pin .IN )
247262 pulses = pycom .pulses_get ('P21' , 100 )
248- self .i2c .init (mode = I2C .MASTER , pins = (self .sda , self .scl ), baudrate = 100000 )
263+ self .i2c .init (mode = I2C .MASTER , pins = (self .sda , self .scl ))
249264 idx = 0
250265 for i in range (len (pulses )):
251266 if pulses [i ][1 ] > EXP_RTC_PERIOD :
0 commit comments