1 Make the Prototype Work
There have been times working on Clock conflics, the PDM depends on PLL clock and FreeRTOS make its own clock. If two many thread opened, none works well. The tick for FreeRTOS is normally 1000, can not responsive well with realtime application. Another solution is duel core cooperation. As another try in later blogs.
This time, with ISR to control based on Anycloud FindMe demo.
After the edrumer connected, the beats detection start automatically.
2 Start the Project
Create the project by copy Findme as template, rename to eDrumer.
int main() { cy_rslt_t rslt; wiced_result_t result; /* This enables RTOS aware debugging in OpenOCD. */ uxTopUsedPriority = configMAX_PRIORITIES - 1; /* Initialize the board support package */ rslt = cybsp_init(); if (CY_RSLT_SUCCESS != rslt) { CY_ASSERT(0); } /* Enable global interrupts */ __enable_irq(); clock_init(); /* Initialize retarget-io to use the debug UART port */ cy_retarget_io_init(CYBSP_DEBUG_UART_TX, CYBSP_DEBUG_UART_RX, CY_RETARGET_IO_BAUDRATE); /* Initialize the User LED */ cyhal_gpio_init(CYBSP_USER_LED3, CYHAL_GPIO_DIR_OUTPUT, CYHAL_GPIO_DRIVE_STRONG, CYBSP_LED_STATE_OFF); /* Initialize the User Button */ cyhal_gpio_init(CYBSP_USER_BTN, CYHAL_GPIO_DIR_INPUT, CYHAL_GPIO_DRIVE_PULLUP, CYBSP_BTN_OFF); cyhal_gpio_enable_event(CYBSP_USER_BTN, CYHAL_GPIO_IRQ_FALL, CYHAL_ISR_PRIORITY_DEFAULT, true); cyhal_gpio_register_callback(CYBSP_USER_BTN, button_isr_handler, NULL); /* Initialize the PDM/PCM block */ cyhal_pdm_pcm_init(&pdm_pcm, PDM_DATA, PDM_CLK, &audio_clock, &pdm_pcm_cfg); cyhal_pdm_pcm_register_callback(&pdm_pcm, pdm_pcm_isr_handler, NULL); cyhal_pdm_pcm_enable_event(&pdm_pcm, CYHAL_PDM_PCM_ASYNC_COMPLETE, CYHAL_ISR_PRIORITY_DEFAULT, true); cyhal_pdm_pcm_start(&pdm_pcm); printf("*********************eDrumer Example***********************************\n"); printf("************* eDrumer Profile Application Start ************************\n"); /* Configure platform specific settings for the BT device */ cybt_platform_config_init(&bt_platform_cfg_settings); /* Register call back and configuration with stack */ result = wiced_bt_stack_init (app_bt_management_callback, &wiced_bt_cfg_settings); /* Check if stack initialization was successful */ if( WICED_BT_SUCCESS == result) { printf("Bluetooth Stack Initialization Successful \n"); } else { printf("Bluetooth Stack Initialization failed!! \n"); CY_ASSERT(0); } /* Start the FreeRTOS scheduler */ vTaskStartScheduler(); /* Should never get here */ CY_ASSERT(0) ; }
This is main.c code to initiated the hardware and timer. The PDM/PCM block need clockinit() first. That brings alot of problems in RTOS applications. So The RTOS is not running in this case.
The main part of the PDM detection is place on adv_led_update() where the hardware is triggered for BLE control remotely.
void adv_led_update(void) { /* CYBSP_USER_LED2 is only present on some kits. For those kits,it is used to indicate advertising/connection status */ #ifdef CYBSP_USER_LED2 cy_rslt_t rslt = CY_RSLT_SUCCESS; /* Stop the advertising led pwm */ cyhal_pwm_stop(&adv_led_pwm); /* Update LED state based on BLE advertising/connection state. * LED OFF for no advertisement/connection, LED blinking for advertisement * state, and LED ON for connected state */ switch(app_bt_adv_conn_state) { case APP_BT_ADV_OFF_CONN_OFF: rslt = cyhal_pwm_set_duty_cycle(&adv_led_pwm, LED_OFF_DUTY_CYCLE, ADV_LED_PWM_FREQUENCY); break; case APP_BT_ADV_ON_CONN_OFF: rslt = cyhal_pwm_set_duty_cycle(&adv_led_pwm, LED_BLINKING_DUTY_CYCLE, ADV_LED_PWM_FREQUENCY); break; case APP_BT_ADV_OFF_CONN_ON: rslt = cyhal_pwm_set_duty_cycle(&adv_led_pwm, LED_ON_DUTY_CYCLE, ADV_LED_PWM_FREQUENCY); break; default: /* LED OFF for unexpected states */ rslt = cyhal_pwm_set_duty_cycle(&adv_led_pwm, LED_OFF_DUTY_CYCLE, ADV_LED_PWM_FREQUENCY); break; } /* Check if update to PWM parameters is successful*/ if (CY_RSLT_SUCCESS != rslt) { printf("Failed to set duty cycle parameters!!"); } rslt = cyhal_pwm_start(&adv_led_pwm); /* Check if PWM started successfully */ if (CY_RSLT_SUCCESS != rslt) { printf("Failed to start PWM !!"); } #endif }
There are some problem with my newly updated window 11, the ScreenShot is not working. So, only code listed.
3 Connectiong with the Board with Mobile BLE app
There is not enough time for better Android APP demo, normal BLE App is used . the Mobile connected with edrumer with BLE,
Then the hardware response to the control from mobile.
Once connected, enter into the PDM cycle in responsive to any soud over threadhold to flash the led and send back the signal to mobile. The android APP shall be build to receive the customized BLE characteristic.
4 More to do
This is raw prototype, There shall be more to added in this drumer as one way of communication to same drum player in community. That part of work need backend running server to support such drumer life.