|
1 | 1 | /* |
2 | | - * This file is part of the Micro Python project, http://micropython.org/ |
| 2 | + * This file is part of the MicroPython project, http://micropython.org/ |
3 | 3 | * |
4 | 4 | * The MIT License (MIT) |
5 | 5 | * |
6 | | - * Copyright (c) 2020 Sean Cross for Adafruit Industries |
| 6 | + * Copyright (c) 2023 MicroDev |
7 | 7 | * |
8 | 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
9 | 9 | * of this software and associated documentation files (the "Software"), to deal |
|
24 | 24 | * THE SOFTWARE. |
25 | 25 | */ |
26 | 26 |
|
| 27 | +#include "py/enum.h" |
| 28 | + |
27 | 29 | #include "shared-bindings/watchdog/WatchDogMode.h" |
28 | 30 |
|
| 31 | +MAKE_ENUM_VALUE(watchdog_watchdogmode_type, watchdogmode, NONE, WATCHDOGMODE_NONE); |
| 32 | +MAKE_ENUM_VALUE(watchdog_watchdogmode_type, watchdogmode, RAISE, WATCHDOGMODE_RAISE); |
| 33 | +MAKE_ENUM_VALUE(watchdog_watchdogmode_type, watchdogmode, RESET, WATCHDOGMODE_RESET); |
| 34 | + |
29 | 35 | //| class WatchDogMode: |
30 | | -//| """run state of the watchdog timer""" |
31 | | -//| |
32 | | -//| def __init__(self) -> None: |
33 | | -//| """Enum-like class to define the run mode of the watchdog timer.""" |
34 | | -//| RAISE: WatchDogMode |
35 | | -//| """Raise an exception when the WatchDogTimer expires. |
| 36 | +//| """Run state of the watchdog timer.""" |
36 | 37 | //| |
37 | | -//| **Limitations:** ``RAISE`` mode is not supported on SAMD or RP2040. |
| 38 | +//| NONE: WatchDogMode |
| 39 | +//| """The `WatchDogTimer` is disabled.""" |
38 | 40 | //| |
39 | | -//| :type WatchDogMode:""" |
| 41 | +//| RAISE: WatchDogMode |
| 42 | +//| """Raise an exception when the `WatchDogTimer` expires.""" |
40 | 43 | //| |
41 | 44 | //| RESET: WatchDogMode |
42 | | -//| """Reset the system if the WatchDogTimer expires. |
43 | | -//| |
44 | | -//| :type WatchDogMode:""" |
| 45 | +//| """Reset the system when the `WatchDogTimer` expires.""" |
45 | 46 | //| |
46 | | -const mp_obj_type_t watchdog_watchdogmode_type; |
47 | | - |
48 | | -const watchdog_watchdogmode_obj_t watchdog_watchdogmode_raise_obj = { |
49 | | - { &watchdog_watchdogmode_type }, |
| 47 | +MAKE_ENUM_MAP(watchdog_watchdogmode) { |
| 48 | + MAKE_ENUM_MAP_ENTRY(watchdogmode, NONE), |
| 49 | + MAKE_ENUM_MAP_ENTRY(watchdogmode, RAISE), |
| 50 | + MAKE_ENUM_MAP_ENTRY(watchdogmode, RESET), |
50 | 51 | }; |
| 52 | +STATIC MP_DEFINE_CONST_DICT(watchdog_watchdogmode_locals_dict, watchdog_watchdogmode_locals_table); |
51 | 53 |
|
52 | | -const watchdog_watchdogmode_obj_t watchdog_watchdogmode_reset_obj = { |
53 | | - { &watchdog_watchdogmode_type }, |
54 | | -}; |
55 | | - |
56 | | -watchdog_watchdogmode_t watchdog_watchdogmode_obj_to_type(mp_obj_t obj) { |
57 | | - if (obj == MP_ROM_PTR(&watchdog_watchdogmode_raise_obj)) { |
58 | | - return WATCHDOGMODE_RAISE; |
59 | | - } else if (obj == MP_ROM_PTR(&watchdog_watchdogmode_reset_obj)) { |
60 | | - return WATCHDOGMODE_RESET; |
61 | | - } |
62 | | - return WATCHDOGMODE_NONE; |
63 | | -} |
| 54 | +MAKE_PRINTER(watchdog, watchdog_watchdogmode); |
64 | 55 |
|
65 | | -mp_obj_t watchdog_watchdogmode_type_to_obj(watchdog_watchdogmode_t mode) { |
66 | | - switch (mode) { |
67 | | - case WATCHDOGMODE_RAISE: |
68 | | - return (mp_obj_t)MP_ROM_PTR(&watchdog_watchdogmode_raise_obj); |
69 | | - case WATCHDOGMODE_RESET: |
70 | | - return (mp_obj_t)MP_ROM_PTR(&watchdog_watchdogmode_reset_obj); |
71 | | - case WATCHDOGMODE_NONE: |
72 | | - default: |
73 | | - return MP_ROM_NONE; |
74 | | - } |
75 | | -} |
76 | | - |
77 | | -STATIC const mp_rom_map_elem_t watchdog_watchdogmode_locals_dict_table[] = { |
78 | | - {MP_ROM_QSTR(MP_QSTR_RAISE), MP_ROM_PTR(&watchdog_watchdogmode_raise_obj)}, |
79 | | - {MP_ROM_QSTR(MP_QSTR_RESET), MP_ROM_PTR(&watchdog_watchdogmode_reset_obj)}, |
80 | | -}; |
81 | | -STATIC MP_DEFINE_CONST_DICT(watchdog_watchdogmode_locals_dict, watchdog_watchdogmode_locals_dict_table); |
82 | | - |
83 | | -STATIC void watchdog_watchdogmode_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { |
84 | | - qstr runmode = MP_QSTR_None; |
85 | | - if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&watchdog_watchdogmode_raise_obj)) { |
86 | | - runmode = MP_QSTR_RAISE; |
87 | | - } else if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&watchdog_watchdogmode_reset_obj)) { |
88 | | - runmode = MP_QSTR_RESET; |
89 | | - } |
90 | | - mp_printf(print, "%q.%q.%q", MP_QSTR_watchdog, MP_QSTR_WatchDogMode, |
91 | | - runmode); |
92 | | -} |
93 | | - |
94 | | -const mp_obj_type_t watchdog_watchdogmode_type = { |
95 | | - { &mp_type_type }, |
96 | | - .name = MP_QSTR_WatchDogMode, |
97 | | - .print = watchdog_watchdogmode_print, |
98 | | - .locals_dict = (mp_obj_t)&watchdog_watchdogmode_locals_dict, |
99 | | -}; |
| 56 | +MAKE_ENUM_TYPE(watchdog, WatchDogMode, watchdog_watchdogmode); |
0 commit comments