Пример #1
0
void uart_disable(UART_CLASS port)
{
	if (port < UARTS_COUNT)
	{
		//disable interrupts
		NVIC_DisableIRQ(UART_IRQ_VECTORS[port]);

		//disable core
		USART[port]->CR1 &= ~USART_CR1_UE;
		//power down
		if (port == UART_1 || port == UART_6)
			RCC->APB2ENR &= ~RCC_UART[port];
		else
			RCC->APB1ENR &= ~RCC_UART[port];

		//disable pins
		if ((USART_TX_DISABLE_MASK & (1 << port)) == 0)
			gpio_disable_pin(UART_TX_PINS[port]);
		if ((USART_RX_DISABLE_MASK & (1 << port)) == 0)
			gpio_disable_pin(UART_RX_PINS[port]);

#if (USART_REMAP_MASK)
		if ((1 << port) & USART_REMAP_MASK)
			afio_unmap();
#endif //USART_REMAP_MASK

		sys_free(_uart_handlers[port]);
		_uart_handlers[port] = NULL;
	}
	else
		error_dev(ERROR_DEVICE_INDEX_OUT_OF_RANGE, DEV_UART, port);
}
Пример #2
0
void gpio_disable_mask(unsigned int port, unsigned int mask)
{
    unsigned int bit;
    unsigned int cur = mask;
    while (cur)
    {
        bit = 31 - __builtin_clz(cur);
        cur &= ~(1 << bit);
        gpio_disable_pin(GPIO_MAKE_PIN(port, bit));
    }
}