Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cm510_controller_fw
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
humanoides
cm510_controller_fw
Commits
8e38170b
Commit
8e38170b
authored
9 years ago
by
Laia Freixas Mateu
Browse files
Options
Downloads
Patches
Plain Diff
Added some logic to avoid false edge detections due to rebounds on the pushbuttons.
parent
ed45c5cf
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
controllers/include/gpio.h
+2
-0
2 additions, 0 deletions
controllers/include/gpio.h
controllers/src/gpio.c
+96
-20
96 additions, 20 deletions
controllers/src/gpio.c
with
98 additions
and
20 deletions
controllers/include/gpio.h
+
2
−
0
View file @
8e38170b
...
...
@@ -16,6 +16,8 @@ typedef enum {LED_BAT=0x01,LED_TxD=0x02,LED_RxD=0x04,LED_AUX=0x08,LED_MANAGE=0x1
typedef
enum
{
BTN_UP
=
0x10
,
BTN_DOWN
=
0x20
,
BTN_LEFT
=
0x40
,
BTN_RIGHT
=
0x80
,
BTN_START
=
0x01
}
pushbuttons_t
;
#define NUM_BUTTONS 5
#define REBOUND_COUNT 20
/**
* \brief Function to initialize the LED's module
*
...
...
This diff is collapsed.
Click to expand it.
controllers/src/gpio.c
+
96
−
20
View file @
8e38170b
...
...
@@ -5,6 +5,7 @@ typedef struct{
volatile
uint8_t
rising_edge
;
volatile
uint8_t
falling_edge
;
volatile
uint8_t
old_state
;
volatile
uint8_t
state_count
;
}
TButtonState
;
/* private variables */
...
...
@@ -22,85 +23,155 @@ void pushbuttons_loop(void)
button_up
.
pressed
=
0x01
;
if
(
button_up
.
old_state
==
0x00
)
{
button_up
.
rising_edge
=
0x01
;
button_up
.
old_state
=
0x01
;
button_up
.
state_count
++
;
if
(
button_up
.
state_count
==
REBOUND_COUNT
)
{
button_up
.
rising_edge
=
0x01
;
button_up
.
old_state
=
0x01
;
button_up
.
state_count
=
0
;
}
}
else
button_up
.
state_count
=
0
;
}
else
{
if
(
button_up
.
old_state
==
0x01
)
{
button_up
.
falling_edge
=
0x01
;
button_up
.
old_state
=
0x00
;
button_up
.
state_count
++
;
if
(
button_up
.
state_count
==
REBOUND_COUNT
)
{
button_up
.
falling_edge
=
0x01
;
button_up
.
old_state
=
0x00
;
button_up
.
state_count
=
0
;
}
}
else
button_up
.
state_count
=
0
;
}
if
((
~
PINE
&
BTN_DOWN
)
!=
0x00
)
{
button_down
.
pressed
=
0x01
;
if
(
button_down
.
old_state
==
0x00
)
{
button_down
.
rising_edge
=
0x01
;
button_down
.
old_state
=
0x01
;
button_down
.
state_count
++
;
if
(
button_down
.
state_count
==
REBOUND_COUNT
)
{
button_down
.
rising_edge
=
0x01
;
button_down
.
old_state
=
0x01
;
button_down
.
state_count
=
0
;
}
}
else
button_down
.
state_count
=
0
;
}
else
{
if
(
button_down
.
old_state
==
0x01
)
{
button_down
.
falling_edge
=
0x01
;
button_down
.
old_state
=
0x00
;
button_down
.
state_count
++
;
if
(
button_down
.
state_count
==
REBOUND_COUNT
)
{
button_down
.
falling_edge
=
0x01
;
button_down
.
old_state
=
0x00
;
button_down
.
state_count
=
0
;
}
}
else
button_down
.
state_count
=
0
;
}
if
((
~
PINE
&
BTN_LEFT
)
!=
0x00
)
{
button_left
.
pressed
=
0x01
;
if
(
button_left
.
old_state
==
0x00
)
{
button_left
.
rising_edge
=
0x01
;
button_left
.
old_state
=
0x01
;
button_left
.
state_count
++
;
if
(
button_left
.
state_count
==
REBOUND_COUNT
)
{
button_left
.
rising_edge
=
0x01
;
button_left
.
old_state
=
0x01
;
button_left
.
state_count
=
0
;
}
}
else
button_left
.
state_count
=
0
;
}
else
{
if
(
button_left
.
old_state
==
0x01
)
{
button_left
.
falling_edge
=
0x01
;
button_left
.
old_state
=
0x00
;
button_left
.
state_count
++
;
if
(
button_left
.
state_count
==
REBOUND_COUNT
)
{
button_left
.
falling_edge
=
0x01
;
button_left
.
old_state
=
0x00
;
button_left
.
state_count
=
0
;
}
}
else
button_left
.
state_count
=
0
;
}
if
((
~
PINE
&
BTN_RIGHT
)
!=
0x00
)
{
button_right
.
pressed
=
0x01
;
if
(
button_right
.
old_state
==
0x00
)
{
button_right
.
rising_edge
=
0x01
;
button_right
.
old_state
=
0x01
;
button_right
.
state_count
++
;
if
(
button_right
.
state_count
==
REBOUND_COUNT
)
{
button_right
.
rising_edge
=
0x01
;
button_right
.
old_state
=
0x01
;
button_right
.
state_count
=
0
;
}
}
else
button_right
.
state_count
=
0
;
}
else
{
if
(
button_right
.
old_state
==
0x01
)
{
button_right
.
falling_edge
=
0x01
;
button_right
.
old_state
=
0x00
;
button_right
.
state_count
++
;
if
(
button_right
.
state_count
==
REBOUND_COUNT
)
{
button_right
.
falling_edge
=
0x01
;
button_right
.
old_state
=
0x00
;
button_right
.
state_count
=
0
;
}
}
else
button_right
.
state_count
=
0
;
}
if
((
~
PIND
&
BTN_START
)
!=
0x00
)
{
button_start
.
pressed
=
0x01
;
if
(
button_start
.
old_state
==
0x00
)
{
button_start
.
rising_edge
=
0x01
;
button_start
.
old_state
=
0x01
;
button_start
.
state_count
++
;
if
(
button_start
.
state_count
==
REBOUND_COUNT
)
{
button_start
.
rising_edge
=
0x01
;
button_start
.
old_state
=
0x01
;
button_start
.
state_count
=
0
;
}
}
else
button_start
.
state_count
=
0
;
}
else
{
if
(
button_start
.
old_state
==
0x01
)
{
button_start
.
falling_edge
=
0x01
;
button_start
.
old_state
=
0x00
;
button_start
.
state_count
++
;
if
(
button_start
.
state_count
==
REBOUND_COUNT
)
{
button_start
.
falling_edge
=
0x01
;
button_start
.
old_state
=
0x00
;
button_start
.
state_count
=
0
;
}
}
else
button_start
.
state_count
=
0
;
}
}
...
...
@@ -117,22 +188,27 @@ void init_leds(void)
button_up
.
rising_edge
=
0x00
;
button_up
.
falling_edge
=
0x00
;
button_up
.
old_state
=
0x00
;
button_up
.
state_count
=
0x00
;
button_down
.
pressed
=
0x00
;
button_down
.
rising_edge
=
0x00
;
button_down
.
falling_edge
=
0x00
;
button_down
.
old_state
=
0x00
;
button_down
.
state_count
=
0x00
;
button_left
.
pressed
=
0x00
;
button_left
.
rising_edge
=
0x00
;
button_left
.
falling_edge
=
0x00
;
button_left
.
old_state
=
0x00
;
button_left
.
state_count
=
0x00
;
button_right
.
pressed
=
0x00
;
button_right
.
rising_edge
=
0x00
;
button_right
.
falling_edge
=
0x00
;
button_right
.
old_state
=
0x00
;
button_right
.
state_count
=
0x00
;
button_start
.
pressed
=
0x00
;
button_start
.
rising_edge
=
0x00
;
button_start
.
falling_edge
=
0x00
;
button_start
.
old_state
=
0x00
;
button_start
.
state_count
=
0x00
;
}
void
turn_led_on
(
leds_t
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