From: Martin Mares Date: Sat, 9 May 2020 22:19:30 +0000 (+0200) Subject: Display test: Trivial clock X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=81f712dc85d4928294b7f506777080a8b37902c1;p=home-hw.git Display test: Trivial clock --- diff --git a/test-display/host/Makefile b/test-display/host/Makefile new file mode 100644 index 0000000..5e6e00c --- /dev/null +++ b/test-display/host/Makefile @@ -0,0 +1,12 @@ +UCWCF:=$(shell PKG_CONFIG_PATH=$(LIBUCW)/lib/pkgconfig pkg-config --cflags libucw) +UCWLF:=$(shell PKG_CONFIG_PATH=$(LIBUCW)/lib/pkgconfig pkg-config --libs libucw) + +CFLAGS=-std=gnu99 -O2 -Wall -Wextra -Wno-parentheses $(UCWCF) +LDLIBS=-lusb-1.0 $(UCWLF) + +all: test + +test: test.c + +clean: + rm -f test diff --git a/test-display/host/test.c b/test-display/host/test.c new file mode 100644 index 0000000..cad8474 --- /dev/null +++ b/test-display/host/test.c @@ -0,0 +1,104 @@ +#include +#include + +#include +#include +#include +#include +#include +#include + +struct libusb_context *usb_ctxt; +struct libusb_device_handle *devh; + +static libusb_device *find_device(void) +{ + libusb_device **devlist; + ssize_t devn = libusb_get_device_list(usb_ctxt, &devlist); + if (devn < 0) + { + fprintf(stderr, "Cannot enumerate USB devices: error %d\n", (int) devn); + exit(1); + } + + for (ssize_t i=0; itm_hour / 10, + tm->tm_hour % 10, + tm->tm_min / 10, + tm->tm_min % 10, + (tm->tm_sec % 2 ? 0xff : 0), + }; + int transferred; + if (err = libusb_bulk_transfer(devh, 0x01, req, 5, &transferred, 1000)) + die("Transfer failed: error %d", err); + // printf("Transferred %d bytes\n", transferred); + +#if 0 + unsigned char resp[64]; + int received; + if (err = libusb_bulk_transfer(devh, 0x82, resp, 64, &received, 2000)) + die("Receive failed: error %d", err); + // printf("Received %d bytes\n", received); + if (received >= 12) + { + int t = get_u32_be(resp); + int p = get_u32_be(resp + 4); + uint cnt = get_u32_be(resp + 8); + msg(L_INFO, "Temperature %d ddegC, pressure %d Pa, cnt %u", t, p, cnt); + } +#endif + + sleep(1); + } + + return 0; +} diff --git a/test-display/main.c b/test-display/main.c index 47c553f..0573a5e 100644 --- a/test-display/main.c +++ b/test-display/main.c @@ -170,6 +170,25 @@ static void display_test(void) mode = !mode; } +static const byte lcd_font[] = { + [0] = 0x7e, + [1] = 0x12, + [2] = 0xbc, + [3] = 0xb6, + [4] = 0xd2, + [5] = 0xe6, + [6] = 0xee, + [7] = 0x32, + [8] = 0xfe, + [9] = 0xf6, + [10] = 0xfa, + [11] = 0xce, + [12] = 0x6c, + [13] = 0x9e, + [14] = 0xec, + [15] = 0xe8, +}; + /*** USB ***/ static usbd_device *usbd_dev; @@ -296,14 +315,24 @@ static enum usbd_request_return_codes dfu_control_cb(usbd_device *dev UNUSED, return USBD_REQ_HANDLED; } -# if 0 static void ep01_cb(usbd_device *dev, uint8_t ep UNUSED) { // We received a frame from the USB host - uint len = usbd_ep_read_packet(dev, 0x01, dmx_next_packet, DMX_MAX_PACKET_SIZE); + byte buf[8]; + uint len = usbd_ep_read_packet(dev, 0x01, buf, 8); debug_printf("USB: Host sent %u bytes\n", len); + if (len >= 5) { + for (uint i=0; i<4; i++) { + if (buf[i] < 16) + disp[i] = lcd_font[buf[i]]; + else + disp[i] = 0; + } + if (buf[4]) + disp[1] |= 1; + display_update(); + } } -#endif static void set_config_cb(usbd_device *dev, uint16_t wValue UNUSED) { @@ -312,7 +341,7 @@ static void set_config_cb(usbd_device *dev, uint16_t wValue UNUSED) USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE, USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT, dfu_control_cb); - // usbd_ep_setup(dev, 0x01, USB_ENDPOINT_ATTR_BULK, 64, ep01_cb); + usbd_ep_setup(dev, 0x01, USB_ENDPOINT_ATTR_BULK, 64, ep01_cb); usb_configured = 1; }