ftdic 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -0
- data/ext/extconf.rb +8 -0
- data/ext/ftdic.c +211 -0
- metadata +60 -0
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/ext/extconf.rb
ADDED
data/ext/ftdic.c
ADDED
@@ -0,0 +1,211 @@
|
|
1
|
+
#include <ftdi.h>
|
2
|
+
#include <ruby.h>
|
3
|
+
|
4
|
+
static VALUE rb_mFtdiC;
|
5
|
+
static VALUE rb_cFtdi_Context;
|
6
|
+
|
7
|
+
static void check_ftdi_result(struct ftdi_context * ctx, int result)
|
8
|
+
{
|
9
|
+
if (result < 0)
|
10
|
+
{
|
11
|
+
char * error_string = ftdi_get_error_string(ctx);
|
12
|
+
rb_raise(rb_eRuntimeError, "ftdi error: %s", error_string);
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
static VALUE ftdi_context_s_new(VALUE klass)
|
17
|
+
{
|
18
|
+
/* TODO: not exception-safe */
|
19
|
+
|
20
|
+
struct ftdi_context * ctx = ftdi_new();
|
21
|
+
|
22
|
+
if (ctx == 0)
|
23
|
+
{
|
24
|
+
rb_raise(rb_eRuntimeError, "unable to create ftdi context");
|
25
|
+
}
|
26
|
+
|
27
|
+
return Data_Wrap_Struct(rb_cFtdi_Context, 0, ftdi_free, ctx);
|
28
|
+
}
|
29
|
+
|
30
|
+
static VALUE ftdi_context_open(VALUE self, VALUE v_desc)
|
31
|
+
{
|
32
|
+
struct ftdi_context * ctx;
|
33
|
+
char const * desc;
|
34
|
+
int result;
|
35
|
+
|
36
|
+
Data_Get_Struct(self, struct ftdi_context, ctx);
|
37
|
+
desc = StringValuePtr(v_desc);
|
38
|
+
|
39
|
+
result = ftdi_usb_open_string(ctx, desc);
|
40
|
+
check_ftdi_result(ctx, result);
|
41
|
+
|
42
|
+
return Qnil;
|
43
|
+
}
|
44
|
+
|
45
|
+
static VALUE ftdi_context_close(VALUE self)
|
46
|
+
{
|
47
|
+
struct ftdi_context * ctx;
|
48
|
+
int result;
|
49
|
+
|
50
|
+
Data_Get_Struct(self, struct ftdi_context, ctx);
|
51
|
+
|
52
|
+
result = ftdi_usb_close(ctx);
|
53
|
+
check_ftdi_result(ctx, result);
|
54
|
+
|
55
|
+
return Qnil;
|
56
|
+
}
|
57
|
+
|
58
|
+
static VALUE ftdi_context_type(VALUE self)
|
59
|
+
{
|
60
|
+
struct ftdi_context * ctx;
|
61
|
+
|
62
|
+
Data_Get_Struct(self, struct ftdi_context, ctx);
|
63
|
+
|
64
|
+
return INT2NUM(ctx->type);
|
65
|
+
|
66
|
+
}
|
67
|
+
|
68
|
+
static VALUE ftdi_context_chipid(VALUE self)
|
69
|
+
{
|
70
|
+
struct ftdi_context * ctx;
|
71
|
+
int result;
|
72
|
+
unsigned int chipid;
|
73
|
+
|
74
|
+
Data_Get_Struct(self, struct ftdi_context, ctx);
|
75
|
+
result = ftdi_read_chipid(ctx, &chipid);
|
76
|
+
check_ftdi_result(ctx, result);
|
77
|
+
|
78
|
+
return UINT2NUM(chipid);
|
79
|
+
|
80
|
+
}
|
81
|
+
|
82
|
+
static VALUE ftdi_context_set_baudrate(VALUE self, VALUE v_baud)
|
83
|
+
{
|
84
|
+
struct ftdi_context * ctx;
|
85
|
+
int baud = NUM2INT(v_baud);
|
86
|
+
int result;
|
87
|
+
|
88
|
+
Data_Get_Struct(self, struct ftdi_context, ctx);
|
89
|
+
|
90
|
+
result = ftdi_set_baudrate(ctx, baud);
|
91
|
+
check_ftdi_result(ctx, result);
|
92
|
+
|
93
|
+
return Qnil;
|
94
|
+
}
|
95
|
+
|
96
|
+
static VALUE ftdi_context_set_bitmode(VALUE self, VALUE v_bitmask, VALUE v_mode)
|
97
|
+
{
|
98
|
+
struct ftdi_context * ctx;
|
99
|
+
unsigned char bitmask = NUM2INT(v_bitmask);
|
100
|
+
unsigned char mode = NUM2INT(v_mode);
|
101
|
+
int result;
|
102
|
+
|
103
|
+
Data_Get_Struct(self, struct ftdi_context, ctx);
|
104
|
+
|
105
|
+
result = ftdi_set_bitmode(ctx, bitmask, mode);
|
106
|
+
check_ftdi_result(ctx, result);
|
107
|
+
|
108
|
+
return Qnil;
|
109
|
+
}
|
110
|
+
|
111
|
+
static VALUE ftdi_context_read_data(VALUE self, VALUE v_size)
|
112
|
+
{
|
113
|
+
struct ftdi_context * ctx;
|
114
|
+
int size = NUM2INT(v_size);
|
115
|
+
VALUE v_buf = rb_str_buf_new(size);
|
116
|
+
char * buf = StringValuePtr(v_buf);
|
117
|
+
int result;
|
118
|
+
|
119
|
+
Data_Get_Struct(self, struct ftdi_context, ctx);
|
120
|
+
|
121
|
+
result = ftdi_read_data(ctx, (unsigned char *)buf, size);
|
122
|
+
check_ftdi_result(ctx, result);
|
123
|
+
|
124
|
+
RSTRING(v_buf)->len = result;
|
125
|
+
|
126
|
+
return Qnil;
|
127
|
+
}
|
128
|
+
|
129
|
+
static VALUE ftdi_context_write_data(VALUE self, VALUE v_str)
|
130
|
+
{
|
131
|
+
struct ftdi_context * ctx;
|
132
|
+
char * buf = StringValuePtr(v_str);
|
133
|
+
int size = RSTRING(v_str)->len;
|
134
|
+
int result;
|
135
|
+
|
136
|
+
Data_Get_Struct(self, struct ftdi_context, ctx);
|
137
|
+
|
138
|
+
result = ftdi_write_data(ctx, (unsigned char *)buf, size);
|
139
|
+
check_ftdi_result(ctx, result);
|
140
|
+
|
141
|
+
return Qnil;
|
142
|
+
}
|
143
|
+
|
144
|
+
void Init_ftdic()
|
145
|
+
{
|
146
|
+
rb_mFtdiC = rb_define_module("FtdiC");
|
147
|
+
|
148
|
+
rb_cFtdi_Context = rb_define_class_under(rb_mFtdiC, "Context", rb_cObject);
|
149
|
+
rb_define_singleton_method(rb_cFtdi_Context, "new", ftdi_context_s_new, 0);
|
150
|
+
rb_define_method(rb_cFtdi_Context, "open", ftdi_context_open, 1);
|
151
|
+
rb_define_method(rb_cFtdi_Context, "close", ftdi_context_close, 0);
|
152
|
+
rb_define_method(rb_cFtdi_Context, "type", ftdi_context_type, 0);
|
153
|
+
rb_define_method(rb_cFtdi_Context, "chipid", ftdi_context_chipid, 0);
|
154
|
+
rb_define_method(rb_cFtdi_Context, "baudrate=", ftdi_context_set_baudrate, 1);
|
155
|
+
rb_define_method(rb_cFtdi_Context, "set_bitmode", ftdi_context_set_bitmode, 2);
|
156
|
+
rb_define_method(rb_cFtdi_Context, "read_data", ftdi_context_read_data, 1);
|
157
|
+
rb_define_method(rb_cFtdi_Context, "write_data", ftdi_context_write_data, 1);
|
158
|
+
|
159
|
+
rb_define_const(rb_mFtdiC, "BITMODE_RESET", INT2NUM(BITMODE_RESET));
|
160
|
+
rb_define_const(rb_mFtdiC, "BITMODE_BITBANG", INT2NUM(BITMODE_BITBANG));
|
161
|
+
rb_define_const(rb_mFtdiC, "BITMODE_MPSSE", INT2NUM(BITMODE_MPSSE));
|
162
|
+
rb_define_const(rb_mFtdiC, "BITMODE_SYNCBB", INT2NUM(BITMODE_SYNCBB));
|
163
|
+
rb_define_const(rb_mFtdiC, "BITMODE_MCU", INT2NUM(BITMODE_MCU));
|
164
|
+
rb_define_const(rb_mFtdiC, "BITMODE_OPTO", INT2NUM(BITMODE_OPTO));
|
165
|
+
rb_define_const(rb_mFtdiC, "BITMODE_CBUS", INT2NUM(BITMODE_CBUS));
|
166
|
+
rb_define_const(rb_mFtdiC, "BITMODE_SYNCFF", INT2NUM(BITMODE_SYNCFF));
|
167
|
+
|
168
|
+
rb_define_const(rb_mFtdiC, "INTERFACE_ANY", INT2NUM(INTERFACE_ANY));
|
169
|
+
rb_define_const(rb_mFtdiC, "INTERFACE_A", INT2NUM(INTERFACE_A));
|
170
|
+
rb_define_const(rb_mFtdiC, "INTERFACE_B", INT2NUM(INTERFACE_B));
|
171
|
+
rb_define_const(rb_mFtdiC, "INTERFACE_C", INT2NUM(INTERFACE_C));
|
172
|
+
rb_define_const(rb_mFtdiC, "INTERFACE_D", INT2NUM(INTERFACE_D));
|
173
|
+
|
174
|
+
rb_define_const(rb_mFtdiC, "TYPE_AM", INT2NUM(TYPE_AM));
|
175
|
+
rb_define_const(rb_mFtdiC, "TYPE_BM", INT2NUM(TYPE_BM));
|
176
|
+
rb_define_const(rb_mFtdiC, "TYPE_R", INT2NUM(TYPE_R));
|
177
|
+
rb_define_const(rb_mFtdiC, "TYPE_2232H", INT2NUM(TYPE_2232H));
|
178
|
+
rb_define_const(rb_mFtdiC, "TYPE_4232H", INT2NUM(TYPE_4232H));
|
179
|
+
|
180
|
+
rb_define_const(rb_mFtdiC, "NONE", INT2NUM(NONE));
|
181
|
+
rb_define_const(rb_mFtdiC, "ODD", INT2NUM(ODD));
|
182
|
+
rb_define_const(rb_mFtdiC, "EVEN", INT2NUM(EVEN));
|
183
|
+
rb_define_const(rb_mFtdiC, "MARK", INT2NUM(MARK));
|
184
|
+
rb_define_const(rb_mFtdiC, "SPACE", INT2NUM(SPACE));
|
185
|
+
|
186
|
+
rb_define_const(rb_mFtdiC, "STOP_BIT_1", INT2NUM(STOP_BIT_1));
|
187
|
+
rb_define_const(rb_mFtdiC, "STOP_BIT_15", INT2NUM(STOP_BIT_15));
|
188
|
+
rb_define_const(rb_mFtdiC, "STOP_BIT_2", INT2NUM(STOP_BIT_2));
|
189
|
+
|
190
|
+
rb_define_const(rb_mFtdiC, "BITS_7", INT2NUM(BITS_7));
|
191
|
+
rb_define_const(rb_mFtdiC, "BITS_8", INT2NUM(BITS_8));
|
192
|
+
|
193
|
+
rb_define_const(rb_mFtdiC, "BREAK_OFF", INT2NUM(BREAK_OFF));
|
194
|
+
rb_define_const(rb_mFtdiC, "BREAK_ON", INT2NUM(BREAK_ON));
|
195
|
+
|
196
|
+
rb_define_const(rb_mFtdiC, "MPSSE_WRITE_NEG", INT2NUM(MPSSE_WRITE_NEG));
|
197
|
+
rb_define_const(rb_mFtdiC, "MPSSE_BITMODE", INT2NUM(MPSSE_BITMODE));
|
198
|
+
rb_define_const(rb_mFtdiC, "MPSSE_READ_NEG", INT2NUM(MPSSE_READ_NEG));
|
199
|
+
rb_define_const(rb_mFtdiC, "MPSSE_LSB", INT2NUM(MPSSE_LSB));
|
200
|
+
rb_define_const(rb_mFtdiC, "MPSSE_DO_WRITE", INT2NUM(MPSSE_DO_WRITE));
|
201
|
+
rb_define_const(rb_mFtdiC, "MPSSE_DO_READ", INT2NUM(MPSSE_DO_READ));
|
202
|
+
rb_define_const(rb_mFtdiC, "MPSSE_WRITE_TMS", INT2NUM(MPSSE_WRITE_TMS));
|
203
|
+
|
204
|
+
rb_define_const(rb_mFtdiC, "SET_BITS_LOW", INT2NUM(SET_BITS_LOW));
|
205
|
+
rb_define_const(rb_mFtdiC, "SET_BITS_HIGH", INT2NUM(SET_BITS_HIGH));
|
206
|
+
rb_define_const(rb_mFtdiC, "GET_BITS_LOW", INT2NUM(GET_BITS_LOW));
|
207
|
+
rb_define_const(rb_mFtdiC, "GET_BITS_HIGH", INT2NUM(GET_BITS_HIGH));
|
208
|
+
rb_define_const(rb_mFtdiC, "LOOPBACK_START", INT2NUM(LOOPBACK_START));
|
209
|
+
rb_define_const(rb_mFtdiC, "TCK_DIVISOR", INT2NUM(TCK_DIVISOR));
|
210
|
+
}
|
211
|
+
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ftdic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paul Brannan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-12-30 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: |
|
17
|
+
FTDIC is a wrapper for the libftdi library. Libftdi is a library for
|
18
|
+
communicating with FTDI chips, used for serial communications.
|
19
|
+
|
20
|
+
email: curlypaul924@gmail.com
|
21
|
+
executables: []
|
22
|
+
|
23
|
+
extensions:
|
24
|
+
- ext/extconf.rb
|
25
|
+
extra_rdoc_files: []
|
26
|
+
|
27
|
+
files:
|
28
|
+
- VERSION
|
29
|
+
- ext/extconf.rb
|
30
|
+
- ext/ftdic.c
|
31
|
+
has_rdoc: true
|
32
|
+
homepage: http://github.com/cout/ftdic/
|
33
|
+
licenses: []
|
34
|
+
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
version:
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
requirements: []
|
53
|
+
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.3.5
|
56
|
+
signing_key:
|
57
|
+
specification_version: 3
|
58
|
+
summary: A wrapper for the libftdi library
|
59
|
+
test_files: []
|
60
|
+
|