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
7193086c
Commit
7193086c
authored
9 years ago
by
Paul Sokolovsky
Browse files
Options
Downloads
Patches
Plain Diff
esp8266/modmachine: Basic implementation of Timer for OS virtual timers.
parent
4284b381
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
esp8266/modmachine.c
+79
-0
79 additions, 0 deletions
esp8266/modmachine.c
esp8266/qstrdefsport.h
+8
-0
8 additions, 0 deletions
esp8266/qstrdefsport.h
with
87 additions
and
0 deletions
esp8266/modmachine.c
+
79
−
0
View file @
7193086c
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
* The MIT License (MIT)
* The MIT License (MIT)
*
*
* Copyright (c) 2013-2015 Damien P. George
* Copyright (c) 2013-2015 Damien P. George
* Copyright (c) 2016 Paul Sokolovsky
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* of this software and associated documentation files (the "Software"), to deal
...
@@ -27,15 +28,93 @@
...
@@ -27,15 +28,93 @@
#include
<stdint.h>
#include
<stdint.h>
#include
"py/obj.h"
#include
"py/obj.h"
#include
"py/runtime.h"
#include
"extmod/machine_mem.h"
#include
"extmod/machine_mem.h"
#include
"utils.h"
#include
"os_type.h"
#include
"osapi.h"
#if MICROPY_PY_MACHINE
#if MICROPY_PY_MACHINE
typedef
struct
_esp_timer_obj_t
{
mp_obj_base_t
base
;
os_timer_t
timer
;
mp_obj_t
callback
;
}
esp_timer_obj_t
;
const
mp_obj_type_t
esp_timer_type
;
STATIC
void
esp_timer_print
(
const
mp_print_t
*
print
,
mp_obj_t
self_in
,
mp_print_kind_t
kind
)
{
esp_timer_obj_t
*
self
=
self_in
;
mp_printf
(
print
,
"Timer(%p)"
,
&
self
->
timer
);
}
STATIC
mp_obj_t
esp_timer_make_new
(
const
mp_obj_type_t
*
type
,
mp_uint_t
n_args
,
mp_uint_t
n_kw
,
const
mp_obj_t
*
args
)
{
mp_arg_check_num
(
n_args
,
n_kw
,
1
,
1
,
false
);
esp_timer_obj_t
*
tim
=
m_new_obj
(
esp_timer_obj_t
);
tim
->
base
.
type
=
&
esp_timer_type
;
return
tim
;
}
STATIC
void
esp_timer_cb
(
void
*
arg
)
{
esp_timer_obj_t
*
self
=
arg
;
call_function_1_protected
(
self
->
callback
,
self
);
}
STATIC
mp_obj_t
esp_timer_init_helper
(
esp_timer_obj_t
*
self
,
mp_uint_t
n_args
,
const
mp_obj_t
*
pos_args
,
mp_map_t
*
kw_args
)
{
static
const
mp_arg_t
allowed_args
[]
=
{
// { MP_QSTR_freq, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
{
MP_QSTR_period
,
MP_ARG_KW_ONLY
|
MP_ARG_INT
,
{.
u_int
=
0xffffffff
}
},
{
MP_QSTR_mode
,
MP_ARG_KW_ONLY
|
MP_ARG_INT
,
{.
u_int
=
1
}
},
{
MP_QSTR_callback
,
MP_ARG_KW_ONLY
|
MP_ARG_OBJ
,
{.
u_obj
=
mp_const_none
}
},
};
// parse args
mp_arg_val_t
args
[
MP_ARRAY_SIZE
(
allowed_args
)];
mp_arg_parse_all
(
n_args
,
pos_args
,
kw_args
,
MP_ARRAY_SIZE
(
allowed_args
),
allowed_args
,
args
);
self
->
callback
=
args
[
2
].
u_obj
;
os_timer_setfn
(
&
self
->
timer
,
esp_timer_cb
,
self
);
os_timer_arm
(
&
self
->
timer
,
args
[
0
].
u_int
,
args
[
1
].
u_int
);
return
mp_const_none
;
}
STATIC
mp_obj_t
esp_timer_init
(
mp_uint_t
n_args
,
const
mp_obj_t
*
args
,
mp_map_t
*
kw_args
)
{
return
esp_timer_init_helper
(
args
[
0
],
n_args
-
1
,
args
+
1
,
kw_args
);
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_KW
(
esp_timer_init_obj
,
1
,
esp_timer_init
);
STATIC
mp_obj_t
esp_timer_deinit
(
mp_obj_t
self_in
)
{
esp_timer_obj_t
*
self
=
self_in
;
os_timer_disarm
(
&
self
->
timer
);
return
mp_const_none
;
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
esp_timer_deinit_obj
,
esp_timer_deinit
);
STATIC
const
mp_map_elem_t
esp_timer_locals_dict_table
[]
=
{
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_deinit
),
(
mp_obj_t
)
&
esp_timer_deinit_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_init
),
(
mp_obj_t
)
&
esp_timer_init_obj
},
// { MP_OBJ_NEW_QSTR(MP_QSTR_callback), (mp_obj_t)&esp_timer_callback_obj },
};
STATIC
MP_DEFINE_CONST_DICT
(
esp_timer_locals_dict
,
esp_timer_locals_dict_table
);
const
mp_obj_type_t
esp_timer_type
=
{
{
&
mp_type_type
},
.
name
=
MP_QSTR_Timer
,
.
print
=
esp_timer_print
,
.
make_new
=
esp_timer_make_new
,
.
locals_dict
=
(
mp_obj_t
)
&
esp_timer_locals_dict
,
};
STATIC
const
mp_rom_map_elem_t
machine_module_globals_table
[]
=
{
STATIC
const
mp_rom_map_elem_t
machine_module_globals_table
[]
=
{
{
MP_ROM_QSTR
(
MP_QSTR___name__
),
MP_ROM_QSTR
(
MP_QSTR_umachine
)
},
{
MP_ROM_QSTR
(
MP_QSTR___name__
),
MP_ROM_QSTR
(
MP_QSTR_umachine
)
},
{
MP_ROM_QSTR
(
MP_QSTR_mem8
),
MP_ROM_PTR
(
&
machine_mem8_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_mem8
),
MP_ROM_PTR
(
&
machine_mem8_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_mem16
),
MP_ROM_PTR
(
&
machine_mem16_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_mem16
),
MP_ROM_PTR
(
&
machine_mem16_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_mem32
),
MP_ROM_PTR
(
&
machine_mem32_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_mem32
),
MP_ROM_PTR
(
&
machine_mem32_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_Timer
),
MP_ROM_PTR
(
&
esp_timer_type
)
},
};
};
STATIC
MP_DEFINE_CONST_DICT
(
machine_module_globals
,
machine_module_globals_table
);
STATIC
MP_DEFINE_CONST_DICT
(
machine_module_globals
,
machine_module_globals_table
);
...
...
This diff is collapsed.
Click to expand it.
esp8266/qstrdefsport.h
+
8
−
0
View file @
7193086c
...
@@ -147,3 +147,11 @@ Q(ticks_us)
...
@@ -147,3 +147,11 @@ Q(ticks_us)
Q
(
ticks_cpu
)
Q
(
ticks_cpu
)
Q
(
ticks_diff
)
Q
(
ticks_diff
)
Q
(
time
)
Q
(
time
)
// machine
Q
(
Timer
)
Q
(
callback
)
Q
(
deinit
)
Q
(
init
)
Q
(
mode
)
Q
(
period
)
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