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
ef13e203
Commit
ef13e203
authored
11 years ago
by
Damien George
Browse files
Options
Downloads
Plain Diff
Merge pull request #410 from dhylands/fix-led
Fix pyb.Led(n) code to work properly.
parents
256afcf9
18d21d1a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
stmhal/led.c
+19
-30
19 additions, 30 deletions
stmhal/led.c
with
19 additions
and
30 deletions
stmhal/led.c
+
19
−
30
View file @
ef13e203
...
...
@@ -13,19 +13,25 @@
#include
"pin.h"
#include
"build/pins.h"
static
const
pin_obj_t
*
gLed
[]
=
{
&
MICROPY_HW_LED1
,
typedef
struct
_pyb_led_obj_t
{
mp_obj_base_t
base
;
machine_uint_t
led_id
;
const
pin_obj_t
*
led_pin
;
}
pyb_led_obj_t
;
STATIC
const
pyb_led_obj_t
pyb_led_obj
[]
=
{
{{
&
pyb_led_type
},
1
,
&
MICROPY_HW_LED1
},
#if defined(MICROPY_HW_LED2)
&
MICROPY_HW_LED2
,
{{
&
pyb_led_type
},
2
,
&
MICROPY_HW_LED2
}
,
#if defined(MICROPY_HW_LED3)
&
MICROPY_HW_LED3
,
{{
&
pyb_led_type
},
3
,
&
MICROPY_HW_LED3
}
,
#if defined(MICROPY_HW_LED4)
&
MICROPY_HW_LED4
,
{{
&
pyb_led_type
},
4
,
&
MICROPY_HW_LED4
}
,
#endif
#endif
#endif
};
#define NUM_LEDS (sizeof(
gLed) / sizeof(gLed
[0]))
#define NUM_LEDS (sizeof(
pyb_led_obj) / sizeof(pyb_led_obj
[0]))
void
led_init
(
void
)
{
/* GPIO structure */
...
...
@@ -38,9 +44,10 @@ void led_init(void) {
/* Turn off LEDs and initialize */
for
(
int
led
=
0
;
led
<
NUM_LEDS
;
led
++
)
{
MICROPY_HW_LED_OFF
(
gLed
[
led
]);
GPIO_InitStructure
.
Pin
=
gLed
[
led
]
->
pin_mask
;
HAL_GPIO_Init
(
gLed
[
led
]
->
gpio
,
&
GPIO_InitStructure
);
const
pin_obj_t
*
led_pin
=
pyb_led_obj
[
led
].
led_pin
;
MICROPY_HW_LED_OFF
(
led_pin
);
GPIO_InitStructure
.
Pin
=
led_pin
->
pin_mask
;
HAL_GPIO_Init
(
led_pin
->
gpio
,
&
GPIO_InitStructure
);
}
#if defined(PYBV4) || defined(PYBV10)
...
...
@@ -82,7 +89,7 @@ void led_state(pyb_led_t led, int state) {
return
;
}
#endif
const
pin_obj_t
*
led_pin
=
gLed
[
led
-
1
];
const
pin_obj_t
*
led_pin
=
pyb_led_obj
[
led
-
1
]
.
led_pin
;
//printf("led_state(%d,%d)\n", led, state);
if
(
state
==
0
)
{
// turn LED off
...
...
@@ -109,7 +116,7 @@ void led_toggle(pyb_led_t led) {
}
#endif
const
pin_obj_t
*
led_pin
=
gLed
[
led
-
1
];
const
pin_obj_t
*
led_pin
=
pyb_led_obj
[
led
-
1
]
.
led_pin
;
GPIO_TypeDef
*
gpio
=
led_pin
->
gpio
;
// We don't know if we're turning the LED on or off, but we don't really
...
...
@@ -138,7 +145,7 @@ int led_get_intensity(pyb_led_t led) {
}
#endif
const
pin_obj_t
*
led_pin
=
gLed
[
led
-
1
];
const
pin_obj_t
*
led_pin
=
pyb_led_obj
[
led
-
1
]
.
led_pin
;
GPIO_TypeDef
*
gpio
=
led_pin
->
gpio
;
// TODO convert high/low to on/off depending on board
...
...
@@ -182,24 +189,6 @@ void led_debug(int n, int delay) {
/******************************************************************************/
/* Micro Python bindings */
typedef
struct
_pyb_led_obj_t
{
mp_obj_base_t
base
;
machine_uint_t
led_id
;
}
pyb_led_obj_t
;
STATIC
const
pyb_led_obj_t
pyb_led_obj
[
NUM_LEDS
]
=
{
{{
&
pyb_led_type
},
1
},
#if defined(PYB_LED2)
{{
&
pyb_led_type
},
2
},
#if defined(PYB_LED3)
{{
&
pyb_led_type
},
3
},
#if defined(PYB_LED4)
{{
&
pyb_led_type
},
4
},
#endif
#endif
#endif
};
void
led_obj_print
(
void
(
*
print
)(
void
*
env
,
const
char
*
fmt
,
...),
void
*
env
,
mp_obj_t
self_in
,
mp_print_kind_t
kind
)
{
pyb_led_obj_t
*
self
=
self_in
;
print
(
env
,
"<LED %lu>"
,
self
->
led_id
);
...
...
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