summaryrefslogtreecommitdiff
path: root/liboctopus/octopus.h
blob: b123335a11877f7bc1e0c8e8f567f2fae972a3cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/***************************************************************************
                          octopus.h  -  description
                             -------------------
    begin                : Fri Apr 1 2007
    copyright            : (C) 2007 by Embedded Projects
    email                : sauter@embedded-projects.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Lesser General Public License           *
 *   version 2.1 as published by the Free Software Foundation;             *
 *                                                                         *
 ***************************************************************************/

#ifndef __liboctopus_h__
#define __liboctopus_h__

#include <usb.h>


#define VID 0x1781
#define PID 0x0c65

/**
  \brief Main context structure for all liboctopus functions.

 Do not access directly if possible.
*/
struct octopus_context {
   // USB specific
   /// libusb's usb_dev_handle
   struct usb_dev_handle *usb_handle;

   /// String representation of last error
   char *error_str;
};

/**
    \brief list of usb devices created by octopus_usb_find_all()
*/
struct octopus_device_list {
   /// pointer to next entry
   struct octopus_device_list *next;
   /// pointer to libusb's usb_device
   struct usb_device *dev;
};

#ifdef __cplusplus
extern "C" {
#endif

   int octopus_init(struct octopus_context *octopus);

   int octopus_open(struct octopus_context *octopus);
   int octopus_open_id(struct octopus_context *octopus, int vendor, int product);
   int octopus_open_serial(struct octopus_context *octopus, char * serial);

   int octopus_open_dev(struct octopus_context *octopus, struct usb_device *dev);

   int octopus_close(struct octopus_context *octopus);

   int octopus_message(struct  octopus_context *octopus, char *msg,
	       int msglen, char *answer, int answerlen);

   char * octopus_get_hwdesc(struct octopus_context *octopus, char *desc);

   /// part: IO

   int octopus_io_init(struct octopus_context *octopus, int pin);
   int octopus_io_init_port(struct octopus_context *octopus, int port);

   int octopus_io_set_port_direction_out(struct octopus_context *octopus, 
                                        int port,unsigned char mask);
   int octopus_io_set_port_direction_in(struct octopus_context *octopus, 
                                       int port, unsigned char mask);
   int octopus_io_set_port_direction_tri(struct octopus_context *octopus, 
                                        int port, unsigned char mask);

   int octopus_io_set_pin_direction_out(struct octopus_context *octopus, int pin);
   int octopus_io_set_pin_direction_in(struct octopus_context *octopus, int pin);
   //int octopus_io_set_pin_direction_in_pullup(struct octopus_context *octopus, int pin);
   int octopus_io_set_pin_direction_tri(struct octopus_context *octopus, int pin);

   unsigned char octopus_io_get_port(struct octopus_context *octopus, int port);

   int octopus_io_set_port(struct octopus_context *octopus, int port, unsigned char value);

   int octopus_io_set_pin(struct octopus_context *octopus, int pin, int value);	//buffered

   int octopus_io_get_pin(struct octopus_context *octopus, int pin);

   /// part: adc

   int octopus_adc_init(struct octopus_context *octopus, int pin);
   int octopus_adc_get(struct octopus_context *octopus, int pin);
   int octopus_adc_ref(struct octopus_context *octopus, int ref); 
   // 1= extern AREF, 2 = AVCC as reference, 3=intern voltage


   /// part: I2C
   int octopus_i2c_init(struct octopus_context *octopus);
   int octopus_i2c_deinit(struct octopus_context *octopus);

   int octopus_i2c_set_bitrate(struct octopus_context *octopus, int bitrate);
   int octopus_i2c_send_byte(struct octopus_context *octopus, char data);
   int octopus_i2c_send_bytes(struct octopus_context *octopus, char *buf, int len);
   unsigned char octopus_i2c_receive_byte(struct octopus_context *octopus, int address,int timeout);
   int octopus_i2c_receive_bytes(struct octopus_context *octopus, int address,char *buf, int len, int timeout);

   int octopus_i2c_send_start(struct octopus_context *octopus);
   int octopus_i2c_send_stop(struct octopus_context *octopus);

   /// part: SPI
   int octopus_spi_init(struct octopus_context *octopus);
   int octopus_spi_deinit(struct octopus_context *octopus);

   int octopus_spi_speed(struct octopus_context *octopus, int speed);
   int octopus_spi_send(struct octopus_context *octopus, unsigned char * buf, int length);
   int octopus_spi_recv(struct octopus_context *octopus, unsigned char * buf, int length);
   int octopus_spi_send_and_recv(struct octopus_context *octopus, unsigned char * buf, int length);

   /// part:  Flash 93c46
   int octopus_93c46_init(struct octopus_context *octopus);
   int octopus_93c46_deinit(struct octopus_context *octopus);

   int octopus_93c46_read(struct octopus_context *octopus, unsigned char address, int length, unsigned char * buf);
   int octopus_93c46_write(struct octopus_context *octopus, unsigned char address, int length, unsigned char * buf);

   /// part:  PWM
   int octopus_pwm_init(struct octopus_context *octopus, int pin);
   int octopus_pwm_deinit(struct octopus_context *octopus, int pin);
   int octopus_pwm_speed(struct octopus_context *octopus, int pin, int speed);
   int octopus_pwm_value(struct octopus_context *octopus, int pin, unsigned char value);

#ifdef __cplusplus
}
#endif

#endif /* __liboctopus_h__ */