simpletools library v0.95 Collection of convenience functions for common microcontroller tasks

- Main Page
- Files

- File List
- Globals

simpletools.h
Go to the documentation of this file.
1
78 #ifndef SIMPLETOOLS_H
79 #define SIMPLETOOLS_H
80
81 #if defined(__cplusplus)
82 extern "C" {
83 #endif
84
85 #include <propeller.h>
86 #include "simpletext.h"
87 #include <driver.h>
88 #include <stdio.h>
89 #include <stdlib.h>
90 #include <string.h>
91 #include <cog.h>
92 #include <ctype.h>
93 #include <unistd.h>
94 #include <sys/stat.h>
95 #include <dirent.h>
96 #include <sys/sd.h>
97 #include <math.h>
98 #include "simplei2c.h"
99
100 // Global variables shared by functions in separate files
101 extern long iodt;
102 extern long t_timeout;
103 extern long pauseTicks;
104 extern long t_mark;
105 extern char setForget;
106 extern int fdserDriverIndex;
107 extern unsigned int buscnt;
108 extern i2c *eeprom;
109 extern int eeInitFlag;
110
111 //extern i2c *eeprom;
112 //extern int dacCtrBits;
113
114 #ifndef PI
115 #define PI 3.141592653589793
116 #endif
117
118 #ifndef EEPROM_ADDR
119 #define EEPROM_ADDR 0xA0 >> 1
120 #endif
121
122 /* Values for use with SimpleIDE Terminal */
123 #ifndef HOME
124 #define HOME (1)
125 #endif
126 #ifndef CRSRXY
127 #define CRSRXY (2)
128 #endif
129 #ifndef CRSRLF
130 #define CRSRLF (3)
131 #endif
132 #ifndef CRSRRT
133 #define CRSRRT (4)
134 #endif
135 #ifndef CRSRUP
136 #define CRSRUP (5)
137 #endif
138 #ifndef CRSRDN
139 #define CRSRDN (6)
140 #endif
141 #ifndef BEEP
142 #define BEEP (7)
143 #endif
144 #ifndef BKSP
145 #define BKSP (8)
146 #endif
147 #ifndef TAB
148 #define TAB (9)
149 #endif
150 #ifndef NL
151 #define NL (10)
152 #endif
153 #ifndef LF
154 #define LF (10)
155 #endif
156 #ifndef CLREOL
157 #define CLREOL (11)
158 #endif
159 #ifndef CLRDN
160 #define CLRDN (12)
161 #endif
162 #ifndef CR
163 #define CR (13)
164 #endif
165 #ifndef CRSRX
166 #define CRSRX (14)
167 #endif
168 #ifndef CRSRY
169 #define CRSRY (15)
170 #endif
171 #ifndef CLS
172 #define CLS (16)
173 #endif
174
175
176 // Values for use with shift_in
177 #ifndef MSBPRE
178 #define MSBPRE 0
179 #endif
180 #ifndef LSBPRE
181 #define LSBPRE 1
182 #endif
183 #ifndef MSBPOST
184 #define MSBPOST 2
185 #endif
186 #ifndef LSBPOST
187 #define LSBPOST 3
188 #endif
189
190 // Values for use with shift_out
191 #ifndef LSBFIRST
192 #define LSBFIRST 0
193 #endif
194
195 #ifndef MSBFIRST
196 #define MSBFIRST 1
197 #endif
198
199 // Counter module values
200 #ifndef NCO_PWM_1
201 #define NCO_PWM_1 (0b00100 << 26)
202 #endif
203
204 #ifndef CTR_NCO
205 #define CTR_NCO (0b100 << 26)
206 #endif
207
208 #ifndef CTR_PLL
209 #define CTR_PLL (0b10 << 26)
210 #endif
211
212 #ifndef DUTY_SE
213 #define DUTY_SE (0b110 << 26)
214 #endif
215
216 // Define types for simplified driver declarations
217 //typedef FILE* serial;
218 //typedef FILE* fdserial;
219 //typedef FILE* sdcard;
220 //typedef I2C* i2c;
221
232 void high(int pin);
233
244 void low(int pin);
245
257 unsigned int toggle(int pin);
258
272 unsigned int input(int pin);
273
285 unsigned int reverse(int pin);
286
304 unsigned int get_state(int pin);
305
320 unsigned int get_direction(int pin);
321
334 unsigned int get_output(int pin);
335
344 void set_direction(int pin, int direction);
345
358 void set_output(int pin, int state);
359
373 unsigned int get_states(int endPin, int startPin);
374
387 unsigned int get_directions(int endPin, int startPin);
388
401 unsigned int get_outputs(int endPin, int startPin);
402
414 void set_directions(int endPin, int startPin, unsigned int pattern);
415
427 void set_outputs(int endPin, int startPin, unsigned int pattern);
428
439 void pause(int time);
440
462 #define pause_ticks(pticks) __builtin_propeller_waitcnt(pticks+CNT, 0)
463
470 void mark(void);
471
480 int timeout(int time);
481
492 void wait(int time);
493
504 void set_pause_dt(int clockticks);
505
515 long count(int pin, long duration);
516
545 void dac_ctr(int pin, int channel, int dacVal);
546
560 void dac_ctr_res(int bits);
561
569 void dac_ctr_stop(void);
570
581 void freqout(int pin, int msTime, int frequency);
582
597 int pwm_start(unsigned int cycleMicroseconds);
598
624 void pwm_set(int pin, int channel, int tHigh);
625
633 void pwm_stop(void);
634
647 long pulse_in(int pin, int state);
648
664 void pulse_out(int pin, int time);
665
681 long rc_time(int pin, int state);
682
701 void square_wave(int pin, int channel, int freq);
702
710 void square_wave_stop(void);
711
721 void set_io_timeout(long clockTicks);
722
733 void set_io_dt(long clockticks);
734
735
747 int shift_in(int pinDat, int pinClk, int mode, int bits);
748
758 void shift_out(int pinDat, int pinClk, int mode, int bits, int value);
759
777 i2c *i2c_newbus(int sclpin, int sdapin, int scldrive);
778
779
807 HUBTEXT int i2c_out(i2c *bus, int i2cAddr,
808 const unsigned char *regAddr, int regSize,
809 const unsigned char *data, int count);
810
811
840 HUBTEXT int i2c_in(i2c *bus, int i2cAddr,
841 const unsigned char *regAddr, int regSize,
842 unsigned char *data, int count);
843
844
853 void ee_putByte(char value, int addr);
854
858 #define ee_put_byte ee_putByte
859
860
870 char ee_getByte(int addr);
871
875 #define ee_get_byte ee_getByte
876
877
887 void ee_putInt(int value, int addr);
888
892 #define ee_put_int ee_putInt
893
894
904 int ee_getInt(int addr);
905
909 #define ee_get_int ee_getInt
910
911
922 void ee_putStr(unsigned char *s, int n, int addr);
923
927 #define ee_put_str ee_putStr
928
929
944 char* ee_getStr(unsigned char* s, int n, int addr);
945
949 #define ee_get_str ee_getStr
950
951
966 void ee_putFloat32(float value, int addr);
967
971 #define ee_put_float32 ee_putFloat32
972
973
989 float ee_getFloat32(int addr);
990
1004 int sd_mount(int doPin, int clkPin, int diPin, int csPin);
1005
1019 char* itoa(int i, char b[], int base);
1020
1021 int add_driver(_Driver *driverAddr);
1022
1023 #if defined(__cplusplus)
1024 }
1025 #endif
1026 /* __cplusplus */
1027 #endif
1028 /* SIMPLETOOLS_H */
1029