|  | 
| 43 | 43 |  b"\xe4\xd2\xc0\x1c\x0e8*TFpb\x8c\x9e\xa8\xba\xc4\xd6\xe0\xf2" | 
| 44 | 44 | ) | 
| 45 | 45 | 
 | 
| 46 |  | -# ruff: noqa: F821 - @asm_thumb and @viper decorator adds names to function scope | 
| 47 |  | -try: | 
| 48 |  | - from uctypes import addressof | 
| 49 |  | - | 
| 50 |  | - @micropython.viper | 
| 51 |  | - def crc7(buf) -> int: | 
| 52 |  | - n = int(len(buf)) | 
| 53 |  | - table = ptr8(addressof(crc7_be_syndrome_table)) | 
| 54 |  | - bp = ptr8(addressof(buf)) | 
| 55 |  | - idx = 0 | 
| 56 |  | - crc = 0 | 
| 57 |  | - while idx < n: | 
| 58 |  | - crc = table[crc ^ bp[idx]] | 
| 59 |  | - idx = idx + 1 | 
| 60 |  | - return crc | 
| 61 |  | - | 
| 62 |  | - # test to make sure this works! | 
| 63 |  | - # print(f"{crc7('abcde'):02x}") | 
| 64 |  | - assert crc7(b"abcde") == 0x34 | 
| 65 |  | -except: | 
| 66 |  | - # non-viper version if viper can'r be built | 
| 67 |  | - def crc7(buf) -> int: | 
| 68 |  | - crc = 0 | 
| 69 |  | - for b in buf: | 
| 70 |  | - crc = crc7_be_syndrome_table[crc ^ b] | 
| 71 |  | - return crc | 
| 72 |  | - | 
|  | 46 | +def crc7(buf) -> int: | 
|  | 47 | + crc = 0 | 
|  | 48 | + for b in buf: | 
|  | 49 | + crc = crc7_be_syndrome_table[crc ^ b] | 
|  | 50 | + return crc | 
| 73 | 51 | 
 | 
| 74 | 52 | def gb(bigval, b0, bn): | 
| 75 | 53 |  # get numbered bits from a buf_to_int from, for example, the CSD | 
|  | 
0 commit comments