void startInputDriver(const char *msg, /*nullable*/digital_input_s *hw, bool isActiveHigh) { if (hw == NULL) { // we can get NULL driver if user somehow has invalid pin in his configuration warning(CUSTOM_ERR_INVALID_INPUT_ICU_PIN, "s_not input pin"); return; } hw->isActiveHigh = isActiveHigh; if (hw->isActiveHigh) { wave_icucfg.mode = ICU_INPUT_ACTIVE_HIGH; } else { wave_icucfg.mode = ICU_INPUT_ACTIVE_LOW; } ICUDriver *driver = hw->driver; if (driver != NULL) { if (hw->started) { icuDisableNotificationsI(driver); icuStopCapture(driver); icuStop(driver); } wave_icucfg.channel = getInputCaptureChannel(hw->brainPin); efiIcuStart(msg, driver, &wave_icucfg); efiAssertVoid(CUSTOM_ERR_6672, driver != NULL, "di: driver is NULL"); efiAssertVoid(CUSTOM_ERR_6673, driver->state == ICU_READY, "di: driver not ready"); icuStartCapture(driver); // this would change state from READY to WAITING icuEnableNotifications(driver); } hw->started = true; }
/* * Application entry point. */ int main(void) { /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); palSetPadMode(TRIGGER_PORT, TRIGGER_PIN, PAL_MODE_OUTPUT_PUSHPULL); palClearPad(TRIGGER_PORT, TRIGGER_PIN); palSetPadMode(GPIOA, GPIOA_PIN8, PAL_MODE_ALTERNATE(1)); icuStart(&ICUD1, &icucfg); icuStartCapture(&ICUD1); icuEnableNotifications(&ICUD1); sdStart(&SD2, NULL); chprintf(chp, "\n\n\r ChibiOS 3.0.2 project by NAFT.\n\r"); chprintf(chp, "\n\r test message to print after boot complete"); chprintf(chp, "\n\r my best number is: %d", 17); chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); chThdCreateStatic(waThread2, sizeof(waThread2), HIGHPRIO, Thread2, NULL); chThdCreateStatic(waThread3, sizeof(waThread3), HIGHPRIO, thread3, NULL); while (true) { chThdSleepMilliseconds(1000); } }
/** * Initialize the serve decoding driver. * * @param d_func * A function that should be called every time the servo signals have been * decoded. Can be NULL. */ void servodec_init(void (*d_func)(void)) { icuStart(&HW_ICU_DEV, &icucfg); palSetPadMode(HW_ICU_GPIO, HW_ICU_PIN, PAL_MODE_ALTERNATE(HW_ICU_GPIO_AF)); icuStartCapture(&HW_ICU_DEV); icuEnableNotifications(&HW_ICU_DEV); for (int i = 0;i < SERVO_NUM;i++) { servo_pos[i] = 0.0; last_len_received[i] = 0.0; } // Set our function pointer done_func = d_func; }
/* * Application entry point. */ int main(void) { /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); /* * Starting PWM driver 1 and enabling the notifications. * GPIOA8 is programmed as PWM output (channel 1 of TIM1). */ pwmStart(&PWMD1, &pwmcfg); pwmEnablePeriodicNotification(&PWMD1); palSetPadMode(GPIOA, GPIOA_ARD_D5, PAL_MODE_ALTERNATE(1)); /* * Starting ICU driver 2. * GPIOA15 is programmed as ICU input (channel 1 of TIM2). */ icuStart(&ICUD2, &icucfg); palSetPadMode(GPIOA, GPIOA_ARD_D9, PAL_MODE_ALTERNATE(1)); /* * GPIOI1 is programmed as output (board LED). */ palClearPad(GPIOI, GPIOI_ARD_D13); palSetPadMode(GPIOI, GPIOI_ARD_D13, PAL_MODE_OUTPUT_PUSHPULL); chThdSleepMilliseconds(1000); /* * Starting ICU capture and enabling the notifications. */ icuStartCapture(&ICUD2); icuEnableNotifications(&ICUD2); /* * Normal main() thread activity, various PWM patterns are generated * cyclically, if the ICU input is connected to the PWM output the * board LED mirrors the PWM output. */ while (true) { /* * Starts the PWM channel 0 using 75% duty cycle. */ pwmEnableChannel(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 7500)); pwmEnableChannelNotification(&PWMD1, 0); chThdSleepMilliseconds(5000); /* * Changes the PWM channel 0 to 50% duty cycle. */ pwmEnableChannel(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 5000)); chThdSleepMilliseconds(5000); /* * Changes the PWM channel 0 to 25% duty cycle. */ pwmEnableChannel(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 2500)); chThdSleepMilliseconds(5000); /* * Changes PWM period to half second the duty cycle becomes 50% * implicitly. */ pwmChangePeriod(&PWMD1, 5000); chThdSleepMilliseconds(5000); /* * Disables channel 0. */ pwmDisableChannel(&PWMD1, 0); } }
/* * Application entry point. */ int main(void) { /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); /* * Initializes the PWM driver 4 and ICU driver 3. * GPIOD12 is the PWM output channel 0. * GPIOC6 is the ICU input ICU_CHANNEL_1. * The two pins have to be externally connected together. */ pwmStart(&PWMD4, &pwmcfg); pwmEnablePeriodicNotification(&PWMD4); palSetPadMode(GPIOD, 12, PAL_MODE_ALTERNATE(2)); icuStart(&ICUD3, &icucfg); palSetPadMode(GPIOC, 6, PAL_MODE_ALTERNATE(2)); icuStartCapture(&ICUD3); icuEnableNotifications(&ICUD3); chThdSleepMilliseconds(2000); /* * Starts the PWM channel 0 using 75% duty cycle. */ pwmEnableChannel(&PWMD4, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD4, 7500)); pwmEnableChannelNotification(&PWMD4, 0); chThdSleepMilliseconds(5000); /* * Changes the PWM channel 0 to 50% duty cycle. */ pwmEnableChannel(&PWMD4, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD4, 5000)); chThdSleepMilliseconds(5000); /* * Changes the PWM channel 0 to 25% duty cycle. */ pwmEnableChannel(&PWMD4, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD4, 2500)); chThdSleepMilliseconds(5000); /* * Changes PWM period to half second the duty cycle becomes 50% * implicitly. */ pwmChangePeriod(&PWMD4, 5000); chThdSleepMilliseconds(5000); /* * Disables channel 0 and stops the drivers. */ pwmDisableChannel(&PWMD4, 0); pwmStop(&PWMD4); icuStopCapture(&ICUD3); icuStop(&ICUD3); palClearPad(GPIOE, GPIOE_LED4_BLUE); palClearPad(GPIOE, GPIOE_LED9_BLUE); /* * Normal main() thread activity, in this demo it does nothing. */ while (true) { chThdSleepMilliseconds(500); } return 0; }