|
7 | 7 | class ESP_SPIcontrol:
|
8 | 8 | GET_CONN_STATUS_CMD = const(0x20)
|
9 | 9 | GET_FW_VERSION_CMD = const(0x37)
|
| 10 | + GET_MACADDR_CMD = const(0x22) |
10 | 11 | START_CMD = const(0xE0)
|
11 | 12 | END_CMD = const(0xEE)
|
12 | 13 | ERR_CMD = const(0xEF)
|
@@ -72,18 +73,23 @@ def wait_for_slave_select(self):
|
72 | 73 |
|
73 | 74 |
|
74 | 75 | def send_command(self, cmd, params=None):
|
75 |
| - num_params = 0 # default to no params |
76 |
| - if params: |
77 |
| - num_params = len(params) |
78 |
| - packet = bytearray(4+num_params) |
79 |
| - packet[0] = START_CMD |
80 |
| - packet[1] = cmd & ~REPLY_FLAG |
81 |
| - packet[2] = num_params |
| 76 | + if not params: |
| 77 | + params = [] |
| 78 | + packet = [] |
| 79 | + packet.append(START_CMD) |
| 80 | + packet.append(cmd & ~REPLY_FLAG) |
| 81 | + packet.append(len(params)) |
82 | 82 |
|
83 | 83 | # handle parameters here
|
84 |
| - |
85 |
| - packet[3] = END_CMD |
86 |
| - self._spi.write(packet) |
| 84 | + for param in params: |
| 85 | + packet.append(len(param)) |
| 86 | + packet += (param) |
| 87 | + |
| 88 | + packet.append(END_CMD) |
| 89 | + print("packet len:", len(packet)) |
| 90 | + while len(packet) % 4 != 0: |
| 91 | + packet.append(0xFF) |
| 92 | + self._spi.write(bytearray(packet)) |
87 | 93 | print("Wrote: ", [hex(b) for b in packet])
|
88 | 94 |
|
89 | 95 | def get_param(self):
|
@@ -146,3 +152,15 @@ def get_firmware_version(self):
|
146 | 152 | resp = self.wait_response_cmd(GET_FW_VERSION_CMD, 1)
|
147 | 153 | self.slave_deselect()
|
148 | 154 | return ''.join([chr(c) for c in resp[0]])
|
| 155 | + |
| 156 | + def get_MAC(self): |
| 157 | + print("MAC address") |
| 158 | + self.wait_for_slave_select() |
| 159 | + self.send_command(GET_MACADDR_CMD, [[0xFF]]) |
| 160 | + self.slave_deselect() |
| 161 | + |
| 162 | + self.wait_for_slave_ready() |
| 163 | + self.spi_slave_select() |
| 164 | + resp = self.wait_response_cmd(GET_MACADDR_CMD, 1) |
| 165 | + self.slave_deselect() |
| 166 | + return resp[0] |
0 commit comments