simpletools library  v0.97
Collection of convenience functions for common microcontroller tasks
simpletools.h
Go to the documentation of this file.
1 
83 #ifndef SIMPLETOOLS_H
84 #define SIMPLETOOLS_H
85 
86 #if defined(__cplusplus)
87 extern "C" {
88 #endif
89 
90 #include <propeller.h>
91 #include "simpletext.h"
92 #include <driver.h>
93 #include <stdio.h>
94 #include <stdlib.h>
95 #include <string.h>
96 #include <cog.h>
97 #include <ctype.h>
98 #include <unistd.h>
99 #include <sys/stat.h>
100 #include <dirent.h>
101 #include <sys/sd.h>
102 #include <math.h>
103 #include "simplei2c.h"
104 
105 // Global variables shared by functions in separate files
106 extern long iodt;
107 extern long t_timeout;
108 extern long pauseTicks;
109 extern long t_mark;
110 extern char setForget;
111 extern int fdserDriverIndex;
112 extern unsigned int buscnt;
113 extern i2c *eeprom;
114 extern int eeInitFlag;
115 
116 //extern i2c *eeprom;
117 //extern int dacCtrBits;
118 
119 #ifndef PI
120 #define PI 3.141592653589793
121 #endif
122 
123 #ifndef EEPROM_ADDR
124 #define EEPROM_ADDR 0xA0 >> 1
125 #endif
126 
127 /* Values for use with SimpleIDE Terminal */
128 #ifndef HOME
129 #define HOME (1)
130 #endif
131 #ifndef CRSRXY
132 #define CRSRXY (2)
133 #endif
134 #ifndef CRSRLF
135 #define CRSRLF (3)
136 #endif
137 #ifndef CRSRRT
138 #define CRSRRT (4)
139 #endif
140 #ifndef CRSRUP
141 #define CRSRUP (5)
142 #endif
143 #ifndef CRSRDN
144 #define CRSRDN (6)
145 #endif
146 #ifndef BEEP
147 #define BEEP (7)
148 #endif
149 #ifndef BKSP
150 #define BKSP (8)
151 #endif
152 #ifndef TAB
153 #define TAB (9)
154 #endif
155 #ifndef NL
156 #define NL (10)
157 #endif
158 #ifndef LF
159 #define LF (10)
160 #endif
161 #ifndef CLREOL
162 #define CLREOL (11)
163 #endif
164 #ifndef CLRDN
165 #define CLRDN (12)
166 #endif
167 #ifndef CR
168 #define CR (13)
169 #endif
170 #ifndef CRSRX
171 #define CRSRX (14)
172 #endif
173 #ifndef CRSRY
174 #define CRSRY (15)
175 #endif
176 #ifndef CLS
177 #define CLS (16)
178 #endif
179 
180 
181 // Values for use with shift_in
182 #ifndef MSBPRE
183 #define MSBPRE 0
184 #endif
185 #ifndef LSBPRE
186 #define LSBPRE 1
187 #endif
188 #ifndef MSBPOST
189 #define MSBPOST 2
190 #endif
191 #ifndef LSBPOST
192 #define LSBPOST 3
193 #endif
194 
195 // Values for use with shift_out
196 #ifndef LSBFIRST
197 #define LSBFIRST 0
198 #endif
199 
200 #ifndef MSBFIRST
201 #define MSBFIRST 1
202 #endif
203 
204 // Counter module values
205 #ifndef NCO_PWM_1
206 #define NCO_PWM_1 (0b00100 << 26)
207 #endif
208 
209 #ifndef CTR_NCO
210 #define CTR_NCO (0b100 << 26)
211 #endif
212 
213 #ifndef CTR_PLL
214 #define CTR_PLL (0b10 << 26)
215 #endif
216 
217 #ifndef DUTY_SE
218 #define DUTY_SE (0b110 << 26)
219 #endif
220 
221 // Define types for simplified driver declarations
222 //typedef FILE* serial;
223 //typedef FILE* fdserial;
224 //typedef FILE* sdcard;
225 //typedef I2C* i2c;
226 
237 void high(int pin);
238 
249 void low(int pin);
250 
262 unsigned int toggle(int pin);
263 
277 unsigned int input(int pin);
278 
290 unsigned int reverse(int pin);
291 
309 unsigned int get_state(int pin);
310 
325 unsigned int get_direction(int pin);
326 
339 unsigned int get_output(int pin);
340 
349 void set_direction(int pin, int direction);
350 
363 void set_output(int pin, int state);
364 
378 unsigned int get_states(int endPin, int startPin);
379 
392 unsigned int get_directions(int endPin, int startPin);
393 
406 unsigned int get_outputs(int endPin, int startPin);
407 
419 void set_directions(int endPin, int startPin, unsigned int pattern);
420 
432 void set_outputs(int endPin, int startPin, unsigned int pattern);
433 
444 void pause(int time);
445 
467 #define pause_ticks(pticks) __builtin_propeller_waitcnt(pticks+CNT, 0)
468 
475 void mark(void);
476 
485 int timeout(int time);
486 
497 void wait(int time);
498 
509 void set_pause_dt(int clockticks);
510 
520 long count(int pin, long duration);
521 
550 void dac_ctr(int pin, int channel, int dacVal);
551 
565 void dac_ctr_res(int bits);
566 
574 void dac_ctr_stop(void);
575 
586 void freqout(int pin, int msTime, int frequency);
587 
602 int pwm_start(unsigned int cycleMicroseconds);
603 
629 void pwm_set(int pin, int channel, int tHigh);
630 
638 void pwm_stop(void);
639 
652 long pulse_in(int pin, int state);
653 
669 void pulse_out(int pin, int time);
670 
686 long rc_time(int pin, int state);
687 
706 void square_wave(int pin, int channel, int freq);
707 
715 void square_wave_stop(void);
716 
726 void set_io_timeout(long clockTicks);
727 
738 void set_io_dt(long clockticks);
739 
740 
752 int shift_in(int pinDat, int pinClk, int mode, int bits);
753 
763 void shift_out(int pinDat, int pinClk, int mode, int bits, int value);
764 
782 i2c *i2c_newbus(int sclpin, int sdapin, int scldrive);
783 
784 
812 HUBTEXT int i2c_out(i2c *bus, int i2cAddr,
813  const unsigned char *regAddr, int regSize,
814  const unsigned char *data, int count);
815 
816 
845 HUBTEXT int i2c_in(i2c *bus, int i2cAddr,
846  const unsigned char *regAddr, int regSize,
847  unsigned char *data, int count);
848 
849 
858 void ee_putByte(char value, int addr);
859 
863 #define ee_put_byte ee_putByte
864 
865 
875 char ee_getByte(int addr);
876 
880 #define ee_get_byte ee_getByte
881 
882 
892 void ee_putInt(int value, int addr);
893 
897 #define ee_put_int ee_putInt
898 
899 
909 int ee_getInt(int addr);
910 
914 #define ee_get_int ee_getInt
915 
916 
927 void ee_putStr(unsigned char *s, int n, int addr);
928 
932 #define ee_put_str ee_putStr
933 
934 
949 char* ee_getStr(unsigned char* s, int n, int addr);
950 
954 #define ee_get_str ee_getStr
955 
956 
971 void ee_putFloat32(float value, int addr);
972 
976 #define ee_put_float32 ee_putFloat32
977 
978 
994 float ee_getFloat32(int addr);
995 
1009 int sd_mount(int doPin, int clkPin, int diPin, int csPin);
1010 
1011 
1023 int start_fpu_cog(void);
1024 
1025 
1037 void stop_fpu_cog(void);
1038 
1039 
1053 char* itoa(int i, char b[], int base);
1054 
1055 
1079 int *cog_run(void (*function)(void *par), int stacksize);
1080 
1081 
1091 void cog_end(int *coginfo);
1092 
1093 
1094 int add_driver(_Driver *driverAddr);
1095 
1096 #if defined(__cplusplus)
1097 }
1098 #endif
1099 /* __cplusplus */
1100 #endif
1101 /* SIMPLETOOLS_H */
1102