simpletools library  v0.98.2
Collection of convenience functions for common microcontroller tasks
simpletools.h
Go to the documentation of this file.
1 
106 #ifndef SIMPLETOOLS_H
107 #define SIMPLETOOLS_H
108 
109 #if defined(__cplusplus)
110 extern "C" {
111 #endif
112 
113 #include <propeller.h>
114 #include "simpletext.h"
115 #include <driver.h>
116 #include <stdio.h>
117 #include <stdlib.h>
118 #include <string.h>
119 #include <cog.h>
120 #include <ctype.h>
121 #include <unistd.h>
122 #include <sys/stat.h>
123 #include <dirent.h>
124 #include <sys/sd.h>
125 #include <math.h>
126 #include "simplei2c.h"
127 
128 
132 extern int ms;
133 
134 
138 extern int us;
139 
140 
141 
153 extern int st_msTicks;
154 
155 
160 extern int st_usTicks;
161 
162 
167 extern int st_iodt;
168 
173 extern int st_timeout;
174 
179 extern int st_pauseTicks;
180 
184 extern int st_mark;
185 
189 extern unsigned int st_buscnt;
190 
194 extern i2c *st_eeprom;
195 
199 extern int st_eeInitFlag;
200 
201 
208 #ifndef PI
209 
212 #define PI 3.141592653589793
213 #endif
214 
215 
216 
224 /* Values for use with SimpleIDE Terminal */
225 #ifndef HOME
226 
229 #define HOME (1)
230 #endif
231 
232 #ifndef CRSRXY
233 
239 #define CRSRXY (2)
240 #endif
241 
242 #ifndef CRSRLF
243 
247 #define CRSRLF (3)
248 #endif
249 
250 #ifndef CRSRRT
251 
255 #define CRSRRT (4)
256 #endif
257 
258 #ifndef CRSRUP
259 
263 #define CRSRUP (5)
264 #endif
265 
266 #ifndef CRSRDN
267 
271 #define CRSRDN (6)
272 #endif
273 
274 #ifndef BEEP
275 
279 #define BEEP (7)
280 #endif
281 
282 #ifndef BKSP
283 
288 #define BKSP (8)
289 #endif
290 
291 #ifndef TAB
292 
296 #define TAB (9)
297 #endif
298 
299 #ifndef NL
300 
304 #define NL (10)
305 #endif
306 
307 #ifndef LF
308 
311 #define LF (10)
312 #endif
313 
314 #ifndef CLREOL
315 
319 #define CLREOL (11)
320 #endif
321 
322 #ifndef CLRDN
323 
327 #define CLRDN (12)
328 #endif
329 
330 #ifndef CR
331 
335 #define CR (13)
336 #endif
337 
338 #ifndef CRSRX
339 
343 #define CRSRX (14)
344 #endif
345 
346 #ifndef CRSRY
347 
351 #define CRSRY (15)
352 #endif
353 
354 #ifndef CLS
355 
359 #define CLS (16)
360 #endif
361 
362 
363 
373 #ifndef MSBPRE
374 
377 #define MSBPRE 0
378 #endif
379 
380 #ifndef LSBPRE
381 
384 #define LSBPRE 1
385 #endif
386 
387 #ifndef MSBPOST
388 
391 #define MSBPOST 2
392 #endif
393 
394 #ifndef LSBPOST
395 
398 #define LSBPOST 3
399 #endif
400 
401 // Values for use with shift_out
402 #ifndef LSBFIRST
403 
406 #define LSBFIRST 0
407 #endif
408 
409 #ifndef MSBFIRST
410 
413 #define MSBFIRST 1
414 #endif
415 
416 
417 
427 #ifndef NCO_PWM_1
428 
432 #define NCO_PWM_1 (0b00100 << 26)
433 #endif
434 
435 #ifndef CTR_NCO
436 
440 #define CTR_NCO (0b100 << 26)
441 #endif
442 
443 #ifndef CTR_PLL
444 
448 #define CTR_PLL (0b10 << 26)
449 #endif
450 
451 #ifndef DUTY_SE
452 
456 #define DUTY_SE (0b110 << 26)
457 #endif
458 
459 
460 
473 #define ee_put_byte ee_putByte
474 
475 
479 #define ee_get_byte ee_getByte
480 
481 
485 #define ee_put_int ee_putInt
486 
487 
491 #define ee_get_int ee_getInt
492 
493 
497 #define ee_put_str ee_putStr
498 
499 
503 #define ee_get_str ee_getStr
504 
505 
509 #define ee_put_float32 ee_putFloat32
510 
511 
516 #define pause_ticks(pticks) __builtin_propeller_waitcnt(pticks+CNT, 0)
517 
518 
519 
529 #ifndef EEPROM_ADDR
530 
533 #define EEPROM_ADDR 0x50
534 #endif
535 
536 
537 
554 void high(int pin);
555 
556 
567 void low(int pin);
568 
569 
584 int input(int pin);
585 
586 
587 
607 unsigned int toggle(int pin);
608 
620 unsigned int reverse(int pin);
621 
622 
640 unsigned int get_state(int pin);
641 
656 unsigned int get_direction(int pin);
657 
670 unsigned int get_output(int pin);
671 
680 void set_direction(int pin, int direction);
681 
694 void set_output(int pin, int state);
695 
696 
697 
720 unsigned int get_states(int endPin, int startPin);
721 
734 unsigned int get_directions(int endPin, int startPin);
735 
748 unsigned int get_outputs(int endPin, int startPin);
749 
761 void set_directions(int endPin, int startPin, unsigned int pattern);
762 
774 void set_outputs(int endPin, int startPin, unsigned int pattern);
775 
776 
777 
778 
799 void pause(int time);
800 
811 void set_pause_dt(int clockticks);
812 
813 
814 
815 
835 long count(int pin, long duration);
836 
865 void dac_ctr(int pin, int channel, int dacVal);
866 
880 void dac_ctr_res(int bits);
881 
889 void dac_ctr_stop(void);
890 
901 void freqout(int pin, int msTime, int frequency);
902 
917 int pwm_start(unsigned int cycleMicroseconds);
918 
944 void pwm_set(int pin, int channel, int tHigh);
945 
953 void pwm_stop(void);
954 
967 long pulse_in(int pin, int state);
968 
984 void pulse_out(int pin, int time);
985 
1001 long rc_time(int pin, int state);
1002 
1021 void square_wave(int pin, int channel, int freq);
1022 
1030 void square_wave_stop(void);
1031 
1041 void set_io_timeout(long clockTicks);
1042 
1053 void set_io_dt(long clockticks);
1054 
1055 
1056 
1057 
1079 int shift_in(int pinDat, int pinClk, int mode, int bits);
1080 
1090 void shift_out(int pinDat, int pinClk, int mode, int bits, int value);
1091 
1092 
1093 
1094 
1123 i2c *i2c_newbus(int sclPin, int sdaPin, int sclDrive);
1124 
1125 
1153 HUBTEXT int i2c_out(i2c *busID, int i2cAddr,
1154  int memAddr, int memAddrCount,
1155  const unsigned char *data, int dataCount);
1156 
1157 
1185 HUBTEXT int i2c_in(i2c *busID, int i2cAddr,
1186  int memAddr, int memAddrCount,
1187  unsigned char *data, int dataCount);
1188 
1189 
1199 HUBTEXT int i2c_busy(i2c *busID, int i2cAddr);
1200 
1201 
1202 
1203 
1223 void ee_putByte(unsigned char value, int addr);
1224 
1234 char ee_getByte(int addr);
1235 
1236 
1246 void ee_putInt(int value, int addr);
1247 
1257 int ee_getInt(int addr);
1258 
1269 void ee_putStr(unsigned char *s, int n, int addr);
1270 
1285 unsigned char* ee_getStr(unsigned char* s, int n, int addr);
1286 
1301 void ee_putFloat32(float value, int addr);
1302 
1318 float ee_getFloat32(int addr);
1319 
1341 void ee_config(int sclPin, int sdaPin, int sclDrive);
1342 
1343 
1344 
1368 int sd_mount(int doPin, int clkPin, int diPin, int csPin);
1369 
1370 
1371 
1407 int *cog_run(void (*function)(void *par), int stacksize);
1408 
1409 
1417 int cog_num(int *coginfo);
1418 
1419 
1429 void cog_end(int *coginfo);
1430 
1431 
1432 
1475 void term_cmd(int termConst, ...);
1476 
1477 
1478 
1501 void endianSwap(void *resultAddr, void *varAddr, int byteCount);
1502 
1503 
1504 
1528 void mark(void);
1529 
1552 int timeout(int time);
1553 
1580 void wait(int time);
1581 
1582 
1583 
1590 #if defined(__cplusplus)
1591 }
1592 #endif
1593 /* __cplusplus */
1594 #endif
1595 /* SIMPLETOOLS_H */
1596