Ejemplo n.º 1
0
void App_Button_Init(void)
{
	ButtonWaiting = 0;

	//Initialize the timer for the debouncing, but don't start it
	Chip_TIMER_Init(DEBOUNCE_TIMER);
	Chip_TIMER_Reset(DEBOUNCE_TIMER);

	DEBOUNCE_TIMER->PR = 100;
	DEBOUNCE_TIMER->MCR = (1<<1)|(1<<0);		//Enable MR0 match interrupt, Reset TC on MR0 match
	DEBOUNCE_TIMER->MR[0]= 0xFFFF;				//MR0 match value

	//Enable the IRQ for the timer
	NVIC_EnableIRQ(DEBOUNCE_TIMER_NVIC_NAME);

	//Set all button pins to GPIO input with pullup
	Chip_IOCON_PinMuxSet(LPC_IOCON, BUTTON_1_PORT, BUTTON_1_PIN, (IOCON_FUNC0 | IOCON_MODE_PULLUP));
	Chip_IOCON_PinMuxSet(LPC_IOCON, BUTTON_2_PORT, BUTTON_2_PIN, (IOCON_FUNC0 | IOCON_MODE_PULLUP));
	Chip_IOCON_PinMuxSet(LPC_IOCON, BUTTON_3_PORT, BUTTON_3_PIN, (IOCON_FUNC0 | IOCON_MODE_PULLUP));
	Chip_IOCON_PinMuxSet(LPC_IOCON, BUTTON_4_PORT, BUTTON_4_PIN, (IOCON_FUNC0 | IOCON_MODE_PULLUP));
	Chip_IOCON_PinMuxSet(LPC_IOCON, BUTTON_5_PORT, BUTTON_5_PIN, (IOCON_FUNC0 | IOCON_MODE_PULLUP));

	Chip_GPIO_SetPinDIRInput(LPC_GPIO, BUTTON_1_PORT, BUTTON_1_PIN);
	Chip_GPIO_SetPinDIRInput(LPC_GPIO, BUTTON_2_PORT, BUTTON_2_PIN);
	Chip_GPIO_SetPinDIRInput(LPC_GPIO, BUTTON_3_PORT, BUTTON_3_PIN);
	Chip_GPIO_SetPinDIRInput(LPC_GPIO, BUTTON_4_PORT, BUTTON_4_PIN);
	Chip_GPIO_SetPinDIRInput(LPC_GPIO, BUTTON_5_PORT, BUTTON_5_PIN);


	//TODO: Probably put this in the main initalization...
	Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_PINT);

	//Setup GPIO interrupts for each button

	/* Configure interrupt channel for the GPIO pin in SysCon block */
	Chip_SYSCTL_SetPinInterrupt(BUTTON_1_PININT_INDEX, BUTTON_1_PORT, BUTTON_1_PIN);
	Chip_SYSCTL_SetPinInterrupt(BUTTON_2_PININT_INDEX, BUTTON_2_PORT, BUTTON_2_PIN);
	Chip_SYSCTL_SetPinInterrupt(BUTTON_3_PININT_INDEX, BUTTON_3_PORT, BUTTON_3_PIN);
	Chip_SYSCTL_SetPinInterrupt(BUTTON_4_PININT_INDEX, BUTTON_4_PORT, BUTTON_4_PIN);
	Chip_SYSCTL_SetPinInterrupt(BUTTON_5_PININT_INDEX, BUTTON_5_PORT, BUTTON_5_PIN);

	/* Configure channel interrupt as edge sensitive and falling edge interrupt */
	Chip_PININT_SetPinModeEdge(LPC_PININT, PININTCH(BUTTON_1_PININT_INDEX));
	Chip_PININT_SetPinModeEdge(LPC_PININT, PININTCH(BUTTON_2_PININT_INDEX));
	Chip_PININT_SetPinModeEdge(LPC_PININT, PININTCH(BUTTON_3_PININT_INDEX));
	Chip_PININT_SetPinModeEdge(LPC_PININT, PININTCH(BUTTON_4_PININT_INDEX));
	Chip_PININT_SetPinModeEdge(LPC_PININT, PININTCH(BUTTON_5_PININT_INDEX));
	Chip_PININT_EnableIntLow(LPC_PININT, PININTCH(BUTTON_1_PININT_INDEX));
	Chip_PININT_EnableIntLow(LPC_PININT, PININTCH(BUTTON_2_PININT_INDEX));
	Chip_PININT_EnableIntLow(LPC_PININT, PININTCH(BUTTON_3_PININT_INDEX));
	Chip_PININT_EnableIntLow(LPC_PININT, PININTCH(BUTTON_4_PININT_INDEX));
	Chip_PININT_EnableIntLow(LPC_PININT, PININTCH(BUTTON_5_PININT_INDEX));

	Chip_PININT_ClearIntStatus(LPC_PININT, ((1 << BUTTON_1_PININT_INDEX)|(1<<BUTTON_2_PININT_INDEX)|(1<<BUTTON_3_PININT_INDEX)|(1<<BUTTON_4_PININT_INDEX)|(1<<BUTTON_5_PININT_INDEX)) );

	App_EnableButtons();

	return;
}
Ejemplo n.º 2
0
uint32_t PWMSetPeriod(uint8_t channel, uint32_t period) {
	if (channel > CHANNEL_C_TIMER_INDEX) {
		return 1;
	}
	if (eDVSMode != EDVS_MODE_INTERNAL && channel == 0) {
		return 1; // channel 0 taken for master/slave mode
	}
	LPC_TIMER_T * timer = halTimers[channel].timer;
	halTimers[channel].period = period;
	/**
	 * If the period equal 0, the timer is disable and its outputs are set as GPIO and driven low.
	 */
	if (period == 0) {
		Chip_TIMER_DeInit(timer); //Stop the timer
		Chip_TIMER_SetMatch(timer, 2, 0);
		halTimers[channel].enabled[0] = DISABLE;
		halTimers[channel].enabled[1] = DISABLE;
		Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, halTimers[channel].portGpio[0], halTimers[channel].pinGpio[0]);
		Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, halTimers[channel].portGpio[1], halTimers[channel].pinGpio[1]);
		Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, halTimers[channel].portGpio[0], halTimers[channel].pinGpio[0]);
		Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, halTimers[channel].portGpio[1], halTimers[channel].pinGpio[1]);
		Chip_SCU_PinMuxSet(halTimers[channel].port[0], halTimers[channel].pin[0], halTimers[channel].gpioMode[0]);
		Chip_SCU_PinMuxSet(halTimers[channel].port[1], halTimers[channel].pin[1], halTimers[channel].gpioMode[1]);
	} else {
		/**
		 * The channel match 2 is used as the controller of the base frequency.
		 * When there is a match on this channel, the timer is reset and the external match bit
		 * is set to 1.
		 * The M0 core is looking for this change and it sets the output of the channels to high.
		 */
		Chip_TIMER_Init(timer);
		Chip_TIMER_Disable(timer);
		Chip_TIMER_Reset(timer);
		/**
		 * The Main clock is running at 192Mhz so set the Prescaler in order to have
		 * a 1 Mhz timer. Timer_CLK = Main_CLK/ (PR+1)
		 */
		Chip_TIMER_PrescaleSet(timer, 191);
		Chip_TIMER_ResetOnMatchEnable(timer, 2);
		Chip_TIMER_StopOnMatchDisable(timer, 2);
		Chip_TIMER_MatchDisableInt(timer, 2);
		Chip_TIMER_SetMatch(timer, 2, period);
		//Reconfigure match channels!
		if (halTimers[channel].enabled[0]) {
			PWMSetWidth(channel, 0, halTimers[channel].witdh[0]);
		}
		if (halTimers[channel].enabled[1]) {
			PWMSetWidth(channel, 1, halTimers[channel].witdh[1]);
		}
		Chip_TIMER_ExtMatchControlSet(timer, 0, TIMER_EXTMATCH_SET, 2);
		// Clear interrupt pending
		timer->IR = 0xFFFFFFFF;
		Chip_TIMER_Enable(timer);
	}
	return 0;
}
Ejemplo n.º 3
0
int main(void) {
	Dice noppa;
	uint32_t sysTickRate;

#if defined (__USE_LPCOPEN)
    // Read clock settings and update SystemCoreClock variable
    SystemCoreClockUpdate();
#if !defined(NO_BOARD_LIB)
    // Set up and initialize all required blocks and
    // functions related to the board hardware
    Board_Init();
    // Set the LED to the state of "On"
    Board_LED_Set(0, true);


#endif
#endif

	sysTickRate = Chip_Clock_GetSysTickClockRate();


	// Määritellään nappi PB1 toimimaan inputtina
	Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 0, (IOCON_MODE_PULLUP | IOCON_DIGMODE_EN | IOCON_INV_EN));
	Chip_GPIO_SetPinDIRInput(LPC_GPIO, 1, 0);

	// Määritellään nappi PC0 toimimaan inputtina
	Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 8, (IOCON_MODE_PULLUP | IOCON_DIGMODE_EN | IOCON_INV_EN));
	Chip_GPIO_SetPinDIRInput(LPC_GPIO, 0, 8);

	/* Enable and setup SysTick Timer at a periodic rate */
	SysTick_Config(sysTickRate / TICKRATE_HZ1);

	noppa.SetValue(0);

	while(1) {

		if (Chip_GPIO_GetPinState(LPC_GPIO, 1,0)) {
			noppa.SetValue(0);
			while(Chip_GPIO_GetPinState(LPC_GPIO, 1,0)) {
    		}

	   		if(!Chip_GPIO_GetPinState(LPC_GPIO, 1,0)) {
	   			noppa.SetValue(calc);
	    	}
		}

   		// Testinappi, kaikki ledit syttyy
   		if (Chip_GPIO_GetPinState(LPC_GPIO, 0,8)) {
   			while(Chip_GPIO_GetPinState(LPC_GPIO, 0,8)) {
   				noppa.SetValue(7);
   			}
   			noppa.SetValue(0);
   		}
    }
   	return 0;
}
Ejemplo n.º 4
0
/**
 * @brief GPIO initialization.
 */
void gpioInit(void) {
    //Chip_GPIO_Init(LPC_GPIO_PORT);
	Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, LCD_BACKLIGHT);
	Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, LCD_BACKLIGHT, 1);

	Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, RANGE_POWER_PIN);
	Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, RANGE_POWER_PIN, 0);

	Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, MoonLander_LED);
	Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, MoonLander_LED, 0);

	Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, 0, SW_LEFT);
	Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, 0, SW_RIGHT);
}
Ejemplo n.º 5
0
/* Initialize buttons on the board */
void Board_Buttons_Init(void)
{
	//enable pull-ups
	Chip_IOCON_PinMuxSet(LPC_IOCON, BUTTONS_ENCA_GPIO_PORT_NUM, BUTTONS_ENCA_GPIO_BIT_NUM,
					(IOCON_FUNC0 | IOCON_MODE_PULLUP | IOCON_DIGMODE_EN));
	Chip_IOCON_PinMuxSet(LPC_IOCON, BUTTONS_ENCB_GPIO_PORT_NUM, BUTTONS_ENCB_GPIO_BIT_NUM,
					(IOCON_FUNC0 | IOCON_MODE_PULLUP | IOCON_DIGMODE_EN));
	Chip_IOCON_PinMuxSet(LPC_IOCON, BUTTONS_ENCC_GPIO_PORT_NUM, BUTTONS_ENCC_GPIO_BIT_NUM,
				(IOCON_FUNC0 | IOCON_MODE_PULLUP | IOCON_DIGMODE_EN));

	//set as input pins
	Chip_GPIO_SetPinDIRInput(LPC_GPIO, BUTTONS_ENCA_GPIO_PORT_NUM, BUTTONS_ENCA_GPIO_BIT_NUM);
	Chip_GPIO_SetPinDIRInput(LPC_GPIO, BUTTONS_ENCB_GPIO_PORT_NUM, BUTTONS_ENCB_GPIO_BIT_NUM);
	Chip_GPIO_SetPinDIRInput(LPC_GPIO, BUTTONS_ENCC_GPIO_PORT_NUM, BUTTONS_ENCC_GPIO_BIT_NUM);
}
Ejemplo n.º 6
0
static void ADC_PinMuxSetup(void)
{
#if defined(BOARD_NXP_LPCXPRESSO_54102)
	/* Enable PININT1, which will trigger SEQ_B */
	Chip_PININT_Init(LPC_PININT);
	Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 24, IOCON_MODE_INACT | IOCON_FUNC0 | IOCON_DIGITAL_EN | IOCON_GPIO_MODE);
	Chip_GPIO_SetPinDIRInput(LPC_GPIO, 0, 24);
	LPC_INMUX->PINTSEL[PININTSELECT1] = 24;
	Chip_PININT_ClearIntStatus(LPC_PININT, PININTCH(PININTSELECT1));
	Chip_PININT_SetPinModeEdge(LPC_PININT, PININTCH(PININTSELECT1));
	Chip_PININT_EnableIntLow(LPC_PININT, PININTCH(PININTSELECT1));
	NVIC_ClearPendingIRQ(PIN_INT1_IRQn);
	NVIC_EnableIRQ(PIN_INT1_IRQn);

	/* All pins to inactive, neither pull-up nor pull-down. */
	Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 29, IOCON_MODE_INACT | IOCON_FUNC1 | IOCON_ANALOG_EN);
	Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 30, IOCON_MODE_INACT | IOCON_FUNC1 | IOCON_ANALOG_EN);
	Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 31, IOCON_MODE_INACT | IOCON_FUNC1 | IOCON_ANALOG_EN);
	Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 0, IOCON_MODE_INACT | IOCON_FUNC1 | IOCON_ANALOG_EN);
	Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 1, IOCON_MODE_INACT | IOCON_FUNC1 | IOCON_ANALOG_EN);
	Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 2, IOCON_MODE_INACT | IOCON_FUNC1 | IOCON_ANALOG_EN);
	Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 3, IOCON_MODE_INACT | IOCON_FUNC1 | IOCON_ANALOG_EN);
	Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 4, IOCON_MODE_INACT | IOCON_FUNC1 | IOCON_ANALOG_EN);
	Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 5, IOCON_MODE_INACT | IOCON_FUNC1 | IOCON_ANALOG_EN);
	Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 6, IOCON_MODE_INACT | IOCON_FUNC1 | IOCON_ANALOG_EN);
	Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 7, IOCON_MODE_INACT | IOCON_FUNC1 | IOCON_ANALOG_EN);
	Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 8, IOCON_MODE_INACT | IOCON_FUNC1 | IOCON_ANALOG_EN);

#else
#warning "No ADC setup for this example"
#endif
}
Ejemplo n.º 7
0
void Board_GPIOs_configure(int32_t gpioNumber,int32_t mode, int32_t pullup)
{
	int32_t pullUpMode=SCU_MODE_INACT;
	switch(pullup)
	{
		case BOARD_GPIO_NOPULL:
			pullUpMode=SCU_MODE_INACT;
			break;
		case BOARD_GPIO_PULLUP:
			pullUpMode=SCU_MODE_PULLUP;
			break;
		case BOARD_GPIO_PULLDOWN:
			pullUpMode=SCU_MODE_PULLDOWN;
			break;
	}
	Chip_SCU_PinMuxSet(gpiosInfo[gpioNumber].port, gpiosInfo[gpioNumber].portBit, (pullUpMode | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | gpiosInfo[gpioNumber].func));

        switch(mode)
        {
                case BOARD_GPIO_MODE_INPUT:
                        Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, gpiosInfo[gpioNumber].gpio, gpiosInfo[gpioNumber].gpioBit);   // Input
                        break;
                case BOARD_GPIO_MODE_OUTPUT_PP:
                        Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, gpiosInfo[gpioNumber].gpio, gpiosInfo[gpioNumber].gpioBit); // Output
                        break;
                case BOARD_GPIO_MODE_OUTPUT_OD:
                        Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, gpiosInfo[gpioNumber].gpio, gpiosInfo[gpioNumber].gpioBit); // Output
                        break;
        }
}
Ejemplo n.º 8
0
/**
 * @brief	Main program body
 * @return	Does not return
 */
int main(void)
{
	/* Generic Initialization */
	SystemCoreClockUpdate();

	/* Board_Init calls Chip_GPIO_Init and enables GPIO clock if needed,
	   Chip_GPIO_Init is not called again */
	Board_Init();
	Board_LED_Set(0, false);

	/* Configure GPIO interrupt pin as input */
	Chip_GPIO_SetPinDIRInput(LPC_GPIO, GPIO_INTERRUPT_PORT, GPIO_INTERRUPT_PIN);

	/* Configure the GPIO interrupt */
	Chip_GPIOINT_SetIntFalling(LPC_GPIOINT, GPIO_INTERRUPT_PORT, 1 << GPIO_INTERRUPT_PIN);

	/* Enable interrupt in the NVIC */
	NVIC_ClearPendingIRQ(GPIO_INTERRUPT_NVIC_NAME);
	NVIC_EnableIRQ(GPIO_INTERRUPT_NVIC_NAME);

	/* Wait for interrupts - LED will toggle on each wakeup event */
	while (1) {
		__WFI();
	}

	return 0;
}
Ejemplo n.º 9
0
/* NXP_Quick_Jack io initilize detect the mic&gnd */
void QUICKJACK_IO_Init(void)
{
	uint32_t MgAcmpOutVal;
	uint32_t i = 0;

	Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, MnGSWENAPINNUM);
	Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, MnGSWENAPINNUM, 1);

	Chip_IOCON_PinSetMode(LPC_IOCON, IOCON_PIO14, PIN_MODE_INACTIVE);
	Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, 0, 14);
	
	Chip_IOCON_PinSetMode(LPC_IOCON, MnGACMPOUTPIN, PIN_MODE_INACTIVE);
	Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, 0, MnGACMPOUTPINNUM);
	
	MgAcmpOutVal = Chip_GPIO_ReadPortBit(LPC_GPIO_PORT, 0, 6);
	
	for(i=0; i<5; i++) {																									/* waiting a while */
		__NOP();
	}
	
	while(MgAcmpOutVal!= Chip_GPIO_ReadPortBit(LPC_GPIO_PORT, 0, 6)) {
		for(i=0; i<5; i++) {																									/* waiting a while */
			__NOP();
		}
		MgAcmpOutVal = Chip_GPIO_ReadPortBit(LPC_GPIO_PORT, 0, 6);
		for(i=0; i<5; i++) {																									/* waiting a while */
			__NOP();
		}
	}
	
	/* configured analog switch selectable pin */
	Chip_IOCON_PinSetMode(LPC_IOCON, MnGSWSELPIN, PIN_MODE_INACTIVE);
	Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, MnGSWSELPINNUM);

	if(MgAcmpOutVal==0) {
		Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, MnGSWSELPINNUM, 1);
	}
	else {
		Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, MnGSWSELPINNUM, 0);
	}

	/* enabled analog switch enabled pin */
	Chip_IOCON_PinSetMode(LPC_IOCON, MnGSWENAPIN, PIN_MODE_INACTIVE);
	Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, MnGSWENAPINNUM);
	Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, MnGSWENAPINNUM, 0);
}
Ejemplo n.º 10
0
void Board_Buttons_Init(void)
{
	 buttonsData[0].callbackSw=NULL;
	 buttonsData[1].callbackSw=NULL;
	 buttonsData[2].callbackSw=NULL;
	 buttonsData[3].callbackSw=NULL;

	Chip_SCU_PinMuxSet(0x1, 0, (SCU_MODE_PULLUP | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC0));		// P1_0 as GPIO0[4]
	Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, BUTTONS_BUTTON1_GPIO_PORT_NUM, BUTTONS_BUTTON1_GPIO_BIT_NUM);	// input
	Chip_SCU_GPIOIntPinSel(0, 0, 4); // GPIO0[4] to INT0
	Chip_PININT_ClearIntStatus(LPC_GPIO_PIN_INT, PININTCH(0)); // INT0
        Chip_PININT_SetPinModeEdge(LPC_GPIO_PIN_INT, PININTCH(0)); // INT0
        Chip_PININT_EnableIntLow(LPC_GPIO_PIN_INT, PININTCH(0));   // INT0
	NVIC_ClearPendingIRQ(PIN_INT0_IRQn);
        NVIC_EnableIRQ(PIN_INT0_IRQn);


        Chip_SCU_PinMuxSet(0x1, 1, (SCU_MODE_PULLUP | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC0));         // P1_1 as GPIO0[8]
        Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, BUTTONS_BUTTON2_GPIO_PORT_NUM, BUTTONS_BUTTON2_GPIO_BIT_NUM);   // input
	Chip_SCU_GPIOIntPinSel(1, 0, 8); // GPIO0[8] to INT1
	Chip_PININT_ClearIntStatus(LPC_GPIO_PIN_INT, PININTCH(1)); // INT1
        Chip_PININT_SetPinModeEdge(LPC_GPIO_PIN_INT, PININTCH(1)); // INT1
        Chip_PININT_EnableIntLow(LPC_GPIO_PIN_INT, PININTCH(1));   // INT1
	NVIC_ClearPendingIRQ(PIN_INT1_IRQn);
        NVIC_EnableIRQ(PIN_INT1_IRQn);


        Chip_SCU_PinMuxSet(0x1, 2, (SCU_MODE_PULLUP | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC0));         // P1_2 as GPIO0[9]
        Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, BUTTONS_BUTTON3_GPIO_PORT_NUM, BUTTONS_BUTTON3_GPIO_BIT_NUM);   // input
	Chip_SCU_GPIOIntPinSel(2, 0, 9); // GPIO0[9] to INT2
	Chip_PININT_ClearIntStatus(LPC_GPIO_PIN_INT, PININTCH(2)); // INT2
        Chip_PININT_SetPinModeEdge(LPC_GPIO_PIN_INT, PININTCH(2)); // INT2
        Chip_PININT_EnableIntLow(LPC_GPIO_PIN_INT, PININTCH(2));   // INT2
        NVIC_ClearPendingIRQ(PIN_INT2_IRQn);
        NVIC_EnableIRQ(PIN_INT2_IRQn);


        Chip_SCU_PinMuxSet(0x1, 6, (SCU_MODE_PULLUP | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC0));         // P1_6 as GPIO1[9]
        Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, BUTTONS_BUTTON4_GPIO_PORT_NUM, BUTTONS_BUTTON4_GPIO_BIT_NUM);   // input
	Chip_SCU_GPIOIntPinSel(3, 1, 9); // GPIO1[9] to INT3
	Chip_PININT_ClearIntStatus(LPC_GPIO_PIN_INT, PININTCH(3)); // INT3
        Chip_PININT_SetPinModeEdge(LPC_GPIO_PIN_INT, PININTCH(3)); // INT3
        Chip_PININT_EnableIntLow(LPC_GPIO_PIN_INT, PININTCH(3));   // INT3
        NVIC_ClearPendingIRQ(PIN_INT3_IRQn);
        NVIC_EnableIRQ(PIN_INT3_IRQn);
}
Ejemplo n.º 11
0
/* Set GPIO direction for a single GPIO pin */
void Chip_GPIO_SetPinDIR(LPC_GPIO_T *pGPIO, uint8_t port, uint8_t pin, bool output)
{
	if (output) {
		Chip_GPIO_SetPinDIROutput(pGPIO, port, pin);
	}
	else {
		Chip_GPIO_SetPinDIRInput(pGPIO, port, pin);
	}
}
Ejemplo n.º 12
0
/* Initializes board Button(s) */
static void Board_BTN_Init(void)
{
    pinmux_t buttons[] = { ONBOARD_BTNS };
    Chip_GPIO_Init(LPC_GPIO_PORT);
    for (int i = 0; i < (sizeof(buttons)/sizeof(buttons[0])); i++)
    {
        Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, TO_PORT(buttons[i]), TO_PIN(buttons[i]));
    }
}
Ejemplo n.º 13
0
/* Initialize Joystick */
void Board_Joystick_Init(void)
{
	int i;

	/* IOCON states already selected in SystemInit(), GPIO setup only. Pullups
	   are external, so IOCON with no states */
	for (i = 0; i < NUM_BUTTONS; i++) {
		Chip_GPIO_SetPinDIRInput(LPC_GPIO, portButton[i], pinButton[i]);
	}
}
Ejemplo n.º 14
0
void Earphone_Init(void)
{
	Chip_IOCON_PinSetMode(LPC_IOCON, IOCON_PIO14, PIN_MODE_INACTIVE);
	Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, 0, 14);
	
	Chip_IOCON_PinSetMode(LPC_IOCON, QUICKJACKTXPIN, PIN_MODE_INACTIVE);
	Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, QUICKJACKTXPINNUM);
	Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, QUICKJACKTXPINNUM, 1);	

	Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM);
	Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_IOCON);
}
Ejemplo n.º 15
0
static void gpio_init(void) {
	Chip_GPIO_Init(LPC_GPIO_PORT);

	// 0_4 -> Wake
	// 0_16 -> Misc

	Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON);

	Chip_IOCON_PinSetMode(LPC_IOCON, IOCON_PIO4, PIN_MODE_PULLUP);

	Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, 0, 4);
}
Ejemplo n.º 16
0
void Board_GPIOs_Init(void)
{
	// GPIOs default: input. pull up and pull down disabled.
	for(int32_t i=0 ; i<9; i++)
        {
	    Chip_SCU_PinMuxSet(gpiosInfo[i].port, gpiosInfo[i].portBit, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | gpiosInfo[i].func));
  	    Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, gpiosInfo[i].gpio, gpiosInfo[i].gpioBit);
	}
	extIntData[0].callback=NULL;
	extIntData[1].callback=NULL;
	extIntData[2].callback=NULL;
	extIntData[3].callback=NULL;
}
Ejemplo n.º 17
0
/**
 * Methods
 */
void nRF24L01PInit(unsigned char transmitMode) {

	Chip_GPIO_SetPinOutHigh(LPC_GPIO, CSN_PORT, CSN_PIN);
	Chip_GPIO_SetPinDIROutput(LPC_GPIO, CSN_PORT, CSN_PIN);
	Chip_GPIO_SetPinOutLow(LPC_GPIO, NORDIC_CE_PORT, NORDIC_CE_PIN);
	Chip_GPIO_SetPinDIROutput(LPC_GPIO, NORDIC_CE_PORT, NORDIC_CE_PIN);
	Chip_GPIO_SetPinDIRInput(LPC_GPIO, NORDIC_IRQ_PORT, NORDIC_IRQ_PIN);
	nRF24L01P.mode = NRF24L01P_MODE_UNKNOWN;
	nRF24L01P.transmissionTimeout = -1;
	nRF24L01P.payloadsinTXFIFO = 0;
	RFdisable();
	Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SSP1);
	Chip_SSP_Set_Mode(LPC_SSP1, SSP_MODE_MASTER);
	Chip_SSP_SetFormat(LPC_SSP1, SSP_BITS_8, SSP_FRAMEFORMAT_SPI, SSP_CLOCK_CPHA0_CPOL0); // 8-bit, ClockPhase = 0, ClockPolarity = 0
	Chip_SSP_SetBitRate(LPC_SSP1, NRF24L01P_SPI_MAX_DATA_RATE / 2); // 2Mbit, 1/5th the maximum transfer rate for the SPI bus
	Chip_SSP_Enable(LPC_SSP1);

	RingBuffer_Init(&nordicTxBuffer, nordictxBufferArray, 1, TX_BUFFER_SIZE);
	memset(&spi, 0, sizeof(spi));
	spi.tx_data = spiBufferTx;
	spi.rx_data = spiBufferRx;

	timerDelayUs(NRF24L01P_TIMING_Tundef2pd_us);    // Wait for Power-on reset

	RFsetRegister(NRF24L01P_REG_CONFIG, 0); // Power Down
	RFsetRegister(NRF24L01P_REG_STATUS, NRF24L01P_STATUS_MAX_RT | NRF24L01P_STATUS_TX_DS | NRF24L01P_STATUS_RX_DR);  // Clear any pending interrupts
	RFsetRegister(NRF24L01P_REG_FEATURE, NRF24L01P_EN_DYN_ACK | NRF24L01P_EN_ACK_PAY | NRF24L01P_EN_DPL); //Enabled no ack packages
	RFsetRegister(NRF24L01P_REG_DYNPD, NRF24L01P_DPL_P0);
	RFsetRegister(NRF24L01P_REG_RF_SETUP, 0); // Clear this register
	//
	// Setup default configuration
	//
	RFdisableAllRxPipes();
	RFsetFrequency(DEFAULTNRF24L01P_RF_FREQUENCY);
	RFsetAirDataRate(DEFAULTNRF24L01P_DATARATE);
	RFsetRfOutputPower(DEFAULTNRF24L01P_TX_PWR);
	RFsetCrcWidth(DEFAULTNRF24L01P_CRC);
	RFsetTxAddress(DEFAULTNRF24L01P_ADDRESS, DEFAULTNRF24L01P_ADDRESS_WIDTH);
	RFsetRxAddress(DEFAULTNRF24L01P_ADDRESS, DEFAULTNRF24L01P_ADDRESS_WIDTH, NRF24L01P_PIPE_P0);
	RFenableAutoRetransmit(250, 3);
	RFdisableAutoAcknowledge();
	RFenableAutoAcknowledge(NRF24L01P_PIPE_P0);
	RFsetTransferSize(DEFAULTNRF24L01P_TRANSFER_SIZE, NRF24L01P_PIPE_P0);
	nRF24L01P.mode = NRF24L01P_MODE_POWER_DOWN;
	if (transmitMode) {
		RFsetTransmitMode();
	} else {
		RFsetReceiveMode();
	}
	RFenable();
}
Ejemplo n.º 18
0
static void pinConfig(void)
{
  // PE.15 FUNC4 => GPIO7[15] output for CS
  Chip_SCU_PinMuxSet(0xE, 15, SCU_MODE_PULLDOWN | FUNC4);
  Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 7, 15);

  // P8.1 FUNC0 => GPIO4[1] input for TP_IRQ
  Chip_SCU_PinMuxSet(0x8, 1, SCU_MODE_INACT | SCU_MODE_INBUFF_EN | FUNC0);
  Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, 4, 1);

  // CS is controlled via PE.15 (GPIO7[16]) and not SSP0_SSEL.
  // Pin PF.1 should be configured as GPIO and set high.
  Chip_SCU_PinMuxSet(0xf, 1, SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_HIGHSPEEDSLEW_EN | FUNC4);
  Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 7, 16);
  Chip_GPIO_SetPinOutHigh(LPC_GPIO_PORT, 7, 16);
}
Ejemplo n.º 19
0
/* Set up and initialize all required blocks and functions related to the
   board hardware */
void Board_Init(void)
{
	QUICKJACK_IO_Init();
	
	/* Initialize GPIO */
	Chip_GPIO_Init(LPC_GPIO_PORT);

	/* Initialize the LEDs */
	Board_LED_Init();

	// init sensor switch
	SensorSwitch_Init();

	/* Configure GPIO pin as input pin */
	Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, 0, 0);

	/* MCU Tx Pin initialize */
	Chip_IOCON_PinSetMode(LPC_IOCON, QUICKJACKTXPIN, PIN_MODE_INACTIVE);
	Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, QUICKJACKTXPINNUM);
	Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, QUICKJACKTXPINNUM, 1);	
	
	/* MCU Rx Pin initialize */
	Chip_IOCON_PinSetMode(LPC_IOCON, QUICKJACKRXPIN, PIN_MODE_INACTIVE);
	/* Configure analog comparator for Manchester Rx */
	Chip_SWM_FixedPinEnable(SWM_FIXED_ACMP_I1, 1);
	Chip_ACMP_Init(LPC_CMP);
	Chip_ACMP_SetPosVoltRef(LPC_CMP, ACMP_POSIN_ACMP_I1);
	Chip_ACMP_SetNegVoltRef(LPC_CMP, ACMP_NEGIN_VLO);
	Chip_ACMP_SetupVoltLadder(LPC_CMP, (15<<1), false);
	Chip_ACMP_EnableVoltLadder(LPC_CMP);
	Chip_ACMP_SetHysteresis(LPC_CMP, ACMP_HYS_10MV);
	Chip_ACMP_SetEdgeSelection(LPC_CMP, ACMP_EDGESEL_RISING);
	/* Uncomment below 2 lines to connect analog comparator output to P1_0 (not needed for normal operation) */
//	Chip_SWM_FixedPinEnable(SWM_FIXED_ACMP_I2, 0);
//	Chip_SWM_MovablePinAssign(SWM_ACMP_O_O, 1);
	
	Chip_ACMP_EdgeClear(LPC_CMP);
	NVIC_EnableIRQ(CMP_IRQn);
	
	/* Disable clocks to SWM and IOCON to save power */
	Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM);
	Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_IOCON);
}
Ejemplo n.º 20
0
void Board_KEYBOARD_Init(uint8_t rows, uint8_t columns)
{
	keyboardInfo.enable=0;

	if(rows>KEYBOARD_MAX_ROWS)
		rows=KEYBOARD_MAX_ROWS;
	if(columns>KEYBOARD_MAX_COLUMNS)
		columns=KEYBOARD_MAX_COLUMNS;

	keyboardInfo.rows=rows;
	keyboardInfo.columns=columns;

        // configure Rows (Input)

        for(i=0 ; i<rows; i++)
        {
            Chip_SCU_PinMuxSet(keyboardRowsPinInfo[i].port, keyboardRowsPinInfo[i].portBit, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | keyboardRowsPinInfo[i].func));
            Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, keyboardRowsPinInfo[i].gpio, keyboardRowsPinInfo[i].gpioBit);
        }


	// configure Columns (output)
        for(i=0 ; i<columns; i++)
        {
            Chip_SCU_PinMuxSet(keyboardColsPinInfo[i].port, keyboardColsPinInfo[i].portBit, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | keyboardColsPinInfo[i].func));
            Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, keyboardColsPinInfo[i].gpio, keyboardColsPinInfo[i].gpioBit);

	    Chip_GPIO_SetPinOutHigh(LPC_GPIO_PORT, keyboardColsPinInfo[i].gpio, keyboardColsPinInfo[i].gpioBit);
        }

	keyboardInfo.state=KEYBOARD_SCAN_STATE_START;

	for(r=0; r<KEYBOARD_MAX_ROWS; r++)
	{
	    for(c=0; c<KEYBOARD_MAX_COLUMNS; c++)
		keyboardInfo.stateMatrix[r][c]=1;
	}
	keyboardInfo.enable=1;
}
Ejemplo n.º 21
0
static void flash_spi_pinmux_init(void)
{
    /* Connect the SPI1 signals to port pins */
    Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 6 ,  (IOCON_FUNC0 | IOCON_MODE_PULLUP | IOCON_DIGITAL_EN));	/* SPI1_SCK */
    Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 16,  (IOCON_FUNC0 | IOCON_MODE_INACT | IOCON_DIGITAL_EN));	/* SPI1_MISO */
    Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 7 ,  (IOCON_FUNC0 | IOCON_MODE_PULLUP | IOCON_DIGITAL_EN));	/* SPI1_MOSI */
    Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 8 ,  (IOCON_FUNC0 | IOCON_MODE_PULLUP | IOCON_DIGITAL_EN));	/* SPI1_SSEL0 */

//  Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 15,  (IOCON_FUNC0 | IOCON_MODE_PULLUP | IOCON_DIGITAL_EN));
//  Chip_GPIO_SetPinDIROutput(LPC_GPIO, 1, 15);
//  Chip_GPIO_SetPinState(LPC_GPIO, 1, 15, 1);

    Chip_GPIO_SetPinDIROutput(LPC_GPIO, 0, 6);
    Chip_GPIO_SetPinState(LPC_GPIO, 0, 6, 0);     /* SPI1_SCK */

    Chip_GPIO_SetPinDIRInput(LPC_GPIO, 1, 16);    /* SPI1_MISO */
    Chip_GPIO_SetPinState(LPC_GPIO, 1, 16, 0);

    Chip_GPIO_SetPinDIROutput(LPC_GPIO, 0, 7);    /* SPI1_MOSI */
    Chip_GPIO_SetPinState(LPC_GPIO, 0, 7, 1);

    Chip_GPIO_SetPinDIROutput(LPC_GPIO, 0, 8);/* SPI1_SSEL0 */
    Chip_GPIO_SetPinState(LPC_GPIO, 0, 8, 1);
}
Ejemplo n.º 22
0
/*
 * Wind Speed translation : V = p*(2,25/t)
 * V: speed in mph
 * p: pulses per sampelperiod
 * t: sample period in sec
 */
void setupirq(){
	DBG("Initialize Wind Cups...\n");

	Chip_GPIOINT_Init(LPC_GPIOINT);
	Chip_GPIO_SetPinDIRInput(LPC_GPIO,2,13);
	Chip_GPIO_SetPinState(LPC_GPIO, 2, 13, true);

	Chip_IOCON_PinMux(LPC_IOCON, 2, 13, IOCON_MODE_PULLUP, IOCON_FUNC0);

	const uint32_t prescaleDivisor = 8;
	Chip_TIMER_Init(LPC_TIMER2);
	Chip_TIMER_PrescaleSet(LPC_TIMER2, prescaleDivisor - 1);
	Chip_TIMER_Enable(LPC_TIMER2);
	ticksPerSecond = Chip_Clock_GetSystemClockRate() / prescaleDivisor / 4;

	Chip_GPIOINT_SetIntFalling(LPC_GPIOINT, GPIOINT_PORT2, (1 << 13));
	Chip_GPIOINT_ClearIntStatus(LPC_GPIOINT, GPIOINT_PORT2, (1 << 13));

	NVIC_ClearPendingIRQ(EINT3_IRQn);
	NVIC_EnableIRQ(EINT3_IRQn);
	DBG("Initialize Wind Cups complete...\n");


}
Ejemplo n.º 23
0
void Board_Buttons_Init(void)
{
    Chip_SCU_PinMuxSet(BUTTONS_BUTTON1_PIN_PORT_NUM, BUTTONS_BUTTON1_PIN_BIT_NUM,
            (SCU_MODE_PULLUP | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | BUTTONS_BUTTON1_MODE_FUNC));
    Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, BUTTONS_BUTTON1_GPIO_PORT_NUM, (1 << BUTTONS_BUTTON1_GPIO_BIT_NUM));  // input
}
Ejemplo n.º 24
0
void Board_Buttons_Init(void)
{
	Chip_SCU_PinMuxSet(0x2, 7, (SCU_MODE_PULLUP | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC0));		// P2_7 as GPIO0[7]
	Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, BUTTONS_BUTTON1_GPIO_PORT_NUM, BUTTONS_BUTTON1_GPIO_BIT_NUM);	// input
}
Ejemplo n.º 25
0
/**
 * @brief	Main program body
 * @return	Does not return
 */
int main(void)
{
	/* Generic Initialization */
	SystemCoreClockUpdate();

	/* Board_Init calls Chip_GPIO_Init and enables GPIO clock if needed,
	   Chip_GPIO_Init is not called again */
	Board_Init();
	Board_LED_Set(0, false);

	Chip_PININT_Init(LPC_PININT);

	/* Configure GPIO pin as input */
	Chip_GPIO_SetPinDIRInput(LPC_GPIO, GPIO_PININT_PORT, GPIO_PININT_PIN);

	/* Configure pin as GPIO */
	Chip_IOCON_PinMuxSet(LPC_IOCON, GPIO_PININT_PORT, GPIO_PININT_PIN,
						 (IOCON_FUNC0 | IOCON_DIGITAL_EN  | IOCON_GPIO_MODE));

	/* Configure pin interrupt selection for the GPIO pin in Input Mux Block */
	Chip_INMUX_PinIntSel(GPIO_PININT_INDEX, GPIO_PININT_PORT, GPIO_PININT_PIN);

	/* Configure channel interrupt as edge sensitive and falling edge interrupt */
	Chip_PININT_ClearIntStatus(LPC_PININT, PININTCH(GPIO_PININT_INDEX));
	Chip_PININT_SetPinModeEdge(LPC_PININT, PININTCH(GPIO_PININT_INDEX));
	Chip_PININT_EnableIntLow(LPC_PININT, PININTCH(GPIO_PININT_INDEX));

	/* Enable interrupt in the NVIC */
	NVIC_EnableIRQ(PININT_NVIC_NAME);

	/* Enable wakeup for PININT0 */
	Chip_SYSCON_EnableWakeup(SYSCON_STARTER_PINT0);

	/* save the clock source, power down the PLL */
	saved_clksrc = Chip_Clock_GetMainClockSource();

	/* Go to sleep mode - LED will toggle on each wakeup event */
	while (1) {
		/* Go to sleep state - will wake up automatically on interrupt */
		/* Disable PLL, if previously enabled, prior to sleep */
		if (saved_clksrc == SYSCON_MAINCLKSRC_PLLOUT) {
			Chip_Clock_SetMainClockSource(SYSCON_MAINCLKSRC_IRC);
			Chip_SYSCON_PowerDown(SYSCON_PDRUNCFG_PD_SYS_PLL);
		}

		/* Lower system voltages to current lock (likely IRC) */
		Chip_POWER_SetVoltage(POWER_LOW_POWER_MODE, Chip_Clock_GetMainClockRate());

		/* Go to sleep leaving SRAM powered during sleep. Use lower
		    voltage during sleep. */
		Chip_POWER_EnterPowerMode(PDOWNMODE,
								  (SYSCON_PDRUNCFG_PD_SRAM0A | SYSCON_PDRUNCFG_PD_SRAM0B));

		/* On wakeup, restore PLL power if needed */
		if (saved_clksrc == SYSCON_MAINCLKSRC_PLLOUT) {
			Chip_SYSCON_PowerUp(SYSCON_PDRUNCFG_PD_SYS_PLL);

			/* Wait for PLL lock */
			while (!Chip_Clock_IsSystemPLLLocked()) {}

			Chip_POWER_SetVoltage(POWER_LOW_POWER_MODE, Chip_Clock_GetSystemPLLOutClockRate(false));

			/* Use PLL for system clock */
			Chip_Clock_SetMainClockSource(SYSCON_MAINCLKSRC_PLLOUT);
		}
	}

	return 0;
}
Ejemplo n.º 26
0
uint8_t __attribute__ ((noinline)) i2c_read_sda(void)
{
  Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, 0, 0);
  return Chip_GPIO_ReadPortBit(LPC_GPIO_PORT, 0, 0);  
}
void Board_Attach_Interrupt(uint32_t ulPin, void (*callback)(void), uint32_t mode)
{
    uint8_t port = 1;
    uint8_t pin = 24;
    uint8_t pinIntChannel = 0;
    LPC1347_IRQn_Type pinIntIRQ = PIN_INT0_IRQn;

    port = APIN_PORT(ulPin);
    pin = APIN_PIN(ulPin);

    pinIntChannel = APIN_INT(ulPin);

    if(pinIntChannel == EXT_INT_0)
    {
        pinIntIRQ = PIN_INT0_IRQn;
        callbackPinIntA = callback;
    }
    else if(pinIntChannel == EXT_INT_1)
    {
        pinIntIRQ = PIN_INT1_IRQn;
        callbackPinIntB = callback;
    }
    else if(pinIntChannel == EXT_INT_2)
    {
        pinIntIRQ = PIN_INT2_IRQn;
        callbackPinIntC = callback;
    }
    else if(pinIntChannel == EXT_INT_3)
    {
        pinIntIRQ = PIN_INT3_IRQn;
        callbackPinIntD = callback;
    }

    /* Configure GPIO pin as input */
    Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, port, pin);

    /* Configure pin as GPIO with pulldown */
    // All digital pins are selected such that GPIO is on IOCON_FUNC0
    Chip_IOCON_PinMuxSet(LPC_IOCON, port, pin, (IOCON_FUNC0 | IOCON_MODE_PULLDOWN));

    /* Enable PININT clock */
    Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_PINT);

    /* Configure interrupt channel for the GPIO pin in SysCon block */
    Chip_SYSCTL_SetPinInterrupt(pinIntChannel, port, pin);

    /* Configure channel interrupt as edge sensitive and falling edge interrupt */
    Chip_PININT_ClearIntStatus(LPC_PININT, PININTCH(pinIntChannel));

    if(mode == HIGH)
    {
        Chip_PININT_SetPinModeLevel(LPC_PININT, PININTCH(pinIntChannel));
        Chip_PININT_EnableIntHigh(LPC_PININT, PININTCH(pinIntChannel));
    }
    else if(mode == LOW)
    {
        Chip_PININT_SetPinModeLevel(LPC_PININT, PININTCH(pinIntChannel));
        Chip_PININT_EnableIntLow(LPC_PININT, PININTCH(pinIntChannel));
    }
    else if(mode == RISING)
    {
        Chip_PININT_SetPinModeEdge(LPC_PININT, PININTCH(pinIntChannel));
        Chip_PININT_EnableIntHigh(LPC_PININT, PININTCH(pinIntChannel));
    }
    else if(mode == FALLING)
    {
        Chip_PININT_SetPinModeEdge(LPC_PININT, PININTCH(pinIntChannel));
        Chip_PININT_EnableIntLow(LPC_PININT, PININTCH(pinIntChannel));
    }
    else if(mode == CHANGE)
    {
        Chip_PININT_SetPinModeEdge(LPC_PININT, PININTCH(pinIntChannel));
        Chip_PININT_EnableIntHigh(LPC_PININT, PININTCH(pinIntChannel));
        Chip_PININT_EnableIntLow(LPC_PININT, PININTCH(pinIntChannel));
    }

    /* Enable interrupt in the NVIC */
    NVIC_ClearPendingIRQ(pinIntIRQ);
    NVIC_EnableIRQ(pinIntIRQ);
}
Ejemplo n.º 28
0
/**
 * @brief Set GPIO direction for a single GPIO pin to an input
 */
void GPIO_setAsInput(uint8_t port, uint8_t pin)
{
  Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT,port,pin);
}
Ejemplo n.º 29
0
void PWMInit(void) {
	halTimers[CHANNEL_A_TIMER_INDEX].timer = CHANNEL_A_TIMER;
	halTimers[CHANNEL_A_TIMER_INDEX].port[0] = CHANNEL_A_0_PORT;
	halTimers[CHANNEL_A_TIMER_INDEX].port[1] = CHANNEL_A_1_PORT;
	halTimers[CHANNEL_A_TIMER_INDEX].pin[0] = CHANNEL_A_0_PIN;
	halTimers[CHANNEL_A_TIMER_INDEX].pin[1] = CHANNEL_A_1_PIN;
	halTimers[CHANNEL_A_TIMER_INDEX].portGpio[0] = CHANNEL_A_0_PORT_GPIO;
	halTimers[CHANNEL_A_TIMER_INDEX].portGpio[1] = CHANNEL_A_1_PORT_GPIO;
	halTimers[CHANNEL_A_TIMER_INDEX].pinGpio[0] = CHANNEL_A_0_PIN_GPIO;
	halTimers[CHANNEL_A_TIMER_INDEX].pinGpio[1] = CHANNEL_A_1_PIN_GPIO;
	halTimers[CHANNEL_A_TIMER_INDEX].timerMode[0] = MD_PUP | FUNC6;
	halTimers[CHANNEL_A_TIMER_INDEX].timerMode[1] = MD_PUP | FUNC6;
	halTimers[CHANNEL_A_TIMER_INDEX].gpioMode[0] = MD_PUP | FUNC4;
	halTimers[CHANNEL_A_TIMER_INDEX].gpioMode[1] = MD_PUP | FUNC4;
	halTimers[CHANNEL_A_TIMER_INDEX].timerChannel[0] = 0;
	halTimers[CHANNEL_A_TIMER_INDEX].timerChannel[1] = 1;
	halTimers[CHANNEL_A_TIMER_INDEX].witdh[0] = 0;
	halTimers[CHANNEL_A_TIMER_INDEX].witdh[1] = 0;
	halTimers[CHANNEL_A_TIMER_INDEX].enabled[0] = 0;
	halTimers[CHANNEL_A_TIMER_INDEX].enabled[1] = 0;
	halTimers[CHANNEL_A_TIMER_INDEX].period = 0;
	Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, CHANNEL_A_0_PORT_GPIO, CHANNEL_A_0_PIN_GPIO);
	Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, CHANNEL_A_1_PORT_GPIO, CHANNEL_A_1_PIN_GPIO);
	Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, CHANNEL_A_0_PORT_GPIO, CHANNEL_A_0_PIN_GPIO);
	Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, CHANNEL_A_1_PORT_GPIO, CHANNEL_A_1_PIN_GPIO);
	Chip_SCU_PinMuxSet(CHANNEL_A_0_PORT, CHANNEL_A_0_PIN, halTimers[CHANNEL_A_TIMER_INDEX].gpioMode[0]);
	Chip_SCU_PinMuxSet(CHANNEL_A_1_PORT, CHANNEL_A_1_PIN, halTimers[CHANNEL_A_TIMER_INDEX].gpioMode[1]);

	halTimers[CHANNEL_B_TIMER_INDEX].timer = CHANNEL_B_TIMER;
	halTimers[CHANNEL_B_TIMER_INDEX].port[0] = CHANNEL_B_0_PORT;
	halTimers[CHANNEL_B_TIMER_INDEX].port[1] = CHANNEL_B_1_PORT;
	halTimers[CHANNEL_B_TIMER_INDEX].pin[0] = CHANNEL_B_0_PIN;
	halTimers[CHANNEL_B_TIMER_INDEX].pin[1] = CHANNEL_B_1_PIN;
	halTimers[CHANNEL_B_TIMER_INDEX].portGpio[0] = CHANNEL_B_0_PORT_GPIO;
	halTimers[CHANNEL_B_TIMER_INDEX].portGpio[1] = CHANNEL_B_1_PORT_GPIO;
	halTimers[CHANNEL_B_TIMER_INDEX].pinGpio[0] = CHANNEL_B_0_PIN_GPIO;
	halTimers[CHANNEL_B_TIMER_INDEX].pinGpio[1] = CHANNEL_B_1_PIN_GPIO;
	halTimers[CHANNEL_B_TIMER_INDEX].timerMode[0] = MD_PUP | FUNC5;
	halTimers[CHANNEL_B_TIMER_INDEX].timerMode[1] = MD_PUP | FUNC5;
	halTimers[CHANNEL_B_TIMER_INDEX].gpioMode[0] = MD_PUP | FUNC4;
	halTimers[CHANNEL_B_TIMER_INDEX].gpioMode[1] = MD_PUP | FUNC4;
	halTimers[CHANNEL_B_TIMER_INDEX].timerChannel[0] = 0;
	halTimers[CHANNEL_B_TIMER_INDEX].timerChannel[1] = 1;
	halTimers[CHANNEL_B_TIMER_INDEX].witdh[0] = 0;
	halTimers[CHANNEL_B_TIMER_INDEX].witdh[1] = 0;
	halTimers[CHANNEL_B_TIMER_INDEX].enabled[0] = 0;
	halTimers[CHANNEL_B_TIMER_INDEX].enabled[1] = 0;
	halTimers[CHANNEL_B_TIMER_INDEX].period = 0;
	Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, CHANNEL_B_0_PORT_GPIO, CHANNEL_B_0_PIN_GPIO);
	Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, CHANNEL_B_1_PORT_GPIO, CHANNEL_B_1_PIN_GPIO);
	Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, CHANNEL_B_0_PORT_GPIO, CHANNEL_B_0_PIN_GPIO);
	Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, CHANNEL_B_1_PORT_GPIO, CHANNEL_B_1_PIN_GPIO);
	Chip_SCU_PinMuxSet(CHANNEL_B_0_PORT, CHANNEL_B_0_PIN, halTimers[CHANNEL_B_TIMER_INDEX].gpioMode[0]);
	Chip_SCU_PinMuxSet(CHANNEL_B_1_PORT, CHANNEL_B_1_PIN, halTimers[CHANNEL_B_TIMER_INDEX].gpioMode[1]);

	halTimers[CHANNEL_C_TIMER_INDEX].timer = CHANNEL_C_TIMER;
	halTimers[CHANNEL_C_TIMER_INDEX].port[0] = CHANNEL_C_0_PORT;
	halTimers[CHANNEL_C_TIMER_INDEX].port[1] = CHANNEL_C_1_PORT;
	halTimers[CHANNEL_C_TIMER_INDEX].pin[0] = CHANNEL_C_0_PIN;
	halTimers[CHANNEL_C_TIMER_INDEX].pin[1] = CHANNEL_C_1_PIN;
	halTimers[CHANNEL_C_TIMER_INDEX].portGpio[0] = CHANNEL_C_0_PORT_GPIO;
	halTimers[CHANNEL_C_TIMER_INDEX].portGpio[1] = CHANNEL_C_1_PORT_GPIO;
	halTimers[CHANNEL_C_TIMER_INDEX].pinGpio[0] = CHANNEL_C_0_PIN_GPIO;
	halTimers[CHANNEL_C_TIMER_INDEX].pinGpio[1] = CHANNEL_C_1_PIN_GPIO;
	halTimers[CHANNEL_C_TIMER_INDEX].timerMode[0] = MD_PUP | FUNC1;
	halTimers[CHANNEL_C_TIMER_INDEX].timerMode[1] = MD_PUP | FUNC1;
	halTimers[CHANNEL_C_TIMER_INDEX].gpioMode[0] = MD_PUP | FUNC4;
	halTimers[CHANNEL_C_TIMER_INDEX].gpioMode[1] = MD_PUP | FUNC0;
	halTimers[CHANNEL_C_TIMER_INDEX].timerChannel[0] = 0;
	halTimers[CHANNEL_C_TIMER_INDEX].timerChannel[1] = 3; // Special mapping for the Channel C_1
	halTimers[CHANNEL_C_TIMER_INDEX].witdh[0] = 0;
	halTimers[CHANNEL_C_TIMER_INDEX].witdh[1] = 0;
	halTimers[CHANNEL_C_TIMER_INDEX].enabled[0] = 0;
	halTimers[CHANNEL_C_TIMER_INDEX].enabled[1] = 0;
	halTimers[CHANNEL_C_TIMER_INDEX].period = 0;
	Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, CHANNEL_C_0_PORT_GPIO, CHANNEL_C_0_PIN_GPIO);
	Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, CHANNEL_C_1_PORT_GPIO, CHANNEL_C_1_PIN_GPIO);
	Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, CHANNEL_C_0_PORT_GPIO, CHANNEL_C_0_PIN_GPIO);
	Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, CHANNEL_C_1_PORT_GPIO, CHANNEL_C_1_PIN_GPIO);
	Chip_SCU_PinMuxSet(CHANNEL_C_0_PORT, CHANNEL_C_0_PIN, halTimers[CHANNEL_C_TIMER_INDEX].gpioMode[0]);
	Chip_SCU_PinMuxSet(CHANNEL_C_1_PORT, CHANNEL_C_1_PIN, halTimers[CHANNEL_C_TIMER_INDEX].gpioMode[1]);
	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < 2; ++j) {
			Chip_TIMER_ResetOnMatchDisable(halTimers[i].timer, halTimers[i].timerChannel[j]);
			Chip_TIMER_StopOnMatchDisable(halTimers[i].timer, halTimers[i].timerChannel[j]);
			Chip_TIMER_MatchDisableInt(halTimers[i].timer, halTimers[i].timerChannel[j]);
			Chip_TIMER_ExtMatchControlSet(halTimers[i].timer, 1, TIMER_EXTMATCH_CLEAR, halTimers[i].timerChannel[j]);
		}
	}

}
int main(void)
{
#if defined (__USE_LPCOPEN)
    // Read clock settings and update SystemCoreClock variable
    SystemCoreClockUpdate();
#if !defined(NO_BOARD_LIB)
#if defined (__MULTICORE_MASTER) || defined (__MULTICORE_NONE)
    // Set up and initialize all required blocks and
    // functions related to the board hardware
    Board_Init();
#endif
    // Set the LED to the state of "On"
    Board_LED_Set(0, true);
#endif
#endif

#if defined (__MULTICORE_MASTER_SLAVE_M0SLAVE) || \
    defined (__MULTICORE_MASTER_SLAVE_M4SLAVE)
    boot_multicore_slave();
#endif

    // Get the address of the PCM value FIFO from the M4 master.
    PCM_FIFO = (PCM_FIFO_T *) Chip_MBOX_GetValue(LPC_MBOX, MAILBOX_CM0PLUS);

    // Map P0.21 as the CLKOUT pin.
    Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 21,
                         (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGITAL_EN));

    // Route the main clock to the CLKOUT pin, for a 1 MHz signal.
    Chip_Clock_SetCLKOUTSource(SYSCON_CLKOUTSRC_MAINCLK, SystemCoreClock / 1000000);

    // Enable the GPIO and pin-interrupt sub-systems.
    Chip_GPIO_Init(LPC_GPIO);
    Chip_PININT_Init(LPC_PININT);

    // Map PIO0_9 as a GPIO input pin.  This is the data signal from the
    // microphone.
    Chip_GPIO_SetPinDIRInput(LPC_GPIO, 0, 9);
    Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 9,
            (IOCON_FUNC0 | IOCON_DIGITAL_EN | IOCON_GPIO_MODE));

    // Map PIO0_11 as a GPIO input pin, triggering pin-interrupt 0.  This will
    // indicate that there is a sample ready from the microphone.
    Chip_GPIO_SetPinDIRInput(LPC_GPIO, 0, 11);
    Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 11,
            (IOCON_FUNC0 | IOCON_DIGITAL_EN | IOCON_GPIO_MODE));
    Chip_INMUX_PinIntSel(PININTSELECT0, 0, 11);

    // Trigger the interrupt on the clock's rising edge.
    Chip_PININT_ClearIntStatus(LPC_PININT, PININTCH(PININTSELECT0));
    Chip_PININT_SetPinModeEdge(LPC_PININT, PININTCH(PININTSELECT0));
    Chip_PININT_EnableIntHigh(LPC_PININT, PININTCH(PININTSELECT0));

    // Enable the interrupt in the NVIC.
    NVIC_EnableIRQ(PIN_INT0_IRQn);

    // Spin while waiting for interrupts from the microphone.
    while (1) {
        __WFI();
    }
    return 0;
}