void init() { //initialise colour sensor sensorInit(); //iniitalise interface InterfaceInit(); //initialise servos for seperator and sorter servoInit(); // Configure button S1 interrupt GPIO_selectInterruptEdge(GPIO_PORT_P1, GPIO_PIN3, GPIO_LOW_TO_HIGH_TRANSITION); GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN3); GPIO_clearInterrupt(GPIO_PORT_P1, GPIO_PIN3); GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN3); // Configure button S2 interrupt GPIO_selectInterruptEdge(GPIO_PORT_P1, GPIO_PIN4, GPIO_LOW_TO_HIGH_TRANSITION); GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN4); GPIO_clearInterrupt(GPIO_PORT_P1, GPIO_PIN4); GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN4); }
void gpio_init_remote_dev(event_handler_t sw1_handler, event_handler_t sw2_handler, event_handler_t sw3_handler, event_handler_t sw4_handler, event_handler_t sw5_handler, event_handler_t sw6_handler, event_handler_t sw7_handler) { // Switch init GPIO_setAsInputPinWithPullUpResistor(SW1_PORT, SW1_PIN); GPIO_setAsInputPinWithPullUpResistor(SW2_PORT, SW2_PIN); GPIO_setAsInputPinWithPullUpResistor(SW3_PORT, SW3_PIN); GPIO_setAsInputPinWithPullUpResistor(SW4_PORT, SW4_PIN); GPIO_setAsInputPinWithPullUpResistor(SW5_PORT, SW5_PIN); /* GPIO_setAsInputPinWithPullUpResistor(SW6_PORT, SW6_PIN); GPIO_setAsInputPinWithPullUpResistor(SW7_PORT, SW7_PIN); */ GPIO_selectInterruptEdge(SW1_PORT, SW1_PIN, GPIO_HIGH_TO_LOW_TRANSITION); GPIO_selectInterruptEdge(SW2_PORT, SW2_PIN, GPIO_HIGH_TO_LOW_TRANSITION); GPIO_selectInterruptEdge(SW3_PORT, SW3_PIN, GPIO_HIGH_TO_LOW_TRANSITION); GPIO_selectInterruptEdge(SW4_PORT, SW4_PIN, GPIO_HIGH_TO_LOW_TRANSITION); GPIO_selectInterruptEdge(SW5_PORT, SW5_PIN, GPIO_HIGH_TO_LOW_TRANSITION); /* GPIO_selectInterruptEdge(SW6_PORT, SW6_PIN, GPIO_HIGH_TO_LOW_TRANSITION); GPIO_selectInterruptEdge(SW7_PORT, SW7_PIN, GPIO_HIGH_TO_LOW_TRANSITION); */ GPIO_clearInterrupt(SW1_PORT, SW1_PIN); GPIO_clearInterrupt(SW2_PORT, SW2_PIN); GPIO_clearInterrupt(SW3_PORT, SW3_PIN); GPIO_clearInterrupt(SW4_PORT, SW4_PIN); GPIO_clearInterrupt(SW5_PORT, SW5_PIN); /* GPIO_clearInterrupt(SW6_PORT, SW6_PIN); GPIO_clearInterrupt(SW7_PORT, SW7_PIN); */ GPIO_enableInterrupt(SW1_PORT, SW1_PIN); GPIO_enableInterrupt(SW2_PORT, SW2_PIN); GPIO_enableInterrupt(SW3_PORT, SW3_PIN); GPIO_enableInterrupt(SW4_PORT, SW4_PIN); GPIO_enableInterrupt(SW5_PORT, SW5_PIN); /* GPIO_enableInterrupt(SW6_PORT, SW6_PIN); GPIO_enableInterrupt(SW7_PORT, SW7_PIN); */ _sw1_event = event_add(sw1_handler); _sw2_event = event_add(sw2_handler); _sw3_event = event_add(sw3_handler); _sw4_event = event_add(sw4_handler); _sw5_event = event_add(sw5_handler); /* _sw6_event = event_add(sw6_handler); _sw7_event = event_add(sw7_handler); */ // LED init GPIO_setAsOutputPin(LED1_PORT, LED1_PIN); GPIO_setAsOutputPin(LED2_PORT, LED2_PIN); GPIO_setAsOutputPin(LED3_PORT, LED3_PIN); GPIO_setOutputLowOnPin(LED1_PORT, LED1_PIN); GPIO_setOutputLowOnPin(LED2_PORT, LED2_PIN); GPIO_setOutputLowOnPin(LED3_PORT, LED3_PIN); }
void button_init() { GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN1); // LaunchPad Button2 GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P2, GPIO_PIN1); // LaunchPad Button1 GPIO_setAsInputPin(GPIO_PORT_P6, GPIO_PIN3); // SernorHub push button 1 GPIO_setAsInputPin(GPIO_PORT_P6, GPIO_PIN4); // SernorHub push button 2 GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P6, GPIO_PIN0); // TI Button RV1 GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P6, GPIO_PIN1); // TI Button RV2 }
void initButtons(void) { GPIO_setOutputHighOnPin(BUTTON1_PORT, BUTTON1_PIN); GPIO_setAsInputPinWithPullUpResistor(BUTTON1_PORT, BUTTON1_PIN); GPIO_clearInterrupt(BUTTON1_PORT, BUTTON1_PIN); GPIO_enableInterrupt(BUTTON1_PORT, BUTTON1_PIN); GPIO_setOutputHighOnPin(BUTTON2_PORT, BUTTON2_PIN); GPIO_setAsInputPinWithPullUpResistor(BUTTON2_PORT, BUTTON2_PIN); GPIO_clearInterrupt(BUTTON2_PORT, BUTTON2_PIN); GPIO_enableInterrupt(BUTTON2_PORT, BUTTON2_PIN); }
int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer // Set pin P1.0 to output direction and initialize low GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN0 ); GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 ); // Set switch 2 (S2) as input button (connected to P1.1) GPIO_setAsInputPinWithPullUpResistor( GPIO_PORT_P2, GPIO_PIN1 ); while(1) { // Read pin P1.1 which is connected to push button 2 usiButton1 = GPIO_getInputPinValue ( GPIO_PORT_P2, GPIO_PIN1 ); if ( usiButton1 == GPIO_INPUT_PIN_LOW ) { // If button is down, turn on LED GPIO_setOutputHighOnPin( GPIO_PORT_P1, GPIO_PIN0 ); } else { // If button is up, turn off LED GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 ); } } }
__LINK_C error_t hw_gpio_configure_pin(pin_id_t pin_id, cc430_gpio_mode_t mode) { // TODO check if already configured (return EALREADY) if(mode == GPIO_MODE_OUTPUT || mode == GPIO_MODE_OUTPUT_FULL_DRIVE_STRENGTH) { GPIO_setAsOutputPin(pin_id.port, pin_id.pin); if(mode == GPIO_MODE_OUTPUT_FULL_DRIVE_STRENGTH) GPIO_setDriveStrength(pin_id.port, pin_id.pin, GPIO_FULL_OUTPUT_DRIVE_STRENGTH); } else if(mode ==GPIO_MODE_INPUT) GPIO_setAsInputPin(pin_id.port, pin_id.pin); else if(mode == GPIO_MODE_INPUT_PULL_UP) GPIO_setAsInputPinWithPullUpResistor(pin_id.port, pin_id.pin); else if(mode == GPIO_MODE_INPUT_PULL_DOWN) GPIO_setAsInputPinWithPullDownResistor(pin_id.port, pin_id.pin); return SUCCESS; }
void main(void) { //Stop watchdog timer WDT_A_hold(WDT_A_BASE); //Set P1.0 to output direction GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN0 ); //Enable P1.4 internal resistance as pull-Up resistance GPIO_setAsInputPinWithPullUpResistor( GPIO_PORT_P1, GPIO_PIN4 ); //P1.4 interrupt enabled GPIO_enableInterrupt( GPIO_PORT_P1, GPIO_PIN4 ); //P1.4 Hi/Lo edge GPIO_selectInterruptEdge( GPIO_PORT_P1, GPIO_PIN4, GPIO_HIGH_TO_LOW_TRANSITION ); //P1.4 IFG cleared GPIO_clearInterrupt( GPIO_PORT_P1, GPIO_PIN4 ); //Enter LPM4 w/interrupt __bis_SR_register(LPM4_bits + GIE); //For debugger __no_operation(); }
void buttonInit(void){ GPIO_setCallback(Board_BUTTON0, gpioButton0); GPIO_enableInt(Board_BUTTON0); /* Configure RGB LED pins */ GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN4 | GPIO_PIN6); GPIO_setAsOutputPin(GPIO_PORT_P5, GPIO_PIN6); /* Set RGB LED to red */ P2OUT |= BIT6; P2OUT &= ~BIT4; P5OUT &= ~BIT6; /* Setup Button */ GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P5,GPIO_PIN1); GPIO_clearInterruptFlag(GPIO_PORT_P5, GPIO_PIN1); GPIO_enableInterrupt(GPIO_PORT_P5, GPIO_PIN1); GPIO_interruptEdgeSelect(GPIO_PORT_P5, GPIO_PIN1, GPIO_HIGH_TO_LOW_TRANSITION); Interrupt_enableInterrupt(INT_PORT5); }
/* * ======== MSP_EXP430F5529LP_initSPI ======== */ void MSP_EXP430F5529LP_initSPI(void) { /* USCIB1 */ /* * NOTE: TI-RTOS examples configure USCIB0 as either SPI or I2C. Thus, * a conflict occurs when the I2C & SPI drivers are used simultaneously in * an application. Modify the pin mux settings in this file and resolve the * conflict before running your the application. */ GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P4, GPIO_PIN3 | GPIO_PIN2 | GPIO_PIN1); /* SOMI/MISO */ GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P4, GPIO_PIN2); /* CLK and SIMO/MOSI */ GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P4, GPIO_PIN3 | GPIO_PIN1); SPI_init(); }