Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
flow3r firmware
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dos
flow3r firmware
Commits
f48cf671
Commit
f48cf671
authored
11 years ago
by
Damien
Browse files
Options
Downloads
Patches
Plain Diff
Implement crude but working REPL for board.
parent
cbb8868f
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
stm/main.c
+27
-21
27 additions, 21 deletions
stm/main.c
stm/printf.c
+2
-2
2 additions, 2 deletions
stm/printf.c
stm/usb.c
+11
-9
11 additions, 9 deletions
stm/usb.c
with
40 additions
and
32 deletions
stm/main.c
+
27
−
21
View file @
f48cf671
...
@@ -184,32 +184,38 @@ static void board_info() {
...
@@ -184,32 +184,38 @@ static void board_info() {
}
}
char
*
readline
(
const
char
*
prompt
)
{
char
*
readline
(
const
char
*
prompt
)
{
printf
(
"a
\n
"
);
vstr_t
vstr
;
led_state
(
PYB_LED_R1
,
1
);
vstr_init
(
&
vstr
);
printf
(
"b
\n
"
);
usb_vcp_send_str
(
prompt
);
usb_vcp_send_str
(
prompt
);
for
(;;)
{
for
(;;)
{
printf
(
"c
\n
"
);
//extern int rx_buf_in;
led_state
(
PYB_LED_R2
,
1
);
//extern int rx_buf_out;
while
(
usb_vcp_rx_any
()
==
0
)
{
//printf("nope %x %x\n", rx_buf_in, rx_buf_out);
sys_tick_delay_ms
(
10
);
}
char
c
=
usb_vcp_rx_get
();
char
c
=
usb_vcp_rx_get
();
led_state
(
PYB_LED_R2
,
0
);
if
(
c
==
4
&&
vstr_len
(
&
vstr
)
==
0
)
{
return
NULL
;
}
else
if
(
c
==
'\r'
)
{
usb_vcp_send_str
(
"
\r\n
"
);
return
vstr_str
(
&
vstr
);
}
else
if
(
c
==
127
)
{
if
(
vstr_len
(
&
vstr
)
>
0
)
{
vstr_cut_tail
(
&
vstr
,
1
);
usb_vcp_send_str
(
"
\b
\b
"
);
}
}
else
if
(
32
<=
c
&&
c
<=
126
)
{
vstr_add_char
(
&
vstr
,
c
);
usb_vcp_send_strn
(
&
c
,
1
);
usb_vcp_send_strn
(
&
c
,
1
);
led_state
(
PYB_LED_G1
,
1
);
}
sys_tick_delay_ms
(
100
);
sys_tick_delay_ms
(
100
);
led_state
(
PYB_LED_G1
,
0
);
}
}
return
NULL
;
return
NULL
;
}
}
extern
char
rx_buf
[];
extern
int
rx_buf_out
;
void
do_repl
()
{
void
do_repl
()
{
int
i
=
0
;
for
(;;)
{
usb_vcp_send_str
(
"Micro Python
\r\n
"
);
usb_vcp_send_str
(
"Micro Python
\r\n
"
);
printf
(
"%d %d %c
\n
"
,
i
++
,
usb_vcp_rx_any
(),
rx_buf
[
rx_buf_out
]);
sys_tick_delay_ms
(
1000
);
}
for
(;;)
{
for
(;;)
{
char
*
line
=
readline
(
">>> "
);
char
*
line
=
readline
(
">>> "
);
...
@@ -282,6 +288,11 @@ int main() {
...
@@ -282,6 +288,11 @@ int main() {
qstr_init
();
qstr_init
();
rt_init
();
rt_init
();
// add some functions to the python namespace
rt_store_name
(
qstr_from_str_static
(
"pyb_delay"
),
rt_make_function_1
(
pyb_delay
));
rt_store_name
(
qstr_from_str_static
(
"pyb_led"
),
rt_make_function_1
(
pyb_led
));
rt_store_name
(
qstr_from_str_static
(
"pyb_sw"
),
rt_make_function_0
(
pyb_sw
));
// print a message
// print a message
printf
(
" micro py board
\n
"
);
printf
(
" micro py board
\n
"
);
...
@@ -478,11 +489,6 @@ int main() {
...
@@ -478,11 +489,6 @@ int main() {
}
else
{
}
else
{
// execute it!
// execute it!
// add some functions to the python namespace
rt_store_name
(
qstr_from_str_static
(
"pyb_delay"
),
rt_make_function_1
(
pyb_delay
));
rt_store_name
(
qstr_from_str_static
(
"pyb_led"
),
rt_make_function_1
(
pyb_led
));
rt_store_name
(
qstr_from_str_static
(
"pyb_sw"
),
rt_make_function_0
(
pyb_sw
));
py_obj_t
module_fun
=
rt_make_function_from_id
(
1
);
py_obj_t
module_fun
=
rt_make_function_from_id
(
1
);
// flash once
// flash once
...
...
This diff is collapsed.
Click to expand it.
stm/printf.c
+
2
−
2
View file @
f48cf671
...
@@ -209,12 +209,12 @@ int pfenv_printf(const pfenv_t *pfenv, const char *fmt, va_list args) {
...
@@ -209,12 +209,12 @@ int pfenv_printf(const pfenv_t *pfenv, const char *fmt, va_list args) {
}
}
void
lcd_print_strn
(
const
char
*
str
,
unsigned
int
len
);
void
lcd_print_strn
(
const
char
*
str
,
unsigned
int
len
);
void
usb_vcp_send
(
const
char
*
str
,
int
len
);
void
usb_vcp_send
_strn
(
const
char
*
str
,
int
len
);
void
stdout_print_strn
(
void
*
data
,
const
char
*
str
,
unsigned
int
len
)
{
void
stdout_print_strn
(
void
*
data
,
const
char
*
str
,
unsigned
int
len
)
{
// send stdout to LCD and USB CDC VCP
// send stdout to LCD and USB CDC VCP
lcd_print_strn
(
str
,
len
);
lcd_print_strn
(
str
,
len
);
//
usb_vcp_send(str, len);
usb_vcp_send
_strn
(
str
,
len
);
}
}
static
const
pfenv_t
pfenv_stdout
=
{
0
,
stdout_print_strn
};
static
const
pfenv_t
pfenv_stdout
=
{
0
,
stdout_print_strn
};
...
...
This diff is collapsed.
Click to expand it.
stm/usb.c
+
11
−
9
View file @
f48cf671
...
@@ -26,6 +26,7 @@ void usb_init() {
...
@@ -26,6 +26,7 @@ void usb_init() {
}
}
void
usb_vcp_receive
(
const
char
*
buf
,
uint32_t
len
)
{
void
usb_vcp_receive
(
const
char
*
buf
,
uint32_t
len
)
{
if
(
is_enabled
)
{
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
rx_buf
[
rx_buf_in
++
]
=
buf
[
i
];
rx_buf
[
rx_buf_in
++
]
=
buf
[
i
];
if
(
rx_buf_in
>=
sizeof
(
rx_buf
))
{
if
(
rx_buf_in
>=
sizeof
(
rx_buf
))
{
...
@@ -39,6 +40,7 @@ void usb_vcp_receive(const char *buf, uint32_t len) {
...
@@ -39,6 +40,7 @@ void usb_vcp_receive(const char *buf, uint32_t len) {
}
}
}
}
}
}
}
int
usb_vcp_rx_any
()
{
int
usb_vcp_rx_any
()
{
if
(
rx_buf_in
>=
rx_buf_out
)
{
if
(
rx_buf_in
>=
rx_buf_out
)
{
...
...
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