diff --git a/bsp/stm32_radio/sdcard.c b/bsp/stm32_radio/sdcard.c index c9e94c244b0d52ef341f0aef92a22a8f01d804a8..fbbc42aab335aa878d3c699db101b24a23d374db 100644 --- a/bsp/stm32_radio/sdcard.c +++ b/bsp/stm32_radio/sdcard.c @@ -2966,6 +2966,7 @@ static void DMA_RxConfiguration(uint32_t *BufferDST, uint32_t BufferSize) static struct rt_device sdcard_device; static SD_CardInfo SDCardInfo; static struct dfs_partition part; +static struct rt_semaphore sd_lock; /* RT-Thread Device Driver Interface */ static rt_err_t rt_sdcard_init(rt_device_t dev) @@ -2978,6 +2979,11 @@ static rt_err_t rt_sdcard_init(rt_device_t dev) NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); + if (rt_sem_init(&sd_lock, "sdlock", 1, RT_IPC_FLAG_FIFO) != RT_EOK) + { + rt_kprintf("init sd lock semaphore failed\n"); + } + return RT_EOK; } @@ -3001,6 +3007,7 @@ static rt_size_t rt_sdcard_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_ // rt_kprintf("read: 0x%x, size %d\n", pos, size); + rt_sem_take(&sd_lock, RT_WAITING_FOREVER); retry = 3; /* read all sectors */ for (i = 0; i < size / SECTOR_SIZE; i ++) @@ -3012,14 +3019,15 @@ __retry: if (status != SD_OK) { if (--retry != 0) goto __retry; - rt_kprintf("sd card read failed, status 0x%08x\n", status); - return 0; + break; } } + rt_sem_release(&sd_lock); + if (status == SD_OK) return size; - rt_kprintf("read failed: %d\n", status); + rt_kprintf("read failed: %d, buffer 0x%08x\n", status, buffer); return 0; } @@ -3030,7 +3038,9 @@ static rt_size_t rt_sdcard_write (rt_device_t dev, rt_off_t pos, const void* buf // rt_kprintf("write: 0x%x, size %d\n", pos, size); - /* read all sectors */ + rt_sem_take(&sd_lock, RT_WAITING_FOREVER); + + /* write all sectors */ for (i = 0; i < size / SECTOR_SIZE; i ++) { status = SD_WriteBlock((part.offset + i)* SECTOR_SIZE + pos, @@ -3039,13 +3049,14 @@ static rt_size_t rt_sdcard_write (rt_device_t dev, rt_off_t pos, const void* buf if (status != SD_OK) { rt_kprintf("sd card write failed\n"); - return 0; + break; } } + rt_sem_release(&sd_lock); if (status == SD_OK) return size; - rt_kprintf("write failed: %d\n", status); + rt_kprintf("write failed: %d, buffer 0x%08x\n", status, buffer); return 0; } @@ -3119,3 +3130,4 @@ void rt_hw_sdcard_init() __return: rt_kprintf("sdcard init failed\n"); } + diff --git a/rtgui/common/asc16font.c b/rtgui/common/asc16font.c index 4af71da2d660d41b4dfe9e2fceaad540de0e67b6..81ee349551f53c2e1eb9fd1a9d25557ec33b74fd 100644 --- a/rtgui/common/asc16font.c +++ b/rtgui/common/asc16font.c @@ -275,7 +275,7 @@ const unsigned char asc16_font[] = { struct rtgui_font_bitmap asc16 = { - asc16_font, /* bmp */ + (const rt_uint8_t*)asc16_font, /* bmp */ 8, /* width */ 16, /* height */ 0, /* first char */ diff --git a/rtgui/common/filerw.c b/rtgui/common/filerw.c index 1e03dda7647511f6c18d42ff395efec3fbc5f6e7..3ad9e8305489b694f84e2accfdc1891bd13ccfd0 100644 --- a/rtgui/common/filerw.c +++ b/rtgui/common/filerw.c @@ -190,12 +190,12 @@ struct rtgui_filerw_mem /* inherit from rtgui_filerw */ struct rtgui_filerw parent; - rt_uint8_t *mem_base, *mem_position, *mem_end; + const rt_uint8_t *mem_base, *mem_position, *mem_end; }; static int mem_seek(struct rtgui_filerw *context, rt_off_t offset, int whence) { - rt_uint8_t* newpos; + const rt_uint8_t* newpos; struct rtgui_filerw_mem* mem = (struct rtgui_filerw_mem*)context; RT_ASSERT(mem != RT_NULL); @@ -250,7 +250,8 @@ static int mem_read(struct rtgui_filerw *context, void *ptr, rt_size_t size, rt_ } static int mem_write(struct rtgui_filerw *context, const void *ptr, rt_size_t size, rt_size_t num) -{ +{ +#if 0 struct rtgui_filerw_mem* mem = (struct rtgui_filerw_mem*)context; if ((mem->mem_position + (num * size)) > mem->mem_end) @@ -261,7 +262,10 @@ static int mem_write(struct rtgui_filerw *context, const void *ptr, rt_size_t si rt_memcpy(mem->mem_position, ptr, num*size); mem->mem_position += num*size; - return num; + return num; +#else + return 0; /* not support memory write */ +#endif } static int mem_tell(struct rtgui_filerw* context) @@ -291,7 +295,7 @@ static int mem_close(struct rtgui_filerw *context) return -1; } -rt_uint8_t* rtgui_filerw_mem_getdata(struct rtgui_filerw* context) +const rt_uint8_t* rtgui_filerw_mem_getdata(struct rtgui_filerw* context) { struct rtgui_filerw_mem* mem = (struct rtgui_filerw_mem*)context; @@ -383,7 +387,7 @@ struct rtgui_filerw* rtgui_filerw_create_file(const char* filename, const char* } #endif -struct rtgui_filerw* rtgui_filerw_create_mem(rt_uint8_t* mem, rt_size_t size) +struct rtgui_filerw* rtgui_filerw_create_mem(const rt_uint8_t* mem, rt_size_t size) { struct rtgui_filerw_mem* rw; RT_ASSERT(mem != RT_NULL); diff --git a/rtgui/common/image.c b/rtgui/common/image.c index 64e2c992e2dfbda8b2daf153f6e4db3be2b06701..40c1363029acba8ffe55838768cbfae3a968160c 100644 --- a/rtgui/common/image.c +++ b/rtgui/common/image.c @@ -122,7 +122,7 @@ struct rtgui_image* rtgui_image_create_from_mem(const char* type, const rt_uint8 struct rtgui_image* image = RT_NULL; /* create filerw context */ - filerw = rtgui_filerw_create_mem((rt_uint8_t*)data, length); + filerw = rtgui_filerw_create_mem(data, length); if (filerw == RT_NULL) return RT_NULL; /* get image engine */ diff --git a/rtgui/include/rtgui/filerw.h b/rtgui/include/rtgui/filerw.h index 0a9395fbb611ff67c3ec2e9297d7f7e25a7a36b1..b05ce3f8e98e4924450a15ff778371fe151b2320 100644 --- a/rtgui/include/rtgui/filerw.h +++ b/rtgui/include/rtgui/filerw.h @@ -32,7 +32,7 @@ struct rtgui_filerw typedef struct rtgui_filerw rtgui_filerw_t; struct rtgui_filerw* rtgui_filerw_create_file(const char* filename, const char* mode); -struct rtgui_filerw* rtgui_filerw_create_mem(rt_uint8_t* mem, rt_size_t size); +struct rtgui_filerw* rtgui_filerw_create_mem(const rt_uint8_t* mem, rt_size_t size); int rtgui_filerw_seek (struct rtgui_filerw* context, rt_off_t offset, int whence); int rtgui_filerw_read (struct rtgui_filerw* context, void* buffer, rt_size_t size, rt_size_t count); @@ -42,6 +42,6 @@ int rtgui_filerw_eof (struct rtgui_filerw* context); int rtgui_filerw_close(struct rtgui_filerw* context); /* get memory data from filerw memory object */ -rt_uint8_t* rtgui_filerw_mem_getdata(struct rtgui_filerw* context); +const rt_uint8_t* rtgui_filerw_mem_getdata(struct rtgui_filerw* context); #endif diff --git a/rtgui/widgets/window.c b/rtgui/widgets/window.c index ae0c708b3cd15a316f7f6b3a3cd2f12b1fb620ac..b006b2e75dc1b19cb052de1ff62727b433bdaf43 100644 --- a/rtgui/widgets/window.c +++ b/rtgui/widgets/window.c @@ -430,6 +430,13 @@ rt_bool_t rtgui_win_event_handler(struct rtgui_widget* widget, struct rtgui_even #endif break; + case RTGUI_EVENT_KBD: + if (RTGUI_CONTAINER(win)->focused != widget) + { + RTGUI_CONTAINER(win)->focused->event_handler(RTGUI_CONTAINER(win)->focused, event); + } + break; + default: /* call parent event handler */ return rtgui_toplevel_event_handler(widget, event);