OBJS = $(PROG).o hid.o
-all: $(TARGET) compress uncompress
+all: $(TARGET) compress uncompress reset
compress: compress.c
$(CC) -o compress compress.c
$(CC) -o $(PROG) $(OBJS) $(LIBS)
$(STRIP) $(PROG)
+
+reset: hid.o reset.o
+ $(CC) -o reset reset.o hid.o $(LIBS)
+ $(STRIP) reset
+
$(PROG).exe: $(PROG)
cp $(PROG) $(PROG).exe
hid.o: hid_$(OS).c hid.h
$(CC) $(CFLAGS) -c -o $@ $<
+reset.o: reset.c
+ $(CC) $(CFLAGS) -c -o $@ $<
+
clean:
rm -f *.o $(PROG) $(PROG).exe $(PROG).dmg
rm -rf tmp
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#if defined(OS_LINUX) || defined(OS_MACOSX)
+#include <sys/ioctl.h>
+#include <termios.h>
+#elif defined(OS_WINDOWS)
+#include <conio.h>
+#endif
+
+#include "hid.h"
+
+
+void sendstr(char * tosend)
+{
+ rawhid_send(0, tosend, strlen(tosend),1000);
+}
+
+int mtime_diff(struct timeval high,struct timeval low)
+{
+ int result=1000*(high.tv_sec-low.tv_sec);
+ result+=high.tv_usec/1000-low.tv_usec/1000;
+ return result;
+}
+
+int main (int argc, char *argv[])
+{
+ // C-based example is 16C0:0480:FFAB:0200
+ int r = rawhid_open(1, 0x16C0, 0x0480, 0xFFAB, 0x0200);
+ if (r <= 0) {
+ // Arduino-based example is 16C0:0486:FFAB:0200
+ r = rawhid_open(1, 0x16C0, 0x0486, 0xFFAB, 0x0200);
+ if (r <= 0) {
+ printf("no rawhid device found\n");
+ return -1;
+ }
+ }
+ sendstr("r"); // clear the buffer
+ return 0;
+}
# List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c \
- usb_rawhid.c \
- analog.c
+ usb_rawhid.c
# MCU name, you MUST set this to match the board you are using
# Program the device.
program: $(TARGET).hex $(TARGET).eep
- echo -n r | ../pc/rawhid_test || true
+ ../pc/reset || true
~/teensy_loader_cli/teensy_loader_cli -mmcu=atmega32u4 -w $(TARGET).hex
+++ /dev/null
-// Simple analog to digitial conversion, similar to Wiring/Arduino
-
-#include <avr/io.h>
-#include <avr/pgmspace.h>
-
-#include "analog.h"
-
-
-#if defined(__AVR_ATmega32U4__)
-
-uint8_t analog_reference_config_val = 0x40;
-
-static const uint8_t PROGMEM adc_mapping[] = {
- 0, 1, 4, 5, 6, 7, 13, 12, 11, 10, 9, 8
-};
-
-int analogRead(uint8_t pin)
-{
- uint8_t low, adc;
-
- if (pin >= 12) return 0;
- adc = pgm_read_byte(adc_mapping + pin);
- if (adc < 8) {
- DIDR0 |= (1 << adc);
- ADCSRB = 0;
- ADMUX = analog_reference_config_val | adc;
- } else {
- adc -= 8;
- DIDR2 |= (1 << adc);
- ADCSRB = (1<<MUX5);
- ADMUX = analog_reference_config_val | adc;
- }
- ADCSRA = (1<<ADSC)|(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
- while (ADCSRA & (1<<ADSC)) ;
- low = ADCL;
- return (ADCH << 8) | low;
-}
-
-#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
-
-uint8_t analog_reference_config_val = 0x40;
-
-int analogRead(uint8_t pin)
-{
- uint8_t low;
-
- if (pin >= 8) return 0;
- DIDR0 |= (1 << pin);
- ADMUX = analog_reference_config_val | pin;
- ADCSRA = (1<<ADSC)|(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
- while (ADCSRA & (1<<ADSC)) ;
- low = ADCL;
- return (ADCH << 8) | low;
-}
-
-#endif
-
+++ /dev/null
-#ifndef _analog_h_included__
-#define _analog_h_included__
-
-#include <stdint.h>
-
-#if defined(__AVR_AT90USB162__)
-#define analogRead(pin) (0)
-#define analogReference(ref)
-#else
-int16_t analogRead(uint8_t pin);
-extern uint8_t analog_reference_config_val;
-#define analogReference(ref) (analog_reference_config_val = (ref) << 6)
-#endif
-
-#endif