simpletools library  v0.96.1
Collection of convenience functions for common microcontroller tasks
simpletools.h
Go to the documentation of this file.
1 
81 #ifndef SIMPLETOOLS_H
82 #define SIMPLETOOLS_H
83 
84 #if defined(__cplusplus)
85 extern "C" {
86 #endif
87 
88 #include <propeller.h>
89 #include "simpletext.h"
90 #include <driver.h>
91 #include <stdio.h>
92 #include <stdlib.h>
93 #include <string.h>
94 #include <cog.h>
95 #include <ctype.h>
96 #include <unistd.h>
97 #include <sys/stat.h>
98 #include <dirent.h>
99 #include <sys/sd.h>
100 #include <math.h>
101 #include "simplei2c.h"
102 
103 // Global variables shared by functions in separate files
104 extern long iodt;
105 extern long t_timeout;
106 extern long pauseTicks;
107 extern long t_mark;
108 extern char setForget;
109 extern int fdserDriverIndex;
110 extern unsigned int buscnt;
111 extern i2c *eeprom;
112 extern int eeInitFlag;
113 
114 //extern i2c *eeprom;
115 //extern int dacCtrBits;
116 
117 #ifndef PI
118 #define PI 3.141592653589793
119 #endif
120 
121 #ifndef EEPROM_ADDR
122 #define EEPROM_ADDR 0xA0 >> 1
123 #endif
124 
125 /* Values for use with SimpleIDE Terminal */
126 #ifndef HOME
127 #define HOME (1)
128 #endif
129 #ifndef CRSRXY
130 #define CRSRXY (2)
131 #endif
132 #ifndef CRSRLF
133 #define CRSRLF (3)
134 #endif
135 #ifndef CRSRRT
136 #define CRSRRT (4)
137 #endif
138 #ifndef CRSRUP
139 #define CRSRUP (5)
140 #endif
141 #ifndef CRSRDN
142 #define CRSRDN (6)
143 #endif
144 #ifndef BEEP
145 #define BEEP (7)
146 #endif
147 #ifndef BKSP
148 #define BKSP (8)
149 #endif
150 #ifndef TAB
151 #define TAB (9)
152 #endif
153 #ifndef NL
154 #define NL (10)
155 #endif
156 #ifndef LF
157 #define LF (10)
158 #endif
159 #ifndef CLREOL
160 #define CLREOL (11)
161 #endif
162 #ifndef CLRDN
163 #define CLRDN (12)
164 #endif
165 #ifndef CR
166 #define CR (13)
167 #endif
168 #ifndef CRSRX
169 #define CRSRX (14)
170 #endif
171 #ifndef CRSRY
172 #define CRSRY (15)
173 #endif
174 #ifndef CLS
175 #define CLS (16)
176 #endif
177 
178 
179 // Values for use with shift_in
180 #ifndef MSBPRE
181 #define MSBPRE 0
182 #endif
183 #ifndef LSBPRE
184 #define LSBPRE 1
185 #endif
186 #ifndef MSBPOST
187 #define MSBPOST 2
188 #endif
189 #ifndef LSBPOST
190 #define LSBPOST 3
191 #endif
192 
193 // Values for use with shift_out
194 #ifndef LSBFIRST
195 #define LSBFIRST 0
196 #endif
197 
198 #ifndef MSBFIRST
199 #define MSBFIRST 1
200 #endif
201 
202 // Counter module values
203 #ifndef NCO_PWM_1
204 #define NCO_PWM_1 (0b00100 << 26)
205 #endif
206 
207 #ifndef CTR_NCO
208 #define CTR_NCO (0b100 << 26)
209 #endif
210 
211 #ifndef CTR_PLL
212 #define CTR_PLL (0b10 << 26)
213 #endif
214 
215 #ifndef DUTY_SE
216 #define DUTY_SE (0b110 << 26)
217 #endif
218 
219 // Define types for simplified driver declarations
220 //typedef FILE* serial;
221 //typedef FILE* fdserial;
222 //typedef FILE* sdcard;
223 //typedef I2C* i2c;
224 
235 void high(int pin);
236 
247 void low(int pin);
248 
260 unsigned int toggle(int pin);
261 
275 unsigned int input(int pin);
276 
288 unsigned int reverse(int pin);
289 
307 unsigned int get_state(int pin);
308 
323 unsigned int get_direction(int pin);
324 
337 unsigned int get_output(int pin);
338 
347 void set_direction(int pin, int direction);
348 
361 void set_output(int pin, int state);
362 
376 unsigned int get_states(int endPin, int startPin);
377 
390 unsigned int get_directions(int endPin, int startPin);
391 
404 unsigned int get_outputs(int endPin, int startPin);
405 
417 void set_directions(int endPin, int startPin, unsigned int pattern);
418 
430 void set_outputs(int endPin, int startPin, unsigned int pattern);
431 
442 void pause(int time);
443 
465 #define pause_ticks(pticks) __builtin_propeller_waitcnt(pticks+CNT, 0)
466 
473 void mark(void);
474 
483 int timeout(int time);
484 
495 void wait(int time);
496 
507 void set_pause_dt(int clockticks);
508 
518 long count(int pin, long duration);
519 
548 void dac_ctr(int pin, int channel, int dacVal);
549 
563 void dac_ctr_res(int bits);
564 
572 void dac_ctr_stop(void);
573 
584 void freqout(int pin, int msTime, int frequency);
585 
600 int pwm_start(unsigned int cycleMicroseconds);
601 
627 void pwm_set(int pin, int channel, int tHigh);
628 
636 void pwm_stop(void);
637 
650 long pulse_in(int pin, int state);
651 
667 void pulse_out(int pin, int time);
668 
684 long rc_time(int pin, int state);
685 
704 void square_wave(int pin, int channel, int freq);
705 
713 void square_wave_stop(void);
714 
724 void set_io_timeout(long clockTicks);
725 
736 void set_io_dt(long clockticks);
737 
738 
750 int shift_in(int pinDat, int pinClk, int mode, int bits);
751 
761 void shift_out(int pinDat, int pinClk, int mode, int bits, int value);
762 
780 i2c *i2c_newbus(int sclpin, int sdapin, int scldrive);
781 
782 
810 HUBTEXT int i2c_out(i2c *bus, int i2cAddr,
811  const unsigned char *regAddr, int regSize,
812  const unsigned char *data, int count);
813 
814 
843 HUBTEXT int i2c_in(i2c *bus, int i2cAddr,
844  const unsigned char *regAddr, int regSize,
845  unsigned char *data, int count);
846 
847 
856 void ee_putByte(char value, int addr);
857 
861 #define ee_put_byte ee_putByte
862 
863 
873 char ee_getByte(int addr);
874 
878 #define ee_get_byte ee_getByte
879 
880 
890 void ee_putInt(int value, int addr);
891 
895 #define ee_put_int ee_putInt
896 
897 
907 int ee_getInt(int addr);
908 
912 #define ee_get_int ee_getInt
913 
914 
925 void ee_putStr(unsigned char *s, int n, int addr);
926 
930 #define ee_put_str ee_putStr
931 
932 
947 char* ee_getStr(unsigned char* s, int n, int addr);
948 
952 #define ee_get_str ee_getStr
953 
954 
969 void ee_putFloat32(float value, int addr);
970 
974 #define ee_put_float32 ee_putFloat32
975 
976 
992 float ee_getFloat32(int addr);
993 
1007 int sd_mount(int doPin, int clkPin, int diPin, int csPin);
1008 
1022 char* itoa(int i, char b[], int base);
1023 
1024 
1036 int start_fpu_cog(void);
1037 
1038 
1050 void stop_fpu_cog(void);
1051 
1052 
1053 int add_driver(_Driver *driverAddr);
1054 
1055 #if defined(__cplusplus)
1056 }
1057 #endif
1058 /* __cplusplus */
1059 #endif
1060 /* SIMPLETOOLS_H */
1061