|
24 | 24 | * THE SOFTWARE. |
25 | 25 | */ |
26 | 26 |
|
27 | | -#include "py/obj.h" |
28 | | - |
29 | | -#include "shared-bindings/canio/__init__.h" |
30 | | - |
31 | | -#include "shared-bindings/canio/BusState.h" |
32 | | -#include "shared-bindings/canio/CAN.h" |
33 | | -#include "shared-bindings/canio/Match.h" |
34 | | -#include "shared-bindings/canio/Message.h" |
35 | | -#include "shared-bindings/canio/Listener.h" |
36 | | - |
37 | 27 | //| """CAN bus access |
38 | 28 | //| |
39 | 29 | //| The `canio` module contains low level classes to support the CAN bus |
|
67 | 57 | //| """ |
68 | 58 | //| |
69 | 59 |
|
| 60 | +#include "py/obj.h" |
| 61 | +#include "py/enum.h" |
| 62 | + |
| 63 | +#include "shared-bindings/canio/__init__.h" |
| 64 | +#include "shared-bindings/canio/CAN.h" |
| 65 | +#include "shared-bindings/canio/Match.h" |
| 66 | +#include "shared-bindings/canio/Message.h" |
| 67 | +#include "shared-bindings/canio/Listener.h" |
| 68 | + |
| 69 | +MAKE_ENUM_VALUE(canio_bus_state_type, bus_state, ERROR_ACTIVE, BUS_STATE_ERROR_ACTIVE); |
| 70 | +MAKE_ENUM_VALUE(canio_bus_state_type, bus_state, ERROR_PASSIVE, BUS_STATE_ERROR_PASSIVE); |
| 71 | +MAKE_ENUM_VALUE(canio_bus_state_type, bus_state, ERROR_WARNING, BUS_STATE_ERROR_WARNING); |
| 72 | +MAKE_ENUM_VALUE(canio_bus_state_type, bus_state, BUS_OFF, BUS_STATE_OFF); |
| 73 | + |
| 74 | +//| class BusState: |
| 75 | +//| """The state of the CAN bus""" |
| 76 | +//| |
| 77 | +//| ERROR_ACTIVE: object |
| 78 | +//| """The bus is in the normal (active) state""" |
| 79 | +//| |
| 80 | +//| ERROR_WARNING: object |
| 81 | +//| """The bus is in the normal (active) state, but a moderate number of errors have occurred recently. |
| 82 | +//| |
| 83 | +//| NOTE: Not all implementations may use ERROR_WARNING. Do not rely on seeing ERROR_WARNING before ERROR_PASSIVE.""" |
| 84 | +//| |
| 85 | +//| ERROR_PASSIVE: object |
| 86 | +//| """The bus is in the passive state due to the number of errors that have occurred recently. |
| 87 | +//| |
| 88 | +//| This device will acknowledge packets it receives, but cannot transmit messages. |
| 89 | +//| If additional errors occur, this device may progress to BUS_OFF. |
| 90 | +//| If it successfully acknowledges other packets on the bus, it can return to ERROR_WARNING or ERROR_ACTIVE and transmit packets. |
| 91 | +//| """ |
| 92 | +//| |
| 93 | +//| BUS_OFF: object |
| 94 | +//| """The bus has turned off due to the number of errors that have |
| 95 | +//| occurred recently. It must be restarted before it will send or receive |
| 96 | +//| packets. This device will neither send or acknowledge packets on the bus.""" |
| 97 | +//| |
| 98 | +MAKE_ENUM_MAP(canio_bus_state) { |
| 99 | + MAKE_ENUM_MAP_ENTRY(bus_state, ERROR_ACTIVE), |
| 100 | + MAKE_ENUM_MAP_ENTRY(bus_state, ERROR_PASSIVE), |
| 101 | + MAKE_ENUM_MAP_ENTRY(bus_state, ERROR_WARNING), |
| 102 | + MAKE_ENUM_MAP_ENTRY(bus_state, BUS_OFF), |
| 103 | +}; |
| 104 | +STATIC MP_DEFINE_CONST_DICT(canio_bus_state_locals_dict, canio_bus_state_locals_table); |
| 105 | + |
| 106 | +MAKE_PRINTER(canio, canio_bus_state); |
| 107 | + |
| 108 | +MAKE_ENUM_TYPE(canio, BusState, canio_bus_state); |
| 109 | + |
70 | 110 | STATIC const mp_rom_map_elem_t canio_module_globals_table[] = { |
71 | 111 | { MP_ROM_QSTR(MP_QSTR_BusState), MP_ROM_PTR(&canio_bus_state_type) }, |
72 | 112 | { MP_ROM_QSTR(MP_QSTR_CAN), MP_ROM_PTR(&canio_can_type) }, |
|
0 commit comments