|
14 | 14 | MP_SPI_STATE_SENDING |
15 | 15 | } mp_machine_hw_spi_state_t; |
16 | 16 |
|
17 | | - typedef struct _mp_machine_hw_spi_bus_obj_t mp_machine_hw_spi_bus_obj_t; |
18 | | - typedef struct _mp_machine_hw_spi_device_obj_t mp_machine_hw_spi_device_obj_t; |
19 | | - |
20 | | - struct _mp_machine_hw_spi_bus_obj_t { |
21 | | - mp_obj_base_t base; |
22 | | - uint8_t host; |
23 | | - mp_obj_t sck; |
24 | | - mp_obj_t data0; |
25 | | - mp_obj_t data1; |
26 | | - mp_obj_t data2; |
27 | | - mp_obj_t data3; |
28 | | - mp_obj_t data4; |
29 | | - mp_obj_t data5; |
30 | | - mp_obj_t data6; |
31 | | - mp_obj_t data7; |
32 | | - bool dual; |
33 | | - bool quad; |
34 | | - bool octal; |
35 | | - uint8_t device_count; |
36 | | - mp_machine_hw_spi_device_obj_t **devices; |
37 | | - mp_machine_hw_spi_state_t state; |
38 | | - const void *user_data; |
39 | | - void (*deinit)(mp_machine_hw_spi_bus_obj_t *bus); |
40 | | - }; |
41 | | - |
42 | | - struct _mp_machine_hw_spi_device_obj_t { |
43 | | - mp_obj_base_t base; |
44 | | - uint32_t freq; |
45 | | - uint8_t polarity; |
46 | | - uint8_t phase; |
47 | | - uint8_t bits; |
48 | | - uint8_t firstbit; |
49 | | - bool dual; |
50 | | - bool quad; |
51 | | - bool octal; |
52 | | - bool active; |
53 | | - mp_obj_t cs; |
54 | | - mp_machine_hw_spi_bus_obj_t *spi_bus; |
55 | | - void *user_data; |
56 | | - void (*deinit)(mp_machine_hw_spi_device_obj_t *device); |
57 | | - }; |
58 | | - |
59 | | - void mp_machine_hw_spi_bus_initilize(mp_machine_hw_spi_bus_obj_t *bus); |
60 | | - void mp_machine_hw_spi_bus_add_device(mp_machine_hw_spi_device_obj_t *device); |
61 | | - void mp_machine_hw_spi_bus_remove_device(mp_machine_hw_spi_device_obj_t *device); |
62 | | - |
63 | | - extern const mp_obj_type_t mp_machine_hw_spi_device_type; |
64 | | - extern const mp_obj_type_t mp_machine_hw_spi_bus_type; |
65 | | - |
66 | | - void mp_machine_hw_spi_bus_deinit_all(void); |
| 17 | + #ifdef ESP_IDF_VERSION |
| 18 | + typedef struct _mp_machine_hw_spi_bus_obj_t mp_machine_hw_spi_bus_obj_t; |
| 19 | + typedef struct _mp_machine_hw_spi_device_obj_t mp_machine_hw_spi_device_obj_t; |
67 | 20 |
|
| 21 | + struct _mp_machine_hw_spi_bus_obj_t { |
| 22 | + mp_obj_base_t base; |
| 23 | + uint8_t host; |
| 24 | + mp_obj_t sck; |
| 25 | + mp_obj_t data0; |
| 26 | + mp_obj_t data1; |
| 27 | + mp_obj_t data2; |
| 28 | + mp_obj_t data3; |
| 29 | + mp_obj_t data4; |
| 30 | + mp_obj_t data5; |
| 31 | + mp_obj_t data6; |
| 32 | + mp_obj_t data7; |
| 33 | + bool dual; |
| 34 | + bool quad; |
| 35 | + bool octal; |
| 36 | + uint8_t device_count; |
| 37 | + mp_machine_hw_spi_device_obj_t **devices; |
| 38 | + mp_machine_hw_spi_state_t state; |
| 39 | + const void *user_data; |
| 40 | + void (*deinit)(mp_machine_hw_spi_bus_obj_t *bus); |
| 41 | + }; |
| 42 | + |
| 43 | + struct _mp_machine_hw_spi_device_obj_t { |
| 44 | + mp_obj_base_t base; |
| 45 | + uint32_t freq; |
| 46 | + uint8_t polarity; |
| 47 | + uint8_t phase; |
| 48 | + uint8_t bits; |
| 49 | + uint8_t firstbit; |
| 50 | + bool dual; |
| 51 | + bool quad; |
| 52 | + bool octal; |
| 53 | + bool active; |
| 54 | + mp_obj_t cs; |
| 55 | + mp_machine_hw_spi_bus_obj_t *spi_bus; |
| 56 | + void *user_data; |
| 57 | + void (*deinit)(mp_machine_hw_spi_device_obj_t *device); |
| 58 | + }; |
| 59 | + |
| 60 | + void mp_machine_hw_spi_bus_initilize(mp_machine_hw_spi_bus_obj_t *bus); |
| 61 | + void mp_machine_hw_spi_bus_add_device(mp_machine_hw_spi_device_obj_t *device); |
| 62 | + void mp_machine_hw_spi_bus_remove_device(mp_machine_hw_spi_device_obj_t *device); |
| 63 | + |
| 64 | + extern const mp_obj_type_t mp_machine_hw_spi_device_type; |
| 65 | + extern const mp_obj_type_t mp_machine_hw_spi_bus_type; |
| 66 | + |
| 67 | + void mp_machine_hw_spi_bus_deinit_all(void); |
| 68 | + |
| 69 | + #else |
| 70 | + // definitions in line with use in micropy_updates/machine_spi.c |
| 71 | + // |
| 72 | + typedef struct _mp_machine_hw_spi_bus_obj_t { |
| 73 | + uint8_t host; |
| 74 | + mp_obj_t sck; |
| 75 | + mp_obj_t mosi; |
| 76 | + mp_obj_t miso; |
| 77 | + int16_t active_devices; |
| 78 | + mp_machine_hw_spi_state_t state; |
| 79 | + const void *user_data; |
| 80 | + } mp_machine_hw_spi_bus_obj_t; |
| 81 | + |
| 82 | + |
| 83 | + typedef struct _machine_hw_spi_obj_t { |
| 84 | + mp_obj_base_t base; |
| 85 | + uint32_t baudrate; |
| 86 | + uint8_t polarity; |
| 87 | + uint8_t phase; |
| 88 | + uint8_t bits; |
| 89 | + uint8_t firstbit; |
| 90 | + bool active; // added as requested in machine_spi_make_new |
| 91 | + mp_obj_t cs; |
| 92 | + mp_machine_hw_spi_bus_obj_t *spi_bus; |
| 93 | + void *user_data; |
| 94 | + } machine_hw_spi_obj_t; |
| 95 | + |
| 96 | + // typedef added to align naming in spi_bus with naming in machine_spi |
| 97 | + typedef struct _machine_hw_spi_obj_t machine_hw_spi_device_obj_t; |
| 98 | + |
| 99 | + |
| 100 | + #endif /* ESP_IDF_VERSION*/ |
68 | 101 | #endif /* __MP_SPI_COMMON_H__ */ |
0 commit comments