diff --git a/fw/atspi/ep0.c b/fw/atspi/ep0.c index 55ea23e..4d457b8 100644 --- a/fw/atspi/ep0.c +++ b/fw/atspi/ep0.c @@ -211,7 +211,6 @@ static __bit my_setup(struct setup_request *setup) __reentrant nSS = 1; usb_send(&ep0, buf, size, NULL, NULL); return 1; -#endif default: error("Unrecognized SETUP: 0x%02x 0x%02x ...\n", diff --git a/fw/atspi/at86rf230.h b/fw/include/at86rf230.h similarity index 84% rename from fw/atspi/at86rf230.h rename to fw/include/at86rf230.h index e0f2701..f4887a7 100644 --- a/fw/atspi/at86rf230.h +++ b/fw/include/at86rf230.h @@ -26,4 +26,11 @@ enum at86rf230_spi_cmd { #define MAX_PSDU 127 /* octets, see AT86RF230 manual section 8.1 */ #define SRAM_SIZE 128 +enum at86rf230_regs { + AT86RF230_REG_PART_NUM = 0x1c, + AT86RF230_REG_VERSION_NUM = 0x1d, + AT86RF230_REG_MAN_ID_0 = 0x1e, + AT86RF230_REG_MAN_ID_1 = 0x1f, +}; + #endif /* !AT86RF230_H */ diff --git a/tools/atspi-id/Makefile b/tools/atspi-id/Makefile index 0afa6d8..51118cb 100644 --- a/tools/atspi-id/Makefile +++ b/tools/atspi-id/Makefile @@ -14,8 +14,8 @@ F32XBASE = ../../../f32xbase MAIN = atspi-id -OBJS = $(F32XBASE)/lib/usb.o include $(F32XBASE)/lib/Makefile.common -CFLAGS += -I$(F32XBASE)/include -I../../fw/include +CFLAGS += -I../../fw/include -I../include +LDLIBS += -L../lib -latspi diff --git a/tools/atspi-id/atspi-id.c b/tools/atspi-id/atspi-id.c index 88b5fe6..de6a085 100644 --- a/tools/atspi-id/atspi-id.c +++ b/tools/atspi-id/atspi-id.c @@ -13,10 +13,10 @@ #include #include +#include -#include "f32xbase/usb.h" #include "atspi/ep0.h" -#include "atspi/usb-ids.h" +#include "atspi.h" #define FROM_DEV ATSPI_FROM_DEV(0) @@ -101,11 +101,9 @@ int main(int argc, const char **argv) if (argc != 1) usage(*argv); - dev = open_usb(USB_VENDOR, USB_PRODUCT); - if (!dev) { - fprintf(stderr, ":-(\n"); + dev = atspi_open(); + if (!dev) return 1; - } show_info(dev); diff --git a/tools/include/atspi.h b/tools/include/atspi.h new file mode 100644 index 0000000..88206eb --- /dev/null +++ b/tools/include/atspi.h @@ -0,0 +1,18 @@ +#ifndef ATSPI_H +#define ATSPI_H + + +#include +#include + + +int atspi_error(void); +int atspi_clear_error(void); + +usb_dev_handle *atspi_open(void); +void atspi_close(usb_dev_handle *dev); + +void atspi_reg_write(usb_dev_handle *dev, uint8_t reg, uint8_t value); +uint8_t atspi_reg_read(usb_dev_handle *dev, uint8_t reg); + +#endif /* !ATSPI_H */ diff --git a/tools/lib/Makefile b/tools/lib/Makefile new file mode 100644 index 0000000..f48255b --- /dev/null +++ b/tools/lib/Makefile @@ -0,0 +1,32 @@ +# +# lib/Makefile - Build the ATSPI library +# +# Written 2010 by Werner Almesberger +# Copyright 2010 Werner Almesberger +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# + + +F32XBASE = ../../../f32xbase + +LIB = libatspi.a + +CFLAGS = -Wall -I$(F32XBASE)/include -I../../fw/include -I../include +OBJS = $(F32XBASE)/lib/usb.o atspi.o + +.PHONY: all clean spotless + +all: $(LIB) + +$(LIB): $(OBJS) + $(AR) cr $@ $^ + +clean: + rm -f $(OBJS) + +spotless: clean + rm -f $(LIB) diff --git a/tools/lib/atspi.c b/tools/lib/atspi.c new file mode 100644 index 0000000..4e8e845 --- /dev/null +++ b/tools/lib/atspi.c @@ -0,0 +1,108 @@ +/* + * lib/atspi.c - ATSPI access functions library + * + * Written 2010 by Werner Almesberger + * Copyright 2010 Werner Almesberger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + + +#include +#include + +#include "f32xbase/usb.h" +#include "atspi/ep0.h" +#include "atspi/usb-ids.h" + +#include "atspi.h" + + +#define FROM_DEV ATSPI_FROM_DEV(0) +#define TO_DEV ATSPI_TO_DEV(0) + + +/* ----- error handling ---------------------------------------------------- */ + + +static int error; + + +int atspi_error(void) +{ + return error; +} + + +int atspi_clear_error(void) +{ + int ret; + + ret = error; + error = 0; + return ret; +} + + +/* ----- open/close -------------------------------------------------------- */ + + +usb_dev_handle *atspi_open(void) +{ + usb_dev_handle *dev; + + dev = open_usb(USB_VENDOR, USB_PRODUCT); + if (dev) { + error = 0; + } else { + fprintf(stderr, ":-(\n"); + error = 1; + } + return dev; +} + + +void atspi_close(usb_dev_handle *dev) +{ + /* to do */ +} + + +/* ----- register access --------------------------------------------------- */ + + +void atspi_reg_write(usb_dev_handle *dev, uint8_t reg, uint8_t value) +{ + int res; + + if (error) + return; + + res = usb_control_msg(dev, TO_DEV, ATSPI_REG_WRITE, value, reg, + NULL, 0, 1000); + if (res < 0) { + fprintf(stderr, "ATSPI_REG_WRITE: %d\n", res); + error = 1; + } +} + + +uint8_t atspi_reg_read(usb_dev_handle *dev, uint8_t reg) +{ + uint8_t value = 0; + int res; + + if (error) + return 0; + + res = usb_control_msg(dev, FROM_DEV, ATSPI_REG_READ, 0, reg, + (void *) &value, 1, 1000); + if (res < 0) { + fprintf(stderr, "ATSPI_REG_READ: %d\n", res); + error = 1; + } + return value; +}