Skip to content

Commit d0c8fbb

Browse files
committed
feat: implement SPIBusFast driver with 90° rotation for AXS15231B QSPI
- Add SPIBusFast bus driver with partial updates support - Enable LVGL partial mode instead of full frame updates - Implement 90° rotation with pixel coordinate transformation - Add RTOS task for double buffering - Support QSPI 4-wire interface for AXS15231B controller
1 parent 11fae09 commit d0c8fbb

File tree

7 files changed

+1061
-0
lines changed

7 files changed

+1061
-0
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// Copyright (c) 2024 - 2025 Kevin G. Schlosser
2+
// Copyright (c) 2024 - 2025 Viktor Vorobjov
3+
4+
#ifndef _ESP32_SPI_BUS_FAST_H_
5+
#define _ESP32_SPI_BUS_FAST_H_
6+
7+
//local_includes
8+
#include "lcd_types.h"
9+
#include "../../../micropy_updates/common/mp_spi_common.h"
10+
11+
// esp-idf includes
12+
#include "esp_lcd_panel_io.h"
13+
#include "esp_heap_caps.h"
14+
#include "driver/spi_common.h"
15+
#include "driver/spi_master.h"
16+
#include "hal/spi_types.h"
17+
18+
#include "freertos/FreeRTOS.h"
19+
#include "freertos/task.h"
20+
#include "freertos/semphr.h"
21+
#include "freertos/event_groups.h"
22+
#include "freertos/idf_additions.h"
23+
24+
// micropython includes
25+
#include "mphalport.h"
26+
#include "py/obj.h"
27+
#include "py/objarray.h"
28+
29+
typedef struct _spi_bus_fast_lock_t {
30+
SemaphoreHandle_t handle;
31+
StaticSemaphore_t buffer;
32+
} spi_bus_fast_lock_t;
33+
34+
typedef struct _spi_bus_fast_event_t {
35+
EventGroupHandle_t handle;
36+
StaticEventGroup_t buffer;
37+
} spi_bus_fast_event_t;
38+
39+
typedef struct _mp_lcd_spi_bus_fast_obj_t {
40+
mp_obj_base_t base;
41+
42+
mp_obj_t callback;
43+
44+
mp_obj_array_t *view1;
45+
mp_obj_array_t *view2;
46+
47+
uint32_t buffer_flags;
48+
49+
bool trans_done;
50+
bool rgb565_byte_swap;
51+
52+
lcd_panel_io_t panel_io_handle;
53+
54+
// Оригинальные поля из spi_bus.h
55+
esp_lcd_panel_io_spi_config_t panel_io_config;
56+
spi_bus_config_t bus_config;
57+
esp_lcd_spi_bus_handle_t bus_handle;
58+
spi_host_device_t host;
59+
mp_machine_hw_spi_device_obj_t spi_device;
60+
61+
// Partial updates specific fields
62+
uint8_t *active_fb;
63+
uint8_t *idle_fb;
64+
uint8_t *partial_buf;
65+
66+
int x_start;
67+
int y_start;
68+
int x_end;
69+
int y_end;
70+
uint16_t width;
71+
uint16_t height;
72+
uint8_t rotation: 2;
73+
uint8_t bytes_per_pixel: 2;
74+
uint8_t last_update: 1;
75+
uint8_t first_frame_received: 1;
76+
77+
// Task synchronization
78+
spi_bus_fast_lock_t copy_lock;
79+
spi_bus_fast_event_t copy_task_exit;
80+
spi_bus_fast_lock_t tx_color_lock;
81+
spi_bus_fast_lock_t init_lock;
82+
83+
TaskHandle_t copy_task_handle;
84+
85+
// ДИАГНОСТИКА - счетчики без printf
86+
volatile uint32_t task_alive_counter;
87+
volatile uint32_t task_loop_counter;
88+
volatile uint32_t copy_function_count; // сколько раз вызвана copy_partial_to_full_buffer
89+
volatile uint32_t send_function_count; // сколько раз вызвана send_full_buffer_chunked
90+
volatile uint32_t send_error_count; // сколько ошибок ESP-IDF API
91+
// Основные диагностические поля убраны - используем ets_printf из task
92+
93+
mp_lcd_err_t init_err;
94+
mp_rom_error_text_t init_err_msg;
95+
96+
} mp_lcd_spi_bus_fast_obj_t;
97+
98+
void spi_bus_fast_event_init(spi_bus_fast_event_t *event);
99+
void spi_bus_fast_event_delete(spi_bus_fast_event_t *event);
100+
bool spi_bus_fast_event_isset(spi_bus_fast_event_t *event);
101+
void spi_bus_fast_event_set(spi_bus_fast_event_t *event);
102+
void spi_bus_fast_event_clear(spi_bus_fast_event_t *event);
103+
void spi_bus_fast_event_wait(spi_bus_fast_event_t *event);
104+
105+
int spi_bus_fast_lock_acquire(spi_bus_fast_lock_t *lock, int32_t wait_ms);
106+
void spi_bus_fast_lock_release(spi_bus_fast_lock_t *lock);
107+
void spi_bus_fast_lock_init(spi_bus_fast_lock_t *lock);
108+
void spi_bus_fast_lock_delete(spi_bus_fast_lock_t *lock);
109+
110+
void spi_bus_fast_copy_task(void *self_in);
111+
112+
// SPIBusFast functions
113+
mp_lcd_err_t spi_fast_tx_color(mp_obj_t obj, int lcd_cmd, void *color, size_t color_size,
114+
int x_start, int y_start, int x_end, int y_end,
115+
uint8_t rotation, bool last_update);
116+
117+
extern const mp_obj_type_t mp_lcd_spi_bus_fast_type;
118+
119+
extern void mp_lcd_spi_bus_fast_deinit_all(void);
120+
121+
#endif /* _ESP32_SPI_BUS_FAST_H_ */
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) 2024 - 2025 Kevin G. Schlosser
2+
// Copyright (c) 2024 - 2025 Viktor Vorobjov
3+
4+
5+
#ifndef __SPI_BUS_FAST_ROTATION_H__
6+
#define __SPI_BUS_FAST_ROTATION_H__
7+
8+
#include <stdint.h>
9+
10+
// Rotation constants
11+
#define SPI_FAST_ROTATION_0 (0)
12+
#define SPI_FAST_ROTATION_90 (1)
13+
#define SPI_FAST_ROTATION_180 (2)
14+
#define SPI_FAST_ROTATION_270 (3)
15+
16+
// Main rotation function for SPIBusFast
17+
void spi_fast_copy_pixels(void *dst, void *src, uint32_t x_start, uint32_t y_start,
18+
uint32_t x_end, uint32_t y_end, uint32_t dst_width, uint32_t dst_height,
19+
uint32_t bytes_per_pixel, uint8_t rotate, uint8_t rgb565_dither);
20+
21+
#endif // __SPI_BUS_FAST_ROTATION_H__

0 commit comments

Comments
 (0)