simpletools library  v0.96
Collection of convenience functions for common microcontroller tasks
simpletools.h
Go to the documentation of this file.
1 
80 #ifndef SIMPLETOOLS_H
81 #define SIMPLETOOLS_H
82 
83 #if defined(__cplusplus)
84 extern "C" {
85 #endif
86 
87 #include <propeller.h>
88 #include "simpletext.h"
89 #include <driver.h>
90 #include <stdio.h>
91 #include <stdlib.h>
92 #include <string.h>
93 #include <cog.h>
94 #include <ctype.h>
95 #include <unistd.h>
96 #include <sys/stat.h>
97 #include <dirent.h>
98 #include <sys/sd.h>
99 #include <math.h>
100 #include "simplei2c.h"
101 
102 // Global variables shared by functions in separate files
103 extern long iodt;
104 extern long t_timeout;
105 extern long pauseTicks;
106 extern long t_mark;
107 extern char setForget;
108 extern int fdserDriverIndex;
109 extern unsigned int buscnt;
110 extern i2c *eeprom;
111 extern int eeInitFlag;
112 
113 //extern i2c *eeprom;
114 //extern int dacCtrBits;
115 
116 #ifndef PI
117 #define PI 3.141592653589793
118 #endif
119 
120 #ifndef EEPROM_ADDR
121 #define EEPROM_ADDR 0xA0 >> 1
122 #endif
123 
124 /* Values for use with SimpleIDE Terminal */
125 #ifndef HOME
126 #define HOME (1)
127 #endif
128 #ifndef CRSRXY
129 #define CRSRXY (2)
130 #endif
131 #ifndef CRSRLF
132 #define CRSRLF (3)
133 #endif
134 #ifndef CRSRRT
135 #define CRSRRT (4)
136 #endif
137 #ifndef CRSRUP
138 #define CRSRUP (5)
139 #endif
140 #ifndef CRSRDN
141 #define CRSRDN (6)
142 #endif
143 #ifndef BEEP
144 #define BEEP (7)
145 #endif
146 #ifndef BKSP
147 #define BKSP (8)
148 #endif
149 #ifndef TAB
150 #define TAB (9)
151 #endif
152 #ifndef NL
153 #define NL (10)
154 #endif
155 #ifndef LF
156 #define LF (10)
157 #endif
158 #ifndef CLREOL
159 #define CLREOL (11)
160 #endif
161 #ifndef CLRDN
162 #define CLRDN (12)
163 #endif
164 #ifndef CR
165 #define CR (13)
166 #endif
167 #ifndef CRSRX
168 #define CRSRX (14)
169 #endif
170 #ifndef CRSRY
171 #define CRSRY (15)
172 #endif
173 #ifndef CLS
174 #define CLS (16)
175 #endif
176 
177 
178 // Values for use with shift_in
179 #ifndef MSBPRE
180 #define MSBPRE 0
181 #endif
182 #ifndef LSBPRE
183 #define LSBPRE 1
184 #endif
185 #ifndef MSBPOST
186 #define MSBPOST 2
187 #endif
188 #ifndef LSBPOST
189 #define LSBPOST 3
190 #endif
191 
192 // Values for use with shift_out
193 #ifndef LSBFIRST
194 #define LSBFIRST 0
195 #endif
196 
197 #ifndef MSBFIRST
198 #define MSBFIRST 1
199 #endif
200 
201 // Counter module values
202 #ifndef NCO_PWM_1
203 #define NCO_PWM_1 (0b00100 << 26)
204 #endif
205 
206 #ifndef CTR_NCO
207 #define CTR_NCO (0b100 << 26)
208 #endif
209 
210 #ifndef CTR_PLL
211 #define CTR_PLL (0b10 << 26)
212 #endif
213 
214 #ifndef DUTY_SE
215 #define DUTY_SE (0b110 << 26)
216 #endif
217 
218 // Define types for simplified driver declarations
219 //typedef FILE* serial;
220 //typedef FILE* fdserial;
221 //typedef FILE* sdcard;
222 //typedef I2C* i2c;
223 
234 void high(int pin);
235 
246 void low(int pin);
247 
259 unsigned int toggle(int pin);
260 
274 unsigned int input(int pin);
275 
287 unsigned int reverse(int pin);
288 
306 unsigned int get_state(int pin);
307 
322 unsigned int get_direction(int pin);
323 
336 unsigned int get_output(int pin);
337 
346 void set_direction(int pin, int direction);
347 
360 void set_output(int pin, int state);
361 
375 unsigned int get_states(int endPin, int startPin);
376 
389 unsigned int get_directions(int endPin, int startPin);
390 
403 unsigned int get_outputs(int endPin, int startPin);
404 
416 void set_directions(int endPin, int startPin, unsigned int pattern);
417 
429 void set_outputs(int endPin, int startPin, unsigned int pattern);
430 
441 void pause(int time);
442 
464 #define pause_ticks(pticks) __builtin_propeller_waitcnt(pticks+CNT, 0)
465 
472 void mark(void);
473 
482 int timeout(int time);
483 
494 void wait(int time);
495 
506 void set_pause_dt(int clockticks);
507 
517 long count(int pin, long duration);
518 
547 void dac_ctr(int pin, int channel, int dacVal);
548 
562 void dac_ctr_res(int bits);
563 
571 void dac_ctr_stop(void);
572 
583 void freqout(int pin, int msTime, int frequency);
584 
599 int pwm_start(unsigned int cycleMicroseconds);
600 
626 void pwm_set(int pin, int channel, int tHigh);
627 
635 void pwm_stop(void);
636 
649 long pulse_in(int pin, int state);
650 
666 void pulse_out(int pin, int time);
667 
683 long rc_time(int pin, int state);
684 
703 void square_wave(int pin, int channel, int freq);
704 
712 void square_wave_stop(void);
713 
723 void set_io_timeout(long clockTicks);
724 
735 void set_io_dt(long clockticks);
736 
737 
749 int shift_in(int pinDat, int pinClk, int mode, int bits);
750 
760 void shift_out(int pinDat, int pinClk, int mode, int bits, int value);
761 
779 i2c *i2c_newbus(int sclpin, int sdapin, int scldrive);
780 
781 
809 HUBTEXT int i2c_out(i2c *bus, int i2cAddr,
810  const unsigned char *regAddr, int regSize,
811  const unsigned char *data, int count);
812 
813 
842 HUBTEXT int i2c_in(i2c *bus, int i2cAddr,
843  const unsigned char *regAddr, int regSize,
844  unsigned char *data, int count);
845 
846 
855 void ee_putByte(char value, int addr);
856 
860 #define ee_put_byte ee_putByte
861 
862 
872 char ee_getByte(int addr);
873 
877 #define ee_get_byte ee_getByte
878 
879 
889 void ee_putInt(int value, int addr);
890 
894 #define ee_put_int ee_putInt
895 
896 
906 int ee_getInt(int addr);
907 
911 #define ee_get_int ee_getInt
912 
913 
924 void ee_putStr(unsigned char *s, int n, int addr);
925 
929 #define ee_put_str ee_putStr
930 
931 
946 char* ee_getStr(unsigned char* s, int n, int addr);
947 
951 #define ee_get_str ee_getStr
952 
953 
968 void ee_putFloat32(float value, int addr);
969 
973 #define ee_put_float32 ee_putFloat32
974 
975 
991 float ee_getFloat32(int addr);
992 
1006 int sd_mount(int doPin, int clkPin, int diPin, int csPin);
1007 
1021 char* itoa(int i, char b[], int base);
1022 
1023 int add_driver(_Driver *driverAddr);
1024 
1025 #if defined(__cplusplus)
1026 }
1027 #endif
1028 /* __cplusplus */
1029 #endif
1030 /* SIMPLETOOLS_H */
1031