Exemple #1
0
static void motor_set(s16_t left, s16_t right) {
  if (left == 0) {
    gpio_disable(MOTORA_PORT, MOTORAIN1_PIN);
    gpio_disable(MOTORA_PORT, MOTORAIN2_PIN);
    set_motora_pwm_duty_cycle(MOTOR_PERIOD);
  } else {
    if (left > 0) {
      gpio_enable(MOTORA_PORT, MOTORAIN1_PIN);
      gpio_disable(MOTORA_PORT, MOTORAIN2_PIN);
    } else {
      gpio_disable(MOTORA_PORT, MOTORAIN1_PIN);
      gpio_enable(MOTORA_PORT, MOTORAIN2_PIN);
      left = -left;
    }
    set_motora_pwm_duty_cycle((MOTOR_PERIOD*left)/128);
  }
  if (right == 0) {
    gpio_disable(MOTORB_PORT, MOTORBIN1_PIN);
    gpio_disable(MOTORB_PORT, MOTORBIN2_PIN);
    set_motorb_pwm_duty_cycle(MOTOR_PERIOD);
  } else {
    if (right > 0) {
      gpio_enable(MOTORB_PORT, MOTORBIN1_PIN);
      gpio_disable(MOTORB_PORT, MOTORBIN2_PIN);
    } else {
      gpio_disable(MOTORB_PORT, MOTORBIN1_PIN);
      gpio_enable(MOTORB_PORT, MOTORBIN2_PIN);
      right = -right;
    }
    set_motorb_pwm_duty_cycle((MOTOR_PERIOD*right)/128);
  }
}
void user_init(void)
{
    uart_set_baud(0, 115200);

    /* configure GPIOs */
    gpio_enable(gpio_frc1, GPIO_OUTPUT);
    gpio_enable(gpio_frc2, GPIO_OUTPUT);
    gpio_write(gpio_frc1, 1);

    /* stop both timers and mask their interrupts as a precaution */
    timer_set_interrupts(FRC1, false);
    timer_set_run(FRC1, false);
    timer_set_interrupts(FRC2, false);
    timer_set_run(FRC2, false);

    /* set up ISRs */
    _xt_isr_attach(INUM_TIMER_FRC1, frc1_interrupt_handler);
    _xt_isr_attach(INUM_TIMER_FRC2, frc2_interrupt_handler);

    /* configure timer frequencies */
    timer_set_frequency(FRC1, freq_frc1);
    timer_set_frequency(FRC2, freq_frc2);

    /* unmask interrupts and start timers */
    timer_set_interrupts(FRC1, true);
    timer_set_run(FRC1, true);
    timer_set_interrupts(FRC2, true);
    timer_set_run(FRC2, true);

    gpio_write(gpio_frc1, 0);
}
Exemple #3
0
int main(int argc, char **argv) {

	int value1,value2;

	printf("Gumstix GPIO test\n");

	gpio_enable(146);
	gpio_enable(147);

	gpio_set_write(146);
	gpio_set_write(147);

	value1=gpio_read(146);
	value2=gpio_read(147);

	value2=!value1;

	while(1){
		gpio_write(146,value1);
		gpio_write(147,value2);

		value1=!value1;
		value2=!value2;
		usleep(500000);

	}

	return 0;
}
Exemple #4
0
void user_init(void)
{
    uart_set_baud(0, 115200);
    gpio_enable(gpio, GPIO_INPUT);
    gpio_enable(gpio_blink, GPIO_OUTPUT);

    tsqueue = xQueueCreate(2, sizeof(uint32_t));
    xTaskCreate(buttonIntTask, (signed char *)"buttonIntTask", 256, &tsqueue, 2, NULL);
    xTaskCreate(buttonPollTask, (signed char*)"buttonPollTask", 256, NULL, 1, NULL);
}
Exemple #5
0
void platform_leds_setup(void)
{
    gpio_enable(LED_0_PORT);
    gpio_enable(LED_1_PORT);
    gpio_enable(LED_2_PORT);

    // Set output pins B10 and B12
    gpio_set_output(LED_0_PORT, LED_0_PIN);
    gpio_set_output(LED_1_PORT, LED_1_PIN);
    gpio_set_output(LED_2_PORT, LED_2_PIN);

    // Clear LEDs
    leds_arch_set(0);
}
Exemple #6
0
void delta_sigma_start(uint32_t period, uint32_t range, uint8_t pins[],
                       uint8_t n_pins)
{
  // Stop the timer during configuration
  timer_set_run(FRC1, false);

  g_n_pins = n_pins;
  for (uint8_t i = 0; i < n_pins; ++i)
  {
    g_pins[i].gpio_mask = BIT(pins[i]);
    g_pins[i].duty = 0;
    g_pins[i].acc = 0;
    gpio_enable(pins[i], GPIO_OUTPUT);
  }
  g_range = range;

  timer_set_interrupts(FRC1, false);
  timer_set_divider(FRC1, TIMER_CLKDIV_256);
  if (period > TIMER_FRC1_MAX_LOAD)
  {
    printf("delta_sigma: period %u too large\n", period);
    period = TIMER_FRC1_MAX_LOAD;
  }
  timer_set_load(FRC1, period);
  timer_set_reload(FRC1, true);
  _xt_isr_attach(INUM_TIMER_FRC1, timer_isr, NULL);
  timer_set_interrupts(FRC1, true);
  timer_set_run(FRC1, true);
}
Exemple #7
0
uint32_t gpio_set(PinName pin) {
    
    if (!gpio_enabled)
         gpio_enable();
    
    return (1UL << ((int)pin & 0x1f));
}
Exemple #8
0
static void gpio_drivers_setup()
{
    // Set base address and AHB bit for all GPIO ports
    gpio_enable(GPIO_A);
    gpio_enable(GPIO_B);
    gpio_enable(GPIO_C);
    gpio_enable(GPIO_D);
    gpio_enable(GPIO_E);
    gpio_enable(GPIO_F);
    gpio_enable(GPIO_G);
    gpio_enable(GPIO_H);
    gpio_enable(GPIO_I);
}
Exemple #9
0
/* This task uses the high level GPIO API (esp_gpio.h) to blink an LED.
 *
 */
void blinkenTask(void *pvParameters)
{
    gpio_enable(gpio, GPIO_OUTPUT);
    while(1) {
        gpio_write(gpio, 1);
        vTaskDelay(1000 / portTICK_RATE_MS);
        gpio_write(gpio, 0);
        vTaskDelay(1000 / portTICK_RATE_MS);
    }
}
Exemple #10
0
void MOTOR_go(s8_t x) {
  if (x == 0) {
    motor_stop();
    return;
  } else if (x > 0) {
    gpio_enable(MOTORA_PORT, MOTORAIN1_PIN);
    gpio_disable(MOTORA_PORT, MOTORAIN2_PIN);
    gpio_enable(MOTORB_PORT, MOTORBIN1_PIN);
    gpio_disable(MOTORB_PORT, MOTORBIN2_PIN);
  } else if (x < 0) {
    gpio_disable(MOTORA_PORT, MOTORAIN1_PIN);
    gpio_enable(MOTORA_PORT, MOTORAIN2_PIN);
    gpio_disable(MOTORB_PORT, MOTORBIN1_PIN);
    gpio_enable(MOTORB_PORT, MOTORBIN2_PIN);
    x = -x;
  }
  set_motora_pwm_duty_cycle((MOTOR_PERIOD*x)/128);
  set_motorb_pwm_duty_cycle((MOTOR_PERIOD*x)/128);
}
Exemple #11
0
uint32_t gpio_set(PinName pin) {
    int f = 0;
    
    if (!gpio_enabled)
         gpio_enable();
    
    pin_function(pin, f);
    
    return (1 << ((int)pin & 0x1F));
}
Exemple #12
0
void platform_drivers_setup()
{
    // Set base address and AHB bit for all GPIO ports
    gpio_enable(GPIO_A);
    gpio_enable(GPIO_B);
    gpio_enable(GPIO_C);
    gpio_enable(GPIO_D);

    // Enable the AFIO
    rcc_apb_enable(RCC_APB_BUS_AFIO, RCC_APB_BIT_AFIO);

    // Start the TIM3 at ~32kHz
    timer_enable(TIM_3);
    timer_select_internal_clock(TIM_3, (rcc_sysclk_get_clock_frequency(
                                           RCC_SYSCLK_CLOCK_PCLK1_TIM) / 32768) - 1);
    timer_start(TIM_3, 0xFFFF, NULL, NULL);

    // Enable the print uart
    gpio_set_uart_tx(GPIO_A, GPIO_PIN_9);
    gpio_set_uart_rx(GPIO_A, GPIO_PIN_10);
    uart_enable(UART_1, PLATFORM_UART_PRINT_BAUDRATE);

    // Configure the DMA for the SPIs
    dma_enable(DMA_1_CH4);
    dma_enable(DMA_1_CH5);

    // Configure the SPI 2
    gpio_set_spi_clk(GPIO_B, GPIO_PIN_13);
    gpio_set_spi_miso(GPIO_B, GPIO_PIN_14);
    gpio_set_spi_mosi(GPIO_B, GPIO_PIN_15);
    spi_set_dma(SPI_2, DMA_1_CH4, DMA_1_CH5);
    spi_enable(SPI_2, 4000000, SPI_CLOCK_MODE_IDLE_LOW_RISING);

    // Configure the I2C 1
    gpio_set_i2c_scl(GPIO_B, GPIO_PIN_6);
    gpio_set_i2c_sda(GPIO_B, GPIO_PIN_7);
    i2c_enable(I2C_1, I2C_CLOCK_MODE_FAST);

    // Force inclusion of EXTI
    exti_set_handler(EXTI_LINE_Px0, NULL, NULL);
}
Exemple #13
0
static void pixcir_reset(struct pixcir_data *pixcir)
{
    gpio_enable(pixcir->rgp_idx, pixcir->rgp_bit, OUTPUT);
    gpio_set_value(pixcir->rgp_idx, pixcir->rgp_bit, LOW);
    mdelay(5);
    gpio_set_value(pixcir->rgp_idx, pixcir->rgp_bit, HIGH);
    mdelay(10);
    gpio_set_value(pixcir->rgp_idx, pixcir->rgp_bit, LOW);
    mdelay(5);

    return;
}
Exemple #14
0
 /**
  * 
  * @param gpio_num
  * @param direction
  * @return 
  */
 int enable(uint8_t gpio_num, gpio_direction_t direction)
 {
     if(m_Valid.pinIsValid(gpio_num) == 0) {
         m_GpioStat[gpio_num].gpio_direction = direction;
         
         gpio_enable(gpio_num, direction);
     }
     else {
         return -1;
     }
     
     return 0;
 }
Exemple #15
0
static void cmd_off(uint32_t argc, char *argv[])
{
    if (argc >= 2) {
        for(int i=1; i<argc; i++) {
            uint8_t gpio_num = atoi(argv[i]);
            gpio_enable(gpio_num, GPIO_OUTPUT);
            gpio_write(gpio_num, false);
            printf("Off %d\n", gpio_num);
        }
    } else {
        printf("Error: missing gpio number.\n");
    }
}
Exemple #16
0
void platform_leds_setup()
{
    // Configure the LEDs
    // Enable port B
    gpio_enable(GPIO_B);

    // Set output pins B10 and B12
    gpio_set_output(GPIO_B, GPIO_PIN_10);
    gpio_set_output(GPIO_B, GPIO_PIN_12);

    // Clear LEDs
    leds_off(LED_0 + LED_1);
}
Exemple #17
0
/* Set gpio direction to output and pull HIGH or LOW  */
static void pch_gpio_config(int gpio, int level, unsigned int gpio_base_addr)
{
	unsigned long int gpio_use_sel_addr, gp_io_sel_addr, gp_lvl_addr;
	int new_gpio;

	/* Set gpio_out direction to output and pull low or high. */
	new_gpio = gpio_setup_addr(&gpio_use_sel_addr, &gp_io_sel_addr, \
                               &gp_lvl_addr, gpio, gpio_base_addr);
	gpio_enable(gpio_use_sel_addr, new_gpio);
	gpio_dir_out(gp_io_sel_addr, gp_lvl_addr, new_gpio, level);

	DBG("gpio_sel_addr = %x, gp_lvl_addr =%x\n", gp_io_sel_addr, gp_lvl_addr);
	printf("Set GPIO[%d] Level to %s\n", gpio, level ? "HIGH" : "LOW");
}
Exemple #18
0
extern void uart_enable(UART_CLASS port, UART_CB *cb, void *param, int priority)
{
	if (port < UARTS_COUNT)
	{
		UART_HW* uart = (UART_HW*)sys_alloc(sizeof(UART_HW));
		if (uart)
		{
			_uart_handlers[port] = uart;
			uart->cb = cb;
			uart->param = param;
			uart->read_buf = NULL;
			uart->write_buf = NULL;
			uart->read_size = 0;
			uart->write_size = 0;
			//setup pins
#if defined(STM32F1)
			if ((USART_TX_DISABLE_MASK & (1 << port)) == 0)
				gpio_enable_afio(UART_TX_PINS[port], AFIO_MODE_PUSH_PULL);
			if ((USART_RX_DISABLE_MASK & (1 << port)) == 0)
				gpio_enable(UART_RX_PINS[port]);
#if (USART_REMAP_MASK)
			if ((1 << port) & USART_REMAP_MASK)
				afio_remap();
#endif //USART_REMAP_MASK
#elif defined(STM32F2)
			if ((USART_TX_DISABLE_MASK & (1 << port)) == 0)
				gpio_enable_afio(UART_TX_PINS[port], port < UART_4 ? AFIO_MODE_USART1_2_3 : AFIO_MODE_UART_4_5_USART_6);
			if ((USART_RX_DISABLE_MASK & (1 << port)) == 0)
				gpio_enable_afio(UART_RX_PINS[port], port < UART_4 ? AFIO_MODE_USART1_2_3 : AFIO_MODE_UART_4_5_USART_6);
#endif

			//power up
			if (port == UART_1 || port == UART_6)
				RCC->APB2ENR |= RCC_UART[port];
			else
				RCC->APB1ENR |= RCC_UART[port];

			//enable interrupts
			NVIC_EnableIRQ(UART_IRQ_VECTORS[port]);
			NVIC_SetPriority(UART_IRQ_VECTORS[port], priority);

			USART[port]->CR1 |= USART_CR1_UE;
		}
		else
			error_dev(ERROR_MEM_OUT_OF_SYSTEM_MEMORY, DEV_UART, port);
	}
	else
		error_dev(ERROR_DEVICE_INDEX_OUT_OF_RANGE, DEV_UART, port);
}
Exemple #19
0
static void pixcir_late_resume(struct early_suspend *handler)
{
    struct pixcir_data *pixcir = container_of(handler, struct pixcir_data, early_suspend);

    pixcir_reset(pixcir);
    msleep(200);
    pixcir_active(pixcir);
    
    pixcir->earlysus = 0;

    gpio_enable(pixcir->igp_idx, pixcir->igp_bit,INPUT);
    gpio_pull_enable(pixcir->igp_idx, pixcir->igp_bit, PULL_UP);
    gpio_setup_irq(pixcir->igp_idx, pixcir->igp_bit, IRQ_FALLING);
    
    return;
}
Exemple #20
0
void platform_usb_enable()
{
    // gpio_enable(GPIO_A);
    // gpio_set_alternate_function(GPIO_A, GPIO_PIN_11, GPIO_AF_10);
    // gpio_set_alternate_function(GPIO_A, GPIO_PIN_12, GPIO_AF_10);

    // external pull-up
    gpio_enable(GPIO_B);
    gpio_set_output(GPIO_B, GPIO_PIN_5);
    gpio_pin_set(GPIO_B, GPIO_PIN_5);
    // internal pull-up

    //syscfg_pmc_config(SYSCFG_PMC_USB, 1);

    nvic_enable_interrupt_line(NVIC_IRQ_LINE_USB_LP);
}
Exemple #21
0
void dmw_amoled_init(void)
{
	amoled_spi = spi_setup_slave(CONFIG_DMW_AMOLED_SPI_UNIT, CONFIG_DMW_GPIO_AMOLED_CS, 0, 0);
	gpio_direction_output(CONFIG_DMW_GPIO_AMOLED_RESET, LED_ACTIVE);
	gpio_enable(CONFIG_DMW_GPIO_AMOLED_RESET);

	dmw_amoled_reset();

	amoled_write_simple_command(amoled_spi, 0x31, 0x08); // SCTE set
	amoled_write_simple_command(amoled_spi, 0x32, 0x14); // SCWE set
	amoled_write_simple_command(amoled_spi, 0x30, 0x02); // Gateless signal
	amoled_write_simple_command(amoled_spi, 0x27, 0x01); // Gateless signal

	/* Display condition set */
	amoled_write_simple_command(amoled_spi, 0x12, 0x08); // VBP set
	amoled_write_simple_command(amoled_spi, 0x13, 0x08); // VFP set
	amoled_write_simple_command(amoled_spi, 0x15, 0x00); // Display con
	amoled_write_simple_command(amoled_spi, 0x16, 0x00); // Color depth set

	amoled_pentile_key(amoled_spi);

	amoled_write_simple_command(amoled_spi, 0x39, 0x44); // Gamma set select

	/* Normal gamma table */
	amoled_run_sequence(amoled_spi, amoled_gamma_table_l_220);

	/* Analog power condition set */
	amoled_write_simple_command(amoled_spi, 0x17, 0x22); // VBP set
	amoled_write_simple_command(amoled_spi, 0x18, 0x33); // VFP set
	amoled_write_simple_command(amoled_spi, 0x19, 0x03); // Display con
	amoled_write_simple_command(amoled_spi, 0x1A, 0x01); // Color depth set
	amoled_write_simple_command(amoled_spi, 0x22, 0xA4);
	amoled_write_simple_command(amoled_spi, 0x23, 0x00); // Gamma set select
	amoled_write_simple_command(amoled_spi, 0x26, 0xA0); // Gamma set select

	/* STB off */
	amoled_write_simple_command(amoled_spi, 0x1D, 0xA0);

	mdelay(100);

	/* Display ON */
	amoled_write_simple_command(amoled_spi, 0x14, 0x03);
}
Exemple #22
0
/* Set gpio blink register */
static int pch_gpio_blink_config(int gpio, int value, unsigned int gpio_base_addr)
{
	unsigned long int gpio_use_sel_addr, gp_io_sel_addr, gp_lvl_addr;
	int new_gpio;

	if (gpio > 31) /* only support GPIO0 to GPIO31 */
		return -1;

	/* Set gpio_out direction to output and pull low or high. */
	new_gpio = gpio_setup_addr(&gpio_use_sel_addr, &gp_io_sel_addr, \
                               &gp_lvl_addr, gpio, gpio_base_addr);
	gpio_enable(gpio_use_sel_addr, new_gpio);
	gpio_blink(gpio_base_addr, new_gpio, value);

	DBG("gpio_sel_addr = %x, gp_lvl_addr =%x\n", gp_io_sel_addr, gp_lvl_addr);
	printf("%s GPIO[%d] blink.\n", value ? "Enalbe" : "Disable", gpio);

	return 0;
}
static void
tdt320t2g706_reset(void)
{
	/* LCD_GPIO_RESET */
	gpio_enable(BGPIO(4));
	gpio_direction_output(BGPIO(4), 1);

	mdelay(1);

	gpio_set_value(BGPIO(4), 0);

	mdelay(10);

	gpio_set_value(BGPIO(4), 1);

	mdelay(50);

	return;
}
Exemple #24
0
int test_gpio_interruption(GPIO_CTRL *gp_ctrl)
{
	int iRet=0;
	/*init gpio interruption pin: input, low trigger, pull up, disable int*/
	gpio_enable(gp_ctrl, INPUT);
	set_gpio_irq_triger_mode(gp_ctrl, IRQ_LOW);
	gpio_pull_enable(gp_ctrl,PULL_UP);
	enable_gpio_int(gp_ctrl,INT_DIS);
	/*register interruption handler funciton*/
	iRet = request_irq(5, gpio_irq_handler, IRQF_SHARED, "gpio_int_test", gp_ctrl);
	if (iRet){
		printk("Request IRQ failed!ERRNO:%d.", iRet);
		return -1;
	}
	printk("register gpio interruption succesful\n");
	/*clear int status register*/
	gpio_clean_irq_status(gp_ctrl);
	/*enable interruption*/
	enable_gpio_int(gp_ctrl,INT_EN);
	printk("enable gpio int\n");
}
Exemple #25
0
void TIMER_irq() {
  if (TIM_GetITStatus(STM32_SYSTEM_TIMER, TIM_IT_Update) != RESET) {
    TIM_ClearITPendingBit(STM32_SYSTEM_TIMER, TIM_IT_Update);
    q++;
    if ((q & 0xffff) < 0x1ff) {
      gpio_enable(PORTF, PIN6);
    } else {
      gpio_disable(PORTF, PIN6);
    }
    bool ms_update = SYS_timer();
    if (ms_update) {
      TRACE_MS_TICK(SYS_get_time_ms() & 0xff);
    }
#ifdef CONFIG_TASK_QUEUE
    TASK_timer();
#endif
#ifdef CONFIG_OS
    if (ms_update) {
      __os_time_tick(SYS_get_time_ms());
    }
#endif
  }
}
Exemple #26
0
void pwm_init(uint8_t npins, uint8_t* pins)
{
    /* Assert number of pins is correct */
    if (npins > MAX_PWM_PINS)
    {
        printf("Incorrect number of PWM pins (%d)\n", npins);
        return;
    }

    /* Initialize */
    pwmInfo._maxLoad = 0;
    pwmInfo._onLoad = 0;
    pwmInfo._offLoad = 0;
    pwmInfo._step = PERIOD_ON;

    /* Save pins information */
    pwmInfo.usedPins = npins;

    uint8_t i = 0;
    for (; i < npins; ++i)
    {
        pwmInfo.pins[i].pin = pins[i];

        /* configure GPIOs */
        gpio_enable(pins[i], GPIO_OUTPUT);
    }

    /* Stop timers and mask interrupts */
    pwm_stop();

    /* set up ISRs */
    _xt_isr_attach(INUM_TIMER_FRC1, frc1_interrupt_handler);

    /* Flag not running */
    pwmInfo.running = 0;
}
Exemple #27
0
void server_task(void *p)
{
    bool camera_ok = false;

    // Power cycle the the camera
    gpio_enable(ARDUCAM_PWR, GPIO_OUTPUT);
    printf("Camera power cycle\n");
    gpio_write(ARDUCAM_PWR, 1);
    delay_ms(250);
    gpio_write(ARDUCAM_PWR, 0);
    delay_ms(250);

    camera_ok = arducam_setup();
    if (!camera_ok) {
        printf("Camera init failed!\n"); 
    }

    while (1) {
        struct sockaddr_in server_addr, client_addr;
        int server_sock, client_sock;
        socklen_t sin_size;
        bzero(&server_addr, sizeof(struct sockaddr_in));
        server_addr.sin_family = AF_INET;
        server_addr.sin_addr.s_addr = INADDR_ANY;
        server_addr.sin_port = htons(80);

        int recbytes;

        do {
            if (-1 == (server_sock = socket(AF_INET, SOCK_STREAM, 0))) {
                printf("Socket error\n");
                break;
            }

            if (-1 == bind(server_sock, (struct sockaddr *)(&server_addr), sizeof(struct sockaddr))) {
                printf("bind fail\n");
                break;
            }

            printf(" bind port: %d\n", ntohs(server_addr.sin_port));

            if (-1 == listen(server_sock, 5)) {
                printf("listen fail\n");
                break;
            }

            sin_size = sizeof(client_addr);

            for (;;) {
                if ((client_sock = accept(server_sock, (struct sockaddr *) &client_addr, &sin_size)) < 0) {
                    printf("accept fail\n");
                    continue;
                }

                printf("Client from %s:%d\n", inet_ntoa(client_addr.sin_addr), htons(client_addr.sin_port));

                int opt = 50;
                if (lwip_setsockopt(client_sock, SOL_SOCKET, SO_RCVTIMEO, &opt, sizeof(int)) < 0) {
                    printf("failed to set timeout on socket\n");
                }
                while ((recbytes = read(client_sock, buffer, BUF_SIZE)) > 0) {
                    buffer[recbytes] = 0;
                }

                sprintf(buffer, "HTTP/1.1 200 OK\nContent-Type: image/jpeg; charset=utf-8\nConnection: close\n\n");

                if (write(client_sock, buffer, strlen(buffer)) > 0) {
                    if (camera_ok) {
                        uint32_t retries = 4;
                        bool success;
                        while(retries--) {
                            success = arducam_capture();
                            if (success) {
                                break;
                            } else {
                                printf("Capture retry\n"); 
                                delay_ms(10); // Arbitrary value
                            }
                        }
                        if (success) {
                            printf("Reading fifo\n"); 
                            arudcam_fifo_to_socket(client_sock);
                            printf("---\n");
                        }
                    }
                }

                if (recbytes <= 0) {
                    close(client_sock);
                }
            }
        } while (0);
    }
}
Exemple #28
0
static int pixcir_probe(struct platform_device *pdev)
{
	int i;
    int err = 0;
	struct pixcir_data *pixcir = platform_get_drvdata(pdev);
    
	INIT_DELAYED_WORK(&pixcir->read_work, pixcir_read_work);
    pixcir->workqueue = create_singlethread_workqueue(pixcir->name);
	if (!pixcir->workqueue) {
		err = -ESRCH;
		goto exit_create_singlethread;
	}
    
    err = pixcir_sysfs_create_group(pixcir, &pixcir_group);
    if(err < 0){
        dbg("create sysfs group failed.\n");
        goto exit_create_group;
    }
    
	pixcir->input_dev = input_allocate_device();
	if (!pixcir->input_dev) {
		err = -ENOMEM;
		dbg("failed to allocate input device\n");
		goto exit_input_dev_alloc_failed;
	}
	
	pixcir->input_dev->name = pixcir->name;
	pixcir->input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
	set_bit(INPUT_PROP_DIRECT, pixcir->input_dev->propbit);

	input_set_abs_params(pixcir->input_dev,
			     ABS_MT_POSITION_X, 0, pixcir->xresl, 0, 0);
	input_set_abs_params(pixcir->input_dev,
			     ABS_MT_POSITION_Y, 0, pixcir->yresl, 0, 0);
    input_set_abs_params(pixcir->input_dev,
                 ABS_MT_TRACKING_ID, 0, 20, 0, 0);
#ifdef TOUCH_KEY 	
	for (i = 0; i <NUM_KEYS; i++)
		set_bit(keycodes[i], pixcir->input_dev->keybit);

	pixcir->input_dev->keycode = keycodes;
	pixcir->input_dev->keycodesize = sizeof(unsigned int);
	pixcir->input_dev->keycodemax = NUM_KEYS;
#endif
    pixcir->earlysus = 1;
	err = input_register_device(pixcir->input_dev);
	if (err) {
		dbg_err("pixcir_ts_probe: failed to register input device.\n");
		goto exit_input_register_device_failed;
	}
        
#ifdef CONFIG_HAS_EARLYSUSPEND
	pixcir->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
	pixcir->early_suspend.suspend = pixcir_early_suspend;
	pixcir->early_suspend.resume = pixcir_late_resume;
	register_early_suspend(&pixcir->early_suspend);
#endif
    
	if(request_irq(pixcir->irq, pixcir_isr_handler, IRQF_SHARED, pixcir->name, pixcir) < 0){
		dbg_err("Could not allocate irq for ts_pixcir !\n");
		err = -1;
		goto exit_register_irq;
	}	
	
    gpio_enable(pixcir->igp_idx, pixcir->igp_bit, INPUT);
    gpio_pull_enable(pixcir->igp_idx, pixcir->igp_bit, PULL_UP);
    gpio_setup_irq(pixcir->igp_idx, pixcir->igp_bit, IRQ_FALLING);
    
    pixcir_reset(pixcir);
    msleep(200);
    pixcir_active(pixcir);
    pixcir->earlysus = 0;
    
    return 0;
    
exit_register_irq:
	unregister_early_suspend(&pixcir->early_suspend);
exit_input_register_device_failed:
	input_free_device(pixcir->input_dev);
exit_input_dev_alloc_failed:
    pixcir_sysfs_remove_group(pixcir, &pixcir_group);
exit_create_group:
	cancel_delayed_work_sync(&pixcir->read_work);
	destroy_workqueue(pixcir->workqueue);  
exit_create_singlethread:
    //kfree(pixcir);
	return err;
}
Exemple #29
0
void interrupt_init(int pin, int changeType) {
    gpio_enable(pin, GPIO_INPUT);
    gpio_set_interrupt(pin, changeType);
}
Exemple #30
0
void CVIDEO_set_input(video_input_t input) {
  vid.input = input;
  if (input == INPUT_CAMERA || input == INPUT_NONE) {
    TIM_DeInit(TIM1);
    TIM_Cmd(TIM1, DISABLE);
    TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Disable);
    NVIC_DisableIRQ(TIM1_UP_IRQn);
    TIM_CtrlPWMOutputs(TIM1, DISABLE);

    if (input == INPUT_CAMERA) {
      if (VID_SEL_PINVAL_GEN) {
        gpio_disable(VID_SEL_PORT, VID_SEL_PIN);
      } else {
        gpio_enable(VID_SEL_PORT, VID_SEL_PIN);
      }
    } else {
      if (VID_SEL_PINVAL_GEN) {
        gpio_enable(VID_SEL_PORT, VID_SEL_PIN);
      } else {
        gpio_disable(VID_SEL_PORT, VID_SEL_PIN);
      }
    }

  } else {
    // INPUT_GENERATED

    TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;

    TIM_Cmd(TIM1, DISABLE);
    NVIC_DisableIRQ(TIM1_UP_IRQn);
    //TIM_DeInit(TIM1);

    if (VID_SEL_PINVAL_GEN) {
      gpio_enable(VID_SEL_PORT, VID_SEL_PIN);
    } else {
      gpio_disable(VID_SEL_PORT, VID_SEL_PIN);
    }

    TIM_TimeBaseStructure.TIM_Period = 4608;//SYS_CPU_FREQ / 15625;
    TIM_TimeBaseStructure.TIM_Prescaler = 1-1;
    TIM_TimeBaseStructure.TIM_ClockDivision = 0;
    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
    TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
    TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);

    TIM_OCInitTypeDef  TIM_OCInitStructure;
    TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
    TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
    TIM_OCInitStructure.TIM_Pulse = 4608/2;
    TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
    TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCPolarity_High;
    TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;
    TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Reset;

    TIM_OC1Init(TIM1, &TIM_OCInitStructure);
    TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable);

    TIM_ARRPreloadConfig(TIM1, DISABLE);

    TIM_ClearITPendingBit(TIM1,
        TIM_IT_Update | TIM_IT_CC1 | TIM_IT_CC2 | TIM_IT_CC3 | TIM_IT_CC4 |
        TIM_IT_COM | TIM_IT_Trigger | TIM_IT_Break);
    TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE);
    NVIC_EnableIRQ(TIM1_UP_IRQn);

    TIM_SetCounter(TIM1, 0);
    TIM_Cmd(TIM1, ENABLE);
    TIM_CtrlPWMOutputs(TIM1, ENABLE);
  }
}