Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External 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
Show more breadcrumbs
fleur
firmware
Commits
f63c6728
Commit
f63c6728
authored
5 years ago
by
Florian Kargl
Committed by
rahix
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
feat(pb): Implement callbacks for portexpander buttons
parent
c084a687
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
lib/card10/pb.c
+76
-22
76 additions, 22 deletions
lib/card10/pb.c
with
76 additions
and
22 deletions
lib/card10/pb.c
+
76
−
22
View file @
f63c6728
...
...
@@ -40,6 +40,9 @@
#include
"portexpander.h"
#include
"MAX77650-Arduino-Library.h"
#include
<stddef.h>
static
const
uint8_t
expander_pins
[]
=
{
5
,
0x0
,
3
,
6
};
/******************************************************************************/
int
PB_Init
(
void
)
{
...
...
@@ -62,21 +65,51 @@ int PB_Init(void)
/******************************************************************************/
int
PB_RegisterCallback
(
unsigned
int
pb
,
pb_callback
callback
)
{
MXC_ASSERT
(
pb
<
num_pbs
);
MXC_ASSERT
((
pb
>
0
)
&&
(
pb
<=
num_pbs
));
if
(
pb
==
2
)
{
return
E_INVALID
;
}
uint8_t
mask
=
(
1
<<
expander_pins
[
pb
-
1
]);
// TODO: portexpander support
if
(
callback
)
{
// Register callback
GPIO_RegisterCallback
(
&
pb_pin
[
pb
],
callback
,
(
void
*
)
pb
);
if
(
portexpander_detected
())
{
// Register callback
portexpander_register_callback
(
mask
,
callback
,
(
void
*
)
pb
);
// Configure and enable interrupt
GPIO_IntConfig
(
&
pb_pin
[
pb
],
GPIO_INT_EDGE
,
GPIO_INT_FALLING
);
GPIO_IntEnable
(
&
pb_pin
[
pb
]);
NVIC_EnableIRQ
((
IRQn_Type
)
MXC_GPIO_GET_IRQ
(
pb_pin
[
pb
].
port
));
// Configure and enable interrupt
portexpander_int_config
(
mask
,
GPIO_INT_FALLING
);
portexpander_int_enable
(
mask
);
}
else
{
// Register callback
GPIO_RegisterCallback
(
&
pb_pin
[
pb
-
1
],
callback
,
(
void
*
)
pb
);
// Configure and enable interrupt
GPIO_IntConfig
(
&
pb_pin
[
pb
-
1
],
GPIO_INT_EDGE
,
GPIO_INT_FALLING
);
GPIO_IntEnable
(
&
pb_pin
[
pb
-
1
]);
NVIC_EnableIRQ
((
IRQn_Type
)
MXC_GPIO_GET_IRQ
(
pb_pin
[
pb
-
1
].
port
)
);
}
}
else
{
// Disable interrupt and clear callback
GPIO_IntDisable
(
&
pb_pin
[
pb
]);
GPIO_RegisterCallback
(
&
pb_pin
[
pb
],
NULL
,
NULL
);
if
(
portexpander_detected
())
{
// Disable interrupt and clear callback
portexpander_int_disable
(
mask
);
portexpander_register_callback
(
mask
,
NULL
,
NULL
);
}
else
{
// Disable interrupt and clear callback
GPIO_IntDisable
(
&
pb_pin
[
pb
-
1
]);
GPIO_RegisterCallback
(
&
pb_pin
[
pb
-
1
],
NULL
,
NULL
);
}
}
return
E_NO_ERROR
;
...
...
@@ -85,25 +118,46 @@ int PB_RegisterCallback(unsigned int pb, pb_callback callback)
//******************************************************************************
void
PB_IntEnable
(
unsigned
int
pb
)
{
// TODO: portexpander support
MXC_ASSERT
(
pb
<
num_pbs
);
GPIO_IntEnable
(
&
pb_pin
[
pb
]);
MXC_ASSERT
((
pb
>
0
)
&&
(
pb
<=
num_pbs
));
if
(
pb
==
2
)
{
return
;
}
if
(
portexpander_detected
())
{
portexpander_int_enable
((
1
<<
expander_pins
[
pb
-
1
]));
}
else
{
GPIO_IntEnable
(
&
pb_pin
[
pb
-
1
]);
}
}
//******************************************************************************
void
PB_IntDisable
(
unsigned
int
pb
)
{
// TODO: portexpander support
MXC_ASSERT
(
pb
<
num_pbs
);
GPIO_IntDisable
(
&
pb_pin
[
pb
]);
MXC_ASSERT
((
pb
>
0
)
&&
(
pb
<=
num_pbs
));
if
(
pb
==
2
)
{
return
;
}
if
(
portexpander_detected
())
{
portexpander_int_disable
((
1
<<
expander_pins
[
pb
-
1
]));
}
else
{
GPIO_IntDisable
(
&
pb_pin
[
pb
-
1
]);
}
}
//******************************************************************************
void
PB_IntClear
(
unsigned
int
pb
)
{
// TODO: portexpander support
MXC_ASSERT
(
pb
<
num_pbs
);
GPIO_IntClr
(
&
pb_pin
[
pb
]);
MXC_ASSERT
((
pb
>
0
)
&&
(
pb
<=
num_pbs
));
if
(
pb
==
2
)
{
return
;
}
if
(
portexpander_detected
())
{
portexpander_int_clr
((
1
<<
expander_pins
[
pb
-
1
]));
}
else
{
GPIO_IntClr
(
&
pb_pin
[
pb
-
1
]);
}
}
//******************************************************************************
...
...
@@ -116,8 +170,8 @@ int PB_Get(unsigned int pb)
case
3
:
case
4
:
if
(
portexpander_detected
())
{
uint8_t
port
=
portexpander_in_get
(
0xFF
);
return
(
port
&
(
1
<<
expander_pins
[
pb
-
1
]))
==
0
;
return
portexpander_in_get
(
(
1
<<
expander_pins
[
pb
-
1
]))
==
0
;
}
else
{
return
GPIO_InGet
(
&
pb_pin
[
pb
-
1
])
==
0
;
}
...
...
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