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
d6b4c665
Commit
d6b4c665
authored
Dec 6, 2013
by
Damien
Browse files
Options
Downloads
Patches
Plain Diff
stm: add Led object; add option to reset filesystem.
parent
065f8a5e
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
stm/main.c
+60
-4
60 additions, 4 deletions
stm/main.c
with
60 additions
and
4 deletions
stm/main.c
+
60
−
4
View file @
d6b4c665
...
@@ -127,6 +127,44 @@ py_obj_t pyb_led(py_obj_t state) {
...
@@ -127,6 +127,44 @@ py_obj_t pyb_led(py_obj_t state) {
return
state
;
return
state
;
}
}
py_obj_t
py_obj_new_user
(
const
py_user_info_t
*
info
,
machine_uint_t
data1
,
machine_uint_t
data2
);
void
py_user_get_data
(
py_obj_t
o
,
machine_uint_t
*
data1
,
machine_uint_t
*
data2
);
void
py_user_set_data
(
py_obj_t
o
,
machine_uint_t
data1
,
machine_uint_t
data2
);
py_obj_t
led_obj_on
(
py_obj_t
self
)
{
machine_uint_t
led_id
;
py_user_get_data
(
self
,
&
led_id
,
NULL
);
switch
(
led_id
)
{
case
1
:
led_state
(
PYB_LED_G1
,
1
);
break
;
case
2
:
led_state
(
PYB_LED_G2
,
1
);
break
;
}
return
py_const_none
;
}
py_obj_t
led_obj_off
(
py_obj_t
self
)
{
machine_uint_t
led_id
;
py_user_get_data
(
self
,
&
led_id
,
NULL
);
switch
(
led_id
)
{
case
1
:
led_state
(
PYB_LED_G1
,
0
);
break
;
case
2
:
led_state
(
PYB_LED_G2
,
0
);
break
;
}
return
py_const_none
;
}
const
py_user_info_t
led_obj_info
=
{
"Led"
,
NULL
,
// print
{
{
"on"
,
0
,
led_obj_on
},
{
"off"
,
0
,
led_obj_off
},
{
NULL
,
0
,
NULL
},
}
};
py_obj_t
pyb_Led
(
py_obj_t
led_id
)
{
return
py_obj_new_user
(
&
led_obj_info
,
(
machine_uint_t
)
py_obj_get_int
(
led_id
),
0
);
}
py_obj_t
pyb_sw
(
void
)
{
py_obj_t
pyb_sw
(
void
)
{
if
(
sw_get
())
{
if
(
sw_get
())
{
return
py_const_true
;
return
py_const_true
;
...
@@ -749,6 +787,9 @@ py_obj_t pyb_rng_get(void) {
...
@@ -749,6 +787,9 @@ py_obj_t pyb_rng_get(void) {
int
main
(
void
)
{
int
main
(
void
)
{
// TODO disable JTAG
// TODO disable JTAG
// update the SystemCoreClock variable
SystemCoreClockUpdate
();
// set interrupt priority config to use all 4 bits for pre-empting
// set interrupt priority config to use all 4 bits for pre-empting
NVIC_PriorityGroupConfig
(
NVIC_PriorityGroup_4
);
NVIC_PriorityGroupConfig
(
NVIC_PriorityGroup_4
);
...
@@ -833,6 +874,7 @@ soft_reset:
...
@@ -833,6 +874,7 @@ soft_reset:
rt_store_attr
(
m
,
qstr_from_str_static
(
"uin"
),
rt_make_function_0
(
pyb_usart_receive
));
rt_store_attr
(
m
,
qstr_from_str_static
(
"uin"
),
rt_make_function_0
(
pyb_usart_receive
));
rt_store_attr
(
m
,
qstr_from_str_static
(
"ustat"
),
rt_make_function_0
(
pyb_usart_status
));
rt_store_attr
(
m
,
qstr_from_str_static
(
"ustat"
),
rt_make_function_0
(
pyb_usart_status
));
rt_store_attr
(
m
,
qstr_from_str_static
(
"rng"
),
rt_make_function_0
(
pyb_rng_get
));
rt_store_attr
(
m
,
qstr_from_str_static
(
"rng"
),
rt_make_function_0
(
pyb_rng_get
));
rt_store_attr
(
m
,
qstr_from_str_static
(
"Led"
),
rt_make_function_1
(
pyb_Led
));
rt_store_name
(
qstr_from_str_static
(
"pyb"
),
m
);
rt_store_name
(
qstr_from_str_static
(
"pyb"
),
m
);
rt_store_name
(
qstr_from_str_static
(
"open"
),
rt_make_function_2
(
pyb_io_open
));
rt_store_name
(
qstr_from_str_static
(
"open"
),
rt_make_function_2
(
pyb_io_open
));
...
@@ -841,14 +883,28 @@ soft_reset:
...
@@ -841,14 +883,28 @@ soft_reset:
// print a message to the LCD
// print a message to the LCD
lcd_print_str
(
" micro py board
\n
"
);
lcd_print_str
(
" micro py board
\n
"
);
// check if user switch held (initiates reset of filesystem)
bool
reset_filesystem
=
false
;
if
(
sw_get
())
{
reset_filesystem
=
true
;
for
(
int
i
=
0
;
i
<
50
;
i
++
)
{
if
(
!
sw_get
())
{
reset_filesystem
=
false
;
break
;
}
sys_tick_delay_ms
(
10
);
}
}
// local filesystem init
// local filesystem init
{
{
// try to mount the flash
// try to mount the flash
FRESULT
res
=
f_mount
(
&
fatfs0
,
"0:"
,
1
);
FRESULT
res
=
f_mount
(
&
fatfs0
,
"0:"
,
1
);
if
(
res
==
FR_OK
)
{
if
(
!
reset_filesystem
&&
res
==
FR_OK
)
{
// mount sucessful
// mount sucessful
}
else
if
(
res
==
FR_NO_FILESYSTEM
)
{
}
else
if
(
reset_filesystem
||
res
==
FR_NO_FILESYSTEM
)
{
// no filesystem, so create a fresh one
// no filesystem, so create a fresh one
// TODO doesn't seem to work correctly when reset_filesystem is true...
// LED on to indicate creation of LFS
// LED on to indicate creation of LFS
led_state
(
PYB_LED_R2
,
1
);
led_state
(
PYB_LED_R2
,
1
);
...
@@ -1165,8 +1221,8 @@ soft_reset:
...
@@ -1165,8 +1221,8 @@ soft_reset:
}
}
// wifi
// wifi
pyb_wlan_init
();
//
pyb_wlan_init();
pyb_wlan_start
();
//
pyb_wlan_start();
do_repl
();
do_repl
();
...
...
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