Skip to content

Commit 76a4313

Browse files
authored
添加cherryusb拓展屏幕工程 #49
1 parent 2e96cd7 commit 76a4313

File tree

40 files changed

+4123
-20
lines changed

40 files changed

+4123
-20
lines changed

.github/workflows/action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ jobs:
6060
- {RTT_BSP: "Edgi_Talk_M55_Blink_LED"}
6161
- {RTT_BSP: "Edgi_Talk_CherryUSB/Edgi_Talk_M55_USB_D"}
6262
- {RTT_BSP: "Edgi_Talk_CherryUSB/Edgi_Talk_M55_USB_H"}
63+
- {RTT_BSP: "Edgi_Talk_CherryUSB/Edgi_Talk_Extend_Screen"}
6364
- {RTT_BSP: "Edgi_Talk_M55_CoreMark"}
6465
- {RTT_BSP: "Edgi_Talk_M33_CDC_Echo"}
6566
- {RTT_BSP: "Edgi_Talk_M33_HyperRam"}

libraries/Common/board/ports/display_panels/drv_touch.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ static struct rt_i2c_client ST7102_client;
1313
static rt_err_t ST7102_write_reg(struct rt_i2c_client *dev, rt_uint8_t *data, rt_uint8_t len)
1414
{
1515
struct rt_i2c_msg msgs[2];
16-
rt_uint8_t buf[2];
1716

1817
msgs[0].addr = dev->client_addr;
1918
msgs[0].flags = RT_I2C_WR;
@@ -30,15 +29,14 @@ static rt_err_t ST7102_write_reg(struct rt_i2c_client *dev, rt_uint8_t *data, rt
3029
}
3130
}
3231

33-
static rt_err_t ST7102_read_regs(struct rt_i2c_client *dev, rt_uint8_t *reg, rt_uint8_t *data, rt_uint8_t len)
32+
static rt_err_t ST7102_read_regs(struct rt_i2c_client *dev, const rt_uint8_t *reg, rt_uint8_t reg_len, rt_uint8_t *data, rt_uint8_t len)
3433
{
3534
struct rt_i2c_msg msgs[2];
36-
rt_uint8_t buf[2];
3735

3836
msgs[0].addr = dev->client_addr;
3937
msgs[0].flags = RT_I2C_WR;
40-
msgs[0].buf = reg;
41-
msgs[0].len = ST7102_REGITER_LEN;
38+
msgs[0].buf = (rt_uint8_t *)reg;
39+
msgs[0].len = reg_len;
4240

4341
msgs[1].addr = dev->client_addr;
4442
msgs[1].flags = RT_I2C_RD;
@@ -59,16 +57,22 @@ static rt_err_t ST7102_get_info(struct rt_i2c_client *dev, struct rt_touch_info
5957
{
6058
rt_uint8_t Reg_High[2];
6159
rt_uint8_t Reg_Low[2];
60+
rt_uint8_t reg;
6261

63-
ST7102_read_regs(dev, ST7102_MAX_X_Coord_High, Reg_High, 1);
64-
ST7102_read_regs(dev, ST7102_MAX_X_Coord_Low, Reg_Low, 1);
62+
reg = ST7102_MAX_X_Coord_High;
63+
ST7102_read_regs(dev, &reg, 1, Reg_High, 1);
64+
reg = ST7102_MAX_X_Coord_Low;
65+
ST7102_read_regs(dev, &reg, 1, Reg_Low, 1);
6566
info->range_x = (Reg_High[0] & 0x3F) << 8 | Reg_Low[0];
6667

67-
ST7102_read_regs(dev, ST7102_MAX_Y_Coord_High, Reg_High, 1);
68-
ST7102_read_regs(dev, ST7102_MAX_Y_Coord_Low, Reg_Low, 1);
68+
reg = ST7102_MAX_Y_Coord_High;
69+
ST7102_read_regs(dev, &reg, 1, Reg_High, 1);
70+
reg = ST7102_MAX_Y_Coord_Low;
71+
ST7102_read_regs(dev, &reg, 1, Reg_Low, 1);
6972
info->range_y = (Reg_High[0] & 0x3F) << 8 | Reg_Low[0];
7073

71-
ST7102_read_regs(dev, ST7102_MAX_Touches, Reg_Low, 1);
74+
reg = ST7102_MAX_Touches;
75+
ST7102_read_regs(dev, &reg, 1, Reg_Low, 1);
7276
info->point_num = Reg_Low[0];
7377

7478
return RT_EOK;
@@ -163,7 +167,7 @@ static rt_size_t ST7102_read_point(struct rt_touch_device *touch, void *buf, rt_
163167
cmd[0] = (rt_uint8_t)((ST7102_Read_Start_Position >> 8) & 0xFF);
164168
cmd[1] = (rt_uint8_t)(ST7102_Read_Start_Position & 0xFF);
165169

166-
if (ST7102_read_regs(&ST7102_client, cmd, read_buf, 8 * ST7102_MAX_TOUCH) != RT_EOK)
170+
if (ST7102_read_regs(&ST7102_client, cmd, 2, read_buf, 8 * ST7102_MAX_TOUCH) != RT_EOK)
167171
{
168172
LOG_D("read point failed\n");
169173
read_num = 0;

libraries/HAL_Drivers/drv_lcd.c

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@
3636

3737
#define LCD_WIDTH 512
3838
#define LCD_HEIGHT 800
39+
#define LCD_STRIDE 512
3940
#define LCD_BITS_PER_PIXEL 16
40-
#define LCD_BUF_SIZE (LCD_WIDTH * LCD_HEIGHT * LCD_BITS_PER_PIXEL / 8)
41+
#define LCD_BUF_SIZE (LCD_STRIDE * LCD_HEIGHT * LCD_BITS_PER_PIXEL / 8)
4142
#define LCD_PIXEL_FORMAT RTGRAPHIC_PIXEL_FORMAT_RGB565
4243
#define LCD_DEVICE(dev) (struct drv_lcd_device*)(dev)
43-
#define RESET_VAL 0U
4444
#define GPU_TESSELLATION_BUFFER_SIZE ((LCD_WIDTH) * 128U)
4545
#define APP_BUFFER_COUNT (2U)
4646
#define DEFAULT_GPU_CMD_BUFFER_SIZE ((64U) * (512))
@@ -76,9 +76,7 @@ struct drv_lcd_device
7676

7777
static rt_err_t drv_lcd_init(struct rt_device *device)
7878
{
79-
struct drv_lcd_device *lcd = LCD_DEVICE(device);
80-
/* nothing, right now */
81-
lcd = lcd;
79+
(void)device;
8280
return RT_EOK;
8381
}
8482

@@ -90,6 +88,53 @@ static rt_err_t drv_lcd_control(struct rt_device *device, int cmd, void *args)
9088
{
9189
case RTGRAPHIC_CTRL_RECT_UPDATE:
9290
{
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+
93138
/* update */
94139
/* Set the frame buffer with the image pointer to be displayed on LCD */
95140
status = Cy_GFXSS_Set_FrameBuffer(gfxbase, (uint32_t*)graphics_buffer, &lcd_gfx_context);
@@ -111,9 +156,11 @@ static rt_err_t drv_lcd_control(struct rt_device *device, int cmd, void *args)
111156
RT_ASSERT(info != RT_NULL);
112157
info->pixel_format = lcd->lcd_info.pixel_format;
113158
info->bits_per_pixel = 16;
159+
info->pitch = lcd->lcd_info.pitch;
114160
info->width = lcd->lcd_info.width;
115161
info->height = lcd->lcd_info.height;
116162
info->framebuffer = lcd->lcd_info.framebuffer;
163+
info->smem_len = lcd->lcd_info.smem_len;
117164
}
118165
break;
119166
}
@@ -148,6 +195,7 @@ static void dc_irq_handler(void)
148195
{
149196
rt_interrupt_enter();
150197
Cy_GFXSS_Clear_DC_Interrupt(gfxbase, &lcd_gfx_context);
198+
rt_sem_release(&_lcd.lcd_lock);
151199
rt_interrupt_leave();
152200
}
153201

@@ -251,6 +299,8 @@ int drv_lcd_hw_init(void)
251299
_lcd.lcd_info.width = LCD_WIDTH;
252300
_lcd.lcd_info.bits_per_pixel = LCD_BITS_PER_PIXEL;
253301
_lcd.lcd_info.pixel_format = LCD_PIXEL_FORMAT;
302+
_lcd.lcd_info.pitch = LCD_STRIDE * (LCD_BITS_PER_PIXEL / 8);
303+
_lcd.lcd_info.smem_len = LCD_BUF_SIZE;
254304

255305
/* malloc memory for Triple Buffering */
256306
// _lcd.front_buf=_lcd.lcd_info.framebuffer = rt_malloc_align(LCD_BUF_SIZE, 32);
@@ -264,7 +314,7 @@ int drv_lcd_hw_init(void)
264314
goto __exit;
265315
}
266316
/* memset buff to 0xFF */
267-
memset(_lcd.lcd_info.framebuffer, 0xFF, LCD_BUF_SIZE);
317+
memset(_lcd.lcd_info.framebuffer, 0x00, LCD_BUF_SIZE);
268318
device->type = RT_Device_Class_Graphic;
269319
#ifdef RT_USING_DEVICE_OPS
270320
device->ops = &lcd_ops;

libraries/M55_Config/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ menu "On-chip Peripheral Drivers"
199199
select RT_USING_LCD
200200
select RT_USING_TOUCH
201201
select RT_TOUCH_PIN_IRQ
202+
select BSP_USING_I2C
203+
select BSP_USING_SOFT_I2C1
202204
default n
203205
if BSP_USING_LCD
204206
config COMPONENT_MTB_DISPLAY_tl043wvv02

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')

0 commit comments

Comments
 (0)