I'm trying to interface a futaba receiver(R617FS) with my maple mini STM32F103 micro controller, using the HAL EXT driver.
I'm detecting both edges on interrupt but to calculate I need to know when is rising and when is falling edge to calculate the pulse. How can I do that? Is this the best way to do it?
Code: Select all
systime_t channel_now[4], channel_lastupdate[4];
uint16_t channel_value[4];
void rx_channel1_interrupt(EXTDriver *extp, expchannel_t channel) {
(void)extp;
(void)channel;
chSysLockFromIsr();
channel_now[0] = chTimeNow();
channel_value[0] = channel_now[0] - channel_lastupdate[0];
channel_lastupdate[0] = channel_now[0];
chSysUnlockFromIsr();
}
void rx_channel2_interrupt(EXTDriver *extp, expchannel_t channel) {
(void)extp;
(void)channel;
chSysLockFromIsr();
channel_now[1] = chTimeNow();
channel_value[1] = channel_now[1] - channel_lastupdate[1];
channel_lastupdate[1] = channel_now[1];
chSysUnlockFromIsr();
}
void rx_channel3_interrupt(EXTDriver *extp, expchannel_t channel) {
(void)extp;
(void)channel;
chSysLockFromIsr();
channel_now[2] = chTimeNow();
channel_value[2] = channel_now[2] - channel_lastupdate[2];
channel_lastupdate[2] = channel_now[2];
chSysUnlockFromIsr();
}
void rx_channel4_interrupt(EXTDriver *extp, expchannel_t channel) {
(void)extp;
(void)channel;
chSysLockFromIsr();
channel_now[3] = chTimeNow();
channel_value[3] = channel_now[3] - channel_lastupdate[3];
channel_lastupdate[3] = channel_now[3];
chSysUnlockFromIsr();
}
static const EXTConfig extcfg = {
{
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_RISING_EDGE | EXT_CH_MODE_AUTOSTART, mpu6050_interrupt_handler},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_FALLING_EDGE | EXT_CH_MODE_AUTOSTART, hmc5883_interrupt_handler},
{EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART, rx_channel1_interrupt},
{EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART, rx_channel2_interrupt},
{EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART, rx_channel3_interrupt},
{EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART, rx_channel4_interrupt}
},
EXT_MODE_EXTI(0, /* 0 */
0, /* 1 */
0, /* 2 */
0, /* 3 */
0, /* 4 */
EXT_MODE_GPIOB, /* 5 */
0, /* 6 */
0, /* 7 */
0, /* 8 */
0, /* 9 */
0, /* 10 */
EXT_MODE_GPIOA, /* 11 */
EXT_MODE_GPIOB, /* 12 */
EXT_MODE_GPIOB, /* 13 */
EXT_MODE_GPIOB, /* 14 */
EXT_MODE_GPIOB) /* 15 */
};