diff --git a/makefiles/virtual/uCNC.dev b/makefiles/virtual/uCNC.dev index 526cbcf62..8c6be53e2 100644 --- a/makefiles/virtual/uCNC.dev +++ b/makefiles/virtual/uCNC.dev @@ -4,14 +4,14 @@ Name=uCNCVirt Type=1 Ver=2 ObjFiles= -Includes=C:\Users\JCEM\Documents\GitHub\uCNC\src;C:\Users\JCEM\Documents\GitHub\uCNC\makefiles\virtual;C:\Users\jcmartins\.platformio\packages\toolchain-gccmingw32\i686-w64-mingw32\include\ +Includes=C:\Users\jcmartins\Downloads\GitHub\uCNC\src;C:\Users\jcmartins\Downloads\GitHub\uCNC\makefiles\virtual;C:\Users\jcmartins\.platformio\packages\toolchain-gccmingw32\i686-w64-mingw32\include\ Libs= PrivateResource= ResourceIncludes= MakeIncludes= -Compiler=-DWIN_INTERFACE=2 -DENABLE_EXTRA_SYSTEM_CMDS -DWIN_COM_NAME=COM11 -DBOARD=BOARD_VIRTUAL -DMCU=MCU_VIRTUAL_WIN_@@_ +Compiler=-DWIN_INTERFACE=2 -DENABLE_EXTRA_SYSTEM_CMDS -DWIN_COM_NAME=COM11 -DBOARD=BOARD_VIRTUAL -DMCU=MCU_VIRTUAL_@@_ CppCompiler=_@@_ -Linker=-lws2_32_@@_ +Linker=-lws2_32 -lSDL2main -lSDL2_@@_ IsCpp=0 Icon= ExeOutput= @@ -29,7 +29,7 @@ IncludeVersionInfo=0 SupportXPThemes=0 CompilerSet=1 CompilerSettings=000000e0a0000000001000000 -UnitCount=81 +UnitCount=202 [VersionInfo] Major=1 @@ -831,7 +831,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit131] -FileName=clib\u8x8_d_s1d15e06.c +FileName=clib\u8x8_d_pcf8814_hx1230.c CompileCpp=0 Folder= Compile=1 @@ -841,7 +841,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit147] -FileName=clib\u8x8_d_ssd1306_96x40.c +FileName=clib\u8x8_d_ssd1306_96x16.c CompileCpp=0 Folder= Compile=1 @@ -851,7 +851,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit148] -FileName=clib\u8x8_d_ssd1306_128x32.c +FileName=clib\u8x8_d_ssd1306_96x40.c CompileCpp=0 Folder= Compile=1 @@ -861,7 +861,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit149] -FileName=clib\u8x8_d_ssd1306_128x64_noname.c +FileName=clib\u8x8_d_ssd1306_128x32.c CompileCpp=0 Folder= Compile=1 @@ -871,7 +871,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit173] -FileName=clib\u8x8_d_st7920.c +FileName=clib\u8x8_d_st7588.c CompileCpp=0 Folder= Compile=1 @@ -881,7 +881,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit174] -FileName=clib\u8x8_d_st75160.c +FileName=clib\u8x8_d_st7920.c CompileCpp=0 Folder= Compile=1 @@ -891,7 +891,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit175] -FileName=clib\u8x8_d_st75256.c +FileName=clib\u8x8_d_st75160.c CompileCpp=0 Folder= Compile=1 @@ -901,7 +901,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit198] -FileName=clib\u8x8_string.c +FileName=clib\u8x8_setup.c CompileCpp=0 Folder= Compile=1 @@ -911,7 +911,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit199] -FileName=clib\u8x8_u8toa.c +FileName=clib\u8x8_string.c CompileCpp=0 Folder= Compile=1 @@ -921,7 +921,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit200] -FileName=clib\u8x8_u16toa.c +FileName=clib\u8x8_u8toa.c CompileCpp=0 Folder= Compile=1 @@ -960,3 +960,1113 @@ Priority=1000 OverrideBuildCmd=0 BuildCmd= +[Unit82] +FileName=clib\mui.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit83] +FileName=clib\mui.h +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit84] +FileName=clib\mui_u8g2.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit85] +FileName=clib\mui_u8g2.h +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit86] +FileName=clib\u8g2.h +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit87] +FileName=clib\u8g2_bitmap.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit88] +FileName=clib\u8g2_box.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit89] +FileName=clib\u8g2_buffer.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit90] +FileName=clib\u8g2_button.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit91] +FileName=clib\u8g2_circle.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit92] +FileName=clib\u8g2_cleardisplay.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit93] +FileName=clib\u8g2_d_memory.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit94] +FileName=clib\u8g2_d_setup.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit95] +FileName=clib\u8g2_font.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit96] +FileName=clib\u8g2_fonts.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit97] +FileName=clib\u8g2_hvline.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit98] +FileName=clib\u8g2_input_value.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit99] +FileName=clib\u8g2_intersection.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit100] +FileName=clib\u8g2_kerning.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit101] +FileName=clib\u8g2_line.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit102] +FileName=clib\u8g2_ll_hvline.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit103] +FileName=clib\u8g2_message.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit104] +FileName=clib\u8g2_polygon.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit105] +FileName=clib\u8g2_selection_list.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit106] +FileName=clib\u8g2_setup.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit107] +FileName=clib\u8log.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit108] +FileName=clib\u8log_u8g2.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit109] +FileName=clib\u8log_u8x8.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit110] +FileName=clib\u8x8.h +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit111] +FileName=clib\u8x8_8x8.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit112] +FileName=clib\u8x8_byte.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit113] +FileName=clib\u8x8_cad.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit114] +FileName=clib\u8x8_capture.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit115] +FileName=clib\u8x8_d_a2printer.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit116] +FileName=clib\u8x8_d_gp1247ai.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit117] +FileName=clib\u8x8_d_gp1287ai.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit118] +FileName=clib\u8x8_d_gu800.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit119] +FileName=clib\u8x8_d_hd44102.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit120] +FileName=clib\u8x8_d_il3820_296x128.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit121] +FileName=clib\u8x8_d_ist3020.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit122] +FileName=clib\u8x8_d_ist3088.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit123] +FileName=clib\u8x8_d_ist7920.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit124] +FileName=clib\u8x8_d_ks0108.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit125] +FileName=clib\u8x8_d_lc7981.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit126] +FileName=clib\u8x8_d_ld7032_60x32.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit127] +FileName=clib\u8x8_d_ls013b7dh03.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit128] +FileName=clib\u8x8_d_max7219.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit129] +FileName=clib\u8x8_d_pcd8544_84x48.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit130] +FileName=clib\u8x8_d_pcf8812.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit132] +FileName=clib\u8x8_d_s1d15e06.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit133] +FileName=clib\u8x8_d_s1d15721.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit134] +FileName=clib\u8x8_d_sbn1661.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit135] +FileName=clib\u8x8_d_sdl_128x64.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit136] +FileName=clib\u8x8_d_sed1330.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit137] +FileName=clib\u8x8_d_sh1106_64x32.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit138] +FileName=clib\u8x8_d_sh1106_72x40.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit139] +FileName=clib\u8x8_d_sh1107.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit140] +FileName=clib\u8x8_d_sh1108.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit141] +FileName=clib\u8x8_d_sh1122.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit142] +FileName=clib\u8x8_d_ssd1305.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit143] +FileName=clib\u8x8_d_ssd1306_48x64.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit144] +FileName=clib\u8x8_d_ssd1306_64x32.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit145] +FileName=clib\u8x8_d_ssd1306_64x48.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit146] +FileName=clib\u8x8_d_ssd1306_72x40.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit150] +FileName=clib\u8x8_d_ssd1306_128x64_noname.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit151] +FileName=clib\u8x8_d_ssd1306_2040x16.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit152] +FileName=clib\u8x8_d_ssd1309.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit153] +FileName=clib\u8x8_d_ssd1316.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit154] +FileName=clib\u8x8_d_ssd1317.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit155] +FileName=clib\u8x8_d_ssd1318.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit156] +FileName=clib\u8x8_d_ssd1320.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit157] +FileName=clib\u8x8_d_ssd1322.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit158] +FileName=clib\u8x8_d_ssd1325.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit159] +FileName=clib\u8x8_d_ssd1326.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit160] +FileName=clib\u8x8_d_ssd1327.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit161] +FileName=clib\u8x8_d_ssd1329.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit162] +FileName=clib\u8x8_d_ssd1606_172x72.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit163] +FileName=clib\u8x8_d_ssd1607_200x200.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit164] +FileName=clib\u8x8_d_st7511.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit165] +FileName=clib\u8x8_d_st7528.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit166] +FileName=clib\u8x8_d_st7565.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit167] +FileName=clib\u8x8_d_st7567.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit168] +FileName=clib\u8x8_d_st7571.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit169] +FileName=clib\u8x8_d_st7586s_erc240160.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit170] +FileName=clib\u8x8_d_st7586s_jlx384160.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit171] +FileName=clib\u8x8_d_st7586s_s028hn118a.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit172] +FileName=clib\u8x8_d_st7586s_ymc240160.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit176] +FileName=clib\u8x8_d_st75256.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit177] +FileName=clib\u8x8_d_st75320.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit178] +FileName=clib\u8x8_d_stdio.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit179] +FileName=clib\u8x8_d_t6963.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit180] +FileName=clib\u8x8_d_uc1601.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit181] +FileName=clib\u8x8_d_uc1604.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit182] +FileName=clib\u8x8_d_uc1608.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit183] +FileName=clib\u8x8_d_uc1609.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit184] +FileName=clib\u8x8_d_uc1610.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit185] +FileName=clib\u8x8_d_uc1611.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit186] +FileName=clib\u8x8_d_uc1617.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit187] +FileName=clib\u8x8_d_uc1638.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit188] +FileName=clib\u8x8_d_uc1701_dogs102.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit189] +FileName=clib\u8x8_d_uc1701_mini12864.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit190] +FileName=clib\u8x8_debounce.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit191] +FileName=clib\u8x8_display.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit192] +FileName=clib\u8x8_fonts.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit193] +FileName=clib\u8x8_gpio.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit194] +FileName=clib\u8x8_input_value.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit195] +FileName=clib\u8x8_message.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit196] +FileName=clib\u8x8_sdl_key.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit197] +FileName=clib\u8x8_selection_list.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit201] +FileName=clib\u8x8_u16toa.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit202] +FileName=..\..\uCNC\src\modules\graphic_display\graphic_display.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + diff --git a/platformio.ini b/platformio.ini index 1da7f9a56..885467301 100644 --- a/platformio.ini +++ b/platformio.ini @@ -11,7 +11,7 @@ [platformio] include_dir=uCNC src_dir=uCNC -default_envs = uno, ramps14, rambo, arduinoM0, bluepill_f103c8, blackpill_f401cc, d1, re_arm, d1_r32, rpi_pico_w +default_envs = AVR-UNO, AVR-MEGA2560-RAMPS-V1_4, AVR-RAMBO, SAMD21-Wemos-M0, STM32F1-Bluepill-F103C8, STM32F4-Blackpill-F401CC, ESP8266-Wemos-D1-R2, LPC176X-RE-ARM, ESP32-Wemos-D1-R32, RP2040-PICO-W extra_configs = uCNC/src/hal/boards/avr/avr.ini uCNC/src/hal/boards/samd21/samd21.ini diff --git a/uCNC/src/README.md b/uCNC/src/README.md index 0aff6bff1..946a3ce56 100644 --- a/uCNC/src/README.md +++ b/uCNC/src/README.md @@ -42,7 +42,7 @@ __NOTE__: Not all event hooks might be listed here. To find all available event | gcode_before_motion | gcode_exec_args_t* | ENABLE_PARSER_MODULES | Fires before a motion group command is executed (G0, G1, G2, etc...). Arg is a pointer to a gcode_exec_args_t struct | | gcode_after_motion | gcode_exec_args_t* | ENABLE_PARSER_MODULES | Fires after a motion group command is executed (G0, G1, G2, etc...). Arg is a pointer to a gcode_exec_args_t struct | | grbl_cmd | grbl_cmd_args_t* | ENABLE_PARSER_MODULES | Fires when a custom/unknown '$' grbl type command is received. Arg is a pointer to a grbl_cmd_args_t struct | -| parse_token | NULL | ENABLE_PARSER_MODULES | Fires when a custom/unknown token/char is received for further processing | +| parse_token | NULL | ENABLE_PARSER_MODULES | Fires when a custom/unknown token/uint8_t is received for further processing | | parser_get_modes | uint8_t * | ENABLE_PARSER_MODULES | Fires when $G command is issued and the active modal states array is being requested (can be used to modify the active modes with extended gcodes). Arg is a pointer to an uint8_t array with the parser motion groups current values | | parser_reset | NULL | ENABLE_PARSER_MODULES | Fires on parser reset | | cnc_reset | NULL | ENABLE_MAIN_LOOP_MODULES | Fires when µCNC resets | @@ -88,7 +88,7 @@ gcode_parse_args_t* - Pointer to a struct of type gcode_parse_args_t. The gcode_ ``` typedef struct gcode_parse_args_ { - unsigned char word; // This is the GCode word being parsed (usually 'G' or 'M') + uint8_t word; // This is the GCode word being parsed (usually 'G' or 'M') uint8_t code; // This is the GCode word argument converted to uint8_t format (example 98) uint8_t error; // The parser current error code (STATUS_GCODE_EXTENDED_UNSUPPORTED) float value; // This is the actual GCode word argument parsed as float. Useful if code has mantissa or is bigger then 255 (example 98.1) @@ -123,9 +123,9 @@ grbl_cmd_args_t* - Pointer to a struct of type grbl_cmd_args_t. The grbl_cmd_arg typedef struct grbl_cmd_args_ { uint8_t *error; // current parser error state - unsigned char *cmd; // pointer to the command string + uint8_t *cmd; // pointer to the command string uint8_t len; // command string length - char next_char; // next char to be read + uint8_t next_char; // next uint8_t to be read } grbl_cmd_args_t; ``` diff --git a/uCNC/src/cnc.c b/uCNC/src/cnc.c index c33bc50b0..cd62ac3f0 100644 --- a/uCNC/src/cnc.c +++ b/uCNC/src/cnc.c @@ -126,7 +126,7 @@ void cnc_run(void) // tries to reset. If fails jumps to error while (cnc_unlock(false) != UNLOCK_ERROR) { - serial_select(SERIAL_UART); + // serial_select(SERIAL_UART); cnc_state.loop_state = LOOP_RUNNING; do @@ -150,7 +150,7 @@ void cnc_run(void) do { - if (!serial_rx_is_empty()) + if (serial_available()) { if (serial_getc() == EOL) { @@ -174,7 +174,7 @@ bool cnc_exec_cmd(void) uint32_t exec_time; #endif // process gcode commands - if (!serial_rx_is_empty()) + if (serial_available()) { uint8_t error = 0; // protocol_echo(); @@ -182,7 +182,7 @@ bool cnc_exec_cmd(void) switch (c) { case OVF: - serial_rx_clear(); + serial_clear(); error = STATUS_OVERFLOW; break; case EOL: // not necessary but faster to catch empty lines and windows newline (CR+LF) @@ -597,7 +597,7 @@ void cnc_reset(void) cnc_state.alarm = EXEC_ALARM_NOALARM; // clear all systems - serial_rx_clear(); + serial_clear(); itp_clear(); planner_clear(); kinematics_init(); @@ -610,6 +610,7 @@ void cnc_reset(void) #ifdef ENABLE_MAIN_LOOP_MODULES EVENT_INVOKE(cnc_reset, NULL); #endif + serial_broadcast(true); protocol_send_string(MSG_STARTUP); } @@ -1029,9 +1030,20 @@ static void cnc_io_dotasks(void) void cnc_run_startup_blocks(void) { - serial_select(SERIAL_N0); - cnc_exec_cmd(); - serial_select(SERIAL_N1); - cnc_exec_cmd(); - serial_select(SERIAL_UART); + serial_broadcast(true); + if (settings_check_startup_gcode(STARTUP_BLOCK0_ADDRESS_OFFSET)) + { + serial_stream_eeprom(STARTUP_BLOCK0_ADDRESS_OFFSET); + cnc_exec_cmd(); + } + + serial_broadcast(true); + if (settings_check_startup_gcode(STARTUP_BLOCK1_ADDRESS_OFFSET)) + { + serial_stream_eeprom(STARTUP_BLOCK1_ADDRESS_OFFSET); + cnc_exec_cmd(); + } + + // reset streams + serial_stream_change(NULL); } diff --git a/uCNC/src/core/motion_control.c b/uCNC/src/core/motion_control.c index d366fd45e..3b2edc8a8 100644 --- a/uCNC/src/core/motion_control.c +++ b/uCNC/src/core/motion_control.c @@ -705,7 +705,7 @@ uint8_t mc_home_axis(uint8_t axis_mask, uint8_t axis_limit) motion_data_t block_data = {0}; uint8_t limits_flags; #ifdef ENABLE_MOTION_CONTROL_MODULES - homing_status_t homing_status __attribute__((__cleanup__(mc_home_axis_finalize))) = {axis, axis_limit, STATUS_OK}; + homing_status_t homing_status __attribute__((__cleanup__(mc_home_axis_finalize))) = {axis_mask, axis_limit, STATUS_OK}; #endif #ifdef ENABLE_G39_H_MAPPING diff --git a/uCNC/src/core/parser.c b/uCNC/src/core/parser.c index b3b8c5424..99508ba67 100644 --- a/uCNC/src/core/parser.c +++ b/uCNC/src/core/parser.c @@ -60,12 +60,12 @@ static float g92permanentoffset[AXIS_COUNT]; static int32_t rt_probe_step_pos[STEPPER_COUNT]; static float parser_last_pos[AXIS_COUNT]; -static unsigned char parser_get_next_preprocessed(bool peek); -FORCEINLINE static void parser_get_comment(unsigned char start_char); -FORCEINLINE static uint8_t parser_get_token(unsigned char *word, float *value); +static uint8_t parser_get_next_preprocessed(bool peek); +FORCEINLINE static void parser_get_comment(uint8_t start_char); +FORCEINLINE static uint8_t parser_get_token(uint8_t *word, float *value); FORCEINLINE static uint8_t parser_gcode_word(uint8_t code, uint8_t mantissa, parser_state_t *new_state, parser_cmd_explicit_t *cmd); FORCEINLINE static uint8_t parser_mcode_word(uint8_t code, uint8_t mantissa, parser_state_t *new_state, parser_cmd_explicit_t *cmd); -FORCEINLINE static uint8_t parser_letter_word(unsigned char c, float value, uint8_t mantissa, parser_words_t *words, parser_cmd_explicit_t *cmd); +FORCEINLINE static uint8_t parser_letter_word(uint8_t c, float value, uint8_t mantissa, parser_words_t *words, parser_cmd_explicit_t *cmd); static uint8_t parse_grbl_exec_code(uint8_t code); static uint8_t parser_fetch_command(parser_state_t *new_state, parser_words_t *words, parser_cmd_explicit_t *cmd); static uint8_t parser_validate_command(parser_state_t *new_state, parser_words_t *words, parser_cmd_explicit_t *cmd); @@ -152,7 +152,7 @@ void parser_init(void) uint8_t parser_read_command(void) { uint8_t error = STATUS_OK; - unsigned char c = serial_peek(); + uint8_t c = serial_peek(); if (c == '$') { @@ -307,8 +307,8 @@ void parser_update_probe_pos(void) static uint8_t parser_grbl_command(void) { serial_getc(); // eat $ - unsigned char c = serial_peek(); - unsigned char grbl_cmd_str[GRBL_CMD_MAX_LEN + 1]; + uint8_t c = serial_peek(); + uint8_t grbl_cmd_str[GRBL_CMD_MAX_LEN + 1]; uint8_t grbl_cmd_len = 0; // if not IDLE @@ -330,7 +330,7 @@ static uint8_t parser_grbl_command(void) do { - c = serial_getc(); + c = serial_peek(); // toupper if (c >= 'a' && c <= 'z') { @@ -339,8 +339,14 @@ static uint8_t parser_grbl_command(void) if (!(c >= 'A' && c <= 'Z')) { + if (c < '0' || c > '9' || grbl_cmd_len) // replaces old ungetc + { + serial_getc(); + } break; } + + serial_getc(); grbl_cmd_str[grbl_cmd_len++] = c; } while ((grbl_cmd_len < GRBL_CMD_MAX_LEN)); @@ -377,7 +383,7 @@ static uint8_t parser_grbl_command(void) { float val = 0; setting_offset_t setting_num = 0; - serial_ungetc(); + // serial_ungetc(); error = parser_get_float(&val); if (!error) { @@ -444,24 +450,27 @@ static uint8_t parser_grbl_command(void) return STATUS_INVALID_STATEMENT; } + settings_save_startup_gcode(block_address); + // run startup block + serial_broadcast(true); + serial_stream_eeprom(block_address); error = parser_fetch_command(&next_state, &words, &cmd); - if (error) + if (error == STATUS_OK) { - return error; + error = parser_validate_command(&next_state, &words, &cmd); } - error = parser_validate_command(&next_state, &words, &cmd); - if (error) + + serial_broadcast(false); + // reset streams + serial_stream_change(NULL); + + if (error != STATUS_OK) { - return error; + // the Gcode is not valid then erase the startup block + mcu_eeprom_putc(block_address, 0); } - // everything ok reverts string and saves it - do - { - serial_ungetc(); - } while (serial_peek() != '='); - serial_getc(); - settings_save_startup_gcode(block_address); - return STATUS_OK; + + return error; case EOL: return GRBL_SEND_STARTUP_BLOCKS; } @@ -537,7 +546,7 @@ static uint8_t parser_grbl_command(void) } #ifdef BOARD_HAS_CUSTOM_SYSTEM_COMMANDS - if (mcu_custom_grbl_cmd((char *)grbl_cmd_str, grbl_cmd_len, c) == STATUS_OK) + if (mcu_custom_grbl_cmd((uint8_t *)grbl_cmd_str, grbl_cmd_len, c) == STATUS_OK) { return STATUS_OK; } @@ -659,10 +668,9 @@ static uint8_t parser_fetch_command(parser_state_t *new_state, parser_words_t *w uint8_t wordcount = 0; for (;;) { - unsigned char word = 0; + uint8_t word = 0; float value = 0; - // this flushes leading white chars and also takes care of processing comments - parser_get_next_preprocessed(true); + #ifdef ECHO_CMD if (!wordcount) { @@ -1849,7 +1857,7 @@ uint8_t parser_get_float(float *value) uint8_t fpcount = 0; uint8_t result = NUMBER_UNDEF; - unsigned char c = parser_get_next_preprocessed(true); + uint8_t c = parser_get_next_preprocessed(true); *value = 0; @@ -1945,7 +1953,7 @@ uint8_t parser_get_float(float *value) */ #define COMMENT_OK 1 #define COMMENT_NOTOK 2 -static void parser_get_comment(unsigned char start_char) +static void parser_get_comment(uint8_t start_char) { uint8_t comment_end = 0; #ifdef PROCESS_COMMENTS @@ -1953,7 +1961,7 @@ static void parser_get_comment(unsigned char start_char) #endif for (;;) { - unsigned char c = serial_peek(); + uint8_t c = serial_peek(); switch (c) { // case '(': //error under RS274NGC (commented for Grbl compatibility) @@ -2011,11 +2019,12 @@ static void parser_get_comment(unsigned char start_char) } } -static uint8_t parser_get_token(unsigned char *word, float *value) +static uint8_t parser_get_token(uint8_t *word, float *value) { - unsigned char c = serial_getc(); + // this flushes leading white chars and also takes care of processing comments + uint8_t c = parser_get_next_preprocessed(false); - // if other char starts tokenization + // if other uint8_t starts tokenization if (c >= 'a' && c <= 'z') { c -= 32; // uppercase @@ -2032,7 +2041,7 @@ static uint8_t parser_get_token(unsigned char *word, float *value) #ifdef ECHO_CMD serial_putc(c); #endif - if (c >= 'A' && c <= 'Z') // invalid recognized char + if (c >= 'A' && c <= 'Z') // invalid recognized uint8_t { if (!parser_get_float(value)) { @@ -2341,7 +2350,7 @@ static uint8_t parser_mcode_word(uint8_t code, uint8_t mantissa, parser_state_t return STATUS_OK; } -static uint8_t parser_letter_word(unsigned char c, float value, uint8_t mantissa, parser_words_t *words, parser_cmd_explicit_t *cmd) +static uint8_t parser_letter_word(uint8_t c, float value, uint8_t mantissa, parser_words_t *words, parser_cmd_explicit_t *cmd) { uint16_t new_words = cmd->words; switch (c) @@ -2492,7 +2501,7 @@ static uint8_t parser_letter_word(unsigned char c, float value, uint8_t mantissa #endif break; default: - if (c >= 'A' && c <= 'Z') // invalid recognized char + if (c >= 'A' && c <= 'Z') // invalid recognized uint8_t { return STATUS_GCODE_UNUSED_WORDS; } @@ -2509,9 +2518,9 @@ static uint8_t parser_letter_word(unsigned char c, float value, uint8_t mantissa return STATUS_OK; } -static unsigned char parser_get_next_preprocessed(bool peek) +static uint8_t parser_get_next_preprocessed(bool peek) { - unsigned char c = serial_peek(); + uint8_t c = serial_peek(); while (c == ' ' || c == '(' || c == ';') { @@ -2533,7 +2542,7 @@ static unsigned char parser_get_next_preprocessed(bool peek) static void parser_discard_command(void) { - unsigned char c = '@'; + uint8_t c = '@'; #ifdef ECHO_CMD serial_putc(c); #endif diff --git a/uCNC/src/core/parser.h b/uCNC/src/core/parser.h index 4d542ab4d..8ef555e8d 100644 --- a/uCNC/src/core/parser.h +++ b/uCNC/src/core/parser.h @@ -292,7 +292,7 @@ extern "C" // generates a default delegate, event and handler hook typedef struct gcode_parse_args_ { - unsigned char word; + uint8_t word; uint8_t code; uint8_t* error; float value; @@ -328,9 +328,9 @@ extern "C" typedef struct grbl_cmd_args_ { uint8_t *error; - unsigned char *cmd; + uint8_t *cmd; uint8_t len; - char next_char; + uint8_t next_char; } grbl_cmd_args_t; DECL_EVENT_HANDLER(grbl_cmd); diff --git a/uCNC/src/hal/boards/avr/avr.ini b/uCNC/src/hal/boards/avr/avr.ini index f651af70e..38759aae2 100644 --- a/uCNC/src/hal/boards/avr/avr.ini +++ b/uCNC/src/hal/boards/avr/avr.ini @@ -11,47 +11,47 @@ extra_scripts = avr_compiler.py ; debug_tool = simavr debug_build_flags = -Og -g3 -ggdb3 -gdwarf-2 build_flags = ${common.build_flags} -mcall-prologues -mrelax -flto -fno-fat-lto-objects -fno-tree-scev-cprop -Wl,--relax -lib_ignore = EEPROM, SPI, Wire +; lib_ignore = EEPROM, SPI, Wire [atmega328p] extends = common_avr board = uno ;saves a bit of flash -build_flags = ${common_avr.build_flags} -D DISABLE_SETTINGS_MODULES +build_flags = ${common_avr.build_flags} -D DISABLE_SETTINGS_MODULES -D DISABLE_MULTISTREAM_SERIAL -[env:uno] +[env:AVR-UNO] extends = atmega328p build_flags = ${atmega328p.build_flags} -D BOARD=BOARD_UNO -[env:uno_shield_v3] +[env:AVR-CNC-Shield-V3] extends = atmega328p build_flags = ${atmega328p.build_flags} -D BOARD=BOARD_UNO_SHIELD_V3 -[env:x_controller] +[env:AVR-X-Controller] extends = atmega328p build_flags = ${atmega328p.build_flags} -D BOARD=BOARD_X_CONTROLLER -[env:mks_dlc] +[env:AVR-MKS-DLC] extends = common_avr board_build.f_cpu = 20000000UL build_flags = ${atmega328p.build_flags} -D BOARD=BOARD_MKS_DLC -[env:ramps14] +[env:AVR-MEGA2560-RAMPS-V1_4] extends = common_avr board = megaatmega2560 build_flags = ${common_avr.build_flags} -D BOARD=BOARD_RAMPS14 -[env:ramps14mirror] -extends = common_avr -board = megaatmega2560 -build_flags = ${common_avr.build_flags} -D BOARD=BOARD_RAMPS14_MIRROR +; [env:ramps14mirror] +; extends = common_avr +; board = megaatmega2560 +; build_flags = ${common_avr.build_flags} -D BOARD=BOARD_RAMPS14_MIRROR -[env:mks_gen_l_v1] +[env:AVR-MKS-GEN-L-V1] extends = common_avr board = megaatmega2560 build_flags = ${common_avr.build_flags} -D BOARD=BOARD_MKS_GEN_L_V1 -[env:rambo] +[env:AVR-RAMBO] extends = common_avr board = megaatmega2560 build_flags = ${common_avr.build_flags} -D BOARD=BOARD_RAMBO14 diff --git a/uCNC/src/hal/boards/esp32/esp32.ini b/uCNC/src/hal/boards/esp32/esp32.ini index e7ea7895d..0aea2c33e 100644 --- a/uCNC/src/hal/boards/esp32/esp32.ini +++ b/uCNC/src/hal/boards/esp32/esp32.ini @@ -7,40 +7,47 @@ platform = espressif32 framework = arduino board = esp32dev ; build_src_filter = +<*>- -build_flags = -mlongcalls -Wno-frame-address -ffunction-sections -fdata-sections -ggdb -Os -freorder-blocks -Wwrite-strings -fstack-protector -fstrict-volatile-bitfields -Wall -fno-jump-tables -fno-tree-switch-conversion -std=gnu++11 -fexceptions -MMD -c -DENABLE_WIFI -DENABLE_BLUETOOTH -DUSE_ARDUINO_EEPROM_LIBRARY -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE +build_flags = -mlongcalls -Wno-frame-address -ffunction-sections -fdata-sections -ggdb -Os -freorder-blocks -Wwrite-strings -fstack-protector -fstrict-volatile-bitfields -Wall -fno-jump-tables -fno-tree-switch-conversion -std=gnu++11 -fexceptions -MMD -c -DUSE_ARDUINO_EEPROM_LIBRARY -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE -DENABLE_WIFI -DENABLE_BLUETOOTH board_build.f_flash = 80000000L board_build.f_cpu = 240000000L board_build.partitions = min_spiffs.csv monitor_filters=esp32_exception_decoder upload_speed = 921600 +lib_deps = SPI, Wire, Wifi, WebServer, HTTPUpdatedServer, BluetoothSerial -[common_esp32_idf] -extends = common_esp32 -framework = arduino, espidf -lib_deps = SPI, Wifi, Wire, WebServer, HTTPUpdatedServer, BluetoothSerial +################## +# Arduino builds # +################## -[env:d1_r32] +[env:ESP32-Wemos-D1-R32] extends = common_esp32 board = wemos_d1_uno32 build_flags = ${common_esp32.build_flags} -DBOARD=BOARD_WEMOS_D1_R32 -[env:mks_tinybee] +[env:ESP32-MKS-DLC32] extends = common_esp32 -build_flags = ${common_esp32.build_flags} -DBOARD=BOARD_MKS_TINYBEE +build_flags = ${common_esp32.build_flags} -DBOARD=BOARD_MKS_DLC32 -[env:mks_dlc32] +[env:ESP32-MKS-TINYBEE] extends = common_esp32 -build_flags = ${common_esp32.build_flags} -DBOARD=BOARD_MKS_DLC32 +build_flags = ${common_esp32.build_flags} -DBOARD=BOARD_MKS_TINYBEE -[env:espidf_d1_r32] -extends = common_esp32_idf +################# +# ESPIDF builds # +################# + +[env:ESP32IDF-Wemos-D1-R32] +extends = common_esp32 +framework = arduino, espidf board = wemos_d1_uno32 -build_flags = ${common_esp32_idf.build_flags} -DBOARD=BOARD_WEMOS_D1_R32 +build_flags = ${common_esp32.build_flags} -DBOARD=BOARD_WEMOS_D1_R32 -[env:espidf_mks_tinybee] -extends = common_esp32_idf -build_flags = ${common_esp32_idf.build_flags} -DBOARD=BOARD_MKS_TINYBEE +[env:ESP32IDF-MKS-DLC32] +extends = common_esp32 +framework = arduino, espidf +build_flags = ${common_esp32.build_flags} -DBOARD=BOARD_MKS_DLC32 -[env:espidf_mks_dlc32] -extends = common_esp32_idf -build_flags = ${common_esp32_idf.build_flags} -DBOARD=BOARD_MKS_DLC32 +[env:ESP32IDF-MKS-TINYBEE] +extends = common_esp32 +framework = arduino, espidf +build_flags = ${common_esp32.build_flags} -DBOARD=BOARD_MKS_TINYBEE diff --git a/uCNC/src/hal/boards/esp8266/esp8266.ini b/uCNC/src/hal/boards/esp8266/esp8266.ini index 80e7d93bf..2deec9412 100644 --- a/uCNC/src/hal/boards/esp8266/esp8266.ini +++ b/uCNC/src/hal/boards/esp8266/esp8266.ini @@ -2,7 +2,7 @@ # ESP8266 Boards # ################## -[env:d1] +[env:ESP8266-Wemos-D1-R2] platform = espressif8266 framework = arduino board = d1 diff --git a/uCNC/src/hal/boards/lpc176x/lpc176x.ini b/uCNC/src/hal/boards/lpc176x/lpc176x.ini index d6af83432..6d00d3b9a 100644 --- a/uCNC/src/hal/boards/lpc176x/lpc176x.ini +++ b/uCNC/src/hal/boards/lpc176x/lpc176x.ini @@ -11,17 +11,17 @@ lib_ldf_mode = off lib_compat_mode = strict build_flags = ${common.build_flags} -D NXP_LPC17xx -D USE_ARDUINO_CDC -[env:re_arm] +[env:LPC176X-RE-ARM] extends = common_lpc176x board = nxp_lpc1768 build_flags = ${common_lpc176x.build_flags} -D BOARD=BOARD_RE_ARM -[env:mks_base_v13] +[env:LPC176X-MKS-BASE-V1_3] extends = common_lpc176x board = nxp_lpc1768 build_flags = ${common_lpc176x.build_flags} -D BOARD=BOARD_MKS_BASE13 -[env:skr_v14_turbo] +[env:LPC176X-SKR-v1_4-TURBO] extends = common_lpc176x board = nxp_lpc1768 build_flags = ${common_lpc176x.build_flags} -D BOARD=BOARD_SKR_V14_TURBO diff --git a/uCNC/src/hal/boards/rp2040/rp2040.ini b/uCNC/src/hal/boards/rp2040/rp2040.ini index 290857ba8..5bbfedb26 100644 --- a/uCNC/src/hal/boards/rp2040/rp2040.ini +++ b/uCNC/src/hal/boards/rp2040/rp2040.ini @@ -18,13 +18,13 @@ board_build.f_cpu = 133000000L ; build_flags = -DUSE_TINYUSB debug_tool = cmsis-dap -[env:rpi_pico] +[env:RP2040-PICO] extends = common_rp2040 board = rpipico lib_ignore = HTTPUpdateServer, LittleFS, WiFi, WebServer, WiFi, SerialBT, DNSServer, Hash build_flags = -DBOARD=BOARD_RPI_PICO -[env:rpi_pico_w] +[env:RP2040-PICO-W] extends = common_rp2040 board = rpipicow build_flags = -DBOARD=BOARD_RPI_PICO_W -DENABLE_WIFI -DENABLE_BLUETOOTH -DPIO_FRAMEWORK_ARDUINO_ENABLE_BLUETOOTH diff --git a/uCNC/src/hal/boards/samd21/samd21.ini b/uCNC/src/hal/boards/samd21/samd21.ini index 6e8d524ef..30ccd4ad6 100644 --- a/uCNC/src/hal/boards/samd21/samd21.ini +++ b/uCNC/src/hal/boards/samd21/samd21.ini @@ -19,12 +19,14 @@ lib_deps = https://github.com/Paciente8159/uCNC-tinyusb.git#v0.15.4 ; load ; monitor reset init -[env:arduinoM0] +[env:SAMD21-Wemos-M0] extends = common_samd21 build_flags = ${common_samd21.build_flags} -D BOARD=BOARD_MZERO board_build.offset = 0x2000 board_upload.offset_address = 0x00002000 -[env:arduinoZero] +[env:SAMD21-Arduino-Zero] extends = common_samd21 build_flags = ${common_samd21.build_flags} -D BOARD=BOARD_ZERO +board_build.offset = 0x4000 +board_upload.offset_address = 0x00004000 diff --git a/uCNC/src/hal/boards/stm32/stm32.ini b/uCNC/src/hal/boards/stm32/stm32.ini index 0ee7cea08..1272c3968 100644 --- a/uCNC/src/hal/boards/stm32/stm32.ini +++ b/uCNC/src/hal/boards/stm32/stm32.ini @@ -5,7 +5,7 @@ [common_stm32] platform = ststm32 ; debug with st-link -upload_protocol = dfu +upload_protocol = cmsis-dap debug_tool = cmsis-dap platform_packages = platformio/tool-openocd debug_build_flags = -Og -g3 -ggdb3 -gdwarf-2 @@ -15,39 +15,42 @@ debug_init_cmds = monitor reset init build_flags = ${common.build_flags} -D HAL_TIM_MODULE_DISABLED -D HAL_EXTI_MODULE_DISABLED -D HAL_UART_MODULE_ONLY lib_deps = https://github.com/Paciente8159/uCNC-tinyusb.git#v0.15.4 -lib_ignore = EEPROM, SPI, Wire +lib_ignore = EEPROM +;, SPI, Wire -[env:bluepill_f103c8] +[env:STM32F1-Bluepill-F103C8] extends = common_stm32 board = bluepill_f103c8 build_flags = ${common_stm32.build_flags} -D BOARD=BOARD_BLUEPILL -DFLASH_SIZE=0x10000UL -[env:bluepill_f103c8_clone] +[env:STM32F1-Bluepill-F103C8-CLONE] extends = common_stm32 board = bluepill_f103c8 build_flags = ${common_stm32.build_flags} -D BOARD=BOARD_BLUEPILL -DFLASH_SIZE=0x10000UL ; uncomment if it's a bluepill clone upload_flags = -c set CPUTAPID 0x2ba01477 -[env:blackpill_f401cc] +[env:STM32F1-MKS-Robin-Nano-V1_2] +extends = common_stm32 +board = genericSTM32F103VE +board_build.offset = 0x7000 +board_upload.offset_address = 0x08007000 +board_build.f_cpu = 72000000L +build_flags = ${common_stm32.build_flags} -D BOARD=BOARD_MKS_ROBIN_NANO_V1_2 + +[env:STM32F4-Blackpill-F401CC] extends = common_stm32 board = blackpill_f401cc +upload_protocol = dfu build_flags = ${common_stm32.build_flags} -D BOARD=BOARD_BLACKPILL -[env:blackpill_f411ce] +[env:STM32F4-Blackpill-F411CE] extends = common_stm32 board = blackpill_f411ce +upload_protocol = dfu build_flags = ${common_stm32.build_flags} -D BOARD=BOARD_BLACKPILL -[env:mks_robin_nano_v1_2] -extends = common_stm32 -board = genericSTM32F103VE -board_build.offset = 0x7000 -board_upload.offset_address = 0x08007000 -board_build.f_cpu = 72000000L -build_flags = ${common_stm32.build_flags} -D BOARD=BOARD_MKS_ROBIN_NANO_V1_2 - -[env:skr_pro_v1_2] +[env:STM32F4-SKR-Pro-V1_2] extends = common_stm32 board = black_f407zg board_build.offset = 0x8000 diff --git a/uCNC/src/hal/mcus/README.md b/uCNC/src/hal/mcus/README.md index 16e7c0fc3..e06e47148 100644 --- a/uCNC/src/hal/mcus/README.md +++ b/uCNC/src/hal/mcus/README.md @@ -313,7 +313,7 @@ Before creating a custom HAL for a custom board/microcontroller the microcontrol #define __romstr__ #endif #ifndef __romarr__ -#define __romarr__ const char +#define __romarr__ const uint8_t #endif #ifndef rom_strptr #define rom_strptr * @@ -771,11 +771,11 @@ Before creating a custom HAL for a custom board/microcontroller the microcontrol #endif #ifdef BOARD_HAS_CUSTOM_SYSTEM_COMMANDS - uint8_t mcu_custom_grbl_cmd(char *grbl_cmd_str, uint8_t grbl_cmd_len, char next_char); + uint8_t mcu_custom_grbl_cmd(uint8_t *grbl_cmd_str, uint8_t grbl_cmd_len, uint8_t next_char); #endif /** - * sends a char either via uart (hardware, software USB CDC, Wifi or BT) + * sends a uint8_t either via uart (hardware, software USB CDC, Wifi or BT) * can be defined either as a function or a macro call * */ #ifndef mcu_putc @@ -862,7 +862,7 @@ Also internally **AT LEAST** these macros need to be defined - use a 1ms interrupt timer or RTC to generate the running time and call `mcu_rtc_cb(uint32_t millis)`. `mcu_dotasks()` **MUST NOT BE CALLED HERE** - - if a hardware communications has events or ISR, the ISR must call `mcu_com_rx_cb(unsigned char c)` with the received char, or if handled internally by library or RTOS send every received char in the buffer through `mcu_com_rx_cb(unsigned char c)`. + - if a hardware communications has events or ISR, the ISR must call `mcu_com_rx_cb(uint8_t c)` with the received uint8_t, or if handled internally by library or RTOS send every received uint8_t in the buffer through `mcu_com_rx_cb(uint8_t c)`. - if interruptible inputs are used they appropriately call mcu_limits_changed_cb(), mcu_controls_changed_cb(), mcu_probe_changed_cb() and mcu_inputs_changed_cb() diff --git a/uCNC/src/hal/mcus/avr/mcu_avr.c b/uCNC/src/hal/mcus/avr/mcu_avr.c index 1fd7e19be..2dc3f534e 100644 --- a/uCNC/src/hal/mcus/avr/mcu_avr.c +++ b/uCNC/src/hal/mcus/avr/mcu_avr.c @@ -372,10 +372,21 @@ ISR(PCINT2_vect, ISR_BLOCK) // input pin on change service routine #endif #ifdef MCU_HAS_UART +DECL_BUFFER(uint8_t, uart_rx, RX_BUFFER_SIZE); ISR(COM_RX_vect, ISR_BLOCK) { #if !defined(DETACH_UART_FROM_MAIN_PROTOCOL) - mcu_com_rx_cb(COM_INREG); + uint8_t c = COM_INREG; + if (mcu_com_rx_cb(c)) + { + if (BUFFER_FULL(uart_rx)) + { + c = OVF; + } + + *(BUFFER_NEXT_FREE(uart_rx)) = c; + BUFFER_STORE(uart_rx); + } #else mcu_uart_rx_cb(COM_INREG); #endif @@ -384,28 +395,39 @@ ISR(COM_RX_vect, ISR_BLOCK) #ifndef UART_TX_BUFFER_SIZE #define UART_TX_BUFFER_SIZE 64 #endif -DECL_BUFFER(uint8_t, uart, UART_TX_BUFFER_SIZE); +DECL_BUFFER(uint8_t, uart_tx, UART_TX_BUFFER_SIZE); ISR(COM_TX_vect, ISR_BLOCK) { - if (BUFFER_EMPTY(uart)) + if (BUFFER_EMPTY(uart_tx)) { CLEARBIT(UCSRB_REG, UDRIE_BIT); return; } uint8_t c; - BUFFER_DEQUEUE(uart, &c); + BUFFER_DEQUEUE(uart_tx, &c); COM_OUTREG = c; } #endif #if defined(MCU_HAS_UART2) +DECL_BUFFER(uint8_t, uart2_rx, RX_BUFFER_SIZE); ISR(COM2_RX_vect, ISR_BLOCK) { #if !defined(DETACH_UART2_FROM_MAIN_PROTOCOL) - mcu_com_rx_cb(COM2_INREG); + uint8_t c = COM2_INREG; + if (mcu_com_rx_cb(c)) + { + if (BUFFER_FULL(uart2_rx)) + { + c = OVF; + } + + *(BUFFER_NEXT_FREE(uart2_rx)) = c; + BUFFER_STORE(uart2_rx); + } #else - mcu_uart2_rx_cb(COM2_INREG); + mcu_uart_rx_cb(COM2_INREG); #endif } @@ -571,13 +593,30 @@ uint8_t mcu_get_servo(uint8_t servo) #ifdef MCU_HAS_UART +uint8_t mcu_uart_getc(void) +{ + uint8_t c = 0; + BUFFER_DEQUEUE(uart_rx, &c); + return c; +} + +uint8_t mcu_uart_available(void) +{ + return BUFFER_READ_AVAILABLE(uart_rx); +} + +void mcu_uart_clear(void) +{ + BUFFER_CLEAR(uart_rx); +} + void mcu_uart_putc(uint8_t c) { - while (BUFFER_FULL(uart)) + while (BUFFER_FULL(uart_tx)) { mcu_uart_flush(); } - BUFFER_ENQUEUE(uart, &c); + BUFFER_ENQUEUE(uart_tx, &c); } void mcu_uart_flush(void) @@ -593,6 +632,23 @@ void mcu_uart_flush(void) #endif #ifdef MCU_HAS_UART2 +uint8_t mcu_uart2_getc(void) +{ + uint8_t c = 0; + BUFFER_DEQUEUE(uart2_rx, &c); + return c; +} + +uint8_t mcu_uart2_available(void) +{ + return BUFFER_READ_AVAILABLE(uart2_rx); +} + +void mcu_uart2_clear(void) +{ + BUFFER_CLEAR(uart2_rx); +} + void mcu_uart2_putc(uint8_t c) { while (BUFFER_FULL(uart2)) diff --git a/uCNC/src/hal/mcus/esp32/esp32_arduino.cpp b/uCNC/src/hal/mcus/esp32/esp32_arduino.cpp index 9f0d2a539..bdf87ff1b 100644 --- a/uCNC/src/hal/mcus/esp32/esp32_arduino.cpp +++ b/uCNC/src/hal/mcus/esp32/esp32_arduino.cpp @@ -73,8 +73,8 @@ typedef struct { uint8_t wifi_on; uint8_t wifi_mode; - char ssid[WIFI_SSID_MAX_LEN]; - char pass[WIFI_SSID_MAX_LEN]; + uint8_t ssid[WIFI_SSID_MAX_LEN]; + uint8_t pass[WIFI_SSID_MAX_LEN]; } wifi_settings_t; uint16_t wifi_settings_offset; @@ -86,15 +86,15 @@ extern "C" #include "../../../cnc.h" #ifdef BOARD_HAS_CUSTOM_SYSTEM_COMMANDS - uint8_t mcu_custom_grbl_cmd(char *grbl_cmd_str, uint8_t grbl_cmd_len, char next_char) + uint8_t mcu_custom_grbl_cmd(uint8_t *grbl_cmd_str, uint8_t grbl_cmd_len, uint8_t next_char) { - char str[64]; - char arg[ARG_MAX_LEN]; - char has_arg = (next_char == '='); + uint8_t str[64]; + uint8_t arg[ARG_MAX_LEN]; + uint8_t has_arg = (next_char == '='); memset(arg, 0, sizeof(arg)); if (has_arg) { - char c = serial_getc(); + uint8_t c = serial_getc(); uint8_t i = 0; while (c) { @@ -108,9 +108,9 @@ extern "C" } #ifdef ENABLE_BLUETOOTH - if (!strncmp(grbl_cmd_str, "BTH", 3)) + if (!strncmp((const char*)grbl_cmd_str, "BTH", 3)) { - if (!strcmp(&grbl_cmd_str[3], "ON")) + if (!strcmp((const char*)&grbl_cmd_str[3], "ON")) { SerialBT.begin(BOARD_NAME); protocol_send_feedback("Bluetooth enabled"); @@ -120,7 +120,7 @@ extern "C" return STATUS_OK; } - if (!strcmp(&grbl_cmd_str[3], "OFF")) + if (!strcmp((const char*)&grbl_cmd_str[3], "OFF")) { SerialBT.end(); protocol_send_feedback("Bluetooth disabled"); @@ -132,35 +132,35 @@ extern "C" } #endif #ifdef ENABLE_WIFI - if (!strncmp(grbl_cmd_str, "WIFI", 4)) + if (!strncmp((const char*)grbl_cmd_str, "WIFI", 4)) { - if (!strcmp(&grbl_cmd_str[4], "ON")) + if (!strcmp((const char*)&grbl_cmd_str[4], "ON")) { WiFi.disconnect(); switch (wifi_settings.wifi_mode) { case 1: WiFi.mode(WIFI_STA); - WiFi.begin(wifi_settings.ssid, wifi_settings.pass); + WiFi.begin((char*)wifi_settings.ssid, (char*)wifi_settings.pass); protocol_send_feedback("Trying to connect to WiFi"); break; case 2: WiFi.mode(WIFI_AP); - WiFi.softAP(BOARD_NAME, wifi_settings.pass); + WiFi.softAP(BOARD_NAME, (char*)wifi_settings.pass); protocol_send_feedback("AP started"); protocol_send_feedback("SSID>" BOARD_NAME); - sprintf(str, "IP>%s", WiFi.softAPIP().toString().c_str()); - protocol_send_feedback(str); + sprintf((char*)str, "IP>%s", WiFi.softAPIP().toString().c_str()); + protocol_send_feedback((const char*)str); break; default: WiFi.mode(WIFI_AP_STA); - WiFi.begin(wifi_settings.ssid, wifi_settings.pass); + WiFi.begin((char*)wifi_settings.ssid, (char*)wifi_settings.pass); protocol_send_feedback("Trying to connect to WiFi"); - WiFi.softAP(BOARD_NAME, wifi_settings.pass); + WiFi.softAP(BOARD_NAME, (char*)wifi_settings.pass); protocol_send_feedback("AP started"); protocol_send_feedback("SSID>" BOARD_NAME); - sprintf(str, "IP>%s", WiFi.softAPIP().toString().c_str()); - protocol_send_feedback(str); + sprintf((char*)str, "IP>%s", WiFi.softAPIP().toString().c_str()); + protocol_send_feedback((const char*)str); break; } @@ -169,7 +169,7 @@ extern "C" return STATUS_OK; } - if (!strcmp(&grbl_cmd_str[4], "OFF")) + if (!strcmp((const char*)&grbl_cmd_str[4], "OFF")) { WiFi.disconnect(); wifi_settings.wifi_on = 0; @@ -177,29 +177,29 @@ extern "C" return STATUS_OK; } - if (!strcmp(&grbl_cmd_str[4], "SSID")) + if (!strcmp((const char*)&grbl_cmd_str[4], "SSID")) { if (has_arg) { - uint8_t len = strlen(arg); + uint8_t len = strlen((const char*)arg); if (len > WIFI_SSID_MAX_LEN) { protocol_send_feedback("WiFi SSID is too long"); } memset(wifi_settings.ssid, 0, sizeof(wifi_settings.ssid)); - strcpy(wifi_settings.ssid, arg); + strcpy((char*)wifi_settings.ssid, (const char*)arg); settings_save(wifi_settings_offset, (uint8_t *)&wifi_settings, sizeof(wifi_settings_t)); protocol_send_feedback("WiFi SSID modified"); } else { - sprintf(str, "SSID>%s", wifi_settings.ssid); - protocol_send_feedback(str); + sprintf((char*)str, "SSID>%s", wifi_settings.ssid); + protocol_send_feedback((const char*)str); } return STATUS_OK; } - if (!strcmp(&grbl_cmd_str[4], "SCAN")) + if (!strcmp((const char*)&grbl_cmd_str[4], "SCAN")) { // Serial.println("[MSG:Scanning Networks]"); protocol_send_feedback("Scanning Networks"); @@ -212,26 +212,26 @@ extern "C" } // print the list of networks seen: - sprintf(str, "%d available networks", numSsid); - protocol_send_feedback(str); + sprintf((char*)str, "%d available networks", numSsid); + protocol_send_feedback((const char*)str); // print the network number and name for each network found: for (int netid = 0; netid < numSsid; netid++) { - sprintf(str, "%d) %s\tSignal: %ddBm", netid, WiFi.SSID(netid).c_str(), WiFi.RSSI(netid)); - protocol_send_feedback(str); + sprintf((char*)str, "%d) %s\tSignal: %ddBm", netid, WiFi.SSID(netid).c_str(), WiFi.RSSI(netid)); + protocol_send_feedback((const char*)str); } return STATUS_OK; } - if (!strcmp(&grbl_cmd_str[4], "SAVE")) + if (!strcmp((const char*)&grbl_cmd_str[4], "SAVE")) { settings_save(wifi_settings_offset, (uint8_t *)&wifi_settings, sizeof(wifi_settings_t)); protocol_send_feedback("WiFi settings saved"); return STATUS_OK; } - if (!strcmp(&grbl_cmd_str[4], "RESET")) + if (!strcmp((const char*)&grbl_cmd_str[4], "RESET")) { settings_erase(wifi_settings_offset, sizeof(wifi_settings_t)); memset(&wifi_settings, 0, sizeof(wifi_settings_t)); @@ -239,11 +239,11 @@ extern "C" return STATUS_OK; } - if (!strcmp(&grbl_cmd_str[4], "MODE")) + if (!strcmp((const char*)&grbl_cmd_str[4], "MODE")) { if (has_arg) { - int mode = atoi(arg) - 1; + int mode = atoi((const char*)arg) - 1; if (mode >= 0) { wifi_settings.wifi_mode = mode; @@ -269,38 +269,38 @@ extern "C" return STATUS_OK; } - if (!strcmp(&grbl_cmd_str[4], "PASS") && has_arg) + if (!strcmp((const char*)&grbl_cmd_str[4], "PASS") && has_arg) { - uint8_t len = strlen(arg); + uint8_t len = strlen((const char*)arg); if (len > WIFI_SSID_MAX_LEN) { protocol_send_feedback("WiFi pass is too long"); } memset(wifi_settings.pass, 0, sizeof(wifi_settings.pass)); - strcpy(wifi_settings.pass, arg); + strcpy((char*)wifi_settings.pass, (const char*)arg); protocol_send_feedback("WiFi password modified"); return STATUS_OK; } - if (!strcmp(&grbl_cmd_str[4], "IP")) + if (!strcmp((const char*)&grbl_cmd_str[4], "IP")) { if (wifi_settings.wifi_on) { switch (wifi_settings.wifi_mode) { case 1: - sprintf(str, "STA IP>%s", WiFi.softAPIP().toString().c_str()); - protocol_send_feedback(str); - sprintf(str, "AP IP>%s", WiFi.softAPIP().toString().c_str()); - protocol_send_feedback(str); + sprintf((char*)str, "STA IP>%s", WiFi.softAPIP().toString().c_str()); + protocol_send_feedback((const char*)str); + sprintf((char*)str, "AP IP>%s", WiFi.softAPIP().toString().c_str()); + protocol_send_feedback((const char*)str); break; case 2: - sprintf(str, "IP>%s", WiFi.softAPIP().toString().c_str()); - protocol_send_feedback(str); + sprintf((char*)str, "IP>%s", WiFi.softAPIP().toString().c_str()); + protocol_send_feedback((const char*)str); break; default: - sprintf(str, "IP>%s", WiFi.softAPIP().toString().c_str()); - protocol_send_feedback(str); + sprintf((char*)str, "IP>%s", WiFi.softAPIP().toString().c_str()); + protocol_send_feedback((const char*)str); break; } } @@ -322,7 +322,7 @@ extern "C" #ifdef ENABLE_WIFI static uint32_t next_info = 30000; static bool connected = false; - char str[64]; + uint8_t str[64]; if (!wifi_settings.wifi_on) { @@ -345,10 +345,10 @@ extern "C" { connected = true; protocol_send_feedback("Connected to WiFi"); - sprintf(str, "SSID>%s", wifi_settings.ssid); - protocol_send_feedback(str); - sprintf(str, "IP>%s", WiFi.localIP().toString().c_str()); - protocol_send_feedback(str); + sprintf((char*)str, "SSID>%s", wifi_settings.ssid); + protocol_send_feedback((const char*)str); + sprintf((char*)str, "IP>%s", WiFi.localIP().toString().c_str()); + protocol_send_feedback((const char*)str); } if (server.hasClient()) @@ -417,33 +417,52 @@ extern "C" #ifndef WIFI_TX_BUFFER_SIZE #define WIFI_TX_BUFFER_SIZE 64 #endif - DECL_BUFFER(uint8_t, wifi, WIFI_TX_BUFFER_SIZE); + DECL_BUFFER(uint8_t, wifi_rx, RX_BUFFER_SIZE); + DECL_BUFFER(uint8_t, wifi_tx, WIFI_TX_BUFFER_SIZE); + + uint8_t mcu_wifi_getc(void) + { + uint8_t c = 0; + BUFFER_DEQUEUE(wifi_rx, &c); + return c; + } + + uint8_t mcu_wifi_available(void) + { + return BUFFER_READ_AVAILABLE(wifi_rx); + } + + void mcu_wifi_clear(void) + { + BUFFER_CLEAR(wifi_rx); + } + void mcu_wifi_putc(uint8_t c) { - while (BUFFER_FULL(wifi)) + while (BUFFER_FULL(wifi_tx)) { mcu_wifi_flush(); } - BUFFER_ENQUEUE(wifi, &c); + BUFFER_ENQUEUE(wifi_tx, &c); } void mcu_wifi_flush(void) { if (esp32_wifi_clientok()) { - while (!BUFFER_EMPTY(wifi)) + while (!BUFFER_EMPTY(wifi_tx)) { uint8_t tmp[WIFI_TX_BUFFER_SIZE]; uint8_t r; - BUFFER_READ(wifi, tmp, WIFI_TX_BUFFER_SIZE, r); + BUFFER_READ(wifi_tx, tmp, WIFI_TX_BUFFER_SIZE, r); serverClient.write(tmp, r); } } else { // no client (discard) - BUFFER_CLEAR(wifi); + BUFFER_CLEAR(wifi_tx); } } #endif @@ -452,26 +471,45 @@ extern "C" #ifndef BLUETOOTH_TX_BUFFER_SIZE #define BLUETOOTH_TX_BUFFER_SIZE 64 #endif - DECL_BUFFER(uint8_t, bluetooth, BLUETOOTH_TX_BUFFER_SIZE); + DECL_BUFFER(uint8_t, bt_rx, RX_BUFFER_SIZE); + DECL_BUFFER(uint8_t, bt_tx, BLUETOOTH_TX_BUFFER_SIZE); + + uint8_t mcu_bt_getc(void) + { + uint8_t c = 0; + BUFFER_DEQUEUE(bt_rx, &c); + return c; + } + + uint8_t mcu_bt_available(void) + { + return BUFFER_READ_AVAILABLE(bt_rx); + } + + void mcu_bt_clear(void) + { + BUFFER_CLEAR(bt_rx); + } + void mcu_bt_putc(uint8_t c) { - while (BUFFER_FULL(bluetooth)) + while (BUFFER_FULL(bt_tx)) { mcu_bt_flush(); } - BUFFER_ENQUEUE(bluetooth, &c); + BUFFER_ENQUEUE(bt_tx, &c); } void mcu_bt_flush(void) { if (SerialBT.hasClient()) { - while (!BUFFER_EMPTY(bluetooth)) + while (!BUFFER_EMPTY(bt_tx)) { uint8_t tmp[BLUETOOTH_TX_BUFFER_SIZE]; uint8_t r; - BUFFER_READ(bluetooth, tmp, BLUETOOTH_TX_BUFFER_SIZE, r); + BUFFER_READ(bt_tx, tmp, BLUETOOTH_TX_BUFFER_SIZE, r); SerialBT.write(tmp, r); SerialBT.flush(); } @@ -479,19 +517,19 @@ extern "C" else { // no client (discard) - BUFFER_CLEAR(bluetooth); + BUFFER_CLEAR(bt_tx); } } #endif - unsigned char esp32_wifi_bt_read(void) + uint8_t esp32_wifi_bt_read(void) { #ifdef ENABLE_WIFI if (esp32_wifi_clientok()) { if (serverClient.available() > 0) { - return (unsigned char)serverClient.read(); + return (uint8_t)serverClient.read(); } } #endif @@ -499,11 +537,11 @@ extern "C" #ifdef ENABLE_BLUETOOTH if (SerialBT.hasClient()) { - return (unsigned char)SerialBT.read(); + return (uint8_t)SerialBT.read(); } #endif - return (unsigned char)0; + return (uint8_t)0; } bool esp32_wifi_bt_rx_ready(void) @@ -532,7 +570,17 @@ extern "C" { esp_task_wdt_reset(); #ifndef DETACH_BLUETOOTH_FROM_MAIN_PROTOCOL - mcu_com_rx_cb((uint8_t)SerialBT.read()); + uint8_t c = SerialBT.read(); + if (mcu_com_rx_cb(c)) + { + if (BUFFER_FULL(bt_rx)) + { + c = OVF; + } + + *(BUFFER_NEXT_FREE(bt_rx)) = c; + BUFFER_STORE(bt_rx); + } #else mcu_bt_rx_cb((uint8_t)SerialBT.read()); #endif @@ -547,7 +595,17 @@ extern "C" { esp_task_wdt_reset(); #ifndef DETACH_WIFI_FROM_MAIN_PROTOCOL - mcu_com_rx_cb((uint8_t)serverClient.read()); + uint8_t c = serverClient.read(); + if (mcu_com_rx_cb(c)) + { + if (BUFFER_FULL(wifi_rx)) + { + c = OVF; + } + + *(BUFFER_NEXT_FREE(wifi_rx)) = c; + BUFFER_STORE(wifi_rx); + } #else mcu_wifi_rx_cb((uint8_t)serverClient.read()); #endif diff --git a/uCNC/src/hal/mcus/esp32/mcu_esp32.c b/uCNC/src/hal/mcus/esp32/mcu_esp32.c index 4c35dfdba..3d70a8b3b 100644 --- a/uCNC/src/hal/mcus/esp32/mcu_esp32.c +++ b/uCNC/src/hal/mcus/esp32/mcu_esp32.c @@ -47,7 +47,7 @@ volatile static uint32_t esp32_io_counter_reload; hw_timer_t *esp32_step_timer; void esp32_wifi_bt_init(void); -void esp32_wifi_bt_flush(char *buffer); +void esp32_wifi_bt_flush(uint8_t *buffer); void esp32_wifi_bt_process(void); #ifndef FLASH_EEPROM_SIZE @@ -599,30 +599,49 @@ uint8_t mcu_get_pwm(uint8_t pwm) /*UART*/ /** - * sends a char either via uart (hardware, software or USB virtual COM port) + * sends a uint8_t either via uart (hardware, software or USB virtual COM port) * can be defined either as a function or a macro call * */ #ifdef MCU_HAS_UART #ifndef UART_TX_BUFFER_SIZE #define UART_TX_BUFFER_SIZE 64 #endif -DECL_BUFFER(uint8_t, uart, UART_TX_BUFFER_SIZE); +DECL_BUFFER(uint8_t, uart_rx, RX_BUFFER_SIZE); +DECL_BUFFER(uint8_t, uart_tx, UART_TX_BUFFER_SIZE); +uint8_t mcu_uart_getc(void) +{ + uint8_t c = 0; + BUFFER_DEQUEUE(uart_rx, &c); + return c; +} + +uint8_t mcu_uart_available(void) +{ + return BUFFER_READ_AVAILABLE(uart_rx); +} + +void mcu_uart_clear(void) +{ + BUFFER_CLEAR(uart_rx); +} + void mcu_uart_putc(uint8_t c) { - while (BUFFER_FULL(uart)) + while (BUFFER_FULL(uart_tx)) { mcu_uart_flush(); } - BUFFER_ENQUEUE(uart, &c); + BUFFER_ENQUEUE(uart_tx, &c); } + void mcu_uart_flush(void) { - while (!BUFFER_EMPTY(uart)) + while (!BUFFER_EMPTY(uart_tx)) { uint8_t tmp[UART_TX_BUFFER_SIZE]; uint8_t r; - BUFFER_READ(uart, tmp, UART_TX_BUFFER_SIZE, r); + BUFFER_READ(uart_tx, tmp, UART_TX_BUFFER_SIZE, r); uart_write_bytes(UART_PORT, tmp, r); } } @@ -632,24 +651,43 @@ void mcu_uart_flush(void) #ifndef UART2_TX_BUFFER_SIZE #define UART2_TX_BUFFER_SIZE 64 #endif -DECL_BUFFER(uint8_t, uart2, UART2_TX_BUFFER_SIZE); +DECL_BUFFER(uint8_t, uart2_rx, RX_BUFFER_SIZE); +DECL_BUFFER(uint8_t, uart2_tx, UART2_TX_BUFFER_SIZE); + +uint8_t mcu_uart2_getc(void) +{ + uint8_t c = 0; + BUFFER_DEQUEUE(uart2_rx, &c); + return c; +} + +uint8_t mcu_uart2_available(void) +{ + return BUFFER_READ_AVAILABLE(uart2_rx); +} + +void mcu_uart2_clear(void) +{ + BUFFER_CLEAR(uart2_rx); +} + void mcu_uart2_putc(uint8_t c) { - while (BUFFER_FULL(uart2)) + while (BUFFER_FULL(uart2_tx)) { mcu_uart2_flush(); } - BUFFER_ENQUEUE(uart2, &c); + BUFFER_ENQUEUE(uart2_tx, &c); } void mcu_uart2_flush(void) { - while (!BUFFER_EMPTY(uart2)) + while (!BUFFER_EMPTY(uart2_tx)) { uint8_t tmp[UART2_TX_BUFFER_SIZE]; uint8_t r; - BUFFER_READ(uart2, tmp, UART2_TX_BUFFER_SIZE, r); + BUFFER_READ(uart2_tx, tmp, UART2_TX_BUFFER_SIZE, r); uart_write_bytes(UART2_PORT, tmp, r); } } @@ -824,13 +862,23 @@ void mcu_dotasks(void) esp_task_wdt_reset(); // loop through received data - char rxdata[RX_BUFFER_SIZE]; + uint8_t rxdata[RX_BUFFER_SIZE]; int rxlen, i; #ifdef MCU_HAS_UART rxlen = uart_read_bytes(UART_PORT, rxdata, RX_BUFFER_CAPACITY, 0); for (i = 0; i < rxlen; i++) { - mcu_com_rx_cb((uint8_t)rxdata[i]); + uint8_t c = (uint8_t)rxdata[i]; + if (mcu_com_rx_cb(c)) + { + if (BUFFER_FULL(uart_rx)) + { + c = OVF; + } + + *(BUFFER_NEXT_FREE(uart_rx)) = c; + BUFFER_STORE(uart_rx); + } } #endif #if defined(MCU_HAS_UART2) @@ -838,7 +886,17 @@ void mcu_dotasks(void) #if !defined(DETACH_UART2_FROM_MAIN_PROTOCOL) for (i = 0; i < rxlen; i++) { - mcu_com_rx_cb((uint8_t)rxdata[i]); + uint8_t c = (uint8_t)rxdata[i]; + if (mcu_com_rx_cb(c)) + { + if (BUFFER_FULL(uart2_rx)) + { + c = OVF; + } + + *(BUFFER_NEXT_FREE(uart2_rx)) = c; + BUFFER_STORE(uart2_rx); + } } #else for (i = 0; i < rxlen; i++) diff --git a/uCNC/src/hal/mcus/esp8266/esp8266_arduino.cpp b/uCNC/src/hal/mcus/esp8266/esp8266_arduino.cpp index fe98d74a4..3d38c4d52 100644 --- a/uCNC/src/hal/mcus/esp8266/esp8266_arduino.cpp +++ b/uCNC/src/hal/mcus/esp8266/esp8266_arduino.cpp @@ -72,15 +72,15 @@ extern "C" #include "../../../cnc.h" #ifdef BOARD_HAS_CUSTOM_SYSTEM_COMMANDS - uint8_t mcu_custom_grbl_cmd(char *grbl_cmd_str, uint8_t grbl_cmd_len, char next_char) + uint8_t mcu_custom_grbl_cmd(uint8_t *grbl_cmd_str, uint8_t grbl_cmd_len, uint8_t next_char) { - char str[64]; - char arg[ARG_MAX_LEN]; - char has_arg = (next_char == '='); + uint8_t str[64]; + uint8_t arg[ARG_MAX_LEN]; + uint8_t has_arg = (next_char == '='); memset(arg, 0, sizeof(arg)); if (has_arg) { - char c = serial_getc(); + uint8_t c = serial_getc(); uint8_t i = 0; while (c) { @@ -94,9 +94,9 @@ extern "C" } #ifdef ENABLE_WIFI - if (!strncmp(grbl_cmd_str, "WIFI", 4)) + if (!strncmp((const char*)grbl_cmd_str, "WIFI", 4)) { - if (!strcmp(&grbl_cmd_str[4], "ON")) + if (!strcmp((const char *)&grbl_cmd_str[4], "ON")) { WiFi.disconnect(); switch (wifi_settings.wifi_mode) @@ -104,25 +104,25 @@ extern "C" case 1: WiFi.mode(WIFI_STA); WiFi.begin(wifi_settings.ssid, wifi_settings.pass); - protocol_send_feedback("Trying to connect to WiFi"); + protocol_send_feedback((const char *)"Trying to connect to WiFi"); break; case 2: WiFi.mode(WIFI_AP); WiFi.softAP(BOARD_NAME, wifi_settings.pass); - protocol_send_feedback("AP started"); - protocol_send_feedback("SSID>" BOARD_NAME); - sprintf(str, "IP>%s", WiFi.softAPIP().toString().c_str()); - protocol_send_feedback(str); + protocol_send_feedback((const char *)"AP started"); + protocol_send_feedback((const char *)"SSID>" BOARD_NAME); + sprintf((char*)str, "IP>%s", WiFi.softAPIP().toString().c_str()); + protocol_send_feedback((const char *)str); break; default: WiFi.mode(WIFI_AP_STA); WiFi.begin(wifi_settings.ssid, wifi_settings.pass); - protocol_send_feedback("Trying to connect to WiFi"); + protocol_send_feedback((const char *)"Trying to connect to WiFi"); WiFi.softAP(BOARD_NAME, wifi_settings.pass); - protocol_send_feedback("AP started"); - protocol_send_feedback("SSID>" BOARD_NAME); - sprintf(str, "IP>%s", WiFi.softAPIP().toString().c_str()); - protocol_send_feedback(str); + protocol_send_feedback((const char *)"AP started"); + protocol_send_feedback((const char *)"SSID>" BOARD_NAME); + sprintf((char*)str, "IP>%s", WiFi.softAPIP().toString().c_str()); + protocol_send_feedback((const char *)str); break; } @@ -131,7 +131,7 @@ extern "C" return STATUS_OK; } - if (!strcmp(&grbl_cmd_str[4], "OFF")) + if (!strcmp((const char *)&grbl_cmd_str[4], "OFF")) { WiFi.disconnect(); wifi_settings.wifi_on = 0; @@ -139,136 +139,136 @@ extern "C" return STATUS_OK; } - if (!strcmp(&grbl_cmd_str[4], "SSID")) + if (!strcmp((const char *)&grbl_cmd_str[4], "SSID")) { if (has_arg) { - uint8_t len = strlen(arg); + uint8_t len = strlen((const char *)arg); if (len > WIFI_SSID_MAX_LEN) { - protocol_send_feedback("WiFi SSID is too long"); + protocol_send_feedback((const char *)"WiFi SSID is too long"); } memset(wifi_settings.ssid, 0, sizeof(wifi_settings.ssid)); - strcpy(wifi_settings.ssid, arg); + strcpy((char *)wifi_settings.ssid, (const char*)arg); settings_save(wifi_settings_offset, (uint8_t *)&wifi_settings, sizeof(wifi_settings_t)); - protocol_send_feedback("WiFi SSID modified"); + protocol_send_feedback((const char *)"WiFi SSID modified"); } else { - sprintf(str, "SSID>%s", wifi_settings.ssid); - protocol_send_feedback(str); + sprintf((char*)str, "SSID>%s", wifi_settings.ssid); + protocol_send_feedback((const char *)str); } return STATUS_OK; } - if (!strcmp(&grbl_cmd_str[4], "SCAN")) + if (!strcmp((const char *)&grbl_cmd_str[4], "SCAN")) { // Serial.println("[MSG:Scanning Networks]"); - protocol_send_feedback("Scanning Networks"); + protocol_send_feedback((const char *)"Scanning Networks"); int numSsid = WiFi.scanNetworks(); if (numSsid == -1) { - protocol_send_feedback("Failed to scan!"); + protocol_send_feedback((const char *)"Failed to scan!"); while (true) ; } // print the list of networks seen: - sprintf(str, "%d available networks", numSsid); - protocol_send_feedback(str); + sprintf((char*)str, "%d available networks", numSsid); + protocol_send_feedback((const char *)str); // print the network number and name for each network found: for (int netid = 0; netid < numSsid; netid++) { - sprintf(str, "%d) %s\tSignal: %ddBm", netid, WiFi.SSID(netid).c_str(), WiFi.RSSI(netid)); - protocol_send_feedback(str); + sprintf((char*)str, "%d) %s\tSignal: %ddBm", netid, WiFi.SSID(netid).c_str(), WiFi.RSSI(netid)); + protocol_send_feedback((const char *)str); } return STATUS_OK; } - if (!strcmp(&grbl_cmd_str[4], "SAVE")) + if (!strcmp((const char *)&grbl_cmd_str[4], "SAVE")) { settings_save(wifi_settings_offset, (uint8_t *)&wifi_settings, sizeof(wifi_settings_t)); - protocol_send_feedback("WiFi settings saved"); + protocol_send_feedback((const char *)"WiFi settings saved"); return STATUS_OK; } - if (!strcmp(&grbl_cmd_str[4], "RESET")) + if (!strcmp((const char *)&grbl_cmd_str[4], "RESET")) { settings_erase(wifi_settings_offset, sizeof(wifi_settings_t)); memset(&wifi_settings, 0, sizeof(wifi_settings_t)); - protocol_send_feedback("WiFi settings deleted"); + protocol_send_feedback((const char *)"WiFi settings deleted"); return STATUS_OK; } - if (!strcmp(&grbl_cmd_str[4], "MODE")) + if (!strcmp((const char *)&grbl_cmd_str[4], "MODE")) { if (has_arg) { - int mode = atoi(arg) - 1; + int mode = atoi((const char*)arg) - 1; if (mode >= 0) { wifi_settings.wifi_mode = mode; } else { - protocol_send_feedback("Invalid value. STA+AP(1), STA(2), AP(3)"); + protocol_send_feedback((const char *)"Invalid value. STA+AP(1), STA(2), AP(3)"); } } switch (wifi_settings.wifi_mode) { case 0: - protocol_send_feedback("WiFi mode>STA+AP"); + protocol_send_feedback((const char *)"WiFi mode>STA+AP"); break; case 1: - protocol_send_feedback("WiFi mode>STA"); + protocol_send_feedback((const char *)"WiFi mode>STA"); break; case 2: - protocol_send_feedback("WiFi mode>AP"); + protocol_send_feedback((const char *)"WiFi mode>AP"); break; } return STATUS_OK; } - if (!strcmp(&grbl_cmd_str[4], "PASS") && has_arg) + if (!strcmp((const char *)&grbl_cmd_str[4], "PASS") && has_arg) { - uint8_t len = strlen(arg); + uint8_t len = strlen((const char *)arg); if (len > WIFI_SSID_MAX_LEN) { - protocol_send_feedback("WiFi pass is too long"); + protocol_send_feedback((const char *)"WiFi pass is too long"); } memset(wifi_settings.pass, 0, sizeof(wifi_settings.pass)); - strcpy(wifi_settings.pass, arg); - protocol_send_feedback("WiFi password modified"); + strcpy((char *)wifi_settings.pass, (const char*)arg); + protocol_send_feedback((const char *)"WiFi password modified"); return STATUS_OK; } - if (!strcmp(&grbl_cmd_str[4], "IP")) + if (!strcmp((const char *)&grbl_cmd_str[4], "IP")) { if (wifi_settings.wifi_on) { switch (wifi_settings.wifi_mode) { case 1: - sprintf(str, "STA IP>%s", WiFi.softAPIP().toString().c_str()); - protocol_send_feedback(str); - sprintf(str, "AP IP>%s", WiFi.softAPIP().toString().c_str()); - protocol_send_feedback(str); + sprintf((char*)str, "STA IP>%s", WiFi.softAPIP().toString().c_str()); + protocol_send_feedback((const char *)str); + sprintf((char*)str, "AP IP>%s", WiFi.softAPIP().toString().c_str()); + protocol_send_feedback((const char *)str); break; case 2: - sprintf(str, "IP>%s", WiFi.softAPIP().toString().c_str()); - protocol_send_feedback(str); + sprintf((char*)str, "IP>%s", WiFi.softAPIP().toString().c_str()); + protocol_send_feedback((const char *)str); break; default: - sprintf(str, "IP>%s", WiFi.softAPIP().toString().c_str()); - protocol_send_feedback(str); + sprintf((char*)str, "IP>%s", WiFi.softAPIP().toString().c_str()); + protocol_send_feedback((const char *)str); break; } } else { - protocol_send_feedback("WiFi is off"); + protocol_send_feedback((const char *)"WiFi is off"); } return STATUS_OK; @@ -284,7 +284,7 @@ extern "C" #ifdef ENABLE_WIFI static uint32_t next_info = 30000; static bool connected = false; - char str[64]; + uint8_t str[64]; if (!wifi_settings.wifi_on) { @@ -299,18 +299,18 @@ extern "C" return false; } next_info = mcu_millis() + 30000; - protocol_send_feedback("Disconnected from WiFi"); + protocol_send_feedback((const char *)"Disconnected from WiFi"); return false; } if (!connected) { connected = true; - protocol_send_feedback("Connected to WiFi"); - sprintf(str, "SSID>%s", wifi_settings.ssid); - protocol_send_feedback(str); - sprintf(str, "IP>%s", WiFi.localIP().toString().c_str()); - protocol_send_feedback(str); + protocol_send_feedback((const char *)"Connected to WiFi"); + sprintf((char*)str, "SSID>%s", wifi_settings.ssid); + protocol_send_feedback((const char *)str); + sprintf((char*)str, "IP>%s", WiFi.localIP().toString().c_str()); + protocol_send_feedback((const char *)str); } if (server.hasClient()) @@ -366,25 +366,43 @@ extern "C" #ifndef UART_TX_BUFFER_SIZE #define UART_TX_BUFFER_SIZE 64 #endif - DECL_BUFFER(uint8_t, uart, UART_TX_BUFFER_SIZE); + DECL_BUFFER(uint8_t, uart_rx, RX_BUFFER_SIZE); + DECL_BUFFER(uint8_t, uart_tx, UART_TX_BUFFER_SIZE); + uint8_t mcu_uart_getc(void) + { + uint8_t c = 0; + BUFFER_DEQUEUE(uart_rx, &c); + return c; + } + + uint8_t mcu_uart_available(void) + { + return BUFFER_READ_AVAILABLE(uart_rx); + } + + void mcu_uart_clear(void) + { + BUFFER_CLEAR(uart_rx); + } + void mcu_uart_putc(uint8_t c) { - while (BUFFER_FULL(uart)) + while (BUFFER_FULL(uart_tx)) { mcu_uart_flush(); } - BUFFER_ENQUEUE(uart, &c); + BUFFER_ENQUEUE(uart_tx, &c); } void mcu_uart_flush(void) { - while (!BUFFER_EMPTY(uart)) + while (!BUFFER_EMPTY(uart_tx)) { uint8_t tmp[UART_TX_BUFFER_SIZE]; uint8_t r; uint8_t max = (uint8_t)MIN(Serial.availableForWrite(), UART_TX_BUFFER_SIZE); - BUFFER_READ(uart, tmp, max, r); + BUFFER_READ(uart_tx, tmp, max, r); Serial.write(tmp, r); Serial.flush(); } @@ -395,34 +413,52 @@ extern "C" #ifndef WIFI_TX_BUFFER_SIZE #define WIFI_TX_BUFFER_SIZE 64 #endif - DECL_BUFFER(uint8_t, wifi, WIFI_TX_BUFFER_SIZE); + DECL_BUFFER(uint8_t, wifi_rx, RX_BUFFER_SIZE); + DECL_BUFFER(uint8_t, wifi_tx, WIFI_TX_BUFFER_SIZE); + + uint8_t mcu_wifi_getc(void) + { + uint8_t c = 0; + BUFFER_DEQUEUE(wifi_tx, &c); + return c; + } + + uint8_t mcu_wifi_available(void) + { + return BUFFER_READ_AVAILABLE(wifi_tx); + } + + void mcu_wifi_clear(void) + { + BUFFER_CLEAR(wifi_tx); + } void mcu_wifi_putc(uint8_t c) { - while (BUFFER_FULL(wifi)) + while (BUFFER_FULL(wifi_tx)) { mcu_wifi_flush(); } - BUFFER_ENQUEUE(wifi, &c); + BUFFER_ENQUEUE(wifi_tx, &c); } void mcu_wifi_flush(void) { if (esp8266_wifi_clientok()) { - while (!BUFFER_EMPTY(wifi)) + while (!BUFFER_EMPTY(wifi_tx)) { uint8_t tmp[WIFI_TX_BUFFER_SIZE]; uint8_t r; uint8_t max = (uint8_t)MIN(serverClient.availableForWrite(), WIFI_TX_BUFFER_SIZE); - BUFFER_READ(wifi, tmp, max, r); + BUFFER_READ(wifi_tx, tmp, max, r); serverClient.write(tmp, r); } } else { // no client (discard) - BUFFER_CLEAR(wifi); + BUFFER_CLEAR(wifi_tx); } } #endif @@ -445,7 +481,17 @@ extern "C" { system_soft_wdt_feed(); #ifndef DETACH_UART_FROM_MAIN_PROTOCOL - mcu_com_rx_cb((uint8_t)Serial.read()); + uint8_t c = (uint8_t)Serial.read(); + if (mcu_com_rx_cb(c)) + { + if (BUFFER_FULL(uart_rx)) + { + c = OVF; + } + + *(BUFFER_NEXT_FREE(uart_rx)) = c; + BUFFER_STORE(uart_rx); + } #else mcu_uart_rx_cb((uint8_t)Serial.read()); #endif @@ -459,7 +505,17 @@ extern "C" { system_soft_wdt_feed(); #ifndef DETACH_WIFI_FROM_MAIN_PROTOCOL - mcu_com_rx_cb((uint8_t)serverClient.read()); + uint8_t c = (uint8_t)serverClient.read(); + if (mcu_com_rx_cb(c)) + { + if (BUFFER_FULL(wifi_rx)) + { + c = OVF; + } + + *(BUFFER_NEXT_FREE(wifi_rx)) = c; + BUFFER_STORE(wifi_rx); + } #else mcu_wifi_rx_cb((uint8_t)serverClient.read()); #endif @@ -475,7 +531,7 @@ extern "C" #include "esp_peri.h" extern "C" { - #include "../../../cnc.h" +#include "../../../cnc.h" void esp8266_spi_init(uint32_t freq, uint8_t mode) { SPI.begin(); diff --git a/uCNC/src/hal/mcus/esp8266/mcu_esp8266.c b/uCNC/src/hal/mcus/esp8266/mcu_esp8266.c index 2355838cc..06c1473eb 100644 --- a/uCNC/src/hal/mcus/esp8266/mcu_esp8266.c +++ b/uCNC/src/hal/mcus/esp8266/mcu_esp8266.c @@ -154,7 +154,7 @@ IRAM_ATTR void mcu_itp_isr(void) // CLEAR_PERI_REG_MASK(UART_INT_ENA(0), UART_RXFIFO_FULL_INT_ENA | UART_RXFIFO_TOUT_INT_ENA); // WRITE_PERI_REG(UART_INT_CLR(0), (READ_PERI_REG(UART_INT_ST(0)) & (UART_RXFIFO_FULL_INT_ST | UART_RXFIFO_TOUT_INT_ST))); // uint8_t fifo_len = (READ_PERI_REG(UART_STATUS(0)) >> UART_RXFIFO_CNT_S) & UART_RXFIFO_CNT; -// unsigned char c = 0; +// uint8_t c = 0; // for (uint8_t i = 0; i < fifo_len; i++) // { diff --git a/uCNC/src/hal/mcus/lpc176x/lpc176x_arduino.cpp b/uCNC/src/hal/mcus/lpc176x/lpc176x_arduino.cpp index 71c04a8c6..bf89c5d24 100644 --- a/uCNC/src/hal/mcus/lpc176x/lpc176x_arduino.cpp +++ b/uCNC/src/hal/mcus/lpc176x/lpc176x_arduino.cpp @@ -27,77 +27,56 @@ #include #include #include +#include extern "C" { #include "../../../cnc.h" #ifdef USE_ARDUINO_CDC - void mcu_usb_dotasks(void) + void lpc176x_usb_dotasks(void) { MSC_RunDeferredCommands(); } - void mcu_usb_init(void) + bool lpc176x_usb_available(void) { - USB_Init(); // USB Initialization - USB_Connect(false); // USB clear connection - USB_Connect(true); - uint32_t usb_timeout = mcu_millis() + 2000; - while (!USB_Configuration && usb_timeout > mcu_millis()) - { - mcu_delay_us(50); - mcu_usb_dotasks(); -#if ASSERT_PIN(ACTIVITY_LED) - io_toggle_output(ACTIVITY_LED); // Flash quickly during USB initialization -#endif - } - UsbSerial.begin(BAUDRATE); + return (UsbSerial.available() > 0); } -#ifndef USB_TX_BUFFER_SIZE -#define USB_TX_BUFFER_SIZE 64 -#endif - DECL_BUFFER(uint8_t, usb, USB_TX_BUFFER_SIZE); - void mcu_usb_flush(void) + uint8_t lpc176x_usb_getc(void) { - - while (!BUFFER_EMPTY(usb)) - { - char tmp[USB_TX_BUFFER_SIZE]; - uint8_t r; - - BUFFER_READ(usb, tmp, USB_TX_BUFFER_SIZE, r); -#ifdef MCU_HAS_USB - UsbSerial.write(tmp, r); - UsbSerial.flushTX(); -#endif - } + return (uint8_t)UsbSerial.read(); } - void mcu_usb_putc(uint8_t c) + void lpc176x_usb_putc(uint8_t c) { - while (BUFFER_FULL(usb)) - { - mcu_usb_flush(); - } - BUFFER_ENQUEUE(usb, &c); + char a = (char)c; + UsbSerial.write(&a, 1); } - char mcu_usb_getc(void) + void lpc176x_usb_write(uint8_t* ptr, uint8_t len) { - int16_t c = UsbSerial.read(); - return (uint8_t)((c >= 0) ? c : 0); + UsbSerial.write((char*)ptr, len); } - uint8_t mcu_usb_available(void) + void lpc176x_usb_init(void) { - return UsbSerial.available(); + USB_Init(); // USB Initialization + USB_Connect(false); // USB clear connection + USB_Connect(true); + uint32_t usb_timeout = mcu_millis() + 2000; + while (!USB_Configuration && usb_timeout > mcu_millis()) + { + mcu_delay_us(50); + MSC_RunDeferredCommands(); +#if ASSERT_PIN(ACTIVITY_LED) + io_toggle_output(ACTIVITY_LED); // Flash quickly during USB initialization +#endif + } + UsbSerial.begin(BAUDRATE); +// // BUFFER_CLEAR(usb_rx); } - uint8_t mcu_usb_tx_available(void) - { - return (UsbSerial.availableForWrite() | (UsbSerial.host_connected ? 0 : 1)); - } #endif } #endif diff --git a/uCNC/src/hal/mcus/lpc176x/mcu_lpc176x.c b/uCNC/src/hal/mcus/lpc176x/mcu_lpc176x.c index 4e4523695..7b465f7f2 100644 --- a/uCNC/src/hal/mcus/lpc176x/mcu_lpc176x.c +++ b/uCNC/src/hal/mcus/lpc176x/mcu_lpc176x.c @@ -24,11 +24,12 @@ #ifdef MCU_HAS_USB #ifdef USE_ARDUINO_CDC -extern void mcu_usb_dotasks(void); -extern void mcu_usb_init(void); -extern char mcu_usb_getc(void); -extern uint8_t mcu_usb_available(void); -extern uint8_t mcu_usb_tx_available(void); +extern void lpc176x_usb_dotasks(void); +extern bool lpc176x_usb_available(void); +extern uint8_t lpc176x_usb_getc(void); +extern void lpc176x_usb_putc(uint8_t c); +extern void lpc176x_usb_init(void); +extern void lpc176x_usb_write(uint8_t *ptr, uint8_t len); #else #include #endif @@ -39,7 +40,8 @@ extern uint8_t mcu_usb_tx_available(void); * Increments every millisecond * Can count up to almost 50 days **/ -static volatile uint32_t mcu_runtime_ms; +// provided by the framework +extern volatile uint64_t _millis; volatile bool lpc_global_isr_enabled; // define the mcu internal servo variables @@ -175,10 +177,8 @@ void MCU_SERVO_ISR(void) void MCU_RTC_ISR(void) { mcu_disable_global_isr(); - uint32_t millis = mcu_runtime_ms; - millis++; - mcu_runtime_ms = millis; - mcu_rtc_cb(millis); + _millis++; + mcu_rtc_cb((uint32_t)_millis); mcu_enable_global_isr(); } @@ -231,7 +231,9 @@ void mcu_clocks_init(void) #ifndef UART_TX_BUFFER_SIZE #define UART_TX_BUFFER_SIZE 64 #endif -DECL_BUFFER(uint8_t, uart, UART_TX_BUFFER_SIZE); +DECL_BUFFER(uint8_t, uart_tx, UART_TX_BUFFER_SIZE); +DECL_BUFFER(uint8_t, uart_rx, RX_BUFFER_SIZE); + void MCU_COM_ISR(void) { __ATOMIC_FORCEON__ @@ -256,9 +258,19 @@ void MCU_COM_ISR(void) if (irqstatus == UART_IIR_INTID_RDA) { - unsigned char c = (unsigned char)(COM_INREG & UART_RBR_MASKBIT); + uint8_t c = (uint8_t)(COM_INREG & UART_RBR_MASKBIT); #if !defined(DETACH_UART_FROM_MAIN_PROTOCOL) - mcu_com_rx_cb(c); + if (mcu_com_rx_cb(c)) + { + if (BUFFER_FULL(uart_rx)) + { + c = OVF; + } + + *(BUFFER_NEXT_FREE(uart_rx)) = c; + BUFFER_STORE(uart_rx); + } + #else mcu_uart_rx_cb(c); #endif @@ -269,13 +281,13 @@ void MCU_COM_ISR(void) // UART_IntConfig(COM_USART, UART_INTCFG_THRE, DISABLE); mcu_enable_global_isr(); - if (BUFFER_EMPTY(uart)) + if (BUFFER_EMPTY(uart_tx)) { COM_UART->IER &= ~UART_IER_THREINT_EN; return; } uint8_t c = 0; - BUFFER_DEQUEUE(uart, &c); + BUFFER_DEQUEUE(uart_tx, &c); COM_OUTREG = c; } } @@ -286,7 +298,8 @@ void MCU_COM_ISR(void) #ifndef UART2_TX_BUFFER_SIZE #define UART2_TX_BUFFER_SIZE 64 #endif -DECL_BUFFER(uint8_t, uart2, UART2_TX_BUFFER_SIZE); +DECL_BUFFER(uint8_t, uart2_rx, RX_BUFFER_SIZE); +DECL_BUFFER(uint8_t, uart2_tx, UART2_TX_BUFFER_SIZE); void MCU_COM2_ISR(void) { __ATOMIC_FORCEON__ @@ -311,9 +324,18 @@ void MCU_COM2_ISR(void) if (irqstatus == UART_IIR_INTID_RDA) { - unsigned char c = (unsigned char)(COM2_INREG & UART_RBR_MASKBIT); + uint8_t c = (uint8_t)(COM2_INREG & UART_RBR_MASKBIT); #if !defined(DETACH_UART2_FROM_MAIN_PROTOCOL) - mcu_com_rx_cb(c); + if (mcu_com_rx_cb(c)) + { + if (BUFFER_FULL(uart2_rx)) + { + c = OVF; + } + + *(BUFFER_NEXT_FREE(uart2_rx)) = c; + BUFFER_STORE(uart2_rx); + } #else mcu_uart2_rx_cb(c); #endif @@ -322,30 +344,19 @@ void MCU_COM2_ISR(void) if (irqstatus == UART_IIR_INTID_THRE) { mcu_enable_global_isr(); - if (BUFFER_EMPTY(uart2)) + if (BUFFER_EMPTY(uart2_tx)) { COM2_UART->IER &= ~UART_IER_THREINT_EN; return; } uint8_t c; - BUFFER_DEQUEUE(uart2, &c); + BUFFER_DEQUEUE(uart2_tx, &c); COM2_OUTREG = c; } } } #endif -#ifdef MCU_HAS_USB -#ifndef USE_ARDUINO_CDC -void USB_IRQHandler(void) -{ - mcu_disable_global_isr(); - tusb_cdc_isr_handler(); - mcu_enable_global_isr(); -} -#endif -#endif - void mcu_usart_init(void) { #ifdef MCU_HAS_UART @@ -396,7 +407,7 @@ void mcu_usart_init(void) #ifdef MCU_HAS_USB #ifdef USE_ARDUINO_CDC - mcu_usb_init(); + lpc176x_usb_init(); #else // // // configure USB as Virtual COM port LPC_PINCON->PINSEL1 &= ~((3 << 26) | (3 << 28)); /* P0.29 D+, P0.30 D- */ @@ -569,29 +580,47 @@ uint8_t mcu_get_servo(uint8_t servo) #endif /** - * sends a char either via uart (hardware, software or USB virtual COM port) + * sends a uint8_t either via uart (hardware, software or USB virtual COM port) * can be defined either as a function or a macro call * */ #ifdef MCU_HAS_UART + +uint8_t mcu_uart_getc(void) +{ + uint8_t c = 0; + BUFFER_DEQUEUE(uart_rx, &c); + return c; +} + +uint8_t mcu_uart_available(void) +{ + return BUFFER_READ_AVAILABLE(uart_rx); +} + +void mcu_uart_clear(void) +{ + BUFFER_CLEAR(uart_rx); +} + void mcu_uart_putc(uint8_t c) { - while (BUFFER_FULL(uart)) + while (BUFFER_FULL(uart_tx)) { mcu_uart_flush(); } - BUFFER_ENQUEUE(uart, &c); + BUFFER_ENQUEUE(uart_tx, &c); } void mcu_uart_flush(void) { if (!(COM_UART->IER & UART_IER_THREINT_EN)) // not ready start flushing { - if (BUFFER_EMPTY(uart)) + if (BUFFER_EMPTY(uart_tx)) { return; } uint8_t c = 0; - BUFFER_DEQUEUE(uart, &c); + BUFFER_DEQUEUE(uart_tx, &c); while (!CHECKBIT(COM_UART->LSR, 5)) ; COM_OUTREG = c; @@ -604,25 +633,42 @@ void mcu_uart_flush(void) #endif #ifdef MCU_HAS_UART2 +uint8_t mcu_uart2_getc(void) +{ + uint8_t c = 0; + BUFFER_DEQUEUE(uart2_rx, &c); + return c; +} + +uint8_t mcu_uart2_available(void) +{ + return BUFFER_READ_AVAILABLE(uart2_rx); +} + +void mcu_uart2_clear(void) +{ + BUFFER_CLEAR(uart2_rx); +} + void mcu_uart2_putc(uint8_t c) { - while (BUFFER_FULL(uart2)) + while (BUFFER_FULL(uart2_tx)) { mcu_uart2_flush(); } - BUFFER_ENQUEUE(uart2, &c); + BUFFER_ENQUEUE(uart2_tx, &c); } void mcu_uart2_flush(void) { if (!(COM2_UART->IER & UART_IER_THREINT_EN)) // not ready start flushing { - if (BUFFER_EMPTY(uart2)) + if (BUFFER_EMPTY(uart2_tx)) { return; } uint8_t c = 0; - BUFFER_DEQUEUE(uart2, &c); + BUFFER_DEQUEUE(uart2_tx, &c); while (!CHECKBIT(COM2_UART->LSR, 5)) ; COM2_OUTREG = c; @@ -749,8 +795,7 @@ void mcu_stop_itp_isr(void) * */ uint32_t mcu_millis() { - uint32_t val = mcu_runtime_ms; - return val; + return (uint32_t)_millis; } /** @@ -759,7 +804,7 @@ uint32_t mcu_millis() * */ uint32_t mcu_micros() { - return ((mcu_runtime_ms * 1000) + ((SysTick->LOAD - SysTick->VAL) / (F_CPU / 1000000))); + return ((mcu_millis() * 1000) + ((SysTick->LOAD - SysTick->VAL) / (F_CPU / 1000000))); } #ifndef mcu_delay_us @@ -773,7 +818,16 @@ void mcu_delay_us(uint16_t delay) #endif #ifdef MCU_HAS_USB +DECL_BUFFER(uint8_t, usb_rx, RX_BUFFER_SIZE); + #ifndef USE_ARDUINO_CDC +void USB_IRQHandler(void) +{ + mcu_disable_global_isr(); + tusb_cdc_isr_handler(); + mcu_enable_global_isr(); +} + void mcu_usb_putc(uint8_t c) { if (!tusb_cdc_write_available()) @@ -795,7 +849,57 @@ void mcu_usb_flush(void) } } } +#else +#ifndef USB_TX_BUFFER_SIZE +#define USB_TX_BUFFER_SIZE 64 #endif + +DECL_BUFFER(uint8_t, usb_tx, USB_TX_BUFFER_SIZE); +void mcu_usb_flush(void) +{ + while (!BUFFER_EMPTY(usb_tx)) + { + // use this of char is not 8bits + // uint8_t c = 0; + // BUFFER_DEQUEUE(usb_tx, &c); + // lpc176x_usb_putc(c); + + // bulk sending + uint8_t tmp[USB_TX_BUFFER_SIZE]; + uint8_t r; + + BUFFER_READ(usb_tx, tmp, USB_TX_BUFFER_SIZE, r); + lpc176x_usb_write(tmp, r); + } +} + +void mcu_usb_putc(uint8_t c) +{ + while (BUFFER_FULL(usb_tx)) + { + mcu_usb_flush(); + } + BUFFER_ENQUEUE(usb_tx, &c); +} +#endif + +uint8_t mcu_usb_getc(void) +{ + char c = BUFFER_PEEK(usb_rx); + BUFFER_REMOVE(usb_rx); + return (uint8_t)c; +} + +uint8_t mcu_usb_available(void) +{ + return BUFFER_READ_AVAILABLE(usb_rx); +} + +void mcu_usb_clear(void) +{ + BUFFER_CLEAR(usb_rx); +} + #endif /** @@ -807,25 +911,42 @@ void mcu_dotasks() { #ifdef MCU_HAS_USB #ifdef USE_ARDUINO_CDC - mcu_usb_flush(); - mcu_usb_dotasks(); - while (mcu_usb_available()) - { - unsigned char c = (unsigned char)mcu_usb_getc(); + lpc176x_usb_dotasks(); #ifndef DETACH_USB_FROM_MAIN_PROTOCOL - mcu_com_rx_cb(c); + while (lpc176x_usb_available()) + { + uint8_t c = lpc176x_usb_getc(); + if (mcu_com_rx_cb(c)) + { + if (BUFFER_FULL(usb_rx)) + { + c = OVF; + } + + *(BUFFER_NEXT_FREE(usb_rx)) = c; + BUFFER_STORE(usb_rx); + } + } #else - mcu_usb_rx_cb(c); + mcu_usb_rx_cb(c); #endif - } #else tusb_cdc_task(); // tinyusb device task while (tusb_cdc_available()) { - unsigned char c = (unsigned char)tusb_cdc_read(); + uint8_t c = (uint8_t)tusb_cdc_read(); #ifndef DETACH_USB_FROM_MAIN_PROTOCOL - mcu_com_rx_cb(c); + if (mcu_com_rx_cb(c)) + { + if (BUFFER_FULL(usb_rx)) + { + c = OVF; + } + + *(BUFFER_NEXT_FREE(usb_rx)) = c; + BUFFER_STORE(usb_rx); + } #else mcu_usb_rx_cb(c); #endif @@ -887,10 +1008,6 @@ static void mcu_i2c_write_stop(bool *stop) } } -static void mcu_i2c_reset() -{ -} - static uint8_t mcu_i2c_write(uint8_t data, bool send_start, bool send_stop) { bool stop __attribute__((__cleanup__(mcu_i2c_write_stop))) = send_stop; diff --git a/uCNC/src/hal/mcus/mcu.c b/uCNC/src/hal/mcus/mcu.c index 4da909a20..158722476 100644 --- a/uCNC/src/hal/mcus/mcu.c +++ b/uCNC/src/hal/mcus/mcu.c @@ -717,49 +717,56 @@ void __attribute__((weak)) mcu_io_init(void) } #ifdef BOARD_HAS_CUSTOM_SYSTEM_COMMANDS -uint8_t __attribute__((weak)) mcu_custom_grbl_cmd(char *grbl_cmd_str, uint8_t grbl_cmd_len, char next_char) +uint8_t __attribute__((weak)) mcu_custom_grbl_cmd(uint8_t *grbl_cmd_str, uint8_t grbl_cmd_len, uint8_t next_char) { return STATUS_INVALID_STATEMENT; } #endif -void mcu_putc(uint8_t c) +// ISR +// New uint8_t handle strategy +// All ascii will be sent to buffer and processed later (including comments) +MCU_RX_CALLBACK bool mcu_com_rx_cb(uint8_t c) { - // USB, WiFi and BT have usually dedicated buffers -#if defined(MCU_HAS_USB) && !defined(DETACH_USB_FROM_MAIN_PROTOCOL) - mcu_usb_putc(c); -#endif -#if defined(MCU_HAS_BLUETOOTH) && !defined(DETACH_BLUETOOTH_FROM_MAIN_PROTOCOL) - mcu_bt_putc(c); -#endif -#if defined(MCU_HAS_UART) && !defined(DETACH_UART_FROM_MAIN_PROTOCOL) - mcu_uart_putc(c); -#endif -#if defined(MCU_HAS_UART2) && !defined(DETACH_UART2_FROM_MAIN_PROTOCOL) - mcu_uart2_putc(c); -#endif -#if defined(MCU_HAS_WIFI) && !defined(DETACH_WIFI_FROM_MAIN_PROTOCOL) - mcu_wifi_putc(c); -#endif -} + static bool is_grbl_cmd = false; + if (c < ((uint8_t)0x7F)) // ascii (all bellow DEL) + { + switch (c) + { + case CMD_CODE_REPORT: +#if STATUS_AUTOMATIC_REPORT_INTERVAL >= 100 + return false; +#endif + case CMD_CODE_RESET: + case CMD_CODE_FEED_HOLD: + cnc_call_rt_command((uint8_t)c); + return false; + case '\n': + case '\r': + case 0: + // EOL marker + is_grbl_cmd = false; + break; + case '$': + is_grbl_cmd = true; + break; + case CMD_CODE_CYCLE_START: + if (!is_grbl_cmd) + { + cnc_call_rt_command(CMD_CODE_CYCLE_START); + return false; + } + break; + } -void mcu_flush(void) -{ -#if defined(MCU_HAS_USB) && !defined(DETACH_USB_FROM_MAIN_PROTOCOL) - mcu_usb_flush(); -#endif -#if defined(MCU_HAS_BLUETOOTH) && !defined(DETACH_BLUETOOTH_FROM_MAIN_PROTOCOL) - mcu_bt_flush(); -#endif -#if defined(MCU_HAS_UART) && !defined(DETACH_UART_FROM_MAIN_PROTOCOL) - mcu_uart_flush(); -#endif -#if defined(MCU_HAS_UART2) && !defined(DETACH_UART2_FROM_MAIN_PROTOCOL) - mcu_uart2_flush(); -#endif -#if defined(MCU_HAS_WIFI) && !defined(DETACH_WIFI_FROM_MAIN_PROTOCOL) - mcu_wifi_flush(); -#endif + } + else // extended ascii (plus CMD_CODE_CYCLE_START and DEL) + { + cnc_call_rt_command((uint8_t)c); + return false; + } + + return true; } #if (defined(MCU_HAS_I2C)) diff --git a/uCNC/src/hal/mcus/mcu.h b/uCNC/src/hal/mcus/mcu.h index e24590124..dc980382d 100644 --- a/uCNC/src/hal/mcus/mcu.h +++ b/uCNC/src/hal/mcus/mcu.h @@ -45,6 +45,13 @@ extern "C" #define F_STEP_MAX 30000 #endif +#define STREAM_UART 1 +#define STREAM_UART2 2 +#define STREAM_USB 4 +#define STREAM_WIFI 8 +#define STREAM_BTH 16 +#define STREAM_BOARDCAST 255 + // defines special mcu to access flash strings and arrays #ifndef __rom__ #define __rom__ @@ -53,7 +60,7 @@ extern "C" #define __romstr__ #endif #ifndef __romarr__ -#define __romarr__ const char +#define __romarr__ const uint8_t #endif #ifndef rom_strptr #define rom_strptr * @@ -77,7 +84,7 @@ extern "C" MCU_CALLBACK void mcu_step_cb(void); MCU_CALLBACK void mcu_step_reset_cb(void); - MCU_RX_CALLBACK void mcu_com_rx_cb(uint8_t c); + MCU_RX_CALLBACK bool mcu_com_rx_cb(uint8_t c); MCU_CALLBACK void mcu_rtc_cb(uint32_t millis); MCU_IO_CALLBACK void mcu_controls_changed_cb(void); MCU_IO_CALLBACK void mcu_limits_changed_cb(void); @@ -511,22 +518,18 @@ extern "C" #endif #ifdef BOARD_HAS_CUSTOM_SYSTEM_COMMANDS - uint8_t mcu_custom_grbl_cmd(char *grbl_cmd_str, uint8_t grbl_cmd_len, char next_char); -#endif - -/** - * sends a char either via uart (hardware, software USB CDC, Wifi or BT) - * can be defined either as a function or a macro call - * */ -#ifndef mcu_putc - void mcu_putc(uint8_t c); + uint8_t mcu_custom_grbl_cmd(uint8_t *grbl_cmd_str, uint8_t grbl_cmd_len, uint8_t next_char); #endif -#ifndef mcu_flush - void mcu_flush(void); -#endif + /** + * sends a uint8_t either via uart (hardware, software USB CDC, Wifi or BT) + * can be defined either as a function or a macro call + * */ #ifdef MCU_HAS_USB + uint8_t mcu_usb_getc(void); + uint8_t mcu_usb_available(void); + void mcu_usb_clear(void); void mcu_usb_putc(uint8_t c); void mcu_usb_flush(void); #ifdef DETACH_USB_FROM_MAIN_PROTOCOL @@ -535,6 +538,9 @@ extern "C" #endif #ifdef MCU_HAS_UART + uint8_t mcu_uart_getc(void); + uint8_t mcu_uart_available(void); + void mcu_uart_clear(void); void mcu_uart_putc(uint8_t c); void mcu_uart_flush(void); #ifdef DETACH_UART_FROM_MAIN_PROTOCOL @@ -543,6 +549,9 @@ extern "C" #endif #ifdef MCU_HAS_UART2 + uint8_t mcu_uart2_getc(void); + uint8_t mcu_uart2_available(void); + void mcu_uart2_clear(void); void mcu_uart2_putc(uint8_t c); void mcu_uart2_flush(void); #ifdef DETACH_UART2_FROM_MAIN_PROTOCOL @@ -551,6 +560,9 @@ extern "C" #endif #ifdef MCU_HAS_WIFI + uint8_t mcu_wifi_getc(void); + uint8_t mcu_wifi_available(void); + void mcu_wifi_clear(void); void mcu_wifi_putc(uint8_t c); void mcu_wifi_flush(void); #ifdef DETACH_WIFI_FROM_MAIN_PROTOCOL @@ -559,6 +571,9 @@ extern "C" #endif #ifdef MCU_HAS_BLUETOOTH + uint8_t mcu_bt_getc(void); + uint8_t mcu_bt_available(void); + void mcu_bt_clear(void); void mcu_bt_putc(uint8_t c); void mcu_bt_flush(void); #ifdef DETACH_BLUETOOTH_FROM_MAIN_PROTOCOL @@ -566,6 +581,22 @@ extern "C" #endif #endif +#ifndef mcu_getc +#define mcu_getc (&mcu_uart_getc) +#endif +#ifndef mcu_available +#define mcu_available (&mcu_uart_available) +#endif +#ifndef mcu_clear +#define mcu_clear (&mcu_uart_clear) +#endif +#ifndef mcu_putc +#define mcu_putc (&mcu_uart_putc) +#endif +#ifndef mcu_flush +#define mcu_flush (&mcu_uart_flush) +#endif + #ifdef __cplusplus } #endif diff --git a/uCNC/src/hal/mcus/rp2040/mcu_rp2040.c b/uCNC/src/hal/mcus/rp2040/mcu_rp2040.c index 8f53c1183..170b1d7e9 100644 --- a/uCNC/src/hal/mcus/rp2040/mcu_rp2040.c +++ b/uCNC/src/hal/mcus/rp2040/mcu_rp2040.c @@ -26,10 +26,6 @@ static volatile bool rp2040_global_isr_enabled; extern void rp2040_uart_init(int baud); -extern void rp2040_uart_flush(void); -extern void rp2040_uart_write(char c); -extern bool rp2040_uart_rx_ready(void); -extern bool rp2040_uart_tx_ready(void); extern void rp2040_uart_process(void); extern void rp2040_eeprom_init(int size); diff --git a/uCNC/src/hal/mcus/rp2040/rp2040_arduino.cpp b/uCNC/src/hal/mcus/rp2040/rp2040_arduino.cpp index 22d7401b7..bd8fdd258 100644 --- a/uCNC/src/hal/mcus/rp2040/rp2040_arduino.cpp +++ b/uCNC/src/hal/mcus/rp2040/rp2040_arduino.cpp @@ -86,15 +86,15 @@ wifi_settings_t wifi_settings; #endif #ifdef BOARD_HAS_CUSTOM_SYSTEM_COMMANDS -uint8_t mcu_custom_grbl_cmd(char *grbl_cmd_str, uint8_t grbl_cmd_len, char next_char) +uint8_t mcu_custom_grbl_cmd(uint8_t *grbl_cmd_str, uint8_t grbl_cmd_len, uint8_t next_char) { - char str[128]; - char arg[ARG_MAX_LEN]; - char has_arg = (next_char == '='); + uint8_t str[128]; + uint8_t arg[ARG_MAX_LEN]; + uint8_t has_arg = (next_char == '='); memset(arg, 0, sizeof(arg)); if (has_arg) { - char c = serial_getc(); + uint8_t c = serial_getc(); uint8_t i = 0; while (c) { @@ -108,22 +108,22 @@ uint8_t mcu_custom_grbl_cmd(char *grbl_cmd_str, uint8_t grbl_cmd_len, char next_ } #ifdef ENABLE_BLUETOOTH - if (!strncmp(grbl_cmd_str, "BTH", 3)) + if (!strncmp((const char*)grbl_cmd_str, "BTH", 3)) { - if (!strcmp(&grbl_cmd_str[3], "ON")) + if (!strcmp((const char*)&grbl_cmd_str[3], "ON")) { SerialBT.begin(BAUDRATE, SERIAL_8N1); - protocol_send_feedback("Bluetooth enabled"); + protocol_send_feedback((const char*)"Bluetooth enabled"); bt_on = 1; settings_save(bt_settings_offset, &bt_on, 1); return STATUS_OK; } - if (!strcmp(&grbl_cmd_str[3], "OFF")) + if (!strcmp((const char*)&grbl_cmd_str[3], "OFF")) { SerialBT.end(); - protocol_send_feedback("Bluetooth disabled"); + protocol_send_feedback((const char*)"Bluetooth disabled"); bt_on = 0; settings_save(bt_settings_offset, &bt_on, 1); @@ -132,9 +132,9 @@ uint8_t mcu_custom_grbl_cmd(char *grbl_cmd_str, uint8_t grbl_cmd_len, char next_ } #endif #ifdef ENABLE_WIFI - if (!strncmp(grbl_cmd_str, "WIFI", 4)) + if (!strncmp((const char*)grbl_cmd_str, "WIFI", 4)) { - if (!strcmp(&grbl_cmd_str[4], "ON")) + if (!strcmp((const char*)&grbl_cmd_str[4], "ON")) { WiFi.disconnect(); switch (wifi_settings.wifi_mode) @@ -142,25 +142,25 @@ uint8_t mcu_custom_grbl_cmd(char *grbl_cmd_str, uint8_t grbl_cmd_len, char next_ case 1: WiFi.mode(WIFI_STA); WiFi.begin(wifi_settings.ssid, wifi_settings.pass); - protocol_send_feedback("Trying to connect to WiFi"); + protocol_send_feedback((const char*)"Trying to connect to WiFi"); break; case 2: WiFi.mode(WIFI_AP); WiFi.softAP(BOARD_NAME, wifi_settings.pass); - protocol_send_feedback("AP started"); - protocol_send_feedback("SSID>" BOARD_NAME); - sprintf(str, "IP>%s", WiFi.softAPIP().toString().c_str()); - protocol_send_feedback(str); + protocol_send_feedback((const char*)"AP started"); + protocol_send_feedback((const char*)"SSID>" BOARD_NAME); + sprintf((char*)str, "IP>%s", WiFi.softAPIP().toString().c_str()); + protocol_send_feedback((const char*)str); break; default: WiFi.mode(WIFI_AP_STA); WiFi.begin(wifi_settings.ssid, wifi_settings.pass); - protocol_send_feedback("Trying to connect to WiFi"); + protocol_send_feedback((const char*)"Trying to connect to WiFi"); WiFi.softAP(BOARD_NAME, wifi_settings.pass); - protocol_send_feedback("AP started"); - protocol_send_feedback("SSID>" BOARD_NAME); - sprintf(str, "IP>%s", WiFi.softAPIP().toString().c_str()); - protocol_send_feedback(str); + protocol_send_feedback((const char*)"AP started"); + protocol_send_feedback((const char*)"SSID>" BOARD_NAME); + sprintf((char*)str, "IP>%s", WiFi.softAPIP().toString().c_str()); + protocol_send_feedback((const char*)str); break; } @@ -169,7 +169,7 @@ uint8_t mcu_custom_grbl_cmd(char *grbl_cmd_str, uint8_t grbl_cmd_len, char next_ return STATUS_OK; } - if (!strcmp(&grbl_cmd_str[4], "OFF")) + if (!strcmp((const char*)&grbl_cmd_str[4], "OFF")) { WiFi.disconnect(); wifi_settings.wifi_on = 0; @@ -177,136 +177,136 @@ uint8_t mcu_custom_grbl_cmd(char *grbl_cmd_str, uint8_t grbl_cmd_len, char next_ return STATUS_OK; } - if (!strcmp(&grbl_cmd_str[4], "SSID")) + if (!strcmp((const char*)&grbl_cmd_str[4], "SSID")) { if (has_arg) { - uint8_t len = strlen(arg); + uint8_t len = strlen((const char*)arg); if (len > WIFI_SSID_MAX_LEN) { - protocol_send_feedback("WiFi SSID is too long"); + protocol_send_feedback((const char*)"WiFi SSID is too long"); } memset(wifi_settings.ssid, 0, sizeof(wifi_settings.ssid)); - strcpy(wifi_settings.ssid, arg); + strcpy(wifi_settings.ssid, (const char*)arg); settings_save(wifi_settings_offset, (uint8_t *)&wifi_settings, sizeof(wifi_settings_t)); - protocol_send_feedback("WiFi SSID modified"); + protocol_send_feedback((const char*)"WiFi SSID modified"); } else { - sprintf(str, "SSID>%s", wifi_settings.ssid); - protocol_send_feedback(str); + sprintf((char*)str, "SSID>%s", wifi_settings.ssid); + protocol_send_feedback((const char*)str); } return STATUS_OK; } - if (!strcmp(&grbl_cmd_str[4], "SCAN")) + if (!strcmp((const char*)&grbl_cmd_str[4], "SCAN")) { // Serial.println("[MSG:Scanning Networks]"); - protocol_send_feedback("Scanning Networks"); + protocol_send_feedback((const char*)"Scanning Networks"); int numSsid = WiFi.scanNetworks(); if (numSsid == -1) { - protocol_send_feedback("Failed to scan!"); + protocol_send_feedback((const char*)"Failed to scan!"); while (true) ; } // print the list of networks seen: - sprintf(str, "%d available networks", numSsid); - protocol_send_feedback(str); + sprintf((char*)str, "%d available networks", numSsid); + protocol_send_feedback((const char*)str); // print the network number and name for each network found: for (int netid = 0; netid < numSsid; netid++) { - sprintf(str, "%d) %s\tSignal: %ddBm", netid, WiFi.SSID(netid), WiFi.RSSI(netid)); - protocol_send_feedback(str); + sprintf((char*)str, "%d) %s\tSignal: %ddBm", netid, WiFi.SSID(netid), WiFi.RSSI(netid)); + protocol_send_feedback((const char*)str); } return STATUS_OK; } - if (!strcmp(&grbl_cmd_str[4], "SAVE")) + if (!strcmp((const char*)&grbl_cmd_str[4], "SAVE")) { settings_save(wifi_settings_offset, (uint8_t *)&wifi_settings, sizeof(wifi_settings_t)); - protocol_send_feedback("WiFi settings saved"); + protocol_send_feedback((const char*)"WiFi settings saved"); return STATUS_OK; } - if (!strcmp(&grbl_cmd_str[4], "RESET")) + if (!strcmp((const char*)&grbl_cmd_str[4], "RESET")) { settings_erase(wifi_settings_offset, sizeof(wifi_settings_t)); memset(&wifi_settings, 0, sizeof(wifi_settings_t)); - protocol_send_feedback("WiFi settings deleted"); + protocol_send_feedback((const char*)"WiFi settings deleted"); return STATUS_OK; } - if (!strcmp(&grbl_cmd_str[4], "MODE")) + if (!strcmp((const char*)&grbl_cmd_str[4], "MODE")) { if (has_arg) { - int mode = atoi(arg) - 1; + int mode = atoi((const char*)arg) - 1; if (mode >= 0) { wifi_settings.wifi_mode = mode; } else { - protocol_send_feedback("Invalid value. STA+AP(1), STA(2), AP(3)"); + protocol_send_feedback((const char*)"Invalid value. STA+AP(1), STA(2), AP(3)"); } } switch (wifi_settings.wifi_mode) { case 0: - protocol_send_feedback("WiFi mode>STA+AP"); + protocol_send_feedback((const char*)"WiFi mode>STA+AP"); break; case 1: - protocol_send_feedback("WiFi mode>STA"); + protocol_send_feedback((const char*)"WiFi mode>STA"); break; case 2: - protocol_send_feedback("WiFi mode>AP"); + protocol_send_feedback((const char*)"WiFi mode>AP"); break; } return STATUS_OK; } - if (!strcmp(&grbl_cmd_str[4], "PASS") && has_arg) + if (!strcmp((const char*)&grbl_cmd_str[4], "PASS") && has_arg) { - uint8_t len = strlen(arg); + uint8_t len = strlen((const char*)arg); if (len > WIFI_PASS_MAX_LEN) { - protocol_send_feedback("WiFi pass is too long"); + protocol_send_feedback((const char*)"WiFi pass is too long"); } memset(wifi_settings.pass, 0, sizeof(wifi_settings.pass)); - strcpy(wifi_settings.pass, arg); - protocol_send_feedback("WiFi password modified"); + strcpy(wifi_settings.pass, (const char*)arg); + protocol_send_feedback((const char*)"WiFi password modified"); return STATUS_OK; } - if (!strcmp(&grbl_cmd_str[4], "IP")) + if (!strcmp((const char*)&grbl_cmd_str[4], "IP")) { if (wifi_settings.wifi_on) { switch (wifi_settings.wifi_mode) { case 1: - sprintf(str, "STA IP>%s", WiFi.softAPIP().toString().c_str()); - protocol_send_feedback(str); - sprintf(str, "AP IP>%s", WiFi.softAPIP().toString().c_str()); - protocol_send_feedback(str); + sprintf((char*)str, "STA IP>%s", WiFi.softAPIP().toString().c_str()); + protocol_send_feedback((const char*)str); + sprintf((char*)str, "AP IP>%s", WiFi.softAPIP().toString().c_str()); + protocol_send_feedback((const char*)str); break; case 2: - sprintf(str, "IP>%s", WiFi.softAPIP().toString().c_str()); - protocol_send_feedback(str); + sprintf((char*)str, "IP>%s", WiFi.softAPIP().toString().c_str()); + protocol_send_feedback((const char*)str); break; default: - sprintf(str, "IP>%s", WiFi.softAPIP().toString().c_str()); - protocol_send_feedback(str); + sprintf((char*)str, "IP>%s", WiFi.softAPIP().toString().c_str()); + protocol_send_feedback((const char*)str); break; } } else { - protocol_send_feedback("WiFi is off"); + protocol_send_feedback((const char*)"WiFi is off"); } return STATUS_OK; @@ -322,7 +322,7 @@ bool rp2040_wifi_clientok(void) #ifdef ENABLE_WIFI static uint32_t next_info = 30000; static bool connected = false; - char str[128]; + uint8_t str[128]; if (!wifi_settings.wifi_on) { @@ -337,18 +337,18 @@ bool rp2040_wifi_clientok(void) return false; } next_info = millis() + 30000; - protocol_send_feedback("Disconnected from WiFi"); + protocol_send_feedback((const char*)"Disconnected from WiFi"); return false; } if (!connected) { connected = true; - protocol_send_feedback("Connected to WiFi"); - sprintf(str, "SSID>%s", wifi_settings.ssid); - protocol_send_feedback(str); - sprintf(str, "IP>%s", WiFi.localIP().toString().c_str()); - protocol_send_feedback(str); + protocol_send_feedback((const char*)"Connected to WiFi"); + sprintf((char*)str, "SSID>%s", wifi_settings.ssid); + protocol_send_feedback((const char*)str); + sprintf((char*)str, "IP>%s", WiFi.localIP().toString().c_str()); + protocol_send_feedback((const char*)str); } if (server.hasClient()) @@ -379,8 +379,8 @@ void rp2040_wifi_bt_init(void) { #ifdef ENABLE_WIFI wifi_settings = {0}; - memcpy(wifi_settings.ssid, BOARD_NAME, strlen(BOARD_NAME)); - memcpy(wifi_settings.pass, WIFI_PASS, strlen(WIFI_PASS)); + memcpy(wifi_settings.ssid, BOARD_NAME, strlen((const char*)BOARD_NAME)); + memcpy(wifi_settings.pass, WIFI_PASS, strlen((const char*)WIFI_PASS)); wifi_settings_offset = settings_register_external_setting(sizeof(wifi_settings_t)); if (settings_load(wifi_settings_offset, (uint8_t *)&wifi_settings, sizeof(wifi_settings_t))) @@ -418,33 +418,52 @@ void rp2040_wifi_bt_init(void) #ifndef WIFI_TX_BUFFER_SIZE #define WIFI_TX_BUFFER_SIZE 64 #endif -DECL_BUFFER(uint8_t, wifi, WIFI_TX_BUFFER_SIZE); +DECL_BUFFER(uint8_t, wifi_tx, WIFI_TX_BUFFER_SIZE); +DECL_BUFFER(uint8_t, wifi_rx, RX_BUFFER_SIZE); + +uint8_t mcu_wifi_getc(void) +{ + uint8_t c = 0; + BUFFER_DEQUEUE(wifi_rx, &c); + return c; +} + +uint8_t mcu_wifi_available(void) +{ + return BUFFER_READ_AVAILABLE(wifi_rx); +} + +void mcu_wifi_clear(void) +{ + BUFFER_CLEAR(wifi_rx); +} + void mcu_wifi_putc(uint8_t c) { - while (BUFFER_FULL(wifi)) + while (BUFFER_FULL(wifi_tx)) { mcu_wifi_flush(); } - BUFFER_ENQUEUE(wifi, &c); + BUFFER_ENQUEUE(wifi_tx, &c); } void mcu_wifi_flush(void) { if (rp2040_wifi_clientok()) { - while (!BUFFER_EMPTY(wifi)) + while (!BUFFER_EMPTY(wifi_tx)) { uint8_t tmp[WIFI_TX_BUFFER_SIZE]; uint8_t r; - BUFFER_READ(wifi, tmp, WIFI_TX_BUFFER_SIZE, r); + BUFFER_READ(wifi_tx, tmp, WIFI_TX_BUFFER_SIZE, r); serverClient.write(tmp, r); } } else { // no client (discard) - BUFFER_CLEAR(wifi); + BUFFER_CLEAR(wifi_tx); } } #endif @@ -453,47 +472,66 @@ void mcu_wifi_flush(void) #ifndef BLUETOOTH_TX_BUFFER_SIZE #define BLUETOOTH_TX_BUFFER_SIZE 64 #endif -DECL_BUFFER(uint8_t, bluetooth, BLUETOOTH_TX_BUFFER_SIZE); +DECL_BUFFER(uint8_t, bt_tx, BLUETOOTH_TX_BUFFER_SIZE); +DECL_BUFFER(uint8_t, bt_rx, RX_BUFFER_SIZE); + +uint8_t mcu_bt_getc(void) +{ + uint8_t c = 0; + BUFFER_DEQUEUE(bt_rx, &c); + return c; +} + +uint8_t mcu_bt_available(void) +{ + return BUFFER_READ_AVAILABLE(bt_rx); +} + +void mcu_bt_clear(void) +{ + BUFFER_CLEAR(bt_rx); +} + void mcu_bt_putc(uint8_t c) { - while (BUFFER_FULL(bluetooth)) + while (BUFFER_FULL(bt_tx)) { mcu_bt_flush(); } - BUFFER_ENQUEUE(bluetooth, &c); + BUFFER_ENQUEUE(bt_tx, &c); } void mcu_bt_flush(void) { - while (!BUFFER_EMPTY(bluetooth)) + while (!BUFFER_EMPTY(bt_tx)) { uint8_t tmp[BLUETOOTH_TX_BUFFER_SIZE]; uint8_t r; - BUFFER_READ(bluetooth, tmp, BLUETOOTH_TX_BUFFER_SIZE, r); + BUFFER_READ(bt_tx, tmp, BLUETOOTH_TX_BUFFER_SIZE, r); SerialBT.write(tmp, r); SerialBT.flush(); } } #endif -unsigned char rp2040_wifi_bt_read(void) +uint8_t rp2040_wifi_bt_read(void) { #ifdef ENABLE_WIFI if (rp2040_wifi_clientok()) { if (serverClient.available() > 0) { - return (unsigned char)serverClient.read(); + return (uint8_t)serverClient.read(); } } #endif #ifdef ENABLE_BLUETOOTH - return (unsigned char)SerialBT.read(); + return (uint8_t)SerialBT.read(); #endif - return (unsigned char)0; + return (uint8_t)0; } bool rp2040_wifi_bt_rx_ready(void) @@ -517,12 +555,25 @@ bool rp2040_wifi_bt_rx_ready(void) void rp2040_wifi_bt_process(void) { #ifdef ENABLE_WIFI + DECL_BUFFER(uint8_t, wifi_rx, RX_BUFFER_SIZE); + if (rp2040_wifi_clientok()) { while (serverClient.available() > 0) { #ifndef DETACH_WIFI_FROM_MAIN_PROTOCOL - mcu_com_rx_cb((uint8_t)serverClient.read()); + uint8_t c = (uint8_t)serverClient.read(); + if (mcu_com_rx_cb(c)) + { + if (BUFFER_FULL(wifi_rx)) + { + c = OVF; + } + + *(BUFFER_NEXT_FREE(wifi_rx)) = c; + BUFFER_STORE(wifi_rx); + } + #else mcu_wifi_rx_cb((uint8_t)serverClient.read()); #endif @@ -533,10 +584,23 @@ void rp2040_wifi_bt_process(void) #endif #ifdef ENABLE_BLUETOOTH + DECL_BUFFER(uint8_t, bt_rx, RX_BUFFER_SIZE); + while (SerialBT.available() > 0) { #ifndef DETACH_BLUETOOTH_FROM_MAIN_PROTOCOL - mcu_com_rx_cb((uint8_t)SerialBT.read()); + uint8_t c = (uint8_t)SerialBT.read(); + if (mcu_com_rx_cb(c)) + { + if (BUFFER_FULL(bt_rx)) + { + c = OVF; + } + + *(BUFFER_NEXT_FREE(bt_rx)) = c; + BUFFER_STORE(bt_rx); + } + #else mcu_bt_rx_cb((uint8_t)SerialBT.read()); #endif @@ -572,24 +636,43 @@ extern "C" #ifndef USB_TX_BUFFER_SIZE #define USB_TX_BUFFER_SIZE 64 #endif - DECL_BUFFER(uint8_t, usb, USB_TX_BUFFER_SIZE); + DECL_BUFFER(uint8_t, usb_tx, USB_TX_BUFFER_SIZE); + DECL_BUFFER(uint8_t, usb_rx, RX_BUFFER_SIZE); + + uint8_t mcu_usb_getc(void) + { + uint8_t c = 0; + BUFFER_DEQUEUE(usb_rx, &c); + return c; + } + + uint8_t mcu_usb_available(void) + { + return BUFFER_READ_AVAILABLE(usb_rx); + } + + void mcu_usb_clear(void) + { + BUFFER_CLEAR(usb_rx); + } + void mcu_usb_putc(uint8_t c) { - while (BUFFER_FULL(usb)) + while (BUFFER_FULL(usb_tx)) { mcu_usb_flush(); } - BUFFER_ENQUEUE(usb, &c); + BUFFER_ENQUEUE(usb_tx, &c); } void mcu_usb_flush(void) { - while (!BUFFER_EMPTY(usb)) + while (!BUFFER_EMPTY(usb_tx)) { - char tmp[USB_TX_BUFFER_SIZE]; + uint8_t tmp[USB_TX_BUFFER_SIZE]; uint8_t r; - BUFFER_READ(usb, tmp, USB_TX_BUFFER_SIZE, r); + BUFFER_READ(usb_tx, tmp, USB_TX_BUFFER_SIZE, r); Serial.write(tmp, r); Serial.flush(); } @@ -600,24 +683,43 @@ extern "C" #ifndef UART_TX_BUFFER_SIZE #define UART_TX_BUFFER_SIZE 64 #endif - DECL_BUFFER(uint8_t, uart, UART_TX_BUFFER_SIZE); + DECL_BUFFER(uint8_t, uart_tx, UART_TX_BUFFER_SIZE); + DECL_BUFFER(uint8_t, uart_rx, RX_BUFFER_SIZE); + + uint8_t mcu_uart_getc(void) + { + uint8_t c = 0; + BUFFER_DEQUEUE(uart_rx, &c); + return c; + } + + uint8_t mcu_uart_available(void) + { + return BUFFER_READ_AVAILABLE(uart_rx); + } + + void mcu_uart_clear(void) + { + BUFFER_CLEAR(uart_rx); + } + void mcu_uart_putc(uint8_t c) { - while (BUFFER_FULL(uart)) + while (BUFFER_FULL(uart_tx)) { mcu_uart_flush(); } - BUFFER_ENQUEUE(uart, &c); + BUFFER_ENQUEUE(uart_tx, &c); } void mcu_uart_flush(void) { - while (!BUFFER_EMPTY(uart)) + while (!BUFFER_EMPTY(uart_tx)) { uint8_t tmp[UART_TX_BUFFER_SIZE]; uint8_t r = 0; - BUFFER_READ(uart, tmp, UART_TX_BUFFER_SIZE, r); + BUFFER_READ(uart_tx, tmp, UART_TX_BUFFER_SIZE, r); COM_UART.write(tmp, r); COM_UART.flush(); } @@ -628,24 +730,43 @@ extern "C" #ifndef UART2_TX_BUFFER_SIZE #define UART2_TX_BUFFER_SIZE 64 #endif - DECL_BUFFER(uint8_t, uart2, UART2_TX_BUFFER_SIZE); + DECL_BUFFER(uint8_t, uart2_tx, UART2_TX_BUFFER_SIZE); + DECL_BUFFER(uint8_t, uart2_rx, RX_BUFFER_SIZE); + + uint8_t mcu_uart2_getc(void) + { + uint8_t c = 0; + BUFFER_DEQUEUE(uart2_rx, &c); + return c; + } + + uint8_t mcu_uart2_available(void) + { + return BUFFER_READ_AVAILABLE(uart2_rx); + } + + void mcu_uart2_clear(void) + { + BUFFER_CLEAR(uart2_rx); + } + void mcu_uart2_putc(uint8_t c) { - while (BUFFER_FULL(uart2)) + while (BUFFER_FULL(uart2_tx)) { mcu_uart2_flush(); } - BUFFER_ENQUEUE(uart2, &c); + BUFFER_ENQUEUE(uart2_tx, &c); } void mcu_uart2_flush(void) { - while (!BUFFER_EMPTY(uart2)) + while (!BUFFER_EMPTY(uart2_tx)) { uint8_t tmp[UART2_TX_BUFFER_SIZE]; uint8_t r; - BUFFER_READ(uart2, tmp, UART2_TX_BUFFER_SIZE, r); + BUFFER_READ(uart2_tx, tmp, UART2_TX_BUFFER_SIZE, r); COM2_UART.write(tmp, r); COM2_UART.flush(); } @@ -670,7 +791,18 @@ extern "C" while (Serial.available() > 0) { #ifndef DETACH_USB_FROM_MAIN_PROTOCOL - mcu_com_rx_cb((uint8_t)Serial.read()); + uint8_t c = (uint8_t)Serial.read(); + if (mcu_com_rx_cb(c)) + { + if (BUFFER_FULL(usb_rx)) + { + c = OVF; + } + + *(BUFFER_NEXT_FREE(usb_rx)) = c; + BUFFER_STORE(usb_rx); + } + #else mcu_usb_rx_cb((uint8_t)Serial.read()); #endif @@ -681,7 +813,17 @@ extern "C" while (COM_UART.available() > 0) { #ifndef DETACH_UART_FROM_MAIN_PROTOCOL - mcu_com_rx_cb((uint8_t)COM_UART.read()); + uint8_t c = (uint8_t)COM_UART.read(); + if (mcu_com_rx_cb(c)) + { + if (BUFFER_FULL(uart_rx)) + { + c = OVF; + } + + *(BUFFER_NEXT_FREE(uart_rx)) = c; + BUFFER_STORE(uart_rx); + } #else mcu_uart_rx_cb((uint8_t)COM_UART.read()); #endif @@ -692,7 +834,18 @@ extern "C" while (COM2_UART.available() > 0) { #ifndef DETACH_UART2_FROM_MAIN_PROTOCOL - mcu_com_rx_cb((uint8_t)COM2_UART.read()); + uint8_t c = (uint8_t)COM2_UART.read(); + if (mcu_com_rx_cb(c)) + { + if (BUFFER_FULL(uart2_rx)) + { + c = OVF; + } + + *(BUFFER_NEXT_FREE(uart2_rx)) = c; + BUFFER_STORE(uart2_rx); + } + #else mcu_uart2_rx_cb((uint8_t)COM2_UART.read()); #endif @@ -734,7 +887,7 @@ extern "C" { if (!EEPROM.commit()) { - protocol_send_feedback(" EEPROM write error"); + protocol_send_feedback((const char*)" EEPROM write error"); } } } diff --git a/uCNC/src/hal/mcus/samd21/mcu_samd21.c b/uCNC/src/hal/mcus/samd21/mcu_samd21.c index d815344f4..07565f5f4 100644 --- a/uCNC/src/hal/mcus/samd21/mcu_samd21.c +++ b/uCNC/src/hal/mcus/samd21/mcu_samd21.c @@ -210,7 +210,9 @@ void MCU_ITP_ISR(void) #ifndef UART_TX_BUFFER_SIZE #define UART_TX_BUFFER_SIZE 64 #endif -DECL_BUFFER(uint8_t, uart, UART_TX_BUFFER_SIZE); +DECL_BUFFER(uint8_t, uart_tx, UART_TX_BUFFER_SIZE); +DECL_BUFFER(uint8_t, uart_rx, RX_BUFFER_SIZE); + void mcu_com_isr() { __ATOMIC_FORCEON__ @@ -218,9 +220,18 @@ void mcu_com_isr() if (COM_UART->USART.INTFLAG.bit.RXC && COM_UART->USART.INTENSET.bit.RXC) { COM_UART->USART.INTFLAG.bit.RXC = 1; - unsigned char c = (0xff & COM_INREG); + uint8_t c = (0xff & COM_INREG); #if !defined(DETACH_UART_FROM_MAIN_PROTOCOL) - mcu_com_rx_cb(c); + if (mcu_com_rx_cb(c)) + { + if (BUFFER_FULL(uart_rx)) + { + c = OVF; + } + + *(BUFFER_NEXT_FREE(uart_rx)) = c; + BUFFER_STORE(uart_rx); + } #else mcu_uart_rx_cb(c); #endif @@ -228,14 +239,14 @@ void mcu_com_isr() if (COM_UART->USART.INTFLAG.bit.DRE && COM_UART->USART.INTENSET.bit.DRE) { mcu_enable_global_isr(); - if (BUFFER_EMPTY(uart)) + if (BUFFER_EMPTY(uart_tx)) { COM_UART->USART.INTENCLR.reg = SERCOM_USART_INTENCLR_DRE; return; } uint8_t c; - BUFFER_DEQUEUE(uart, &c); + BUFFER_DEQUEUE(uart_tx, &c); COM_OUTREG = c; } } @@ -246,7 +257,9 @@ void mcu_com_isr() #ifndef UART2_TX_BUFFER_SIZE #define UART2_TX_BUFFER_SIZE 64 #endif -DECL_BUFFER(uint8_t, uart2, UART2_TX_BUFFER_SIZE); +DECL_BUFFER(uint8_t, uart2_tx, UART2_TX_BUFFER_SIZE); +DECL_BUFFER(uint8_t, uart2_rx, RX_BUFFER_SIZE); + void mcu_com2_isr() { __ATOMIC_FORCEON__ @@ -254,9 +267,18 @@ void mcu_com2_isr() if (COM2_UART->USART.INTFLAG.bit.RXC && COM2_UART->USART.INTENSET.bit.RXC) { COM2_UART->USART.INTFLAG.bit.RXC = 1; - unsigned char c = (0xff & COM2_INREG); + uint8_t c = (0xff & COM2_INREG); #if !defined(DETACH_UART2_FROM_MAIN_PROTOCOL) - mcu_com_rx_cb(c); + if (mcu_com_rx_cb(c)) + { + if (BUFFER_FULL(uart2_rx)) + { + c = OVF; + } + + *(BUFFER_NEXT_FREE(uart2_rx)) = c; + BUFFER_STORE(uart2_rx); + } #else mcu_uart2_rx_cb(c); #endif @@ -265,13 +287,13 @@ void mcu_com2_isr() { // keeps sending chars until null is found mcu_enable_global_isr(); - if (BUFFER_EMPTY(uart2)) + if (BUFFER_EMPTY(uart2_tx)) { COM2_UART->USART.INTENCLR.reg = SERCOM_USART_INTENCLR_DRE; return; } uint8_t c; - BUFFER_DEQUEUE(uart2, &c); + BUFFER_DEQUEUE(uart2_tx, &c); COM2_OUTREG = c; } } @@ -737,7 +759,7 @@ uint8_t mcu_get_pwm(uint8_t pwm) #endif /** - * checks if the serial hardware of the MCU is ready do send the next char + * checks if the serial hardware of the MCU is ready do send the next uint8_t * */ #ifndef mcu_tx_ready bool mcu_tx_ready(void) @@ -747,10 +769,29 @@ bool mcu_tx_ready(void) #endif /** - * sends a char either via uart (hardware, software or USB virtual COM_UART port) + * sends a uint8_t either via uart (hardware, software or USB virtual COM_UART port) * can be defined either as a function or a macro call * */ #ifdef MCU_HAS_USB +DECL_BUFFER(uint8_t, usb_rx, RX_BUFFER_SIZE); + +uint8_t mcu_usb_getc(void) +{ + uint8_t c = 0; + BUFFER_DEQUEUE(usb_rx, &c); + return c; +} + +uint8_t mcu_usb_available(void) +{ + return BUFFER_READ_AVAILABLE(usb_rx); +} + +void mcu_usb_clear(void) +{ + BUFFER_CLEAR(usb_rx); +} + void mcu_usb_putc(uint8_t c) { if (!tusb_cdc_write_available()) @@ -775,13 +816,30 @@ void mcu_usb_flush(void) #endif #ifdef MCU_HAS_UART +uint8_t mcu_uart_getc(void) +{ + uint8_t c = 0; + BUFFER_DEQUEUE(uart_rx, &c); + return c; +} + +uint8_t mcu_uart_available(void) +{ + return BUFFER_READ_AVAILABLE(uart_rx); +} + +void mcu_uart_clear(void) +{ + BUFFER_CLEAR(uart_rx); +} + void mcu_uart_putc(uint8_t c) { - while (BUFFER_FULL(uart)) + while (BUFFER_FULL(uart_tx)) { mcu_uart_flush(); } - BUFFER_ENQUEUE(uart, &c); + BUFFER_ENQUEUE(uart_tx, &c); } void mcu_uart_flush(void) @@ -797,13 +855,30 @@ void mcu_uart_flush(void) #endif #ifdef MCU_HAS_UART2 +uint8_t mcu_uart2_getc(void) +{ + uint8_t c = 0; + BUFFER_DEQUEUE(uart2_rx, &c); + return c; +} + +uint8_t mcu_uart2_available(void) +{ + return BUFFER_READ_AVAILABLE(uart2_rx); +} + +void mcu_uart2_clear(void) +{ + BUFFER_CLEAR(uart2_rx); +} + void mcu_uart2_putc(uint8_t c) { - while (BUFFER_FULL(uart2)) + while (BUFFER_FULL(uart2_tx)) { mcu_uart2_flush(); } - BUFFER_ENQUEUE(uart2, &c); + BUFFER_ENQUEUE(uart2_tx, &c); } void mcu_uart_flush(void) @@ -1025,7 +1100,16 @@ void mcu_dotasks(void) { uint8_t c = (uint8_t)tusb_cdc_read(); #ifndef DETACH_USB_FROM_MAIN_PROTOCOL - mcu_com_rx_cb(c); + if (mcu_com_rx_cb(c)) + { + if (BUFFER_FULL(usb_rx)) + { + c = OVF; + } + + *(BUFFER_NEXT_FREE(usb_rx)) = c; + BUFFER_STORE(usb_rx); + } #else mcu_usb_rx_cb(c); #endif diff --git a/uCNC/src/hal/mcus/samd21/mcumap_samd21.h b/uCNC/src/hal/mcus/samd21/mcumap_samd21.h index 2fdd8680f..27dc8a382 100644 --- a/uCNC/src/hal/mcus/samd21/mcumap_samd21.h +++ b/uCNC/src/hal/mcus/samd21/mcumap_samd21.h @@ -64,7 +64,7 @@ extern "C" // defines special mcu to access flash strings and arrays #define __rom__ #define __romstr__ -#define __romarr__ const char +#define __romarr__ const uint8_t #define rom_strptr * #define rom_strcpy strcpy #define rom_strncpy strncpy diff --git a/uCNC/src/hal/mcus/stm32f1x/mcu_stm32f1x.c b/uCNC/src/hal/mcus/stm32f1x/mcu_stm32f1x.c index 18ec17f65..63e81343c 100644 --- a/uCNC/src/hal/mcus/stm32f1x/mcu_stm32f1x.c +++ b/uCNC/src/hal/mcus/stm32f1x/mcu_stm32f1x.c @@ -76,16 +76,27 @@ volatile bool stm32_global_isr_enabled; #ifndef UART_TX_BUFFER_SIZE #define UART_TX_BUFFER_SIZE 64 #endif -DECL_BUFFER(uint8_t, uart, UART_TX_BUFFER_SIZE); +DECL_BUFFER(uint8_t, uart_tx, UART_TX_BUFFER_SIZE); +DECL_BUFFER(uint8_t, uart_rx, RX_BUFFER_SIZE); + void MCU_SERIAL_ISR(void) { __ATOMIC_FORCEON__ { if (COM_UART->SR & USART_SR_RXNE) { - unsigned char c = COM_INREG; + uint8_t c = COM_INREG; #if !defined(DETACH_UART_FROM_MAIN_PROTOCOL) - mcu_com_rx_cb(c); + if (mcu_com_rx_cb(c)) + { + if (BUFFER_FULL(uart_rx)) + { + c = OVF; + } + + *(BUFFER_NEXT_FREE(uart_rx)) = c; + BUFFER_STORE(uart_rx); + } #else mcu_uart_rx_cb(c); #endif @@ -94,13 +105,13 @@ void MCU_SERIAL_ISR(void) if ((COM_UART->SR & USART_SR_TXE) && (COM_UART->CR1 & USART_CR1_TXEIE)) { mcu_enable_global_isr(); - if (BUFFER_EMPTY(uart)) + if (BUFFER_EMPTY(uart_tx)) { COM_UART->CR1 &= ~(USART_CR1_TXEIE); return; } uint8_t c; - BUFFER_DEQUEUE(uart, &c); + BUFFER_DEQUEUE(uart_tx, &c); COM_OUTREG = c; } } @@ -111,16 +122,27 @@ void MCU_SERIAL_ISR(void) #ifndef UART2_TX_BUFFER_SIZE #define UART2_TX_BUFFER_SIZE 64 #endif -DECL_BUFFER(uint8_t, uart2, UART2_TX_BUFFER_SIZE); +DECL_BUFFER(uint8_t, uart2_tx, UART2_TX_BUFFER_SIZE); +DECL_BUFFER(uint8_t, uart2_rx, RX_BUFFER_SIZE); + void MCU_SERIAL2_ISR(void) { __ATOMIC_FORCEON__ { if (COM2_UART->SR & USART_SR_RXNE) { - unsigned char c = COM2_INREG; + uint8_t c = COM2_INREG; #if !defined(DETACH_UART2_FROM_MAIN_PROTOCOL) - mcu_com_rx_cb(c); + if (mcu_com_rx_cb(c)) + { + if (BUFFER_FULL(uart2_rx)) + { + c = OVF; + } + + *(BUFFER_NEXT_FREE(uart2_rx)) = c; + BUFFER_STORE(uart2_rx); + } #else mcu_uart2_rx_cb(c); #endif @@ -129,13 +151,13 @@ void MCU_SERIAL2_ISR(void) if ((COM2_UART->SR & USART_SR_TXE) && (COM2_UART->CR1 & USART_CR1_TXEIE)) { mcu_enable_global_isr(); - if (BUFFER_EMPTY(uart2)) + if (BUFFER_EMPTY(uart2_tx)) { COM2_UART->CR1 &= ~(USART_CR1_TXEIE); return; } uint8_t c; - BUFFER_DEQUEUE(uart2, &c); + BUFFER_DEQUEUE(uart2_tx, &c); COM2_OUTREG = c; } } @@ -417,8 +439,8 @@ void mcu_clocks_init() DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; } - //free some jtag pins - AFIO->MAPR |= (2<<24); + // free some jtag pins + AFIO->MAPR |= (2 << 24); } void mcu_usart_init(void) @@ -473,6 +495,24 @@ void mcu_usart_init(void) } #ifdef MCU_HAS_USB +DECL_BUFFER(uint8_t, usb_rx, RX_BUFFER_SIZE); +uint8_t mcu_usb_getc(void) +{ + uint8_t c = 0; + BUFFER_DEQUEUE(usb_rx, &c); + return c; +} + +uint8_t mcu_usb_available(void) +{ + return BUFFER_READ_AVAILABLE(usb_rx); +} + +void mcu_usb_clear(void) +{ + BUFFER_CLEAR(usb_rx); +} + void mcu_usb_putc(uint8_t c) { if (!tusb_cdc_write_available()) @@ -498,13 +538,30 @@ void mcu_usb_flush(void) #ifdef MCU_HAS_UART +uint8_t mcu_uart_getc(void) +{ + uint8_t c = 0; + BUFFER_DEQUEUE(uart_rx, &c); + return c; +} + +uint8_t mcu_uart_available(void) +{ + return BUFFER_READ_AVAILABLE(uart_rx); +} + +void mcu_uart_clear(void) +{ + BUFFER_CLEAR(uart_rx); +} + void mcu_uart_putc(uint8_t c) { - while (BUFFER_FULL(uart)) + while (BUFFER_FULL(uart_tx)) { mcu_uart_flush(); } - BUFFER_ENQUEUE(uart, &c); + BUFFER_ENQUEUE(uart_tx, &c); } void mcu_uart_flush(void) @@ -523,13 +580,30 @@ void mcu_uart_flush(void) #ifdef MCU_HAS_UART2 +uint8_t mcu_uart2_getc(void) +{ + uint8_t c = 0; + BUFFER_DEQUEUE(uart2_rx, &c); + return c; +} + +uint8_t mcu_uart2_available(void) +{ + return BUFFER_READ_AVAILABLE(uart2_rx); +} + +void mcu_uart2_clear(void) +{ + BUFFER_CLEAR(uart2_rx); +} + void mcu_uart2_putc(uint8_t c) { - while (BUFFER_FULL(uart2)) + while (BUFFER_FULL(uart2_tx)) { mcu_uart2_flush(); } - BUFFER_ENQUEUE(uart2, &c); + BUFFER_ENQUEUE(uart2_tx, &c); } void mcu_uart2_flush(void) @@ -735,9 +809,18 @@ void mcu_dotasks() while (tusb_cdc_available()) { - unsigned char c = (unsigned char)tusb_cdc_read(); + uint8_t c = (uint8_t)tusb_cdc_read(); #if !defined(DETACH_USB_FROM_MAIN_PROTOCOL) - mcu_com_rx_cb(c); + if (mcu_com_rx_cb(c)) + { + if (BUFFER_FULL(usb_rx)) + { + c = OVF; + } + + *(BUFFER_NEXT_FREE(usb_rx)) = c; + BUFFER_STORE(usb_rx); + } #else mcu_usb_rx_cb(c); #endif diff --git a/uCNC/src/hal/mcus/stm32f1x/mcumap_stm32f1x.h b/uCNC/src/hal/mcus/stm32f1x/mcumap_stm32f1x.h index ccbe90d68..0358441bf 100644 --- a/uCNC/src/hal/mcus/stm32f1x/mcumap_stm32f1x.h +++ b/uCNC/src/hal/mcus/stm32f1x/mcumap_stm32f1x.h @@ -50,7 +50,7 @@ extern "C" // defines special mcu to access flash strings and arrays #define __rom__ #define __romstr__ -#define __romarr__ const char +#define __romarr__ const uint8_t #define rom_strptr * #define rom_strcpy strcpy #define rom_strncpy strncpy diff --git a/uCNC/src/hal/mcus/stm32f4x/mcu_stm32f4x.c b/uCNC/src/hal/mcus/stm32f4x/mcu_stm32f4x.c index 7e0efef5a..cceb5a376 100644 --- a/uCNC/src/hal/mcus/stm32f4x/mcu_stm32f4x.c +++ b/uCNC/src/hal/mcus/stm32f4x/mcu_stm32f4x.c @@ -79,16 +79,27 @@ volatile bool stm32_global_isr_enabled; #ifndef UART_TX_BUFFER_SIZE #define UART_TX_BUFFER_SIZE 64 #endif -DECL_BUFFER(uint8_t, uart, UART_TX_BUFFER_SIZE); +DECL_BUFFER(uint8_t, uart_tx, UART_TX_BUFFER_SIZE); +DECL_BUFFER(uint8_t, uart_rx, RX_BUFFER_SIZE); + void MCU_SERIAL_ISR(void) { __ATOMIC_FORCEON__ { if (COM_UART->SR & USART_SR_RXNE) { - unsigned char c = COM_INREG; + uint8_t c = COM_INREG; #if !defined(DETACH_UART_FROM_MAIN_PROTOCOL) - mcu_com_rx_cb(c); + if (mcu_com_rx_cb(c)) + { + if (BUFFER_FULL(uart_rx)) + { + c = OVF; + } + + *(BUFFER_NEXT_FREE(uart_rx)) = c; + BUFFER_STORE(uart_rx); + } #else mcu_uart_rx_cb(c); #endif @@ -97,13 +108,13 @@ void MCU_SERIAL_ISR(void) if ((COM_UART->SR & USART_SR_TXE) && (COM_UART->CR1 & USART_CR1_TXEIE)) { mcu_enable_global_isr(); - if (BUFFER_EMPTY(uart)) + if (BUFFER_EMPTY(uart_tx)) { COM_UART->CR1 &= ~(USART_CR1_TXEIE); return; } uint8_t c; - BUFFER_DEQUEUE(uart, &c); + BUFFER_DEQUEUE(uart_tx, &c); COM_OUTREG = c; } } @@ -114,16 +125,27 @@ void MCU_SERIAL_ISR(void) #ifndef UART2_TX_BUFFER_SIZE #define UART2_TX_BUFFER_SIZE 64 #endif -DECL_BUFFER(uint8_t, uart2, UART2_TX_BUFFER_SIZE); +DECL_BUFFER(uint8_t, uart2_tx, UART2_TX_BUFFER_SIZE); +DECL_BUFFER(uint8_t, uart2_rx, RX_BUFFER_SIZE); + void MCU_SERIAL2_ISR(void) { __ATOMIC_FORCEON__ { if (COM2_UART->SR & USART_SR_RXNE) { - unsigned char c = COM2_INREG; + uint8_t c = COM2_INREG; #if !defined(DETACH_UART2_FROM_MAIN_PROTOCOL) - mcu_com_rx_cb(c); + if (mcu_com_rx_cb(c)) + { + if (BUFFER_FULL(uart2_rx)) + { + c = OVF; + } + + *(BUFFER_NEXT_FREE(uart2_rx)) = c; + BUFFER_STORE(uart2_rx); + } #else mcu_uart2_rx_cb(c); #endif @@ -132,13 +154,13 @@ void MCU_SERIAL2_ISR(void) if ((COM2_UART->SR & USART_SR_TXE) && (COM2_UART->CR1 & USART_CR1_TXEIE)) { mcu_enable_global_isr(); - if (BUFFER_EMPTY(uart2)) + if (BUFFER_EMPTY(uart2_tx)) { COM2_UART->CR1 &= ~(USART_CR1_TXEIE); return; } uint8_t c; - BUFFER_DEQUEUE(uart2, &c); + BUFFER_DEQUEUE(uart2_tx, &c); COM2_OUTREG = c; } } @@ -482,6 +504,25 @@ void mcu_usart_init(void) } #ifdef MCU_HAS_USB +DECL_BUFFER(uint8_t, usb_rx, RX_BUFFER_SIZE); + +uint8_t mcu_usb_getc(void) +{ + uint8_t c = 0; + BUFFER_DEQUEUE(usb_rx, &c); + return c; +} + +uint8_t mcu_usb_available(void) +{ + return BUFFER_READ_AVAILABLE(usb_rx); +} + +void mcu_usb_clear(void) +{ + BUFFER_CLEAR(usb_rx); +} + void mcu_usb_putc(uint8_t c) { if (!tusb_cdc_write_available()) @@ -506,14 +547,30 @@ void mcu_usb_flush(void) #endif #ifdef MCU_HAS_UART +uint8_t mcu_uart_getc(void) +{ + uint8_t c = 0; + BUFFER_DEQUEUE(uart_rx, &c); + return c; +} + +uint8_t mcu_uart_available(void) +{ + return BUFFER_READ_AVAILABLE(uart_rx); +} + +void mcu_uart_clear(void) +{ + BUFFER_CLEAR(uart_rx); +} void mcu_uart_putc(uint8_t c) { - while (BUFFER_FULL(uart)) + while (BUFFER_FULL(uart_tx)) { mcu_uart_flush(); } - BUFFER_ENQUEUE(uart, &c); + BUFFER_ENQUEUE(uart_tx, &c); } void mcu_uart_flush(void) @@ -531,14 +588,30 @@ void mcu_uart_flush(void) #endif #ifdef MCU_HAS_UART2 +uint8_t mcu_uart2_getc(void) +{ + uint8_t c = 0; + BUFFER_DEQUEUE(uart2_rx, &c); + return c; +} + +uint8_t mcu_uart2_available(void) +{ + return BUFFER_READ_AVAILABLE(uart2_rx); +} + +void mcu_uart2_clear(void) +{ + BUFFER_CLEAR(uart2_rx); +} void mcu_uart2_putc(uint8_t c) { - while (BUFFER_FULL(uart2)) + while (BUFFER_FULL(uart2_tx)) { mcu_uart2_flush(); } - BUFFER_ENQUEUE(uart2, &c); + BUFFER_ENQUEUE(uart2_tx, &c); } void mcu_uart2_flush(void) @@ -646,7 +719,7 @@ uint8_t mcu_get_servo(uint8_t servo) void mcu_freq_to_clocks(float frequency, uint16_t *ticks, uint16_t *prescaller) { frequency = CLAMP((float)F_STEP_MIN, frequency, (float)F_STEP_MAX); - + // up and down counter (generates half the step rate at each event) uint32_t totalticks = (uint32_t)((float)(TIMER_CLOCK >> 1) / frequency); *prescaller = 1; @@ -729,9 +802,18 @@ void mcu_dotasks() while (tusb_cdc_available()) { - unsigned char c = (unsigned char)tusb_cdc_read(); + uint8_t c = (uint8_t)tusb_cdc_read(); #if !defined(DETACH_USB_FROM_MAIN_PROTOCOL) - mcu_com_rx_cb(c); + if (mcu_com_rx_cb(c)) + { + if (BUFFER_FULL(usb_rx)) + { + c = OVF; + } + + *(BUFFER_NEXT_FREE(usb_rx)) = c; + BUFFER_STORE(usb_rx); + } #else mcu_usb_rx_cb(c); #endif diff --git a/uCNC/src/hal/mcus/stm32f4x/mcumap_stm32f4x.h b/uCNC/src/hal/mcus/stm32f4x/mcumap_stm32f4x.h index f79805205..3f9fc676f 100644 --- a/uCNC/src/hal/mcus/stm32f4x/mcumap_stm32f4x.h +++ b/uCNC/src/hal/mcus/stm32f4x/mcumap_stm32f4x.h @@ -51,7 +51,7 @@ extern "C" // defines special mcu to access flash strings and arrays #define __rom__ #define __romstr__ -#define __romarr__ const char +#define __romarr__ const uint8_t #define rom_strptr * #define rom_strcpy strcpy #define rom_strncpy strncpy diff --git a/uCNC/src/hal/mcus/virtual/mcu_virtual.c b/uCNC/src/hal/mcus/virtual/mcu_virtual.c index 022231cc4..ce96478a3 100644 --- a/uCNC/src/hal/mcus/virtual/mcu_virtual.c +++ b/uCNC/src/hal/mcus/virtual/mcu_virtual.c @@ -7,8 +7,8 @@ void itp_step_isr(); void itp_step_reset_isr(); serial.h - void serial_rx_isr(char c); - char serial_tx_isr(); + void serial_rx_isr(uint8_t c); + uint8_t serial_tx_isr(); trigger_control.h void dio_limits_isr(uint8_t limits); void io_controls_isr(uint8_t controls); @@ -241,7 +241,7 @@ void ioserver(void *args) // Send a message to the pipe server. cbToWrite = sizeof(VIRTUAL_MAP); - char lpvMessage[sizeof(VIRTUAL_MAP)]; + uint8_t lpvMessage[sizeof(VIRTUAL_MAP)]; do { memcpy(lpvMessage, &virtualmap, sizeof(VIRTUAL_MAP)); @@ -310,9 +310,11 @@ void ioserver(void *args) * */ HANDLE rxReady, rxThread; HANDLE txReady, txThread; +HANDLE txReady, txThread, txFree; HANDLE bufferMutex; -char com_buffer[256]; -char mcu_tx_buffer[256]; +HANDLE bufferMutexDone; +uint8_t com_buffer[256]; +uint8_t mcu_tx_buffer[256]; volatile bool mcu_tx_empty; volatile bool mcu_tx_enabled; @@ -331,7 +333,7 @@ DWORD WINAPI socketserver(LPVOID lpParam) struct addrinfo hints; int iSendResult; - char recvbuf[256]; + uint8_t recvbuf[256]; int recvbuflen = 256; // Initialize Winsock @@ -449,7 +451,7 @@ DWORD WINAPI socketserver(LPVOID lpParam) void socketclient(void) { DWORD dwWaitResult; - char buffer[256]; + uint8_t buffer[256]; int iSendResult; int iResult; @@ -504,8 +506,8 @@ void socketclient(void) #ifdef USESERIAL volatile HANDLE hComm = NULL; -unsigned char ComPortName[] = "\\\\.\\" str(WIN_COM_NAME); -unsigned char ComParams[] = "baud=" str(BAUDRATE) " parity=N data=8 stop=1"; +uint8_t ComPortName[] = "\\\\.\\" str(WIN_COM_NAME); +uint8_t ComParams[] = "baud=" str(BAUDRATE) " parity=N data=8 stop=1"; DWORD WINAPI virtualserialserver(LPVOID lpParam) { @@ -596,7 +598,7 @@ DWORD WINAPI virtualserialserver(LPVOID lpParam) // Status event is stored in the event flag // specified in the original WaitCommEvent call. // Deal with the status event as appropriate. - char recvbuf[256]; + uint8_t recvbuf[256]; int recvbuflen = 256; DWORD dwRead = 0; switch (dwCommEvent) @@ -645,7 +647,7 @@ void virtualserialclient(void) { DWORD dwWaitResult; OVERLAPPED osWrite = {0}; - char buffer[256]; + uint8_t buffer[256]; int iSendResult; int iResult; @@ -703,7 +705,8 @@ void virtualserialclient(void) #endif #ifdef USECONSOLE - +DECL_BUFFER(uint8_t, uart_rx, 128); +DECL_BUFFER(uint8_t, uart_tx, 64); DWORD WINAPI virtualconsoleserver(LPVOID lpParam) { WSADATA wsaData; @@ -715,7 +718,7 @@ DWORD WINAPI virtualconsoleserver(LPVOID lpParam) struct addrinfo hints; int iSendResult; - char recvbuf[256]; + uint8_t recvbuf[256]; int recvbuflen = 256; memset(recvbuf, 0, sizeof(recvbuf)); @@ -723,39 +726,19 @@ DWORD WINAPI virtualconsoleserver(LPVOID lpParam) // Receive until the peer shuts down the connection do { - unsigned char c = getchar(); + uint8_t c = getchar(); switch (c) { - // case '"': - // virtualmap.special_inputs ^= (1 << (ESTOP - LIMIT_X)); - // mcu_controls_changed_cb(); - // break; - // case '%': - // virtualmap.special_inputs ^= (1 << (LIMIT_X - LIMIT_X)); - // mcu_limits_changed_cb(); - // break; - // case '&': - // virtualmap.special_inputs ^= (1 << (LIMIT_Y - LIMIT_X)); - // mcu_limits_changed_cb(); - // break; - // case '/': - // virtualmap.special_inputs ^= (1 << (LIMIT_Z - LIMIT_X)); - // mcu_limits_changed_cb(); - // break; - // case '[': - // virtualmap.special_inputs ^= (1 << (LIMIT_X2 - LIMIT_X)); - // mcu_limits_changed_cb(); - // break; - // case ']': - // virtualmap.special_inputs ^= (1 << (LIMIT_Y2 - LIMIT_X)); - // mcu_limits_changed_cb(); - // break; - // case '}': - // virtualmap.special_inputs ^= (1 << (SAFETY_DOOR - LIMIT_X)); - // mcu_controls_changed_cb(); - // break; default: - mcu_com_rx_cb(c); + if (mcu_com_rx_cb(c)) + { + if (BUFFER_FULL(uart_rx)) + { + c = OVF; + } + + BUFFER_ENQUEUE(uart_rx, &c); + } break; } @@ -771,10 +754,10 @@ void virtualconsoleclient(void) while (1) { + SetEvent(txFree); dwWaitResult = WaitForSingleObject( txReady, // event handle INFINITE); // indefinite wait - switch (dwWaitResult) { // Event object was signaled @@ -792,6 +775,7 @@ void virtualconsoleclient(void) { putchar(com_buffer[k]); } + memset(com_buffer, 0, 256); break; // The thread got ownership of an abandoned mutex @@ -805,7 +789,7 @@ void virtualconsoleclient(void) // An error occurred default: printf("Serial client thread error (%d)\n", (int)GetLastError()); - return 0; + return; } memset(com_buffer, 0, 256); @@ -871,6 +855,19 @@ void com_init(void) return; } + txFree = CreateEvent( + NULL, // default security attributes + FALSE, // manual-reset event + FALSE, // initial state is nonsignaled + TEXT("txFree") // object name + ); + + if (txFree == NULL) + { + printf("CreateEvent failed (%d)\n", GetLastError()); + return; + } + rxThread = CreateThread( NULL, // default security attributes 0, // use default stack size @@ -918,28 +915,37 @@ void com_init(void) void com_send(char *buff, int len) { - DWORD dwWaitResult; - dwWaitResult = WaitForSingleObject( - bufferMutex, // handle to mutex - INFINITE); // no time-out interval - mcu_tx_empty = false; + DWORD dwWaitResult = WaitForSingleObject( + txFree, // event handle + INFINITE); // indefinite wait switch (dwWaitResult) { // The thread got ownership of the mutex case WAIT_OBJECT_0: - memcpy(com_buffer, buff, len); - ReleaseMutex(bufferMutex); - mcu_tx_empty = true; - break; + + dwWaitResult = WaitForSingleObject( + bufferMutex, // handle to mutex + INFINITE); // no time-out interval + mcu_tx_empty = false; + switch (dwWaitResult) + { + // The thread got ownership of the mutex + case WAIT_OBJECT_0: + memcpy(com_buffer, buff, len); + ReleaseMutex(bufferMutex); + mcu_tx_empty = true; + break; - // The thread got ownership of an abandoned mutex - case WAIT_ABANDONED: - printf("Wait error (%d)\n", (int)GetLastError()); - return; - } + // The thread got ownership of an abandoned mutex + case WAIT_ABANDONED: + printf("Wait error (%d)\n", (int)GetLastError()); + return; + } - SetEvent(txReady); - sleep(1); + SetEvent(txReady); + break; + } + // sleep(1); } // UART communication @@ -967,7 +973,7 @@ volatile unsigned long *pulse_counter_ptr; volatile unsigned long integrator_counter = 0; volatile bool pulse_enabled = false; volatile bool send_char = false; -volatile unsigned char uart_char; +volatile uint8_t uart_char; uint8_t pwms[16]; @@ -977,7 +983,7 @@ pthread_t thread_idout; pthread_t thread_timer_id; pthread_t thread_step_id; -void mcu_rx_isr(unsigned char c) +void mcu_rx_isr(uint8_t c) { if (c) { @@ -999,7 +1005,7 @@ void mcu_tx_isr(void) // #else // for (;;) // { -// unsigned char c = getch(); +// uint8_t c = getch(); // if (c != 0) // { // uart_char = c; @@ -1127,7 +1133,7 @@ void ticksimul(void) { // FILE *infile = fopen("inputs.txt", "r"); - // char inputs[255]; + // uint8_t inputs[255]; // if (infile != NULL) //checks input file // { @@ -1434,22 +1440,60 @@ bool mcu_tx_ready(void) return mcu_tx_empty; } +uint8_t mcu_uart_getc() +{ + uint8_t c = 0; + BUFFER_DEQUEUE(uart_rx, &c); + + return c; +} + +uint8_t mcu_uart_available(void) +{ + return BUFFER_READ_AVAILABLE(uart_rx); +} + +void mcu_uart_clear(void) +{ + BUFFER_CLEAR(uart_rx); +} + void mcu_uart_putc(uint8_t c) { - // #ifdef ENABLE_SYNC_TX - // com_send(c, 1); - // #endif - putchar(c); + while (BUFFER_FULL(uart_tx)) + { + mcu_uart_flush(); + } + BUFFER_ENQUEUE(uart_tx, &c); } + void mcu_uart_flush(void) { - // #ifndef ENABLE_SYNC_TX - // uint8_t i = (mcu_com_tx_buffer_write < TX_BUFFER_HALF) ? 0 : TX_BUFFER_HALF; - // com_send(&mcu_com_tx_buffer[i], strlen(&mcu_com_tx_buffer[i])); - // #endif + uint8_t buff[64]; + int len = 0; + BUFFER_READ(uart_tx, buff, 64, len); + com_send(buff, len); +#if ASSERT_PIN(ACTIVITY_LED) + io_toggle_output(ACTIVITY_LED); +#endif } -// void mcu_putc(char c) +// void mcu_uart_putc(uint8_t c) +// { +// // #ifdef ENABLE_SYNC_TX +// // com_send(c, 1); +// // #endif +// putchar(c); +// } +// void mcu_uart_flush(void) +// { +// // #ifndef ENABLE_SYNC_TX +// // uint8_t i = (mcu_com_tx_buffer_write < TX_BUFFER_HALF) ? 0 : TX_BUFFER_HALF; +// // com_send(&mcu_com_tx_buffer[i], strlen(&mcu_com_tx_buffer[i])); +// // #endif +// } + +// void mcu_putc(uint8_t c) //{ // static int buff_index = 0; // if (c != 0) @@ -1471,36 +1515,36 @@ void mcu_uart_flush(void) // mcu_tx_enabled = true; // } -char mcu_getc(void) -{ - char c = 0; - if (g_mcu_buffertail != g_mcu_bufferhead) - { - c = g_mcu_combuffer[g_mcu_buffertail]; - if (++g_mcu_buffertail == COM_BUFFER_SIZE) - { - g_mcu_buffertail = 0; - } - - if (c == '\n') - { - g_mcu_buffercount--; - } - } - - return c; -} - -char mcu_peek(void) -{ - if (g_mcu_buffercount == 0) - return 0; - return g_mcu_combuffer[g_mcu_buffertail]; -} +//uint8_t mcu_getc(void) +//{ +// uint8_t c = 0; +// if (g_mcu_buffertail != g_mcu_bufferhead) +// { +// c = g_mcu_combuffer[g_mcu_buffertail]; +// if (++g_mcu_buffertail == COM_BUFFER_SIZE) +// { +// g_mcu_buffertail = 0; +// } +// +// if (c == '\n') +// { +// g_mcu_buffercount--; +// } +// } +// +// return c; +//} +// +//uint8_t mcu_peek(void) +//{ +// if (g_mcu_buffercount == 0) +// return 0; +// return g_mcu_combuffer[g_mcu_buffertail]; +//} void mcu_bufferClear(void) { - memset(&g_mcu_combuffer, 0, sizeof(char) * COM_BUFFER_SIZE); + memset(&g_mcu_combuffer, 0, sizeof(uint8_t) * COM_BUFFER_SIZE); g_mcu_buffertail = 0; g_mcu_bufferhead = 0; } @@ -1553,10 +1597,10 @@ void mcu_stop_itp_isr(void) pulse_enabled = false; } -void mcu_printfp(const char *__fmt, ...) +void mcu_printfp(const uint8_t *__fmt, ...) { - char buffer[50]; - char *newfmt = strcpy((char *)&buffer, __fmt); + uint8_t buffer[50]; + uint8_t *newfmt = strcpy((uint8_t *)&buffer, __fmt); va_list __ap; va_start(__ap, __fmt); vprintf(newfmt, __ap); @@ -1574,18 +1618,18 @@ void virtual_delay_us(uint16_t delay) } while (elapsed < delay); } -void mcu_loadDummyPayload(const char *__fmt, ...) +void mcu_loadDummyPayload(const uint8_t *__fmt, ...) { - char buffer[30]; - char payload[50]; - char *newfmt = strcpy((char *)&buffer, __fmt); + uint8_t buffer[30]; + uint8_t payload[50]; + uint8_t *newfmt = strcpy((uint8_t *)&buffer, __fmt); va_list __ap; va_start(__ap, __fmt); - vsprintf((char *)&payload, newfmt, __ap); + vsprintf((uint8_t *)&payload, newfmt, __ap); va_end(__ap); g_mcu_bufferhead = strlen(payload); memset(&g_mcu_combuffer, 0, g_mcu_bufferhead); - strcpy((char *)&g_mcu_combuffer, payload); + strcpy((uint8_t *)&g_mcu_combuffer, payload); g_mcu_buffertail = 0; g_mcu_buffercount++; } diff --git a/uCNC/src/hal/mcus/virtual/mcumap_virtual.h b/uCNC/src/hal/mcus/virtual/mcumap_virtual.h index 71a1fd3b1..f6ddb75ee 100644 --- a/uCNC/src/hal/mcus/virtual/mcumap_virtual.h +++ b/uCNC/src/hal/mcus/virtual/mcumap_virtual.h @@ -29,7 +29,7 @@ #endif #define __rom__ #define __romstr__ -#define __romarr__ const char +#define __romarr__ const uint8_t #define rom_strptr * #define rom_strcpy strcpy #define rom_strncpy strncpy diff --git a/uCNC/src/interface/grbl_interface.h b/uCNC/src/interface/grbl_interface.h index 80d5e87bc..4f0f6460d 100644 --- a/uCNC/src/interface/grbl_interface.h +++ b/uCNC/src/interface/grbl_interface.h @@ -106,6 +106,7 @@ extern "C" #define STATUS_TOOL_FAILURE 55 #define STATUS_INVALID_PLANE_SELECTED 56 #define STATUS_HARDLIMITS_DISABLED 57 +#define STATUS_STREAM_FAILED 58 #define STATUS_GCODE_EXTENDED_UNSUPPORTED 254 // deprecated #define STATUS_CRITICAL_FAIL 255 diff --git a/uCNC/src/interface/protocol.c b/uCNC/src/interface/protocol.c index f78d66f31..203fe7269 100644 --- a/uCNC/src/interface/protocol.c +++ b/uCNC/src/interface/protocol.c @@ -48,6 +48,7 @@ WEAK_EVENT_HANDLER(protocol_send_gcode_modes) static void protocol_send_newline(void) { protocol_send_string(MSG_EOL); + serial_broadcast(false); } void protocol_send_ok(void) @@ -65,6 +66,7 @@ void protocol_send_error(uint8_t error) void protocol_send_alarm(int8_t alarm) { + serial_broadcast(true); protocol_send_string(MSG_ALARM); serial_print_int(alarm); protocol_send_newline(); @@ -72,19 +74,21 @@ void protocol_send_alarm(int8_t alarm) void protocol_send_string(const char *__s) { - unsigned char c = (unsigned char)rom_strptr(__s++); + uint8_t c = (uint8_t)rom_strptr(__s++); do { serial_putc(c); - c = (unsigned char)rom_strptr(__s++); + c = (uint8_t)rom_strptr(__s++); } while (c != 0); } void protocol_send_feedback(const char *__s) { + serial_broadcast(true); protocol_send_string(MSG_START); protocol_send_string(__s); - protocol_send_string(MSG_END); + serial_putc(']'); + protocol_send_newline(); } void protocol_send_ip(uint32_t ip) @@ -201,6 +205,8 @@ void protocol_send_status(void) return; } + serial_broadcast(true); + float axis[MAX(AXIS_COUNT, 3)]; int32_t steppos[AXIS_TO_STEPPERS]; @@ -399,7 +405,7 @@ void protocol_send_status(void) protocol_send_string(MSG_STATUS_BUF); serial_print_int((uint32_t)planner_get_buffer_freeblocks()); serial_putc(','); - serial_print_int((uint32_t)serial_get_rx_freebytes()); + serial_print_int((uint32_t)serial_freebytes()); } serial_putc('>'); @@ -473,7 +479,7 @@ void protocol_send_probe_result(uint8_t val) protocol_send_newline(); } -static void protocol_send_parser_modalstate(unsigned char word, uint8_t val, uint8_t mantissa) +static void protocol_send_parser_modalstate(uint8_t word, uint8_t val, uint8_t mantissa) { serial_putc(word); serial_print_int(val); @@ -495,6 +501,8 @@ void protocol_send_gcode_modes(void) parser_get_modes(modalgroups, &feed, &spindle, &coolant); + serial_broadcast(true); + protocol_send_string(__romstr__("[GC:")); protocol_send_parser_modalstate('G', modalgroups[0], modalgroups[12]); @@ -568,7 +576,7 @@ void protocol_send_gcode_setting_line_flt(setting_offset_t setting, float value) void protocol_send_start_blocks(void) { protocol_busy = true; - unsigned char c = 0; + uint8_t c = 0; uint16_t address = STARTUP_BLOCK0_ADDRESS_OFFSET; protocol_send_string(__romstr__("$N0=")); for (;;) diff --git a/uCNC/src/interface/serial.c b/uCNC/src/interface/serial.c index 88f4e90ab..ca4110524 100644 --- a/uCNC/src/interface/serial.c +++ b/uCNC/src/interface/serial.c @@ -1,10 +1,21 @@ /* Name: serial.c Description: Serial communication basic read/write functions µCNC. + The serial has been completelly redesigned to allow multiple stream sources of code. + Streams are prority based. + Priority is as follows + UART + UART2 + USB + WIFI + BT + Others + + Copyright: Copyright (c) João Martins Author: João Martins - Date: 30/12/2019 + Date: 07-10-2023 µCNC is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -19,167 +30,312 @@ #include #include "../cnc.h" -static unsigned char serial_rx_buffer[RX_BUFFER_SIZE]; -static uint8_t serial_rx_read; -static volatile uint8_t serial_rx_write; -static volatile uint8_t serial_rx_overflow; +static stream_getc_cb stream_getc; +static stream_available_cb stream_available; +static stream_clear_cb stream_clear; -static uint8_t serial_read_select; -static uint16_t serial_read_index; +#ifndef DISABLE_MULTISTREAM_SERIAL +static serial_stream_t *default_stream; +static serial_stream_t *current_stream; -// static void serial_rx_clear(); +#if defined(MCU_HAS_UART) && !defined(DETACH_UART_FROM_MAIN_PROTOCOL) +DECL_SERIAL_STREAM(uart_serial_stream, mcu_uart_getc, mcu_uart_available, mcu_uart_clear, mcu_uart_putc, mcu_uart_flush); +#endif +#if defined(MCU_HAS_UART2) && !defined(DETACH_UART2_FROM_MAIN_PROTOCOL) +DECL_SERIAL_STREAM(uart2_serial_stream, mcu_uart2_getc, mcu_uart2_available, mcu_uart2_clear, mcu_uart2_putc, mcu_uart2_flush); +#endif +#if defined(MCU_HAS_USB) && !defined(DETACH_USB_FROM_MAIN_PROTOCOL) +DECL_SERIAL_STREAM(usb_serial_stream, mcu_usb_getc, mcu_usb_available, mcu_usb_clear, mcu_usb_putc, mcu_usb_flush); +#endif +#if defined(MCU_HAS_WIFI) && !defined(DETACH_WIFI_FROM_MAIN_PROTOCOL) +DECL_SERIAL_STREAM(wifi_serial_stream, mcu_wifi_getc, mcu_wifi_available, mcu_wifi_clear, mcu_wifi_putc, mcu_wifi_flush); +#endif +#if defined(MCU_HAS_BLUETOOTH) && !defined(DETACH_BLUETOOTH_FROM_MAIN_PROTOCOL) +DECL_SERIAL_STREAM(bt_serial_stream, mcu_bt_getc, mcu_bt_available, mcu_bt_clear, mcu_bt_putc, mcu_bt_flush); +#endif +#else +// if not multistreaming +void (*stream_putc)(uint8_t); +void (*stream_flush)(void); + +#endif + +static uint8_t serial_peek_buffer; void serial_init(void) { #ifdef FORCE_GLOBALS_TO_0 - serial_rx_write = 0; - serial_rx_read = 0; - memset(serial_rx_buffer, 0, sizeof(serial_rx_buffer)); + default_stream = NULL; +#endif +#ifndef DISABLE_MULTISTREAM_SERIAL +#if defined(MCU_HAS_UART) && !defined(DETACH_UART_FROM_MAIN_PROTOCOL) + serial_stream_register(&uart_serial_stream); +#endif +#if defined(MCU_HAS_UART2) && !defined(DETACH_UART2_FROM_MAIN_PROTOCOL) + serial_stream_register(&uart2_serial_stream); +#endif +#if defined(MCU_HAS_USB) && !defined(DETACH_USB_FROM_MAIN_PROTOCOL) + serial_stream_register(&usb_serial_stream); #endif +#if defined(MCU_HAS_WIFI) && !defined(DETACH_WIFI_FROM_MAIN_PROTOCOL) + serial_stream_register(&wifi_serial_stream); +#endif +#if defined(MCU_HAS_BLUETOOTH) && !defined(DETACH_BLUETOOTH_FROM_MAIN_PROTOCOL) + serial_stream_register(&bt_serial_stream); +#endif +#endif + + serial_stream_change(NULL); } -bool serial_rx_is_empty(void) +#ifndef DISABLE_MULTISTREAM_SERIAL +void serial_stream_register(serial_stream_t *stream) { - switch (serial_read_select) + if (default_stream == NULL) { - case SERIAL_UART: - return (serial_rx_write == serial_rx_read); - case SERIAL_N0: - case SERIAL_N1: - return false; + default_stream = stream; + default_stream->next = NULL; } + else + { + serial_stream_t *p = default_stream; + while (p->next != NULL) + { + p = p->next; + } + p->next = stream; + p->next->next = NULL; + } +} - return true; +// on cleanup sets the correct stdin streams +void stream_stdin(uint8_t *p) +{ + stream_getc = current_stream->stream_getc; + stream_available = current_stream->stream_available; + stream_clear = current_stream->stream_clear; } +#endif -unsigned char serial_getc(void) +void serial_stream_change(serial_stream_t *stream) { - unsigned char c; - switch (serial_read_select) +#ifndef DISABLE_MULTISTREAM_SERIAL + uint8_t cleanup __attribute__((__cleanup__(stream_stdin))) = 0; + serial_peek_buffer = 0; + if (stream != NULL) { - case SERIAL_UART: - while (serial_rx_write == serial_rx_read) - { - cnc_dotasks(); - } + current_stream = stream; + return; + } - c = serial_rx_buffer[serial_rx_read]; - if (++serial_rx_read == RX_BUFFER_SIZE) - { - serial_rx_read = 0; - } + // starts by the prioritary and test one by one until one that as characters available is found + current_stream = default_stream; +#else + stream_getc = mcu_getc; + stream_available = mcu_available; + stream_clear = mcu_clear; +#endif +} - switch (c) - { - case '\r': - case '\n': - case EOL: - return EOL; - case '\t': - return ' '; - } +void serial_stream_readonly(stream_getc_cb getc_cb, stream_available_cb available_cb, stream_clear_cb clear_cb) +{ + stream_getc = getc_cb; + stream_available = available_cb; + stream_clear = clear_cb; +} - return c; - break; - case SERIAL_N0: - case SERIAL_N1: - c = mcu_eeprom_getc(serial_read_index++); - if (c > 0 && c < 128) - { - serial_putc(c); - } - else - { - c = 0; - serial_putc(':'); - serial_read_select = SERIAL_UART; // resets the serial select - } - return c; - } +static uint16_t stream_eeprom_address; +static uint8_t stream_eeprom_getc(void) +{ + return mcu_eeprom_getc(stream_eeprom_address++); +} - return EOL; +void serial_stream_eeprom(uint16_t address) +{ + stream_eeprom_address = address; + serial_stream_readonly(&stream_eeprom_getc, NULL, NULL); +} + +char serial_getc(void) +{ + uint8_t peek = serial_peek(); + serial_peek_buffer = 0; + return peek; } -void serial_ungetc(void) +static FORCEINLINE char _serial_peek(void) { - if (--serial_rx_read == 0xFF) + char peek = serial_peek_buffer; + if (peek) { - serial_rx_read = RX_BUFFER_SIZE - 1; + return peek; } + + while (!serial_available()) + { + mcu_dotasks(); + } + +#ifndef DISABLE_MULTISTREAM_SERIAL + if (!stream_getc) + { + // if getc not defined return overflow to force multiple overflow errors + return OVF; + } +#endif + peek = (char)stream_getc(); + // prevents null char reading from eeprom + if (!peek) + { + peek = '\n'; + } + serial_peek_buffer = peek; + return peek; } -void serial_select(uint8_t source) +char serial_peek(void) { - serial_read_select = source; - switch (serial_read_select) + uint8_t peek = _serial_peek(); + switch (peek) { - case SERIAL_N0: - serial_putc('>'); - serial_read_index = STARTUP_BLOCK0_ADDRESS_OFFSET; - break; - case SERIAL_N1: - serial_putc('>'); - serial_read_index = STARTUP_BLOCK1_ADDRESS_OFFSET; - break; + case '\n': + case '\r': + case 0: + return EOL; + case '\t': + return ' '; } + return peek; } -unsigned char serial_peek(void) +uint8_t serial_available(void) { - unsigned char c; - switch (serial_read_select) +#ifndef DISABLE_MULTISTREAM_SERIAL + if (stream_available == NULL) { - case SERIAL_UART: - while (serial_rx_write == serial_rx_read) - { - cnc_dotasks(); - } - c = serial_rx_buffer[serial_rx_read]; - switch (c) + // if undef allow to continue + return 1; + } + + uint8_t count = stream_available(); + if (!count) + { + serial_stream_t *p = default_stream; + while (p != NULL) { - case '\r': - case '\n': - case EOL: - return EOL; - case '\t': - return ' '; - default: - return c; + count = (!(p->stream_available)) ? 0 : p->stream_available(); + if (count) + { + serial_stream_change(p); + return count; + } + p = p->next; } - break; - case SERIAL_N0: - case SERIAL_N1: - c = mcu_eeprom_getc(serial_read_index); - return (c > 0 && c < 128) ? c : 0; } - return EOL; + + return count; +#else + if (!stream_available) + { + // if undef allow to continue + return 1; + } + return stream_available(); +#endif } -void serial_inject_cmd(const char *__s) +uint8_t serial_freebytes(void) { - unsigned char c; - do + return (RX_BUFFER_SIZE - serial_available()); +} + +void serial_clear(void) +{ +#ifndef DISABLE_MULTISTREAM_SERIAL + if (stream_clear) { - c = (unsigned char)*__s++; - mcu_com_rx_cb(c); - } while (c); + stream_clear(); + } +#else + mcu_clear(); +#endif +} + +#ifndef DISABLE_MULTISTREAM_SERIAL +static bool serial_broadcast_enabled; +#endif +void serial_broadcast(bool enable) +{ +#ifndef DISABLE_MULTISTREAM_SERIAL + serial_broadcast_enabled = enable; +#endif } static uint8_t serial_tx_count; -void serial_putc(unsigned char c) +void serial_putc(char c) { serial_tx_count++; +#ifndef DISABLE_MULTISTREAM_SERIAL + if (!serial_broadcast_enabled) + { + if (current_stream->stream_putc) + { + current_stream->stream_putc(c); + } + } + else + { + serial_stream_t *p = default_stream; + while (p) + { + if (p->stream_putc) + { + p->stream_putc((uint8_t)c); + } + p = p->next; + } + } +#else mcu_putc(c); +#endif + if (c == '\n') { serial_tx_count = 0; - mcu_flush(); + serial_flush(); } #if ASSERT_PIN(ACTIVITY_LED) io_toggle_output(ACTIVITY_LED); #endif } +void serial_flush(void) +{ +#ifndef DISABLE_MULTISTREAM_SERIAL + if (!serial_broadcast_enabled) + { + if (current_stream->stream_flush) + { + current_stream->stream_flush(); + } + } + else + { + serial_stream_t *p = default_stream; + while (p) + { + if (p->stream_flush) + { + p->stream_flush(); + } + p = p->next; + } + } +#else + mcu_flush(); +#endif +} + uint8_t serial_tx_busy(void) { return serial_tx_count; @@ -199,7 +355,7 @@ void print_bytes(print_cb cb, const uint8_t *data, uint8_t count) { cb(' '); uint8_t up = *data >> 4; - char c = (up > 9) ? ('a' + up - 10) : ('0' + up); + uint8_t c = (up > 9) ? ('a' + up - 10) : ('0' + up); cb(c); up = *data & 0x0F; c = (up > 9) ? ('a' + up - 10) : ('0' + up); @@ -216,7 +372,7 @@ void print_int(print_cb cb, int32_t num) return; } - unsigned char buffer[11]; + uint8_t buffer[11]; uint8_t i = 0; if (num < 0) @@ -325,83 +481,3 @@ void print_fltarr(print_cb cb, float *arr, uint8_t count) } while (--i); } } - -// ISR -// New char handle strategy -// All ascii will be sent to buffer and processed later (including comments) -MCU_RX_CALLBACK void mcu_com_rx_cb(unsigned char c) -{ - static bool is_grbl_cmd = false; - uint8_t write; - if (c < ((unsigned char)0x7F)) // ascii (all bellow DEL) - { - switch (c) - { - case CMD_CODE_REPORT: -#if STATUS_AUTOMATIC_REPORT_INTERVAL >= 100 - return; -#endif - case CMD_CODE_RESET: - case CMD_CODE_FEED_HOLD: - cnc_call_rt_command((uint8_t)c); - return; - case '\n': - case '\r': - case 0: - // EOL marker - is_grbl_cmd = false; - break; - case '$': - is_grbl_cmd = true; - break; - case CMD_CODE_CYCLE_START: - if (!is_grbl_cmd) - { - cnc_call_rt_command(CMD_CODE_CYCLE_START); - return; - } - break; - } - - if (serial_rx_overflow) - { - c = OVF; - } - write = serial_rx_write; - serial_rx_buffer[write] = c; - if (++write == RX_BUFFER_SIZE) - { - write = 0; - } - if (write == serial_rx_read) - { - serial_rx_overflow++; - } - - serial_rx_write = write; - return; - } - else // extended ascii (plus CMD_CODE_CYCLE_START and DEL) - { - cnc_call_rt_command((uint8_t)c); - } -} - -void serial_rx_clear(void) -{ - serial_rx_write = 0; - serial_rx_read = 0; - serial_rx_overflow = 0; - memset(serial_rx_buffer, 0, RX_BUFFER_SIZE); -} - -uint8_t serial_get_rx_freebytes(void) -{ - uint16_t buf = serial_rx_write; - if (serial_rx_read > buf) - { - buf += RX_BUFFER_SIZE; - } - - return (uint8_t)(RX_BUFFER_CAPACITY - (buf - serial_rx_read)); -} diff --git a/uCNC/src/interface/serial.h b/uCNC/src/interface/serial.h index c0529b436..a33feeb1b 100644 --- a/uCNC/src/interface/serial.h +++ b/uCNC/src/interface/serial.h @@ -24,36 +24,55 @@ extern "C" { #endif +#include #include #include #include -#define EOL 0x00 // end of line char -#define OVF 0x15 // overflow char +#define EOL 0x00 // end of line uint8_t +#define OVF 0x15 // overflow uint8_t #define SAFEMARGIN 2 #ifndef RX_BUFFER_CAPACITY #define RX_BUFFER_CAPACITY 128 #endif #define RX_BUFFER_SIZE (RX_BUFFER_CAPACITY + SAFEMARGIN) // buffer sizes -#define SERIAL_UART 0 -#define SERIAL_N0 1 -#define SERIAL_N1 2 + typedef uint8_t (*stream_getc_cb)(void); + typedef uint8_t (*stream_available_cb)(void); + typedef void (*stream_clear_cb)(void); + + typedef struct serial_stream_ + { + stream_getc_cb stream_getc; + stream_available_cb stream_available; + stream_clear_cb stream_clear; + void (*stream_putc)(uint8_t); + void (*stream_flush)(void); + struct serial_stream_ *next; + } serial_stream_t; + +#define DECL_SERIAL_STREAM(name, getc_cb, available_cb, clear_cb, putc_cb, flush_cb) serial_stream_t name = {getc_cb, available_cb, clear_cb, putc_cb, flush_cb, NULL} void serial_init(); - bool serial_rx_is_empty(void); - unsigned char serial_getc(void); - void serial_ungetc(void); - unsigned char serial_peek(void); - void serial_inject_cmd(const char *__s); - void serial_rx_clear(void); - void serial_select(uint8_t source); + void serial_stream_register(serial_stream_t *stream); + void serial_stream_change(serial_stream_t *stream); + void serial_stream_readonly(stream_getc_cb getc_cb, stream_available_cb available_cb, stream_clear_cb clear_cb); + void serial_stream_eeprom(uint16_t address); - void serial_putc(unsigned char c); + void serial_broadcast(bool enable); + void serial_putc(char c); + void serial_flush(void); uint8_t serial_tx_busy(void); + + char serial_getc(void); + char serial_peek(void); + uint8_t serial_available(void); + void serial_clear(void); + uint8_t serial_freebytes(void); + // printing utils - typedef void (*print_cb)(unsigned char); + typedef void (*print_cb)(char); void print_str(print_cb cb, const char *__s); void print_bytes(print_cb cb, const uint8_t *data, uint8_t count); void print_int(print_cb cb, int32_t num); @@ -70,8 +89,6 @@ extern "C" #define serial_print_intarr(arr, count) print_intarr(serial_putc, arr, count) #define serial_print_fltarr(arr, count) print_fltarr(serial_putc, arr, count) - uint8_t serial_get_rx_freebytes(void); - #ifdef __cplusplus } #endif diff --git a/uCNC/src/interface/settings.c b/uCNC/src/interface/settings.c index bf63aca14..f993209bf 100644 --- a/uCNC/src/interface/settings.c +++ b/uCNC/src/interface/settings.c @@ -186,7 +186,7 @@ WEAK_EVENT_HANDLER(settings_erase) void settings_init(void) { - const char version[3] = SETTINGS_VERSION; + const uint8_t version[3] = SETTINGS_VERSION; uint8_t error = settings_load(SETTINGS_ADDRESS_OFFSET, (uint8_t *)&g_settings, (uint8_t)sizeof(settings_t)); if (!error) @@ -305,7 +305,7 @@ bool settings_allows_negative(setting_offset_t id) } #endif #ifdef ENABLE_SKEW_COMPENSATION - if (id >=37 && id <= 39) + if (id >= 37 && id <= 39) { return true; } @@ -595,10 +595,13 @@ void settings_erase(uint16_t address, uint8_t size) bool settings_check_startup_gcode(uint16_t address) { + serial_putc('>'); + serial_putc(':'); + #ifndef RAM_ONLY_SETTINGS uint8_t size = (RX_BUFFER_SIZE - 1); // defined in serial.h uint8_t crc = 0; - unsigned char c; + uint8_t c; uint16_t cmd_address = address; // pre-checks command valid crc @@ -615,14 +618,16 @@ bool settings_check_startup_gcode(uint16_t address) if (crc ^ mcu_eeprom_getc(cmd_address)) { - serial_putc('>'); - serial_putc(':'); protocol_send_error(STATUS_SETTING_READ_FAIL); settings_erase(address, 1); return false; } -#endif + return true; +#else + protocol_send_ok(); + return false; +#endif } void settings_save_startup_gcode(uint16_t address) @@ -630,12 +635,13 @@ void settings_save_startup_gcode(uint16_t address) #ifndef RAM_ONLY_SETTINGS uint8_t size = (RX_BUFFER_SIZE - 1); uint8_t crc = 0; - unsigned char c; + uint8_t c; do { c = serial_getc(); crc = crc7(c, crc); - mcu_eeprom_putc(address++, (uint8_t)c); + mcu_eeprom_putc(address, (uint8_t)c); + address++; size--; } while (size && c); diff --git a/uCNC/src/interface/settings.h b/uCNC/src/interface/settings.h index 6c396048a..b8826f7ad 100644 --- a/uCNC/src/interface/settings.h +++ b/uCNC/src/interface/settings.h @@ -31,7 +31,7 @@ extern "C" typedef struct { - char version[3]; + uint8_t version[3]; float max_step_rate; // step delay not used uint8_t step_invert_mask; diff --git a/uCNC/src/modules/ic74hc595.c b/uCNC/src/modules/ic74hc595.c index 1ac32605f..8e4e3c0c8 100644 --- a/uCNC/src/modules/ic74hc595.c +++ b/uCNC/src/modules/ic74hc595.c @@ -53,7 +53,7 @@ MCU_CALLBACK void __attribute__((weak)) ic74hc595_shift_io_pins(void) { do { - memcpy(pins, ic74hc595_io_pins, IC74HC595_COUNT); + memcpy(pins, (const void*)ic74hc595_io_pins, IC74HC595_COUNT); mcu_clear_output(IC74HC595_LATCH); for (uint8_t i = IC74HC595_COUNT; i != 0;) { diff --git a/uCNC/src/modules/language/language_en.h b/uCNC/src/modules/language/language_en.h index 4cf773cee..2dc82a79c 100644 --- a/uCNC/src/modules/language/language_en.h +++ b/uCNC/src/modules/language/language_en.h @@ -61,6 +61,7 @@ extern "C" #define STR_TOOL_100 "Tool 100%:" #define STR_RT_CMD_SENT "RT command sent" #define STR_CMD_SENT "Command sent" +#define STR_CMD_NOTSENT "ERROR\nCommand not sent" #define STR_SETTINGS_LOADED "Settings loaded" #define STR_SETTINGS_SAVED "Settings saved" #define STR_SETTINGS_RESET "Settings reset" diff --git a/uCNC/src/modules/softuart.c b/uCNC/src/modules/softuart.c index a2422a113..f4eee6fb4 100644 --- a/uCNC/src/modules/softuart.c +++ b/uCNC/src/modules/softuart.c @@ -17,7 +17,7 @@ */ #include "softuart.h" -void softuart_putc(softuart_port_t *port, uint8_t c) +void softuart_putc(softuart_port_t *port, char c) { if (!port) { @@ -50,7 +50,7 @@ void softuart_putc(softuart_port_t *port, uint8_t c) int16_t softuart_getc(softuart_port_t *port, uint32_t ms_timeout) { - unsigned char val = 0; + char val = 0; if (!port) { diff --git a/uCNC/src/modules/softuart.h b/uCNC/src/modules/softuart.h index e1b8103fd..9ff8b7c2e 100644 --- a/uCNC/src/modules/softuart.h +++ b/uCNC/src/modules/softuart.h @@ -56,7 +56,7 @@ extern "C" void NAME##_waithalf(void) { mcu_delay_cycles(F_CPU / 2 / BAUD); } \ __attribute__((used)) softuart_port_t NAME = {.wait = &NAME##_wait, .waithalf = &NAME##_waithalf, .tx = &NAME##_tx, .rx = &NAME##_rx}; - void softuart_putc(softuart_port_t *port, uint8_t c); + void softuart_putc(softuart_port_t *port, char c); int16_t softuart_getc(softuart_port_t *port, uint32_t ms_timeout); #ifdef __cplusplus diff --git a/uCNC/src/modules/system_menu.c b/uCNC/src/modules/system_menu.c index a06c6ad8d..8f2e6cf6c 100644 --- a/uCNC/src/modules/system_menu.c +++ b/uCNC/src/modules/system_menu.c @@ -437,7 +437,7 @@ void system_menu_render(void) if (!item_index) { char buff[SYSTEM_MENU_MAX_STR_LEN]; - rom_strcpy(buff, menu_page->page_label); + rom_strcpy((char *)buff, (const char *)menu_page->page_label); system_menu_render_header(buff); } @@ -648,7 +648,7 @@ bool system_menu_action_rt_cmd(uint8_t action, system_menu_item_t *item) { cnc_call_rt_command((uint8_t)VARG_CONST(item->action_arg)); char buffer[SYSTEM_MENU_MAX_STR_LEN]; - rom_strcpy(buffer, __romstr__(STR_RT_CMD_SENT)); + rom_strcpy((char *)buffer, __romstr__(STR_RT_CMD_SENT)); system_menu_show_modal_popup(SYSTEM_MENU_MODAL_POPUP_MS, buffer); return true; } @@ -659,11 +659,18 @@ bool system_menu_action_serial_cmd(uint8_t action, system_menu_item_t *item) { if (action == SYSTEM_MENU_ACTION_SELECT && item) { - if (serial_get_rx_freebytes() > 20) + if (serial_freebytes() > 20) { - serial_inject_cmd((const char *)item->action_arg); char buffer[SYSTEM_MENU_MAX_STR_LEN]; - rom_strcpy(buffer, __romstr__(STR_CMD_SENT)); + if (system_menu_send_cmd((const char *)item->action_arg) == STATUS_OK) + { + rom_strcpy((char *)buffer, __romstr__(STR_CMD_SENT)); + } + else + { + rom_strcpy((char *)buffer, __romstr__(STR_CMD_NOTSENT)); + } + system_menu_show_modal_popup(SYSTEM_MENU_MODAL_POPUP_MS, buffer); } return true; @@ -685,7 +692,7 @@ static bool system_menu_action_overrides(uint8_t action, system_menu_item_t *ite } else if (g_system_menu.flags & SYSTEM_MENU_MODE_SIMPLE_EDIT) { - char override = (char)VARG_CONST(item->action_arg); + uint8_t override = (uint8_t)VARG_CONST(item->action_arg); switch (action) { case SYSTEM_MENU_ACTION_NEXT: @@ -739,17 +746,17 @@ static bool system_menu_action_jog(uint8_t action, system_menu_item_t *item) else if (g_system_menu.flags & SYSTEM_MENU_MODE_SIMPLE_EDIT) { // one jog command at time - if (serial_get_rx_freebytes() > 32) + if (serial_freebytes() > 32) { char buffer[SYSTEM_MENU_MAX_STR_LEN]; memset(buffer, 0, SYSTEM_MENU_MAX_STR_LEN); - rom_strcpy(buffer, __romstr__("$J=G91")); + rom_strcpy((char *)buffer, __romstr__("$J=G91")); char *ptr = buffer; // search for the end of string while (*++ptr) ; // replaces the axis letter - *ptr++ = *((char *)item->action_arg); + *ptr++ = *((uint8_t *)item->action_arg); switch (action) { case SYSTEM_MENU_ACTION_NEXT: @@ -770,7 +777,11 @@ static bool system_menu_action_jog(uint8_t action, system_menu_item_t *item) while (*++ptr) ; *ptr++ = '\r'; - serial_inject_cmd(buffer); + if (system_menu_send_cmd(buffer) != STATUS_OK) + { + rom_strcpy((char *)buffer, __romstr__(STR_CMD_NOTSENT)); + system_menu_show_modal_popup(SYSTEM_MENU_MODAL_POPUP_MS, buffer); + } } return true; } @@ -788,15 +799,15 @@ static bool system_menu_action_settings_cmd(uint8_t action, system_menu_item_t * { case 0: settings_init(); - rom_strcpy(buffer, __romstr__(STR_SETTINGS_LOADED)); + rom_strcpy((char *)buffer, __romstr__(STR_SETTINGS_LOADED)); break; case 1: settings_save(SETTINGS_ADDRESS_OFFSET, (uint8_t *)&g_settings, (uint8_t)sizeof(settings_t)); - rom_strcpy(buffer, __romstr__(STR_SETTINGS_SAVED)); + rom_strcpy((char *)buffer, __romstr__(STR_SETTINGS_SAVED)); break; case 2: settings_reset(false); - rom_strcpy(buffer, __romstr__(STR_SETTINGS_RESET)); + rom_strcpy((char *)buffer, __romstr__(STR_SETTINGS_RESET)); break; default: break; @@ -1002,10 +1013,12 @@ bool system_menu_action_edit(uint8_t action, system_menu_item_t *item) case VAR_TYPE_INT16: case VAR_TYPE_UINT16: g_system_menu.current_multiplier = CLAMP(-1, currentmult, 4); + break; case VAR_TYPE_INT32: case VAR_TYPE_UINT32: case VAR_TYPE_FLOAT: g_system_menu.current_multiplier = CLAMP(-1, currentmult, 9); + break; } } @@ -1082,6 +1095,12 @@ void __attribute__((weak)) system_menu_render_modal_popup(const char *__s) // renders the modal popup message } +// this needs to be implemented using a serial stream +uint8_t __attribute__((weak)) system_menu_send_cmd(const char *__s) +{ + return STATUS_STREAM_FAILED; +} + /** * Helper µCNC render callbacks * **/ @@ -1122,7 +1141,7 @@ void system_menu_item_render_var_arg(uint8_t render_flags, system_menu_item_t *i system_menu_flt_to_str(buffer, *((float *)item->argptr)); break; default: - buff_ptr = (char *)item->argptr; + buff_ptr = item->argptr; break; } @@ -1165,7 +1184,7 @@ void system_menu_var_to_str_set_buffer(char *ptr) system_menu_var_to_str_set_buffer_ptr = ptr; } -void system_menu_var_to_str(unsigned char c) +void system_menu_var_to_str(char c) { *system_menu_var_to_str_set_buffer_ptr = c; *(++system_menu_var_to_str_set_buffer_ptr) = 0; diff --git a/uCNC/src/modules/system_menu.h b/uCNC/src/modules/system_menu.h index c972bddef..00042446f 100644 --- a/uCNC/src/modules/system_menu.h +++ b/uCNC/src/modules/system_menu.h @@ -99,9 +99,9 @@ extern "C" const char *label; void *argptr; system_menu_item_render_cb item_render; - void *render_arg; + const void *render_arg; system_menu_item_action_cb item_action; - void *action_arg; + const void *action_arg; }; typedef struct system_menu_index_ @@ -188,6 +188,8 @@ extern "C" void system_menu_render_idle(void); void system_menu_render_alarm(void); void system_menu_render_modal_popup(const char *__s); + // this needs to be implemented using a serial stream + uint8_t system_menu_send_cmd(const char *__s); /** * Helper µCNC action callbacks @@ -213,7 +215,7 @@ extern "C" * **/ extern char *system_menu_var_to_str_set_buffer_ptr; void system_menu_var_to_str_set_buffer(char *ptr); - void system_menu_var_to_str(unsigned char c); + void system_menu_var_to_str(char c); #define system_menu_int_to_str(buf_ptr, var) \ system_menu_var_to_str_set_buffer(buf_ptr); \ diff --git a/uCNC/src/modules/tmc.c b/uCNC/src/modules/tmc.c index ab27eebe8..ccb99e55e 100644 --- a/uCNC/src/modules/tmc.c +++ b/uCNC/src/modules/tmc.c @@ -219,6 +219,7 @@ uint32_t tmc_write_register(tmc_driver_t *driver, uint8_t address, uint32_t val) val >>= 8; data[1] = (uint8_t)(val & 0xFF); driver->rw(data, 5, 5); + break; default: return TMC_WRITE_ERROR; } diff --git a/uCNC/src/utils.h b/uCNC/src/utils.h index 431d32891..f34000b99 100644 --- a/uCNC/src/utils.h +++ b/uCNC/src/utils.h @@ -244,29 +244,27 @@ extern "C" #define BUFFER_READ_AVAILABLE(buffer) (buffer.count) #define BUFFER_EMPTY(buffer) (!buffer.count) #define BUFFER_FULL(buffer) (buffer.count == buffer##_size) -#define BUFFER_PEEK(buffer) (&buffer##_bufferdata[buffer.tail]) -#define BUFFER_PULL(buffer) \ - { \ - uint8_t count, tail; \ - __ATOMIC__ \ - { \ - tail = buffer.tail; \ - } \ - void *p = &buffer##_bufferdata[tail]; \ - if (!BUFFER_EMPTY(buffer)) \ - { \ - tail++; \ - if (tail >= buffer##_size) \ - { \ - tail = 0; \ - } \ - __ATOMIC__ \ - { \ - buffer.tail = tail; \ - buffer.count++; \ - } \ - } \ - p; \ +#define BUFFER_PEEK(buffer) (buffer##_bufferdata[buffer.tail]) +#define BUFFER_REMOVE(buffer) \ + { \ + uint8_t tail; \ + __ATOMIC__ \ + { \ + tail = buffer.tail; \ + } \ + if (!BUFFER_EMPTY(buffer)) \ + { \ + tail++; \ + if (tail >= buffer##_size) \ + { \ + tail = 0; \ + } \ + __ATOMIC__ \ + { \ + buffer.tail = tail; \ + buffer.count--; \ + } \ + } \ } #define BUFFER_DEQUEUE(buffer, ptr) \ @@ -292,7 +290,7 @@ extern "C" } \ } -#define BUFFER_PUSH(buffer) \ +#define BUFFER_STORE(buffer) \ { \ if (!BUFFER_FULL(buffer)) \ { \ @@ -339,7 +337,6 @@ extern "C" #define BUFFER_NEXT_FREE(buffer) (&buffer##_bufferdata[buffer.head]) #define BUFFER_WRITE(buffer, ptr, len, written) ({ \ - written = 0; \ uint8_t count, head; \ __ATOMIC__ \ { \ @@ -347,6 +344,7 @@ extern "C" count = buffer.count; \ } \ count = MIN(buffer##_size - count, len); \ + written = 0; \ if (count) \ { \ uint8_t avail = (buffer##_size - head); \ @@ -380,7 +378,6 @@ extern "C" }) #define BUFFER_READ(buffer, ptr, len, read) ({ \ - read = 0; \ uint8_t count, tail; \ __ATOMIC__ \ { \ @@ -391,6 +388,7 @@ extern "C" { \ count = len; \ } \ + read = 0; \ if (count) \ { \ uint8_t avail = buffer##_size - tail; \ @@ -423,9 +421,16 @@ extern "C" } \ }) -#define BUFFER_CLEAR(buffer) ({__ATOMIC__{buffer##_bufferdata[0] = 0;buffer.tail = 0;buffer.head = 0;buffer.count = 0; \ - } \ - }) +#define BUFFER_CLEAR(buffer) \ + { \ + __ATOMIC__ \ + { \ + buffer##_bufferdata[0] = 0; \ + buffer.tail = 0; \ + buffer.head = 0; \ + buffer.count = 0; \ + } \ + } #ifdef __cplusplus }