Skip to content

Commit 670afcc

Browse files
committed
添加驱动文件,补充readme
1 parent ea982c0 commit 670afcc

File tree

24 files changed

+582
-711
lines changed

24 files changed

+582
-711
lines changed

libraries/HAL_Drivers/drv_lcd.c

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
#define LCD_BUF_SIZE (LCD_STRIDE * LCD_HEIGHT * LCD_BITS_PER_PIXEL / 8)
4242
#define LCD_PIXEL_FORMAT RTGRAPHIC_PIXEL_FORMAT_RGB565
4343
#define LCD_DEVICE(dev) (struct drv_lcd_device*)(dev)
44-
#define RESET_VAL 0U
4544
#define GPU_TESSELLATION_BUFFER_SIZE ((LCD_WIDTH) * 128U)
4645
#define APP_BUFFER_COUNT (2U)
4746
#define DEFAULT_GPU_CMD_BUFFER_SIZE ((64U) * (512))
@@ -77,9 +76,7 @@ struct drv_lcd_device
7776

7877
static rt_err_t drv_lcd_init(struct rt_device *device)
7978
{
80-
struct drv_lcd_device *lcd = LCD_DEVICE(device);
81-
/* nothing, right now */
82-
lcd = lcd;
79+
(void)device;
8380
return RT_EOK;
8481
}
8582

@@ -91,6 +88,53 @@ static rt_err_t drv_lcd_control(struct rt_device *device, int cmd, void *args)
9188
{
9289
case RTGRAPHIC_CTRL_RECT_UPDATE:
9390
{
91+
struct rt_device_rect_info *info = (struct rt_device_rect_info *)args;
92+
uint32_t start_line = 0U;
93+
uint32_t end_line = lcd->lcd_info.height;
94+
rt_bool_t try_partial = RT_FALSE;
95+
96+
if (info != RT_NULL)
97+
{
98+
if ((info->width == 0U) || (info->height == 0U))
99+
{
100+
return RT_EOK;
101+
}
102+
if ((info->x >= lcd->lcd_info.width) || (info->y >= lcd->lcd_info.height))
103+
{
104+
return RT_EOK;
105+
}
106+
if ((info->x + info->width) > lcd->lcd_info.width)
107+
{
108+
info->width = lcd->lcd_info.width - info->x;
109+
}
110+
if ((info->y + info->height) > lcd->lcd_info.height)
111+
{
112+
info->height = lcd->lcd_info.height - info->y;
113+
}
114+
115+
start_line = info->y;
116+
end_line = info->y + info->height;
117+
if ((info->x == 0U) && (info->width == lcd->lcd_info.width))
118+
{
119+
try_partial = RT_TRUE;
120+
}
121+
}
122+
123+
if (try_partial &&
124+
((lcd_gfx_context.dc_context.display_type == GFX_DISP_TYPE_DBI_A) ||
125+
(lcd_gfx_context.dc_context.display_type == GFX_DISP_TYPE_DBI_B) ||
126+
(lcd_gfx_context.dc_context.display_type == GFX_DISP_TYPE_DBI_C) ||
127+
(lcd_gfx_context.dc_context.display_type == GFX_DISP_TYPE_DSI_DBI)))
128+
{
129+
status = Cy_GFXSS_TransferPartialFrame(gfxbase, start_line, end_line, &lcd_gfx_context);
130+
if (CY_GFX_SUCCESS != status)
131+
{
132+
LOG_E("[%s: %d] Partial frame transfer failed. Error type: %u\r\n", __func__, __LINE__, status);
133+
CY_ASSERT(0);
134+
}
135+
break;
136+
}
137+
94138
/* update */
95139
/* Set the frame buffer with the image pointer to be displayed on LCD */
96140
status = Cy_GFXSS_Set_FrameBuffer(gfxbase, (uint32_t*)graphics_buffer, &lcd_gfx_context);

libraries/components/CherryUSB-1.6.0/Kconfig.rtt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ if RT_USING_CHERRYUSB
139139
prompt "Enable usb dfu device"
140140
default n
141141

142+
config RT_CHERRYUSB_DEVICE_DISPLAY
143+
bool
144+
prompt "Enable usb display device"
145+
default n
146+
142147
config RT_CHERRYUSB_DEVICE_CDC_ACM_CHARDEV
143148
bool
144149
prompt "Enable chardev for cdc acm device"
@@ -243,6 +248,10 @@ if RT_USING_CHERRYUSB
243248
bool
244249
prompt "webusb_hid"
245250
depends on RT_CHERRYUSB_DEVICE_HID
251+
config RT_CHERRYUSB_DEVICE_TEMPLATE_DISPLAY
252+
bool
253+
prompt "display"
254+
depends on RT_CHERRYUSB_DEVICE_DISPLAY
246255
config RT_CHERRYUSB_DEVICE_TEMPLATE_ADB
247256
bool
248257
prompt "adb"

libraries/components/CherryUSB-1.6.0/SConscript

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ path += [cwd + '/class/dfu']
1717
path += [cwd + '/class/serial']
1818
path += [cwd + '/class/vendor/net']
1919
path += [cwd + '/class/vendor/wifi']
20+
path += [cwd + '/class/vendor/display']
2021
src = []
2122

2223
LIBS = []
@@ -136,6 +137,11 @@ if GetDepend(['RT_CHERRYUSB_DEVICE']):
136137
src += Glob('class/cdc/usbd_cdc_ncm.c')
137138
if GetDepend(['RT_CHERRYUSB_DEVICE_DFU']):
138139
src += Glob('class/dfu/usbd_dfu.c')
140+
if GetDepend(['RT_CHERRYUSB_DEVICE_DISPLAY']):
141+
path += [cwd + '/third_party/cherrymp']
142+
src += Glob('class/vendor/display/usbd_display.c')
143+
src += Glob('third_party/cherrymp/chry_mempool.c')
144+
src += Glob('third_party/cherrymp/chry_mempool_osal_rtthread.c')
139145
if GetDepend(['RT_CHERRYUSB_DEVICE_ADB']):
140146
src += Glob('class/adb/usbd_adb.c')
141147
src += Glob('platform/rtthread/usbd_adb_shell.c')
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
/*
2+
* Copyright (c) 2026, sakumisu
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include "usbd_core.h"
8+
#include "usbd_display.h"
9+
#include "chry_mempool.h"
10+
11+
struct usbd_disp_frame_header {
12+
uint16_t crc16; //payload crc16
13+
uint8_t type; //raw rgb,yuv,jpg,other
14+
uint8_t cmd;
15+
uint16_t x; //32bit
16+
uint16_t y;
17+
uint16_t width; //32bit
18+
uint16_t height;
19+
uint32_t frame_id : 10;
20+
uint32_t payload_total : 22; //payload max 4MB
21+
} __PACKED;
22+
23+
struct usbd_display_priv {
24+
struct chry_mempool pool;
25+
struct usbd_endpoint out_ep;
26+
struct usbd_endpoint in_ep;
27+
struct usbd_display_frame *current_frame;
28+
} g_usbd_display;
29+
30+
int usbd_display_frame_create(struct usbd_display_frame *frame, uint32_t count)
31+
{
32+
return chry_mempool_create(&g_usbd_display.pool, frame, sizeof(struct usbd_display_frame), count);
33+
}
34+
35+
struct usbd_display_frame *usbd_display_frame_alloc(void)
36+
{
37+
return (struct usbd_display_frame *)chry_mempool_alloc(&g_usbd_display.pool);
38+
}
39+
40+
int usbd_display_frame_free(struct usbd_display_frame *frame)
41+
{
42+
return chry_mempool_free(&g_usbd_display.pool, (uintptr_t *)frame);
43+
}
44+
45+
int usbd_display_frame_send(struct usbd_display_frame *frame)
46+
{
47+
return chry_mempool_send(&g_usbd_display.pool, (uintptr_t *)frame);
48+
}
49+
50+
int usbd_display_frame_recv(struct usbd_display_frame **frame, uint32_t timeout)
51+
{
52+
return chry_mempool_recv(&g_usbd_display.pool, (uintptr_t **)frame, timeout);
53+
}
54+
55+
uint8_t usb_dispay_dummy[512];
56+
volatile uint32_t usb_display_buf_offset;
57+
volatile bool usb_display_ignore_frame;
58+
59+
static void display_notify_handler(uint8_t busid, uint8_t event, void *arg)
60+
{
61+
switch (event) {
62+
case USBD_EVENT_RESET:
63+
break;
64+
case USBD_EVENT_CONFIGURED:
65+
usb_display_buf_offset = 0;
66+
usb_display_ignore_frame = true;
67+
g_usbd_display.current_frame = NULL;
68+
usbd_ep_start_read(busid, g_usbd_display.out_ep.ep_addr, usb_dispay_dummy, usbd_get_ep_mps(0, g_usbd_display.out_ep.ep_addr));
69+
break;
70+
default:
71+
break;
72+
}
73+
}
74+
75+
void usbd_display_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
76+
{
77+
if (usb_display_ignore_frame) {
78+
// alloc frame for next at the end of current frame
79+
if ((nbytes % usbd_get_ep_mps(0, g_usbd_display.out_ep.ep_addr)) || (nbytes == 0)) {
80+
if (g_usbd_display.current_frame == NULL) {
81+
g_usbd_display.current_frame = usbd_display_frame_alloc();
82+
if (g_usbd_display.current_frame) {
83+
usb_display_ignore_frame = false;
84+
usb_display_buf_offset = 0;
85+
86+
goto get_frame;
87+
} else {
88+
goto drop_frame;
89+
}
90+
} else {
91+
usb_display_ignore_frame = false;
92+
usb_display_buf_offset = 0;
93+
94+
goto get_frame;
95+
}
96+
} else {
97+
goto drop_frame;
98+
}
99+
} else {
100+
struct usbd_disp_frame_header *header = (struct usbd_disp_frame_header *)&g_usbd_display.current_frame->frame_buf[0];
101+
struct usbd_display_frame *frame;
102+
103+
if (header->payload_total > g_usbd_display.current_frame->frame_bufsize) {
104+
USB_LOG_ERR("frame overflow, drop it\r\n");
105+
usb_display_ignore_frame = true;
106+
107+
goto drop_frame;
108+
}
109+
110+
usb_display_buf_offset += nbytes;
111+
112+
if ((nbytes % usbd_get_ep_mps(0, g_usbd_display.out_ep.ep_addr)) || (nbytes == 0)) {
113+
frame = g_usbd_display.current_frame;
114+
g_usbd_display.current_frame = NULL;
115+
116+
frame->frame_format = header->type;
117+
frame->frame_size = header->payload_total;
118+
usbd_display_frame_send(frame);
119+
120+
g_usbd_display.current_frame = usbd_display_frame_alloc();
121+
if (g_usbd_display.current_frame) {
122+
usb_display_ignore_frame = false;
123+
usb_display_buf_offset = 0;
124+
125+
goto get_frame;
126+
} else {
127+
usb_display_ignore_frame = true;
128+
129+
goto drop_frame;
130+
}
131+
} else {
132+
goto get_frame;
133+
}
134+
}
135+
return;
136+
137+
drop_frame:
138+
// drop current frame
139+
usbd_ep_start_read(busid, g_usbd_display.out_ep.ep_addr, usb_dispay_dummy, usbd_get_ep_mps(0, g_usbd_display.out_ep.ep_addr));
140+
return;
141+
get_frame:
142+
usbd_ep_start_read(busid, g_usbd_display.out_ep.ep_addr, &g_usbd_display.current_frame->frame_buf[usb_display_buf_offset], 16384);
143+
return;
144+
}
145+
146+
void usbd_display_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
147+
{
148+
}
149+
150+
struct usbd_interface *usbd_display_init_intf(struct usbd_interface *intf,
151+
const uint8_t out_ep,
152+
const uint8_t in_ep,
153+
struct usbd_display_frame *frame,
154+
uint32_t count)
155+
{
156+
intf->class_interface_handler = NULL;
157+
intf->class_endpoint_handler = NULL;
158+
intf->vendor_handler = NULL;
159+
intf->notify_handler = display_notify_handler;
160+
161+
g_usbd_display.out_ep.ep_addr = out_ep;
162+
g_usbd_display.out_ep.ep_cb = usbd_display_bulk_out;
163+
g_usbd_display.in_ep.ep_addr = in_ep;
164+
g_usbd_display.in_ep.ep_cb = usbd_display_bulk_in;
165+
usbd_add_endpoint(0, &g_usbd_display.out_ep);
166+
usbd_add_endpoint(0, &g_usbd_display.in_ep);
167+
168+
for (uint32_t i = 0; i < count; i++) {
169+
USB_ASSERT_MSG(frame[i].frame_bufsize % 16384, "frame_bufsize must be the multiple of 16384");
170+
}
171+
172+
usbd_display_frame_create(frame, count);
173+
return intf;
174+
}
175+
176+
int usbd_display_dequeue(struct usbd_display_frame **frame, uint32_t timeout)
177+
{
178+
return usbd_display_frame_recv(frame, timeout);
179+
}
180+
181+
int usbd_display_enqueue(struct usbd_display_frame *frame)
182+
{
183+
return usbd_display_frame_free(frame);
184+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2026, sakumisu
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#ifndef USBD_DISPLAY_H
7+
#define USBD_DISPLAY_H
8+
9+
#define USBD_DISPLAY_TYPE_RGB565 0
10+
#define USBD_DISPLAY_TYPE_RGB888 1
11+
#define USBD_DISPLAY_TYPE_YUV420 2
12+
#define USBD_DISPLAY_TYPE_JPG 3
13+
14+
struct usbd_display_frame {
15+
uint8_t *frame_buf;
16+
uint32_t frame_bufsize;
17+
uint32_t frame_format;
18+
uint32_t frame_size;
19+
};
20+
21+
#ifdef __cplusplus
22+
extern "C" {
23+
#endif
24+
25+
/* Init display interface driver */
26+
struct usbd_interface *usbd_display_init_intf(struct usbd_interface *intf,
27+
const uint8_t out_ep,
28+
const uint8_t in_ep,
29+
struct usbd_display_frame *frame,
30+
uint32_t count);
31+
32+
int usbd_display_dequeue(struct usbd_display_frame **frame, uint32_t timeout);
33+
int usbd_display_enqueue(struct usbd_display_frame *frame);
34+
35+
#ifdef __cplusplus
36+
}
37+
#endif
38+
39+
#endif /* USBD_DISPLAY_H */

libraries/components/CherryUSB-1.6.0/third_party/cherrymp/chry_mempool.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ int chry_mempool_create(struct chry_mempool *pool, void *block, uint32_t block_s
145145
return -1;
146146
}
147147

148-
if (pool->block_size % 4) {
148+
if (block_size % 4) {
149149
return -1;
150150
}
151151

@@ -176,9 +176,9 @@ int chry_mempool_create(struct chry_mempool *pool, void *block, uint32_t block_s
176176

177177
void chry_mempool_delete(struct chry_mempool *pool)
178178
{
179-
chry_mempool_osal_sem_delete(pool->out_sem);
180179
__chry_ringbuffer_reset(&pool->in);
181180
__chry_ringbuffer_reset(&pool->out);
181+
chry_mempool_osal_sem_delete(pool->out_sem);
182182
}
183183

184184
uintptr_t *chry_mempool_alloc(struct chry_mempool *pool)

0 commit comments

Comments
 (0)