예제 #1
0
파일: spi.c 프로젝트: imfgz/fgz_quadcopter
void spi_gpio_init(uint8_t int_flag)
{
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

        //F0-----MISO    -----  INPUT
        ROM_GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0);

        //F1,F2,F3:MOSI,CLK,CSN  -----  OUTPUT
        ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);

        //CE-----PA6                 -----  OUTPUT
        ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_6);

        //IRQ-----PA7    -----  INPUT
        ROM_GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_7);

        if(int_flag == 1) //开引脚外部中断
        {
                GPIOIntTypeSet(GPIO_PORTA_BASE,GPIO_PIN_7,GPIO_FALLING_EDGE);
                GPIOIntEnable(GPIO_PORTA_BASE,GPIO_INT_PIN_7); //打开PA7外部中断进行数据读取
                GPIOIntRegister(GPIO_PORTA_BASE, PA7_int_hander);//指定外部中断处理函数
        }
        else
        {
                GPIOIntDisable(GPIO_PORTA_BASE,GPIO_INT_PIN_7);
        }
}
예제 #2
0
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;
}
예제 #3
0
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);
}
예제 #4
0
void pinMode(uint8_t pin, uint8_t mode)
{
    uint8_t bit = digitalPinToBitMask(pin);
    uint8_t port = digitalPinToPort(pin);
    uint32_t portBase = (uint32_t) portBASERegister(port);
    volatile uint32_t *lock = portLOCKRegister(port);
    volatile uint32_t *cr = portCRRegister(port);
    
    if (port == NOT_A_PORT) return;
    
    if (mode == INPUT) {
        ROM_GPIOPinTypeGPIOInput(portBase, bit);
    } else if (mode == INPUT_PULLUP) {
        *lock = GPIO_LOCK_KEY_DD;
        *cr |= bit;
        *lock = 0;
        ROM_GPIODirModeSet(portBase, bit, GPIO_DIR_MODE_IN);
        GPIOPadConfigSet(portBase, bit,
                     GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
        *cr &= ~bit;
    } else if (mode == INPUT_PULLDOWN) {
        *lock = GPIO_LOCK_KEY_DD;
        *cr |= bit;
        *lock = 0;
        ROM_GPIODirModeSet(portBase, bit, GPIO_DIR_MODE_IN);
        GPIOPadConfigSet(portBase, bit,
                     GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPD);
        *cr &= ~bit;
    } else {//mode == OUTPUT
        ROM_GPIOPinTypeGPIOOutput(portBase, bit);
    }

}
예제 #5
0
파일: main.c 프로젝트: jlugao/Project1-GPIO
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)
예제 #6
0
파일: rgb.c 프로젝트: AlexGeControl/tiva-c
//*****************************************************************************
//
//! Disable the RGB LED by configuring the GPIO's as inputs.
//!
//! This function or RGBEnable should be called during application
//! initialization to configure the GPIO pins to which the LEDs are attached.
//! This function disables the timers and configures the GPIO pins as inputs
//! for minimum current draw.
//!
//! \return None.
//
//*****************************************************************************
void
RGBDisable(void)
{
    //
    // Configure the GPIO pads as general purpose inputs.
    //
    ROM_GPIOPinTypeGPIOInput(RED_GPIO_BASE, RED_GPIO_PIN);
    ROM_GPIOPinTypeGPIOInput(GREEN_GPIO_BASE, GREEN_GPIO_PIN);
    ROM_GPIOPinTypeGPIOInput(BLUE_GPIO_BASE, BLUE_GPIO_PIN);

    //
    // Stop the timer counting.
    //
    ROM_TimerDisable(RED_TIMER_BASE, TIMER_BOTH);
    ROM_TimerDisable(GREEN_TIMER_BASE, TIMER_BOTH);
    ROM_TimerDisable(BLUE_TIMER_BASE, TIMER_BOTH);
}
예제 #7
0
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);
}
예제 #8
0
파일: lcd.c 프로젝트: francisvalois/design3
// Fonction qui gère le temps de traitement du LCD
void wait(void) {
	// Change pin type
	ROM_GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, 0xFF); // Toutes les pins
	//Read busy flag until it's 0
	volatile unsigned long busyflag;
	do {
		ROM_GPIOPinWrite(GPIO_PORTJ_BASE, LCD_RS | LCD_RW, LCD_RS_Instruction | LCD_RW_Read);
		ROM_GPIOPinWrite(GPIO_PORTJ_BASE, LCD_E, LCD_E);
		busyflag = ROM_GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_7);
		ROM_GPIOPinWrite(GPIO_PORTJ_BASE, LCD_E, 0);
	} while(busyflag == 128);
	// Restore pin type
	ROM_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, 0xFF); // Toutes les pins
}
예제 #9
0
//*****************************************************************************
//
//! 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);
}
예제 #10
0
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);
}
예제 #11
0
파일: gpio.c 프로젝트: michalnand/suzuha_os
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);
}
예제 #12
0
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]);
}
예제 #13
0
//-------------------------- 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);

}
예제 #14
0
파일: lcd.c 프로젝트: francisvalois/design3
void afficher_speed(volatile unsigned long secondes) {
	// Lecture de l'adresse actuelle du curseur
	wait();
	unsigned char adresse_curseur;
	// Change pin type
	ROM_GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, 0xFF); // Toutes les pins
	// Read adress
	ROM_GPIOPinWrite(GPIO_PORTJ_BASE, LCD_RS | LCD_RW, LCD_RS_Instruction | LCD_RW_Read);
	ROM_GPIOPinWrite(GPIO_PORTJ_BASE, LCD_E, LCD_E);
	adresse_curseur = ROM_GPIOPinRead(GPIO_PORTE_BASE, 0x7F); // 7 pins d'adresse
	ROM_GPIOPinWrite(GPIO_PORTJ_BASE, LCD_E, 0);
	// Restore pin type
	ROM_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, 0xFF); // Toutes les pins
	
	// Changement de l'adresse du curseur pour aller a la ligne du haut
	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, 0x80 | 0xC0);
	ROM_GPIOPinWrite(GPIO_PORTJ_BASE, LCD_E, 0);
	
	// Ecriture du temps
	write_char('0' + (secondes/10000)%10);
	write_char('0' + (secondes/1000)%10);
	write_char('0' + (secondes/100)%10);
	write_char('0' + (secondes/10)%10);
	write_char('0' + (secondes/1)%10);
	
	// Ecriture de l'adresse du curseur pour retourner a la ligne du bas
	// Set DDRAM address to second line
	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, 0x80 | adresse_curseur);
	ROM_GPIOPinWrite(GPIO_PORTJ_BASE, LCD_E, 0);
}
예제 #15
0
//*****************************************************************************
//
// Main application entry point.
//
//*****************************************************************************
int
main(void)
{
    int_fast32_t i32IPart[16], i32FPart[16];
    uint_fast32_t ui32Idx, ui32CompDCMStarted;
    float pfData[16];
    float *pfAccel, *pfGyro, *pfMag, *pfEulers, *pfQuaternion;

    //
    // Initialize convenience pointers that clean up and clarify the code
    // meaning. We want all the data in a single contiguous array so that
    // we can make our pretty printing easier later.
    //
    pfAccel = pfData;
    pfGyro = pfData + 3;
    pfMag = pfData + 6;
    pfEulers = pfData + 9;
    pfQuaternion = pfData + 12;

    //
    // Setup the system clock to run at 40 Mhz from PLL with crystal reference
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
                       SYSCTL_OSC_MAIN);

    //
    // Enable port B used for motion interrupt.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

    //
    // Initialize the UART.
    //
    ConfigureUART();

    //
    // Print the welcome message to the terminal.
    //
    UARTprintf("\033[2JMPU9150 Raw Example\n");

    //
    // Set the color to a purple approximation.
    //
    g_pui32Colors[RED] = 0x8000;
    g_pui32Colors[BLUE] = 0x8000;
    g_pui32Colors[GREEN] = 0x0000;

    //
    // Initialize RGB driver.
    //
    RGBInit(0);
    RGBColorSet(g_pui32Colors);
    RGBIntensitySet(0.5f);
    RGBEnable();

    //
    // The I2C3 peripheral must be enabled before use.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

    //
    // Configure the pin muxing for I2C3 functions on port D0 and D1.
    //
    ROM_GPIOPinConfigure(GPIO_PD0_I2C3SCL);
    ROM_GPIOPinConfigure(GPIO_PD1_I2C3SDA);

    //
    // Select the I2C function for these pins.  This function will also
    // configure the GPIO pins pins for I2C operation, setting them to
    // open-drain operation with weak pull-ups.  Consult the data sheet
    // to see which functions are allocated per pin.
    //
    GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0);
    ROM_GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1);

    //
    // Configure and Enable the GPIO interrupt. Used for INT signal from the
    // MPU9150
    //
    ROM_GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_2);
    GPIOIntEnable(GPIO_PORTB_BASE, GPIO_PIN_2);
    ROM_GPIOIntTypeSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_FALLING_EDGE);
    ROM_IntEnable(INT_GPIOB);

    //
    // Keep only some parts of the systems running while in sleep mode.
    // GPIOB is for the MPU9150 interrupt pin.
    // UART0 is the virtual serial port
    // TIMER0, TIMER1 and WTIMER5 are used by the RGB driver
    // I2C3 is the I2C interface to the ISL29023
    //
    ROM_SysCtlPeripheralClockGating(true);
    ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOB);
    ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART0);
    ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER0);
    ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER1);
    ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_I2C3);
    ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_WTIMER5);

    //
    // Enable interrupts to the processor.
    //
    ROM_IntMasterEnable();

    //
    // Initialize I2C3 peripheral.
    //
    I2CMInit(&g_sI2CInst, I2C3_BASE, INT_I2C3, 0xff, 0xff,
             ROM_SysCtlClockGet());

    //
    // Initialize the MPU9150 Driver.
    //
    MPU9150Init(&g_sMPU9150Inst, &g_sI2CInst, MPU9150_I2C_ADDRESS,
                MPU9150AppCallback, &g_sMPU9150Inst);

    //
    // Wait for transaction to complete
    //
    MPU9150AppI2CWait(__FILE__, __LINE__);

    //
    // Write application specifice sensor configuration such as filter settings
    // and sensor range settings.
    //
    g_sMPU9150Inst.pui8Data[0] = MPU9150_CONFIG_DLPF_CFG_94_98;
    g_sMPU9150Inst.pui8Data[1] = MPU9150_GYRO_CONFIG_FS_SEL_250;
    g_sMPU9150Inst.pui8Data[2] = (MPU9150_ACCEL_CONFIG_ACCEL_HPF_5HZ |
                                  MPU9150_ACCEL_CONFIG_AFS_SEL_2G);
    MPU9150Write(&g_sMPU9150Inst, MPU9150_O_CONFIG, g_sMPU9150Inst.pui8Data, 3,
                 MPU9150AppCallback, &g_sMPU9150Inst);

    //
    // Wait for transaction to complete
    //
    MPU9150AppI2CWait(__FILE__, __LINE__);

    //
    // Configure the data ready interrupt pin output of the MPU9150.
    //
    g_sMPU9150Inst.pui8Data[0] = MPU9150_INT_PIN_CFG_INT_LEVEL |
                                    MPU9150_INT_PIN_CFG_INT_RD_CLEAR |
                                    MPU9150_INT_PIN_CFG_LATCH_INT_EN;
    g_sMPU9150Inst.pui8Data[1] = MPU9150_INT_ENABLE_DATA_RDY_EN;
    MPU9150Write(&g_sMPU9150Inst, MPU9150_O_INT_PIN_CFG,
                 g_sMPU9150Inst.pui8Data, 2, MPU9150AppCallback,
                 &g_sMPU9150Inst);

    //
    // Wait for transaction to complete
    //
    MPU9150AppI2CWait(__FILE__, __LINE__);

    //
    // Initialize the DCM system. 50 hz sample rate.
    // accel weight = .2, gyro weight = .8, mag weight = .2
    //
    CompDCMInit(&g_sCompDCMInst, 1.0f / 50.0f, 0.2f, 0.6f, 0.2f);

    UARTprintf("\033[2J\033[H");
    UARTprintf("MPU9150 9-Axis Simple Data Application Example\n\n");
    UARTprintf("\033[20GX\033[31G|\033[43GY\033[54G|\033[66GZ\n\n");
    UARTprintf("Accel\033[8G|\033[31G|\033[54G|\n\n");
    UARTprintf("Gyro\033[8G|\033[31G|\033[54G|\n\n");
    UARTprintf("Mag\033[8G|\033[31G|\033[54G|\n\n");
    UARTprintf("\n\033[20GRoll\033[31G|\033[43GPitch\033[54G|\033[66GYaw\n\n");
    UARTprintf("Eulers\033[8G|\033[31G|\033[54G|\n\n");

    UARTprintf("\n\033[17GQ1\033[26G|\033[35GQ2\033[44G|\033[53GQ3\033[62G|"
               "\033[71GQ4\n\n");
    UARTprintf("Q\033[8G|\033[26G|\033[44G|\033[62G|\n\n");

    //
    // Enable blinking indicates config finished successfully
    //
    RGBBlinkRateSet(1.0f);

    ui32CompDCMStarted = 0;

    while(1)
    {
        //
        // Go to sleep mode while waiting for data ready.
        //
        while(!g_vui8I2CDoneFlag)
        {
            ROM_SysCtlSleep();
        }

        //
        // Clear the flag
        //
        g_vui8I2CDoneFlag = 0;

        //
        // Get floating point version of the Accel Data in m/s^2.
        //
        MPU9150DataAccelGetFloat(&g_sMPU9150Inst, pfAccel, pfAccel + 1,
                                 pfAccel + 2);

        //
        // Get floating point version of angular velocities in rad/sec
        //
        MPU9150DataGyroGetFloat(&g_sMPU9150Inst, pfGyro, pfGyro + 1,
                                pfGyro + 2);

        //
        // Get floating point version of magnetic fields strength in tesla
        //
        MPU9150DataMagnetoGetFloat(&g_sMPU9150Inst, pfMag, pfMag + 1,
                                   pfMag + 2);

        //
        // Check if this is our first data ever.
        //
        if(ui32CompDCMStarted == 0)
        {
            //
            // Set flag indicating that DCM is started.
            // Perform the seeding of the DCM with the first data set.
            //
            ui32CompDCMStarted = 1;
            CompDCMMagnetoUpdate(&g_sCompDCMInst, pfMag[0], pfMag[1],
                                 pfMag[2]);
            CompDCMAccelUpdate(&g_sCompDCMInst, pfAccel[0], pfAccel[1],
                               pfAccel[2]);
            CompDCMGyroUpdate(&g_sCompDCMInst, pfGyro[0], pfGyro[1],
                              pfGyro[2]);
            CompDCMStart(&g_sCompDCMInst);
        }
        else
        {
            //
            // DCM Is already started.  Perform the incremental update.
            //
            CompDCMMagnetoUpdate(&g_sCompDCMInst, pfMag[0], pfMag[1],
                                 pfMag[2]);
            CompDCMAccelUpdate(&g_sCompDCMInst, pfAccel[0], pfAccel[1],
                               pfAccel[2]);
            CompDCMGyroUpdate(&g_sCompDCMInst, -pfGyro[0], -pfGyro[1],
                              -pfGyro[2]);
            CompDCMUpdate(&g_sCompDCMInst);
        }

        //
        // Increment the skip counter.  Skip counter is used so we do not
        // overflow the UART with data.
        //
        g_ui32PrintSkipCounter++;
        if(g_ui32PrintSkipCounter >= PRINT_SKIP_COUNT)
        {
            //
            // Reset skip counter.
            //
            g_ui32PrintSkipCounter = 0;

            //
            // Get Euler data. (Roll Pitch Yaw)
            //
            CompDCMComputeEulers(&g_sCompDCMInst, pfEulers, pfEulers + 1,
                                 pfEulers + 2);

            //
            // Get Quaternions.
            //
            CompDCMComputeQuaternion(&g_sCompDCMInst, pfQuaternion);

            //
            // convert mag data to micro-tesla for better human interpretation.
            //
            pfMag[0] *= 1e6;
            pfMag[1] *= 1e6;
            pfMag[2] *= 1e6;

            //
            // Convert Eulers to degrees. 180/PI = 57.29...
            // Convert Yaw to 0 to 360 to approximate compass headings.
            //
            pfEulers[0] *= 57.295779513082320876798154814105f;
            pfEulers[1] *= 57.295779513082320876798154814105f;
            pfEulers[2] *= 57.295779513082320876798154814105f;
            if(pfEulers[2] < 0)
            {
                pfEulers[2] += 360.0f;
            }

            //
            // Now drop back to using the data as a single array for the
            // purpose of decomposing the float into a integer part and a
            // fraction (decimal) part.
            //
            for(ui32Idx = 0; ui32Idx < 16; ui32Idx++)
            {
                //
                // Conver float value to a integer truncating the decimal part.
                //
                i32IPart[ui32Idx] = (int32_t) pfData[ui32Idx];

                //
                // Multiply by 1000 to preserve first three decimal values.
                // Truncates at the 3rd decimal place.
                //
                i32FPart[ui32Idx] = (int32_t) (pfData[ui32Idx] * 1000.0f);

                //
                // Subtract off the integer part from this newly formed decimal
                // part.
                //
                i32FPart[ui32Idx] = i32FPart[ui32Idx] -
                                    (i32IPart[ui32Idx] * 1000);

                //
                // make the decimal part a positive number for display.
                //
                if(i32FPart[ui32Idx] < 0)
                {
                    i32FPart[ui32Idx] *= -1;
                }
            }

            //
            // Print the acceleration numbers in the table.
            //
            UARTprintf("\033[5;17H%3d.%03d", i32IPart[0], i32FPart[0]);
            UARTprintf("\033[5;40H%3d.%03d", i32IPart[1], i32FPart[1]);
            UARTprintf("\033[5;63H%3d.%03d", i32IPart[2], i32FPart[2]);

            //
            // Print the angular velocities in the table.
            //
            UARTprintf("\033[7;17H%3d.%03d", i32IPart[3], i32FPart[3]);
            UARTprintf("\033[7;40H%3d.%03d", i32IPart[4], i32FPart[4]);
            UARTprintf("\033[7;63H%3d.%03d", i32IPart[5], i32FPart[5]);

            //
            // Print the magnetic data in the table.
            //
            UARTprintf("\033[9;17H%3d.%03d", i32IPart[6], i32FPart[6]);
            UARTprintf("\033[9;40H%3d.%03d", i32IPart[7], i32FPart[7]);
            UARTprintf("\033[9;63H%3d.%03d", i32IPart[8], i32FPart[8]);

            //
            // Print the Eulers in a table.
            //
            UARTprintf("\033[14;17H%3d.%03d", i32IPart[9], i32FPart[9]);
            UARTprintf("\033[14;40H%3d.%03d", i32IPart[10], i32FPart[10]);
            UARTprintf("\033[14;63H%3d.%03d", i32IPart[11], i32FPart[11]);

            //
            // Print the quaternions in a table format.
            //
            UARTprintf("\033[19;14H%3d.%03d", i32IPart[12], i32FPart[12]);
            UARTprintf("\033[19;32H%3d.%03d", i32IPart[13], i32FPart[13]);
            UARTprintf("\033[19;50H%3d.%03d", i32IPart[14], i32FPart[14]);
            UARTprintf("\033[19;68H%3d.%03d", i32IPart[15], i32FPart[15]);

        }
    }
}
예제 #16
0
void initsensorhub(void)
{
	//
	// Enable port B used for motion interrupt.
	//
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

	//
	// Initialize the UART.
	//
	ConfigureUART();

	//
	// Print the welcome message to the terminal.
	//
	UARTprintf("\033[2JMPU9150 Raw Example\n");

	//
	// Set the color to a purple approximation.
	//
	g_pui32Colors[RED] = 0x8000;
	g_pui32Colors[BLUE] = 0x8000;
	g_pui32Colors[GREEN] = 0x0000;

	//
	// Initialize RGB driver.
	//
	RGBInit(0);
	RGBColorSet(g_pui32Colors);
	RGBIntensitySet(0.5f);
	RGBEnable();

	//
	// The I2C3 peripheral must be enabled before use.
	//
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3);
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

	//
	// Configure the pin muxing for I2C3 functions on port D0 and D1.
	//
	ROM_GPIOPinConfigure(GPIO_PD0_I2C3SCL);
	ROM_GPIOPinConfigure(GPIO_PD1_I2C3SDA);

	//
	// Select the I2C function for these pins.  This function will also
	// configure the GPIO pins pins for I2C operation, setting them to
	// open-drain operation with weak pull-ups.  Consult the data sheet
	// to see which functions are allocated per pin.
	//
	GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0);
	ROM_GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1);

	//
	// Configure and Enable the GPIO interrupt. Used for INT signal from the
	// MPU9150
	//
	ROM_GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_2);
	GPIOIntEnable(GPIO_PORTB_BASE, GPIO_PIN_2);
	ROM_GPIOIntTypeSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_FALLING_EDGE);
	ROM_IntEnable(INT_GPIOB);

	//
	// Keep only some parts of the systems running while in sleep mode.
	// GPIOB is for the MPU9150 interrupt pin.
	// UART0 is the virtual serial port
	// TIMER0, TIMER1 and WTIMER5 are used by the RGB driver
	// I2C3 is the I2C interface to the ISL29023
	//
	ROM_SysCtlPeripheralClockGating(true);
	ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOB);
	ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART0);
	ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER0);
	ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER1);
	ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_I2C3);
	ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_WTIMER5);

	//
	// Enable interrupts to the processor.
	//
	ROM_IntMasterEnable();

	//
	// Initialize I2C3 peripheral.
	//
	I2CMInit(&g_sI2CInst, I2C3_BASE, INT_I2C3, 0xff, 0xff,
			ROM_SysCtlClockGet());

	//
	// Initialize the MPU9150 Driver.
	//
	MPU9150Init(&g_sMPU9150Inst, &g_sI2CInst, MPU9150_I2C_ADDRESS,
			MPU9150AppCallback, &g_sMPU9150Inst);

	//
	// Wait for transaction to complete
	//
	MPU9150AppI2CWait(__FILE__, __LINE__);

	//
	// Write application specifice sensor configuration such as filter settings
	// and sensor range settings.
	//
	g_sMPU9150Inst.pui8Data[0] = MPU9150_CONFIG_DLPF_CFG_94_98;
	g_sMPU9150Inst.pui8Data[1] = MPU9150_GYRO_CONFIG_FS_SEL_250;
	g_sMPU9150Inst.pui8Data[2] = (MPU9150_ACCEL_CONFIG_ACCEL_HPF_5HZ |
			MPU9150_ACCEL_CONFIG_AFS_SEL_2G);
	MPU9150Write(&g_sMPU9150Inst, MPU9150_O_CONFIG, g_sMPU9150Inst.pui8Data, 3,
			MPU9150AppCallback, &g_sMPU9150Inst);

	//
	// Wait for transaction to complete
	//
	MPU9150AppI2CWait(__FILE__, __LINE__);

	//
	// Configure the data ready interrupt pin output of the MPU9150.
	//
	g_sMPU9150Inst.pui8Data[0] = MPU9150_INT_PIN_CFG_INT_LEVEL |
			MPU9150_INT_PIN_CFG_INT_RD_CLEAR |
			MPU9150_INT_PIN_CFG_LATCH_INT_EN;
	g_sMPU9150Inst.pui8Data[1] = MPU9150_INT_ENABLE_DATA_RDY_EN;
	MPU9150Write(&g_sMPU9150Inst, MPU9150_O_INT_PIN_CFG,
			g_sMPU9150Inst.pui8Data, 2, MPU9150AppCallback,
			&g_sMPU9150Inst);

	//
	// Wait for transaction to complete
	//
	MPU9150AppI2CWait(__FILE__, __LINE__);

	//
	// Initialize the DCM system. 50 hz sample rate.
	// accel weight = .2, gyro weight = .8, mag weight = .2
	//
	CompDCMInit(&g_sCompDCMInst, 1.0f / 50.0f, 0.2f, 0.6f, 0.2f);

	UARTprintf("\033[2J\033[H");
	UARTprintf("MPU9150 9-Axis Simple Data Application Example\n\n");
	UARTprintf("\033[20GX\033[31G|\033[43GY\033[54G|\033[66GZ\n\n");
	 UARTprintf("Accel\033[8G|\033[31G|\033[54G|\n\n");
	  UARTprintf("Gyro\033[8G|\033[31G|\033[54G|\n\n");
	 UARTprintf("Mag\033[8G|\033[31G|\033[54G|\n\n");
	UARTprintf("\n\033[20GRoll\033[31G|\033[43GPitch\033[54G|\033[66GYaw\n\n");
	UARTprintf("Eulers\033[8G|\033[31G|\033[54G|\n\n");

	  UARTprintf("\n\033[17GQ1\033[26G|\033[35GQ2\033[44G|\033[53GQ3\033[62G|"
	            "\033[71GQ4\n\n");
	  UARTprintf("Q\033[8G|\033[26G|\033[44G|\033[62G|\n\n");

	//
	// Enable blinking indicates config finished successfully
	//
	RGBBlinkRateSet(1.0f);
	//
	// Initialize convenience pointers that clean up and clarify the code
	// meaning. We want all the data in a single contiguous array so that
	// we can make our pretty printing easier later.
	//
	pfAccel = pfData;
	pfGyro = pfData + 3;
	pfMag = pfData + 6;
	pfEulers = pfData + 9;
	pfQuaternion = pfData + 12;

}
//*****************************************************************************
//
// Initializes the ISL29023 task.
//
//*****************************************************************************
uint32_t
ISL29023TaskInit(void)
{
    //
    // Reset the GPIO port to be sure all previous interrupt config is cleared.
    //
    SysCtlPeripheralReset(SYSCTL_PERIPH_GPIOE);
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOE))
    {
        //
        // Do Nothing. Wait for reset to complete.
        //
    }

    //
    // Configure and Enable the GPIO interrupt. Used for INT signal from the
    // ISL29023
    //
    ROM_GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_5);
    GPIOIntEnable(GPIO_PORTE_BASE, GPIO_PIN_5);
    ROM_GPIOIntTypeSet(GPIO_PORTE_BASE, GPIO_PIN_5, GPIO_FALLING_EDGE);

    //
    // Change the interrupt priority so that the interrupt handler function can
    // call FreeRTOS APIs.
    //
    IntPrioritySet(INT_GPIOE, 0xE0);
    ROM_IntEnable(INT_GPIOE);

    //
    // Create a transaction complete semaphore to sync the application callback
    // which is called from the I2C master driver in I2C interrupt context and
    // the task.
    //
    vSemaphoreCreateBinary(g_xISL29023TransactionCompleteSemaphore);

    //
    // Create a semaphore for notifying from the light threshold ISR to the task
    // that the light thresholds have been exceeded (too high or too low).
    //
    vSemaphoreCreateBinary(g_xISL29023AdjustRangeSemaphore);

    //
    // Create the switch task.
    //
    if(xTaskCreate(ISL29023Task, (const portCHAR *)"ISL29023  ",
                   ISL29023_TASK_STACK_SIZE, NULL, tskIDLE_PRIORITY +
                   PRIORITY_ISL29023_TASK, g_xISL29023Handle) != pdTRUE)
    {
        //
        // Task creation failed.
        //
        return(1);
    }

    //
    // Check if Semaphore creation was successfull.
    //
    if((g_xISL29023TransactionCompleteSemaphore == NULL) ||
       (g_xISL29023AdjustRangeSemaphore == NULL))
    {
        //
        // Semaphore was not created successfully.
        //
        return(1);
    }

    //
    // Set the active flag that shows this task is running properly.
    // Initialize the other variables in the data structure.
    //
    g_sISL29023Data.bActive = true;
    g_sISL29023Data.fVisible = 0.0f;
    g_sISL29023Data.fInfrared = 0.0f;
    g_sISL29023Data.ui8Range = 0;
    g_sISL29023Data.xTimeStampTicks = 0;

    //
    // Initialize the cloud data global pointer to this sensors local data.
    //
    g_sCloudData.psISL29023Data = &g_sISL29023Data;

    //
    // Success.
    //
    return(0);

}
//*****************************************************************************
//
// Main 'C' Language entry point.
//
//*****************************************************************************
int
main(void)
{
    float fAmbient;
    int32_t i32IntegerPart, i32FractionPart;
    uint8_t ui8Mask;

    //
    // Setup the system clock to run at 40 Mhz from PLL with crystal reference
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
                       SYSCTL_OSC_MAIN);

    //
    // Enable the peripherals used by this example.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

    //
    // Initialize the UART and its pins.
    //
    ConfigureUART();

    //
    // Print the welcome message to the terminal.
    //
    UARTprintf("\033[2JISL29023 Example\n");

    //
    // Set the color to a white approximation.
    //
    g_pui32Colors[RED] = 0x8000;
    g_pui32Colors[BLUE] = 0x8000;
    g_pui32Colors[GREEN] = 0x8000;

    //
    // Initialize RGB driver. Use a default intensity and blink rate.
    //
    RGBInit(0);
    RGBColorSet(g_pui32Colors);
    RGBIntensitySet(0.5f);
    RGBEnable();

    //
    // The I2C3 peripheral must be enabled before use.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

    //
    // Configure the pin muxing for I2C3 functions on port D0 and D1.
    // This step is not necessary if your part does not support pin muxing.
    //
    ROM_GPIOPinConfigure(GPIO_PD0_I2C3SCL);
    ROM_GPIOPinConfigure(GPIO_PD1_I2C3SDA);

    //
    // Select the I2C function for these pins.  This function will also
    // configure the GPIO pins pins for I2C operation, setting them to
    // open-drain operation with weak pull-ups.  Consult the data sheet
    // to see which functions are allocated per pin.
    //
    GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0);
    ROM_GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1);

    //
    // Configure and Enable the GPIO interrupt. Used for INT signal from the
    // ISL29023
    //
    ROM_GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_5);
    GPIOIntEnable(GPIO_PORTE_BASE, GPIO_PIN_5);
    ROM_GPIOIntTypeSet(GPIO_PORTE_BASE, GPIO_PIN_5, GPIO_FALLING_EDGE);
    ROM_IntEnable(INT_GPIOE);

    //
    // Keep only some parts of the systems running while in sleep mode.
    // GPIOE is for the ISL29023 interrupt pin.
    // UART0 is the virtual serial port
    // TIMER0, TIMER1 and WTIMER5 are used by the RGB driver
    // I2C3 is the I2C interface to the ISL29023
    //
    ROM_SysCtlPeripheralClockGating(true);
    ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOE);
    ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART0);
    ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER0);
    ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER1);
    ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_I2C3);
    ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_WTIMER5);

    //
    // Configure desired interrupt priorities.  Setting the I2C interrupt to be
    // of more priority than SysTick and the GPIO interrupt means those
    // interrupt routines can use the I2CM_DRV Application context does not use
    // I2CM_DRV API and GPIO and SysTick are at the same priority level. This
    // prevents re-entrancy problems with I2CM_DRV but keeps the MCU in sleep
    // state as much as possible. UART is at least priority so it can operate
    // in the background.
    //
    ROM_IntPrioritySet(INT_I2C3, 0x00);
    ROM_IntPrioritySet(FAULT_SYSTICK, 0x40);
    ROM_IntPrioritySet(INT_GPIOE, 0x80);
    ROM_IntPrioritySet(INT_UART0, 0x80);

    //
    // Enable interrupts to the processor.
    //
    ROM_IntMasterEnable();

    //
    // Initialize I2C3 peripheral.
    //
    I2CMInit(&g_sI2CInst, I2C3_BASE, INT_I2C3, 0xff, 0xff,
             ROM_SysCtlClockGet());

    //
    // Initialize the ISL29023 Driver.
    //
    ISL29023Init(&g_sISL29023Inst, &g_sI2CInst, ISL29023_I2C_ADDRESS,
                 ISL29023AppCallback, &g_sISL29023Inst);

    //
    // Wait for transaction to complete
    //
    ISL29023AppI2CWait(__FILE__, __LINE__);

    //
    // Configure the ISL29023 to measure ambient light continuously. Set a 8
    // sample persistence before the INT pin is asserted. Clears the INT flag.
    // Persistence setting of 8 is sufficient to ignore camera flashes.
    //
    ui8Mask = (ISL29023_CMD_I_OP_MODE_M | ISL29023_CMD_I_INT_PERSIST_M |
               ISL29023_CMD_I_INT_FLAG_M);
    ISL29023ReadModifyWrite(&g_sISL29023Inst, ISL29023_O_CMD_I, ~ui8Mask,
                            (ISL29023_CMD_I_OP_MODE_ALS_CONT |
                             ISL29023_CMD_I_INT_PERSIST_8),
                            ISL29023AppCallback, &g_sISL29023Inst);

    //
    // Wait for transaction to complete
    //
    ISL29023AppI2CWait(__FILE__, __LINE__);

    //
    // Configure the upper threshold to 80% of maximum value
    //
    g_sISL29023Inst.pui8Data[1] = 0xCC;
    g_sISL29023Inst.pui8Data[2] = 0xCC;
    ISL29023Write(&g_sISL29023Inst, ISL29023_O_INT_HT_LSB,
                  g_sISL29023Inst.pui8Data, 2, ISL29023AppCallback,
                  &g_sISL29023Inst);

    //
    // Wait for transaction to complete
    //
    ISL29023AppI2CWait(__FILE__, __LINE__);

    //
    // Configure the lower threshold to 20% of maximum value
    //
    g_sISL29023Inst.pui8Data[1] = 0x33;
    g_sISL29023Inst.pui8Data[2] = 0x33;
    ISL29023Write(&g_sISL29023Inst, ISL29023_O_INT_LT_LSB,
                  g_sISL29023Inst.pui8Data, 2, ISL29023AppCallback,
                  &g_sISL29023Inst);
    //
    // Wait for transaction to complete
    //
    ISL29023AppI2CWait(__FILE__, __LINE__);

    //
    //Configure and enable SysTick Timer
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND);
    ROM_SysTickIntEnable();
    ROM_SysTickEnable();

    //
    // After all the init and config we start blink the LED
    //
    RGBBlinkRateSet(1.0f);

    //
    // Loop Forever
    //
    while(1)
    {
        ROM_SysCtlSleep();

        if(g_vui8DataFlag)
        {
            g_vui8DataFlag = 0;

            //
            // Get a local floating point copy of the latest light data
            //
            ISL29023DataLightVisibleGetFloat(&g_sISL29023Inst, &fAmbient);

            //
            // Perform the conversion from float to a printable set of integers
            //
            i32IntegerPart = (int32_t)fAmbient;
            i32FractionPart = (int32_t)(fAmbient * 1000.0f);
            i32FractionPart = i32FractionPart - (i32IntegerPart * 1000);
            if(i32FractionPart < 0)
            {
                i32FractionPart *= -1;
            }

            //
            // Print the temperature as integer and fraction parts.
            //
            UARTprintf("Visible Lux: %3d.%03d\n", i32IntegerPart,
                       i32FractionPart);

            //
            // Check if the intensity of light has crossed a threshold. If so
            // then adjust range of sensor readings to track intensity.
            //
            if(g_vui8IntensityFlag)
            {
                //
                // Disable the low priority interrupts leaving only the I2C
                // interrupt enabled.
                //
                ROM_IntPriorityMaskSet(0x40);

                //
                // Reset the intensity trigger flag.
                //
                g_vui8IntensityFlag = 0;

                //
                // Adjust the lux range.
                //
                ISL29023AppAdjustRange(&g_sISL29023Inst);

                //
                // Now we must manually clear the flag in the ISL29023
                // register.
                //
                ISL29023Read(&g_sISL29023Inst, ISL29023_O_CMD_I,
                             g_sISL29023Inst.pui8Data, 1, ISL29023AppCallback,
                             &g_sISL29023Inst);

                //
                // Wait for transaction to complete
                //
                ISL29023AppI2CWait(__FILE__, __LINE__);

                //
                // Disable priority masking so all interrupts are enabled.
                //
                ROM_IntPriorityMaskSet(0);
            }
        }
    }
}
//*****************************************************************************
//
// Abstraction for LED output.
//
//*****************************************************************************
void
LEDOutput(uint32_t ui32WheelPosition)
{
    //
    // Put all of our pins in a known state where all LEDs are off.
    //
    ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_4, 0);
    ROM_GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_5);
    ROM_GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_4);
    ROM_GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_6);
    ROM_GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_7);

    if((ui32WheelPosition == 0) || (ui32WheelPosition == 8))
    {
        //
        // If the top or bottom button is being pressed, we have no indicator
        // lights, so return without doing anything.
        //
        return;
    }
    else if(ui32WheelPosition < 8)
    {
        //
        // Positions less than 8 correspond to the right side of the wheel,
        // whose LEDs may turn on when PE4 is pulled high.
        //
        ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_4, GPIO_PIN_4);

        //
        // Write a zero to the appropriate GPIO(s) to turn on the light(s)
        // nearest to the current wheel position.
        //
        switch(ui32WheelPosition)
        {
            case 1:
            {
                ROM_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_5);
                ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_5, 0);
                break;
            }

            case 2:
            {
                ROM_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_5);
                ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_5, 0);
                ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_4);
                ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_4, 0);
                break;
            }

            case 3:
            {
                ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_4);
                ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_4, 0);
                break;
            }

            case 4:
            {
                ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_4);
                ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_4, 0);
                ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_6);
                ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_6, 0);
                break;
            }

            case 5:
            {
                ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_6);
                ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_6, 0);
                break;
            }

            case 6:
            {
                ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_6);
                ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_6, 0);
                ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_7);
                ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, 0);
                break;
            }

            case 7:
            {
                ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_7);
                ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, 0);
                break;
            }

            default:
            {
                //
                // We should never get here.
                //
                break;
            }
        }

    }
    else
    {
        //
        // Positions greater than 8 correspond to the left side of the wheel,
        // whose LEDs may turn on when PE4 is pulled low.
        //
        ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_4, 0);

        //
        // Write a one to the appropriate GPIO(s) to turn on the light(s)
        // nearest to the current wheel position.
        //
        switch(ui32WheelPosition)
        {
            case 9:
            {
                ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_7);
                ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, GPIO_PIN_7);
                break;
            }

            case 10:
            {
                ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_7);
                ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, GPIO_PIN_7);
                ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_6);
                ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_6, GPIO_PIN_6);
                break;
            }

            case 11:
            {
                ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_6);
                ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_6, GPIO_PIN_6);
                break;
            }

            case 12:
            {
                ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_6);
                ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_6, GPIO_PIN_6);
                ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_4);
                ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_4, GPIO_PIN_4);
                break;
            }

            case 13:
            {
                ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_4);
                ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_4, GPIO_PIN_4);
                break;
            }

            case 14:
            {
                ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_4);
                ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_4, GPIO_PIN_4);
                ROM_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_5);
                ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_5, GPIO_PIN_5);
                break;
            }

            case 15:
            {
                ROM_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_5);
                ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_5, GPIO_PIN_5);
                break;
            }

            default:
            {
                //
                // We should never get here.
                //
                break;
            }
        }
    }
}
//*****************************************************************************
//
//! Initializes the TLV320AIC3107 DAC.
//!
//! This function initializes the I2C interface and the TLV320AIC3107 DAC.  It
//! must be called prior to any other API in the DAC module.
//!
//! \return Returns \b true on success or \b false on failure.
//
//*****************************************************************************
tBoolean
DACInit(void)
{
    tBoolean bRetcode;
    unsigned char ucTest;

    //
    // Enable the GPIO port containing the I2C pins and set the SDA pin as a
    // GPIO input for now and engage a weak pull-down.  If the daughter board
    // is present, the pull-up on the board should easily overwhelm
    // the pull-down and we should read the line state as high.
    //
    ROM_SysCtlPeripheralEnable(DAC_I2CSCL_GPIO_PERIPH);
    ROM_GPIOPinTypeGPIOInput(DAC_I2CSCL_GPIO_PORT, DAC_I2CSDA_PIN);
    ROM_GPIOPadConfigSet(DAC_I2CSCL_GPIO_PORT, DAC_I2CSDA_PIN,
                         GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPD);

    //
    // Enable the I2C peripheral.
    //
    ROM_SysCtlPeripheralEnable(DAC_I2C_PERIPH);

    //
    // Delay a while to ensure that we read a stable value from the SDA
    // GPIO pin.  If we read too quickly, the result is unpredictable.
    // This delay is around 2mS.
    //
    SysCtlDelay(ROM_SysCtlClockGet() / (3 * 500));

    //
    // Configure the pin mux.
    //
    GPIOPinConfigure(GPIO_PB2_I2C0SCL);
    GPIOPinConfigure(GPIO_PB3_I2C0SDA);

    //
    // Configure the I2C SCL and SDA pins for I2C operation.
    //
    ROM_GPIOPinTypeI2C(DAC_I2CSCL_GPIO_PORT, DAC_I2CSCL_PIN | DAC_I2CSDA_PIN);

    //
    // Initialize the I2C master.
    //
    ROM_I2CMasterInitExpClk(DAC_I2C_MASTER_BASE, SysCtlClockGet(), 0);

    //
    // Enable the I2C peripheral.
    //
    ROM_SysCtlPeripheralEnable(DAC_RESET_GPIO_PERIPH);

    //
    // Configure the PH2 as a GPIO output.
    //
    ROM_GPIOPinTypeGPIOOutput(DAC_RESET_GPIO_PORT, DAC_RESET_PIN);

    //
    // Reset the DAC
    //
    ROM_GPIOPinWrite(DAC_RESET_GPIO_PORT , DAC_RESET_PIN, 0);
    ROM_GPIOPinWrite(DAC_RESET_GPIO_PORT , DAC_RESET_PIN, DAC_RESET_PIN);

    //
    // Reset the DAC.  Check the return code on this call since we use it to
    // indicate whether or not the DAC is present.  If the register write
    // fails, we assume the I2S daughter board and DAC are not present and
    // return false.
    //
    bRetcode = DACWriteRegister(TI_SOFTWARE_RESET_R, 0x80);
    if(!bRetcode)
    {
        return(bRetcode);
    }

    //
    // Codec Datapath Setup Register
    // ----------------------
    // D7     = 1  : Fsref = 44.1-kHz
    // D6     = 0  : ADC Dual rate mode is disabled
    // D5     = 0  : DAC Dual rate mode is disabled
    // D[4:3] = 11 : Left DAC datapath plays mono mix of left and right channel
    //               input data
    // D[1:1] = 00 : Right DAC datapath is off
    // D0     = 0  : reserved
    // ----------------------
    // D[7:0] =  10011010
    //
    DACWriteRegister(TI_CODEC_DATAPATH_R, 0x98);

    //
    // Audio Serial Data Interface Control Register A
    // ----------------------
    // D7     = 0  : BCLK is an input (slave mode)
    // D6     = 0  : WCLK (or GPIO1 if programmed as WCLK) is an input
    //               (slave mode)
    // D5     = 0  : Do not 3-state DOUT when valid data is not being sent
    // D4     = 0  : BCLK / WCLK (or GPIO1 if programmed as WCLK) will not
    //               continue to be transmitted when running in master mode if codec is powered down
    // D3     = 0  : Reserved.
    // D2     = 0  : Disable 3-D digital effect processing
    // D[1:0] = 00 : reserved
    // ----------------------
    // D[7:0] = 00000000
    //
    DACWriteRegister(TI_ASDI_CTL_A_R, 0x00);

    //
    // Audio Serial Data Interface Control Register B
    // ----------------------
    // D[7:6] = 00 : Serial data bus uses I2S mode
    // D[5:4] = 00 : Audio data word length = 16-bits
    // D3     = 0  : Continuous-transfer mode used to determine master mode
    //               bit clock rate
    // D2     = 0  : Don't Care
    // D1     = 0  : Don't Care
    // D0     = 0  : Re-Sync is done without soft-muting the channel. (ADC/DAC)
    // ----------------------
    // D[7:0] = 00000000
    //
    DACWriteRegister(TI_ASDI_CTL_B_R, 0x00);

    //
    // Audio Serial Data Interface Control Register C
    // ----------------------
    // D[7:0] = 00000000 : Data offset = 0 bit clocks
    // ----------------------
    // D[7:0] = 00000000
    //
    DACWriteRegister(TI_ASDI_CTL_C_R, 0x00);

    //
    // DAC Power and Output Driver Control Register
    // ----------------------
    // D7     = 1  : Left DAC is powered up
    // D6     = 1  : Right DAC is powered up
    // D[5:4] = 00 : HPCOM configured as differential of HPLOUT
    // D[3:0] = 0  : reserved
    // ----------------------
    // D[7:0] = 11000000
    //
    DACWriteRegister(TI_DACPOD_CTL_R, 0xC0);

    //
    // Left DAC Digital Volume Control Register
    // ----------------------
    // D7     = 0  : The left DAC channel is not muted
    // D[6:0] = 0  :
    // ----------------------
    // D[7:0] =
    //
    DACWriteRegister(TI_LEFT_DAC_DIG_VOL_CTL_R, 0x00);

    //
    // Right DAC Digital Volume Control Register
    // ----------------------
    // D7     = 0  : The right DAC channel is not muted
    // D[6:0] = 0  :
    // ----------------------
    // D[7:0] =
    //
    DACWriteRegister(TI_RIGHT_DAC_DIG_VOL_CTL_R, 0x00);

    //
    // DAC_L1 to LEFT_LOP Volume Control Register
    // ----------------------
    // D7     = 1  : DAC_L1 is routed to LEFT_LOP
    // D[6:0] = 0110010 (50)  : Gain
    // ----------------------
    // D[7:0] = 10110010
    //
    DACWriteRegister(TI_DAC_L1_LEFT_LOP_VOL_CTL_R, 0xA0);

    //
    // LEFT_LOP Output Level Control Register
    // ----------------------
    // D[7:4] = 0110  : Output level control = 6 dB
    // D3     = 1     :    LEFT_LOP is not muted
    // D2     = 0     :    Reserved.
    // D1     = 0     :    All programmed gains to LEFT_LOP have been applied
    // D0     = 1     :    LEFT_LOP is fully powered up
    // ----------------------
    // D[7:0] = 00001001
    //
    DACWriteRegister(TI_LEFT_LOP_OUTPUT_LVL_CTL_R, 0xC9);

    //
    // From the TLV320AIC3107 datasheet:
    // The following initialization sequence must be written to the AIC3107
    // registers prior to enabling the class-D amplifier:
    // register data:
    // 1. 0x00 0x0D
    // 2. 0x0D 0x0D
    // 3. 0x08 0x5C
    // 4. 0x08 0x5D
    // 5. 0x08 0x5C
    // 6. 0x00 0x00
    //
    DACWriteRegister(0x00, 0x0D);
    DACWriteRegister(0x0D, 0x0D);
    DACWriteRegister(0x08, 0x5C);
    DACWriteRegister(0x08, 0x5D);
    DACWriteRegister(0x08, 0x5C);
    DACWriteRegister(0x00, 0x00);

    //
    // Class-D and Bypass Switch Control Register
    // ----------------------
    // D[7:6] = 01 : Left Class-D amplifier gain = 6.0 dB
    // D[5:4] = 00 : Right Class-D amplifier gain = 0.0 dB
    // D3     = 1  : enable left class-D channel
    // D2     = 0  : disable right class-D channel
    // D1     = 0  : disable bypass switch
    // D0     = 0  : disable bypass switch bootstrap clock
    // ----------------------
    // D[7:0] = 01001000
    //
    DACWriteRegister(TI_CLASSD_BYPASS_SWITCH_CTL_R, 0x40);

    //
    //Read Module Power Status Register
    //
    bRetcode = DACReadRegister(TI_MODULE_PWR_STAT_R, &ucTest);
    if(!bRetcode)
    {
        return(bRetcode);
    }

    return(true);
}
예제 #21
0
void tm4c123_i2c_initialize(void)
{
  uint32_t count;

    tm4c123_i2c_device.state = I2C_STATE_IDLE;

    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

    /* Disable I2C3 */
    I2C3->MCR  = I2C_MCR_MFE;

    ROM_GPIOPinTypeGPIOOutputOD(GPIOD_BASE, GPIO_PIN_0);
    ROM_GPIOPinTypeGPIOInput(GPIOD_BASE, GPIO_PIN_1);
    
    /* Delay for 10usec */
    armv7m_udelay(10);

    /* If SDA is tied low by a slave, issue clock pulses till it releases
     * the bus.
     */
    for (count = 0; count < 128; count++)
    {
	if (GPIOD->DATA & GPIO_PIN_1)
	{
	    break;
	}

        /* Set SCL to L */ 
	armv7m_bitband_peripheral_write(&GPIOD->DATA, 0, 0);
        armv7m_udelay(5);    
	
        /* Set SCL to H */ 
	armv7m_bitband_peripheral_write(&GPIOD->DATA, 0, 1);
        armv7m_udelay(5);    
    }

    ROM_GPIOPinTypeGPIOOutput(GPIOD_BASE, GPIO_PIN_1);

    armv7m_bitband_peripheral_write(&GPIOD->DATA, 0, 1);
    armv7m_bitband_peripheral_write(&GPIOD->DATA, 1, 1);
    armv7m_udelay(5);    


    /* Now SCL is H and SDA is H, so generate a STOP condition.
     */

    /* Set SCL to L */ 
    armv7m_bitband_peripheral_write(&GPIOD->DATA, 0, 0);
    armv7m_udelay(5);    

    /* Set SDA to L */ 
    armv7m_bitband_peripheral_write(&GPIOD->DATA, 1, 0);
    armv7m_udelay(5);    
    
    /* Set SCL to H */ 
    armv7m_bitband_peripheral_write(&GPIOD->DATA, 0, 1);
    armv7m_udelay(5);    

    /* Set SDA to H */ 
    armv7m_bitband_peripheral_write(&GPIOD->DATA, 1, 1);
    armv7m_udelay(5);    

    /* After this recovery, switch to regular I2C mode.
     */


    /* Enable pin PD0 for I2C3 I2C3SCL
     */
    ROM_GPIOPinConfigure(GPIO_PD0_I2C3SCL);
    ROM_GPIOPinTypeI2CSCL(GPIOD_BASE, GPIO_PIN_0);

    /* Enable pin PD1 for I2C3 I2C3SDA
     */
    ROM_GPIOPinConfigure(GPIO_PD1_I2C3SDA);
    ROM_GPIOPinTypeI2C(GPIOD_BASE, GPIO_PIN_1);

    tm4c123_i2c_reset();

    NVIC_SetPriority(I2C3_IRQn, 3);
    NVIC_EnableIRQ(I2C3_IRQn);
}
예제 #22
0
파일: ti_Board.c 프로젝트: younghonor/2016
//函数创建区
//----------------------------------------Start-------------------------------------------
void Init_Button()
{
    //Enable 按键
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    ROM_GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1);    //使能输入
}
예제 #23
0
파일: gpio_jtag.c 프로젝트: mileat/proj-emb
//*****************************************************************************
//
// The interrupt handler for the PB4 pin interrupt.  When triggered, this will
// toggle the JTAG pins between JTAG and GPIO mode.
//
//*****************************************************************************
void
SysTickIntHandler(void)
{
    uint8_t ui8Buttons;
    uint8_t ui8ButtonsChanged;

    //
    // Grab the current, debounced state of the buttons.
    //
    ui8Buttons = ButtonsPoll(&ui8ButtonsChanged, 0);

    //
    // If the USR_SW1 button has been pressed, and was previously not pressed,
    // start the process of changing the behavior of the JTAG pins.
    //
    if(BUTTON_PRESSED(USR_SW1, ui8Buttons, ui8ButtonsChanged))
    {
        //
        // Toggle the pin mode.
        //
        g_ui32Mode ^= 1;

        //
        // See if the pins should be in JTAG or GPIO mode.
        //
        if(g_ui32Mode == 0)
        {
            //
            // Change PC0-3 into hardware (i.e. JTAG) pins.
            //
            HWREG(GPIO_PORTC_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
            HWREG(GPIO_PORTC_BASE + GPIO_O_CR) = 0x01;
            HWREG(GPIO_PORTC_BASE + GPIO_O_AFSEL) |= 0x01;
            HWREG(GPIO_PORTC_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
            HWREG(GPIO_PORTC_BASE + GPIO_O_CR) = 0x02;
            HWREG(GPIO_PORTC_BASE + GPIO_O_AFSEL) |= 0x02;
            HWREG(GPIO_PORTC_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
            HWREG(GPIO_PORTC_BASE + GPIO_O_CR) = 0x04;
            HWREG(GPIO_PORTC_BASE + GPIO_O_AFSEL) |= 0x04;
            HWREG(GPIO_PORTC_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
            HWREG(GPIO_PORTC_BASE + GPIO_O_CR) = 0x08;
            HWREG(GPIO_PORTC_BASE + GPIO_O_AFSEL) |= 0x08;
            HWREG(GPIO_PORTC_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
            HWREG(GPIO_PORTC_BASE + GPIO_O_CR) = 0x00;
            HWREG(GPIO_PORTC_BASE + GPIO_O_LOCK) = 0;

            //
            // Turn on the LED to indicate that the pins are in JTAG mode.
            //
            ROM_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0 | GPIO_PIN_1,
                             GPIO_PIN_0);
        }
        else
        {
            //
            // Change PC0-3 into GPIO inputs.
            //
            HWREG(GPIO_PORTC_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
            HWREG(GPIO_PORTC_BASE + GPIO_O_CR) = 0x01;
            HWREG(GPIO_PORTC_BASE + GPIO_O_AFSEL) &= 0xfe;
            HWREG(GPIO_PORTC_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
            HWREG(GPIO_PORTC_BASE + GPIO_O_CR) = 0x02;
            HWREG(GPIO_PORTC_BASE + GPIO_O_AFSEL) &= 0xfd;
            HWREG(GPIO_PORTC_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
            HWREG(GPIO_PORTC_BASE + GPIO_O_CR) = 0x04;
            HWREG(GPIO_PORTC_BASE + GPIO_O_AFSEL) &= 0xfb;
            HWREG(GPIO_PORTC_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
            HWREG(GPIO_PORTC_BASE + GPIO_O_CR) = 0x08;
            HWREG(GPIO_PORTC_BASE + GPIO_O_AFSEL) &= 0xf7;
            HWREG(GPIO_PORTC_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
            HWREG(GPIO_PORTC_BASE + GPIO_O_CR) = 0x00;
            HWREG(GPIO_PORTC_BASE + GPIO_O_LOCK) = 0;
            ROM_GPIOPinTypeGPIOInput(GPIO_PORTC_BASE, (GPIO_PIN_0 | GPIO_PIN_1 |
                                     GPIO_PIN_2 |
                                     GPIO_PIN_3));

            //
            // Turn off the LED to indicate that the pins are in GPIO mode.
            //
            ROM_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0 | GPIO_PIN_1,
                             GPIO_PIN_1);
        }
    }
}
예제 #24
0
파일: motion.c 프로젝트: PhamVanNhi/ECE5770
//*****************************************************************************
//
// Initialize the I2C, MPU9150 and Gesture systems.
//
//*****************************************************************************
void
MotionInit(void)
{
	//
    // Enable port B used for motion interrupt.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

    //
    // The I2C3 peripheral must be enabled before use.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

    //
    // Configure the pin muxing for I2C3 functions on port D0 and D1.
    //
    ROM_GPIOPinConfigure(GPIO_PD0_I2C3SCL);
    ROM_GPIOPinConfigure(GPIO_PD1_I2C3SDA);

    //
    // Select the I2C function for these pins.  This function will also
    // configure the GPIO pins pins for I2C operation, setting them to
    // open-drain operation with weak pull-ups.  Consult the data sheet
    // to see which functions are allocated per pin.
    //
    GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0);
    ROM_GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1);

    //
    // Configure and Enable the GPIO interrupt. Used for INT signal from the
    // MPU9150
    //
    ROM_GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_2);
    GPIOIntEnable(GPIO_PORTB_BASE, GPIO_PIN_2);
    ROM_GPIOIntTypeSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_FALLING_EDGE);
    ROM_IntEnable(INT_GPIOB);

    //
    // Enable interrupts to the processor.
    //
    ROM_IntMasterEnable();

    //
    // Initialize I2C3 peripheral.
    //
    I2CMInit(&g_sI2CInst, I2C3_BASE, INT_I2C3, 0xff, 0xff,
             ROM_SysCtlClockGet());

    //
    // Set the motion state to initializing.
    //
    g_ui8MotionState = MOTION_STATE_INIT;

    //
    // Initialize the MPU9150 Driver.
    //
    MPU9150Init(&g_sMPU9150Inst, &g_sI2CInst, MPU9150_I2C_ADDRESS,
                MotionCallback, &g_sMPU9150Inst);

    //
    // Wait for transaction to complete
    //
    MotionI2CWait(__FILE__, __LINE__);

    //
    // Write application specifice sensor configuration such as filter settings
    // and sensor range settings.
    //
    g_sMPU9150Inst.pui8Data[0] = MPU9150_CONFIG_DLPF_CFG_94_98;
    g_sMPU9150Inst.pui8Data[1] = MPU9150_GYRO_CONFIG_FS_SEL_250;
    g_sMPU9150Inst.pui8Data[2] = (MPU9150_ACCEL_CONFIG_ACCEL_HPF_5HZ |
                                  MPU9150_ACCEL_CONFIG_AFS_SEL_2G);
    MPU9150Write(&g_sMPU9150Inst, MPU9150_O_CONFIG, g_sMPU9150Inst.pui8Data, 3,
                 MotionCallback, &g_sMPU9150Inst);

    //
    // Wait for transaction to complete
    //
    MotionI2CWait(__FILE__, __LINE__);

    //
    // Configure the data ready interrupt pin output of the MPU9150.
    //
    g_sMPU9150Inst.pui8Data[0] = (MPU9150_INT_PIN_CFG_INT_LEVEL |
                                  MPU9150_INT_PIN_CFG_INT_RD_CLEAR |
                                  MPU9150_INT_PIN_CFG_LATCH_INT_EN);
    g_sMPU9150Inst.pui8Data[1] = MPU9150_INT_ENABLE_DATA_RDY_EN;
    MPU9150Write(&g_sMPU9150Inst, MPU9150_O_INT_PIN_CFG,
                 g_sMPU9150Inst.pui8Data, 2, MotionCallback, &g_sMPU9150Inst);

    //
    // Wait for transaction to complete
    //
    MotionI2CWait(__FILE__, __LINE__);

	//
	// Initialize the DCM system.
	//
	CompDCMInit(&g_sCompDCMInst, 1.0f / ((float) MOTION_SAMPLE_FREQ_HZ),
				DCM_ACCEL_WEIGHT, DCM_GYRO_WEIGHT, DCM_MAG_WEIGHT);

	//
	// Initialize the gesture instance and establish a initial state estimate.
	//
    GestureInit(&g_sGestureInst, g_pfInitProb, g_ppfPath, g_ppfTransitionProb,
                g_ppfEmitProb, GESTURE_PATH_LENGTH, GESTURE_NUM_STATES,
                GESTURE_STATE_IDLE);
}
//*****************************************************************************
//
// This is the main loop that runs the application.
//
//*****************************************************************************
int
main(void)
{
    unsigned long ulButton, ulPrevious, ulLastTickCount;
    tBoolean bLastSuspend;

    //
    // Set the clocking to run from the PLL at 50MHz.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // Enable USB pins
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_4 | GPIO_PIN_5);

    //
    // Enable the UART.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTStdioInit(0);
    UARTprintf("\033[2JKeyboard device application\n");

    //
    // Enable the GPIO that is used for the on-board push button.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    ROM_GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_4);
    ROM_GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA,
                         GPIO_PIN_TYPE_STD_WPU);

    //
    // Enable the GPIO that is used for the on-board LED.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1);
    ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0);


    //
    // Not configured initially.
    //
    g_bConnected = false;
    g_bSuspended = false;
    bLastSuspend = false;


    //
    // Set the USB stack mode to Device mode with VBUS monitoring.
    //
    USBStackModeSet(0, USB_MODE_DEVICE, 0);

    //
    // Pass our device information to the USB HID device class driver,
    // initialize the USB
    // controller and connect the device to the bus.
    //
    USBDHIDKeyboardInit(0, &g_sKeyboardDevice);

    //
    // Set the system tick to fire 100 times per second.
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND);
    ROM_SysTickIntEnable();
    ROM_SysTickEnable();

    //
    // The main loop starts here.  We begin by waiting for a host connection
    // then drop into the main keyboard handling section.  If the host
    // disconnects, we return to the top and wait for a new connection.
    //
    ulPrevious = 1;
    setup();
    while(1)
    {
        //
        // Tell the user what we are doing and provide some basic instructions.
        //
        UARTprintf("Waiting for host...\n");

        //
        // Wait for USB configuration to complete. 
        //
        while(!g_bConnected)
        {
        }

        //
        // Update the status.
        //
        UARTprintf("Host connected...\n");

        //
        // Enter the idle state.
        //
        g_eKeyboardState = STATE_IDLE;

        //
        // Assume that the bus is not currently suspended if we have just been
        // configured.
        //
        bLastSuspend = false;

        //
        // Keep transferring characters from the UART to the USB host for as
        // long as we are connected to the host.
        //
        while(g_bConnected)
        {
            //
            // Remember the current time.
            //
            ulLastTickCount = g_ulSysTickCount;

            //
            // Has the suspend state changed since last time we checked?
            //
            if(bLastSuspend != g_bSuspended)
            {
                //
                // Yes - the state changed so update the display.
                //
                bLastSuspend = g_bSuspended;
                UARTprintf(bLastSuspend ? "Bus suspended...\n" :
                           "Host connected...\n");
            }

            //
            // See if the button was just pressed.
            //
            ulButton = num;
            if(ulButton != ulPrevious)
            {
                //
                // If the bus is suspended then resume it.  Otherwise, type
                // some "random" characters.
                //
                if(g_bSuspended)
                {
                    //
                    // We are suspended so request a remote wakeup.
                    //
                    USBDHIDKeyboardRemoteWakeupRequest(
                                                   (void *)&g_sKeyboardDevice);
                }
                else
                {
                	char s[2] = {0x30+num,0};
                    SendString(s);
                }
            }
            ulPrevious = ulButton;

            //
            // Wait for at least 1 system tick to have gone by before we poll
            // the buttons again.
            //
            while(g_ulSysTickCount == ulLastTickCount)
            {
                //
                // Hang around doing nothing.
                //
            }
        }

        //
        // Dropping out of the previous loop indicates that the host has
        // disconnected so go back and wait for reconnection.
        //
        if(g_bConnected == false)
        {
            UARTprintf("Host disconnected...\n");
        }
    }
}
//*****************************************************************************
//
// This is the main loop that runs the application.
//
//*****************************************************************************
int
main(void)
{

	ROM_FPULazyStackingEnable();
    // Set the clocking to run from the PLL at 50MHz.
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

    // Configure USB pins
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_4 | GPIO_PIN_5);

    // Set the system tick to fire 100 times per second.
    ROM_SysTickEnable();
    ROM_SysTickIntEnable();
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND);

    // Initialize the on board buttons
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    // Right button is muxed so you need to unlock and configure
    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;
    ROM_GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_4 |GPIO_PIN_0);
    ROM_GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4 |GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);

    // Enable Output Status Light
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
    // Set initial LED Status to RED to indicate not connected
     ROM_GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 2);

    // Set the USB stack mode to Device mode with VBUS monitoring.
    USBStackModeSet(0, USB_MODE_DEVICE, 0);

    // Pass the USB library our device information, initialize the USB
    // controller and connect the device to the bus.
    USBDHIDCustomHidInit(0, (tUSBDHIDCustomHidDevice *)&g_sCustomHidDevice);

    // Drop into the main loop.
    while(1)
    {
        // Wait for USB configuration to complete.
        while(!g_bConnected)
        {
        	   ROM_GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 2);
        }

        // Update the status to green when connected.
        ROM_GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 8);

        // Now keep processing the customhid as long as the host is connected.
        while(g_bConnected)
        {
            // If it is time to check the buttons and send a customhid report then do so.
            if(HWREGBITW(&g_ulCommands, TICK_EVENT) == 1)
            {
               HWREGBITW(&g_ulCommands, TICK_EVENT) = 0;
               CustomHidChangeHandler();
            }
        }
    }
}
int main(void)
{
	// setup the system clock to run at 80 MHz from the external crystal:
	ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

	// enable peripherals to operate when CPU is in sleep:
	ROM_SysCtlPeripheralClockGating(true);

	// enable all of the GPIOs:
	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_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOA);
	ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOB);
	ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOC);
	ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOD);
	ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOE);
	ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOF);

	// setup pins connected to RGB LED:
	ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);

	//setup the UART console
	InitConsole();

// Test either the interrupts on a simple pushbutton to turn-on a led:
// 			1- interrupt with static allocation on the vector table
//			2- interrupt with dynamic allocation on the vector table

//			2- interrupt with dynamic allocation on the vector table

// setup pin connected to SW1 and SW2

	// 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;
	HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01;
	HWREG(GPIO_PORTF_BASE + GPIO_O_AFSEL) |= 0x000;
	HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0;

	//Configures pin(s) for use as GPIO inputs
    ROM_GPIOPinTypeGPIOInput(GPIO_PORTF_BASE,GPIO_PIN_4 | GPIO_PIN_0);
    //Sets the pad configuration for the specified pin(s).
    ROM_GPIOPadConfigSet(GPIO_PORTF_BASE,GPIO_PIN_4 | GPIO_PIN_0,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
    // Make PORT F pin 0,4 high level triggered interrupts.
    ROM_GPIOIntTypeSet(GPIO_PORTF_BASE,GPIO_PIN_4 | GPIO_PIN_0,GPIO_BOTH_EDGES);


    //dynamic allocation on the vector table of GPIO_PORTF_isr interrupt handler
    GPIOIntRegister(GPIO_PORTF_BASE, GPIO_PORTF_isr);

    //Enables the specified GPIO interrupt
    IntEnable(INT_GPIOF);
    GPIOIntEnable(GPIO_PORTF_BASE,GPIO_INT_PIN_4 | GPIO_INT_PIN_0);

    IntMasterEnable();

    uint8_t PORTF_status;

	//uint32_t ui32Loop = 0;

    //
    // Loop forever
    //
    while(1)
    {
    	uint8_t PORTF_status=GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_0 | GPIO_PIN_4);
    	/*
    	if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_4))
    	{
    		ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 ,0);
    	}
    	else
    	{
    		ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 , GPIO_PIN_1);
    	}
    	*/

    	/*
        //
        // Turn on the red LED .
        //
        ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 , GPIO_PIN_1);
        ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, GPIO_PIN_7);
        //
        // Delay for a bit.
        //
        for(ui32Loop = 0; ui32Loop < 2000000; ui32Loop++)
        {
        }

        //
        // Turn on the green LED.
        //
        ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 , GPIO_PIN_2);
        ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, 0);
        //
        // Delay for a bit.
        //
        for(ui32Loop = 0; ui32Loop < 2000000; ui32Loop++)
        {
        }

        //
        // Turn on the blue LED.
        //
        ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 , GPIO_PIN_3);
        //
        // Delay for a bit.
        //
        for(ui32Loop = 0; ui32Loop < 2000000; ui32Loop++)
        {
        }
        */
    }
}
void StellarisPortPin::setAsInput() {
	ROM_GPIOPinTypeGPIOInput(_portBase, _pin);
}
//*****************************************************************************
//
//! Configures the device pins for the standard usages on the EK-TM4C1294XL.
//!
//! \param bEthernet is a boolean used to determine function of Ethernet pins.
//! If true Ethernet pins are  configured as Ethernet LEDs.  If false GPIO are
//! available for application use.
//! \param bUSB is a boolean used to determine function of USB pins. If true USB
//! pins are configured for USB use.  If false then USB pins are available for
//! application use as GPIO.
//!
//! This function enables the GPIO modules and configures the device pins for
//! the default, standard usages on the EK-TM4C1294XL.  Applications that
//! require alternate configurations of the device pins can either not call
//! this function and take full responsibility for configuring all the device
//! pins, or can reconfigure the required device pins after calling this
//! function.
//!
//! \return None.
//
//*****************************************************************************
void
PinoutSet(bool bEthernet, bool bUSB)
{
    //
    // Enable all the GPIO peripherals.
    //
    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_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOQ);

    //
    // PA0-1 are used for UART0.
    //
    ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
    ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // PB0-1/PD6/PL6-7 are used for USB.
    // PQ4 can be used as a power fault detect on this board but it is not
    // the hardware peripheral power fault input pin.
    //
    if(bUSB)
    {
        HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
        HWREG(GPIO_PORTD_BASE + GPIO_O_CR) = 0xff;
        ROM_GPIOPinConfigure(GPIO_PD6_USB0EPEN);
        ROM_GPIOPinTypeUSBAnalog(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);
        ROM_GPIOPinTypeUSBDigital(GPIO_PORTD_BASE, GPIO_PIN_6);
        ROM_GPIOPinTypeUSBAnalog(GPIO_PORTL_BASE, GPIO_PIN_6 | GPIO_PIN_7);
        ROM_GPIOPinTypeGPIOInput(GPIO_PORTQ_BASE, GPIO_PIN_4);
    }
    else
    {
        //
        // Keep the default config for most pins used by USB.
        // Add a pull down to PD6 to turn off the TPS2052 switch
        //
        ROM_GPIOPinTypeGPIOInput(GPIO_PORTD_BASE, GPIO_PIN_6);
        MAP_GPIOPadConfigSet(GPIO_PORTD_BASE, GPIO_PIN_6, GPIO_STRENGTH_2MA,
                             GPIO_PIN_TYPE_STD_WPD);

    }

    //
    // PF0/PF4 are used for Ethernet LEDs.
    //
    if(bEthernet)
    {
        //
        // this app wants to configure for ethernet LED function.
        //
        ROM_GPIOPinConfigure(GPIO_PF0_EN0LED0);
        ROM_GPIOPinConfigure(GPIO_PF4_EN0LED1);

        GPIOPinTypeEthernetLED(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4);

    }
    else
    {

        //
        // This app does not want Ethernet LED function so configure as
        // standard outputs for LED driving.
        //
        ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4);

        //
        // Default the LEDs to OFF.
        //
        ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4, 0);
        MAP_GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4,
                             GPIO_STRENGTH_12MA, GPIO_PIN_TYPE_STD);


    }

    //
    // PJ0 and J1 are used for user buttons
    //
    ROM_GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    ROM_GPIOPinWrite(GPIO_PORTJ_BASE, GPIO_PIN_0 | GPIO_PIN_1, 0);

    //
    // PN0 and PN1 are used for USER LEDs.
    //
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    MAP_GPIOPadConfigSet(GPIO_PORTN_BASE, GPIO_PIN_0 | GPIO_PIN_1,
                             GPIO_STRENGTH_12MA, GPIO_PIN_TYPE_STD);

    //
    // Default the LEDs to OFF.
    //
    ROM_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0 | GPIO_PIN_1, 0);
}
//*****************************************************************************
//
// Play the Colossal Cave Adventure game using either an Ethernet telnet
// connection or a USB CDC serial connection.
//
//*****************************************************************************
int
main(void)
{
    //
    // Set the clocking to run from the PLL at 80 MHz.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // Enable the UART.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTStdioInit(0);

    //
    // Print out a greeting.
    //
    UARTprintf("\033[2JColossal Cave Adventure\n");
    UARTprintf("-----------------------\n");
    UARTprintf("Connect to either the USB virtual COM port or\n");
    UARTprintf("telnet into the Ethernet port in order to play.\n\n");

    //
    // Enable the GPIO that is used for the on-board push button.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    ROM_GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_4);
    ROM_GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA,
                         GPIO_PIN_TYPE_STD_WPU);

    //
    // Enable the GPIO that is used for the on-board LED.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_0);
    ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, 0);

    //
    // Configure SysTick for a periodic interrupt.
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKHZ);
    ROM_SysTickEnable();
    ROM_SysTickIntEnable();

    //
    // Enable processor interrupts.
    //
    ROM_IntMasterEnable();

    //
    // Initialize the Ethernet and USB interfaces.
    //
    EnetIFInit();
    USBIFInit();

    //
    // Provide a working area to the memory allocator.
    //
    bpool(g_pucPool, sizeof(g_pucPool));

    //
    // Configure the Z-machine interpreter.
    //
    configure(V1, V5);

    //
    // Initialize the Z-machine screen interface.
    //
    initialize_screen();

    //
    // Pre-fill the Z-machine interpreter's cache.
    //
    load_cache();

    //
    // Loop forever.
    //
    while(1)
    {
        //
        // Wait until a connection has been made via either the Ethernet or USB
        // interfaces.
        //
        while(g_ulGameIF == GAME_IF_NONE)
        {
        }

        //
        // Turn on the LED to indicate that the game is in progress.
        //
        ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, GPIO_PIN_0);

        //
        // Loop until the game has been exited.  Repeat this loop if the game
        // exited because the restart button was pressed.
        //
        do
        {
            //
            // Take the Z-machine interpreter out of the halt state.
            //
            halt = 0;

            //
            // Set the restart flag to zero.
            //
            g_ulRestart = 0;

            //
            // Restart the Z-machine interpreter.
            //
            restart();

            //
            // Run the Z-machine interpreter until it halts.
            //
            interpret();
        }
        while(g_ulRestart);

        //
        // Turn off the LED to indicate that the game has finished.
        //
        ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, 0);

        //
        // Close down the Ethernet connection if it was being used to play the
        // game.
        //
        if(g_ulGameIF == GAME_IF_ENET)
        {
            EnetIFClose();
        }

        //
        // Forget the interface used to play the game so that the selection
        // process will be repeated.
        //
        g_ulGameIF = GAME_IF_NONE;
    }
}