/*
* Display digits:
*
- * ---- 20 ----
+ * ---- 40 ----
* | |
* | |
- * 40 10
+ * 20 80
* | |
* | |
- * ---- 80 ----
+ * ---- 10 ----
* | |
* | |
* 08 02
* (01)
*/
+static byte disp[4];
+static byte ctrl = 0x56;
+
+static void display_update(void)
+{
+ debug_puts("Display pdate\n");
+ byte cmds[4];
+ cmds[0] = 0;
+ cmds[1] = ctrl;
+ cmds[2] = ((disp[1] & 0x88) >> 3) | ((disp[1] & 0x44) >> 1) | ((disp[1] & 0x22) << 1) | ((disp[1] & 0x11) << 3);
+ cmds[3] = disp[0];
+ i2c_transfer7(I2C1, 0x76/2, (byte *) cmds, sizeof(cmds), NULL, 0);
+
+ cmds[2] = ((disp[3] & 0x88) >> 3) | ((disp[3] & 0x44) >> 1) | ((disp[3] & 0x22) << 1) | ((disp[3] & 0x11) << 3);
+ cmds[3] = disp[2];
+ i2c_transfer7(I2C1, 0x70/2, (byte *) cmds, sizeof(cmds), NULL, 0);
+
+ debug_puts("Update done\n");
+}
static void display_init(void)
{
i2c_set_speed(I2C1, i2c_speed_sm_100k, rcc_apb1_frequency / 1000000);
i2c_peripheral_enable(I2C1);
- debug_puts("I2C transfer\n");
-
- // byte disp[] = { 0xb6, 0xb6, 0xb6, 0xb6 };
- // byte disp[] = { 0x7f, 0x12, 0xbc, 0xb6 };
- // byte disp[] = { 0xff, 0xff, 0xff, 0xff };
- byte disp[] = { 0x80, 0x80, 0x80, 0xff };
- byte cmds[] = { 0x00, 0x47, 0, 0, 0, 0 };
- cmds[2] = (disp[0] & 0xf0) | (disp[2] >> 4);
- cmds[3] = (disp[1] & 0xf0) | (disp[3] >> 4);
- cmds[4] = (disp[2] & 0x0f) | (disp[0] << 4);
- cmds[5] = (disp[3] & 0x0f) | (disp[1] << 4);
- i2c_transfer7(I2C1, 0x70/2, (byte *) cmds, sizeof(cmds), NULL, 0);
-
- debug_puts("I2C done\n");
+ disp[0] = 0x82;
+ disp[1] = 0xdc;
+ disp[2] = 0xd6;
+ disp[3] = 0xb2;
+ display_update();
}
static void display_test(void)
{
static byte mode;
+ disp[0] ^= 0x01;
+ display_update();
+
+#if 0
byte cmds[] = { 0x00, mode ? 0x77 : 0x77 };
i2c_transfer7(I2C1, 0x70/2, (byte *) cmds, sizeof(cmds), NULL, 0);
+#endif
+
+#if 0
+ byte disp[] = { 0xff, 0xff, mode ? 0xff : 0x00, mode ? 0xff : 0xff };
+ byte cmds[] = { 0x00, 0x77, 0, 0, 0, 0 };
+ cmds[2] = (disp[0] & 0xf0) | (disp[2] >> 4);
+ cmds[3] = (disp[1] & 0xf0) | (disp[3] >> 4);
+ cmds[4] = (disp[2] & 0x0f) | (disp[0] << 4);
+ cmds[5] = (disp[3] & 0x0f) | (disp[1] << 4);
+ i2c_transfer7(I2C1, 0x70/2, (byte *) cmds, sizeof(cmds), NULL, 0);
+#endif
mode = !mode;
}
+static const byte lcd_font[] = {
+ [0] = 0xee,
+ [1] = 0x82,
+ [2] = 0xdc,
+ [3] = 0xd6,
+ [4] = 0xb2,
+ [5] = 0x76,
+ [6] = 0x7e,
+ [7] = 0xc2,
+ [8] = 0xfe,
+ [9] = 0xf6,
+ [10] = 0xea,
+ [11] = 0x3e,
+ [12] = 0x6c,
+ [13] = 0x9e,
+ [14] = 0x7c,
+ [15] = 0x78,
+};
+
/*** USB ***/
static usbd_device *usbd_dev;
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)
{
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;
}
u32 last_blink = 0;
for (;;) {
- if (ms_ticks - last_blink >= 100) {
+ if (ms_ticks - last_blink >= 500) {
debug_led_toggle();
last_blink = ms_ticks;
display_test();