void tm4c123_button_initialize(void) { ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); /* Enable pin PB3 for GPIOInput with weak pullup */ ROM_GPIOPinTypeGPIOInput(GPIOB_BASE, GPIO_PIN_3); ROM_GPIOPadConfigSet(GPIOB_BASE, GPIO_PIN_3, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); /* Enable IRQs on both edges. */ GPIOB->IS &= ~GPIO_PIN_3; GPIOB->IBE |= GPIO_PIN_3; GPIOB->IM |= GPIO_PIN_3; NVIC_SetPriority(GPIOB_IRQn, 6); NVIC_EnableIRQ(GPIOB_IRQn); #if (KITTY_CONFIG_ALTERNATIVE == 1) (&GPIOF->LOCK)[0] = GPIO_LOCK_KEY; /* GPIOD->LOCK */ (&GPIOF->LOCK)[1] = 0x01; /* GPIOD->CR */ /* Enable pin PF0 for GPIOInput with weak pullup */ ROM_GPIOPinTypeGPIOInput(GPIOF_BASE, GPIO_PIN_0); ROM_GPIOPadConfigSet(GPIOF_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); /* Enable IRQs on both edges. */ GPIOF->IS &= ~GPIO_PIN_0; GPIOF->IBE |= GPIO_PIN_0; GPIOF->IM |= GPIO_PIN_0; #endif /* KITTY_CONFIG_ALTERNATIVE == 1 */ /* Enable pin PF4 for GPIOInput with weak pullup */ ROM_GPIOPinTypeGPIOInput(GPIOF_BASE, GPIO_PIN_4); ROM_GPIOPadConfigSet(GPIOF_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); /* Enable IRQs on both edges. */ GPIOF->IS &= ~GPIO_PIN_4; GPIOF->IBE |= GPIO_PIN_4; GPIOF->IM |= GPIO_PIN_4; NVIC_SetPriority(GPIOF_IRQn, 6); NVIC_EnableIRQ(GPIOF_IRQn); }
void Init_I2C(void) { ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_GPIOPinConfigure(GPIO_PB2_I2C0SCL); ROM_GPIOPinConfigure(GPIO_PB3_I2C0SDA); ROM_GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3); GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2); ROM_GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD); ROM_GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_3, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD); ROM_I2CMasterInitExpClk(I2C0_BASE,ROM_SysCtlClockGet(),true); SysCtlDelay(500000); ROM_I2CMasterEnable(I2C0_BASE); }
// BSP functions ============================================================= void BSP_init(void) { // NOTE: SystemInit() already called from the startup code // but SystemCoreClock needs to be updated // SystemCoreClockUpdate(); // configure the FPU usage by choosing one of the options... // Do NOT to use the automatic FPU state preservation and // do NOT to use the FPU lazy stacking. // // NOTE: // Use the following setting when FPU is used only by active objects // and NOT in any ISR. This setting is very efficient, but if any ISRs // start using the FPU, this can lead to corruption of the FPU registers. // FPU->FPCCR &= ~((1U << FPU_FPCCR_ASPEN_Pos) | (1U << FPU_FPCCR_LSPEN_Pos)); // enable clock for to the peripherals used by this application... SYSCTL->RCGCGPIO |= (1U << 5); // enable Run mode for GPIOF // configure the LEDs and push buttons GPIOF->DIR |= (LED_RED | LED_GREEN | LED_BLUE); // set direction: output GPIOF->DEN |= (LED_RED | LED_GREEN | LED_BLUE); // digital enable GPIOF->DATA_Bits[LED_RED] = 0U; // turn the LED off GPIOF->DATA_Bits[LED_GREEN] = 0U; // turn the LED off GPIOF->DATA_Bits[LED_BLUE] = 0U; // turn the LED off // configure the Buttons GPIOF->DIR &= ~(BTN_SW1 | BTN_SW2); // set direction: input ROM_GPIOPadConfigSet(GPIOF_BASE, (BTN_SW1 | BTN_SW2), GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); }
// Fonction qui initialise le LCD void init_lcd(void) { // Enable ports on board ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); // Configure pins ROM_GPIOPadConfigSet(GPIO_PORTE_BASE, 0xFF, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPD); // Enable data as output ROM_GPIOPinTypeGPIOOutput(GPIO_PORTJ_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, 0xFF); // Toutes les pins // Default values of pins to zero ROM_GPIOPinWrite(GPIO_PORTJ_BASE, LCD_RS | LCD_RW | LCD_E, 0x00); ROM_GPIOPinWrite(GPIO_PORTE_BASE, 0xFF, 0x00); // Set LCD to 2line mode wait(); ROM_GPIOPinWrite(GPIO_PORTJ_BASE, LCD_RS | LCD_RW, LCD_RS_Instruction | LCD_RW_Write); ROM_GPIOPinWrite(GPIO_PORTJ_BASE, LCD_E, LCD_E); ROM_GPIOPinWrite(GPIO_PORTE_BASE, 0xFF, 0x38); ROM_GPIOPinWrite(GPIO_PORTJ_BASE, LCD_E, 0); // Activate cursor blinking wait(); ROM_GPIOPinWrite(GPIO_PORTJ_BASE, LCD_RS | LCD_RW, LCD_RS_Instruction | LCD_RW_Write); ROM_GPIOPinWrite(GPIO_PORTJ_BASE, LCD_E, LCD_E); ROM_GPIOPinWrite(GPIO_PORTE_BASE, 0xFF, 0x0F); ROM_GPIOPinWrite(GPIO_PORTJ_BASE, LCD_E, 0); // Clear LCD clear(); }
//***************************************************************************** // //! Initializes the GPIO pins used by the board pushbuttons. //! //! This function must be called during application initialization to //! configure the GPIO pins to which the pushbuttons are attached. It enables //! the port used by the buttons and configures each button GPIO as an input //! with a weak pull-up. //! //! \return None. // //***************************************************************************** void ButtonsInit(void) { // // Enable the GPIO port to which the pushbuttons are connected. // ROM_SysCtlPeripheralEnable(BUTTONS_GPIO_PERIPH); // // Unlock PF0 so we can change it to a GPIO input // Once we have enabled (unlocked) the commit register then re-lock it // to prevent further changes. PF0 is muxed with NMI thus a special case. // HWREG(BUTTONS_GPIO_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY; HWREG(BUTTONS_GPIO_BASE + GPIO_O_CR) |= 0x01; HWREG(BUTTONS_GPIO_BASE + GPIO_O_LOCK) = 0; // // Set each of the button GPIO pins as an input with a pull-up. // ROM_GPIODirModeSet(BUTTONS_GPIO_BASE, ALL_BUTTONS, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(BUTTONS_GPIO_BASE, ALL_BUTTONS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // // Initialize the debounced button state with the current state read from // the GPIO bank. // g_ui8ButtonStates = ROM_GPIOPinRead(BUTTONS_GPIO_BASE, ALL_BUTTONS); }
/*..........................................................................*/ void BSP_init(void) { /* Enable the floating-point unit */ SCB->CPACR |= (0xFU << 20); /* Enable lazy stacking for interrupt handlers. This allows FPU * instructions to be used within interrupt handlers, but at the * expense of extra stack usage. */ ROM_FPULazyStackingEnable(); /* Set the clocking to run directly from the crystal */ ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); /* enable clock to the peripherals used by the application */ SYSCTL->RCGC2 |= (1U << 5); /* enable clock to GPIOF */ __NOP(); /* wait after enabling clocks */ __NOP(); __NOP(); /* configure the LEDs */ GPIOF->DIR |= (LED_RED | LED_GREEN | LED_BLUE);/* set direction: output */ GPIOF->DEN |= (LED_RED | LED_GREEN | LED_BLUE); /* digital enable */ GPIOF->DATA_Bits[LED_RED] = 0U; /* turn the LED off */ GPIOF->DATA_Bits[LED_GREEN] = 0U; /* turn the LED off */ GPIOF->DATA_Bits[LED_BLUE] = 0U; /* turn the LED off */ /* configure the User Switches */ GPIOF->DIR &= ~(USR_SW1 | USR_SW2); /* set direction: input */ ROM_GPIOPadConfigSet(GPIO_PORTF_BASE, (USR_SW1 | USR_SW2), GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); }
void GPIO_Initial(void) { ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_6); //Laser ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_2|GPIO_PIN_4); //预留、吹风机 ROM_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_0| \ GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3); //振镜Y、X、CLK、SYN ROM_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_0|GPIO_PIN_1|\ GPIO_PIN_2|GPIO_PIN_3 | GPIO_PIN_5); //预留、塔灯红、绿、黄、光闸、抽风机 ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|\ GPIO_PIN_3|GPIO_PIN_4); //板上显示灯:红、蓝、绿;LCD复位 ROM_GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_3, \ GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); //冷水机开关信号 ROM_GPIOPinTypeGPIOInput(GPIO_PORTC_BASE, GPIO_PIN_6); //测速 ROM_GPIOPinTypeGPIOInput(GPIO_PORTD_BASE, GPIO_PIN_6); //手动开关、运行模式 HWREG(GPIO_PORTD_BASE+GPIO_O_LOCK) = GPIO_LOCK_KEY; HWREG(GPIO_PORTD_BASE+GPIO_O_CR) |= 0x80; HWREG(GPIO_PORTD_BASE+GPIO_O_AFSEL) &= ~(0x80); HWREG(GPIO_PORTD_BASE+GPIO_O_DEN) |= 0x80; ROM_GPIOPinTypeGPIOInput(GPIO_PORTC_BASE, GPIO_PIN_7); HWREG(GPIO_PORTD_BASE+GPIO_O_LOCK) = 0; }
//***************************************************************************** // //! Initialize LEDs //! //! \param none //! //! \return none //! //! \brief Initializes LED Ports and Pins // //***************************************************************************** void initLEDs() { // Enable use of PORTF to toggle LED and disable interrupt on this port MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // // Unlock PF0 so we can change it to a GPIO input // Once we have enabled (unlocked) the commit register then re-lock it // to prevent further changes. PF0 is muxed with NMI thus a special case. // HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY_DD; HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01; HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0; MAP_GPIOPinIntDisable(GPIO_PORTF_BASE, 0xFF); // Configure Red LED MAP_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1); MAP_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, PIN_LOW); // Configure Blue LED MAP_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2); MAP_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, PIN_LOW); // Configure Green LED MAP_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3); MAP_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, PIN_LOW); // Button inputs ROM_GPIODirModeSet(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); }
BOOL xMBTCPPortInit(USHORT port) { ROM_SysCtlPeripheralEnable(WIZ610_GPIO_PERIPH); ROM_GPIODirModeSet(WIZ610_GPIO_BASE,WIZ610_GPIO_PIN_CMD_ENABLE ,GPIO_DIR_MODE_OUT); ROM_GPIOPadConfigSet(WIZ610_GPIO_BASE,WIZ610_GPIO_PIN_CMD_ENABLE,GPIO_STRENGTH_8MA,GPIO_PIN_TYPE_STD_WPU); ROM_GPIOPinWrite(WIZ610_GPIO_BASE,WIZ610_GPIO_PIN_CMD_ENABLE,WIZ610_GPIO_PIN_CMD_ENABLE); // uart setup ROM_SysCtlPeripheralEnable(WIZ610_UART_PERIPH); ROM_GPIOPinConfigure(GPIO_PB0_U1RX); ROM_GPIOPinConfigure(GPIO_PB1_U1TX); ROM_GPIOPinTypeUART(WIZ610_GPIO_BASE, WIZ610_GPIO_PIN_RX | WIZ610_GPIO_PIN_TX); ROM_UARTConfigSetExpClk(WIZ610_UART_BASE, ROM_SysCtlClockGet(), 38400, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); ROM_GPIOPinWrite(WIZ610_GPIO_BASE,WIZ610_GPIO_PIN_CMD_ENABLE,WIZ610_GPIO_PIN_CMD_ENABLE); ROM_UARTFIFOLevelSet(WIZ610_UART_BASE, UART_FIFO_TX4_8, UART_FIFO_RX1_8); ROM_IntEnable(INT_UART1); ROM_UARTEnable(WIZ610_UART_BASE); ROM_UARTDMAEnable(WIZ610_UART_BASE, UART_DMA_TX); ROM_UARTIntEnable(WIZ610_UART_BASE, UART_INT_RX); ROM_IntEnable(INT_UDMA); WIZ610Transfer(); cmd_modbus_switch=0; g_ulRxBufACount=0; modbus_tcp_rab=MODBUS_TCP_IDLE; return TRUE; }
int main() { ROM_SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, LED_RED|LED_BLUE|LED_GREEN); HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK)=GPIO_LOCK_KEY; HWREG(GPIO_PORTF_BASE + GPIO_O_CR)|=GPIO_PIN_0; ROM_GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, SW2|SW1); ROM_GPIOPadConfigSet(GPIO_PORTF_BASE,SW2|SW1,GPIO_STRENGTH_4MA,GPIO_PIN_TYPE_STD_WPU); Out=0x02; while (1) { // set the red LED pin high, others low In1 = ROM_GPIOPinRead(GPIO_PORTF_BASE,SW1|SW2); In2 = (In1 & 0x10) >>4; In1 = In1 & 0x01; if(In1 == 0 && In2 == 1 && flag == 0) { flag =1; Out = Out << 1; if (Out > 0x08) Out = 0x02; } else if (In1 == 1 && In2 == 0 && flag == 0) { flag =1; Out = Out >> 1; if (Out<0x02) Out=0x08; } else if (In1 ==1 && In2==1 && flag ==1)
void Interrupt_PB3Init(void) { GPIOIntRegister(GPIO_PORTB_BASE,Interrupt_PB3Handler); ROM_GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_3); ROM_GPIOPadConfigSet(GPIO_PORTB_BASE,GPIO_PIN_3,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU); GPIOIntDisable(GPIO_PORTB_BASE,GPIO_INT_PIN_3); GPIOIntClear(GPIO_PORTB_BASE,GPIO_INT_PIN_3); GPIOIntTypeSet(GPIO_PORTB_BASE,GPIO_INT_PIN_3,GPIO_LOW_LEVEL); }
//***************************************************************************** // // This function initializes the state of the button handler and prepares it // to debounce the state of the button. If the button is initially pressed, // the state of the motor controller is reverted to the factory settings. // //***************************************************************************** void ButtonInit(void) { // // Set the GPIO as an input and enable the weak pull up. When pressed, the // button is read as 0. // ROM_GPIODirModeSet(BUTTON_PORT, BUTTON_PIN, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(BUTTON_PORT, BUTTON_PIN, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // // Delay for a bit before sampling the reset state of the button. // SysCtlDelay(1000); // // Read the current state of the button and consider it to be the debounced // state. // g_ulDebouncedState = ROM_GPIOPinRead(BUTTON_PORT, BUTTON_PIN); // // Reset the debounce and hold counters. // g_ulDebounceCount = BUTTON_DEBOUNCE_COUNT; g_ulHoldCount = 0; // // See if the button was initially pressed. // if(g_ulDebouncedState == BUTTON_DOWN) { // // Reset the parameters to the default values. // ParamLoadDefault(); // // Save the default parameters. // ParamSave(); // // Indicate that the configuration was just reset to the default // settings. // LEDParameterReset(); // // Set the hold count such that the power-on hold of the push button // will not cause the servo calibration process to start. // g_ulHoldCount = BUTTON_HOLD_COUNT; } }
void gpio_init() { ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3); ROM_GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, KEY_1|KEY_2); ROM_GPIOPadConfigSet(GPIO_PORTF_BASE, KEY_1, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); ROM_GPIOPadConfigSet(GPIO_PORTF_BASE, KEY_2, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); led_off(LED_1); led_off(LED_2); led_off(LED_3); }
void cfg_GPIO() { ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //Enable clock for GPIOF /* Unlock pull ups to buttons on board */ HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY; HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01; HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0; /* Unlock pull ups to buttons on board */ ROM_GPIODirModeSet(GPIO_PORTF_BASE, GPIO_PIN_4|GPIO_PIN_0, GPIO_DIR_MODE_IN); //Configure as input the PORTF_0 and PORTF_4 ROM_GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4|GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); //Configure as input with fan in of 2mA, weak pull-up }
int main() { uint8_t ui8Buttons; uint8_t ui8ButtonsChanged; ROM_SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,LED_RED | LED_BLUE | LED_GREEN); ROM_SysCtlPeripheralEnable(BUTTONS_GPIO_PERIPH); HWREG(BUTTONS_GPIO_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY; HWREG(BUTTONS_GPIO_BASE + GPIO_O_CR) |= 0x01; HWREG(BUTTONS_GPIO_BASE + GPIO_O_LOCK) = 0; ROM_GPIODirModeSet(BUTTONS_GPIO_BASE, ALL_BUTTONS, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(BUTTONS_GPIO_BASE,ALL_BUTTONS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); g_ui8ButtonStates = ROM_GPIOPinRead(BUTTONS_GPIO_BASE, ALL_BUTTONS); for(;;) { /* ui8Buttons = ButtonsPoll(&ui8ButtonsChanged, 0); if(BUTTON_PRESSED(LEFT_BUTTON, ui8Buttons, ui8ButtonsChanged)) { ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE, LED_RED); }//Button leftside, if button leftside is pressed the LED will be flash red else if(BUTTON_PRESSED(RIGHT_BUTTON, ui8Buttons, ui8ButtonsChanged)) { ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE, LED_GREEN); }//Button rightside, if button leftside is pressed the LED will be flash green else if(BUTTON_RELEASED(LEFT_BUTTON|RIGHT_BUTTON, ui8Buttons, ui8ButtonsChanged)) { ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE, 0); }//If the buttons will be release the LED turn off. */ //----Wenn beide Buttons gedrueckt werden leuchten auch --- ui8Buttons = (uint8_t)~ROM_GPIOPinRead(BUTTONS_GPIO_BASE, ALL_BUTTONS); led_switch = 0; if(LEFT_BUTTON & ui8Buttons) led_switch |= LED_RED; if(RIGHT_BUTTON & ui8Buttons) led_switch |= LED_GREEN; ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE, led_switch); } return 0; }
//***************************************************************************** // // Main entry point for the USB stick update example. // // This function will check to see if a flash update should be performed from // the USB memory stick, or if the user application should just be run without // any update. // // The following checks are made, any of which mean that an update should be // performed: // - the PC and SP for the user app do not appear to be valid // - a memory location contains a certain value, meaning the user app wants // to force an update // - the user button on the eval board is being pressed, meaning the user wants // to force an update even if there is a valid user app in memory // // If any of the above checks are true, then that means that an update should // be attempted. The USB stick updater will then wait for a USB stick to be // plugged in, and once it is look for a firmware update file. // // If none of the above checks are true, then the user application that is // already in flash is run and no update is performed. // // \return None. // //***************************************************************************** int main(void) { uint32_t *pui32App; // // See if the first location is 0xfffffffff or something that does not // look like a stack pointer, or if the second location is 0xffffffff or // something that does not look like a reset vector. // pui32App = (uint32_t *)APP_START_ADDRESS; if((pui32App[0] == 0xffffffff) || ((pui32App[0] & 0xfff00000) != 0x20000000) || (pui32App[1] == 0xffffffff) || ((pui32App[1] & 0xfff00001) != 0x00000001)) { // // App starting stack pointer or PC is not valid, so force an update. // UpdaterMain(); } // // Check to see if the application has requested an update // if(HWREG(FORCE_UPDATE_ADDR) == FORCE_UPDATE_VALUE) { HWREG(FORCE_UPDATE_ADDR) = 0; UpdaterMain(); } // // Enable the GPIO input for the user button. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM); ROM_GPIODirModeSet(GPIO_PORTM_BASE, GPIO_PIN_4, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(GPIO_PORTM_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // // Check if the button is pressed, if so then force an update. // if(ROM_GPIOPinRead(GPIO_PORTM_BASE, GPIO_PIN_4) == 0) { UpdaterMain(); } // // If we get to here that means that none of the conditions that should // cause an update are true. Therefore, call the application. // CallApplication(APP_START_ADDRESS); }
void Config_System(void) { ROM_FPUEnable(); ROM_FPULazyStackingEnable(); // Config clock ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); system_SystickConfig(1); // ROM_SysCtlPeripheralEnable(BOOST_ENABLE_PREIPHERAL); ROM_GPIOPinTypeGPIOOutput(BOOST_ENABLE_PORT, BOOST_ENABLE_PIN); ROM_GPIOPadConfigSet(BOOST_ENABLE_PORT, BOOST_ENABLE_PIN, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD_WPU); ROM_GPIOPinWrite(BOOST_ENABLE_PORT, BOOST_ENABLE_PIN, 0xff); }
//***************************************************************************** // //! Initializes the EVALBOT's push buttons. //! //! This function must be called prior to PushButtonGetStatus() to configure //! the GPIOs used to support the user switches on EVALBOT. //! //! \return None. // //***************************************************************************** void PushButtonsInit (void) { // // Enable the GPIO port used by the pushbuttons. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); // // Set the button GPIOs as inputs. // ROM_GPIOPinTypeGPIOInput(GPIO_PORTD_BASE, GPIO_PIN_6 | GPIO_PIN_7); ROM_GPIOPadConfigSet(GPIO_PORTD_BASE, GPIO_PIN_6 | GPIO_PIN_7, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); }
void Button_init(void) { ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY; HWREG(GPIO_PORTF_BASE + GPIO_O_CR) = 0x01; HWREG(GPIO_PORTF_BASE + GPIO_O_AFSEL) &= ~0x01; ROM_GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4); ROM_GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4, GPIO_STRENGTH_8MA_SC, GPIO_PIN_TYPE_STD_WPU); ROM_GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4, GPIO_FALLING_EDGE); GPIOIntRegister(GPIO_PORTF_BASE, &ButtonsISR); ROM_IntEnable(INT_GPIOF); GPIOIntEnable(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4); GPIOIntClear(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4); }
int main() { uint8_t ui8Buttons; uint8_t led_switch; /* uint8_t ui8ButtonsChanged; */ ROM_SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, LED_RED|LED_BLUE|LED_GREEN); ROM_SysCtlPeripheralEnable(BUTTONS_GPIO_PERIPH); HWREG(BUTTONS_GPIO_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY; HWREG(BUTTONS_GPIO_BASE + GPIO_O_CR) |= 0x01; HWREG(BUTTONS_GPIO_BASE + GPIO_O_LOCK) = 0; ROM_GPIODirModeSet(BUTTONS_GPIO_BASE, ALL_BUTTONS, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(BUTTONS_GPIO_BASE, ALL_BUTTONS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); /* ButtonsInit(); */ for (;;) { /* ui8Buttons = ButtonsPoll(&ui8ButtonsChanged, 0); if(BUTTON_PRESSED(LEFT_BUTTON, ui8Buttons, ui8ButtonsChanged)) ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE, LED_RED); else if(BUTTON_PRESSED(RIGHT_BUTTON, ui8Buttons, ui8ButtonsChanged)) ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE, LED_GREEN); else if(BUTTON_RELEASED(LEFT_BUTTON|RIGHT_BUTTON, ui8Buttons, ui8ButtonsChanged)) ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE, 0); */ ui8Buttons = (uint8_t)~ROM_GPIOPinRead(BUTTONS_GPIO_BASE, ALL_BUTTONS); led_switch = 0; if(LEFT_BUTTON & ui8Buttons) led_switch |= LED_RED; if(RIGHT_BUTTON & ui8Buttons) led_switch |= LED_GREEN; ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE, led_switch); } return 0; }
//***************************************************************************** // // This function initializes the fan interface, preparing it to manage the // operation of the fan. // //***************************************************************************** void FanInit(void) { // // Configure the GPIO as an output and enable the 8 mA drive. // ROM_GPIODirModeSet(FAN_PORT, FAN_PIN, GPIO_DIR_MODE_OUT); ROM_GPIOPadConfigSet(FAN_PORT, FAN_PIN, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD); // // Turn on the fan to test it. // g_ulFanState = 1; ROM_GPIOPinWrite(FAN_PORT, FAN_PIN, FAN_ON); // // Set the fan time to FAN_TEST_TIME. // g_ulFanTime = FAN_TEST_TIME; }
//***************************************************************************** // //! Initializes the GPIO pins used by the board pushbuttons. //! //! This function must be called during application initialization to //! configure the GPIO pins to which the pushbuttons are attached. It enables //! the port used by the buttons and configures each button GPIO as an input //! with a weak pull-up. //! //! \return None. // //***************************************************************************** void ButtonsInit(void) { // // Enable the GPIO port to which the pushbuttons are connected. // ROM_SysCtlPeripheralEnable(BUTTONS_GPIO_PERIPH); // // Set each of the button GPIO pins as an input with a pull-up. // ROM_GPIODirModeSet(BUTTONS_GPIO_BASE, ALL_BUTTONS, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(BUTTONS_GPIO_BASE, ALL_BUTTONS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // // Initialize the debounced button state with the current state read from // the GPIO bank. // g_ucButtonStates = ROM_GPIOPinRead(BUTTONS_GPIO_BASE, ALL_BUTTONS); }
void init_am27c_ports(void) { unsigned char i; for(i = 0; i < NELEMS(PERIPH); i++) ROM_SysCtlPeripheralEnable(PERIPH[i]); for(i = 0; i < NELEMS(A_PORTS); i++) ROM_GPIOPinTypeGPIOOutput(A_PORTS[i], A_PINS[i]); HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY_DD; HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01; HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0; for(i = 0; i < NELEMS(DQ_PORTS); i++) { ROM_GPIOPinTypeGPIOInput(DQ_PORTS[i], DQ_PINS[i]); ROM_GPIOPadConfigSet(DQ_PORTS[i], DQ_PINS[i], GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); } for(i = 0; i < NELEMS(CTL_PORTS); i++) ROM_GPIOPinTypeGPIOOutput(CTL_PORTS[i], CTL_PINS[i]); }
//............................................................................ void BSP_init(void) { // Enable the floating-point unit SCB->CPACR |= (0xFU << 20); // Enable lazy stacking for interrupt handlers. This allows FPU // instructions to be used within interrupt handlers, but at the // expense of extra stack and CPU usage. // FPU->FPCCR |= (1U << FPU_FPCCR_ASPEN_Pos) | (1U << FPU_FPCCR_LSPEN_Pos); // Set the clocking to run directly from the crystal ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // enable clock to the peripherals used by the application SYSCTL->RCGC2 |= (1U << 5); // enable clock to GPIOF __NOP(); // wait after enabling clocks __NOP(); __NOP(); // configure the LEDs and push buttons GPIOF->DIR |= (LED_RED | LED_GREEN | LED_BLUE); // set direction: output GPIOF->DEN |= (LED_RED | LED_GREEN | LED_BLUE); // digital enable GPIOF->DATA_Bits[LED_RED] = 0; // turn the LED off GPIOF->DATA_Bits[LED_GREEN] = 0; // turn the LED off GPIOF->DATA_Bits[LED_BLUE] = 0; // turn the LED off // configure the User Switches GPIOF->DIR &= ~(USR_SW1 | USR_SW2); // set direction: input ROM_GPIOPadConfigSet(GPIO_PORTF_BASE, (USR_SW1 | USR_SW2), GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); BSP_randomSeed(1234U); Q_ALLEGE(QS_INIT(static_cast<void *>(0))); QS_RESET(); QS_OBJ_DICTIONARY(&l_SysTick_Handler); QS_OBJ_DICTIONARY(&l_GPIOPortA_IRQHandler); QS_USR_DICTIONARY(PHILO_STAT); }
int gpio_init_int(gpio_t pin, gpio_mode_t mode, gpio_flank_t flank, gpio_cb_t cb, void *arg) { const uint8_t port_num = _port_num(pin); const uint32_t port_addr = _port_base[port_num]; const uint32_t icr_reg_addr = port_addr + GPIO_ICR_R_OFF; const uint8_t pin_num = _pin_num(pin); const uint8_t pin_bit = 1<<pin_num; const unsigned int int_num = _int_assign[port_num]; const uint32_t sysctl_port_base = _sysctl_port_base[port_num]; ROM_SysCtlPeripheralEnable(sysctl_port_base); gpio_config[port_num][pin_num].cb = cb; gpio_config[port_num][pin_num].arg = arg; DEBUG("init int pin:%d, int num %d, port addr %" PRIx32 "\n", pin_num, int_num, port_addr); ROM_GPIODirModeSet(port_addr, 1<<pin_num, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(port_addr, 1<<pin_num, GPIO_STRENGTH_2MA, TYPE(mode)); ROM_IntMasterDisable(); HWREG(icr_reg_addr) = pin_bit; ROM_GPIOIntTypeSet(port_addr, pin_bit, flank); HWREG(port_addr+GPIO_LOCK_R_OFF) = GPIO_LOCK_KEY; HWREG(port_addr+GPIO_CR_R_OFF) |= pin_bit; HWREG(port_addr+GPIO_DEN_R_OFF) |= pin_bit; HWREG(port_addr+GPIO_LOCK_R_OFF) = 0; gpio_irq_enable(pin); ROM_IntEnable(int_num); ROM_IntMasterEnable(); return 0; }
/*..........................................................................*/ void BSP_init(void) { /* Enable the floating-point unit */ SCB->CPACR |= (0xFU << 20); /* Enable lazy stacking for interrupt handlers. This allows FPU * instructions to be used within interrupt handlers, but at the * expense of extra stack and CPU usage. */ FPU->FPCCR |= (1U << FPU_FPCCR_ASPEN_Pos) | (1U << FPU_FPCCR_LSPEN_Pos); /* Set the clocking to run directly from the crystal */ ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); /* enable clock to the peripherals used by the application */ SYSCTL->RCGC2 |= (1U << 5); /* enable clock to GPIOF */ __NOP(); /* wait after enabling clocks */ __NOP(); __NOP(); /* configure the LEDs and push buttons */ GPIOF->DIR |= (LED_RED | LED_GREEN | LED_BLUE);/* set direction: output */ GPIOF->DEN |= (LED_RED | LED_GREEN | LED_BLUE); /* digital enable */ GPIOF->DATA_Bits[LED_RED] = 0; /* turn the LED off */ GPIOF->DATA_Bits[LED_GREEN] = 0; /* turn the LED off */ GPIOF->DATA_Bits[LED_BLUE] = 0; /* turn the LED off */ /* configure the User Switches */ GPIOF->DIR &= ~(USR_SW1 | USR_SW2); /* set direction: input */ ROM_GPIOPadConfigSet(GPIO_PORTF_BASE, (USR_SW1 | USR_SW2), GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); BSP_randomSeed(1234U); if (QS_INIT((void *)0) == 0) { /* initialize the QS software tracing */ Q_ERROR(); } QS_OBJ_DICTIONARY(&l_SysTick_Handler); QS_OBJ_DICTIONARY(&l_GPIOPortA_IRQHandler); }
//-------------------------- IR pint init ---------------------------------- void ir_pin_init(void) { ROM_GPIOPinTypeGPIOInput(IR_PORT, IR_PIN); ROM_GPIOPadConfigSet( IR_PORT, IR_PIN, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD_WPU); // // Register the port-level interrupt handler. This handler is the // first level interrupt handler for all the pin interrupts. // GPIOIntRegister(IR_PORT, PortEIntHandler); // PORT E // // Make pin rising edge triggered interrupt. // ROM_GPIOIntTypeSet(IR_PORT, IR_PIN, GPIO_FALLING_EDGE); // GPIO_HIGH_LEVEL GPIO_RISING_EDGE GPIO_FALLING_EDGE GPIOIntClear(IR_PORT, IR_PIN); // // Enable the pin interrupts. // GPIOIntEnable(IR_PORT, IR_PIN); }
void wiz610_init(void) { ROM_SysCtlPeripheralEnable(WIZ610_GPIO_PERIPH); ROM_GPIODirModeSet(WIZ610_GPIO_BASE,WIZ610_GPIO_PIN_CMD_ENABLE ,GPIO_DIR_MODE_OUT); ROM_GPIOPadConfigSet(WIZ610_GPIO_BASE,WIZ610_GPIO_PIN_CMD_ENABLE,GPIO_STRENGTH_8MA,GPIO_PIN_TYPE_STD_WPU); ROM_GPIOPinWrite(WIZ610_GPIO_BASE,WIZ610_GPIO_PIN_CMD_ENABLE,WIZ610_GPIO_PIN_CMD_ENABLE); // uart setup ROM_SysCtlPeripheralEnable(WIZ610_UART_PERIPH); ROM_GPIOPinConfigure(GPIO_PB0_U1RX); ROM_GPIOPinConfigure(GPIO_PB1_U1TX); ROM_GPIOPinTypeUART(WIZ610_GPIO_BASE, WIZ610_GPIO_PIN_RX | WIZ610_GPIO_PIN_TX); ROM_UARTConfigSetExpClk(WIZ610_UART_BASE, ROM_SysCtlClockGet(), 38400, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); ROM_GPIOPinWrite(WIZ610_GPIO_BASE,WIZ610_GPIO_PIN_CMD_ENABLE,0); ROM_UARTFIFOLevelSet(WIZ610_UART_BASE, UART_FIFO_TX4_8, UART_FIFO_RX1_8); ROM_IntEnable(INT_UART1); ROM_UARTEnable(WIZ610_UART_BASE); ROM_UARTDMAEnable(WIZ610_UART_BASE, UART_DMA_TX); ROM_UARTIntEnable(WIZ610_UART_BASE, UART_INT_RX); ROM_IntEnable(INT_UDMA); cmd_modbus_switch=1; }
/* BSP functions ===========================================================*/ void BSP_init(void) { /* NOTE: SystemInit() has been already called from the startup code * but SystemCoreClock needs to be updated */ SystemCoreClockUpdate(); /* enable clock to the peripherals used by the application */ SYSCTL->RCGC2 |= (1U << 5); /* enable clock to GPIOF */ __NOP(); /* wait after enabling clocks */ __NOP(); __NOP(); /* configure the LEDs and push buttons */ GPIOF->DIR |= (LED_RED | LED_GREEN | LED_BLUE); /* set as output */ GPIOF->DEN |= (LED_RED | LED_GREEN | LED_BLUE);/* digital enable */ GPIOF->DATA_Bits[LED_RED] = 0U; /* turn the LED off */ GPIOF->DATA_Bits[LED_GREEN] = 0U; /* turn the LED off */ GPIOF->DATA_Bits[LED_BLUE] = 0U; /* turn the LED off */ /* configure the User Switches */ GPIOF->DIR &= ~(BTN_SW1 | BTN_SW2); /* set direction: input */ ROM_GPIOPadConfigSet(GPIOF_BASE, (BTN_SW1 | BTN_SW2), GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); }
int gpio_init(gpio_t pin, gpio_mode_t mode) { const uint8_t port_num = _port_num(pin); const uint32_t port_addr = _port_base[port_num]; const uint8_t pin_num = _pin_num(pin); const uint32_t sysctl_port_base = _sysctl_port_base[port_num]; const unsigned long pin_bit = 1ul << pin_num; DEBUG("Init GPIO: port %c, %d\n", 'A' + port_num, pin_num); DEBUG("Sysctl %" PRIx32 "\n", sysctl_port_base); ROM_SysCtlPeripheralEnable(sysctl_port_base); HWREG(port_addr+GPIO_LOCK_R_OFF) = GPIO_LOCK_KEY; HWREG(port_addr+GPIO_CR_R_OFF) |= pin_bit; HWREG(port_addr+GPIO_DEN_R_OFF) |= pin_bit; HWREG(port_addr+GPIO_LOCK_R_OFF) = 0; ROM_GPIOPadConfigSet(port_addr, pin_bit, GPIO_STRENGTH_2MA, TYPE(mode)); ROM_GPIODirModeSet(port_addr, pin_bit, MODE(mode)); return 0; }