screen->window, win.update() is ok

This commit is contained in:
lyon1998 2021-11-02 22:58:30 +08:00
parent d82a078077
commit db5710d50f
13 changed files with 304 additions and 342 deletions

View File

@ -3,17 +3,29 @@ import Arm2D
mem = PikaStdLib.MemChecker()
screen = Arm2D.Screen()
screen.init()
screen.background.setColor('white')
win = Arm2D.Window()
win.init()
win.background.setColor('white')
screen.elems.b1 = Arm2D.Box()
screen.elems.b1.init()
screen.elems.b1.setColor('blue')
screen.elems.b1.move(100, 100)
win.elems.b1 = Arm2D.Box()
win.elems.b1.init()
win.elems.b1.setColor('blue')
win.elems.b1.move(100, 100)
win.update()
print('hello world')
print('hello pikaScript')
print('mem used max:')
mem.max()
print('mem used now:')
mem.now()
i = 0
x0 = 100
y0 = 100
while i < 100:
x = x0 + i
y = y0 + i
win.elems.b1.move(x, y)
win.update()
i = i + 1
print(i)

View File

@ -11,12 +11,12 @@ class BackGround(TinyObj):
def getColor() -> str:
pass
def update(ptTile: pointer, bIsNewFrame: int):
def update():
pass
class ElementList(BaseObj):
def update(ptTile: pointer, bIsNewFrame: int):
def update():
pass
@ -39,13 +39,13 @@ class Element(TinyObj):
def down(y: int):
pass
def update(ptTile: pointer, bIsNewFrame: int):
def update():
pass
class Box(Element):
# override
def update(ptTile: pointer, bIsNewFrame: int):
def update():
pass
def init():
@ -60,7 +60,7 @@ class Box(Element):
class Star(Element):
# override
def update(ptTile: pointer, bIsNewFrame: int):
def update():
pass
def init():
@ -73,12 +73,12 @@ class Star(Element):
pass
class Screen(BaseObj):
class Window(BaseObj):
background = BackGround()
elems = ElementList()
def init():
pass
def update(ptTile: pointer, bIsNewFrame: int):
def update():
pass

View File

@ -11,11 +11,13 @@ char *Arm2D_BackGround_getColor(PikaObj *self)
}
void Arm2D_BackGround_update(PikaObj *self, int bIsNewFrame, void * ptTile)
void Arm2D_BackGround_update(PikaObj *self)
{
void *target_tile = pika_arm2d_window.pfb_tile_now;
char *color = obj_getStr(self, "color");
uint16_t backGroundColor = getColorCode(color);
arm_2d_rgb16_fill_colour(ptTile, NULL, backGroundColor);
arm_2d_rgb16_fill_colour(target_tile, NULL, backGroundColor);
}
void Arm2D_BackGround_setColor(PikaObj *self, char *color)

View File

@ -1,32 +1,32 @@
#include "Arm2D_common.h"
#include "Arm2D_Box.h"
void Arm2D_Box_init(PikaObj *self)
{
obj_setInt(self, "posX", 0);
obj_setInt(self, "posY", 0);
obj_setInt(self, "sizeX", 50);
obj_setInt(self, "sizeY", 50);
obj_setStr(self, "color", "blue");
void Arm2D_Box_init(PikaObj *self) {
obj_setInt(self, "posX", 0);
obj_setInt(self, "posY", 0);
obj_setInt(self, "sizeX", 50);
obj_setInt(self, "sizeY", 50);
obj_setStr(self, "color", "blue");
}
void Arm2D_Box_update(PikaObj *self, int bIsNewFrame, void * ptTile)
{
int posX = obj_getInt(self, "posX");
int posY = obj_getInt(self, "posY");
int sizeX = obj_getInt(self, "sizeX");
int sizeY = obj_getInt(self, "sizeY");
char *color = obj_getStr(self, "color");
arm_2d_region_t tBox = {
.tLocation = {posX, posY},
.tSize = {sizeX, sizeY},
};
arm_2d_rgb16_fill_colour(ptTile, &tBox, getColorCode(color));
void Arm2D_Box_update(PikaObj *self) {
void *target_tile = pika_arm2d_window.pfb_tile_now;
int posX = obj_getInt(self, "posX");
int posY = obj_getInt(self, "posY");
int sizeX = obj_getInt(self, "sizeX");
int sizeY = obj_getInt(self, "sizeY");
char *color = obj_getStr(self, "color");
arm_2d_region_t tBox = { .tLocation = { posX, posY }, .tSize = { sizeX,
sizeY }, };
arm_2d_rgb16_fill_colour(target_tile, &tBox, getColorCode(color));
}
void Arm2D_Box_setColor(PikaObj *self, char *color)
{
obj_setStr(self, "color", color);
void Arm2D_Box_setColor(PikaObj *self, char *color) {
obj_setStr(self, "color", color);
}
void Arm2D_Box_setSize(PikaObj *self, int x, int y)
{
obj_setInt(self, "sizeX", x);
obj_setInt(self, "sizeY", y);
void Arm2D_Box_setSize(PikaObj *self, int x, int y) {
obj_setInt(self, "sizeX", x);
obj_setInt(self, "sizeY", y);
}

View File

@ -1,6 +1,6 @@
#include "Arm2D_common.h"
void Arm2D_Element_update(PikaObj *self, int bIsNewFrame, void * ptTile)
void Arm2D_Element_update(PikaObj *self)
{
/* need to be override */
obj_setErrorCode(self, 1);

View File

@ -3,23 +3,15 @@
int32_t __foreach_ElementList_update(Arg *elem, Args *buffs)
{
char *type = arg_getType(elem);
void *ptTile = args_getPtr(buffs, "ptTile");
int bIsNewFrame = args_getInt(buffs, "bIsNewFrame");
if (strIsStartWith(type, "_class"))
{
PikaObj *elemObj = arg_getPtr(elem);
obj_setPtr(elemObj, "ptTile", ptTile);
obj_setInt(elemObj, "bIsNewFrame", bIsNewFrame);
obj_run(elemObj, "update(ptTile, bIsNewFrame)");
obj_run(elemObj, "update()");
}
return 0;
}
void Arm2D_ElementList_update(PikaObj *self, int bIsNewFrame, void *ptTile)
void Arm2D_ElementList_update(PikaObj *self)
{
Args *buffs = New_args(NULL);
args_setPtr(buffs, "ptTile", (void *)ptTile);
args_setInt(buffs, "bIsNewFrame", bIsNewFrame);
args_foreach(self->attributeList, __foreach_ElementList_update, buffs);
args_deinit(buffs);
}
args_foreach(self->attributeList, __foreach_ElementList_update, NULL);
}

View File

@ -1,14 +0,0 @@
#include "Arm2D_common.h"
void Arm2D_Screen_init(PikaObj *self)
{
obj_run(self, "background.init()");
}
void Arm2D_Screen_update(PikaObj *self, int bIsNewFrame, void *ptTile)
{
obj_setPtr(self, "ptTile", (void *)ptTile);
obj_setInt(self, "bIsNewFrame", bIsNewFrame);
obj_run(self, "background.update(ptTile, bIsNewFrame)");
obj_run(self, "elems.update(ptTile, bIsNewFrame)");
}

View File

@ -0,0 +1,92 @@
#include "Arm2D_common.h"
#include "Arm2D_Window.h"
#include "Arm2D_Background.h"
#include "Arm2D_ElementList.h"
#include <rtthread.h>
#include <board.h>
#include "arm_2d.h"
#include "arm_2d_helper.h"
#include "lcd_printf.h"
#include "pikaScript.h"
pika_arm2d_window_t pika_arm2d_window;
extern int32_t GLCD_DrawBitmap(uint32_t x, uint32_t y, uint32_t width,
uint32_t height, const uint8_t *bitmap);
static arm_2d_helper_pfb_t s_tPFBHelper;
static IMPL_PFB_ON_LOW_LV_RENDERING(__pfb_render_handler) {
const arm_2d_tile_t *pfb_tile = &(ptPFB->tTile);
ARM_2D_UNUSED(pTarget);
ARM_2D_UNUSED(bIsNewFrame);
GLCD_DrawBitmap(pfb_tile->tRegion.tLocation.iX,
pfb_tile->tRegion.tLocation.iY, pfb_tile->tRegion.tSize.iWidth,
pfb_tile->tRegion.tSize.iHeight, pfb_tile->pchBuffer);
arm_2d_helper_pfb_report_rendering_complete(&s_tPFBHelper,
(arm_2d_pfb_t *) ptPFB);
}
static IMPL_PFB_ON_DRAW(pika_pfb_drow_window_hanlder) {
ARM_2D_UNUSED(pTarget);
ARM_2D_UNUSED(bIsNewFrame);
pika_arm2d_window.pfb_tile_now = (arm_2d_tile_t *) ptTile;
pika_arm2d_window.pfb_is_new_frame = bIsNewFrame;
PikaObj * win = pika_arm2d_window.pika_windows_object;
PikaObj * background = args_getPtr(win, "background");
PikaObj * elems = args_getPtr(win, "elems");
Arm2D_BackGround_update(background);
Arm2D_ElementList_update(elems);
return arm_fsm_rt_cpl;
}
void pika_arm2d_init(void) {
arm_irq_safe
{
arm_2d_init()
;
}
//! initialise FPB helper
if (ARM_2D_HELPER_PFB_INIT(
&s_tPFBHelper, //!< FPB Helper object
LCD_WIDTH,//!< screen width
LCD_HEIGHT,//!< screen height
uint16_t,//!< colour date type
LCD_WIDTH,//!< PFB block width
80,//!< 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 = &pika_pfb_drow_window_hanlder,
},
}) < 0) {
//! error detected
assert(false);
}
}
void pika_arm2d_update() {
while (arm_fsm_rt_cpl != arm_2d_helper_pfb_task(&s_tPFBHelper, NULL))
;
}
void Arm2D_Window_init(PikaObj *self) {
pika_arm2d_init();
obj_run(self, "background.init()");
}
void Arm2D_Window_update(PikaObj *self) {
pika_arm2d_window.pika_windows_object = self;
pika_arm2d_update();
}

View File

@ -5,20 +5,53 @@
#include "arm_2d_helper.h"
#include "lcd_printf.h"
#include "pikaScript.h"
#include "app-arm2d.h"
#include "Arm2D_Box.h"
#include "dataStrs.h"
#include "BaseObj.h"
#include <stdbool.h>
#ifndef ARM2DQEMUBOOTER_APP_ARM2D_H_
#define APPLICATIONS_APP_ARM2D_H_
typedef struct pika_arm2d_window_t_ {
arm_2d_tile_t *pfb_tile_now;
bool pfb_is_new_frame;
PikaObj * pika_windows_object;
} pika_arm2d_window_t;
extern pika_arm2d_window_t pika_arm2d_window;
/* GLCD RGB color definitions */
#define GLCD_COLOR_BLACK 0x0000 /* 0, 0, 0 */
#define GLCD_COLOR_NAVY 0x000F /* 0, 0, 128 */
#define GLCD_COLOR_DARK_GREEN 0x03E0 /* 0, 128, 0 */
#define GLCD_COLOR_DARK_CYAN 0x03EF /* 0, 128, 128 */
#define GLCD_COLOR_MAROON 0x7800 /* 128, 0, 0 */
#define GLCD_COLOR_PURPLE 0x780F /* 128, 0, 128 */
#define GLCD_COLOR_OLIVE 0x7BE0 /* 128, 128, 0 */
#define GLCD_COLOR_LIGHT_GREY 0xC618 /* 192, 192, 192 */
#define GLCD_COLOR_DARK_GREY 0x7BEF /* 128, 128, 128 */
#define GLCD_COLOR_BLUE 0x001F /* 0, 0, 255 */
#define GLCD_COLOR_GREEN 0x07E0 /* 0, 255, 0 */
#define GLCD_COLOR_CYAN 0x07FF /* 0, 255, 255 */
#define GLCD_COLOR_RED 0xF800 /* 255, 0, 0 */
#define GLCD_COLOR_MAGENTA 0xF81F /* 255, 0, 255 */
#define GLCD_COLOR_YELLOW 0xFFE0 /* 255, 255, 0 */
#define GLCD_COLOR_WHITE 0xFFFF /* 255, 255, 255 */
void pika_arm2d_init(void);
void pika_arm2d_update();
#endif /* ARM2DQEMUBOOTER_APP_ARM2D_H_ */
uint16_t getColorCode(char *colorName);
typedef struct
{
arm_2d_op_rotate_t tOP;
const arm_2d_tile_t *ptTile;
float fAngle;
float fAngleSpeed;
arm_2d_location_t tCentre;
arm_2d_region_t tRegion;
typedef struct {
arm_2d_op_rotate_t tOP;
const arm_2d_tile_t *ptTile;
float fAngle;
float fAngleSpeed;
arm_2d_location_t tCentre;
arm_2d_region_t tRegion;
} rotate_tile_t;
#endif
#endif

View File

@ -1,79 +1,67 @@
#include "Arm2d_common.h"
extern const uint8_t c_bmpSun[56 * 57 * sizeof(uint16_t)];
const static arm_2d_tile_t c_tPictureSun = {
.tRegion = {
.tSize = {
.iWidth = 56,
.iHeight = 57},
},
.tInfo.bIsRoot = true,
.phwBuffer = (uint16_t *)c_bmpSun,
};
const static arm_2d_tile_t c_tPictureSun = { .tRegion = { .tSize = { .iWidth =
56, .iHeight = 57 }, }, .tInfo.bIsRoot = true, .phwBuffer =
(uint16_t *) c_bmpSun, };
void Arm2D_Star_centra(PikaObj *self, int x, int y)
{
obj_setInt(self, "centreX", x);
obj_setInt(self, "centreY", y);
void Arm2D_Star_centra(PikaObj *self, int x, int y) {
obj_setInt(self, "centreX", x);
obj_setInt(self, "centreY", y);
}
void Arm2D_Star_speed(PikaObj *self, float speed)
{
obj_setFloat(self, "angleSpeed", speed);
void Arm2D_Star_speed(PikaObj *self, float speed) {
obj_setFloat(self, "angleSpeed", speed);
}
void Arm2D_Star_init(PikaObj *self)
{
// obj_setInt(self, "posX", 250);
// obj_setInt(self, "posY", 250);
// obj_setInt(self, "centreX", 0);
// obj_setInt(self, "centreY", 0);
// obj_setFloat(self, "angleSpeed", 0.5f);
// obj_setFloat(self, "angle", 0.0f);
//
// rotate_tile_t rotateTile = {
// .ptTile = &c_tPictureSun,
// .fAngleSpeed = 0.0f,
// .tCentre = {
// .iX = 0,
// .iY = 0,
// },
// .tRegion = {
// .tLocation = {
// .iX = 200,
// .iY = 200,
// },
// .tSize = c_tPictureSun.tRegion.tSize,
// },
// .fAngle = 0.0,
// };
//
// Arg *rotateTileArg = New_arg(NULL);
// arg_setcontent(rotateTileArg, &rotateTile, sizeof(rotate_tile_t));
// arg_setName(rotateTileArg, "rotateTile");
// arg_setType(rotateTileArg, "rotate_tile_t");
// obj_setArg(self, "rotateTile", rotateTileArg);
// arg_deinit(rotateTileArg);
void Arm2D_Star_init(PikaObj *self) {
obj_setInt(self, "posX", 250);
obj_setInt(self, "posY", 250);
obj_setInt(self, "centreX", 0);
obj_setInt(self, "centreY", 0);
obj_setFloat(self, "angleSpeed", 0.5f);
obj_setFloat(self, "angle", 0.0f);
rotate_tile_t rotateTile = {
.ptTile = &c_tPictureSun,
.fAngleSpeed = 0.0f,
.tCentre = {
.iX = 0,
.iY = 0,
},
.tRegion = {
.tLocation = {
.iX = 200,
.iY = 200,
},
.tSize = c_tPictureSun.tRegion.tSize,
},
.fAngle = 0.0,
};
Arg *rotateTileArg = New_arg(NULL);
arg_setContent(rotateTileArg, &rotateTile, sizeof(rotate_tile_t));
arg_setName(rotateTileArg, "rotateTile");
arg_setType(rotateTileArg, "rotate_tile_t");
obj_setArg(self, "rotateTile", rotateTileArg);
arg_deinit(rotateTileArg);
}
void Arm2D_Star_update(PikaObj *self, int bIsNewFrame, void *ptTile)
{
// Arg *rotateTileArg = obj_getArg(self, "rotateTile");
// rotate_tile_t *s_tSun = arg_getcontent(rotateTileArg);
// s_tSun->tRegion.tLocation.iX = obj_getInt(self, "posX");
// s_tSun->tRegion.tLocation.iY = obj_getInt(self, "posY");
// s_tSun->tCentre.iX = obj_getInt(self, "centreX");
// s_tSun->tCentre.iY = obj_getInt(self, "centreY");
// s_tSun->fAngleSpeed = obj_getFloat(self, "angleSpeed");
//
// if (bIsNewFrame)
// {
// s_tSun->fAngle += s_tSun->fAngleSpeed;
// }
// arm_2dp_rgb565_tile_rotation(&(s_tSun->tOP),
// s_tSun->ptTile,
// ptTile,
// &(s_tSun->tRegion),
// s_tSun->tCentre,
// s_tSun->fAngle,
// GLCD_COLOR_WHITE);
void Arm2D_Star_update(PikaObj *self) {
int bIsNewFrame = pika_arm2d_window.pfb_is_new_frame;
void *target_tile = pika_arm2d_window.pfb_tile_now;
Arg *rotateTileArg = obj_getArg(self, "rotateTile");
rotate_tile_t *s_tSun = arg_getContent(rotateTileArg);
s_tSun->tRegion.tLocation.iX = obj_getInt(self, "posX");
s_tSun->tRegion.tLocation.iY = obj_getInt(self, "posY");
s_tSun->tCentre.iX = obj_getInt(self, "centreX");
s_tSun->tCentre.iY = obj_getInt(self, "centreY");
s_tSun->fAngleSpeed = obj_getFloat(self, "angleSpeed");
if (bIsNewFrame) {
s_tSun->fAngle += s_tSun->fAngleSpeed;
}
arm_2dp_rgb565_tile_rotation(&(s_tSun->tOP), s_tSun->ptTile, target_tile,
&(s_tSun->tRegion), s_tSun->tCentre, s_tSun->fAngle,
GLCD_COLOR_WHITE);
}

View File

@ -1,93 +0,0 @@
#include "app-arm2d.h"
#include <rtthread.h>
#include <board.h>
#include "arm_2d.h"
#include "arm_2d_helper.h"
#include "lcd_printf.h"
#include "pikaScript.h"
extern PikaObj *pikaMain;
static arm_2d_helper_pfb_t s_tPFBHelper;
extern int32_t GLCD_DrawBitmap(uint32_t x,
uint32_t y,
uint32_t width,
uint32_t height,
const uint8_t *bitmap);
static IMPL_PFB_ON_LOW_LV_RENDERING(__pfb_render_handler)
{
const arm_2d_tile_t *ptTile = &(ptPFB->tTile);
ARM_2D_UNUSED(pTarget);
ARM_2D_UNUSED(bIsNewFrame);
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_handler_t)
{
ARM_2D_UNUSED(pTarget);
ARM_2D_UNUSED(bIsNewFrame);
obj_setPtr(pikaMain, "ptTile", (void *)ptTile);
obj_setInt(pikaMain, "bIsNewFrame", bIsNewFrame);
obj_run(pikaMain, "screen.update(ptTile, bIsNewFrame)");
return arm_fsm_rt_cpl;
}
__OVERRIDE_WEAK
void example_gui_on_refresh_evt_handler(const arm_2d_tile_t *ptFrameBuffer)
{
ARM_2D_UNUSED(ptFrameBuffer);
//! print performance info
}
void arm_2d_app_init(void)
{
arm_irq_safe
{
arm_2d_init();
}
//! initialise FPB helper
if (ARM_2D_HELPER_PFB_INIT(
&s_tPFBHelper, //!< FPB Helper object
LCD_WIDTH, //!< screen width
LCD_HEIGHT, //!< screen height
uint16_t, //!< colour date type
LCD_WIDTH, //!< PFB block width
80, //!< 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_handler_t,
},
}) < 0)
{
//! error detected
assert(false);
}
}
void arm_2d_app_update()
{
while (arm_fsm_rt_cpl != arm_2d_helper_pfb_task(&s_tPFBHelper, NULL))
;
}

View File

@ -1,34 +0,0 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-08-28 lyon the first version
*/
#ifndef ARM2DQEMUBOOTER_APP_ARM2D_H_
#define APPLICATIONS_APP_ARM2D_H_
/* GLCD RGB color definitions */
#define GLCD_COLOR_BLACK 0x0000 /* 0, 0, 0 */
#define GLCD_COLOR_NAVY 0x000F /* 0, 0, 128 */
#define GLCD_COLOR_DARK_GREEN 0x03E0 /* 0, 128, 0 */
#define GLCD_COLOR_DARK_CYAN 0x03EF /* 0, 128, 128 */
#define GLCD_COLOR_MAROON 0x7800 /* 128, 0, 0 */
#define GLCD_COLOR_PURPLE 0x780F /* 128, 0, 128 */
#define GLCD_COLOR_OLIVE 0x7BE0 /* 128, 128, 0 */
#define GLCD_COLOR_LIGHT_GREY 0xC618 /* 192, 192, 192 */
#define GLCD_COLOR_DARK_GREY 0x7BEF /* 128, 128, 128 */
#define GLCD_COLOR_BLUE 0x001F /* 0, 0, 255 */
#define GLCD_COLOR_GREEN 0x07E0 /* 0, 255, 0 */
#define GLCD_COLOR_CYAN 0x07FF /* 0, 255, 255 */
#define GLCD_COLOR_RED 0xF800 /* 255, 0, 0 */
#define GLCD_COLOR_MAGENTA 0xF81F /* 255, 0, 255 */
#define GLCD_COLOR_YELLOW 0xFFE0 /* 255, 255, 0 */
#define GLCD_COLOR_WHITE 0xFFFF /* 255, 255, 255 */
void arm_2d_app_init(void);
void arm_2d_app_update();
#endif /* ARM2DQEMUBOOTER_APP_ARM2D_H_ */

View File

@ -17,92 +17,76 @@
#include <stdint.h>
#include "pikaScript.h"
#include "dataStrs.h"
#include "app-arm2d.h"
#include "Arm2D_common.h"
#define SAMPLE_UART_NAME "uart1" /* 串口设备名称 */
static rt_device_t serial; /* 串口设备句柄 */
static struct rt_semaphore rx_sem; /* 用于接收消息的信号量 */
static rt_device_t serial; /* 串口设备句柄 */
static struct rt_semaphore rx_sem; /* 用于接收消息的信号量 */
#define RX_Buff_SIZE 256
char rxBuff[RX_Buff_SIZE] = {0};
char rxBuff[RX_Buff_SIZE] = { 0 };
Args *rxArgs;
uint8_t isRxOk = 0;
PikaObj *pikaMain;
void rxSingleLineCallBack(char *line)
{
Args * resArgs = obj_runDirect(pikaMain, line);
char * sysOut = args_getSysOut(resArgs);
rt_kprintf("\r\n");
void rx_single_line_handle(char *line) {
Args * resArgs = obj_runDirect(pikaMain, line);
char * sysOut = args_getSysOut(resArgs);
rt_kprintf("\r\n");
if (!strEqu(sysOut, ""))
{
rt_kprintf("%s\r\n", sysOut);
}
args_deinit(resArgs);
if (!strEqu(sysOut, "")) {
rt_kprintf("%s\r\n", sysOut);
}
args_deinit(resArgs);
rt_kprintf(">>>");
rt_kprintf(">>>");
}
/* 接收数据回调函数 */
static rt_err_t uart_input(rt_device_t dev, rt_size_t size)
{
/* 串口接收到数据后产生中断,调用此回调函数,然后发送接收信号量 */
char inputChar;
rt_device_read(serial, -1, &inputChar, 1);
rt_device_write(serial, 0, &inputChar, 1);
if (inputChar != '\r' && inputChar != '\n')
{
strAppendWithSize(rxBuff, &inputChar, 1);
}
if (inputChar == '\r')
{
isRxOk = 1;
}
return RT_EOK;
static rt_err_t uart_input_callback(rt_device_t dev, rt_size_t size) {
/* 串口接收到数据后产生中断,调用此回调函数,然后发送接收信号量 */
char inputChar;
rt_device_read(serial, -1, &inputChar, 1);
rt_device_write(serial, 0, &inputChar, 1);
if (inputChar != '\r' && inputChar != '\n') {
strAppendWithSize(rxBuff, &inputChar, 1);
}
if (inputChar == '\r') {
isRxOk = 1;
}
return RT_EOK;
}
static void clearBuff(char *buff, uint32_t size)
{
for (int i =0;i <size; i++)
{
buff[i] = 0;
}
static void clearBuff(char *buff, uint32_t size) {
for (int i = 0; i < size; i++) {
buff[i] = 0;
}
}
static void uart_init()
{
serial = rt_device_find(SAMPLE_UART_NAME);
static void uart_init() {
serial = rt_device_find(SAMPLE_UART_NAME);
/* 以中断接收及轮询发送模式打开串口设备 */
rt_device_open(serial, RT_DEVICE_FLAG_INT_RX);
/* 以中断接收及轮询发送模式打开串口设备 */
rt_device_open(serial, RT_DEVICE_FLAG_INT_RX);
/* 初始化信号量 */
rt_sem_init(&rx_sem, "rx_sem", 0, RT_IPC_FLAG_FIFO);
/* 初始化信号量 */
rt_sem_init(&rx_sem, "rx_sem", 0, RT_IPC_FLAG_FIFO);
/* 设置接收回调函数 */
rt_device_set_rx_indicate(serial, uart_input);
/* 设置接收回调函数 */
rt_device_set_rx_indicate(serial, uart_input_callback);
}
int main(void)
{
uart_init();
pikaMain = pikaScriptInit();
clearBuff(rxBuff, RX_Buff_SIZE);
arm_2d_app_init();
rt_kprintf(">>>");
while(1)
{
if(isRxOk)
{
isRxOk = 0;
rxSingleLineCallBack(rxBuff);
clearBuff(rxBuff, RX_Buff_SIZE);
}
arm_2d_app_update();
}
return RT_EOK;
int main(void) {
uart_init();
pikaMain = pikaScriptInit();
clearBuff(rxBuff, RX_Buff_SIZE);
rt_kprintf(">>>");
while (1) {
if (isRxOk) {
isRxOk = 0;
rx_single_line_handle(rxBuff);
clearBuff(rxBuff, RX_Buff_SIZE);
}
}
return RT_EOK;
}