Beispiel #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;
}
Beispiel #3
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);
}
Beispiel #4
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);
}