257 lines
7.4 KiB
C
Raw Normal View History

2021-09-05 14:34:01 +08:00
#include "led.h"
#include "beep.h"
#include "key.h"
#include "lcd.h"
#include "arm_2d.h"
#include "arm_2d_helper.h"
#include "uart.h"
#include "PikaMain.h"
static arm_2d_helper_pfb_t s_tPFBHelper;
MimiObj *pikaMain;
#define GLCD_COLOR_WHITE WHITE
#define GLCD_COLOR_BLACK BLACK
#define GLCD_COLOR_BLUE BLUE
int32_t GLCD_DrawBitmap (uint32_t x,
uint32_t y,
uint32_t width,
uint32_t height,
const uint8_t *bitmap)
{
LCD_Draw_Picture(x, y, x + width - 1, y + height- 1,(uint16_t *) bitmap);
return 0;
}
static IMPL_PFB_ON_LOW_LV_RENDERING(__pfb_render_handler)
{
const arm_2d_tile_t *ptTile = &(ptPFB->tTile);
ARM_2D_UNUSED(pTarget);
GLCD_DrawBitmap(ptTile->tRegion.tLocation.iX,
ptTile->tRegion.tLocation.iY,
ptTile->tRegion.tSize.iWidth,
ptTile->tRegion.tSize.iHeight,
ptTile->pchBuffer);
arm_2d_helper_pfb_report_rendering_complete(&s_tPFBHelper,
(arm_2d_pfb_t *)ptPFB);
}
static IMPL_PFB_ON_DRAW(__pfb_draw_background_handler)
{
ARM_2D_UNUSED(pTarget);
//! <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
arm_2d_rgb16_fill_colour(ptTile, NULL, GLCD_COLOR_WHITE);
return arm_fsm_rt_cpl;
}
extern DMEM_STATE DMEMS;
void MemoryChecker_size(MimiObj *self)
{
char buff[256] = {0};
sprintf(buff, "memory loop size = %0.2f kB\r\n", DMEM_TOTAL_SIZE / 1024.0);
uart1_sendStr(buff);
}
void MemoryChecker_max(MimiObj *self)
{
char buff[256] = {0};
sprintf(buff, "memory used max = %0.2f kB\r\n", DMEMS.maxNum * DMEM_BLOCK_SIZE / 1024.0);
uart1_sendStr(buff);
}
void MemoryChecker_now(MimiObj *self)
{
char buff[256] = {0};
sprintf(buff, "memory used now = %0.2f kB\r\n", DMEMS.blk_num * DMEM_BLOCK_SIZE / 1024.0);
uart1_sendStr(buff);
}
void Block_init(MimiObj *self)
{
obj_setInt(self, "isOn", 0);
obj_setInt(self, "x", 50);
obj_setInt(self, "y", 50);
obj_setInt(self, "sizeX", 150);
obj_setInt(self, "sizeY", 75);
}
void Block_moveLeft(MimiObj *self, int x)
{
obj_setInt(self, "x", obj_getInt(self, "x") - x);
}
void Block_moveRight(MimiObj *self, int x)
{
obj_setInt(self, "x", obj_getInt(self, "x") + x);
}
void Block_moveTo(MimiObj *self, int x, int y)
{
obj_setInt(self, "x", x);
obj_setInt(self, "y", y);
}
void Block_off(MimiObj *self)
{
obj_setInt(self, "isOn", 0);
}
void Block_on(MimiObj *self)
{
obj_setInt(self, "isOn", 1);
}
void Block_setColor(MimiObj *self, char * color)
{
}
void Block_setSize(MimiObj *self, int sizeX, int sizeY)
{
obj_setInt(self, "sizeX", sizeX);
obj_setInt(self, "sizeY", sizeY);
}
static IMPL_PFB_ON_DRAW(__pfb_draw_handler)
{
ARM_2D_UNUSED(pTarget);
int x = obj_getInt(pikaMain,"block.x");
int y = obj_getInt(pikaMain,"block.y");
int sizeX = obj_getInt(pikaMain,"block.sizeX");
int sizeY = obj_getInt(pikaMain,"block.sizeY");
int isOn = obj_getInt(pikaMain,"block.isOn");
arm_2d_region_t tBox = {
.tLocation = {x, y},
.tSize = {sizeX, sizeY},
};
//! <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
arm_2d_rgb16_fill_colour(ptTile, NULL, GLCD_COLOR_WHITE);
if (isOn)
{
//! <20><>boxָ<78><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƺ<EFBFBD>ɫӰ<C9AB><D3B0>
arm_2d_rgb16_fill_colour(ptTile, &tBox, GLCD_COLOR_BLACK);
//! <20>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͻ<EFBFBD><CFBD>ƶ<EFBFBD>box
tBox.tLocation.iX -= 5;
tBox.tLocation.iY -= 5;
//! <20><>boxָ<78><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9> 50%(128/255)<29><>͸<EFBFBD><CDB8>Ч<EFBFBD><D0A7>
arm_2d_rgb565_fill_colour_with_alpha(
ptTile,
&tBox,
(arm_2d_color_rgb565_t){GLCD_COLOR_BLUE},
128); //!< ͸<><CDB8><EFBFBD><EFBFBD>
}
return arm_fsm_rt_cpl;
}
void draw_main()
{
ARM_2D_HELPER_PFB_UPDATE_ON_DRAW_HANDLER( &s_tPFBHelper,
&__pfb_draw_handler);
while(arm_fsm_rt_cpl != arm_2d_helper_pfb_task(&s_tPFBHelper, NULL));
}
void obj_run_uart1(MimiObj *self, char *cmd)
{
/* safe, stop when error occord and error info would be print32_t */
Args *res = obj_runDirect(self, cmd);
char *sysOut = args_getStr(res, "sysOut");
if (NULL != sysOut)
{
uart1_sendStr(sysOut);
uart1_sendStr("\r\n");
}
if (0 != args_getInt(res, "errCode"))
{
uart1_sendStr("[info] input commond: \r\n");
uart1_sendStr(cmd);
uart1_sendStr("\r\n");
while (1)
;
}
if (NULL != res)
{
args_deinit(res);
}
}
int main(void)
{
/* hardware init */
HAL_Init(); //<2F><>ʼ<EFBFBD><CABC>HAL<41><4C>
Stm32_Clock_Init(336,8,2,7); //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>,168Mhz
delay_init(); //<2F><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
LED_Init(); //LED<45><44>ʼ<EFBFBD><CABC>
BEEP_Init(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
KEY_Init(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
LCD_Init(); //<2F><>ʼ<EFBFBD><CABC>LCD FSMC<4D>ӿں<D3BF><DABA><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
uart1_init(115200);
/* Arm-2D init */
arm_2d_init();
/* Arg-2D-helper init */
//! initialise FPB helper
if (ARM_2D_HELPER_PFB_INIT(
&s_tPFBHelper, //!< FPB Helper object
24 * 10, //!< screen width
32 * 10, //!< screen height
uint16_t, //!< colour date type
16 , //!< PFB block width
16 , //!< PFB block height
1, //!< number of PFB in the PFB pool
{
.evtOnLowLevelRendering = {
//! callback for low level rendering
.fnHandler = &__pfb_render_handler,
},
.evtOnDrawing = {
//! callback for drawing GUI
.fnHandler = &__pfb_draw_background_handler,
},
}
) < 0) {
//! error detected
assert(false);
}
/* PikaScript init */
pikaMain = newRootObj("pikaMain", New_PikaMain);
/* user init */
while(arm_fsm_rt_cpl != arm_2d_helper_pfb_task(&s_tPFBHelper, NULL));
uart1_sendStr("\r\n");
uart1_sendStr("==============================================\r\n");
uart1_sendStr("* Arm-2D and PikaScript in STM32f407 *\r\n");
uart1_sendStr("* https://github.com/ARM-software/EndpointAI *\r\n");
uart1_sendStr("* https://github.com/mimilib/pikascript *\r\n");
uart1_sendStr("* Have fun! *\r\n");
uart1_sendStr("==============================================\r\n");
obj_run_uart1(pikaMain, " print('Pika script Initing...') ");
obj_run_uart1(pikaMain, " block.init() ");
obj_run_uart1(pikaMain, " print('hello Arm-2D and PikaScript!') ");
uart1_sendStr(">>> ");
while(1)
{
if(UART1_reciveOk)
{
UART1_reciveOk = 0;
/* run mimiScript and get res */
Args *resArgs = obj_runDirect(pikaMain, (char *)UART1_reciveStr);
/* get system output of mimiScript*/
char *sysOut = args_getStr(resArgs, "sysOut");
uart1_sendStr((char *)UART1_reciveStr);
uart1_sendStr("\r\n");
if (NULL != sysOut)
{
/* print32_t out the system output */
uart1_sendStr(sysOut);
uart1_sendStr("\r\n");
}
uart1_sendStr(">>> ");
/* deinit the res */
args_deinit(resArgs);
draw_main();
}
}
}