Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
f704e7f2
Commit
f704e7f2
authored
11 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
stmhal: Improve REPL CTRL commands.
parent
2f8beb8d
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
stmhal/main.c
+13
-1
13 additions, 1 deletion
stmhal/main.c
stmhal/pyexec.c
+40
-21
40 additions, 21 deletions
stmhal/pyexec.c
stmhal/pyexec.h
+9
-2
9 additions, 2 deletions
stmhal/pyexec.h
with
62 additions
and
24 deletions
stmhal/main.c
+
13
−
1
View file @
f704e7f2
...
@@ -446,7 +446,19 @@ soft_reset:
...
@@ -446,7 +446,19 @@ soft_reset:
#endif
#endif
#endif
#endif
pyexec_repl
();
// enter REPL
// REPL mode can change, or it can request a soft reset
for
(;;)
{
if
(
pyexec_mode_kind
==
PYEXEC_MODE_RAW_REPL
)
{
if
(
pyexec_raw_repl
()
!=
0
)
{
break
;
}
}
else
{
if
(
pyexec_friendly_repl
()
!=
0
)
{
break
;
}
}
}
printf
(
"PYB: sync filesystems
\n
"
);
printf
(
"PYB: sync filesystems
\n
"
);
storage_flush
();
storage_flush
();
...
...
This diff is collapsed.
Click to expand it.
stmhal/pyexec.c
+
40
−
21
View file @
f704e7f2
...
@@ -24,7 +24,8 @@
...
@@ -24,7 +24,8 @@
#include
"usb.h"
#include
"usb.h"
#include
"usart.h"
#include
"usart.h"
static
bool
repl_display_debugging_info
=
0
;
pyexec_mode_kind_t
pyexec_mode_kind
=
PYEXEC_MODE_FRIENDLY_REPL
;
STATIC
bool
repl_display_debugging_info
=
0
;
void
stdout_tx_str
(
const
char
*
str
)
{
void
stdout_tx_str
(
const
char
*
str
)
{
if
(
pyb_usart_global_debug
!=
PYB_USART_NONE
)
{
if
(
pyb_usart_global_debug
!=
PYB_USART_NONE
)
{
...
@@ -279,12 +280,12 @@ bool parse_compile_execute(mp_lexer_t *lex, mp_parse_input_kind_t input_kind, bo
...
@@ -279,12 +280,12 @@ bool parse_compile_execute(mp_lexer_t *lex, mp_parse_input_kind_t input_kind, bo
return
ret
;
return
ret
;
}
}
void
pyexec_raw_repl
(
void
)
{
int
pyexec_raw_repl
(
void
)
{
vstr_t
line
;
vstr_t
line
;
vstr_init
(
&
line
,
32
);
vstr_init
(
&
line
,
32
);
raw_repl_reset:
raw_repl_reset:
stdout_tx_str
(
"raw REPL; CTRL-
C
to exit
\r\n
"
);
stdout_tx_str
(
"raw REPL; CTRL-
B
to exit
\r\n
"
);
for
(;;)
{
for
(;;)
{
vstr_reset
(
&
line
);
vstr_reset
(
&
line
);
...
@@ -292,11 +293,19 @@ raw_repl_reset:
...
@@ -292,11 +293,19 @@ raw_repl_reset:
for
(;;)
{
for
(;;)
{
char
c
=
stdin_rx_chr
();
char
c
=
stdin_rx_chr
();
if
(
c
==
VCP_CHAR_CTRL_A
)
{
if
(
c
==
VCP_CHAR_CTRL_A
)
{
// reset raw REPL
goto
raw_repl_reset
;
goto
raw_repl_reset
;
}
else
if
(
c
==
VCP_CHAR_CTRL_B
)
{
// change to friendly REPL
stdout_tx_str
(
"
\r\n
"
);
vstr_clear
(
&
line
);
pyexec_mode_kind
=
PYEXEC_MODE_FRIENDLY_REPL
;
return
0
;
}
else
if
(
c
==
VCP_CHAR_CTRL_C
)
{
}
else
if
(
c
==
VCP_CHAR_CTRL_C
)
{
// clear line
vstr_reset
(
&
line
);
vstr_reset
(
&
line
);
break
;
}
else
if
(
c
==
VCP_CHAR_CTRL_D
)
{
}
else
if
(
c
==
VCP_CHAR_CTRL_D
)
{
// input finished
break
;
break
;
}
else
if
(
c
==
'\r'
)
{
}
else
if
(
c
==
'\r'
)
{
vstr_add_char
(
&
line
,
'\n'
);
vstr_add_char
(
&
line
,
'\n'
);
...
@@ -305,30 +314,35 @@ raw_repl_reset:
...
@@ -305,30 +314,35 @@ raw_repl_reset:
}
}
}
}
// indicate reception of command
stdout_tx_str
(
"OK"
);
stdout_tx_str
(
"OK"
);
if
(
vstr_len
(
&
line
)
==
0
)
{
if
(
line
.
len
==
0
)
{
// finished
// exit for a soft reset
break
;
stdout_tx_str
(
"
\r\n
"
);
vstr_clear
(
&
line
);
return
1
;
}
}
mp_lexer_t
*
lex
=
mp_lexer_new_from_str_len
(
MP_QSTR__lt_stdin_gt_
,
vstr_str
(
&
line
),
vstr_len
(
&
line
)
,
0
);
mp_lexer_t
*
lex
=
mp_lexer_new_from_str_len
(
MP_QSTR__lt_stdin_gt_
,
line
.
buf
,
line
.
len
,
0
);
parse_compile_execute
(
lex
,
MP_PARSE_FILE_INPUT
,
false
);
parse_compile_execute
(
lex
,
MP_PARSE_FILE_INPUT
,
false
);
// indicate end of output with EOF character
stdout_tx_str
(
"
\004
"
);
stdout_tx_str
(
"
\004
"
);
}
}
vstr_clear
(
&
line
);
stdout_tx_str
(
"
\r\n
"
);
}
}
void
pyexec_repl
(
void
)
{
int
pyexec_friendly_repl
(
void
)
{
vstr_t
line
;
vstr_init
(
&
line
,
32
);
#if defined(USE_HOST_MODE) && MICROPY_HW_HAS_LCD
#if defined(USE_HOST_MODE) && MICROPY_HW_HAS_LCD
// in host mode, we enable the LCD for the repl
// in host mode, we enable the LCD for the repl
mp_obj_t
lcd_o
=
rt_call_function_0
(
rt_load_name
(
qstr_from_str
(
"LCD"
)));
mp_obj_t
lcd_o
=
rt_call_function_0
(
rt_load_name
(
qstr_from_str
(
"LCD"
)));
rt_call_function_1
(
rt_load_attr
(
lcd_o
,
qstr_from_str
(
"light"
)),
mp_const_true
);
rt_call_function_1
(
rt_load_attr
(
lcd_o
,
qstr_from_str
(
"light"
)),
mp_const_true
);
#endif
#endif
friendly_repl_reset:
stdout_tx_str
(
"Micro Python build <git hash> on 25/1/2014; "
MICROPY_HW_BOARD_NAME
" with STM32F405RG
\r\n
"
);
stdout_tx_str
(
"Micro Python build <git hash> on 25/1/2014; "
MICROPY_HW_BOARD_NAME
" with STM32F405RG
\r\n
"
);
stdout_tx_str
(
"Type
\"
help()
\"
for more information.
\r\n
"
);
stdout_tx_str
(
"Type
\"
help()
\"
for more information.
\r\n
"
);
...
@@ -350,22 +364,29 @@ void pyexec_repl(void) {
...
@@ -350,22 +364,29 @@ void pyexec_repl(void) {
}
}
*/
*/
vstr_t
line
;
vstr_init
(
&
line
,
32
);
for
(;;)
{
for
(;;)
{
vstr_reset
(
&
line
);
vstr_reset
(
&
line
);
int
ret
=
readline
(
&
line
,
">>> "
);
int
ret
=
readline
(
&
line
,
">>> "
);
if
(
ret
==
VCP_CHAR_CTRL_A
)
{
if
(
ret
==
VCP_CHAR_CTRL_A
)
{
pyexec_raw_repl
();
// change to raw REPL
continue
;
stdout_tx_str
(
"
\r\n
"
);
vstr_clear
(
&
line
);
pyexec_mode_kind
=
PYEXEC_MODE_RAW_REPL
;
return
0
;
}
else
if
(
ret
==
VCP_CHAR_CTRL_B
)
{
// reset friendly REPL
stdout_tx_str
(
"
\r\n
"
);
goto
friendly_repl_reset
;
}
else
if
(
ret
==
VCP_CHAR_CTRL_C
)
{
}
else
if
(
ret
==
VCP_CHAR_CTRL_C
)
{
// break
stdout_tx_str
(
"
\r\n
"
);
stdout_tx_str
(
"
\r\n
"
);
continue
;
continue
;
}
else
if
(
ret
==
VCP_CHAR_CTRL_D
)
{
}
else
if
(
ret
==
VCP_CHAR_CTRL_D
)
{
// EOF
// exit for a soft reset
break
;
stdout_tx_str
(
"
\r\n
"
);
vstr_clear
(
&
line
);
return
1
;
}
else
if
(
vstr_len
(
&
line
)
==
0
)
{
}
else
if
(
vstr_len
(
&
line
)
==
0
)
{
continue
;
continue
;
}
}
...
@@ -385,8 +406,6 @@ void pyexec_repl(void) {
...
@@ -385,8 +406,6 @@ void pyexec_repl(void) {
mp_lexer_t
*
lex
=
mp_lexer_new_from_str_len
(
MP_QSTR__lt_stdin_gt_
,
vstr_str
(
&
line
),
vstr_len
(
&
line
),
0
);
mp_lexer_t
*
lex
=
mp_lexer_new_from_str_len
(
MP_QSTR__lt_stdin_gt_
,
vstr_str
(
&
line
),
vstr_len
(
&
line
),
0
);
parse_compile_execute
(
lex
,
MP_PARSE_SINGLE_INPUT
,
true
);
parse_compile_execute
(
lex
,
MP_PARSE_SINGLE_INPUT
,
true
);
}
}
stdout_tx_str
(
"
\r\n
"
);
}
}
bool
pyexec_file
(
const
char
*
filename
)
{
bool
pyexec_file
(
const
char
*
filename
)
{
...
...
This diff is collapsed.
Click to expand it.
stmhal/pyexec.h
+
9
−
2
View file @
f704e7f2
void
pyexec_raw_repl
(
void
);
typedef
enum
{
void
pyexec_repl
(
void
);
PYEXEC_MODE_RAW_REPL
,
PYEXEC_MODE_FRIENDLY_REPL
,
}
pyexec_mode_kind_t
;
extern
pyexec_mode_kind_t
pyexec_mode_kind
;
int
pyexec_raw_repl
(
void
);
int
pyexec_friendly_repl
(
void
);
bool
pyexec_file
(
const
char
*
filename
);
bool
pyexec_file
(
const
char
*
filename
);
MP_DECLARE_CONST_FUN_OBJ
(
pyb_set_repl_info_obj
);
MP_DECLARE_CONST_FUN_OBJ
(
pyb_set_repl_info_obj
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment