@@ -77,6 +77,7 @@ extern "C" {
7777/* Private function prototypes -----------------------------------------------*/
7878#if CONFIG_USING_GUI
7979static void ili_set_pixel (rtgui_color_t *c, int x, int y);
80+ static void ili_get_pixel (rtgui_color_t *c, int x, int y);
8081static void ili_draw_hline (rtgui_color_t *c, int x1, int x2, int y);
8182static void ili_draw_vline (rtgui_color_t *c, int x , int y1, int y2);
8283static void ili_draw_raw_hline (rt_uint8_t *pixels, int x1, int x2, int y);
@@ -127,7 +128,7 @@ static const struct rt_device_graphic_info disp_info = {
127128
128129static struct rtgui_graphic_driver_ops disp_ops = {
129130 .set_pixel = ili_set_pixel,
130- .get_pixel = RT_NULL ,
131+ .get_pixel = ili_get_pixel ,
131132 .draw_hline = ili_draw_hline,
132133 .draw_vline = ili_draw_vline,
133134 .draw_raw_hline = ili_draw_raw_hline,
@@ -227,12 +228,15 @@ static rt_err_t ili_write_data(rt_device_t ldev, rt_uint8_t *data,
227228 ret = ili_write_cmd (ldev, ILI_CMD_RAMWR, RT_NULL, RT_NULL, 0 );
228229 if (RT_EOK !=ret) break ;
229230
230- /* send param and receive resp */
231- /* build inst
231+ /* send param and receive resp
232+ - color in RGB565 (RRRRRGGG GGGBBBBB) format
233+ - send MSB first (RRRRRGGG)
234+ */
235+ /* build inst
232236 - inst len: 0
233237 - inst: none
234238 - tx buf addr: offset align with RT_ALIGN_SIZE
235- */
239+ */
236240 buf_ins[0 ] = 0 ;
237241 #pragma GCC diagnostic push
238242 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
@@ -250,6 +254,48 @@ static rt_err_t ili_write_data(rt_device_t ldev, rt_uint8_t *data,
250254 return ret;
251255}
252256
257+ static rt_err_t ili_read_data (rt_device_t ldev, rt_uint8_t *data,
258+ rt_uint32_t len) {
259+ rt_uint8_t buf_ins[RT_ALIGN (5 , RT_ALIGN_SIZE)];
260+ rt_err_t ret;
261+
262+ ret = RT_EOK;
263+ LOG_D (" [ILI] read data [%d]" , len);
264+
265+ do {
266+ rt_size_t ret_len;
267+
268+ ret = ili_write_cmd (ldev, ILI_CMD_RAMRD, RT_NULL, RT_NULL, 0 );
269+ if (RT_EOK !=ret) break ;
270+
271+ /* read data
272+ - color in RGB666 format
273+ - dummy read 1 byte
274+ - receive RRRRRR000, GGGGGG000, BBBBBB000
275+ */
276+ /* build inst
277+ - inst len: 0
278+ - inst: none
279+ - tx buf addr: offset align with RT_ALIGN_SIZE
280+ */
281+ buf_ins[0 ] = 0 ;
282+ #pragma GCC diagnostic push
283+ #pragma GCC diagnostic ignored "-Wstrict-aliasing"
284+ *(rt_uint8_t **)(&buf_ins[RT_ALIGN (1 , RT_ALIGN_SIZE)]) = data;
285+ #pragma GCC diagnostic pop
286+
287+ ret_len = rt_device_read (ldev, 0 , buf_ins, len);
288+ if (len != ret_len) {
289+ LOG_E (" [ILI E] read data failed! [%d]" , ret_len);
290+ ret = -RT_EIO;
291+ break ;
292+ }
293+ LOG_HEX (" read" , 16 , data, len);
294+ } while (0 );
295+
296+ return ret;
297+ }
298+
253299static rt_uint8_t ili_read_reg (rt_device_t ldev, rt_uint8_t reg,
254300 rt_uint8_t idx) {
255301 rt_uint8_t buf[2 ];
@@ -281,7 +327,7 @@ static void ili_set_window(rt_uint16_t x1, rt_uint16_t x2, rt_uint16_t y1,
281327 LOG_D (" [ILI] win (%d,%d) (%d,%d)" , x1, y1, x2, y2);
282328
283329 /* set x */
284- data[0 ] = 5 ;
330+ data[0 ] = 4 ;
285331 data[1 ] = (rt_uint8_t )((x1 & 0xff00 ) >> 8 );
286332 data[2 ] = (rt_uint8_t )(x1 & 0x00ff );
287333 data[3 ] = (rt_uint8_t )((x2 & 0xff00 ) >> 8 );
@@ -308,7 +354,23 @@ SCOPE void ili_set_pixel(rtgui_color_t *c, int x, int y) {
308354 ili_write_data (ILI_CTX ()->ldev , (rt_uint8_t *)c, 2 );
309355 ILI_STOP ();
310356 rt_device_close (ILI_CTX ()->ldev );
311- LOG_D (" [ILI] set pixel %04d (%d, %d)" , *c, x, y);
357+ LOG_D (" [ILI] set pixel %08x (%d, %d)" , *c, x, y);
358+ }
359+
360+ SCOPE void ili_get_pixel (rtgui_color_t *c, int x, int y) {
361+ rt_uint16_t x1 = x & 0x0000ffff ;
362+ rt_uint16_t y1 = y & 0x0000ffff ;
363+ rt_uint8_t buf[4 ];
364+
365+ if (RT_EOK != rt_device_open (ILI_CTX ()->ldev , RT_DEVICE_OFLAG_RDWR))
366+ return ;
367+ ILI_START ();
368+ ili_set_window (x1, x1, y1, y1);
369+ ili_read_data (ILI_CTX ()->ldev , buf, 4 );
370+ ILI_STOP ();
371+ rt_device_close (ILI_CTX ()->ldev );
372+ *c = (buf[1 ] << 16 ) | (buf[2 ] << 8 ) | buf[3 ];
373+ LOG_D (" [ILI] get pixel %08x (%d, %d)" , *c, x, y);
312374}
313375
314376SCOPE void ili_draw_raw_hline (rt_uint8_t *pixels, int x1, int x2, int y) {
0 commit comments