| simpletools library v1.1.7 Collection of convenience functions for common microcontroller tasks

simpletools.h
Go to the documentation of this file.
1
108 #ifndef SIMPLETOOLS_H
109 #define SIMPLETOOLS_H
110
111 #if defined(__cplusplus)
112 extern "C" {
113 #endif
114
115 #include <propeller.h>
116 #include "simpletext.h"
117 #include <driver.h>
118 #include <stdio.h>
119 #include <stdlib.h>
120 #include <string.h>
121 #include <cog.h>
122 #include <ctype.h>
123 #include <unistd.h>
124 #include <sys/stat.h>
125 #include <dirent.h>
126 #include <sys/sd.h>
127 #include <math.h>
128 #include "simplei2c.h"
129
130
134 extern int ms;
135
136
140 extern int us;
141
142
143
155 extern int st_msTicks;
156
157
162 extern int st_usTicks;
163
164
169 extern int st_iodt;
170
175 extern int st_timeout;
176
181 extern int st_pauseTicks;
182
186 extern int st_mark;
187
191 extern unsigned int st_buscnt;
192
196 extern i2c *st_eeprom;
197
201 extern int st_eeInitFlag;
202
203
210 #ifndef PI
211
214 #define PI 3.141592653589793
215 #endif
216
217
218
226 /* Values for use with SimpleIDE Terminal */
227 #ifndef HOME
228
231 #define HOME (1)
232 #endif
233
234 #ifndef CRSRXY
235
241 #define CRSRXY (2)
242 #endif
243
244 #ifndef CRSRLF
245
249 #define CRSRLF (3)
250 #endif
251
252 #ifndef CRSRRT
253
257 #define CRSRRT (4)
258 #endif
259
260 #ifndef CRSRUP
261
265 #define CRSRUP (5)
266 #endif
267
268 #ifndef CRSRDN
269
273 #define CRSRDN (6)
274 #endif
275
276 #ifndef BEEP
277
281 #define BEEP (7)
282 #endif
283
284 #ifndef BKSP
285
290 #define BKSP (8)
291 #endif
292
293 #ifndef TAB
294
298 #define TAB (9)
299 #endif
300
301 #ifndef NL
302
306 #define NL (10)
307 #endif
308
309 #ifndef LF
310
313 #define LF (10)
314 #endif
315
316 #ifndef CLREOL
317
321 #define CLREOL (11)
322 #endif
323
324 #ifndef CLRDN
325
329 #define CLRDN (12)
330 #endif
331
332 #ifndef CR
333
337 #define CR (13)
338 #endif
339
340 #ifndef CRSRX
341
345 #define CRSRX (14)
346 #endif
347
348 #ifndef CRSRY
349
353 #define CRSRY (15)
354 #endif
355
356 #ifndef CLS
357
361 #define CLS (16)
362 #endif
363
364
365
375 #ifndef MSBPRE
376
379 #define MSBPRE 0
380 #endif
381
382 #ifndef LSBPRE
383
386 #define LSBPRE 1
387 #endif
388
389 #ifndef MSBPOST
390
393 #define MSBPOST 2
394 #endif
395
396 #ifndef LSBPOST
397
400 #define LSBPOST 3
401 #endif
402
403 // Values for use with shift_out
404 #ifndef LSBFIRST
405
408 #define LSBFIRST 0
409 #endif
410
411 #ifndef MSBFIRST
412
415 #define MSBFIRST 1
416 #endif
417
418
419
429 #ifndef NCO_PWM_1
430
434 #define NCO_PWM_1 (0b00100 << 26)
435 #endif
436
437 #ifndef CTR_NCO
438
442 #define CTR_NCO (0b100 << 26)
443 #endif
444
445 #ifndef CTR_PLL
446
450 #define CTR_PLL (0b10 << 26)
451 #endif
452
453 #ifndef DUTY_SE
454
458 #define DUTY_SE (0b110 << 26)
459 #endif
460
461
462
475 #define ee_put_byte ee_putByte
476
477
481 #define ee_get_byte ee_getByte
482
483
487 #define ee_put_int ee_putInt
488
489
493 #define ee_get_int ee_getInt
494
495
499 #define ee_put_str ee_putStr
500
501
505 #define ee_get_str ee_getStr
506
507
511 #define ee_put_float32 ee_putFloat32
512
513
518 #define pause_ticks(pticks) __builtin_propeller_waitcnt(pticks+CNT, 0)
519
520
521
531 #ifndef EEPROM_ADDR
532
535 #define EEPROM_ADDR 0x50
536 #endif
537
538
539
556 void high(int pin);
557
558
569 void low(int pin);
570
571
586 int input(int pin);
587
588
589
609 unsigned int toggle(int pin);
610
622 unsigned int reverse(int pin);
623
624
642 unsigned int get_state(int pin);
643
658 unsigned int get_direction(int pin);
659
672 unsigned int get_output(int pin);
673
682 void set_direction(int pin, int direction);
683
696 void set_output(int pin, int state);
697
698
699
722 unsigned int get_states(int endPin, int startPin);
723
736 unsigned int get_directions(int endPin, int startPin);
737
750 unsigned int get_outputs(int endPin, int startPin);
751
763 void set_directions(int endPin, int startPin, unsigned int pattern);
764
776 void set_outputs(int endPin, int startPin, unsigned int pattern);
777
778
779
780
801 void pause(int time);
802
813 void set_pause_dt(int clockticks);
814
815
816
817
837 long count(int pin, long duration);
838
867 void dac_ctr(int pin, int channel, int dacVal);
868
882 void dac_ctr_res(int bits);
883
891 void dac_ctr_stop(void);
892
903 void freqout(int pin, int msTime, int frequency);
904
919 int pwm_start(unsigned int cycleMicroseconds);
920
946 void pwm_set(int pin, int channel, int tHigh);
947
955 void pwm_stop(void);
956
969 long pulse_in(int pin, int state);
970
986 void pulse_out(int pin, int time);
987
1003 long rc_time(int pin, int state);
1004
1023 void square_wave(int pin, int channel, int freq);
1024
1032 void square_wave_stop(void);
1033
1043 void set_io_timeout(long clockTicks);
1044
1055 void set_io_dt(long clockticks);
1056
1057
1058
1059
1081 int shift_in(int pinDat, int pinClk, int mode, int bits);
1082
1092 void shift_out(int pinDat, int pinClk, int mode, int bits, int value);
1093
1094
1095
1096
1125 i2c *i2c_newbus(int sclPin, int sdaPin, int sclDrive);
1126
1127
1155 HUBTEXT int i2c_out(i2c *busID, int i2cAddr,
1156 int memAddr, int memAddrCount,
1157 const unsigned char *data, int dataCount);
1158
1159
1187 HUBTEXT int i2c_in(i2c *busID, int i2cAddr,
1188 int memAddr, int memAddrCount,
1189 unsigned char *data, int dataCount);
1190
1191
1201 HUBTEXT int i2c_busy(i2c *busID, int i2cAddr);
1202
1203
1204
1205
1225 void ee_putByte(unsigned char value, int addr);
1226
1236 char ee_getByte(int addr);
1237
1238
1248 void ee_putInt(int value, int addr);
1249
1259 int ee_getInt(int addr);
1260
1271 void ee_putStr(unsigned char *s, int n, int addr);
1272
1287 unsigned char* ee_getStr(unsigned char* s, int n, int addr);
1288
1303 void ee_putFloat32(float value, int addr);
1304
1320 float ee_getFloat32(int addr);
1321
1343 void ee_config(int sclPin, int sdaPin, int sclDrive);
1344
1345
1346
1370 int sd_mount(int doPin, int clkPin, int diPin, int csPin);
1371
1372
1373
1409 int *cog_run(void (*function)(void *par), int stacksize);
1410
1411
1419 int cog_num(int *coginfo);
1420
1421
1431 void cog_end(int *coginfo);
1432
1433
1434
1477 void term_cmd(int termConst, ...);
1478
1479
1480
1503 void endianSwap(void *resultAddr, void *varAddr, int byteCount);
1504
1505
1506
1530 void mark(void);
1531
1554 int timeout(int time);
1555
1582 void wait(int time);
1583
1584
1585
1592 #if defined(__cplusplus)
1593 }
1594 #endif
1595 /* __cplusplus */
1596 #endif
1597 /* SIMPLETOOLS_H */
1598