Skip to content

Commit b93935b

Browse files
committed
working on the global rotate
1 parent aa82540 commit b93935b

File tree

14 files changed

+317
-154
lines changed

14 files changed

+317
-154
lines changed

ext_mod/lcd_bus/include/common/sw_rotate_task_common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
void mp_lcd_event_wait(mp_lcd_event_t *event);
1919

2020
/* lock */
21-
bool mp_lcd_lock_acquire(mp_lcd_lock_t *lock);
21+
void mp_lcd_lock_acquire(mp_lcd_lock_t *lock);
2222
void mp_lcd_lock_release(mp_lcd_lock_t *lock);
2323
void mp_lcd_lock_init(mp_lcd_lock_t *lock);
2424
void mp_lcd_lock_delete(mp_lcd_lock_t *lock);

ext_mod/lcd_bus/include/posix/i2c_bus.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
// Copyright (c) 2024 - 2025 Kevin G. Schlosser
22

3+
#include "py/obj.h"
4+
35
#ifndef _I2C_BUS_H_
46
#define _I2C_BUS_H_
57

6-
//local_includes
8+
#include "common/lcd_common_types.h"
79
#include "common/modlcd_bus.h"
8-
#include "common/lcd_framebuf.h"
9-
#include "common/sw_rotate.h"
10-
11-
// micropython includes
12-
#include "py/obj.h"
13-
#include "py/runtime.h"
10+
#include "lcd_types.h"
1411

1512

1613
struct _mp_lcd_i2c_bus_obj_t {

ext_mod/lcd_bus/include/posix/i80_bus.h

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
// Copyright (c) 2024 - 2025 Kevin G. Schlosser
22

3+
#include "py/obj.h"
4+
5+
36
#ifndef _I80_BUS_H_
47
#define _I80_BUS_H_
58

6-
//local_includes
9+
#include "common/lcd_common_types.h"
710
#include "common/modlcd_bus.h"
8-
#include "common/lcd_framebuf.h"
9-
#include "common/sw_rotate.h"
10-
11-
#include "mphalport.h"
12-
13-
// micropython includes
14-
#include "py/obj.h"
15-
#include "py/objarray.h"
16-
#include "py/runtime.h"
17-
11+
#include "lcd_types.h"
1812

1913
struct _mp_lcd_i80_bus_obj_t {
2014
struct _mp_lcd_bus_obj_t;

ext_mod/lcd_bus/include/posix/rgb_bus.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
// Copyright (c) 2024 - 2025 Kevin G. Schlosser
22

3+
#include "py/obj.h"
4+
5+
36
#ifndef _RGB_BUS_H_
47
#define _RGB_BUS_H_
58

6-
//local_includes
9+
#include "common/lcd_common_types.h"
710
#include "common/modlcd_bus.h"
8-
#include "common/lcd_framebuf.h"
9-
#include "common/sw_rotate.h"
10-
11-
// micropython includes
12-
#include "py/obj.h"
13-
#include "py/runtime.h"
11+
#include "lcd_types.h"
1412

1513

1614
struct _mp_lcd_rgb_bus_obj_t {

ext_mod/lcd_bus/include/posix/spi_bus.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// Copyright (c) 2024 - 2025 Kevin G. Schlosser
22

3+
#include "py/obj.h"
4+
5+
36
#ifndef _SPI_BUS_H_
47
#define _SPI_BUS_H_
58

6-
//local_includes
79
#include "common/lcd_common_types.h"
810
#include "common/modlcd_bus.h"
9-
10-
#include "py/obj.h"
11-
11+
#include "lcd_types.h"
1212

1313
struct _mp_lcd_spi_bus_obj_t {
1414
struct _mp_lcd_bus_obj_t;
Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,59 @@
1+
2+
#include <pthread.h>
3+
14
#ifndef __SW_ROTATE_TASK_H__
25
#define __SW_ROTATE_TASK_H__
36

4-
#define mp_lcd_task_handle_t TaskHandle_t
7+
#define mp_lcd_task_handle_t pthread_t
58

6-
typedef struct _mp_lcd_lock_t {
7-
SemaphoreHandle_t handle;
8-
StaticSemaphore_t buffer;
9-
} mp_lcd_lock_t;
9+
struct _mp_lcd_lock_t {
10+
pthread_mutex_t handle;
11+
pthread_mutexattr_t attr;
12+
};
13+
14+
struct _mp_lcd_event_t {
15+
pthread_cond_t handle;
16+
mp_lcd_lock_t event_lock;
17+
uint8_t state;
18+
pthread_condattr_t attr;
19+
};
20+
21+
#endif /* __SW_ROTATE_TASK_H__ */
22+
23+
24+
pthread_atfork(3),
25+
26+
27+
pthread_cleanup_push(3),
28+
29+
pthread_cond_signal(3),
30+
pthread_cond_wait(3),
31+
32+
pthread_attr_init(3),
33+
pthread_cancel(3),
34+
pthread_create(3),
35+
pthread_detach(3),
36+
pthread_equal(3),
37+
pthread_exit(3),
38+
pthread_key_create(3),
39+
pthread_kill(3),
40+
41+
42+
pthread_mutex_lock(3),
43+
pthread_mutex_unlock(3),
44+
pthread_mutexattr_destroy(3),
45+
pthread_mutexattr_init(3),
46+
47+
pthread_once(3),
48+
49+
pthread_rwlockattr_setkind_np(3),
50+
pthread_setcancelstate(3),
51+
pthread_setcanceltype(3),
52+
pthread_setspecific(3),
53+
pthread_sigmask(3),
54+
pthread_sigqueue(3),
55+
pthread_testcancel(3)
1056

11-
typedef struct _mp_lcd_event_t {
12-
EventGroupHandle_t handle;
13-
StaticEventGroup_t buffer;
14-
} mp_lcd_event_t;
1557

16-
#endif /* __SW_ROTATE_TASK_H__ */
58+
pthread_spin_init(3),
59+
pthread_spin_lock(3),

ext_mod/lcd_bus/src/esp32/i2c_bus.c

Lines changed: 82 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,93 @@
11
// Copyright (c) 2024 - 2025 Kevin G. Schlosser
22

3-
// local includes
4-
#include "common/lcd_types.h"
5-
#include "common/modlcd_bus.h"
6-
#include "esp32/i2c_bus.h"
7-
8-
// esp-idf includes
9-
#include "esp_lcd_panel_io.h"
10-
#include "driver/i2c.h"
11-
12-
// micropython includes
13-
#include "mphalport.h"
143
#include "py/obj.h"
154
#include "py/runtime.h"
165

17-
// stdlib includes
18-
#include <string.h>
6+
#include "esp_lcd_panel_io.h"
7+
#include "driver/i2c.h"
198

209

10+
#include "common/lcd_commmon_types.h"
11+
#include "common/modlcd_bus.h"
12+
#include "lcd_types.h"
13+
#include "i2c_bus.h"
2114

2215
mp_lcd_err_t i2c_del(mp_obj_t obj);
2316
mp_lcd_err_t i2c_init(mp_obj_t obj, uint16_t width, uint16_t height, uint8_t bpp, uint32_t buffer_size, bool rgb565_byte_swap, uint8_t cmd_bits, uint8_t param_bits);
24-
mp_lcd_err_t i2c_get_lane_count(mp_obj_t obj, uint8_t *lane_count);
2517

2618

27-
static uint8_t i2c_bus_count = 0;
28-
static mp_lcd_i2c_bus_obj_t **i2c_bus_objs;
19+
static bool i2c_trans_done_cb(esp_lcd_panel_handle_t panel,
20+
const esp_lcd_rgb_panel_event_data_t *edata, void *user_ctx)
21+
{
22+
mp_lcd_i2c_bus_obj_t *self = (mp_lcd_i2c_bus_obj_t *)user_ctx;
23+
24+
if (self->trans_done == 0) {
25+
if (self->callback != mp_const_none && mp_obj_is_callable(self->callback)) {
26+
mp_lcd_flush_ready_cb(self->callback);
27+
}
28+
self->trans_done = 1;
29+
}
30+
31+
return false;
32+
}
2933

3034

31-
void mp_lcd_i2c_bus_deinit_all(void)
35+
static void i2c_tx_param_cb(void* self_in, int cmd, uint8_t *params, size_t params_len)
36+
{
37+
esp_lcd_panel_io_tx_param(self->panel_io_handle.panel_io, cmd, params, params_len);
38+
}
39+
40+
41+
static bool i2c_init_cb(void *self_in)
3242
{
33-
// we need to copy the existing array to a new one so the order doesn't
34-
// get all mucked up when objects get removed.
35-
mp_lcd_i2c_bus_obj_t *objs[i2c_bus_count];
43+
mp_lcd_i2c_bus_obj_t *self = (mp_lcd_i2c_bus_obj_t *)self_in;
44+
mp_lcd_sw_rotation_init_t *init = &self->sw_rot.init;
45+
46+
init->err = i2c_param_config(self->host, self->bus_config);
47+
if (init->err != LCD_OK) {
48+
init->err_msg = MP_ERROR_TEXT("%d(i2c_param_config)");
49+
return false;
50+
}
3651

37-
for (uint8_t i=0;i<i2c_bus_count;i++) {
38-
objs[i] = i2c_bus_objs[i];
52+
init->err = i2c_driver_install(self->host, I2C_MODE_MASTER, 0, 0, 0);
53+
54+
if (init->err != LCD_OK) {
55+
init->err_msg = MP_ERROR_TEXT("%d(i2c_driver_install)");
56+
return false;
3957
}
4058

41-
for (uint8_t i=0;i<i2c_bus_count;i++) {
42-
i2c_del(MP_OBJ_FROM_PTR(objs[i]));
59+
init->err = esp_lcd_new_panel_io_i2c(self->bus_handle , self->panel_io_config, &self->panel_io_handle.panel_io);
60+
61+
if (init->err != LCD_OK) {
62+
init->err_msg = MP_ERROR_TEXT("%d(esp_lcd_new_panel_io_i2c)");
63+
return false;
64+
}
65+
66+
free(self->panel_io_config);
67+
free(self->bus_config);
68+
self->panel_io_config = NULL;
69+
self->bus_config = NULL;
70+
71+
return true;
72+
}
73+
74+
75+
static void i2c_flush_cb(void *self_in, uint8_t last_update, int cmd, uint8_t *idle_fb)
76+
{
77+
LCD_UNUSED(last_update);
78+
mp_lcd_i2c_bus_obj_t *self = (mp_lcd_i2c_bus_obj_t *)self_in;
79+
mp_lcd_sw_rotation_buffers_t *buffers = &self->sw_rot.buffers;
80+
81+
82+
if (idle_fb == buffers->idle) {
83+
buffers->idle = buffers->active;
84+
buffers->active = idle_fb;
85+
}
86+
87+
mp_lcd_err_t ret = esp_lcd_panel_io_tx_color(self->panel_io_handle.panel_io, cmd, idle_fb, self->fb1->len);
88+
89+
if (ret != LCD_OK) {
90+
mp_printf(&mp_plat_print, "esp_lcd_panel_draw_bitmap error (%d)\n", ret);
4391
}
4492
}
4593

@@ -120,7 +168,6 @@ static mp_obj_t mp_lcd_i2c_bus_make_new(const mp_obj_type_t *type, size_t n_args
120168

121169
self->panel_io_handle.del = &i2c_del;
122170
self->panel_io_handle.init = &i2c_init;
123-
self->panel_io_handle.get_lane_count = &i2c_get_lane_count;
124171

125172
return MP_OBJ_FROM_PTR(self);
126173
}
@@ -146,86 +193,30 @@ mp_lcd_err_t i2c_del(mp_obj_t obj)
146193

147194
self->panel_io_handle.panel_io = NULL;
148195

149-
if (self->view1 != NULL) {
150-
heap_caps_free(self->view1->items);
151-
self->view1->items = NULL;
152-
self->view1->len = 0;
153-
self->view1 = NULL;
154-
LCD_DEBUG_PRINT("i2c_free_framebuffer(self, buf=1)\n")
155-
}
156-
157-
if (self->view2 != NULL) {
158-
heap_caps_free(self->view2->items);
159-
self->view2->items = NULL;
160-
self->view2->len = 0;
161-
self->view2 = NULL;
162-
LCD_DEBUG_PRINT("i2c_free_framebuffer(self, buf=1)\n")
163-
}
164-
165-
uint8_t i= 0;
166-
for (;i<i2c_bus_count;i++) {
167-
if (i2c_bus_objs[i] == self) {
168-
i2c_bus_objs[i] = NULL;
169-
break;
170-
}
171-
}
172-
173-
for (uint8_t j=i + 1;j<i2c_bus_count;j++) {
174-
i2c_bus_objs[j - i + 1] = i2c_bus_objs[j];
175-
}
176-
177-
i2c_bus_count--;
178-
i2c_bus_objs = m_realloc(i2c_bus_objs, i2c_bus_count * sizeof(mp_lcd_i2c_bus_obj_t *));
179-
180196
return ret;
181197
} else {
182198
return LCD_FAIL;
183199
}
184200
}
185201

186202

187-
mp_lcd_err_t i2c_init(mp_obj_t obj, uint16_t width, uint16_t height, uint8_t bpp, uint32_t buffer_size, bool rgb565_byte_swap, uint8_t cmd_bits, uint8_t param_bits)
203+
mp_lcd_err_t i2c_init(mp_obj_t obj, uint8_t cmd_bits, uint8_t param_bits)
188204
{
189205
mp_lcd_i2c_bus_obj_t *self = (mp_lcd_i2c_bus_obj_t *)obj;
190206

191-
if (bpp == 16) {
192-
self->rgb565_byte_swap = rgb565_byte_swap;
193-
} else {
207+
if (self->sw_rot.data.bytes_per_pixel == 2) {
194208
self->rgb565_byte_swap = false;
195-
}
196-
209+
197210
self->panel_io_config->lcd_cmd_bits = (int)cmd_bits;
198211
self->panel_io_config->lcd_param_bits = (int)param_bits;
212+
213+
self->sw_rot.data.dst_width = 0;
214+
self->sw_rot.data.dst_height = 0;
215+
self->sw_rot.init.cb = &i2c_init_cb;
216+
self->sw_rot.flush_cb = &i2c_flush_cb;
217+
self->sw_rot.tx_params.cb = &i2c_tx_param_cb;
199218

200-
mp_lcd_err_t ret = i2c_param_config(self->host, self->bus_config);
201-
if (ret != 0) {
202-
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("%d(i2c_param_config)"), ret);
203-
return ret;
204-
}
205-
206-
ret = i2c_driver_install(self->host, I2C_MODE_MASTER, 0, 0, 0);
207-
if (ret != 0) {
208-
mp_raise_msg_varg(&mp_type_OSError, MP_ERROR_TEXT("%d(i2c_driver_install)"), ret);
209-
return ret;
210-
}
211-
212-
ret = esp_lcd_new_panel_io_i2c(self->bus_handle , self->panel_io_config, &self->panel_io_handle.panel_io);
213-
214-
if (ret != 0) {
215-
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("%d(esp_lcd_new_panel_io_i2c)"), ret);
216-
return ret;
217-
}
218-
219-
// add the new bus ONLY after successfull initilization of the bus
220-
i2c_bus_count++;
221-
i2c_bus_objs = m_realloc(i2c_bus_objs, i2c_bus_count * sizeof(mp_lcd_i2c_bus_obj_t *));
222-
i2c_bus_objs[i2c_bus_count - 1] = self;
223-
224-
free(self->panel_io_config);
225-
free(self->bus_config);
226-
self->panel_io_config = NULL;
227-
self->bus_config = NULL;
228-
return ret;
219+
return LCD_OK;
229220
}
230221

231222

0 commit comments

Comments
 (0)