1# SPDX-FileCopyrightText: 2014-2022 Fredrik Ahlberg, Angus Gratton,
2# Espressif Systems (Shanghai) CO LTD, other contributors as noted.
3#
4# SPDX-License-Identifier: GPL-2.0-or-later
5
6from .esp32h2beta1 import ESP32H2BETA1ROM
7
8
9class ESP32H2BETA2ROM(ESP32H2BETA1ROM):
10    CHIP_NAME = "ESP32-H2(beta2)"
11    IMAGE_CHIP_ID = 14
12
13    CHIP_DETECT_MAGIC_VALUE = [0x6881B06F]
14
15    def get_chip_description(self):
16        chip_name = {
17            1: "ESP32-H2(beta2)",
18        }.get(self.get_pkg_version(), "unknown ESP32-H2")
19        major_rev = self.get_major_chip_version()
20        minor_rev = self.get_minor_chip_version()
21        return f"{chip_name} (revision v{major_rev}.{minor_rev})"
22
23
24class ESP32H2BETA2StubLoader(ESP32H2BETA2ROM):
25    """Access class for ESP32H2BETA2 stub loader, runs on top of ROM.
26
27    (Basically the same as ESP32StubLoader, but different base class.
28    Can possibly be made into a mixin.)
29    """
30
31    FLASH_WRITE_SIZE = 0x4000  # matches MAX_WRITE_BLOCK in stub_loader.c
32    STATUS_BYTES_LENGTH = 2  # same as ESP8266, different to ESP32 ROM
33    IS_STUB = True
34
35    def __init__(self, rom_loader):
36        self.secure_download_mode = rom_loader.secure_download_mode
37        self._port = rom_loader._port
38        self._trace_enabled = rom_loader._trace_enabled
39        self.cache = rom_loader.cache
40        self.flush_input()  # resets _slip_reader
41
42
43ESP32H2BETA2ROM.STUB_CLASS = ESP32H2BETA2StubLoader
44