Skip to content

Commit c7abdd0

Browse files
committed
intermediate commit
1 parent 2bd6cb5 commit c7abdd0

File tree

5 files changed

+106
-57
lines changed

5 files changed

+106
-57
lines changed

ext_mod/lcd_bus/common_include/spi_bus.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@
6464
void *buf1;
6565
void *buf2;
6666

67+
/* buffer_flags is not used, but it needs to be here
68+
* otherwise function pointers are no more aligned
69+
* with the pointer use in _mp_lcd_bus_obj_t
70+
*/
71+
uint32_t buffer_flags;
72+
6773
bool trans_done;
6874
bool rgb565_byte_swap;
6975

ext_mod/lcd_bus/common_src/i80_bus.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "py/obj.h"
1111
#include "py/runtime.h"
1212
#include "py/objarray.h"
13+
#include "mphalport.h" // for mp_hal_pin_output
1314

1415
//#include "mpconfigport.h"
1516
//#include "modmachine.h"

ext_mod/lcd_bus/common_src/spi_bus.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
// local includes
66
#include "lcd_types.h"
77
#include "modlcd_bus.h"
8-
#include "spi_bus.h"
8+
// compiler doesn't find spi_bus.h without ../common_include/ ??
9+
#include "../common_include/spi_bus.h"
910
#include "../../../micropy_updates/common/mp_spi_common.h"
1011

1112
// micropython includes
@@ -14,6 +15,7 @@
1415
// #else
1516
#include "py/obj.h"
1617
#include "py/runtime.h"
18+
#include "extmod/modmachine.h" // for mp_machine_p_t
1719

1820
// stdlib includes
1921
#include <string.h>
@@ -189,23 +191,26 @@
189191

190192
mp_lcd_spi_bus_obj_t *self = MP_OBJ_TO_PTR(obj);
191193

192-
uint8_t bits;
194+
// uint8_t bits; no more used
193195

194196
if (cmd_bits == 16) {
195197
self->send_cmd = send_cmd_16;
196-
bits = 16;
198+
// bits = 16;
197199
} else {
198200
self->send_cmd = send_cmd_8;
199-
bits = 8;
201+
// bits = 8;
200202
}
201203

202204
if (param_bits == 16) {
203205
self->send_param = send_param_16;
204-
bits = 16;
206+
// bits = 16;
205207
} else {
206208
self->send_param = send_param_8;
207209
}
208210

211+
/* constructor above takes a machine_hw_spi_device as argument
212+
so we should not create another one
213+
209214
mp_obj_base_t *spi;
210215
mp_obj_t spi_args[12];
211216
@@ -228,6 +233,10 @@
228233
229234
self->bus_handle = spi;
230235
self->panel_io_config.spi_transfer = ((mp_machine_spi_p_t *)MP_OBJ_TYPE_GET_SLOT(spi->type, protocol))->transfer;
236+
*/
237+
238+
// we take the transfer pointer from the bus inside the existing device
239+
self->panel_io_config.spi_transfer = ((mp_machine_spi_p_t *)MP_OBJ_TYPE_GET_SLOT(&machine_spi_type, protocol))->transfer;
231240

232241
return LCD_OK;
233242
}

micropy_updates/common/mp_spi_common.h

Lines changed: 83 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -14,55 +14,88 @@
1414
MP_SPI_STATE_SENDING
1515
} mp_machine_hw_spi_state_t;
1616

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;
6720

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*/
68101
#endif /* __MP_SPI_COMMON_H__ */

micropy_updates/rp2/machine_spi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ mp_machine_hw_spi_bus_obj_t rp2_machine_spi_bus_obj[] = {
111111
.miso = MP_OBJ_NULL,
112112
.active_devices = 0,
113113
.state = 0,
114-
.user_data = (const void *)spi0
114+
.user_data = (void *)spi0
115115
},
116116
{
117117
.host = 1,
@@ -120,7 +120,7 @@ mp_machine_hw_spi_bus_obj_t rp2_machine_spi_bus_obj[] = {
120120
.miso = MP_OBJ_NULL,
121121
.active_devices = 0,
122122
.state = 0,
123-
.user_data = (const void *)spi1
123+
.user_data = (void *)spi1
124124
}
125125
};
126126

0 commit comments

Comments
 (0)