Little-Wire
 All Classes Functions Groups Pages
littleWire.h
1 #ifndef LITTLEWIRE_H
2 #define LITTLEWIRE_H
3 
4 /*
5  Cross platform computer interface library for Little Wire project
6 
7  http://littlewire.github.io
8 
9  Copyright (C) <2013> ihsan Kehribar <ihsan@kehribar.me>
10  Copyright (C) <2013> Omer Kilic <omerkilic@gmail.com>
11 
12  Permission is hereby granted, free of charge, to any person obtaining a copy of
13  this software and associated documentation files (the "Software"), to deal in
14  the Software without restriction, including without limitation the rights to
15  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
16  of the Software, and to permit persons to whom the Software is furnished to do
17  so, subject to the following conditions:
18 
19  The above copyright notice and this permission notice shall be included in all
20  copies or substantial portions of the Software.
21 
22  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28  SOFTWARE.
29 */
30 
31 #if defined(LINUX)
32  #include <usb.h> // this is libusb, see http://libusb.sourceforge.net/
33 #else
34  #include <lusb0_usb.h> // this is libusb, see http://libusb.sourceforge.net/
35 #endif
36 #include "opendevice.h" // common code moved to separate module
37 #include "littleWire_util.h"
38 #include <stdio.h>
39 
40 #define VENDOR_ID 0x1781
41 #define PRODUCT_ID 0x0c9f
42 #define USB_TIMEOUT 5000
43 #define RX_BUFFER_SIZE 64
44 
45 #define INPUT 1
46 #define OUTPUT 0
47 
48 #define ENABLE 1
49 #define DISABLE 0
50 
51 #define HIGH 1
52 #define LOW 0
53 
54 #define AUTO_CS 1
55 #define MANUAL_CS 0
56 
57 // Voltage ref definition
58 #define VREF_VCC 0
59 #define VREF_1100mV 1
60 #define VREF_2560mV 2
61 
62 // I2C definition
63 #define END_WITH_STOP 1
64 #define NO_STOP 0
65 #define READ 1
66 #define WRITE 0
67 
68 // General Purpose Pins
69 #define PIN1 1
70 #define PIN2 2
71 #define PIN3 5
72 #define PIN4 0
73 
74 // ADC Channels
75 #define ADC_PIN3 0
76 #define ADC_PIN2 1
77 #define ADC_TEMP_SENS 2
78 
79 // PWM Pins
80 #define PWM1 PIN4
81 #define PWM2 PIN1
82 
83 // Aliases
84 #define ADC0 ADC_PIN3
85 #define ADC1 ADC_PIN2
86 #define ADC2 ADC_TEMP_SENS
87 #define PWMA PWM1
88 #define PWMB PWM2
89 
90 // 'AVR ISP' Pins
91 #define SCK_PIN PIN2
92 #define MISO_PIN PIN1
93 #define MOSI_PIN PIN4
94 #define RESET_PIN PIN3
95 
96 unsigned char rxBuffer[RX_BUFFER_SIZE]; /* This has to be unsigned for the data's sake */
97 unsigned char ROM_NO[8];
98 int lwStatus;
99 
105 typedef usb_dev_handle littleWire;
106 
107 typedef struct lwCollection
108 {
109  struct usb_device* lw_device;
110  int serialNumber;
111 }lwCollection;
112 
113 lwCollection lwResults[16];
114 
115 int lw_totalDevices;
116 
124 int littlewire_search();
125 
132 littleWire* littlewire_connect_byID(int desiredID);
133 
141 littleWire* littlewire_connect_bySerialNum(int mySerial);
142 
149 littleWire* littleWire_connect();
150 
158 unsigned char readFirmwareVersion(littleWire* lwHandle);
159 
166 void changeSerialNumber(littleWire* lwHandle,int serialNumber);
167 
180 int customMessage(littleWire* lwHandle,unsigned char* receiveBuffer,unsigned char command,unsigned char d1,unsigned char d2, unsigned char d3, unsigned char d4);
181 
188 int littleWire_error ();
189 
196 char *littleWire_errorName ();
197 
213 void digitalWrite(littleWire* lwHandle, unsigned char pin, unsigned char state);
214 
223 void pinMode(littleWire* lwHandle, unsigned char pin, unsigned char mode);
224 
232 unsigned char digitalRead(littleWire* lwHandle, unsigned char pin);
233 
243 void internalPullup(littleWire* lwHandle, unsigned char pin, unsigned char state);
244 
260 void analog_init(littleWire* lwHandle, unsigned char voltageRef);
261 
270 unsigned int analogRead(littleWire* lwHandle, unsigned char channel);
271 
285 void pwm_init(littleWire* lwHandle);
286 
293 void pwm_stop(littleWire* lwHandle);
294 
303 void pwm_updateCompare(littleWire* lwHandle, unsigned char channelA, unsigned char channelB);
304 
312 void pwm_updatePrescaler(littleWire* lwHandle, unsigned int value);
313 
327 void spi_init(littleWire* lwHandle);
328 
339 void spi_sendMessage(littleWire* lwHandle, unsigned char * sendBuffer, unsigned char * inputBuffer, unsigned char length ,unsigned char mode);
340 
349 unsigned char debugSpi(littleWire* lwHandle, unsigned char message);
350 
359 void spi_updateDelay(littleWire* lwHandle, unsigned int duration);
360 
373 void i2c_init(littleWire* lwHandle);
374 
383 unsigned char i2c_start(littleWire* lwHandle, unsigned char address7bit, unsigned char direction);
384 
394 void i2c_write(littleWire* lwHandle, unsigned char* sendBuffer, unsigned char length, unsigned char endWithStop);
395 
405 void i2c_read(littleWire* lwHandle, unsigned char* readBuffer, unsigned char length, unsigned char endWithStop);
406 
414 void i2c_updateDelay(littleWire* lwHandle, unsigned int duration);
415 
430 void onewire_sendBit(littleWire* lwHandle, unsigned char bitValue);
431 
439 void onewire_writeByte(littleWire* lwHandle, unsigned char messageToSend);
440 
447 unsigned char onewire_readByte(littleWire* lwHandle);
448 
455 unsigned char onewire_readBit(littleWire* lwHandle);
456 
463 unsigned char onewire_resetPulse(littleWire* lwHandle);
464 
472 int onewire_firstAddress(littleWire* lwHandle);
473 
481 int onewire_nextAddress(littleWire* lwHandle);
482 
497 void softPWM_state(littleWire* lwHandle,unsigned char state);
498 
508 void softPWM_write(littleWire* lwHandle,unsigned char ch1,unsigned char ch2,unsigned char ch3);
509 
534 void ws2812_write(littleWire* lwHandle, unsigned char pin,unsigned char r,unsigned char g,unsigned char b);
535 
545 void ws2812_flush(littleWire* lwHandle, unsigned char pin);
546 
556 void ws2812_preload(littleWire* lwHandle, unsigned char r,unsigned char g,unsigned char b);
557 
568 #endif