#define NPIX_B0 30
#define NPIX_B1 60
-#define NUM_LEDS 12
-static byte led_rgb[NUM_LEDS][3];
+static byte led_rgb[NPIX_NUM_LEDS][3];
-static byte neopixel_buf[NPIX_RESET + NUM_LEDS*24 + 1];
+static byte neopixel_buf[NPIX_RESET + NPIX_NUM_LEDS*24 + 1];
static bool neopixel_dma_running;
static bool neopixel_want_send;
byte *buf = neopixel_buf;
for (uint i = 0; i < NPIX_RESET; i++)
*buf++ = 0;
- for (uint i = 0; i < NUM_LEDS; i++) {
+ for (uint i = 0; i < NPIX_NUM_LEDS; i++) {
// The order is GRB, MSB first
for (uint m = 0x80; m; m >>= 1)
*buf++ = ((led_rgb[i][1] & m) ? NPIX_B1 : NPIX_B0);
if (ms_ticks - last_blink >= 100) {
debug_led_toggle();
last_blink = ms_ticks;
- led_rgb[NUM_LEDS - 1][1] ^= 0x33;
+ led_rgb[NPIX_NUM_LEDS - 1][1] ^= 0x33;
neopixel_want_send = 1;
}
--- /dev/null
+#include <ucw/lib.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <time.h>
+#include <libusb-1.0/libusb.h>
+
+#include "../firmware/interface.h"
+
+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; i<devn; i++)
+ {
+ struct libusb_device_descriptor desc;
+ libusb_device *dev = devlist[i];
+ if (!libusb_get_device_descriptor(dev, &desc))
+ {
+ if (desc.idVendor == NPIX_USB_VENDOR && desc.idProduct == NPIX_USB_PRODUCT)
+ {
+ printf("Found device at usb%d.%d\n", libusb_get_bus_number(dev), libusb_get_device_address(dev));
+ // FIXME: Free device list
+ return dev;
+ }
+ }
+ }
+
+ libusb_free_device_list(devlist, 1);
+ fprintf(stderr, "Device not found\n");
+ exit(1);
+}
+
+int main(int argc, char **argv)
+{
+ byte packet[NPIX_NUM_LEDS*3] = { };
+ int len = 0;
+
+ if (argc > NPIX_NUM_LEDS*3 + 1)
+ die("Too many arguments!");
+
+ for (int i=1; i < argc; i++)
+ packet[len++] = atoi(argv[i]);
+
+ int err;
+ if (err = libusb_init(&usb_ctxt))
+ die("Cannot initialize libusb: error %d", err);
+
+ libusb_device *dev = find_device();
+
+ if (err = libusb_open(dev, &devh))
+ die("Cannot open device: error %d", err);
+ // libusb_reset_device(devh);
+ if (err = libusb_claim_interface(devh, 0))
+ die("Cannot claim interface: error %d", err);
+
+ int transferred;
+ if (err = libusb_bulk_transfer(devh, 0x01, packet, len, &transferred, 1000))
+ die("Transfer failed: error %d\n", err);
+ if (transferred != len)
+ die("Short transfer: %d out of %d bytes", transferred, len);
+
+ return 0;
+}