Little-Wire
library/littleWire.h
00001 #ifndef LITTLEWIRE_H
00002 #define LITTLEWIRE_H
00003 
00029 extern "C" {
00030   #if defined(LINUX)
00031     #include <usb.h>
00032   #else
00033     #include <lusb0_usb.h>
00034   #endif
00035 
00036   #include "opendevice.h"
00037 }
00038 
00039 //namespace LittleWire
00040 //{
00041 
00045 #define VENDOR_ID       0x1781
00046 #define PRODUCT_ID      0x0c9f
00047 #define USB_TIMEOUT     5000
00048 #define RX_BUFFER_SIZE  64
00049 
00053 // General Purpose Pins
00054 #define PIN1    1
00055 #define PIN2    2
00056 #define PIN3    5
00057 #define PIN4    0
00058 
00059 // ADC Channels
00060 #define ADC_PIN3                0
00061 #define ADC_PIN2                1
00062 #define ADC_TEMP_SENS   2
00063 
00064 // PWM Pins
00065 #define PWM1    PIN4
00066 #define PWM2    PIN1
00067 
00068 // Aliases
00069 #define ADC0    ADC_PIN3
00070 #define ADC1    ADC_PIN2
00071 #define ADC2    ADC_TEMP_SENS
00072 #define PWMA    PWM1
00073 #define PWMB    PWM2
00074 
00075 // 'AVR ISP' Pins
00076 #define SCK_PIN         PIN2
00077 #define MISO_PIN        PIN1
00078 #define MOSI_PIN        PIN4
00079 #define RESET_PIN       PIN3
00080 
00084 #define STEP_SIZE       0.062   // in miliseconds
00085 #define MIN_LIMIT       0.8     // in miliseconds
00086 #define MAX_LIMIT       2.2     // in miliseconds
00087 #define RANGE           180     // in degrees
00088 
00092 #define INPUT   1
00093 #define OUTPUT  0
00094 
00095 #define AUTO_CS 1
00096 #define MANUAL_CS       0
00097 
00098 #define HIGH    1
00099 #define LOW     0
00100 
00101 
00106 class littleWire
00107 {
00108 
00109 private:
00110         unsigned char rxBuffer[RX_BUFFER_SIZE];
00111         usb_dev_handle* lwHandle;
00112 
00113 public:
00120         littleWire();
00121 
00128         ~littleWire();
00129         
00136         unsigned char connect();
00137         
00145         unsigned char readFirmwareVersion();
00146 
00159         void pinMode(unsigned char pin, unsigned char mode);
00160 
00168         void digitalWrite(unsigned char pin, unsigned char state);
00169 
00176         unsigned char digitalRead(unsigned char pin);
00191         unsigned int analogRead(unsigned char channel);
00192         
00205         void pwm_init();
00206 
00212         void pwm_stop();
00213 
00221         void pwm_updateCompare(unsigned char channelA, unsigned char channelB);
00222 
00229         void pwm_updatePrescaler(unsigned int value);
00243         void spi_init();
00244 
00251         unsigned char spi_sendMessage(unsigned char message);
00252 
00263         void spi_sendMessageMulti(unsigned char* sendBuffer, unsigned char* inputBuffer, unsigned char length, unsigned char mode);
00264 
00272         void spi_updateDelay(unsigned int duration);
00286         void i2c_init();
00287 
00294         void i2c_beginTransmission(unsigned char address);
00295 
00302         void i2c_send(unsigned char message);
00303 
00310         void i2c_endTransmission();
00311 
00320         void i2c_requestFrom(unsigned char address,unsigned char numBytes,unsigned char* responseBuffer);
00334         void servo_init();
00335 
00343         void servo_updateLocation(unsigned char locationChannelA, unsigned char locationChannelB);
00346 };
00347 
00348 //} //namespace
00349 
00350 
00371 #endif
00372 
 All Classes Functions