void SPI::_SPI(const char* _spi_path, uint32_t _bps, GPIO::GPIO_pin_type _cs_pin){ // allocate memory cs_pin = _cs_pin; cs_enable_high = false; fd = open(_spi_path, O_RDWR); if (fd < 0) { warn("cannot open: %s", _spi_path); } bps = _bps; GPIO_mode(cs_pin, GPIO::GPIO_OUTPUT); GPIO_write(cs_pin, (int)!cs_enable_high); printf("[SPI] Opened %s with FD %d\n", _spi_path, fd); }
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; }
// 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; }