void hd64465_gpio_configure(int portpin, int direction) { unsigned short cr; unsigned int shift = (_PINOF(portpin)<<1); cr = inw(GPIO_CR(_PORTOF(portpin))); cr &= ~(3<<shift); cr |= direction<<shift; outw(cr, GPIO_CR(_PORTOF(portpin))); }
/* * GPIO setup: * Enable the pins driving the RGB LED as outputs. */ static void gpio_setup(void) { /* * Configure GPIOF * This port is used to control the RGB LED */ periph_clock_enable(RCC_GPIOF); const u32 outpins = (LED_R | LED_G | LED_B); GPIO_DIR(RGB_PORT) |= outpins; /* Configure outputs. */ GPIO_DEN(RGB_PORT) |= outpins; /* Enable digital function on outputs. */ /* * Now take care of our buttons */ const u32 btnpins = USR_SW1 | USR_SW2; /* * PF0 is locked by default. We need to unlock the GPIO_CR register, * then enable PF0 commit. After we do this, we can setup PF0. If we * don't do this, any configuration done to PF0 is lost, and we will not * have a PF0 interrupt. */ GPIO_LOCK(GPIOF) = 0x4C4F434B; GPIO_CR(GPIOF) |= USR_SW2; /* Configure pins as inputs. */ GPIO_DIR(GPIOF) &= ~btnpins; /* Enable digital function on the pins. */ GPIO_DEN(GPIOF) |= btnpins; /* Pull-up the pins. We don't have an external pull-up */ GPIO_PUR(GPIOF) |= btnpins; }
/** * \brief Unlock the commit control of a special function pin * * Unlocks the commit control of the given pin or group of pins. If a pin is a * JTAG/SWD or NMI, the pin may then be reconfigured as a GPIO pin. If the pin * is not locked by default, this has no effect. * * @param[in] gpioport GPIO block register address base @ref gpio_reg_base * @param[in] gpios @ref gpio_pin_id. Any combination of pins may be specified * by OR'ing then together. */ void gpio_unlock_commit(uint32_t gpioport, uint8_t gpios) { /* Unlock the GPIO_CR register */ GPIO_LOCK(gpioport) = GPIO_LOCK_UNLOCK_CODE; /* Enable committing changes */ GPIO_CR(gpioport) |= gpios; /* Lock the GPIO_CR register */ GPIO_LOCK(gpioport) = ~GPIO_LOCK_UNLOCK_CODE; }
void setupUSB (void) { #ifdef HAS_MAPLE_HARDWARE /* Setup USB DISC pin as output open drain */ SET_REG(GPIO_CR(USB_DISC_BANK,USB_DISC),(GET_REG(GPIO_CR(USB_DISC_BANK,USB_DISC)) & crMask(USB_DISC)) | CR_OUTPUT_OD << CR_SHITF(LED_PIN)); gpio_write_bit(USB_DISC_BANK,USB_DISC,1); /* turn on the USB clock */ //pRCC->APB1ENR |= RCC_APB1ENR_USB_CLK;// done in setupCLK() gpio_write_bit(USB_DISC_BANK,USB_DISC,0); /* present ourselves to the host */ #else /* Generic boards don't have disconnect hardware, so we drive PA12 which is connected to the usb D+ line*/ #define USB_DISC_BANK GPIOA #define USB_DISC 12 SET_REG(GPIO_CR(USB_DISC_BANK,USB_DISC), (GET_REG(GPIO_CR(USB_DISC_BANK,USB_DISC)) & crMask(USB_DISC)) | CR_OUTPUT_PP << CR_SHITF(USB_DISC)); gpio_write_bit(USB_DISC_BANK,USB_DISC,0); /* present ourselves to the host */ volatile unsigned int delay; for(delay = 0;delay<256;delay++); // volatile unsigned x = 1024; do { ; }while(--x);// wait a moment /* turn on the USB clock */ SET_REG(GPIO_CR(USB_DISC_BANK,USB_DISC), (GET_REG(GPIO_CR(USB_DISC_BANK,USB_DISC)) & crMask(USB_DISC)) | CR_INPUT << CR_SHITF(USB_DISC)); //Sets the PA12 as floating input // pRCC->APB1ENR |= RCC_APB1ENR_USB_CLK; #endif /* initialize the usb application */ wTransferSize=getFlashPageSize(); u8_usbConfigDescriptorDFU[41]=(wTransferSize & 0x00FF); u8_usbConfigDescriptorDFU[42]=(wTransferSize & 0xFF00)>>8; u8_usbFunctionalDescriptor[5]=(wTransferSize & 0x00FF); u8_usbFunctionalDescriptor[6]=(wTransferSize & 0xFF00)>>8; usbAppInit(); }