simpletools library
v0.98
Collection of convenience functions for common microcontroller tasks
Main Page
Files
File List
Globals
simpletools.h
Go to the documentation of this file.
1
92
#ifndef SIMPLETOOLS_H
93
#define SIMPLETOOLS_H
94
95
#if defined(__cplusplus)
96
extern
"C"
{
97
#endif
98
99
#include <propeller.h>
100
#include "simpletext.h"
101
#include <driver.h>
102
#include <stdio.h>
103
#include <stdlib.h>
104
#include <string.h>
105
#include <cog.h>
106
#include <ctype.h>
107
#include <unistd.h>
108
#include <sys/stat.h>
109
#include <dirent.h>
110
#include <sys/sd.h>
111
#include <math.h>
112
#include "simplei2c.h"
113
114
118
extern
int
ms
;
119
120
124
extern
int
us
;
125
126
131
extern
int
st_msTicks
;
132
133
138
extern
int
st_usTicks
;
139
140
145
extern
int
st_iodt
;
146
151
extern
int
st_timeout
;
152
157
extern
int
st_pauseTicks
;
158
162
extern
int
st_mark
;
163
167
extern
unsigned
int
st_buscnt
;
168
172
extern
i2c *
st_eeprom
;
173
177
extern
int
st_eeInitFlag
;
178
179
//extern i2c *eeprom;
180
//extern int dacCtrBits;
181
182
#ifndef PI
183
186
#define PI 3.141592653589793
187
#endif
188
189
#ifndef EEPROM_ADDR
190
193
#define EEPROM_ADDR 0xA0 >> 1
194
#endif
195
196
/* Values for use with SimpleIDE Terminal */
197
#ifndef HOME
198
201
#define HOME (1)
202
#endif
203
204
#ifndef CRSRXY
205
211
#define CRSRXY (2)
212
#endif
213
214
#ifndef CRSRLF
215
219
#define CRSRLF (3)
220
#endif
221
222
#ifndef CRSRRT
223
227
#define CRSRRT (4)
228
#endif
229
230
#ifndef CRSRUP
231
235
#define CRSRUP (5)
236
#endif
237
238
#ifndef CRSRDN
239
243
#define CRSRDN (6)
244
#endif
245
246
#ifndef BEEP
247
251
#define BEEP (7)
252
#endif
253
254
#ifndef BKSP
255
260
#define BKSP (8)
261
#endif
262
263
#ifndef TAB
264
268
#define TAB (9)
269
#endif
270
271
#ifndef NL
272
276
#define NL (10)
277
#endif
278
279
#ifndef LF
280
283
#define LF (10)
284
#endif
285
286
#ifndef CLREOL
287
291
#define CLREOL (11)
292
#endif
293
294
#ifndef CLRDN
295
299
#define CLRDN (12)
300
#endif
301
302
#ifndef CR
303
307
#define CR (13)
308
#endif
309
310
#ifndef CRSRX
311
315
#define CRSRX (14)
316
#endif
317
318
#ifndef CRSRY
319
323
#define CRSRY (15)
324
#endif
325
326
#ifndef CLS
327
331
#define CLS (16)
332
#endif
333
334
335
// Values for use with shift_in
336
#ifndef MSBPRE
337
340
#define MSBPRE 0
341
#endif
342
343
#ifndef LSBPRE
344
347
#define LSBPRE 1
348
#endif
349
350
#ifndef MSBPOST
351
354
#define MSBPOST 2
355
#endif
356
357
#ifndef LSBPOST
358
361
#define LSBPOST 3
362
#endif
363
364
// Values for use with shift_out
365
#ifndef LSBFIRST
366
369
#define LSBFIRST 0
370
#endif
371
372
#ifndef MSBFIRST
373
376
#define MSBFIRST 1
377
#endif
378
379
// Counter module values
380
#ifndef NCO_PWM_1
381
385
#define NCO_PWM_1 (0b00100 << 26)
386
#endif
387
388
#ifndef CTR_NCO
389
393
#define CTR_NCO (0b100 << 26)
394
#endif
395
396
#ifndef CTR_PLL
397
401
#define CTR_PLL (0b10 << 26)
402
#endif
403
404
#ifndef DUTY_SE
405
409
#define DUTY_SE (0b110 << 26)
410
#endif
411
412
// Define types for simplified driver declarations
413
//typedef FILE* serial;
414
//typedef FILE* fdserial;
415
//typedef FILE* sdcard;
416
//typedef I2C* i2c;
417
428
void
high
(
int
pin);
429
440
void
low
(
int
pin);
441
453
unsigned
int
toggle
(
int
pin);
454
468
unsigned
int
input
(
int
pin);
469
481
unsigned
int
reverse
(
int
pin);
482
500
unsigned
int
get_state
(
int
pin);
501
516
unsigned
int
get_direction
(
int
pin);
517
530
unsigned
int
get_output
(
int
pin);
531
540
void
set_direction
(
int
pin,
int
direction);
541
554
void
set_output
(
int
pin,
int
state);
555
569
unsigned
int
get_states
(
int
endPin,
int
startPin);
570
583
unsigned
int
get_directions
(
int
endPin,
int
startPin);
584
597
unsigned
int
get_outputs
(
int
endPin,
int
startPin);
598
610
void
set_directions
(
int
endPin,
int
startPin,
unsigned
int
pattern);
611
623
void
set_outputs
(
int
endPin,
int
startPin,
unsigned
int
pattern);
624
635
void
pause
(
int
time);
636
658
#define pause_ticks(pticks) __builtin_propeller_waitcnt(pticks+CNT, 0)
659
666
void
mark
(
void
);
667
676
int
timeout
(
int
time);
677
688
void
wait
(
int
time);
689
700
void
set_pause_dt
(
int
clockticks);
701
711
long
count
(
int
pin,
long
duration);
712
741
void
dac_ctr
(
int
pin,
int
channel,
int
dacVal);
742
756
void
dac_ctr_res
(
int
bits);
757
765
void
dac_ctr_stop
(
void
);
766
777
void
freqout
(
int
pin,
int
msTime,
int
frequency);
778
793
int
pwm_start
(
unsigned
int
cycleMicroseconds);
794
820
void
pwm_set
(
int
pin,
int
channel,
int
tHigh);
821
829
void
pwm_stop
(
void
);
830
843
long
pulse_in
(
int
pin,
int
state);
844
860
void
pulse_out
(
int
pin,
int
time);
861
877
long
rc_time
(
int
pin,
int
state);
878
897
void
square_wave
(
int
pin,
int
channel,
int
freq);
898
906
void
square_wave_stop
(
void
);
907
917
void
set_io_timeout
(
long
clockTicks);
918
929
void
set_io_dt
(
long
clockticks);
930
931
943
int
shift_in
(
int
pinDat,
int
pinClk,
int
mode,
int
bits);
944
954
void
shift_out
(
int
pinDat,
int
pinClk,
int
mode,
int
bits,
int
value);
955
974
i2c *
i2c_newbus
(
int
sclPin,
int
sdaPin,
int
sclDrive);
975
976
1002
HUBTEXT
int
i2c_out
(i2c *busID,
int
i2cAddr,
1003
int
memAddr,
int
memAddrCount,
1004
const
unsigned
char
*data,
int
dataCount);
1005
1006
1032
HUBTEXT
int
i2c_in
(i2c *busID,
int
i2cAddr,
1033
int
memAddr,
int
memAddrCount,
1034
unsigned
char
*data,
int
dataCount);
1035
1036
1046
HUBTEXT
int
i2c_busy
(i2c *busID,
int
i2cAddr);
1047
1048
1058
void
ee_putByte
(
unsigned
char
value,
int
addr);
1059
1063
#define ee_put_byte ee_putByte
1064
1065
1075
char
ee_getByte
(
int
addr);
1076
1080
#define ee_get_byte ee_getByte
1081
1082
1092
void
ee_putInt
(
int
value,
int
addr);
1093
1097
#define ee_put_int ee_putInt
1098
1099
1109
int
ee_getInt
(
int
addr);
1110
1114
#define ee_get_int ee_getInt
1115
1116
1127
void
ee_putStr
(
unsigned
char
*s,
int
n,
int
addr);
1128
1132
#define ee_put_str ee_putStr
1133
1134
1149
unsigned
char
*
ee_getStr
(
unsigned
char
* s,
int
n,
int
addr);
1150
1154
#define ee_get_str ee_getStr
1155
1156
1171
void
ee_putFloat32
(
float
value,
int
addr);
1172
1176
#define ee_put_float32 ee_putFloat32
1177
1178
1194
float
ee_getFloat32
(
int
addr);
1195
1209
int
sd_mount
(
int
doPin,
int
clkPin,
int
diPin,
int
csPin);
1210
1211
1223
int
start_fpu_cog
(
void
);
1224
1225
1226
/*
1227
* @brief Stop floating point coprocessing cog that is started
1228
* automatically when an application that uses the simpletools library
1229
* is launched. When this function stops the cog running the floating
1230
* point coprocessor, it will save a cog, but disable certain floating
1231
* point functionalities until it is restarted by calling start_fpu_cog.
1232
* CAUTION: Do not try call simpletext library functions while the
1233
* fpu cog is shut down, it could cause the application to hang.
1234
*
1235
* @returns Nonzero if successful, or zero if no cogs available.
1236
1237
void stop_fpu_cog(void);
1238
1239
*/
1240
1241
1242
/*
1243
* @brief Convert value to zero terminated text string.
1244
*
1245
* @details Given an int, a character array pointer and a base, this function
1246
* converts the int into the characters that represent the value in
1247
* the specified base.
1248
*
1249
* @param i An integer value.
1250
* @param b[] A character array pointer.
1251
* @param base The number base for the character representation.
1252
*
1253
* @returns The character array address it received.
1254
1255
char* itoa(int i, char b[], int base);
1256
1257
*/
1258
1259
1284
int
*
cog_run
(
void
(*
function
)(
void
*par),
int
stacksize);
1285
1286
1294
int
cog_num
(
int
*coginfo);
1295
1296
1306
void
cog_end
(
int
*coginfo);
1307
1308
1322
void
endianSwap
(
void
*resultAddr,
void
*varAddr,
int
byteCount);
1323
1324
1325
#if defined(__cplusplus)
1326
}
1327
#endif
1328
/* __cplusplus */
1329
#endif
1330
/* SIMPLETOOLS_H */
1331
Generated on Thu Apr 10 2014 17:36:46 for simpletools library by
1.8.1.2