PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
simpletools.h
Go to the documentation of this file.
1 
110 #ifndef SIMPLETOOLS_H
111 #define SIMPLETOOLS_H
112 
113 #if defined(__cplusplus)
114 extern "C" {
115 #endif
116 
117 #include <propeller.h>
118 #include "simpletext.h"
119 #include <driver.h>
120 #include <stdio.h>
121 #include <stdlib.h>
122 #include <string.h>
123 #include <cog.h>
124 #include <ctype.h>
125 #include <unistd.h>
126 #include <sys/stat.h>
127 #include <dirent.h>
128 #include <sys/sd.h>
129 #include <math.h>
130 #include "simplei2c.h"
131 
132 
136 extern int ms;
137 
138 
142 extern int us;
143 
144 
145 
157 extern int st_msTicks;
158 
159 
164 extern int st_usTicks;
165 
166 
171 extern int st_iodt;
172 
177 extern int st_timeout;
178 
183 extern int st_pauseTicks;
184 
188 extern int st_mark;
189 
193 extern unsigned int st_buscnt;
194 
198 extern i2c *st_eeprom;
199 
203 extern int st_eeInitFlag;
204 
205 
212 #ifndef PI
213 
216 #define PI 3.141592653589793
217 #endif
218 
219 
220 
228 /* Values for use with SimpleIDE Terminal */
229 #ifndef HOME
230 
233 #define HOME (1)
234 #endif
235 
236 #ifndef CRSRXY
237 
243 #define CRSRXY (2)
244 #endif
245 
246 #ifndef CRSRLF
247 
251 #define CRSRLF (3)
252 #endif
253 
254 #ifndef CRSRRT
255 
259 #define CRSRRT (4)
260 #endif
261 
262 #ifndef CRSRUP
263 
267 #define CRSRUP (5)
268 #endif
269 
270 #ifndef CRSRDN
271 
275 #define CRSRDN (6)
276 #endif
277 
278 #ifndef BEEP
279 
283 #define BEEP (7)
284 #endif
285 
286 #ifndef BKSP
287 
292 #define BKSP (8)
293 #endif
294 
295 #ifndef TAB
296 
300 #define TAB (9)
301 #endif
302 
303 #ifndef NL
304 
308 #define NL (10)
309 #endif
310 
311 #ifndef LF
312 
315 #define LF (10)
316 #endif
317 
318 #ifndef CLREOL
319 
323 #define CLREOL (11)
324 #endif
325 
326 #ifndef CLRDN
327 
331 #define CLRDN (12)
332 #endif
333 
334 #ifndef CR
335 
339 #define CR (13)
340 #endif
341 
342 #ifndef CRSRX
343 
347 #define CRSRX (14)
348 #endif
349 
350 #ifndef CRSRY
351 
355 #define CRSRY (15)
356 #endif
357 
358 #ifndef CLS
359 
363 #define CLS (16)
364 #endif
365 
366 
367 
377 #ifndef MSBPRE
378 
381 #define MSBPRE 0
382 #endif
383 
384 #ifndef LSBPRE
385 
388 #define LSBPRE 1
389 #endif
390 
391 #ifndef MSBPOST
392 
395 #define MSBPOST 2
396 #endif
397 
398 #ifndef LSBPOST
399 
402 #define LSBPOST 3
403 #endif
404 
405 // Values for use with shift_out
406 #ifndef LSBFIRST
407 
410 #define LSBFIRST 0
411 #endif
412 
413 #ifndef MSBFIRST
414 
417 #define MSBFIRST 1
418 #endif
419 
420 
421 
431 #ifndef NCO_PWM_1
432 
436 #define NCO_PWM_1 (0b00100 << 26)
437 #endif
438 
439 #ifndef CTR_NCO
440 
444 #define CTR_NCO (0b100 << 26)
445 #endif
446 
447 #ifndef CTR_PLL
448 
452 #define CTR_PLL (0b10 << 26)
453 #endif
454 
455 #ifndef DUTY_SE
456 
460 #define DUTY_SE (0b110 << 26)
461 #endif
462 
463 
464 
477 #define ee_put_byte ee_putByte
478 
479 
483 #define ee_get_byte ee_getByte
484 
485 
489 #define ee_put_int ee_putInt
490 
491 
495 #define ee_get_int ee_getInt
496 
497 
501 #define ee_put_str ee_putStr
502 
503 
507 #define ee_get_str ee_getStr
508 
509 
513 #define ee_put_float32 ee_putFloat32
514 
515 
520 #define pause_ticks(pticks) __builtin_propeller_waitcnt(pticks+CNT, 0)
521 
522 
523 
533 #ifndef EEPROM_ADDR
534 
537 #define EEPROM_ADDR 0x50
538 #endif
539 
540 
541 
558 void high(int pin);
559 
560 
571 void low(int pin);
572 
573 
588 int input(int pin);
589 
590 
591 
611 unsigned int toggle(int pin);
612 
624 unsigned int reverse(int pin);
625 
626 
644 unsigned int get_state(int pin);
645 
660 unsigned int get_direction(int pin);
661 
674 unsigned int get_output(int pin);
675 
684 void set_direction(int pin, int direction);
685 
698 void set_output(int pin, int state);
699 
700 
701 
724 unsigned int get_states(int endPin, int startPin);
725 
738 unsigned int get_directions(int endPin, int startPin);
739 
752 unsigned int get_outputs(int endPin, int startPin);
753 
765 void set_directions(int endPin, int startPin, unsigned int pattern);
766 
778 void set_outputs(int endPin, int startPin, unsigned int pattern);
779 
780 
781 
782 
803 void pause(int time);
804 
815 void set_pause_dt(int clockticks);
816 
817 
818 
819 
839 long count(int pin, long duration);
840 
869 void dac_ctr(int pin, int channel, int dacVal);
870 
884 void dac_ctr_res(int bits);
885 
893 void dac_ctr_stop(void);
894 
905 void freqout(int pin, int msTime, int frequency);
906 
921 int pwm_start(unsigned int cycleMicroseconds);
922 
948 void pwm_set(int pin, int channel, int tHigh);
949 
957 void pwm_stop(void);
958 
971 long pulse_in(int pin, int state);
972 
988 void pulse_out(int pin, int time);
989 
1005 long rc_time(int pin, int state);
1006 
1025 void square_wave(int pin, int channel, int freq);
1026 
1034 void square_wave_stop(void);
1035 
1045 void set_io_timeout(long clockTicks);
1046 
1057 void set_io_dt(long clockticks);
1058 
1059 
1060 
1061 
1083 int shift_in(int pinDat, int pinClk, int mode, int bits);
1084 
1094 void shift_out(int pinDat, int pinClk, int mode, int bits, int value);
1095 
1096 
1097 
1098 
1127 i2c *i2c_newbus(int sclPin, int sdaPin, int sclDrive);
1128 
1129 
1157 HUBTEXT int i2c_out(i2c *busID, int i2cAddr,
1158  int memAddr, int memAddrCount,
1159  const unsigned char *data, int dataCount);
1160 
1161 
1189 HUBTEXT int i2c_in(i2c *busID, int i2cAddr,
1190  int memAddr, int memAddrCount,
1191  unsigned char *data, int dataCount);
1192 
1193 
1203 HUBTEXT int i2c_busy(i2c *busID, int i2cAddr);
1204 
1205 
1206 
1207 
1227 void ee_putByte(unsigned char value, int addr);
1228 
1238 char ee_getByte(int addr);
1239 
1240 
1250 void ee_putInt(int value, int addr);
1251 
1261 int ee_getInt(int addr);
1262 
1273 void ee_putStr(unsigned char *s, int n, int addr);
1274 
1289 unsigned char* ee_getStr(unsigned char* s, int n, int addr);
1290 
1305 void ee_putFloat32(float value, int addr);
1306 
1322 float ee_getFloat32(int addr);
1323 
1345 void ee_config(int sclPin, int sdaPin, int sclDrive);
1346 
1347 
1348 
1372 int sd_mount(int doPin, int clkPin, int diPin, int csPin);
1373 
1374 
1375 
1411 int *cog_run(void (*function)(void *par), int stacksize);
1412 
1413 
1421 int cog_num(int *coginfo);
1422 
1423 
1433 void cog_end(int *coginfo);
1434 
1435 
1436 
1479 void term_cmd(int termConst, ...);
1480 
1481 
1482 
1507 float constrainFloat(float value, float min, float max);
1508 
1509 
1525 int constrainInt(int value, int min, int max);
1526 
1527 
1541 void endianSwap(void *resultAddr, void *varAddr, int byteCount);
1542 
1543 
1563 float mapFloat(float value, float fromMin, float fromMax, float toMin, float toMax);
1564 
1565 
1584 int mapInt(int value, int fromMin, int fromMax, int toMin, int toMax);
1585 
1586 
1599 int random(int limitLow, int limitHigh);
1600 
1601 
1602 
1603 
1627 void mark(void);
1628 
1629 
1652 int timeout(int time);
1653 
1680 void wait(int time);
1681 
1682 
1683 
1690 #if defined(__cplusplus)
1691 }
1692 #endif
1693 /* __cplusplus */
1694 #endif
1695 /* SIMPLETOOLS_H */
1696 
ee_getInt
int ee_getInt(int addr)
Get an int value from a certain address in the Propeller Chip's dedicated EEPROM. If you are fetching...
Definition: eeprom_getInt.c:24
pwm_stop
void pwm_stop(void)
Shut down PWM process and reclaim cog and I/O pins for other uses.
Definition: pwm.c:58
st_buscnt
unsigned int st_buscnt
Variable used by i2c_newbus.
Definition: i2c_init.c:22
set_directions
void set_directions(int endPin, int startPin, unsigned int pattern)
Set directions for a contiguous group of I/O pins.
Definition: setDirections.c:19
square_wave_stop
void square_wave_stop(void)
Stop the cog that's transmitting a square wave.
Definition: squareWave.c:72
st_msTicks
int st_msTicks
Propeller system clock ticks in 1 millisecond. Changing this value is not recommended because it can ...
Definition: timeTicks.c:22
shift_out
void shift_out(int pinDat, int pinClk, int mode, int bits, int value)
Send data to a synchronous serial device.
Definition: shiftOut.c:19
ee_putByte
void ee_putByte(unsigned char value, int addr)
Store a byte value at a certain address in the Propeller Chip's dedicated EEPROM.
Definition: eeprom_putByte.c:24
us
int us
Propeller system clock ticks in 1 millisecond (us).
Definition: abcalibrate.c:36
endianSwap
void endianSwap(void *resultAddr, void *varAddr, int byteCount)
Take bytes in one variable at varAddr, swap their order, and store them in another variable at result...
Definition: endianSwap.c:15
wait
void wait(int time)
Waits a certain number of time increments from the last call to mark or wait functions (deprecated).
Definition: wait.c:19
st_timeout
int st_timeout
Clock ticks in a time increment used by pulse_in, pulse_out, and rc_time. Default value is the number...
Definition: timeTicks.c:25
ee_putInt
void ee_putInt(int value, int addr)
Store an int value at a certain address in the Propeller Chip's dedicated EEPROM. An int value occupi...
Definition: eeprom_putInt.c:24
ee_getByte
char ee_getByte(int addr)
Get a byte value from a certain address in the Propeller Chip's dedicated EEPROM.
Definition: eeprom_getByte.c:24
get_states
unsigned int get_states(int endPin, int startPin)
Get states of a contiguous group of I/O pins.
Definition: getStates.c:19
ee_putFloat32
void ee_putFloat32(float value, int addr)
Store a 32-bit precision floating point value at a certain address in the Propeller Chip's dedicated ...
Definition: eeprom_putFloat.c:24
freqout
void freqout(int pin, int msTime, int frequency)
Use same cog to send square wave of a certain frequency for a certain amount of time....
Definition: freqout.c:10
pause
void pause(int time)
Delay cog from moving on to the next statement for a certain length of time.
Definition: libws2812.c:125
pwm_start
int pwm_start(unsigned int cycleMicroseconds)
Start pulse width modulation (PWM) process in another cog.
Definition: pwm.c:34
i2c_in
HUBTEXT int i2c_in(i2c *busID, int i2cAddr, int memAddr, int memAddrCount, unsigned char *data, int dataCount)
Receive data from device using I2C protocol.
Definition: i2c_in.c:20
low
void low(int pin)
Set an I/O pin to output-low.
Definition: low.c:19
set_outputs
void set_outputs(int endPin, int startPin, unsigned int pattern)
Set output states for a contiguous group of I/O pins.
Definition: setOutputs.c:20
i2c_busy
HUBTEXT int i2c_busy(i2c *busID, int i2cAddr)
Check if I2C device is busy or responding.
Definition: i2c_busy.c:20
st_eeprom
i2c * st_eeprom
The busID for the Propeller Activity Board's EEPROM bus.
Definition: accel_shaken.c:9
mark
void mark(void)
Mark the current time (deprecated).
Definition: mark.c:19
timeout
int timeout(int time)
Compares the time against the time elapsed since mark (deprecated).
Definition: timeout.c:19
cog_num
int cog_num(int *coginfo)
Get the cog ID.
Definition: cognum.c:15
dirent.h
Provides directory operations API declarations.
ee_putStr
void ee_putStr(unsigned char *s, int n, int addr)
Store a string of byte values starting at a certain address in the Propeller Chip's dedicated EEPROM.
Definition: eeprom_putStr.c:25
pulse_in
long pulse_in(int pin, int state)
Measure the duration of a pulse applied to an I/O pin.
Definition: pulseIn.c:19
term_cmd
void term_cmd(int termConst,...)
Send a command to SimpleIDE Terminal. Examples of commands include HOME, CLS, BKSP,...
Definition: term_cmd.c:44
mapFloat
float mapFloat(float value, float fromMin, float fromMax, float toMin, float toMax)
Maps a floating point value from its position in one range to its corresponding. position in a differ...
Definition: mapFloat.c:21
shift_in
int shift_in(int pinDat, int pinClk, int mode, int bits)
Receive data from a synchronous serial device.
Definition: shiftIn.c:20
pulse_out
void pulse_out(int pin, int time)
Transmit a pulse with an I/O pin.
Definition: pulseOut.c:19
st_pauseTicks
int st_pauseTicks
Clock ticks in a time increment used by pause function. Default value is the number of system clock t...
Definition: timeTicks.c:26
pwm_set
void pwm_set(int pin, int channel, int tHigh)
Set a PWM signal's high time.
Definition: pwm.c:42
i2c_newbus
i2c * i2c_newbus(int sclPin, int sdaPin, int sclDrive)
Set up a simple serial driver with transmit & receive pins.
Definition: i2c_init.c:26
get_state
unsigned int get_state(int pin)
Check the state of an I/O pin without setting it to input.
Definition: getState.c:19
reverse
unsigned int reverse(int pin)
Reverse the direction of an I/O pin.
Definition: reverse.c:19
cog.h
Inludes common API definitions for COG programming.
sd_mount
int sd_mount(int doPin, int clkPin, int diPin, int csPin)
Mount an SD card with the minimal 4-pin interface. For Parallax Learn Site examples,...
Definition: sddriverconfig.c:7
rc_time
long rc_time(int pin, int state)
Set I/O pin to input and measure the time it takes a signal to transition from a start state to the o...
Definition: rcTime.c:19
dac_ctr_res
void dac_ctr_res(int bits)
Set D/A voltage resolution.
Definition: dac.c:31
input
int input(int pin)
Set an I/O pin to input and return 1 if pin detects a high signal, or 0 if it detects low.
Definition: input.c:19
get_direction
unsigned int get_direction(int pin)
Check the direction of the I/O pin.
Definition: getDirection.c:19
count
long count(int pin, long duration)
Count number of low to high transitions an external input applies to an I/O pin over a certain period...
Definition: count.c:19
constrainFloat
float constrainFloat(float value, float min, float max)
Constrains a floating point value to a range from a minimum value to a maximum value....
Definition: constrainFloat.c:22
constrainInt
int constrainInt(int value, int min, int max)
Constrains an integer value to a range from a minimum value to a maximum value. If the value is above...
Definition: constrainInt.c:21
simpletext.h
This library provides a collection of functions for communicating with text devices such as SimpleIDE...
set_io_timeout
void set_io_timeout(long clockTicks)
Sets the timeout value for the following timed I/O functions: pulse_in, rc_time.
Definition: setTimeout.c:19
i2c_st
Definition: simplei2c.h:25
set_io_dt
void set_io_dt(long clockticks)
Sets the time increment for the following timed I/O functions: count, pulse_in, pulse_out,...
Definition: setIoDt.c:19
get_directions
unsigned int get_directions(int endPin, int startPin)
Get directions for a contiguous group of I/O pins.
Definition: getDirections.c:19
cog_end
void cog_end(int *coginfo)
End function code running in another cog that was launched with cog_run.
Definition: cogend.c:15
square_wave
void square_wave(int pin, int channel, int freq)
Make I/O pin transmit a repeated high/low signal at a certain frequency. High and low times are the s...
Definition: squareWave.c:38
random
int random(int limitLow, int limitHigh)
Generates a pseudo-random integer value that falls in a range from limitLow to limitHigh....
Definition: random.c:22
st_eeInitFlag
int st_eeInitFlag
Initialization flag used by ee_ functions.
Definition: accel_shaken.c:10
st_usTicks
int st_usTicks
Propeller system clock ticks in 1 microsecond. Changing this value is not recommended because it can ...
Definition: timeTicks.c:23
mapInt
int mapInt(int value, int fromMin, int fromMax, int toMin, int toMax)
Maps an integer value from its position in one range to its corresponding. position in a different ra...
Definition: mapInt.c:23
st_iodt
int st_iodt
Clock ticks in a time increment used by pulse_in, pulse_out, and rc_time. Default value is the number...
Definition: timeTicks.c:24
simplei2c.h
Provides simple i2c start, stop, read, and write functions. See simpletools library for additional I2...
st_mark
int st_mark
Variable shared by mark and time_out functions.
ms
int ms
Propeller system clock ticks in 1 millisecond (ms).
Definition: timeTicks.c:20
ee_config
void ee_config(int sclPin, int sdaPin, int sclDrive)
Optional function for setting a custom EEPROM configuration. Other ee_ functions automatically check ...
Definition: eeprom_initSclDrive.c:22
set_direction
void set_direction(int pin, int direction)
Set an I/O pin to a given direction.
Definition: setDirection.c:19
ee_getFloat32
float ee_getFloat32(int addr)
Fetch a 32-bit precision floating point value from a certain address in the Propeller Chip's dedicate...
Definition: eeprom_getFloat.c:24
cog_run
int * cog_run(void(*function)(void *par), int stacksize)
Run a function's code in the next available cog (processor).
Definition: cogrun.c:15
get_outputs
unsigned int get_outputs(int endPin, int startPin)
Get output settings for a contiguous group of I/O pins.
Definition: getOutputs.c:19
i2c_out
HUBTEXT int i2c_out(i2c *busID, int i2cAddr, int memAddr, int memAddrCount, const unsigned char *data, int dataCount)
Send data to device using I2C protocol.
Definition: i2c_out.c:20
dac_ctr_stop
void dac_ctr_stop(void)
Stop the cog that's transmitting the DAC signal(s).
Definition: dac.c:96
set_pause_dt
void set_pause_dt(int clockticks)
Set time increment for pause function.
Definition: setPauseDt.c:19
ee_getStr
unsigned char * ee_getStr(unsigned char *s, int n, int addr)
Fetch a string of byte values starting at a certain address in Propeller Chip's dedicated EEPROM.
high
void high(int pin)
Set an I/O pin to output-high.
Definition: high.c:19
get_output
unsigned int get_output(int pin)
Get I/O pin output state.
Definition: getOutput.c:19
toggle
unsigned int toggle(int pin)
Toggle the output state of the I/O pin.
Definition: toggle.c:19
set_output
void set_output(int pin, int state)
Set I/O pin output register bit to either 1 or 0.
Definition: setOutput.c:19
dac_ctr
void dac_ctr(int pin, int channel, int dacVal)
Set D/A voltage.
Definition: dac.c:36
HUBTEXT
#define HUBTEXT
HUBTEXT tells compiler to put code into HUB RAM section.
Definition: propeller.h:43