Exemplo n.º 1
0
/* Configure GPIO pins to be used as LED and push button */
static void configure_gpios()
{
	mdev_t *pinmux_dev, *gpio_dev;

	/* Initialize  pinmux driver */
	pinmux_drv_init();

	/* Open pinmux driver */
	pinmux_dev = pinmux_drv_open("MDEV_PINMUX");

	/* Initialize GPIO driver */
	gpio_drv_init();

	/* Open GPIO driver */
	gpio_dev = gpio_drv_open("MDEV_GPIO");

	/* Configure GPIO pin function for GPIO connected to LED */
	pinmux_drv_setfunc(pinmux_dev, gpio_led, GPIO_LED_FN);

	/* Configure GPIO pin direction as Output */
	gpio_drv_setdir(gpio_dev, gpio_led, GPIO_OUTPUT);
	/* Keep initial state of LED: ON */
	gpio_drv_write(gpio_dev, gpio_led, 0);

	/* Close drivers */
	pinmux_drv_close(pinmux_dev);
	gpio_drv_close(gpio_dev);
}
/* Basic Sensor IO initialization to be done here

	This function will be called only once during sensor registration
 */
int ultrasonic_sensor_init(struct sensor_info *curevent)
{
	wmprintf("%s\r\n", __FUNCTION__);

	mdev_t *pinmux_dev, *gpio_dev;

	/* Initialize  pinmux driver */
	pinmux_drv_init();

	/* Open pinmux driver */
	pinmux_dev = pinmux_drv_open("MDEV_PINMUX");

	/* Initialize GPIO driver */
	gpio_drv_init();

	/* Open GPIO driver */
	gpio_dev = gpio_drv_open("MDEV_GPIO");

	/* Configure GPIO pin function for GPIO connected to LED */
	pinmux_drv_setfunc(pinmux_dev, ULTRASONIC_SEN_IO, ULTRASONIC_SEN_IO_GPIO);

	/* Confiugre GPIO pin direction as Input */
	gpio_drv_setdir(gpio_dev, ULTRASONIC_SEN_IO, GPIO_INPUT);

	/* Close drivers */
	pinmux_drv_close(pinmux_dev);
	gpio_drv_close(gpio_dev);

#ifdef ULTRASONIC_SENSOR_TEST
	check_ultrasonic_sensor();
#endif /* ULTRASONIC_SENSOR_TEST */

	return 0;
}
Exemplo n.º 3
0
/* This function turns off the LED*/
static void gpio_led_off(void)
{
	mdev_t *gpio_dev = gpio_drv_open("MDEV_GPIO");
	/* Turn off LED by writing  1 in GPIO register */
	gpio_drv_write(gpio_dev, gpio_led, 1);
	gpio_drv_close(gpio_dev);
}
Exemplo n.º 4
0
/* This function turns on the LED*/
static void gpio_led_on(void)
{
	mdev_t *gpio_dev = gpio_drv_open("MDEV_GPIO");
	/* Turn on LED by writing  0 in GPIO register */
	gpio_drv_write(gpio_dev, gpio_led, 0);
	gpio_drv_close(gpio_dev);
	gpio_led_state = 1;
}
Exemplo n.º 5
0
static void gpio_led_off(void)
{
	mdev_t *gpio_dev = gpio_drv_open("MDEV_GPIO");
	/* Turn off LED by writing  1 in GPIO register */
	gpio_drv_write(gpio_dev, gpio_led, 1);
	gpio_drv_close(gpio_dev);
	gpio_led_state = 0;
	gpio_led_on();	//giving the control back to the calling function.
}
Exemplo n.º 6
0
//function to blink the led the number of times equal to occurence of the word
static void gpio_led_on(wcount)	//passing the word count
{
	int count=wcount;	//setting the counter

	
	mdev_t *gpio_dev = gpio_drv_open("MDEV_GPIO");
	/* Turn on LED by writing  0 in GPIO register */
	gpio_drv_write(gpio_dev, gpio_led, 0);
	gpio_drv_close(gpio_dev);
	gpio_led_state = 1;
	gpio_led_off();	//turning off the led to give the binking effect
	count=count-1;	//decreasing the counter by 1 after glowing led
	while(count!=1)	//recursive function, to be visited till counter becomes 1(not 0 because counter starts from w,not w-1)
	{	
		gpio_led_on(count); //recursive function
	}
	
}
Exemplo n.º 7
0
// configuring gpios
static void configure_gpios()
{
	mdev_t *pinmux_dev, *gpio_dev;

	/* Initialize  pinmux driver */
	pinmux_drv_init();

	/* Open pinmux driver */
	pinmux_dev = pinmux_drv_open("MDEV_PINMUX");

	/* Initialize GPIO driver */
	gpio_drv_init();

	/* Open GPIO driver */
	gpio_dev = gpio_drv_open("MDEV_GPIO");

	/* Configure GPIO pin function for GPIO connected to LED */
	pinmux_drv_setfunc(pinmux_dev, gpio_led, GPIO_LED_FN);

	/* Configure GPIO pin direction as Output */
	gpio_drv_setdir(gpio_dev, gpio_led, GPIO_OUTPUT);
	/* Keep initial state of LED: ON */
	gpio_drv_write(gpio_dev, gpio_led, 0);

	/* Configure GPIO pin function for GPIO connected to push button */
	pinmux_drv_setfunc(pinmux_dev, gpio_pushbutton, GPIO_PUSHBUTTON_FN);

	/* Configure GPIO pin direction as input */
	gpio_drv_setdir(gpio_dev, gpio_pushbutton, GPIO_INPUT);

	/* Register a callback for push button interrupt */
	gpio_drv_set_cb(gpio_dev, gpio_pushbutton, GPIO_INT_FALLING_EDGE,
			NULL,
			pushbutton_press);

	/* Close drivers */
	pinmux_drv_close(pinmux_dev);
	gpio_drv_close(gpio_dev);
}
Exemplo n.º 8
0
/* Initialise the LCD configuration */
static void init_lcd(void)
{
	uint8_t buf[20];
	mdev_t *i2c_dev;

	pinmux_dev = pinmux_drv_open("MDEV_PINMUX");
	if (pinmux_dev == NULL) {
		lcd_d("Pinmux driver init is required before open");
		return;
	}

	gpio_dev = gpio_drv_open("MDEV_GPIO");
	if (gpio_dev == NULL) {
		lcd_d("GPIO driver init is required before open");
		return;
	}

	board_lcd_reset();

	i2c_dev = i2c_drv_open(MDEV_lcd.private_data,
			I2C_SLAVEADR(I2C_LCD_ADDR >> 1));
	if (i2c_dev == NULL) {
		lcd_d("I2C driver init is required before open");
		return;
	}

	/* The LCD Screen operates in one of the two modes, configuration and
	 * data. In configuration mode various parameters specific to the LCD
	 * screen are set while in data mode data is written in the RAM of the
	 * screen which is then displayed. Set the configuration mode first.
	 * The device stays in this mode until a I2C_STOP is received. */
	buf[0] = LCD_CMD_CONFIG_MODE;	/* Com send */
	/* Internal OSC Frequency
	 * Bits: 0 0 0 1 BS F2 F1 F0
	 * BS: 1 -> 1/4 bias, 0 -> 1/5 bias
	 * F2~0: internal oscillator frequency
	 */
	buf[1] = 0x14;
	/* Function Set
	 * Bits: 0 0 1 DL N DH 0 IS
	 * DL: interface data 1 -> 8 bits, 0 -> 4 bits
	 * N: number of lines 1 -> 2 lines, 0 -> 1 line
	 * DH: enable double height font
	 * IS: Instruction set select 0/1
	 */
	buf[2] = 0x39;
	/* Contrast Set
	 * Bits: 0 1 1 1 C3 C2 C1 C0
	 * C3~0: Last 4 bits of the contrast value
	 */
	buf[3] = 0x78;
	/* Contrast Set
	 * Bits: 0 1 0 1 I B C5 C4
	 * I: ICON display on/off
	 * B: booster circuit on/off
	 * C5~4: Higher order 2 bits of the contrast value
	 */
	buf[4] = 0x55;
	/* Follower Control
	 * Bits: 0 1 1 0 F RAB2 RAB1 RAB0
	 * F : Follower Ckt on/off
	 * RAB2~0: follower amplifier ratio
	 */
	buf[5] = 0x6d;
	/* Display on/off
	 * Bits: 0 0 0 0 1 D C B
	 * D: display on/off
	 * C: cursor on/off
	 * B: cursor position on/off
	 */
	buf[6] = 0x0c;
	/* Clear Display
	 * Bits: 0 0 0 0 0 0 0 1
	 * Set DDRAM address to 00H, and clear display
	 */
	buf[7] = 0x01;
	/* Entry mode
	 * Bits: 0 0 0 0 0 1 I/D S
	 * I/D: Cursor move direction inc/dec
	 * S: Display shift on/off
	 */
	buf[8] = 0x06;

	os_thread_sleep(os_msec_to_ticks(35));
	i2c_drv_write(i2c_dev, buf, 9);

	i2c_drv_close(i2c_dev);
}
/* Sensor input from IO should be read here and to be passed
	in curevent->event_curr_value variable to the upper layer

	This function will be called periodically by the upper layer
	hence you can poll your input here, and there is no need of
	callback IO interrupt, this is very usefull to sense variable
	data from analog sensors connected to ADC lines. Event this can
	be used to digital IO scanning and polling
*/
int ultrasonic_sensor_input_scan(struct sensor_info *curevent)
{
	int val;
	mdev_t *gpio_dev;
	unsigned int duration = 0;
	unsigned int fduration = 0;

	/* Open GPIO driver */
	gpio_dev = gpio_drv_open("MDEV_GPIO");

	/* Confiugre GPIO pin direction as Input */
	gpio_drv_setdir(gpio_dev, ULTRASONIC_SEN_IO, GPIO_OUTPUT);

	/* Ultrosonic distance reading
		Send one altrasonic pulse and wait for
		its return responce
		Then calculate the distance between transmistted
		and received input
	*/

	/* Send a pulse */
	gpio_drv_write(gpio_dev, ULTRASONIC_SEN_IO, 0);
	os_thread_sleep(1);
	gpio_drv_write(gpio_dev, ULTRASONIC_SEN_IO, 1);
	os_thread_sleep(1);
	gpio_drv_write(gpio_dev, ULTRASONIC_SEN_IO, 0);

	/* Confiugre GPIO pin direction as Input */
	gpio_drv_setdir(gpio_dev, ULTRASONIC_SEN_IO, GPIO_INPUT);

	/* Check the line is low */
	while(1) {
		gpio_drv_read(gpio_dev, ULTRASONIC_SEN_IO, &val);
		if (!val)
			break;
	};

	/* Check the line is going high */
	while(1) {
		gpio_drv_read(gpio_dev, ULTRASONIC_SEN_IO, &val);
		if (val)
			break;
	};
	duration = os_get_timestamp(); /* start pulse width measurement */

	/* Check the line is going low */
	while(1) {
		gpio_drv_read(gpio_dev, ULTRASONIC_SEN_IO, &val);
		if (!val)
			break;
	};
	fduration = os_get_timestamp(); /* stop pulse width measurement */

	if (fduration > duration) {
		duration = fduration - duration; /* distance in usec */
		/* Calibrate distance measured in centimeters */
		duration /= 29;
		duration /= 2;

		wmprintf("%s senval=%d cm\r\n", __FUNCTION__, duration);
		sprintf(curevent->event_curr_value, "%d", duration);
	}

	gpio_drv_close(gpio_dev);

	return 0;
}