int usb_configure(usb_attr_t * attr) { if (attr == NULL) { return 0; } if (attr->use_present_pin) { if (!IS_GPIO_ALL_PERIPH(attr->present_port->GPIOx) || !IS_GPIO_PIN_SOURCE(attr->present_pin)) { return 0; } gpio_set_mode(attr->present_port, attr->present_pin, GPIO_INPUT_PU); } preempt_prio = attr->preempt_prio; sub_prio = attr->sub_prio; // USB Device Initialize USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb, &USR_cb); usb_ready = 1; return 1; }
void gpio_toggle_bit(gpio_dev* dev, uint8_t pin) { /* Check the parameters */ assert_param(IS_GPIO_ALL_PERIPH(dev->GPIOx)); assert_param(IS_GPIO_PIN_SOURCE(pin)); dev->GPIOx->ODR ^= BIT(pin); }
void afio_exti_select(afio_exti_num exti, afio_exti_port gpio_port) { /* Check the parameters */ assert_param(IS_GPIO_PIN_SOURCE(exti)); assert_param(IS_GPIO_EXTI_PORT_SOURCE(gpio_port)); GPIO_EXTILineConfig(gpio_port, exti); }
void gpio_write_bit(gpio_dev* dev, uint8_t pin, uint8_t val) { /* Check the parameters */ assert_param(IS_GPIO_ALL_PERIPH(dev->GPIOx)); assert_param(IS_GPIO_PIN_SOURCE(pin)); if (val) { dev->GPIOx->BSRR = BIT(pin); } else { dev->GPIOx->BRR = BIT(pin); } }
void gpio_set_mode(gpio_dev* dev, uint8_t pin, gpio_pin_mode mode) { /* Check the parameters */ assert_param(IS_GPIO_ALL_PERIPH(dev->GPIOx)); assert_param(IS_GPIO_PIN_SOURCE(pin)); GPIO_InitTypeDef config; /* Enable the GPIO Clock */ dev->clkcmd(dev->clk, ENABLE); /* Configure the pin */ GPIO_StructInit(&config); config.GPIO_Speed = GPIO_DEFAULT_SPEED; switch(mode) { case GPIO_OUTPUT_PP: config.GPIO_Mode = GPIO_Mode_Out_PP; break; case GPIO_OUTPUT_OD: config.GPIO_Mode = GPIO_Mode_Out_OD; break; case GPIO_INPUT_FLOATING: config.GPIO_Mode = GPIO_Mode_IN_FLOATING; break; case GPIO_INPUT_ANALOG: config.GPIO_Mode = GPIO_Mode_AIN; break; case GPIO_INPUT_PU: config.GPIO_Mode = GPIO_Mode_IPU; break; case GPIO_INPUT_PD: config.GPIO_Mode = GPIO_Mode_IPD; break; case GPIO_AF_OUTPUT_PP: config.GPIO_Mode = GPIO_Mode_AF_PP; break; case GPIO_AF_OUTPUT_OD: config.GPIO_Mode = GPIO_Mode_AF_OD; break; default: errno_r = EINVAL; return; } config.GPIO_Pin = BIT(pin); GPIO_Init(dev->GPIOx, &config); }
uint8_t gpio_read_bit(gpio_dev* dev, uint8_t pin) { uint8_t bitstatus = 0x00; /* Check the parameters */ assert_param(IS_GPIO_ALL_PERIPH(dev->GPIOx)); assert_param(IS_GPIO_PIN_SOURCE(pin)); if ((dev->GPIOx->IDR & BIT(pin)) != (uint32_t)Bit_RESET) { bitstatus = (uint8_t)Bit_SET; } else { bitstatus = (uint8_t)Bit_RESET; } return bitstatus; }
/***************************************************************************** * Function: Init * * Description: *****************************************************************************/ void AlternateFunctionPin::Init(void) { assert_param(IS_GPIO_ALL_PERIPH(this->port)); assert_param(IS_GET_GPIO_PIN(this->pin)); assert_param(IS_GPIO_PIN_SOURCE(this->pin_source)); assert_param(IS_GPIO_AF(this->alternate_function)); assert_param(IS_RCC_AHB1_CLOCK_PERIPH(this->clock)); // Peripheral clock enable. RCC_AHB1PeriphClockCmd(this->clock, ENABLE); // Configure pin in alternate function mode. GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = this->pin; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(this->port, &GPIO_InitStructure); GPIO_PinAFConfig(this->port, this->pin_source, this->alternate_function); } // AlternateFunctionPin::Init()