|
34 | 34 | Q unsigned long long 8
|
35 | 35 | f float 4
|
36 | 36 | d double 8
|
37 |
| - |
38 |
| -
|
39 | 37 | """
|
40 | 38 |
|
41 | 39 | from machine import I2C
|
|
44 | 42 | class RORegBit:
|
45 | 43 | def __init__(self, i2c, dev_addr, reg_addr, num_bytes, bit_location, endian='', fmt='B'):
|
46 | 44 | """
|
47 |
| - Creates an :class:`RORegBit` object which allows read only access to a single bit within a register. |
48 |
| - |
| 45 | + Creates an :class:`RORegBit` object which allows read only access to a single bit within a register. |
49 | 46 |
|
50 | 47 | :param i2c: I2C bus which connects the host system to the peripheral device
|
51 | 48 | :type kind: machine.I2C()
|
@@ -780,8 +777,7 @@ def __setreg(reg_object, settings):
|
780 | 777 | if isinstance(reg_object, RWReg):
|
781 | 778 | if isinstance(settings, (bytes, bytearray)):
|
782 | 779 | # Write to device
|
783 |
| - reg_object._i2c.writeto_mem(reg_object._dev_addr, reg_object._reg_addr, settings) |
784 |
| - |
| 780 | + reg_object._i2c.writeto_mem(reg_object._dev_addr, reg_object._reg_addr, settings) |
785 | 781 |
|
786 | 782 | elif isinstance(settings, (tuple, list)):
|
787 | 783 | # Where our data will go
|
@@ -809,8 +805,7 @@ def __calc_mask(lsb, msb, numbytes):
|
809 | 805 | Takes in full description of bitfield that needs masking
|
810 | 806 |
|
811 | 807 | returns ints() pre, mask, post
|
812 |
| - """ |
813 |
| - |
| 808 | + """ |
814 | 809 | # Check input types
|
815 | 810 | if lsb.__class__() == int() and lsb >= 0:
|
816 | 811 | if msb.__class__() == int() and msb >= 0:
|
@@ -894,106 +889,3 @@ def __check_reg(reg_object):
|
894 | 889 | raise TypeError("format and endian must be of type str()")
|
895 | 890 | else:
|
896 | 891 | raise TypeError("incorrect object type - must be ROReg, RWReg, ROBits, RWBits, ROReg, RWReg")
|
897 |
| - |
898 |
| -class Transaction: |
899 |
| - """ |
900 |
| - The user can supply a transaction object with a list of any number of |
901 |
| - Register objects. The Transaction object will then perform one I2C |
902 |
| - transaction and return all data as a list OR perform all write operations. |
903 |
| - |
904 |
| - 1) The Register objects should all be from one physical I2C device |
905 |
| - 2) True = Read, False = Write (Default is read) |
906 |
| - 3) Reads can be from non-sequential registers |
907 |
| - 4) Writes can be made only to sequential registers OR more than one |
908 |
| - transaction will be generated |
909 |
| - |
910 |
| - i.e. |
911 |
| - |
912 |
| - # Define Register objects |
913 |
| - register1 = ROBits() |
914 |
| - register2 = ROBits() |
915 |
| - register3 = ROBits() |
916 |
| - |
917 |
| - # Create list object containing only Register objects |
918 |
| - list_of_registers = [register1, register2, register3] |
919 |
| - |
920 |
| - # Instantiate Transaction object |
921 |
| - data_from_device = Transaction(list_of_registers) |
922 |
| - |
923 |
| - # Retrieve data |
924 |
| - data = data_from_device.__get__() |
925 |
| - |
926 |
| - # Use data as desired |
927 |
| - datapoint_1 = data_from_device[0] |
928 |
| - datapoint_2 = data_from_device[1] |
929 |
| - datapoint_3 = data_from_device[2] |
930 |
| - """ |
931 |
| - |
932 |
| - |
933 |
| - def __init__(self, read_or_write:bool = True, list_of_registers:list() =[]): |
934 |
| - # Data |
935 |
| - self.__list_of_registers = list_of_registers |
936 |
| - |
937 |
| - # Check if it is a list |
938 |
| - if self.__list_of_registers.__class__() == list(): |
939 |
| - |
940 |
| - for reg in self.__list_of_registers: |
941 |
| - # Check each element against all possible Register types |
942 |
| - if self.__list_of_registers[reg].__class__() in [RORegBit, RORegBits, RWRegBit, RWRegBits, RORegStruct]: |
943 |
| - pass |
944 |
| - |
945 |
| - else: |
946 |
| - # Error - list_element[reg] not a register object |
947 |
| - pass |
948 |
| - |
949 |
| - else: |
950 |
| - # Error - list_of_registers object must be list() |
951 |
| - pass |
952 |
| - |
953 |
| - def add_reg(self, reg_object): |
954 |
| - """ |
955 |
| - This function allows for register objects to be added to an already |
956 |
| - instantiated Transaction object |
957 |
| - """ |
958 |
| - if reg_object.__class__() in [RORegBit, RORegBits, RWRegBit, RWRegBits, RORegStruct]: |
959 |
| - self.__list_of_registers.append(reg_object) |
960 |
| - |
961 |
| - self._order_list() |
962 |
| - |
963 |
| - else: |
964 |
| - # Error - reg object of incorrect type() |
965 |
| - pass |
966 |
| - |
967 |
| - def rem_reg(self, index): |
968 |
| - """ |
969 |
| - This function allows for a register object to be removed from an |
970 |
| - already instantiated transaction object |
971 |
| - """ |
972 |
| - if index in range(0, len(self.__list_of_registers)): |
973 |
| - # Remove element |
974 |
| - self.__list_of_registers.remove(index) |
975 |
| - else: |
976 |
| - # Error - index out of bounds |
977 |
| - pass |
978 |
| - |
979 |
| - def order_list(self): |
980 |
| - """ |
981 |
| - Sorts list of registers by register address |
982 |
| - """ |
983 |
| - self.__list_of_registers = sorted(self.__list_of_registers, key=lambda reg:reg.reg_addr) |
984 |
| - |
985 |
| - def data(self): |
986 |
| - """ |
987 |
| - Performs 1 i2c transaction and returns data as list |
988 |
| - """ |
989 |
| - |
990 |
| - |
991 |
| - |
992 |
| - |
993 |
| - |
994 |
| - |
995 |
| - |
996 |
| - |
997 |
| - |
998 |
| - |
999 |
| - |
0 commit comments