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
GitLab 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
3c4b5d42
Commit
3c4b5d42
authored
May 13, 2015
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
stmhal: Implement sys.std{in,out,err}.buffer, for raw byte mode.
It's configurable and only enabled for stmhal port.
parent
968b7dd1
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
py/mpconfig.h
+5
-0
5 additions, 0 deletions
py/mpconfig.h
py/qstrdefs.h
+3
-0
3 additions, 0 deletions
py/qstrdefs.h
stmhal/mpconfigport.h
+1
-0
1 addition, 0 deletions
stmhal/mpconfigport.h
stmhal/pybstdio.c
+39
-0
39 additions, 0 deletions
stmhal/pybstdio.c
with
48 additions
and
0 deletions
py/mpconfig.h
+
5
−
0
View file @
3c4b5d42
...
@@ -594,6 +594,11 @@ typedef double mp_float_t;
...
@@ -594,6 +594,11 @@ typedef double mp_float_t;
#define MICROPY_PY_SYS_STDFILES (0)
#define MICROPY_PY_SYS_STDFILES (0)
#endif
#endif
// Whether to provide sys.{stdin,stdout,stderr}.buffer object
// This is implemented per-port
#ifndef MICROPY_PY_SYS_STDIO_BUFFER
#define MICROPY_PY_SYS_STDIO_BUFFER (0)
#endif
// Extended modules
// Extended modules
...
...
This diff is collapsed.
Click to expand it.
py/qstrdefs.h
+
3
−
0
View file @
3c4b5d42
...
@@ -448,6 +448,9 @@ Q(platform)
...
@@ -448,6 +448,9 @@ Q(platform)
Q
(
stdin
)
Q
(
stdin
)
Q
(
stdout
)
Q
(
stdout
)
Q
(
stderr
)
Q
(
stderr
)
#if MICROPY_PY_SYS_STDIO_BUFFER
Q
(
buffer
)
#endif
Q
(
version
)
Q
(
version
)
Q
(
version_info
)
Q
(
version_info
)
#if MICROPY_PY_ATTRTUPLE
#if MICROPY_PY_ATTRTUPLE
...
...
This diff is collapsed.
Click to expand it.
stmhal/mpconfigport.h
+
1
−
0
View file @
3c4b5d42
...
@@ -66,6 +66,7 @@
...
@@ -66,6 +66,7 @@
#define MICROPY_PY_SYS_EXIT (1)
#define MICROPY_PY_SYS_EXIT (1)
#define MICROPY_PY_SYS_MAXSIZE (1)
#define MICROPY_PY_SYS_MAXSIZE (1)
#define MICROPY_PY_SYS_STDFILES (1)
#define MICROPY_PY_SYS_STDFILES (1)
#define MICROPY_PY_SYS_STDIO_BUFFER (1)
#define MICROPY_PY_COLLECTIONS_ORDEREDDICT (1)
#define MICROPY_PY_COLLECTIONS_ORDEREDDICT (1)
#define MICROPY_PY_MATH_SPECIAL_FUNCTIONS (1)
#define MICROPY_PY_MATH_SPECIAL_FUNCTIONS (1)
#define MICROPY_PY_CMATH (1)
#define MICROPY_PY_CMATH (1)
...
...
This diff is collapsed.
Click to expand it.
stmhal/pybstdio.c
+
39
−
0
View file @
3c4b5d42
...
@@ -48,6 +48,10 @@ typedef struct _pyb_stdio_obj_t {
...
@@ -48,6 +48,10 @@ typedef struct _pyb_stdio_obj_t {
int
fd
;
int
fd
;
}
pyb_stdio_obj_t
;
}
pyb_stdio_obj_t
;
#if MICROPY_PY_SYS_STDIO_BUFFER
STATIC
const
pyb_stdio_obj_t
stdio_buffer_obj
;
#endif
void
stdio_obj_print
(
const
mp_print_t
*
print
,
mp_obj_t
self_in
,
mp_print_kind_t
kind
)
{
void
stdio_obj_print
(
const
mp_print_t
*
print
,
mp_obj_t
self_in
,
mp_print_kind_t
kind
)
{
pyb_stdio_obj_t
*
self
=
self_in
;
pyb_stdio_obj_t
*
self
=
self_in
;
mp_printf
(
print
,
"<io.FileIO %d>"
,
self
->
fd
);
mp_printf
(
print
,
"<io.FileIO %d>"
,
self
->
fd
);
...
@@ -89,6 +93,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(stdio_obj___exit___obj, 4, 4, stdio_o
...
@@ -89,6 +93,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(stdio_obj___exit___obj, 4, 4, stdio_o
// TODO gc hook to close the file if not already closed
// TODO gc hook to close the file if not already closed
STATIC
const
mp_map_elem_t
stdio_locals_dict_table
[]
=
{
STATIC
const
mp_map_elem_t
stdio_locals_dict_table
[]
=
{
#if MICROPY_PY_SYS_STDIO_BUFFER
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_buffer
),
(
mp_obj_t
)
&
stdio_buffer_obj
},
#endif
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_read
),
(
mp_obj_t
)
&
mp_stream_read_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_read
),
(
mp_obj_t
)
&
mp_stream_read_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_readall
),
(
mp_obj_t
)
&
mp_stream_readall_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_readall
),
(
mp_obj_t
)
&
mp_stream_readall_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_readinto
),
(
mp_obj_t
)
&
mp_stream_readinto_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_readinto
),
(
mp_obj_t
)
&
mp_stream_readinto_obj
},
...
@@ -123,3 +130,35 @@ STATIC const mp_obj_type_t stdio_obj_type = {
...
@@ -123,3 +130,35 @@ STATIC const mp_obj_type_t stdio_obj_type = {
const
pyb_stdio_obj_t
mp_sys_stdin_obj
=
{{
&
stdio_obj_type
},
.
fd
=
STDIO_FD_IN
};
const
pyb_stdio_obj_t
mp_sys_stdin_obj
=
{{
&
stdio_obj_type
},
.
fd
=
STDIO_FD_IN
};
const
pyb_stdio_obj_t
mp_sys_stdout_obj
=
{{
&
stdio_obj_type
},
.
fd
=
STDIO_FD_OUT
};
const
pyb_stdio_obj_t
mp_sys_stdout_obj
=
{{
&
stdio_obj_type
},
.
fd
=
STDIO_FD_OUT
};
const
pyb_stdio_obj_t
mp_sys_stderr_obj
=
{{
&
stdio_obj_type
},
.
fd
=
STDIO_FD_ERR
};
const
pyb_stdio_obj_t
mp_sys_stderr_obj
=
{{
&
stdio_obj_type
},
.
fd
=
STDIO_FD_ERR
};
#if MICROPY_PY_SYS_STDIO_BUFFER
STATIC
mp_uint_t
stdio_buffer_read
(
mp_obj_t
self_in
,
void
*
buf
,
mp_uint_t
size
,
int
*
errcode
)
{
for
(
uint
i
=
0
;
i
<
size
;
i
++
)
{
((
byte
*
)
buf
)[
i
]
=
mp_hal_stdin_rx_chr
();
}
return
size
;
}
STATIC
mp_uint_t
stdio_buffer_write
(
mp_obj_t
self_in
,
const
void
*
buf
,
mp_uint_t
size
,
int
*
errcode
)
{
mp_hal_stdout_tx_strn
(
buf
,
size
);
return
size
;
}
STATIC
const
mp_stream_p_t
stdio_buffer_obj_stream_p
=
{
.
read
=
stdio_buffer_read
,
.
write
=
stdio_buffer_write
,
.
is_text
=
false
,
};
STATIC
const
mp_obj_type_t
stdio_buffer_obj_type
=
{
{
&
mp_type_type
},
.
name
=
MP_QSTR_FileIO
,
.
print
=
stdio_obj_print
,
.
getiter
=
mp_identity
,
.
iternext
=
mp_stream_unbuffered_iter
,
.
stream_p
=
&
stdio_buffer_obj_stream_p
,
.
locals_dict
=
(
mp_obj_t
)
&
stdio_locals_dict
,
};
STATIC
const
pyb_stdio_obj_t
stdio_buffer_obj
=
{{
&
stdio_buffer_obj_type
},
.
fd
=
0
};
// fd unused
#endif
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