Esempio n. 1
0
static void display_destroy(void *param) {
	if (NULL != param) {
		EPD_destroy(epd);
		SPI_destroy(spi);
		GPIO_teardown();
	}
}
Esempio n. 2
0
File: gpio.c Progetto: RavenB/gratis
// set up access to the GPIO and PWM
bool GPIO_setup() {

	// ensure the base firmware is setup
	if (load_firmware(NULL)) {
		// return success
		return true;
	}

	// shudown anything that was created
	GPIO_teardown();
	return false;
}
Esempio n. 3
0
static void *display_init(struct fuse_conn_info *conn) {

	if (!GPIO_setup()) {
		warn("GPIO_setup failed");
		goto done;
	}

	spi = SPI_create(spi_device, spi_bps);
	if (NULL == spi) {
		warn("SPI_setup failed");
		goto done_gpio;
	}

	GPIO_mode(panel_on_pin, GPIO_OUTPUT);
	GPIO_mode(border_pin, GPIO_OUTPUT);
	GPIO_mode(discharge_pin, GPIO_OUTPUT);
#if EPD_COG_VERSION == 1
	GPIO_mode(pwm_pin, GPIO_PWM);
#endif
	GPIO_mode(reset_pin, GPIO_OUTPUT);
	GPIO_mode(busy_pin, GPIO_INPUT);

	epd = EPD_create(panel->size,
			 panel_on_pin,
			 border_pin,
			 discharge_pin,
#if EPD_COG_VERSION == 1
			 pwm_pin,
#endif
			 reset_pin,
			 busy_pin,
			 spi);

	if (NULL == epd) {
		warn("EPD_setup failed");
		goto done_spi;
	}

	return (void *)epd;

	// release resources
//done_epd:
//        EPD_destroy(epd);
done_spi:
	SPI_destroy(spi);
done_gpio:
	GPIO_teardown();
done:
	return NULL;
}
Esempio n. 4
0
// set up access to the GPIO and PWM
bool GPIO_setup() {
	const char *memory_device = "/dev/mem";

	memset(gpio_map, 0, sizeof(gpio_map));

	int mem_fd = open(memory_device, O_RDWR | O_SYNC | O_CLOEXEC);

	if (mem_fd < 0) {
		warn("cannot open: %s", memory_device);
		return false;
	}

	// memory map entry to access the various peripheral registers

	if (!create_rw_map(&gpio_map[0], mem_fd, GPIO0_REGISTERS)) {
		warn("failed to mmap gpio0");
		goto fail;
	}
	if (!create_rw_map(&gpio_map[1], mem_fd, GPIO1_REGISTERS)) {
		warn("failed to mmap gpio1");
		goto fail;
	}
	if (!create_rw_map(&gpio_map[2], mem_fd, GPIO2_REGISTERS)) {
		warn("failed to mmap gpio2");
		goto fail;
	}
	if (!create_rw_map(&gpio_map[3], mem_fd, GPIO3_REGISTERS)) {
		warn("failed to mmap gpio3");
		goto fail;
	}

	// close memory device
	close(mem_fd);

	// ensure the base firmware is setup
	if (!load_firmware(NULL)) {
		goto fail;
	}


	// return success
	return true;

fail:
	// failure case delete items already created
	close(mem_fd);
	GPIO_teardown();
	return false;
}
Esempio n. 5
0
// the main test program
int main(int argc, char *argv[]) {

	int rc = 0;
	EPD_size display_size = EPD_1_44;
	const uint8_t *const *images = images_1_44;
	int image_count = SIZE_OF_ARRAY(images_1_44);

	if (argc < 2) {
		usage(argv[0], "missing argument(s)");
	} else if (argc > 3) {
		usage(argv[0], "extraneous extra argument(s)");
	}

	if (0 == strcmp("1.44", argv[1]) || 0 == strcmp("1_44", argv[1])) {
		display_size = EPD_1_44;
		images = images_1_44;
		image_count = SIZE_OF_ARRAY(images_1_44);
#if EPD_1_9_SUPPORT
	} else if (0 == strcmp("1.9", argv[1]) || 0 == strcmp("1_9", argv[1])) {
		display_size = EPD_1_9;
		images = images_1_9;
		image_count = SIZE_OF_ARRAY(images_1_9);
#endif
	} else if (0 == strcmp("2.0", argv[1]) || 0 == strcmp("2_0", argv[1])) {
		display_size = EPD_2_0;
		images = images_2_0;
		image_count = SIZE_OF_ARRAY(images_2_0);
#if EPD_2_6_SUPPORT
	} else if (0 == strcmp("2.6", argv[1]) || 0 == strcmp("2_6", argv[1])) {
		display_size = EPD_2_6;
		images = images_2_6;
		image_count = SIZE_OF_ARRAY(images_2_6);
#endif
	} else if (0 == strcmp("2.7", argv[1]) || 0 == strcmp("2_7", argv[1])) {
		display_size = EPD_2_7;
		images = images_2_7;
		image_count = SIZE_OF_ARRAY(images_2_7);
	} else {
		usage(argv[0], "unknown display size: %s", argv[1]);
	}

	if (argc > 2) {
		int n = atoi(argv[2]);
		if (n < 0) {
			usage(argv[0], "image-count cannot be negative");
		} else if (n > image_count) {
			usage(argv[0], "image-count: %d, cannot be greater than: %d", n, image_count);
		}
		image_count = n;
	}

	if (!GPIO_setup()) {
		rc = 1;
		warn("GPIO_setup failed");
		goto done;
	}

	SPI_type *spi = SPI_create(SPI_DEVICE, SPI_BPS);
	if (NULL == spi) {
		rc = 1;
		warn("SPI_setup failed");
		goto done_gpio;
	}

	GPIO_mode(panel_on_pin, GPIO_OUTPUT);
	GPIO_mode(border_pin, GPIO_OUTPUT);
	GPIO_mode(discharge_pin, GPIO_OUTPUT);
#if EPD_PWM_REQUIRED
	GPIO_mode(pwm_pin, GPIO_PWM);
#endif
	GPIO_mode(reset_pin, GPIO_OUTPUT);
	GPIO_mode(busy_pin, GPIO_INPUT);

	EPD_type *epd = EPD_create(display_size,
				   panel_on_pin,
				   border_pin,
				   discharge_pin,
#if EPD_PWM_REQUIRED
				   pwm_pin,
#endif
				   reset_pin,
				   busy_pin,
				   spi);

	if (NULL == epd) {
		rc = 1;
		warn("EPD_setup failed");
		goto done_spi;
	}

	// EPD display
	printf("clear display\n");
	EPD_begin(epd);
	EPD_clear(epd);
	EPD_end(epd);

	if (image_count > 0) {
		printf("images start\n");
		for (int i = 0; i < image_count; ++i) {
			printf("image = %d\n", i);
			EPD_begin(epd);
#if EPD_IMAGE_TWO_ARG
			if (0 == i) {
				EPD_image_0(epd, images[i]);
			} else {
				EPD_image(epd, images[i - 1], images[i]);
			}
#elif EPD_IMAGE_ONE_ARG
			EPD_image(epd, images[i]);
#else
#error "unsupported EPD_image() function"
#endif
			EPD_end(epd);
			if (i < image_count - 1) {
				sleep(5);
			}
		}
	}

	// release resources
//done_epd:
	EPD_destroy(epd);
done_spi:
	SPI_destroy(spi);
done_gpio:
	GPIO_teardown();
done:
	return rc;
}