microsoft / pxt-robotis

Microsoft MakeCode for ROBOTIS
https://5d8c71b7-aa36-4a68-a9cb-288b989efb08.pxt.io/
MIT License
3 stars 7 forks source link

Size of image buffer is 38400 rather than 9600 #24

Closed irarykim closed 4 years ago

irarykim commented 4 years ago

Describe the bug If I want to use ILI9341 LCD (320x240), the value of img->pixLength() in updateScreen() in libs/st7735---screen/scree.cpp is 38400. But it should be 9600.

To Reproduce Steps to reproduce the behavior:

  1. Set LCD related parameters as follows in config.ts. (If I use parameters of ST7735, LCD works fine)
    
    export const PIN_DISPLAY_SCK = DAL.P0_1;
    export const PIN_DISPLAY_MISO = DAL.P0_24;
    export const PIN_DISPLAY_MOSI = DAL.P1_2;
    export const PIN_DISPLAY_CS = DAL.P0_5;
    export const PIN_DISPLAY_DC = DAL.P1_5;
    export const PIN_DISPLAY_RST = DAL.P1_3;
    export const PIN_DISPLAY_BL = DAL.P1_7;

export const DISPLAY_TYPE = 9341 export const DISPLAY_WIDTH = 320 export const DISPLAY_HEIGHT = 240 export const DISPLAY_CFG0 = 0x08 export const DISPLAY_CFG1 = 0x0010ff export const DISPLAY_CFG2 = 50

2. Add `"game": "file:../game"` to "dependencies" category of pxt.json.
3. Then from the makecode editor, I can use [Scene] category. If I use [Set background image to ()] block and download uf2 file to my board, my board blinks LED irregularly. 
4. I found it entered `target_panic(PANIC_GC_TOO_BIG_ALLOCATION)`. It is because it satisfies `if (numbytes > GC_MAX_ALLOC_SIZE)` condition in `void *gcAllocate(int numbytes)` in libs/base/gc.cpp. The value of `GC_MAX_ALLOC_SIZE` is 16k while `numbytes` is 38416.
5. If I change `GC_MAX_ALLOC_SIZE` to larger value, like 64k, then this panic doesn't happen.
6. But `target_panic(PANIC_SCREEN_ERROR)` happens. Because `img->width() * mult != display->width` condition and `img->height() * mult != display->displayHeight` condition are satisfied in `updateScreen()` of libs/st7735---screen/scree.cpp.
7. Followings are related values:
_For the explanation why `img->pixLength()` should be 9600, please refer to https://github.com/lancaster-university/codal-core/pull/118. This PR is closed but I think the calculation result is correct._ 

display->doubleSize : 1 mult : 2 img->bpp : 4 img->width() : 320 ---> it should be 160, since actually use LCD as 160x120 resolutuion img->height() : 240 ---> it should be 120, since actually use LCD as 160x120 resolutuion display->width : 320 display->height : 240 img->pixLength() : 38400 ---> it should be 9600, since actually use LCD as 160x120 resolutuion


8. I think if the image buffer size is corrected, the `PANIC_GC_TOO_BIG_ALLOCATION `panic will not happen.
irarykim commented 4 years ago

I think I found a way. I can modify arguments of image.create() in pxt-common-packages\libs\screen---st7735\targetoverrides.ts to fix image size to 160x128 or 160x120. I will close this issue.