summaryrefslogtreecommitdiff
path: root/src/util/ao-make-product.5c
diff options
context:
space:
mode:
authorBdale Garbee <bdale@gag.com>2015-07-15 16:43:50 -0600
committerBdale Garbee <bdale@gag.com>2015-07-15 16:43:50 -0600
commit643c2fb03833d658320f476ef731bbb06fe3cc31 (patch)
tree878c9df5dbd9bab9169becea4e06e8bae3529541 /src/util/ao-make-product.5c
parente41786fb384892961a6547e17812a24314ce9623 (diff)
parent271f56a41c7e785b0fab7e572325df842d104277 (diff)
Merge branch 'master' of ssh://git.gag.com/scm/git/fw/altos
Diffstat (limited to 'src/util/ao-make-product.5c')
-rw-r--r--src/util/ao-make-product.5c49
1 files changed, 34 insertions, 15 deletions
diff --git a/src/util/ao-make-product.5c b/src/util/ao-make-product.5c
index 5f2eb8e8..3ab8d16e 100644
--- a/src/util/ao-make-product.5c
+++ b/src/util/ao-make-product.5c
@@ -1,54 +1,58 @@
-#!/bin/sh
+#!/usr/bin/nickle
autoimport ParseArgs;
+file out = stdout;
+
void
write_ucs2(string a, string description)
{
int len = String::length(a);
- printf("/* %s */\n", description);
- printf("#define AO_%s_LEN 0x%02x\n", description, len * 2 + 2);
- printf("#define AO_%s_STRING \"%s\"\n", description, a);
- printf("#define AO_%s_UCS2", description);
+ File::fprintf(out, "/* %s */\n", description);
+ File::fprintf(out, "#define AO_%s_LEN 0x%02x\n", description, len * 2 + 2);
+ File::fprintf(out, "#define AO_%s_STRING \"%s\"\n", description, a);
+ File::fprintf(out, "#define AO_%s_UCS2", description);
for (int i = 0; i < len; i++) {
int c = a[i];
if (i > 0)
- printf(",");
+ File::fprintf(out, ",");
if (0x20 <= c && c < 128)
- printf(" '%c', 0", c);
+ File::fprintf(out, " '%c', 0", c);
else
- printf(" LE_WORD(0x%04x),", c);
+ File::fprintf(out, " LE_WORD(0x%04x),", c);
}
- printf("\n\n");
+ File::fprintf(out, "\n\n");
}
void
write_string(string a, string description)
{
- printf ("/* %s */\n", description);
- printf ("#define AO_%s_STRING \"%s\"\n", description, a);
+ File::fprintf(out, "/* %s */\n", description);
+ File::fprintf(out, "#define AO_%s_STRING \"%s\"\n", description, a);
}
void
write_int(int a, string description)
{
- printf ("/* %s */\n", description);
- printf ("#define AO_%s_NUMBER %d\n\n", description, a);
+ File::fprintf(out, "/* %s */\n", description);
+ File::fprintf(out, "#define AO_%s_NUMBER %d\n\n", description, a);
}
void
write_hex(int a, string description)
{
- printf ("/* %s */\n", description);
- printf ("#define AO_%s_NUMBER 0x%04x\n\n", description, a);
+ File::fprintf(out, "/* %s */\n", description);
+ File::fprintf(out, "#define AO_%s_NUMBER 0x%04x\n\n", description, a);
}
string manufacturer = "altusmetrum.org";
string product = "TeleMetrum";
string version = "0.0";
+string output = "";
int serial = 1;
int user_argind = 0;
+int id_vendor = 0xfffe;
int id_product = 0x000a;
argdesc argd = {
@@ -66,6 +70,12 @@ argdesc argd = {
.expr_name = "prod",
.desc = "Product name." },
{
+ .var = { .arg_int = &id_vendor },
+ .abbr = 'V',
+ .name = "id_vendor",
+ .expr_name = "id_v",
+ .desc = "Vendor ID." },
+ {
.var = { .arg_int = &id_product },
.abbr = 'i',
.name = "id_product",
@@ -83,6 +93,12 @@ argdesc argd = {
.name = "version",
.expr_name = "string",
.desc = "Program version." },
+ {
+ .var = { .arg_string = &output },
+ .abbr = 'o',
+ .name = "output",
+ .expr_name = "out",
+ .desc = "Output file." },
},
.prog_name = "usb descriptors",
};
@@ -92,11 +108,14 @@ main()
{
string[dim(argv)-1] nargv = {[n] = argv[n+1]};
parseargs(&argd, &nargv);
+ if (output != "")
+ out = File::open(output, "w");
write_ucs2(manufacturer, "iManufacturer");
write_ucs2(product, "iProduct");
write_ucs2(sprintf("%06d", serial), "iSerial");
write_int(serial, "iSerial");
write_hex(id_product, "idProduct");
+ write_hex(id_vendor, "idVendor");
write_string(version, "iVersion");
}