simpletools library  v0.94
Collection of convenience functions for common microcontroller tasks
simpletools.h
Go to the documentation of this file.
1 
76 #ifndef SIMPLETOOLS_H
77 #define SIMPLETOOLS_H
78 
79 #if defined(__cplusplus)
80 extern "C" {
81 #endif
82 
83 #include <propeller.h>
84 #include "simpletext.h"
85 #include <driver.h>
86 #include <stdio.h>
87 #include <stdlib.h>
88 #include <string.h>
89 #include <cog.h>
90 #include <ctype.h>
91 #include <unistd.h>
92 #include <sys/stat.h>
93 #include <dirent.h>
94 #include <sys/sd.h>
95 #include <math.h>
96 #include "simplei2c.h"
97 
98 // Global variables shared by functions in separate files
99 extern long iodt;
100 extern long t_timeout;
101 extern long pauseTicks;
102 extern long t_mark;
103 extern char setForget;
104 extern int fdserDriverIndex;
105 extern unsigned int buscnt;
106 extern i2c *eeprom;
107 extern int eeInitFlag;
108 
109 //extern i2c *eeprom;
110 //extern int dacCtrBits;
111 
112 #ifndef PI
113 #define PI 3.141592653589793
114 #endif
115 
116 #ifndef EEPROM_ADDR
117 #define EEPROM_ADDR 0xA0 >> 1
118 #endif
119 
120 /* Values for use with SimpleIDE Terminal */
121 #ifndef HOME
122 #define HOME (1)
123 #endif
124 #ifndef CRSRXY
125 #define CRSRXY (2)
126 #endif
127 #ifndef CRSRLF
128 #define CRSRLF (3)
129 #endif
130 #ifndef CRSRRT
131 #define CRSRRT (4)
132 #endif
133 #ifndef CRSRUP
134 #define CRSRUP (5)
135 #endif
136 #ifndef CRSRDN
137 #define CRSRDN (6)
138 #endif
139 #ifndef BEEP
140 #define BEEP (7)
141 #endif
142 #ifndef BKSP
143 #define BKSP (8)
144 #endif
145 #ifndef TAB
146 #define TAB (9)
147 #endif
148 #ifndef NL
149 #define NL (10)
150 #endif
151 #ifndef LF
152 #define LF (10)
153 #endif
154 #ifndef CLREOL
155 #define CLREOL (11)
156 #endif
157 #ifndef CLRDN
158 #define CLRDN (12)
159 #endif
160 #ifndef CR
161 #define CR (13)
162 #endif
163 #ifndef CRSRX
164 #define CRSRX (14)
165 #endif
166 #ifndef CRSRY
167 #define CRSRY (15)
168 #endif
169 #ifndef CLS
170 #define CLS (16)
171 #endif
172 
173 
174 // Values for use with shift_in
175 #ifndef MSBPRE
176 #define MSBPRE 0
177 #endif
178 #ifndef LSBPRE
179 #define LSBPRE 1
180 #endif
181 #ifndef MSBPOST
182 #define MSBPOST 2
183 #endif
184 #ifndef LSBPOST
185 #define LSBPOST 3
186 #endif
187 
188 // Values for use with shift_out
189 #ifndef LSBFIRST
190 #define LSBFIRST 0
191 #endif
192 
193 #ifndef MSBFIRST
194 #define MSBFIRST 1
195 #endif
196 
197 // Counter module values
198 #ifndef NCO_PWM_1
199 #define NCO_PWM_1 (0b00100 << 26)
200 #endif
201 
202 #ifndef CTR_NCO
203 #define CTR_NCO (0b100 << 26)
204 #endif
205 
206 #ifndef CTR_PLL
207 #define CTR_PLL (0b10 << 26)
208 #endif
209 
210 #ifndef DUTY_SE
211 #define DUTY_SE (0b110 << 26)
212 #endif
213 
214 // Define types for simplified driver declarations
215 //typedef FILE* serial;
216 //typedef FILE* fdserial;
217 //typedef FILE* sdcard;
218 //typedef I2C* i2c;
219 
230 void high(int pin);
231 
242 void low(int pin);
243 
255 unsigned int toggle(int pin);
256 
270 unsigned int input(int pin);
271 
283 unsigned int reverse(int pin);
284 
302 unsigned int get_state(int pin);
303 
318 unsigned int get_direction(int pin);
319 
332 unsigned int get_output(int pin);
333 
342 void set_direction(int pin, int direction);
343 
356 void set_output(int pin, int state);
357 
371 unsigned int get_states(int endPin, int startPin);
372 
385 unsigned int get_directions(int endPin, int startPin);
386 
399 unsigned int get_outputs(int endPin, int startPin);
400 
412 void set_directions(int endPin, int startPin, unsigned int pattern);
413 
425 void set_outputs(int endPin, int startPin, unsigned int pattern);
426 
437 void pause(int time);
438 
460 #define pause_ticks(pticks) __builtin_propeller_waitcnt(pticks+CNT, 0)
461 
468 void mark(void);
469 
478 int timeout(int time);
479 
490 void wait(int time);
491 
502 void set_pause_dt(int clockticks);
503 
513 long count(int pin, long duration);
514 
543 void dac_ctr(int pin, int channel, int dacVal);
544 
558 void dac_ctr_res(int bits);
559 
567 void dac_ctr_stop(void);
568 
579 void freqout(int pin, int msTime, int frequency);
580 
595 int pwm_start(unsigned int cycleMicroseconds);
596 
622 void pwm_set(int pin, int channel, int tHigh);
623 
631 void pwm_stop(void);
632 
645 long pulse_in(int pin, int state);
646 
662 void pulse_out(int pin, int time);
663 
679 long rc_time(int pin, int state);
680 
699 void square_wave(int pin, int channel, int freq);
700 
708 void square_wave_stop(void);
709 
719 void set_io_timeout(long clockTicks);
720 
731 void set_io_dt(long clockticks);
732 
733 
745 int shift_in(int pinDat, int pinClk, int mode, int bits);
746 
756 void shift_out(int pinDat, int pinClk, int mode, int bits, int value);
757 
775 i2c *i2c_newbus(int sclpin, int sdapin, int scldrive);
776 
777 
805 HUBTEXT int i2c_out(i2c *bus, int i2cAddr,
806  const unsigned char *regAddr, int regSize,
807  const unsigned char *data, int count);
808 
809 
838 HUBTEXT int i2c_in(i2c *bus, int i2cAddr,
839  const unsigned char *regAddr, int regSize,
840  unsigned char *data, int count);
841 
842 
851 void ee_putByte(char value, int addr);
852 
856 #define ee_put_byte ee_putByte
857 
858 
868 char ee_getByte(int addr);
869 
873 #define ee_get_byte ee_getByte
874 
875 
885 void ee_putInt(int value, int addr);
886 
890 #define ee_put_int ee_putInt
891 
892 
902 int ee_getInt(int addr);
903 
907 #define ee_get_int ee_getInt
908 
909 
920 void ee_putStr(unsigned char *s, int n, int addr);
921 
925 #define ee_put_str ee_putStr
926 
927 
942 char* ee_getStr(unsigned char* s, int n, int addr);
943 
947 #define ee_get_str ee_getStr
948 
949 
964 void ee_putFloat32(float value, int addr);
965 
969 #define ee_put_float32 ee_putFloat32
970 
971 
987 float ee_getFloat32(int addr);
988 
1002 int sd_mount(int doPin, int clkPin, int diPin, int csPin);
1003 
1017 char* itoa(int i, char b[], int base);
1018 
1019 int add_driver(_Driver *driverAddr);
1020 
1021 #if defined(__cplusplus)
1022 }
1023 #endif
1024 /* __cplusplus */
1025 #endif
1026 /* SIMPLETOOLS_H */
1027