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
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
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
card10
firmware
Commits
2fa1945c
Commit
2fa1945c
authored
5 years ago
by
Florian Kargl
Browse files
Options
Downloads
Patches
Plain Diff
Modify PB callback interface to allow distinction between up/down events
parent
47224cbc
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
lib/card10/pb.c
+24
-6
24 additions, 6 deletions
lib/card10/pb.c
lib/card10/pb.h
+145
-0
145 additions, 0 deletions
lib/card10/pb.h
lib/card10/portexpander.c
+1
-1
1 addition, 1 deletion
lib/card10/portexpander.c
lib/card10/portexpander.h
+1
-1
1 addition, 1 deletion
lib/card10/portexpander.h
with
171 additions
and
8 deletions
lib/card10/pb.c
+
24
−
6
View file @
2fa1945c
...
...
@@ -42,6 +42,7 @@
#include
<stddef.h>
static
const
uint8_t
expander_pins
[]
=
{
5
,
0x0
,
3
,
6
};
static
pb_callback
pb_callbacks
[
4
]
=
{
NULL
};
/******************************************************************************/
int
PB_Init
(
void
)
...
...
@@ -62,6 +63,23 @@ int PB_Init(void)
return
retval
;
}
static
void
pe_pb_callback
(
gpio_int_pol_t
edge_type
,
void
*
cbdata
)
{
unsigned
int
pb
=
(
unsigned
int
)
cbdata
;
if
(
pb_callbacks
[
pb
-
1
])
{
pb_callbacks
[
pb
-
1
](
pb
,
edge_type
==
GPIO_INT_FALLING
);
}
}
static
void
gpio_pb_callback
(
void
*
cbdata
)
{
unsigned
int
pb
=
(
unsigned
int
)
cbdata
;
if
(
pb_callbacks
[
pb
-
1
])
{
int
level
=
GPIO_InGet
(
&
pb_pin
[
pb
-
1
]);
pb_callbacks
[
pb
-
1
](
pb
,
!
level
);
}
}
/******************************************************************************/
int
PB_RegisterCallback
(
unsigned
int
pb
,
pb_callback
callback
)
{
...
...
@@ -71,29 +89,29 @@ int PB_RegisterCallback(unsigned int pb, pb_callback callback)
return
E_INVALID
;
}
pb_callbacks
[
pb
-
1
]
=
callback
;
uint8_t
mask
=
(
1
<<
expander_pins
[
pb
-
1
]);
if
(
callback
)
{
if
(
portexpander_detected
())
{
// Register callback
portexpander_register_callback
(
mask
,
callback
,
(
void
*
)
pb
mask
,
pe_pb_
callback
,
(
void
*
)
pb
);
// Configure and enable interrupt
portexpander_int_config
(
mask
,
GPIO_INT_
FALLING
);
portexpander_int_config
(
mask
,
GPIO_INT_
BOTH
);
portexpander_int_enable
(
mask
);
}
else
{
// Register callback
GPIO_RegisterCallback
(
&
pb_pin
[
pb
-
1
],
callback
,
(
void
*
)
pb
&
pb_pin
[
pb
-
1
],
gpio_pb_
callback
,
(
void
*
)
pb
);
// Configure and enable interrupt
GPIO_IntConfig
(
&
pb_pin
[
pb
-
1
],
GPIO_INT_EDGE
,
GPIO_INT_FALLING
&
pb_pin
[
pb
-
1
],
GPIO_INT_EDGE
,
GPIO_INT_BOTH
);
GPIO_IntEnable
(
&
pb_pin
[
pb
-
1
]);
NVIC_EnableIRQ
((
IRQn_Type
)
MXC_GPIO_GET_IRQ
(
...
...
This diff is collapsed.
Click to expand it.
lib/card10/pb.h
0 → 100644
+
145
−
0
View file @
2fa1945c
/**
* @file pb.h
* @brief Pushbutton driver header file.
*/
/* ****************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2018-10-31 15:32:51 +0000 (Wed, 31 Oct 2018) $
* $Revision: 38826 $
*
*************************************************************************** */
#ifndef _PB_H_
#define _PB_H_
#include
"gpio.h"
#include
<stdbool.h>
#ifdef __cplusplus
extern
"C"
{
#endif
/**
* @ingroup bsp
* @defgroup pushbutton_evkit Push button driver board support
* @{
*/
/* **** Global Variables **** */
extern
const
gpio_cfg_t
pb_pin
[];
extern
const
unsigned
int
num_pbs
;
/* **** Function Prototypes **** */
/**
* @brief Initialize all push buttons.
* @return \c #E_NO_ERROR Push buttons initialized successfully.
* @return "Error Code" @ref MXC_Error_Codes "Error Code" if unsuccessful.
*
*/
int
PB_Init
(
void
);
/**
* Type alias @c pb_callback for the push button callback.
* @details The function is of type:
* @code
* void pb_callback(unsigned int pb, bool falling)
* @endcode
* To receive notification of a push button event, define a callback
* function and pass it as a pointer to the PB_RegisterCallback(unsigned int pb, pb_callback callback) function.
* @param pb push button index that triggered the callback.
*/
typedef
void
(
*
pb_callback
)(
unsigned
int
pb
,
bool
falling
);
/**
* @brief Register or Unregister a callback handler for events on the @p pb push button.
* @details
* - Calling this function with a pointer to a function @p callback, configures the pushbutton @p pb and enables the
* interrupt to handle the push button events.
* - Calling this function with a <tt>NULL</tt> pointer will disable the interrupt and unregister the
* callback function.
* @p pb must be a value between 0 and \c num_pbs.
*
* @param pb push button index to receive event callbacks.
* @param callback Callback function pointer of type @c pb_callback
* @return #E_NO_ERROR if configured and callback registered successfully.
* @return "Error Code" @ref MXC_Error_Codes "Error Code" if unsuccessful.
*/
int
PB_RegisterCallback
(
unsigned
int
pb
,
pb_callback
callback
);
/**
* @brief Register or Unregister a callback handler for rising and falling events on the @p pb push button.
* @details
* - Calling this function with a pointer to a function @p callback, configures the pushbutton @p pb and enables the
* interrupt to handle the push button events.
* - Calling this function with a <tt>NULL</tt> pointer will disable the interrupt and unregister the
* callback function.
* @p pb must be a value between 0 and \c num_pbs.
*
* @param pb push button index to receive event callbacks.
* @param callback Callback function pointer of type @c pb_callback
* @return #E_NO_ERROR if configured and callback registered successfully.
* @return "Error Code" @ref MXC_Error_Codes "Error Code" if unsuccessful.
*/
int
PB_RegisterRiseFallCallback
(
unsigned
int
pb
,
pb_callback
callback
);
/**
* @brief Enable a callback interrupt.
* @note PB_RegisterCallback must be called prior to enabling the callback interrupt.
* @param pb push button index value between 0 and \c num_pbs.
*/
void
PB_IntEnable
(
unsigned
int
pb
);
/**
* @brief Disable a callback interrupt.
* @param pb push button index
*/
void
PB_IntDisable
(
unsigned
int
pb
);
/**
* @brief Clear a callback interrupt.
* @param pb push button index value between 0 and \c num_pbs.
*/
void
PB_IntClear
(
unsigned
int
pb
);
/**
* @brief Get the current state of the push button.
* @param pb push button index value between 0 and \c num_pbs.
* @return TRUE The button is pressed.
* @return FALSE The button is not pressed.
*/
int
PB_Get
(
unsigned
int
pb
);
/**@}*/
#ifdef __cplusplus
}
#endif
#endif
/* _PB_H_ */
This diff is collapsed.
Click to expand it.
lib/card10/portexpander.c
+
1
−
1
View file @
2fa1945c
...
...
@@ -335,7 +335,7 @@ void portexpander_poll()
GPIO_INT_FALLING
);
if
((
int_edge_config
[
pin
]
==
GPIO_INT_BOTH
)
||
(
edge_type
==
int_edge_config
[
pin
]))
{
callbacks
[
pin
](
cbparam
[
pin
]);
callbacks
[
pin
](
edge_type
,
cbparam
[
pin
]);
}
}
}
...
...
This diff is collapsed.
Click to expand it.
lib/card10/portexpander.h
+
1
−
1
View file @
2fa1945c
...
...
@@ -16,7 +16,7 @@ typedef struct {
}
portexpander_cfg_t
;
typedef
void
(
*
pe_callback
)(
void
*
cbdata
);
typedef
void
(
*
pe_callback
)(
gpio_int_pol_t
edge_type
,
void
*
cbdata
);
int
portexpander_init
(
void
);
bool
portexpander_detected
(
void
);
...
...
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