|
34 | 34 |
|
35 | 35 | #include "lib/utils/buffer_helper.h"
|
36 | 36 | #include "lib/utils/context_manager_helpers.h"
|
| 37 | +#include "py/objproperty.h" |
37 | 38 | #include "py/runtime.h"
|
38 | 39 | #include "supervisor/shared/translate.h"
|
39 | 40 |
|
@@ -100,22 +101,51 @@ STATIC mp_obj_t adafruit_bus_device_spidevice_make_new(const mp_obj_type_t *type
|
100 | 101 | return (mp_obj_t)self;
|
101 | 102 | }
|
102 | 103 |
|
| 104 | +//| def __enter__(self) -> busio.SPI: |
| 105 | +//| """Starts a SPI transaction by configuring the SPI and asserting chip select.""" |
| 106 | +//| ... |
| 107 | +//| |
103 | 108 | STATIC mp_obj_t adafruit_bus_device_spidevice_obj___enter__(mp_obj_t self_in) {
|
104 | 109 | adafruit_bus_device_spidevice_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
105 |
| - common_hal_adafruit_bus_device_spidevice_enter(self); |
106 |
| - return self->spi; |
| 110 | + return common_hal_adafruit_bus_device_spidevice_enter(self); |
107 | 111 | }
|
108 | 112 | STATIC MP_DEFINE_CONST_FUN_OBJ_1(adafruit_bus_device_spidevice___enter___obj, adafruit_bus_device_spidevice_obj___enter__);
|
109 | 113 |
|
| 114 | + |
| 115 | +//| def __exit__(self) -> None: |
| 116 | +//| """Ends a SPI transaction by deasserting chip select. See |
| 117 | +//| :ref:`lifetime-and-contextmanagers` for more info.""" |
| 118 | +//| ... |
| 119 | +//| |
110 | 120 | STATIC mp_obj_t adafruit_bus_device_spidevice_obj___exit__(size_t n_args, const mp_obj_t *args) {
|
111 | 121 | common_hal_adafruit_bus_device_spidevice_exit(MP_OBJ_TO_PTR(args[0]));
|
112 | 122 | return mp_const_none;
|
113 | 123 | }
|
114 | 124 | STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(adafruit_bus_device_spidevice___exit___obj, 4, 4, adafruit_bus_device_spidevice_obj___exit__);
|
115 | 125 |
|
| 126 | +//| spi: busio.SPI |
| 127 | +//| """The underlying SPI bus. Useful for weird uses like clocking an SD card without chip select. |
| 128 | +//| |
| 129 | +//| You shouldn't normally need this.""" |
| 130 | +//| |
| 131 | +STATIC mp_obj_t adafruit_bus_device_spidevice_obj_get_spi(mp_obj_t self_in) { |
| 132 | + adafruit_bus_device_spidevice_obj_t *self = MP_OBJ_TO_PTR(self_in); |
| 133 | + return common_hal_adafruit_bus_device_spidevice_get_spi(self); |
| 134 | +} |
| 135 | +MP_DEFINE_CONST_FUN_OBJ_1(adafruit_bus_device_spidevice_get_spi_obj, adafruit_bus_device_spidevice_obj_get_spi); |
| 136 | + |
| 137 | +const mp_obj_property_t adafruit_bus_device_spidevice_spi_obj = { |
| 138 | + .base.type = &mp_type_property, |
| 139 | + .proxy = {(mp_obj_t)&adafruit_bus_device_spidevice_get_spi_obj, |
| 140 | + (mp_obj_t)&mp_const_none_obj, |
| 141 | + (mp_obj_t)&mp_const_none_obj}, |
| 142 | +}; |
| 143 | + |
116 | 144 | STATIC const mp_rom_map_elem_t adafruit_bus_device_spidevice_locals_dict_table[] = {
|
117 | 145 | { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&adafruit_bus_device_spidevice___enter___obj) },
|
118 | 146 | { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&adafruit_bus_device_spidevice___exit___obj) },
|
| 147 | + |
| 148 | + { MP_ROM_QSTR(MP_QSTR_spi), MP_ROM_PTR(&adafruit_bus_device_spidevice_spi_obj) }, |
119 | 149 | };
|
120 | 150 |
|
121 | 151 | STATIC MP_DEFINE_CONST_DICT(adafruit_bus_device_spidevice_locals_dict, adafruit_bus_device_spidevice_locals_dict_table);
|
|
0 commit comments