Exemplo n.º 1
0
void gpio_test_write(void)
{
	int i = 0;

	//set gpio direction to output
#ifdef RALINK_GPIO_HAS_5124
	gpio_set_dir(gpio5140, gpio_out);
	gpio_set_dir(gpio3924, gpio_out);
#endif
	gpio_set_dir(gpio2300, gpio_out);

	//turn off LEDs
#ifdef RALINK_GPIO_HAS_5124
	gpio_write_int(gpio5140, 0xffffffff);
	gpio_write_int(gpio3924, 0xffffffff);
#endif
	gpio_write_int(gpio2300, 0xffffffff);
	sleep(3);

	//turn on all LEDs
#ifdef RALINK_GPIO_HAS_5124
	gpio_write_int(gpio5140, 0);
	gpio_write_int(gpio3924, 0);
#endif
	gpio_write_int(gpio2300, 0);
}
Exemplo n.º 2
0
int target_panel_reset(uint8_t enable, struct panel_reset_sequence *resetseq,
						struct msm_panel_info *pinfo)
{
	int ret = NO_ERROR;
	if (enable) {
		if (pinfo->mipi.use_enable_gpio) {
			gpio_tlmm_config(enable_gpio.pin_id, 0,
				enable_gpio.pin_direction, enable_gpio.pin_pull,
				enable_gpio.pin_strength,
				enable_gpio.pin_state);

			gpio_set_dir(enable_gpio.pin_id, 2);
		}

		gpio_tlmm_config(reset_gpio.pin_id, 0,
				reset_gpio.pin_direction, reset_gpio.pin_pull,
				reset_gpio.pin_strength, reset_gpio.pin_state);

		gpio_set_dir(reset_gpio.pin_id, 2);

		gpio_set_value(reset_gpio.pin_id, resetseq->pin_state[0]);
		mdelay(resetseq->sleep[0]);
		gpio_set_value(reset_gpio.pin_id, resetseq->pin_state[1]);
		mdelay(resetseq->sleep[1]);
		gpio_set_value(reset_gpio.pin_id, resetseq->pin_state[2]);
		mdelay(resetseq->sleep[2]);
	} else if(!target_cont_splash_screen()) {
		gpio_set_value(reset_gpio.pin_id, 0);
		if (pinfo->mipi.use_enable_gpio)
			gpio_set_value(enable_gpio.pin_id, 0);
	}

	return ret;
}
Exemplo n.º 3
0
void gpio_test_intr(int gpio_num)
{
	//set gpio direction to input
#ifdef RALINK_GPIO_HAS_5124
	gpio_set_dir(gpio5140, gpio_in);
	gpio_set_dir(gpio3924, gpio_in);
#endif
	gpio_set_dir(gpio2300, gpio_in);

	//enable gpio interrupt
	gpio_enb_irq();

	//register my information
	gpio_reg_info(gpio_num);

	//issue a handler to handle SIGUSR1
	signal(SIGUSR1, signal_handler);
	signal(SIGUSR2, signal_handler);

	//wait for signal
	pause();

	//disable gpio interrupt
	gpio_dis_irq();
}
Exemplo n.º 4
0
void encode_setup(){
    gpio_export(pin_A);
    gpio_export(pin_B);
    gpio_set_dir(pin_A, 0);
    gpio_set_dir(pin_B, 0);
    gpio_set_edge(pin_A, "falling");
    gpio_set_edge(pin_B, "falling");
}
Exemplo n.º 5
0
/****************************************************************
 * Main
 ****************************************************************/
int main(int argc, char **argv, char **envp)
{
        struct pollfd fdset;
        int nfds = 1;
        int gpio_in_fd, gpio_out_fd, timeout, rc, value;
        unsigned int gpio_in, gpio_out;
        unsigned long cntr = 0;

        if (argc < 3) {
                printf("Usage: gpio-int <gpio-input-pin> <gpio-output-pin>\n\n");
                printf("Waits for a change in the GPIO pin voltage level and copy its value to output pin\n");
                exit(-1);
        }

        gpio_in = atoi(argv[1]);
        gpio_out = atoi(argv[2]);

        /* initialize input pin */
        gpio_export(gpio_in);
        gpio_set_dir(gpio_in, 0);
        gpio_set_edge(gpio_in, "both");
        gpio_in_fd = gpio_fd_open(gpio_in);

        /* initialize output pin */
        gpio_export(gpio_out);
        gpio_set_dir(gpio_out, 1);
        gpio_out_fd = gpio_fd_open(gpio_out);

        timeout = POLL_TIMEOUT;

        while (1) {
                memset(&fdset, 0, sizeof(fdset));
      
                fdset.fd = gpio_in_fd;
                fdset.events = POLLPRI;

                rc = poll(&fdset, nfds, timeout);

                if (rc < 0) {
                        printf("\npoll() failed!\n");
                        return -1;
                }

                if (fdset.revents & POLLPRI) {
                        printf("\r%lu", ++cntr);
                        gpio_get_value(gpio_in, &value);
                        gpio_set_value(gpio_out, value);
                }

                fflush(stdout);
        }

        gpio_fd_close(gpio_in_fd);
        gpio_fd_close(gpio_out_fd);
        return 0;
}
Exemplo n.º 6
0
void lcd_display_off(void)
{
#if 0 //xltao del
#ifdef LCD_STANDBY_PIN
	gpio_set_dir(LCD_STANDBY_PIN, 1, LCD_STANDBY_LEVEL);
#else
	gpio_set_dir(LCD_POWER_PIN, 1, !LCD_POWER_ON_LEVEL);
#endif
#endif
}
Exemplo n.º 7
0
int gpioInit(){
	gpio_export(LEFT_FWD_GPIO);
	gpio_set_dir(LEFT_FWD_GPIO, 1);
	gpio_export(LEFT_BCK_GPIO);
	gpio_set_dir(LEFT_BCK_GPIO, 1);
	gpio_export(RIGHT_FWD_GPIO);
	gpio_set_dir(RIGHT_FWD_GPIO, 1);
	gpio_export(RIGHT_BCK_GPIO);
	gpio_set_dir(RIGHT_BCK_GPIO, 1);
}
Exemplo n.º 8
0
void gpio_init(void)
{
#ifdef AMP_SHUT_DOWN_PIN
	// Shut Down AMP if NEEDED
	#if (AMP_SHUT_DOWN_LEVEL == GPIO_LOW_LEVEL)
		gpio_set_dir(AMP_SHUT_DOWN_PIN, 1, 0);
	#else
		gpio_set_dir(AMP_SHUT_DOWN_PIN, 1, 1);
	#endif
#endif
}
/*********************************************************************************
*	int initialize_button_interrups()
*
*	start 4 threads to handle 4 interrupt routines for pressing and
*	releasing the two buttons.
**********************************************************************************/
int initialize_button_handlers(){
	
	#ifdef DEBUG
	printf("setting up mode & pause gpio pins\n");
	#endif
	//set up mode pin
	if(gpio_export(MODE_BTN)){
		printf("can't export gpio %d \n", MODE_BTN);
		return (-1);
	}
	gpio_set_dir(MODE_BTN, INPUT_PIN);
	gpio_set_edge(MODE_BTN, "both");  // Can be rising, falling or both
	
	//set up pause pin
	if(gpio_export(PAUSE_BTN)){
		printf("can't export gpio %d \n", PAUSE_BTN);
		return (-1);
	}
	gpio_set_dir(PAUSE_BTN, INPUT_PIN);
	gpio_set_edge(PAUSE_BTN, "both");  // Can be rising, falling or both
	
	#ifdef DEBUG
	printf("starting button handling threads\n");
	#endif
	struct sched_param params;
	pthread_attr_t attr;
	params.sched_priority = sched_get_priority_max(SCHED_FIFO)/2;
	pthread_attr_init(&attr);
	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
   
	set_pause_pressed_func(&null_func);
	set_pause_unpressed_func(&null_func);
	set_mode_pressed_func(&null_func);
	set_mode_unpressed_func(&null_func);
	
	
	pthread_create(&pause_pressed_thread, &attr,			 \
				pause_pressed_handler, (void*) NULL);
	pthread_create(&pause_unpressed_thread, &attr,			 \
				pause_unpressed_handler, (void*) NULL);
	pthread_create(&mode_pressed_thread, &attr,			 \
					mode_pressed_handler, (void*) NULL);
	pthread_create(&mode_unpressed_thread, &attr,			 \
					mode_unpressed_handler, (void*) NULL);
	
	// apply medium priority to all threads
	pthread_setschedparam(pause_pressed_thread, SCHED_FIFO, &params);
	pthread_setschedparam(pause_unpressed_thread, SCHED_FIFO, &params);
	pthread_setschedparam(mode_pressed_thread, SCHED_FIFO, &params);
	pthread_setschedparam(mode_unpressed_thread, SCHED_FIFO, &params);
	 
	return 0;
}
Exemplo n.º 10
0
void WT588DInit(void) {

    syscon_ahb_enable(SYSCON_CLK_IOCON);
    /* p1_0  */
    LPC_IOCON->PIO1_10   |= IOCON_FUNC0 | IOCON_MODE_PULLUP;
    LPC_IOCON->R_PIO0_11 |= IOCON_FUNC1 | IOCON_MODE_PULLUP;
    syscon_ahb_enable(SYSCON_CLK_GPIO);
    gpio_set_dir(LPC_GPIO1, 10, GPIO_OUT);
    gpio_set_dir(LPC_GPIO0, 11, GPIO_IN);

    WT588DAdjustVolume(WT588D_VOLUME_5);
}
Exemplo n.º 11
0
/*
#ifdef LCD_STANDBY_PIN
void lcd_display_on(void)
{
	gpio_set_dir(LCD_STANDBY_PIN, 1, LCD_STANDBY_LEVEL);
}

void lcd_display_off(void)
{
	unsigned int level = LCD_STANDBY_LEVEL ? GPIO_LOW_LEVEL : GPIO_HIGH_LEVEL;
	gpio_set_dir(LCD_STANDBY_PIN, 1, level);
}
#endif
*/
void lcd_display_on(void)
{
#if 0 //xltao del
#ifdef LCD_STANDBY_PIN
	gpio_set_dir(LCD_STANDBY_PIN, 1, !LCD_STANDBY_LEVEL);
#else
	gpio_set_dir(LCD_POWER_PIN, 1, LCD_POWER_ON_LEVEL);
	gpio_set_dir(LCD_RESET_PIN, 1, LCD_RESET_LEVEL);
	mdelay(20);		// The Delay should be > 10ms.
	gpio_set_dir(LCD_RESET_PIN, 1, !LCD_RESET_LEVEL);
	mdelay(5);
#endif
#endif
}
static int target_panel_reset_skuh(uint8_t enable)
{
	int ret = NO_ERROR;
	if (enable) {
		/* for tps65132 ENP pin */
		gpio_tlmm_config(enp_gpio.pin_id, 0,
			enp_gpio.pin_direction, enp_gpio.pin_pull,
			enp_gpio.pin_strength,
			enp_gpio.pin_state);
		gpio_set_dir(enp_gpio.pin_id, 2);

		/* for tps65132 ENN pin*/
		gpio_tlmm_config(enn_gpio.pin_id, 0,
			enn_gpio.pin_direction, enn_gpio.pin_pull,
			enn_gpio.pin_strength,
			enn_gpio.pin_state);
		gpio_set_dir(enn_gpio.pin_id, 2);

		i2c_dev = qup_blsp_i2c_init(BLSP_ID_1, QUP_ID_1, 100000, 19200000);
		if(!i2c_dev) {
			dprintf(CRITICAL, "qup_blsp_i2c_init failed \n");
			ASSERT(0);
		}

		ret = qrd_lcd_i2c_write(QRD_LCD_VPOS_ADDRESS, 0x0E); /* 5.4V */
		if (ret) {
			dprintf(CRITICAL, "VPOS Register: I2C Write failure\n");
		}

		ret = qrd_lcd_i2c_write(QRD_LCD_VNEG_ADDRESS, 0x0E); /* -5.4V */
		if (ret) {
			dprintf(CRITICAL, "VNEG Register: I2C write failure\n");
		}

		ret = qrd_lcd_i2c_write(QRD_LCD_DIS_ADDRESS, 0x0F);
		if (ret) {
			dprintf(CRITICAL, "Apps freq DIS Register: I2C write failure\n");
		}

		ret = qrd_lcd_i2c_write(QRD_LCD_CONTROL_ADDRESS, 0xF0);
		if (ret) {
			dprintf(CRITICAL, "Control Register: I2C write failure\n");
		}
	} else {
		gpio_set_dir(enp_gpio.pin_id, 0); /* ENP */
		gpio_set_dir(enn_gpio.pin_id, 0); /* ENN */
	}
	return 0;
}
Exemplo n.º 13
0
static int subcommand_gpio_dir(int argc, const char **argv) {
	/* > gpio dir $pin $dir(0:input, 1:output) */
	uint8_t pin;
	bool dir;

	if (argc < 3) {
		return -1;
	}

	pin = (uint8_t)atoi(argv[1]);
	if (pin >= MAX_PIN_NUMBER) {
		return -1;
	}
	dir = !!atoi(argv[2]);
	gpio_set_dir(pin, dir);

	uart_put_line("gpio dir set: pin=");
	uart_put_char(ascii_num_to_char(pin/10));
	uart_put_char(ascii_num_to_char(pin%10));
	uart_put_line(" dir=");
	uart_put_char(ascii_num_to_char(gpio_get_dir(pin)));
	uart_put_char('\n');

	return 0;
}
Exemplo n.º 14
0
int wm8350_gpio_config(struct wm8350 *wm8350, int gpio, int dir, int func,
		       int pol, int pull, int invert, int debounce)
{
	/* make sure we never pull up and down at the same time */
	if (pull == WM8350_GPIO_PULL_NONE) {
		if (gpio_set_pull_up(wm8350, gpio, 0))
			goto err;
		if (gpio_set_pull_down(wm8350, gpio, 0))
			goto err;
	} else if (pull == WM8350_GPIO_PULL_UP) {
		if (gpio_set_pull_down(wm8350, gpio, 0))
			goto err;
		if (gpio_set_pull_up(wm8350, gpio, 1))
			goto err;
	} else if (pull == WM8350_GPIO_PULL_DOWN) {
		if (gpio_set_pull_up(wm8350, gpio, 0))
			goto err;
		if (gpio_set_pull_down(wm8350, gpio, 1))
			goto err;
	}

	if (gpio_set_invert(wm8350, gpio, invert))
		goto err;
	if (gpio_set_polarity(wm8350, gpio, pol))
		goto err;
	if (gpio_set_debounce(wm8350, gpio, debounce))
		goto err;
	if (gpio_set_dir(wm8350, gpio, dir))
		goto err;
	return gpio_set_func(wm8350, gpio, func);

err:
	return -EIO;
}
Exemplo n.º 15
0
void gpio_init (uint32_t dir) {
    // Direction: 1=Output, 0=Input
    gpio_set_irq_mask (0x00000000);
    gpio_set_dir (dir);
    gpio_set_data (0x00000000);
    enable_io_pad();
}
void setup_pins(void){
	gpio_export(valve2Pin);
	gpio_set_dir(valve2Pin, OUTPUT);
	gpio_export(valve3Pin);
	gpio_set_dir(valve3Pin, OUTPUT);
	gpio_export(valve4Pin);
	gpio_set_dir(valve4Pin, OUTPUT);
	gpio_export(pump2Pin);
	gpio_set_dir(pump2Pin, OUTPUT);

	/* Turn on valves & pump2 */
	gpio_set_value(valve2Pin, LOW);
	gpio_set_value(valve3Pin, LOW);
	gpio_set_value(valve4Pin, LOW);
	gpio_set_value(pump2Pin, LOW);
}
Exemplo n.º 17
0
static int arduino_open(PROGRAMMER * pgm, char * port)
{
    union pinfo pinfo;
    strcpy(pgm->port, port);
    pinfo.baud = pgm->baudrate? pgm->baudrate: 115200;
    if (serial_open(port, pinfo, &pgm->fd)==-1) {
        return -1;
    }
#ifdef CUSTOMER_REST_PIN
    gpio_export(pgm->reset_pin);
    gpio_set_dir(pgm->reset_pin, OUT);
    gpio_set_value(pgm->reset_pin,LOW);
    usleep(250*1000);
    gpio_set_value(pgm->reset_pin,HIGH);
    usleep(50*1000);
#else

    /* Clear DTR and RTS to unload the RESET capacitor
     * (for example in Arduino) */
    serial_set_dtr_rts(&pgm->fd, 0);
    usleep(250*1000);
    /* Set DTR and RTS back to high */
    serial_set_dtr_rts(&pgm->fd, 1);
    usleep(50*1000);
#endif
    /*
     * drain any extraneous input
     */
    stk500_drain(pgm, 0);

    if (stk500_getsync(pgm) < 0)
        return -1;

    return 0;
}
Exemplo n.º 18
0
void timer0_setup(void)
{

  gpio_set_dir(0,22, 1);
  gpio_set_pin(0,22,1);


  PCONP |= (1 << 1);   // Habilitar Timer 0 Pag 63
  PCLKSEL0 &= ~(3 << 2);  // Clock for timer: CCLK/4.... 25MHz


  TIMER0->TCR_ENABLED = 0;    // Apago el temporizador
  TIMER0->TCR_RESET = 1;      // Reseteo el temporizador

  TIMER0->PR = 25; //1Mhz    3125;      //25MHz/3125 = 8kHz
  TIMER0->PC = 0;
  TIMER0->MR0 = 1;      // match0 a 8kHz
  TIMER0->TC = 0;

  TIMER0->MCR = 0x00;     // Aseguro la condición de arranque
  TIMER0->MCR_MR0I = 1;   // Interrupt on Match0
  TIMER0->MCR_MR0R = 1;   // Reset on Match0


  ISER0 |= (0x00000001)<<  1;  // Habilito interrupcion del Timer0

  TIMER0->TCR_RESET = 0;      // Apago el bit de RESET
  TIMER0->TCR_ENABLED = 1;    // Enciendo el temporizador

}
Exemplo n.º 19
0
/****************************************************************
 * Main
 ****************************************************************/
int main()
{
    int gpio_fd;
	unsigned int gpio = 68;
	   
    //i2c_init();
    
    //system("chmod 777 /sys/class/gpio");
#if 0    
    system("chmod 777 /sys/class/gpio/export");
    system("echo 68 > export");
    system("chmod 777 /sys/class/gpio/gpio68/direction");
    system("chmod 777 /sys/class/gpio/gpio68/edge");
    system("chmod 777 /sys/class/gpio/gpio68/value");

	gpio_export(gpio);
	gpio_set_dir(gpio, 0);
	gpio_set_edge(gpio, "rising");
	
	gpio_fd = gpio_fd_open(gpio);
	gpio_fd_close(gpio_fd);
#endif
    printf("main finished!");
    	
	return 0;
}
Exemplo n.º 20
0
JNIEXPORT jint JNICALL Java_com_robot_et_core_hardware_wakeup_WakeUp_faceWakeUpInit
(JNIEnv *env, jclass cls)
{
    int gpio;
    
    system("setenforce 0");
    system("chmod 777 /sys/class/gpio");
    system("chmod 777 /sys/class/gpio/export");
    system("echo 72 > /sys/class/gpio/export");
    system("chmod 777 /sys/class/gpio/gpio72");
    system("chmod 777 /sys/class/gpio/gpio72/direction");
    system("chmod 777 /sys/class/gpio/gpio72/edge");
    system("chmod 777 /sys/class/gpio/gpio72/value");    
    
    gpio = GPIO_C8;
    
    gpio_export(gpio);
    gpio_set_dir(gpio, 0);
    gpio_set_edge(gpio, (char*)"rising");
    gpioC8_fileId = gpio_fd_open(gpio);
    if (gpioC8_fileId < 0)
    {
        return WAKEUP_FAIL;        
    }

    return gpioC8_fileId;    
}
Exemplo n.º 21
0
JNIEXPORT jint JNICALL Java_com_robot_et_core_hardware_wakeup_WakeUp_wakeUpInit
(JNIEnv *env, jclass cls)
{
    int gpio;
    int ret;

    /* i2c init */
    ret = i2c_init();
    if (ret < 0)
    {
        return ret;
    }

    system("setenforce 0");
    system("chmod 777 /sys/class/gpio");
    system("chmod 777 /sys/class/gpio/export");
    system("echo 68 > /sys/class/gpio/export");
    system("chmod 777 /sys/class/gpio/gpio68");
    system("chmod 777 /sys/class/gpio/gpio68/direction");
    system("chmod 777 /sys/class/gpio/gpio68/edge");
    system("chmod 777 /sys/class/gpio/gpio68/value");

    gpio = GPIO_C4;

    gpio_export(gpio);
    gpio_set_dir(gpio, 0);
    gpio_set_edge(gpio, (char*)"rising");
    gpioC4_fileId = gpio_fd_open(gpio);
    if (gpioC4_fileId < 0)
    {
        return WAKEUP_FAIL;        
    }

    return gpioC4_fileId;
}
//// MPU9150 IMU ////
int initialize_imu(int sample_rate, signed char orientation[9]){
	printf("Initializing IMU\n");
	//set up gpio interrupt pin connected to imu
	if(gpio_export(INTERRUPT_PIN)){
		printf("can't export gpio %d \n", INTERRUPT_PIN);
		return (-1);
	}
	gpio_set_dir(INTERRUPT_PIN, INPUT_PIN);
	gpio_set_edge(INTERRUPT_PIN, "falling");  // Can be rising, falling or both
		
	linux_set_i2c_bus(1);

	
	if (mpu_init(NULL)) {
		printf("\nmpu_init() failed\n");
		return -1;
	}
 
	mpu_set_sensors(INV_XYZ_GYRO | INV_XYZ_ACCEL | INV_XYZ_COMPASS);
	mpu_set_sample_rate(sample_rate);
	
	// compass run at 100hz max. 
	if(sample_rate > 100){
		// best to sample at a fraction of the gyro/accel
		mpu_set_compass_sample_rate(sample_rate/2);
	}
	else{
		mpu_set_compass_sample_rate(sample_rate);
	}
	mpu_set_lpf(188); //as little filtering as possible
	dmp_load_motion_driver_firmware(sample_rate);

	dmp_set_orientation(inv_orientation_matrix_to_scalar(orientation));
  	dmp_enable_feature(DMP_FEATURE_6X_LP_QUAT | DMP_FEATURE_SEND_RAW_ACCEL 
						| DMP_FEATURE_SEND_CAL_GYRO | DMP_FEATURE_GYRO_CAL);

	dmp_set_fifo_rate(sample_rate);
	
	if (mpu_set_dmp_state(1)) {
		printf("\nmpu_set_dmp_state(1) failed\n");
		return -1;
	}
	if(loadGyroCalibration()){
		printf("\nGyro Calibration File Doesn't Exist Yet\n");
		printf("Use calibrate_gyro example to create one\n");
		printf("Using 0 offset for now\n");
	};
	
	// set the imu_interrupt_thread to highest priority since this is used
	// for real-time control with time-sensitive IMU data
	set_imu_interrupt_func(&null_func);
	pthread_t imu_interrupt_thread;
	struct sched_param params;
	pthread_create(&imu_interrupt_thread, NULL, imu_interrupt_handler, (void*) NULL);
	params.sched_priority = sched_get_priority_max(SCHED_FIFO);
	pthread_setschedparam(imu_interrupt_thread, SCHED_FIFO, &params);
	
	return 0;
}
Exemplo n.º 23
0
void export_All_GPIO()
{
	gpio_export(DISPL_PWRDWN);
	gpio_export(INTERRUPT_DISPL);
	gpio_export(ADC_BUF);
	gpio_export(PROTOCOL_SELECT);

	gpio_set_dir(DISPL_PWRDWN, OUTPUT);
	gpio_set_dir(INTERRUPT_DISPL, INPUT);
	gpio_set_dir(ADC_BUF, OUTPUT);
	gpio_set_dir(PROTOCOL_SELECT, OUTPUT);

	gpio_set_value(ADC_BUF, HIGH);
	gpio_set_value(DISPL_PWRDWN, HIGH);
	gpio_set_value(PROTOCOL_SELECT, IONET);

}
Exemplo n.º 24
0
void gpio_test_read(void)
{
	int i, d;

#ifdef RALINK_GPIO_HAS_5124
	gpio_set_dir(gpio5140, gpio_in);
	gpio_read_int(gpio5140, &d);
	printf("gpio 51~40 = 0x%x\n", d);

	gpio_set_dir(gpio3924, gpio_in);
	gpio_read_int(gpio3924, &d);
	printf("gpio 39~24 = 0x%x\n", d);
#endif
	gpio_set_dir(gpio2300, gpio_in);
	gpio_read_int(gpio2300, &d);
	printf("gpio 23~00 = 0x%x\n", d);
}
Exemplo n.º 25
0
void keyboard_setup(void){

#ifdef USE_SW1_WITH_INTERRUPTS
  // Configuro el SW1 para que trabaje como EINT0
  // Esto debe hacerse con la interrupcion deshabilitada
  set_pin_sel(EINT0_PIN, 1);
  // Configuro la interrupcion externa 0 por flanco
  EXTMODE0_F;
  // Habilito Interrupcion Externa 0
  ISE_EINT0;
#endif

#ifdef USE_SW4_WITH_INTERRUPTS
  // Configuro el SW4 para que trabaje como EINT3
  // Esto debe hacerse con la interrupcion deshabilitada
  set_pin_sel(EINT3_PIN, 1);
  // Configuro la interrupcion externa 0 por flanco
  EXTMODE0_F;
  // Habilito Interrupcion Externa 0
  ISE_EINT3;
#endif

#ifdef USE_SW1_WITH_POLLING
  set_pin_sel( KEY_PIN(0),0);
  gpio_set_dir(KEY_PIN(0),0);
#endif
#ifdef USE_SW2_WITH_POLLING
  set_pin_sel( KEY_PIN(1),0);
  gpio_set_dir(KEY_PIN(1),0);
#endif
#ifdef USE_SW3_WITH_POLLING
  set_pin_sel( KEY_PIN(2),0);
  gpio_set_dir(KEY_PIN(2),0);
#endif
#ifdef USE_SW4_WITH_POLLING
  set_pin_sel( KEY_PIN(3),0);
  gpio_set_dir(KEY_PIN(3),0);
#endif


#ifdef USE_SW_WITH_POLLING
  systick_delay_async(20, 1,keyboard_refresh);
#endif

}
Exemplo n.º 26
0
void KeyInit(void) {

    syscon_ahb_enable(SYSCON_CLK_IOCON);
    /* p0_1 4 */
    LPC_IOCON->PIO0_1 |= IOCON_FUNC0;
    syscon_ahb_enable(SYSCON_CLK_GPIO);
    gpio_set_dir(LPC_GPIO0, 1, GPIO_IN);
    
}
Exemplo n.º 27
0
int hwpl_gpio_setattr(int port, void * ctl){
	gpio_attr_t * ctlp = (gpio_attr_t*)ctl;

	//set the input pins as input
	gpio_clr_dir(port, ctlp->input);

	//set output pins as output
	gpio_set_dir(port, ctlp->output);

	return 0;
}
Exemplo n.º 28
0
void DoorInit(void) {

    syscon_ahb_enable(SYSCON_CLK_IOCON);
    // p1_0 INPUT
    LPC_IOCON->R_PIO1_0 = (IOCON_FUNC1|IOCON_MODE_PULLDOWN|IOCON_DIGMODE_EN);
    syscon_ahb_enable(SYSCON_CLK_GPIO);    
    gpio_set_dir(LPC_GPIO1, 0, GPIO_IN);

    door.sta = DOOR_STA_NONE;
    door.tick = 0;
    
}
Exemplo n.º 29
0
int gpio_input_trap_proc()
{
    int shutdown_fd = -1;
    int gpio_shutdown;
    char *buf[MAX_BUF];
    fd_set exceptfds;
    int res;

    gpio_shutdown = GetGpioNumberByFuncName("shutdownSwitch");

    if (-1 != gpio_shutdown) {
        LOG(LOG_NOTICE, "set shutdownSwitch on GPIO %d", gpio_shutdown);
        gpio_export(gpio_shutdown);
        gpio_set_dir(gpio_shutdown, 2);
        gpio_set_value(gpio_shutdown, 1);
        gpio_set_edge(gpio_shutdown, "both");
        //shutdown_fd = gpio_fd_open(gpio_shutdown);
    } else {
        LOG(LOG_NOTICE, "No set shutdownSwitch on GPIO pin");
        return 0;
    }

    // Trap an output GPIO is restric by GPIO driver in Linux kernel
    //   https://github.com/torvalds/linux/commit/d468bf9ecaabd3bf3a6134e5a369ced82b1d1ca1
    // /var/log/kern.log shows:
    //    GPIO chip pinctrl-bcm2835: gpio_lock_as_irq: tried to flag a GPIO set as output for IRQ
    //    gpio-18 (sysfs): failed to flag the GPIO for IRQ
    // But with dummy read() it still works, however if we use poll() to trap POLLPRI
    // system could freeze (could be kernel bugs)
    while (1) {
        shutdown_fd = gpio_fd_open(gpio_shutdown);

        FD_ZERO(&exceptfds);
        FD_SET(shutdown_fd, &exceptfds);
        read(shutdown_fd, buf, MAX_BUF); //dummy read(); any newly opened file is considered changed.

        res = select(shutdown_fd+1,
                     NULL,               // readfds - not needed
                     NULL,               // writefds - not needed
                     &exceptfds,
                     NULL);              // timeout (never)
        if (res > 0 && FD_ISSET(shutdown_fd, &exceptfds)) {
            if (gpio_get_value(gpio_shutdown) == 0) {
                LOG(LOG_NOTICE, "get shutdown signal from GPIO %d", gpio_shutdown);
                Shutdown();
            }
        }
        gpio_fd_close(shutdown_fd);
        read(shutdown_fd, buf, MAX_BUF);
    }

    return 0;
}
static int target_panel_reset_skuk(uint8_t enable)
{
	if (enable) {
		/* for tps65132 ENP pin*/
		gpio_tlmm_config(enp_gpio_skuk.pin_id, 0,
			enp_gpio_skuk.pin_direction, enp_gpio_skuk.pin_pull,
			enp_gpio_skuk.pin_strength, enp_gpio_skuk.pin_state);
		gpio_set_dir(enp_gpio_skuk.pin_id, 2);

		/* for tps65132 ENN pin*/
		gpio_tlmm_config(enn_gpio_skuk.pin_id, 0,
			enn_gpio_skuk.pin_direction, enn_gpio_skuk.pin_pull,
			enn_gpio_skuk.pin_strength, enn_gpio_skuk.pin_state);
		gpio_set_dir(enn_gpio_skuk.pin_id, 2);

		/* configure backlight gpio for SKUK */
		gpio_tlmm_config(bkl_gpio_skuk.pin_id, 0,
			bkl_gpio_skuk.pin_direction, bkl_gpio_skuk.pin_pull,
			bkl_gpio_skuk.pin_strength, bkl_gpio_skuk.pin_state);
		gpio_set_dir(bkl_gpio_skuk.pin_id, 2);
	} else {
		gpio_set_dir(bkl_gpio_skuk.pin_id, 0);
		gpio_set_dir(enp_gpio_skuk.pin_id, 0); /* ENP */
		gpio_set_dir(enn_gpio_skuk.pin_id, 0); /* ENN */
	}
	return 0;
}