void RX_PIN_WAKEUP_handler(void *arg) { (void)arg; platform_uart_driver_t* driver = arg; uint32_t uart_number; platform_gpio_enable_clock( driver->peripheral->pin_rx ); uart_number = platform_uart_get_port_number( driver->peripheral->port ); uart_peripheral_clock_functions[ uart_number ]( uart_peripheral_clocks[ uart_number ], ENABLE ); /* Enable DMA peripheral clock */ if ( driver->peripheral->tx_dma_config.controller == DMA1 ) { RCC->AHB1ENR |= RCC_AHB1Periph_DMA1; } else { RCC->AHB1ENR |= RCC_AHB1Periph_DMA2; } platform_gpio_irq_disable( driver->peripheral->pin_rx ); platform_mcu_powersave_disable( ); mico_rtos_set_semaphore( &driver->sem_wakeup ); }
OSStatus platform_adc_init( const platform_adc_t* adc, uint32_t sample_cycle ) { GPIO_InitTypeDef gpio_init_structure; ADC_InitTypeDef adc_init_structure; ADC_CommonInitTypeDef adc_common_init_structure; uint8_t a; OSStatus err = kNoErr; platform_mcu_powersave_disable(); require_action_quiet( adc != NULL, exit, err = kParamErr); /* Enable peripheral clock for this port */ err = platform_gpio_enable_clock( adc->pin ); require_noerr(err, exit); /* Initialize the associated GPIO */ gpio_init_structure.GPIO_Pin = (uint32_t)( 1 << adc->pin->pin_number );; gpio_init_structure.GPIO_Speed = (GPIOSpeed_TypeDef) 0; gpio_init_structure.GPIO_Mode = GPIO_Mode_AN; gpio_init_structure.GPIO_PuPd = GPIO_PuPd_NOPULL; gpio_init_structure.GPIO_OType = GPIO_OType_OD; GPIO_Init( adc->pin->port, &gpio_init_structure ); RCC_APB2PeriphClockCmd( adc->adc_peripheral_clock, ENABLE ); /* Initialize the ADC */ ADC_StructInit( &adc_init_structure ); adc_init_structure.ADC_Resolution = ADC_Resolution_12b; adc_init_structure.ADC_ScanConvMode = DISABLE; adc_init_structure.ADC_ContinuousConvMode = DISABLE; adc_init_structure.ADC_ExternalTrigConv = ADC_ExternalTrigConvEdge_None; adc_init_structure.ADC_DataAlign = ADC_DataAlign_Right; adc_init_structure.ADC_NbrOfConversion = 1; ADC_Init( adc->port, &adc_init_structure ); ADC_CommonStructInit( &adc_common_init_structure ); adc_common_init_structure.ADC_Mode = ADC_Mode_Independent; adc_common_init_structure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; adc_common_init_structure.ADC_Prescaler = ADC_Prescaler_Div2; adc_common_init_structure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles; ADC_CommonInit( &adc_common_init_structure ); ADC_Cmd( adc->port, ENABLE ); /* Find the closest supported sampling time by the MCU */ for ( a = 0; ( a < sizeof( adc_sampling_cycle ) / sizeof(uint16_t) ) && adc_sampling_cycle[a] < sample_cycle; a++ ) { } /* Initialize the ADC channel */ ADC_RegularChannelConfig( adc->port, adc->channel, adc->rank, a ); exit: platform_mcu_powersave_enable(); return err; }