Esempio n. 1
0
//*****************************************************************************
//
//! Initializes the touch screen driver.
//!
//! \param ui32SysClock is the frequency of the system clock.
//!
//! This function initializes the touch screen driver, beginning the process of
//! reading from the touch screen.  This driver uses the following hardware
//! resources:
//!
//! - ADC 0 sample sequence 3
//! - Timer 5 subtimer B
//!
//! \return None.
//
//*****************************************************************************
void
TouchScreenInit(uint32_t ui32SysClock)
{
    //
    // Set the initial state of the touch screen driver's state machine.
    //
    g_ui32TSState = TS_STATE_INIT;

    //
    // There is no touch screen handler initially.
    //
    g_pfnTSHandler = 0;

    //
    // Enable the peripherals used by the touch screen interface.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER5);

    //
    // Configure the ADC sample sequence used to read the touch screen reading.
    //
    ROM_ADCHardwareOversampleConfigure(ADC0_BASE, 4);
    ROM_ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0);
    ROM_ADCSequenceStepConfigure(ADC0_BASE, 3, 0,
                                 TS_YP_ADC | ADC_CTL_END | ADC_CTL_IE);
    ROM_ADCSequenceEnable(ADC0_BASE, 3);

    //
    // Enable the ADC sample sequence interrupt.
    //
    ROM_ADCIntEnable(ADC0_BASE, 3);
    ROM_IntEnable(INT_ADC0SS3);

    //
    // Configure the timer to trigger the sampling of the touch screen
    // every 2.5 milliseconds.
    //
    if((HWREG(TIMER5_BASE + TIMER_O_CTL) & TIMER_CTL_TAEN) == 0) {
        ROM_TimerConfigure(TIMER5_BASE, (TIMER_CFG_SPLIT_PAIR |
                                         TIMER_CFG_A_PWM |
                                         TIMER_CFG_B_PERIODIC));
    }
    ROM_TimerPrescaleSet(TIMER5_BASE, TIMER_B, 255);
    ROM_TimerLoadSet(TIMER5_BASE, TIMER_B, ((ui32SysClock / 256) / 400) - 1);
    TimerControlTrigger(TIMER5_BASE, TIMER_B, true);

    //
    // Enable the timer.  At this point, the touch screen state machine will
    // sample and run every 2.5 ms.
    //
    ROM_TimerEnable(TIMER5_BASE, TIMER_B);
}
Esempio n. 2
0
void BattSense_init(void)
{
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC1);
	ROM_GPIOPinTypeADC(GPIO_PORTB_BASE, GPIO_PIN_4);
	ROM_ADCHardwareOversampleConfigure(ADC1_BASE, 64);

	ROM_ADCSequenceConfigure(ADC1_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
	ROM_ADCSequenceStepConfigure(ADC1_BASE, 3, 0, ADC_CTL_END | ADC_CTL_CH10 | ADC_CTL_IE);
	ROM_ADCSequenceEnable(ADC1_BASE, 3);
 	ADCIntRegister(ADC1_BASE, 3, &BattSenseISR);
 	ROM_ADCIntEnable(ADC1_BASE, 3);

 	battery_Runtimeout(&BattSenseTimerTimout, 10000);
}
Esempio n. 3
0
rt_uint8_t battery_adc_initialize(void)
{
	
	ROM_SysCtlADCSpeedSet(SYSCTL_ADCSPEED_1MSPS);
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
	
	
	ROM_ADCHardwareOversampleConfigure(ADC0_BASE,64);
	ROM_GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2);
	
	ADCSequenceConfigure(ADC0_BASE, 3,ADC_TRIGGER_PROCESSOR, 0);
	ROM_ADCSequenceStepConfigure(ADC0_BASE,3, 0, ADC_CTL_CH1| ADC_CTL_IE |ADC_CTL_END);
	
	ROM_ADCSequenceEnable(ADC0_BASE, 3);
	rt_kprintf("battery_adc_initialize\n");
	return 0;
}
Esempio n. 4
0
void
configureADC()
{

    //
    // Setup ADC Using ROM functions
    //
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); //Enable ADC0
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); //Enable GPIO E
	ROM_ADCHardwareOversampleConfigure(ADC0_BASE, 64); //Configure hardware oversampling to sample 64 times and average
	HWREG(ADC0_BASE + ADC_O_PC) = ADC_PC_SR_125K; //Set ADC speed to 125K

	ROM_GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3); //Enable ADC on PE3
	ROM_ADCSequenceDisable(ADC0_BASE, 3); //Disable sequence before configuring it
	ROM_ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0); //Use sequencer 3 to trigger at all times with a priority of 0 (highest)
	ROM_ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END); //Enable sampling using sequencer 3 on CH0 (PE3)

	ROM_ADCSequenceEnable(ADC0_BASE, 3); //Enable the sequencer
}
Esempio n. 5
0
void IRDetector_init(void)
{
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
	ROM_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
	ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, 0x00);

	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
	ROM_GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
	ROM_ADCHardwareOversampleConfigure(ADC0_BASE, 32);

	ROM_ADCSequenceConfigure(ADC0_BASE, 2, ADC_TRIGGER_PROCESSOR, 0);
	ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_END | ADC_CTL_CH0 | ADC_CTL_IE);	//PE3, enable interrupt

	ROM_ADCSequenceEnable(ADC0_BASE, 2);
 	ADCIntRegister(ADC0_BASE, 2, &IR_Detector_ISR);
 	ROM_ADCIntEnable(ADC0_BASE, 2);


 	ADC_Step = 0;
 	TURN_ON_IRD1();
 	ir_Runtimeout(&IR_Timer_Timeout, 1);
}
Esempio n. 6
0
//*****************************************************************************
//
//! Initializes the touch screen driver.
//!
//! This function initializes the touch screen driver, beginning the process of
//! reading from the touch screen.  This driver uses the following hardware
//! resources:
//!
//! - ADC sample sequence 3
//! - Timer 1 subtimer A
//!
//! \return None.
//
//*****************************************************************************
void
TouchScreenInit(void)
{
    //
    // Set the initial state of the touch screen driver's state machine.
    //
    g_ulTSState = TS_STATE_INIT;

    //
    // Determine which calibration parameter set we will be using.
    //
    g_plParmSet = g_lTouchParameters[SET_NORMAL];
    if(g_eDaughterType == DAUGHTER_SRAM_FLASH)
    {
        //
        // If the SRAM/Flash daughter board is present, select the appropriate
        // calibration parameters and reading threshold value.
        //
        g_plParmSet = g_lTouchParameters[SET_SRAM_FLASH];
        g_sTouchMin = 40;
    }
    else if(g_eDaughterType == DAUGHTER_FPGA)
    {
        //
        // If the FPGA daughter board is present, select the appropriate
        // calibration parameters and reading threshold value.
        //
        g_plParmSet = g_lTouchParameters[SET_FPGA];
        g_sTouchMin = 70;
    }

    //
    // There is no touch screen handler initially.
    //
    g_pfnTSHandler = 0;

    //
    // Enable the peripherals used by the touch screen interface.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    ROM_SysCtlPeripheralEnable(TS_P_PERIPH);
    ROM_SysCtlPeripheralEnable(TS_N_PERIPH);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);

    //
    // Configure the ADC sample sequence used to read the touch screen reading.
    //
    ROM_ADCHardwareOversampleConfigure(ADC0_BASE, 4);
    ROM_ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0);
    ROM_ADCSequenceStepConfigure(ADC0_BASE, 3, 0,
                             ADC_CTL_CH_YP | ADC_CTL_END | ADC_CTL_IE);
    ROM_ADCSequenceEnable(ADC0_BASE, 3);

    //
    // Enable the ADC sample sequence interrupt.
    //
    ROM_ADCIntEnable(ADC0_BASE, 3);
    ROM_IntEnable(INT_ADC0SS3);

    //
    // Configure the GPIOs used to drive the touch screen layers.
    //
    ROM_GPIOPinTypeGPIOOutput(TS_P_BASE, TS_XP_PIN | TS_YP_PIN);

    //
    // If no daughter board or one which does not rewire the touchscreen
    // interface is installed, set up GPIOs to drive the XN and YN signals.
    //
    if((g_eDaughterType != DAUGHTER_SRAM_FLASH) &&
       (g_eDaughterType != DAUGHTER_FPGA))
    {
        ROM_GPIOPinTypeGPIOOutput(TS_N_BASE, TS_XN_PIN | TS_YN_PIN);
    }

    ROM_GPIOPinWrite(TS_P_BASE, TS_XP_PIN | TS_YP_PIN, 0x00);

    if(g_eDaughterType == DAUGHTER_SRAM_FLASH)
    {
        HWREGB(LCD_CONTROL_CLR_REG) = LCD_CONTROL_XN | LCD_CONTROL_YN;
    }
    else if(g_eDaughterType == DAUGHTER_FPGA)
    {
        HWREGH(LCD_FPGA_CONTROL_CLR_REG) = LCD_CONTROL_XN | LCD_CONTROL_YN;
    }
    else
    {
        ROM_GPIOPinWrite(TS_N_BASE, TS_XN_PIN | TS_YN_PIN, 0x00);
    }

    //
    // See if the ADC trigger timer has been configured, and configure it only
    // if it has not been configured yet.
    //
    if((HWREG(TIMER1_BASE + TIMER_O_CTL) & TIMER_CTL_TAEN) == 0)
    {
        //
        // Configure the timer to trigger the sampling of the touch screen
        // every millisecond.
        //
        ROM_TimerConfigure(TIMER1_BASE, (TIMER_CFG_SPLIT_PAIR |
                           TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC));
        ROM_TimerLoadSet(TIMER1_BASE, TIMER_A,
                         (ROM_SysCtlClockGet() / 1000) - 1);
        ROM_TimerControlTrigger(TIMER1_BASE, TIMER_A, true);

        //
        // Enable the timer.  At this point, the touch screen state machine
        // will sample and run once per millisecond.
        //
        ROM_TimerEnable(TIMER1_BASE, TIMER_A);
    }
}
Esempio n. 7
0
int main(void)
{
	uint32_t ui32ADC0Value[4];
	volatile uint32_t ui32TempAvg;
	volatile uint32_t ui32TempValueC;
	volatile uint32_t ui32TempValueF;


	ROM_SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
	ROM_ADCHardwareOversampleConfigure(ADC0_BASE, 64);
	ROM_ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
	ROM_ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS);
	ROM_ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS);
	ROM_ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS);
	ROM_ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END);
	ROM_ADCSequenceEnable(ADC0_BASE, 1);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
	ROM_ADCHardwareOversampleConfigure(ADC0_BASE, 64);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
	GPIOPinConfigure(GPIO_PA0_U0RX);
	GPIOPinConfigure(GPIO_PA1_U0TX);
	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);

	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);

	UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));


	IntMasterEnable();
	IntEnable(INT_UART0);
	UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);

	while(1)
	{
		if(mode == 0)
		{
			ROM_ADCIntClear(ADC0_BASE, 1);
			ROM_ADCProcessorTrigger(ADC0_BASE, 1);
			while(!ROM_ADCIntStatus(ADC0_BASE, 1, false))
			{
			}
			ROM_ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value);
			ui32TempAvg = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2] + ui32ADC0Value[3] + 2)/4;
			ui32TempValueC = (1475 - ((2475 * ui32TempAvg)) / 4096)/10;
			ui32TempValueF = ((ui32TempValueC * 9) + 160) / 5;

			UARTStrPut("Current Temperature ");
			UARTIntPut(ui32TempValueC);
			UARTCharPut(UART0_BASE, 176);

			UARTStrPut("C, Set Temperature ");
			UARTIntPut(setTemp);
			UARTCharPut(UART0_BASE, 176);
			UARTStrPut("C\r\n");

			int temp;
			if (setTemp < ui32TempValueC) temp = 2; // red
			else if (setTemp > ui32TempValueC) temp = 8; // green
			else temp = 4; // blue if equal
			GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, temp);
			SysCtlDelay(SysCtlClockGet()/3);
		}
	}
}
Esempio n. 8
0
//*****************************************************************************
//
//! Initializes the touch screen driver.
//!
//! This function initializes the touch screen driver, beginning the process of
//! reading from the touch screen.  This driver uses the following hardware
//! resources:
//!
//! - ADC sample sequence 3
//! - Timer 1 subtimer A
//!
//! \return None.
//
//*****************************************************************************
void
TouchScreenInit(void)
{
    //
    // Set the initial state of the touch screen driver's state machine.
    //
    g_ulTSState = TS_STATE_INIT;

    //
    // There is no touch screen handler initially.
    //
    g_pfnTSHandler = 0;

    //
    // Enable the peripherals used by the touch screen interface.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    ROM_SysCtlPeripheralEnable(TS_P_PERIPH);
    ROM_SysCtlPeripheralEnable(TS_N_PERIPH);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);

    //
    // Configure the ADC sample sequence used to read the touch screen reading.
    //
    ROM_ADCHardwareOversampleConfigure(ADC0_BASE, 4);
    ROM_ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0);
    ROM_ADCSequenceStepConfigure(ADC0_BASE, 3, 0,
                                 ADC_CTL_CH_YP | ADC_CTL_END | ADC_CTL_IE);
    ROM_ADCSequenceEnable(ADC0_BASE, 3);

    //
    // Enable the ADC sample sequence interrupt.
    //
    ROM_ADCIntEnable(ADC0_BASE, 3);
    ROM_IntEnable(INT_ADC0SS3);

    //
    // Configure the GPIOs used to drive the touch screen layers.
    //
    ROM_GPIOPinTypeGPIOOutput(TS_P_BASE, TS_XP_PIN | TS_YP_PIN);
    ROM_GPIOPinTypeGPIOOutput(TS_N_BASE, TS_XN_PIN | TS_YN_PIN);
    ROM_GPIOPinWrite(TS_P_BASE, TS_XP_PIN | TS_YP_PIN, 0x00);
    ROM_GPIOPinWrite(TS_N_BASE, TS_XN_PIN | TS_YN_PIN, 0x00);

    //
    // See if the ADC trigger timer has been configured, and configure it only
    // if it has not been configured yet.
    //
    if((HWREG(TIMER1_BASE + TIMER_O_CTL) & TIMER_CTL_TAEN) == 0)
    {
        //
        // Configure the timer to trigger the sampling of the touch screen
        // every millisecond.
        //
        ROM_TimerConfigure(TIMER1_BASE, (TIMER_CFG_SPLIT_PAIR |
                           TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC));
        ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, (SysCtlClockGet() / 1000) - 1);
        ROM_TimerControlTrigger(TIMER1_BASE, TIMER_A, true);

        //
        // Enable the timer.  At this point, the touch screen state machine
        // will sample and run once per millisecond.
        //
        ROM_TimerEnable(TIMER1_BASE, TIMER_A);
    }
}