simpletools library  v0.93
Collection of convenience functions for common microcontroller tasks
simpletools.h
Go to the documentation of this file.
1 
73 #ifndef SIMPLETOOLS_H
74 #define SIMPLETOOLS_H
75 
76 #if defined(__cplusplus)
77 extern "C" {
78 #endif
79 
80 #include <propeller.h>
81 #include "simpletext.h"
82 #include <driver.h>
83 #include <stdio.h>
84 #include <stdlib.h>
85 #include <string.h>
86 #include <cog.h>
87 #include <ctype.h>
88 #include <unistd.h>
89 #include <sys/stat.h>
90 #include <dirent.h>
91 #include <sys/sd.h>
92 #include <math.h>
93 #include "simplei2c.h"
94 
95 // Global variables shared by functions in separate files
96 extern long iodt;
97 extern long t_timeout;
98 extern long pauseTicks;
99 extern long t_mark;
100 extern char setForget;
101 extern int fdserDriverIndex;
102 extern unsigned int buscnt;
103 extern i2c *eeprom;
104 extern int eeInitFlag;
105 
106 //extern i2c *eeprom;
107 //extern int dacCtrBits;
108 
109 #ifndef PI
110 #define PI 3.141592653589793
111 #endif
112 
113 #ifndef EEPROM_ADDR
114 #define EEPROM_ADDR 0xA0 >> 1
115 #endif
116 
117 /* Values for use with SimpleIDE Terminal */
118 #ifndef HOME
119 #define HOME (1)
120 #endif
121 #ifndef CRSRXY
122 #define CRSRXY (2)
123 #endif
124 #ifndef CRSRLF
125 #define CRSRLF (3)
126 #endif
127 #ifndef CRSRRT
128 #define CRSRRT (4)
129 #endif
130 #ifndef CRSRUP
131 #define CRSRUP (5)
132 #endif
133 #ifndef CRSRDN
134 #define CRSRDN (6)
135 #endif
136 #ifndef BEEP
137 #define BEEP (7)
138 #endif
139 #ifndef BKSP
140 #define BKSP (8)
141 #endif
142 #ifndef TAB
143 #define TAB (9)
144 #endif
145 #ifndef NL
146 #define NL (10)
147 #endif
148 #ifndef LF
149 #define LF (10)
150 #endif
151 #ifndef CLREOL
152 #define CLREOL (11)
153 #endif
154 #ifndef CLRDN
155 #define CLRDN (12)
156 #endif
157 #ifndef CR
158 #define CR (13)
159 #endif
160 #ifndef CRSRX
161 #define CRSRX (14)
162 #endif
163 #ifndef CRSRY
164 #define CRSRY (15)
165 #endif
166 #ifndef CLS
167 #define CLS (16)
168 #endif
169 
170 
171 // Values for use with shift_in
172 #ifndef MSBPRE
173 #define MSBPRE 0
174 #endif
175 #ifndef LSBPRE
176 #define LSBPRE 1
177 #endif
178 #ifndef MSBPOST
179 #define MSBPOST 2
180 #endif
181 #ifndef LSBPOST
182 #define LSBPOST 3
183 #endif
184 
185 // Values for use with shift_out
186 #ifndef LSBFIRST
187 #define LSBFIRST 0
188 #endif
189 
190 #ifndef MSBFIRST
191 #define MSBFIRST 1
192 #endif
193 
194 // Counter module values
195 #ifndef NCO_PWM_1
196 #define NCO_PWM_1 (0b00100 << 26)
197 #endif
198 
199 #ifndef CTR_NCO
200 #define CTR_NCO (0b100 << 26)
201 #endif
202 
203 #ifndef CTR_PLL
204 #define CTR_PLL (0b10 << 26)
205 #endif
206 
207 #ifndef DUTY_SE
208 #define DUTY_SE (0b110 << 26)
209 #endif
210 
211 // Define types for simplified driver declarations
212 //typedef FILE* serial;
213 //typedef FILE* fdserial;
214 //typedef FILE* sdcard;
215 //typedef I2C* i2c;
216 
227 void high(int pin);
228 
239 void low(int pin);
240 
252 unsigned int toggle(int pin);
253 
267 unsigned int input(int pin);
268 
280 unsigned int reverse(int pin);
281 
299 unsigned int get_state(int pin);
300 
315 unsigned int get_direction(int pin);
316 
329 unsigned int get_output(int pin);
330 
339 void set_direction(int pin, int direction);
340 
353 void set_output(int pin, int state);
354 
368 unsigned int get_states(int endPin, int startPin);
369 
382 unsigned int get_directions(int endPin, int startPin);
383 
396 unsigned int get_outputs(int endPin, int startPin);
397 
409 void set_directions(int endPin, int startPin, unsigned int pattern);
410 
422 void set_outputs(int endPin, int startPin, unsigned int pattern);
423 
434 void pause(int time);
435 
457 #define pause_ticks(pticks) __builtin_propeller_waitcnt(pticks+CNT, 0)
458 
465 void mark(void);
466 
475 int timeout(int time);
476 
487 void wait(int time);
488 
499 void set_pause_dt(int clockticks);
500 
510 long count(int pin, long duration);
511 
540 void dac_ctr(int pin, int channel, int dacVal);
541 
555 void dac_ctr_res(int bits);
556 
564 void dac_ctr_stop(void);
565 
576 void freqout(int pin, int msTime, int frequency);
577 
592 int pwm_start(unsigned int cycleMicroseconds);
593 
619 void pwm_set(int pin, int channel, int tHigh);
620 
628 void pwm_stop(void);
629 
642 long pulse_in(int pin, int state);
643 
659 void pulse_out(int pin, int time);
660 
676 long rc_time(int pin, int state);
677 
696 void square_wave(int pin, int channel, int freq);
697 
705 void square_wave_stop(void);
706 
716 void set_io_timeout(long clockTicks);
717 
728 void set_io_dt(long clockticks);
729 
730 
742 int shift_in(int pinDat, int pinClk, int mode, int bits);
743 
753 void shift_out(int pinDat, int pinClk, int mode, int bits, int value);
754 
772 i2c *i2c_newbus(int sclpin, int sdapin, int scldrive);
773 
774 
802 HUBTEXT int i2c_out(i2c *bus, int i2cAddr,
803  const unsigned char *regAddr, int regSize,
804  const unsigned char *data, int count);
805 
806 
835 HUBTEXT int i2c_in(i2c *bus, int i2cAddr,
836  const unsigned char *regAddr, int regSize,
837  unsigned char *data, int count);
838 
839 
848 void ee_putByte(char value, int addr);
849 
853 #define ee_put_byte ee_putByte
854 
855 
865 char ee_getByte(int addr);
866 
870 #define ee_get_byte ee_getByte
871 
872 
882 void ee_putInt(int value, int addr);
883 
887 #define ee_put_int ee_putInt
888 
889 
899 int ee_getInt(int addr);
900 
904 #define ee_get_int ee_getInt
905 
906 
917 void ee_putStr(unsigned char *s, int n, int addr);
918 
922 #define ee_put_str ee_putStr
923 
924 
939 char* ee_getStr(unsigned char* s, int n, int addr);
940 
944 #define ee_get_str ee_getStr
945 
946 
961 void ee_putFloat32(float value, int addr);
962 
966 #define ee_put_float32 ee_putFloat32
967 
968 
984 float ee_getFloat32(int addr);
985 
999 int sd_mount(int doPin, int clkPin, int diPin, int csPin);
1000 
1014 char* itoa(int i, char b[], int base);
1015 
1016 int add_driver(_Driver *driverAddr);
1017 
1018 #if defined(__cplusplus)
1019 }
1020 #endif
1021 /* __cplusplus */
1022 #endif
1023 /* SIMPLETOOLS_H */
1024