git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3314 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
b86e5efeeb
commit
fbac4d253d
|
@ -39,12 +39,14 @@
|
|||
* @name EXT channels modes
|
||||
* @{
|
||||
*/
|
||||
#define EXT_CH_MODE_EDGES_MASK 3 /**< @brief Mask of edges field. */
|
||||
#define EXT_CH_MODE_DISABLED 0 /**< @brief Channel disabled. */
|
||||
#define EXT_CH_MODE_RISING_EDGE 1 /**< @brief Rising edge callback. */
|
||||
#define EXT_CH_MODE_FALLING_EDGE 2 /**< @brief Falling edge callback. */
|
||||
/** @brief Both edges callback.*/
|
||||
#define EXT_CH_MODE_BOTH_EDGES (EXT_CH_MODE_RISING_EDGE | \
|
||||
EXT_CH_MODE_FALLING_EDGE)
|
||||
#define EXT_CH_MODE_BOTH_EDGES 3 /**< @brief Both edges callback. */
|
||||
|
||||
#define EXT_CH_MODE_AUTOSTART 4 /**< @brief Channel started
|
||||
automatically on driver start. */
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
|
@ -79,6 +81,26 @@ typedef struct EXTDriver EXTDriver;
|
|||
/* Driver macros. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Enables an EXT channel.
|
||||
*
|
||||
* @param[in] extp pointer to the @p EXTDriver object
|
||||
* @param[in] channel channel to be enabled
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
#define extChannelEnableI(extp, channel) ext_lld_channel_enable(extp, channel)
|
||||
|
||||
/**
|
||||
* @brief Disables an EXT channel.
|
||||
*
|
||||
* @param[in] extp pointer to the @p EXTDriver object
|
||||
* @param[in] channel channel to be disabled
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
#define extChannelDisableI(extp, channel) ext_lld_channel_disable(extp, channel)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* External declarations. */
|
||||
/*===========================================================================*/
|
||||
|
@ -90,6 +112,8 @@ extern "C" {
|
|||
void extObjectInit(EXTDriver *extp);
|
||||
void extStart(EXTDriver *extp, const EXTConfig *config);
|
||||
void extStop(EXTDriver *extp);
|
||||
void extChannelEnable(EXTDriver *extp, expchannel_t channel);
|
||||
void extChannelDisable(EXTDriver *extp, expchannel_t channel);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -328,7 +328,7 @@ void ext_lld_start(EXTDriver *extp) {
|
|||
/* Configuration.*/
|
||||
imr = emr = rtsr = ftsr = 0;
|
||||
for (i = 0; i < EXT_MAX_CHANNELS; i++) {
|
||||
if (extp->config->channels[i].mode != EXT_CH_MODE_DISABLED) {
|
||||
if (extp->config->channels[i].mode & EXT_CH_MODE_AUTOSTART) {
|
||||
if (extp->config->channels[i].cb != NULL)
|
||||
imr |= (1 << i);
|
||||
else
|
||||
|
@ -344,11 +344,11 @@ void ext_lld_start(EXTDriver *extp) {
|
|||
AFIO->EXTICR[2] = extp->config->exti[2];
|
||||
AFIO->EXTICR[3] = extp->config->exti[3];
|
||||
EXTI->SWIER = 0;
|
||||
EXTI->RTSR = rtsr;
|
||||
EXTI->FTSR = ftsr;
|
||||
EXTI->PR = EXT_CHANNELS_MASK;
|
||||
EXTI->EMR = emr;
|
||||
EXTI->IMR = imr;
|
||||
EXTI->RTSR = rtsr;
|
||||
EXTI->FTSR = ftsr;
|
||||
EXTI->PR = EXT_CHANNELS_MASK;
|
||||
EXTI->EMR = emr;
|
||||
EXTI->IMR = imr;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -385,6 +385,45 @@ void ext_lld_stop(EXTDriver *extp) {
|
|||
EXTI->PR = EXT_CHANNELS_MASK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enables an EXT channel.
|
||||
*
|
||||
* @param[in] extp pointer to the @p EXTDriver object
|
||||
* @param[in] channel channel to be enabled
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
void ext_lld_channel_enable(EXTDriver *extp, expchannel_t channel) {
|
||||
|
||||
if (extp->config->channels[channel].cb != NULL)
|
||||
EXTI->IMR |= (1 << channel);
|
||||
else
|
||||
EXTI->EMR |= (1 << channel);
|
||||
if (extp->config->channels[channel].mode & EXT_CH_MODE_RISING_EDGE)
|
||||
EXTI->RTSR |= (1 << channel);
|
||||
if (extp->config->channels[channel].mode & EXT_CH_MODE_FALLING_EDGE)
|
||||
EXTI->FTSR |= (1 << channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disables an EXT channel.
|
||||
*
|
||||
* @param[in] extp pointer to the @p EXTDriver object
|
||||
* @param[in] channel channel to be disabled
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
void ext_lld_channel_disable(EXTDriver *extp, expchannel_t channel) {
|
||||
|
||||
(void)extp;
|
||||
|
||||
EXTI->IMR &= ~(1 << channel);
|
||||
EXTI->EMR &= ~(1 << channel);
|
||||
EXTI->RTSR &= ~(1 << channel);
|
||||
EXTI->FTSR &= ~(1 << channel);
|
||||
EXTI->PR = (1 << channel);
|
||||
}
|
||||
|
||||
#endif /* HAL_USE_EXT */
|
||||
|
||||
/** @} */
|
||||
|
|
|
@ -254,6 +254,8 @@ extern "C" {
|
|||
void ext_lld_init(void);
|
||||
void ext_lld_start(EXTDriver *extp);
|
||||
void ext_lld_stop(EXTDriver *extp);
|
||||
void ext_lld_channel_enable(EXTDriver *extp, expchannel_t channel);
|
||||
void ext_lld_channel_disable(EXTDriver *extp, expchannel_t channel);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -78,6 +78,8 @@ void extObjectInit(EXTDriver *extp) {
|
|||
|
||||
/**
|
||||
* @brief Configures and activates the EXT peripheral.
|
||||
* @post After activation all EXT channels are in the disabled state,
|
||||
* use @p extChannelEnable() in order to activate them.
|
||||
*
|
||||
* @param[in] extp pointer to the @p EXTDriver object
|
||||
* @param[in] config pointer to the @p EXTConfig object
|
||||
|
@ -116,6 +118,50 @@ void extStop(EXTDriver *extp) {
|
|||
chSysUnlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enables an EXT channel.
|
||||
*
|
||||
* @param[in] extp pointer to the @p EXTDriver object
|
||||
* @param[in] channel channel to be enabled
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
void extChannelEnable(EXTDriver *extp, expchannel_t channel) {
|
||||
|
||||
chDbgCheck((extp != NULL) &&
|
||||
(channel < EXT_MAX_CHANNELS) &&
|
||||
(extp->config->channels[channel].mode != EXT_CH_MODE_DISABLED),
|
||||
"extChannelEnable");
|
||||
|
||||
chSysLock();
|
||||
chDbgAssert(extp->state == EXT_ACTIVE,
|
||||
"extChannelEnable(), #1", "invalid state");
|
||||
extChannelEnableI(extp, channel);
|
||||
chSysUnlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disables an EXT channel.
|
||||
*
|
||||
* @param[in] extp pointer to the @p EXTDriver object
|
||||
* @param[in] channel channel to be disabled
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
void extChannelDisable(EXTDriver *extp, expchannel_t channel) {
|
||||
|
||||
chDbgCheck((extp != NULL) &&
|
||||
(channel < EXT_MAX_CHANNELS) &&
|
||||
(extp->config->channels[channel].mode != EXT_CH_MODE_DISABLED),
|
||||
"extChannelDisable");
|
||||
|
||||
chSysLock();
|
||||
chDbgAssert(extp->state == EXT_ACTIVE,
|
||||
"extChannelDisable(), #1", "invalid state");
|
||||
extChannelDisableI(extp, channel);
|
||||
chSysUnlock();
|
||||
}
|
||||
|
||||
#endif /* HAL_USE_EXT */
|
||||
|
||||
/** @} */
|
||||
|
|
|
@ -94,6 +94,30 @@ void ext_lld_stop(EXTDriver *extp) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enables an EXT channel.
|
||||
*
|
||||
* @param[in] extp pointer to the @p EXTDriver object
|
||||
* @param[in] channel channel to be enabled
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
void ext_lld_channel_enable(EXTDriver *extp, expchannel_t channel) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disables an EXT channel.
|
||||
*
|
||||
* @param[in] extp pointer to the @p EXTDriver object
|
||||
* @param[in] channel channel to be disabled
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
void ext_lld_channel_disable(EXTDriver *extp, expchannel_t channel) {
|
||||
|
||||
}
|
||||
|
||||
#endif /* HAL_USE_EXT */
|
||||
|
||||
/** @} */
|
||||
|
|
|
@ -114,6 +114,8 @@ extern "C" {
|
|||
void ext_lld_init(void);
|
||||
void ext_lld_start(EXTDriver *extp);
|
||||
void ext_lld_stop(EXTDriver *extp);
|
||||
void ext_lld_channel_enable(EXTDriver *extp, expchannel_t channel);
|
||||
void ext_lld_channel_disable(EXTDriver *extp, expchannel_t channel);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -51,7 +51,7 @@ static void extcb2(EXTDriver *extp, expchannel_t channel) {
|
|||
|
||||
static const EXTConfig extcfg = {
|
||||
{
|
||||
{EXT_CH_MODE_BOTH_EDGES, extcb1},
|
||||
{EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART, extcb1},
|
||||
{EXT_CH_MODE_DISABLED, NULL},
|
||||
{EXT_CH_MODE_DISABLED, NULL},
|
||||
{EXT_CH_MODE_DISABLED, NULL},
|
||||
|
@ -63,7 +63,7 @@ static const EXTConfig extcfg = {
|
|||
{EXT_CH_MODE_DISABLED, NULL},
|
||||
{EXT_CH_MODE_DISABLED, NULL},
|
||||
{EXT_CH_MODE_DISABLED, NULL},
|
||||
{EXT_CH_MODE_RISING_EDGE, extcb2},
|
||||
{EXT_CH_MODE_RISING_EDGE | EXT_CH_MODE_AUTOSTART, extcb2},
|
||||
{EXT_CH_MODE_DISABLED, NULL},
|
||||
{EXT_CH_MODE_DISABLED, NULL},
|
||||
{EXT_CH_MODE_DISABLED, NULL},
|
||||
|
@ -107,10 +107,13 @@ int main(void) {
|
|||
extStart(&EXTD1, &extcfg);
|
||||
|
||||
/*
|
||||
* Normal main() thread activity, in this demo it does nothing except
|
||||
* sleeping in a loop and check the button state.
|
||||
* Normal main() thread activity, in this demo it enables and disables the
|
||||
* button EXT channel using 5 seconds intervals.
|
||||
*/
|
||||
while (TRUE) {
|
||||
chThdSleepMilliseconds(500);
|
||||
chThdSleepMilliseconds(5000);
|
||||
extChannelDisable(&EXTD1, 0);
|
||||
chThdSleepMilliseconds(5000);
|
||||
extChannelEnable(&EXTD1, 0);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue