示例#1
0
static int spi_test_init(void *unused)
{
	dev = spi_create(&spi_device);
	if (!dev)
		return -1;

	return 0;
}
示例#2
0
文件: sys.c 项目: ilyak/vimol
void
sys_reset_bonds(struct sys *sys, struct sel *sel)
{
	struct spi *spi;
	struct pair pair;
	int i, j, k, n, *map;

	spi = spi_create();
	n = sel_get_count(sel);
	map = calloc(n, sizeof(int));

	sel_iter_start(sel);

	for (k = 0; sel_iter_next(sel, &i); k++) {
		spi_add_point(spi, sys_get_atom_xyz(sys, i));
		map[k] = i;
	}

	spi_compute(spi, 1.6);
	n = spi_get_pair_count(spi);

	for (k = 0; k < n; k++) {
		pair = spi_get_pair(spi, k);

		i = map[pair.i];
		j = map[pair.j];

		if (is_hydrogen(sys_get_atom_name(sys, i)) &&
		    is_hydrogen(sys_get_atom_name(sys, j)))
			continue;

		if (graph_edge_find(sys->graph, i, j) == NULL)
			graph_edge_create(sys->graph, i, j, 1);
	}

	spi_free(spi);
	free(map);
}
示例#3
0
static int lcd_cmd(struct spi_dev *dev, int cmd)
{
	uint8_t buf[1] = {cmd};
	struct spi_obuf sob = {.len = 1, .buf = buf};
	int ret;

	gpio_set(GPIODC, 0);
	ret = spi_write(dev, SPI_F_DEFAULT, &sob);
	return ret;
}

static int lcd_data(struct spi_dev *dev, int cmd)
{
	uint8_t buf[1] = {cmd};
	struct spi_obuf sob = {.len = 1, .buf = buf};
	int ret;

	gpio_set(GPIODC, 1);
	ret = spi_write(dev, SPI_F_DEFAULT, &sob);
	return ret;
}

static int lcd_task_init(void *arg)
{
	struct spi_dev *dev = arg;

	printf("%s: %i\n", __func__, __LINE__);
	/* My board other devices on SPI: disable their CS */
	gpio_dir_af(GPIOCS_NO0, 1, 1, 0);
	gpio_set(GPIOCS_NO0, 1);
	gpio_dir_af(GPIOCS_NO1, 1, 1, 0);
	gpio_set(GPIOCS_NO1, 1);
	/* This is our gpio and the reset */
	gpio_dir_af(GPIOCS, 1, 1, 0);
	gpio_set(GPIOCS, 1);
	gpio_dir_af(13, 1, 1, 0);
	gpio_set(13, 1);

	/* d/c */
	gpio_dir_af(GPIODC, 1, 1, 0);
	gpio_set(GPIODC, 1);

	spi_create(&spi_dev);

	lcd_cmd(dev, 0x21);
	lcd_cmd(dev, 0x90);
	lcd_cmd(dev, 0x20);
	lcd_cmd(dev, 0x0c);

	return 0;
}

/* The task sends out one packet and reads pending ones */
static void *lcd_task_run(void *arg)
{
	struct spi_dev *dev = arg;
	static u8 inpacket[50];
	int i, j;

	printf("%s: %i\n", __func__, __LINE__);
	printf("cmd: %i\n", i);

	for (j = 0; j < 0x20; j++)
		i = lcd_data(dev, j);

	return dev;
}

static struct bathos_task __task t_lcd = {
	.name = "n5110", .period = HZ,
	.arg = &spi_dev,
	.init = lcd_task_init, .job = lcd_task_run,
	.release = 15
};