2014-01-12 22:31:59 +01:00
|
|
|
/*
|
|
|
|
This is free and unencumbered software released into the public domain.
|
|
|
|
|
|
|
|
Anyone is free to copy, modify, publish, use, compile, sell, or
|
|
|
|
distribute this software, either in source code form or as a compiled
|
|
|
|
binary, for any purpose, commercial or non-commercial, and by any
|
|
|
|
means.
|
|
|
|
|
|
|
|
In jurisdictions that recognize copyright laws, the author or authors
|
|
|
|
of this software dedicate any and all copyright interest in the
|
|
|
|
software to the public domain. We make this dedication for the benefit
|
|
|
|
of the public at large and to the detriment of our heirs and
|
|
|
|
successors. We intend this dedication to be an overt act of
|
|
|
|
relinquishment in perpetuity of all present and future rights to this
|
|
|
|
software under copyright law.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
For more information, please refer to <http://unlicense.org/>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PIGPIOD_IF_H
|
|
|
|
#define PIGPIOD_IF_H
|
|
|
|
|
|
|
|
#include "pigpio.h"
|
|
|
|
|
2014-04-19 13:19:29 +02:00
|
|
|
#define PIGPIOD_IF_VERSION 5
|
2014-01-12 22:31:59 +01:00
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
pigif_bad_send = -2000,
|
|
|
|
pigif_bad_recv = -2001,
|
|
|
|
pigif_bad_getaddrinfo = -2002,
|
|
|
|
pigif_bad_connect = -2003,
|
|
|
|
pigif_bad_socket = -2004,
|
|
|
|
pigif_bad_noib = -2005,
|
|
|
|
pigif_duplicate_callback = -2006,
|
|
|
|
pigif_bad_malloc = -2007,
|
|
|
|
pigif_bad_callback = -2008,
|
|
|
|
pigif_notify_failed = -2009,
|
|
|
|
pigif_callback_not_found = -2010,
|
2014-01-29 00:07:05 +01:00
|
|
|
} pigifError_t;
|
2014-01-12 22:31:59 +01:00
|
|
|
|
|
|
|
|
2014-01-29 00:07:05 +01:00
|
|
|
typedef void (*CBFunc_t) (unsigned gpio, unsigned level, uint32_t tick);
|
2014-01-12 22:31:59 +01:00
|
|
|
|
2014-01-29 00:07:05 +01:00
|
|
|
typedef void (*CBFuncEx_t)
|
|
|
|
(unsigned gpio, unsigned level, uint32_t tick, void * user);
|
2014-01-12 22:31:59 +01:00
|
|
|
|
|
|
|
typedef struct callback_s callback_t;
|
|
|
|
|
|
|
|
#define RISING_EDGE 0
|
|
|
|
#define FALLING_EDGE 1
|
|
|
|
#define EITHER_EDGE 2
|
|
|
|
|
|
|
|
double time_time(void);
|
|
|
|
/* Return the current time in seconds since the Epoch.*/
|
|
|
|
|
|
|
|
void time_sleep(double seconds);
|
|
|
|
/* Delay execution for a given number of seconds */
|
|
|
|
|
|
|
|
const char *pigpio_error(int error);
|
|
|
|
/* Return a string for a pigpio library error. */
|
|
|
|
|
|
|
|
unsigned pigpiod_if_version(void);
|
|
|
|
/* Return the pigpiod_if version. */
|
|
|
|
|
2014-01-21 20:04:59 +01:00
|
|
|
pthread_t *start_thread(gpioThreadFunc_t func, void *arg);
|
2014-01-12 22:31:59 +01:00
|
|
|
/* Starts a new thread of execution with func as the main routine.
|
|
|
|
|
|
|
|
Returns a pointer to pthread_t if OK, otherwise NULL.
|
|
|
|
|
|
|
|
The function is passed the single argument arg.
|
|
|
|
|
|
|
|
The thread can be cancelled by passing the pointer to pthread_t to
|
2014-03-13 16:50:23 +01:00
|
|
|
stop_thread().
|
2014-01-12 22:31:59 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
void stop_thread(pthread_t *pth);
|
|
|
|
/* Cancels the thread pointed at by pth.
|
|
|
|
|
|
|
|
No value is returned.
|
|
|
|
|
2014-03-13 16:50:23 +01:00
|
|
|
The thread to be stopped should have been started with start_thread().
|
2014-01-12 22:31:59 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
int pigpio_start(char *addrStr, char *portStr);
|
|
|
|
/* Connect to the pigpio daemon. Reserving command and
|
|
|
|
notification streams.
|
|
|
|
|
|
|
|
addrStr specifies the host or IP address of the Pi running
|
|
|
|
the pigpio daemon. It may be NULL in which case localhost
|
|
|
|
is used unless overriden by the PIGPIO_ADDR environment
|
|
|
|
variable.
|
|
|
|
|
|
|
|
portStr specifies the port address used by the Pi running
|
|
|
|
the pigpio daemon. It may be NULL in which case "8888"
|
|
|
|
is used unless overriden by the PIGPIO_PORT environment
|
|
|
|
variable.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void pigpio_stop(void);
|
|
|
|
/*
|
|
|
|
Terminates the connection to the pigpio daemon and releases
|
|
|
|
resources used by the library.
|
|
|
|
*/
|
|
|
|
|
2014-01-29 00:07:05 +01:00
|
|
|
int set_mode(unsigned gpio, unsigned mode);
|
2014-01-12 22:31:59 +01:00
|
|
|
/* Set the gpio mode.
|
|
|
|
|
|
|
|
gpio: 0-53.
|
|
|
|
mode: INPUT, OUTPUT, ALT0, ALT1, ALT2, ALT3, ALT4, ALT5.
|
|
|
|
|
|
|
|
Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_MODE,
|
|
|
|
or PI_NOT_PERMITTED.
|
|
|
|
*/
|
|
|
|
|
2014-01-29 00:07:05 +01:00
|
|
|
int get_mode(unsigned gpio);
|
2014-01-12 22:31:59 +01:00
|
|
|
/* Get the gpio mode.
|
|
|
|
|
|
|
|
Returns the gpio mode if OK, otherwise PI_BAD_GPIO.
|
|
|
|
|
|
|
|
gpio: 0-53.
|
|
|
|
*/
|
|
|
|
|
2014-01-29 00:07:05 +01:00
|
|
|
int set_pull_up_down(unsigned gpio, unsigned pud);
|
2014-01-12 22:31:59 +01:00
|
|
|
/* Set or clear the gpio pull-up/down resistor.
|
|
|
|
|
|
|
|
Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_PUD,
|
|
|
|
or PI_NOT_PERMITTED.
|
|
|
|
|
|
|
|
gpio: 0-53.
|
|
|
|
pud: PUD_UP, PUD_DOWN, PUD_OFF.
|
|
|
|
*/
|
|
|
|
|
2014-03-13 16:50:23 +01:00
|
|
|
int gpio_read(unsigned gpio);
|
2014-01-12 22:31:59 +01:00
|
|
|
/* Read the gpio level.
|
|
|
|
|
|
|
|
Returns the gpio level if OK, otherwise PI_BAD_GPIO.
|
|
|
|
|
|
|
|
gpio:0-53.
|
|
|
|
*/
|
|
|
|
|
2014-03-13 16:50:23 +01:00
|
|
|
int gpio_write(unsigned gpio, unsigned level);
|
2014-01-12 22:31:59 +01:00
|
|
|
/*
|
|
|
|
Write the gpio level.
|
|
|
|
|
|
|
|
Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_LEVEL,
|
|
|
|
or PI_NOT_PERMITTED.
|
|
|
|
|
|
|
|
gpio: 0-53.
|
|
|
|
level: 0, 1.
|
|
|
|
|
|
|
|
Notes
|
|
|
|
|
|
|
|
If PWM or servo pulses are active on the gpio they are switched off.
|
|
|
|
*/
|
|
|
|
|
2014-01-29 00:07:05 +01:00
|
|
|
int set_PWM_dutycycle(unsigned user_gpio, unsigned dutycycle);
|
2014-01-12 22:31:59 +01:00
|
|
|
/* Start (non-zero dutycycle) or stop (0) PWM pulses on the gpio.
|
|
|
|
|
|
|
|
Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYCYCLE,
|
|
|
|
or PI_NOT_PERMITTED.
|
|
|
|
|
|
|
|
user_gpio: 0-31.
|
|
|
|
dutycycle: 0-range (range defaults to 255).
|
|
|
|
|
|
|
|
Notes
|
|
|
|
|
|
|
|
The set_PWM_range() function can change the default range of 255.
|
|
|
|
*/
|
|
|
|
|
2014-01-29 00:07:05 +01:00
|
|
|
int set_PWM_range(unsigned user_gpio, unsigned range_);
|
2014-01-12 22:31:59 +01:00
|
|
|
/* Set the range of PWM values to be used on the gpio.
|
|
|
|
|
|
|
|
Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYRANGE,
|
|
|
|
or PI_NOT_PERMITTED.
|
|
|
|
|
|
|
|
user_gpio: 0-31.
|
|
|
|
range_: 25-40000.
|
|
|
|
|
|
|
|
Notes
|
|
|
|
|
|
|
|
If PWM is currently active on the gpio its dutycycle will be
|
|
|
|
scaled to reflect the new range.
|
|
|
|
|
|
|
|
The real range, the number of steps between fully off and fully on
|
|
|
|
for each of the 18 available gpio frequencies is
|
|
|
|
|
|
|
|
25(#1), 50(#2), 100(#3), 125(#4), 200(#5), 250(#6), 400(#7),
|
|
|
|
500(#8), 625(#9), 800(#10), 1000(#11), 1250(#12), 2000(#13),
|
|
|
|
2500(#14), 4000(#15), 5000(#16), 10000(#17), 20000(#18)
|
|
|
|
|
|
|
|
The real value set by set_PWM_range is
|
|
|
|
(dutycycle * real range) / range.
|
|
|
|
*/
|
|
|
|
|
2014-01-29 00:07:05 +01:00
|
|
|
int get_PWM_range(unsigned user_gpio);
|
2014-01-12 22:31:59 +01:00
|
|
|
/* Get the range of PWM values being used on the gpio.
|
|
|
|
|
|
|
|
Returns the dutycycle range used for the gpio if OK,
|
|
|
|
otherwise PI_BAD_USER_GPIO.
|
|
|
|
|
|
|
|
user_gpio: 0-31.
|
|
|
|
*/
|
|
|
|
|
2014-01-29 00:07:05 +01:00
|
|
|
int get_PWM_real_range(unsigned user_gpio);
|
2014-01-12 22:31:59 +01:00
|
|
|
/* Get the real underlying range of PWM values being used on the gpio.
|
|
|
|
|
|
|
|
Returns the real range used for the gpio if OK,
|
|
|
|
otherwise PI_BAD_USER_GPIO.
|
|
|
|
|
|
|
|
user_gpio: 0-31.
|
|
|
|
*/
|
|
|
|
|
2014-01-29 00:07:05 +01:00
|
|
|
int set_PWM_frequency(unsigned user_gpio, unsigned frequency);
|
2014-01-12 22:31:59 +01:00
|
|
|
/*
|
|
|
|
Set the frequency (in Hz) of the PWM to be used on the gpio.
|
|
|
|
|
|
|
|
Returns the numerically closest frequency if OK, otherwise
|
|
|
|
PI_BAD_USER_GPIO or PI_NOT_PERMITTED.
|
|
|
|
|
|
|
|
user_gpio: 0-31.
|
|
|
|
frequency: 0- (Hz).
|
|
|
|
|
|
|
|
The selectable frequencies depend upon the sample rate which
|
|
|
|
may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The
|
|
|
|
sample rate is set when the C pigpio library is started.
|
|
|
|
|
|
|
|
Each gpio can be independently set to one of 18 different
|
|
|
|
PWM frequencies.
|
|
|
|
|
|
|
|
If PWM is currently active on the gpio it will be switched
|
|
|
|
off and then back on at the new frequency.
|
|
|
|
|
|
|
|
1us 40000, 20000, 10000, 8000, 5000, 4000, 2500, 2000, 1600,
|
|
|
|
1250, 1000, 800, 500, 400, 250, 200, 100, 50
|
|
|
|
|
|
|
|
2us 20000, 10000, 5000, 4000, 2500, 2000, 1250, 1000, 800,
|
|
|
|
625, 500, 400, 250, 200, 125, 100, 50, 25
|
|
|
|
|
|
|
|
4us 10000, 5000, 2500, 2000, 1250, 1000, 625, 500, 400,
|
|
|
|
313, 250, 200, 125, 100, 63, 50, 25, 13
|
|
|
|
|
|
|
|
5us 8000, 4000, 2000, 1600, 1000, 800, 500, 400, 320,
|
|
|
|
250, 200, 160, 100, 80, 50, 40, 20, 10
|
|
|
|
|
|
|
|
8us 5000, 2500, 1250, 1000, 625, 500, 313, 250, 200,
|
|
|
|
156, 125, 100, 63, 50, 31, 25, 13, 6
|
|
|
|
|
|
|
|
10us 4000, 2000, 1000, 800, 500, 400, 250, 200, 160,
|
|
|
|
125, 100, 80, 50, 40, 25, 20, 10, 5
|
|
|
|
*/
|
|
|
|
|
2014-01-29 00:07:05 +01:00
|
|
|
int get_PWM_frequency(unsigned user_gpio);
|
2014-01-12 22:31:59 +01:00
|
|
|
/*
|
|
|
|
Get the frequency of PWM being used on the gpio.
|
|
|
|
|
|
|
|
Returns the frequency (in hertz) used for the gpio if OK,
|
|
|
|
otherwise PI_BAD_USER_GPIO.
|
|
|
|
|
|
|
|
user_gpio: 0-31.
|
|
|
|
*/
|
|
|
|
|
2014-01-29 00:07:05 +01:00
|
|
|
int set_servo_pulsewidth(unsigned user_gpio, unsigned pulsewidth);
|
2014-01-12 22:31:59 +01:00
|
|
|
/*
|
|
|
|
Start (500-2500) or stop (0) servo pulses on the gpio.
|
|
|
|
|
|
|
|
Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_PULSEWIDTH or
|
|
|
|
PI_NOT_PERMITTED.
|
|
|
|
|
|
|
|
user_gpio: 0-31.
|
|
|
|
pulsewidth: 0 (off), 500 (most anti-clockwise) - 2500 (most clockwise).
|
|
|
|
|
|
|
|
The selected pulsewidth will continue to be transmitted until
|
|
|
|
changed by a subsequent call to set_servo_pulsewidth().
|
|
|
|
|
|
|
|
The pulsewidths supported by servos varies and should probably be
|
|
|
|
determined by experiment. A value of 1500 should always be safe and
|
|
|
|
represents the mid-point of rotation.
|
|
|
|
|
|
|
|
You can DAMAGE a servo if you command it to move beyond its limits.
|
|
|
|
|
|
|
|
OTHER UPDATE RATES:
|
|
|
|
|
|
|
|
This function updates servos at 50Hz. If you wish to use a different
|
|
|
|
update frequency you will have to use the PWM functions.
|
|
|
|
|
|
|
|
Update Rate (Hz) 50 100 200 400 500
|
|
|
|
1E6/Hz 20000 10000 5000 2500 2000
|
|
|
|
|
|
|
|
Firstly set the desired PWM frequency using set_PWM_frequency().
|
|
|
|
|
|
|
|
Then set the PWM range using set_PWM_range() to 1E6/Hz.
|
|
|
|
Doing this allows you to use units of microseconds when setting
|
|
|
|
the servo pulse width.
|
|
|
|
|
|
|
|
E.g. If you want to update a servo connected to gpio 25 at 400Hz
|
|
|
|
|
|
|
|
set_PWM_frequency(25, 400);
|
|
|
|
set_PWM_range(25, 2500);
|
|
|
|
|
|
|
|
Thereafter use the set_PWM_dutycycle() function to move the servo,
|
|
|
|
e.g. set_PWM_dutycycle(25, 1500) will set a 1500 us pulse.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int notify_open(void);
|
|
|
|
/*
|
|
|
|
Get a free notification handle.
|
|
|
|
|
|
|
|
Returns a handle greater than or equal to zero if OK,
|
|
|
|
otherwise PI_NO_HANDLE.
|
|
|
|
|
|
|
|
A notification is a method for being notified of gpio state
|
|
|
|
changes via a pipe.
|
|
|
|
|
|
|
|
Pipes are only accessible from the local machine so this function
|
|
|
|
serves no purpose if you are using the library from a remote machine.
|
|
|
|
The in-built (socket) notifications provided by callback()
|
|
|
|
should be used instead.
|
|
|
|
|
|
|
|
Notifications for handle x will be available at the pipe
|
|
|
|
named /dev/pigpiox (where x is the handle number).
|
|
|
|
E.g. if the function returns 15 then the notifications must be
|
|
|
|
read from /dev/pigpio15.
|
|
|
|
*/
|
|
|
|
|
2014-01-29 00:07:05 +01:00
|
|
|
int notify_begin(unsigned handle, uint32_t bits);
|
2014-01-12 22:31:59 +01:00
|
|
|
/*
|
|
|
|
Start notifications on a previously opened handle.
|
|
|
|
|
|
|
|
Returns 0 if OK, otherwise PI_BAD_HANDLE.
|
|
|
|
|
|
|
|
handle: 0-31 (as returned by notify_open())
|
|
|
|
bits: a mask indicating the gpios to be notified.
|
|
|
|
|
|
|
|
The notification sends state changes for each gpio whose
|
|
|
|
corresponding bit in bits is set.
|
|
|
|
|
|
|
|
Notes
|
|
|
|
|
|
|
|
Each notification occupies 12 bytes in the fifo as follows:
|
|
|
|
|
|
|
|
H (16 bit) seqno
|
|
|
|
H (16 bit) flags
|
|
|
|
I (32 bit) tick
|
|
|
|
I (32 bit) level
|
|
|
|
*/
|
|
|
|
|
2014-01-29 00:07:05 +01:00
|
|
|
int notify_pause(unsigned handle);
|
2014-01-12 22:31:59 +01:00
|
|
|
/*
|
|
|
|
Pause notifications on a previously opened handle.
|
|
|
|
|
|
|
|
Returns 0 if OK, otherwise PI_BAD_HANDLE.
|
|
|
|
|
|
|
|
handle: 0-31 (as returned by notify_open())
|
|
|
|
|
|
|
|
Notifications for the handle are suspended until
|
|
|
|
notify_begin() is called again.
|
|
|
|
*/
|
|
|
|
|
2014-01-29 00:07:05 +01:00
|
|
|
int notify_close(unsigned handle);
|
2014-01-12 22:31:59 +01:00
|
|
|
/*
|
|
|
|
Stop notifications on a previously opened handle and
|
|
|
|
release the handle for reuse.
|
|
|
|
|
|
|
|
Returns 0 if OK, otherwise PI_BAD_HANDLE.
|
|
|
|
|
|
|
|
handle: 0-31 (as returned by notify_open())
|
|
|
|
*/
|
|
|
|
|
2014-01-29 00:07:05 +01:00
|
|
|
int set_watchdog(unsigned user_gpio, unsigned timeout);
|
2014-01-12 22:31:59 +01:00
|
|
|
/*
|
|
|
|
Sets a watchdog for a gpio.
|
|
|
|
|
|
|
|
Returns 0 if OK, otherwise PI_BAD_USER_GPIO
|
|
|
|
or PI_BAD_WDOG_TIMEOUT.
|
|
|
|
|
|
|
|
user_gpio: 0-31.
|
|
|
|
timeout: 0-60000.
|
|
|
|
|
|
|
|
The watchdog is nominally in milliseconds.
|
|
|
|
|
|
|
|
Only one watchdog may be registered per gpio.
|
|
|
|
|
|
|
|
The watchdog may be cancelled by setting timeout to 0.
|
|
|
|
|
|
|
|
If no level change has been detected for the gpio for timeout
|
|
|
|
milliseconds any notification for the gpio has a report written
|
|
|
|
to the fifo with the flags set to indicate a watchdog timeout.
|
|
|
|
|
|
|
|
The callback() and callback_ex functions interpret the flags and will
|
|
|
|
call registered callbacks for the gpio with level TIMEOUT.
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint32_t read_bank_1(void);
|
|
|
|
/*
|
|
|
|
Read the levels of the bank 1 gpios (gpios 0-31).
|
|
|
|
|
|
|
|
The returned 32 bit integer has a bit set if the corresponding
|
|
|
|
gpio is logic 1. Gpio n has bit value (1<<n).
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint32_t read_bank_2(void);
|
|
|
|
/*
|
|
|
|
Read the levels of the bank 2 gpios (gpios 32-53).
|
|
|
|
|
|
|
|
The returned 32 bit integer has a bit set if the corresponding
|
|
|
|
gpio is logic 1. Gpio n has bit value (1<<(n-32)).
|
|
|
|
*/
|
|
|
|
|
|
|
|
int clear_bank_1(uint32_t levels);
|
|
|
|
/*
|
|
|
|
Clears gpios 0-31 if the corresponding bit in levels is set.
|
|
|
|
|
|
|
|
Returns 0 if OK, otherwise PI_SOME_PERMITTED.
|
|
|
|
|
|
|
|
A status of PI_SOME_PERMITTED indicates that the user is not
|
|
|
|
allowed to write to one or more of the gpios.
|
|
|
|
|
|
|
|
levels: a bit mask with 1 set if the corresponding gpio is
|
|
|
|
to be cleared.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int clear_bank_2(uint32_t levels);
|
|
|
|
/*
|
|
|
|
Clears gpios 32-53 if the corresponding bit (0-21) in levels is set.
|
|
|
|
|
|
|
|
Returns 0 if OK, otherwise PI_SOME_PERMITTED.
|
|
|
|
|
|
|
|
A status of PI_SOME_PERMITTED indicates that the user is not
|
|
|
|
allowed to write to one or more of the gpios.
|
|
|
|
|
|
|
|
levels: a bit mask with 1 set if the corresponding gpio is
|
|
|
|
to be cleared.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int set_bank_1(uint32_t levels);
|
|
|
|
/*
|
|
|
|
Sets gpios 0-31 if the corresponding bit in levels is set.
|
|
|
|
|
|
|
|
Returns 0 if OK, otherwise PI_SOME_PERMITTED.
|
|
|
|
|
|
|
|
A status of PI_SOME_PERMITTED indicates that the user is not
|
|
|
|
allowed to write to one or more of the gpios.
|
|
|
|
|
|
|
|
levels: a bit mask with 1 set if the corresponding gpio is
|
|
|
|
to be set.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int set_bank_2(uint32_t levels);
|
|
|
|
/*
|
|
|
|
Sets gpios 32-53 if the corresponding bit (0-21) in levels is set.
|
|
|
|
|
|
|
|
Returns 0 if OK, otherwise PI_SOME_PERMITTED.
|
|
|
|
|
|
|
|
A status of PI_SOME_PERMITTED indicates that the user is not
|
|
|
|
allowed to write to one or more of the gpios.
|
|
|
|
|
|
|
|
levels: a bit mask with 1 set if the corresponding gpio is
|
|
|
|
to be set.
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint32_t get_current_tick(void);
|
|
|
|
/*
|
|
|
|
|
|
|
|
Gets the current system tick.
|
|
|
|
|
|
|
|
Tick is the number of microseconds since system boot.
|
|
|
|
|
|
|
|
As tick is an unsigned 32 bit quantity it wraps around after
|
|
|
|
2**32 microseconds, which is approximately 1 hour 12 minutes.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint32_t get_hardware_revision(void);
|
|
|
|
/*
|
|
|
|
Get the Pi's hardware revision number.
|
|
|
|
|
|
|
|
It is unfortunate that Pi boards have been named Revision.1 and
|
|
|
|
Revision.2. That use of the word revision is distinct from the
|
|
|
|
Pi's hardware revision number.'
|
|
|
|
|
|
|
|
The hardware revision is the last 4 characters on the Revision line
|
|
|
|
of /proc/cpuinfo.
|
|
|
|
|
|
|
|
The revision number can be used to determine the assignment of gpios
|
|
|
|
to pins.
|
|
|
|
|
|
|
|
There are at least two types of board.
|
|
|
|
|
|
|
|
Type 1 has gpio 0 on P1-3, gpio 1 on P1-5, and gpio 21 on P1-13.
|
|
|
|
Type 2 has gpio 2 on P1-3, gpio 3 on P1-5, gpio 27 on P1-13, and
|
|
|
|
gpios 28-31 on P5.
|
|
|
|
|
|
|
|
Type 1 boards have hardware revision numbers of 2 and 3.
|
|
|
|
|
|
|
|
Type 2 boards have hardware revision numbers of 4, 5, 6, and 15.
|
|
|
|
|
|
|
|
If the hardware revision can not be found or is not a valid
|
|
|
|
hexadecimal number the function returns 0.
|
|
|
|
*/
|
|
|
|
|
2014-03-13 16:50:23 +01:00
|
|
|
uint32_t get_pigpio_version(void);
|
|
|
|
/*
|
|
|
|
Returns the pigpio version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2014-01-21 20:04:59 +01:00
|
|
|
int wave_clear(void);
|
2014-04-19 13:19:29 +02:00
|
|
|
/* This function clears all waveforms and any data added by calls to the
|
|
|
|
wave_add_* functions.
|
2014-01-21 20:04:59 +01:00
|
|
|
|
|
|
|
Returns 0 if OK.
|
2014-04-19 13:19:29 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
int wave_add_new(void);
|
|
|
|
/* This function starts a new empty waveform. You wouldn't normally need
|
|
|
|
to call this function as it is automatically called after a waveform is
|
|
|
|
created with the wave_create function.
|
|
|
|
|
|
|
|
Returns 0 if OK.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int wave_add_generic(unsigned numPulses, gpioPulse_t *pulses);
|
|
|
|
/* This function adds a number of pulses to the current waveform.
|
|
|
|
|
|
|
|
Returns the new total number of pulses in the current waveform if OK,
|
|
|
|
otherwise PI_TOO_MANY_PULSES.
|
|
|
|
|
|
|
|
The pulses are interleaved in time order within the existing waveform
|
|
|
|
(if any).
|
2014-01-21 20:04:59 +01:00
|
|
|
|
2014-04-19 13:19:29 +02:00
|
|
|
Merging allows the waveform to be built in parts, that is the settings
|
|
|
|
for gpio#1 can be added, and then gpio#2 etc.
|
|
|
|
|
|
|
|
If the added waveform is intended to start after or within the existing
|
|
|
|
waveform then the first pulse should consist solely of a delay.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int wave_add_serial
|
|
|
|
(unsigned gpio, unsigned baud, unsigned offset, unsigned numChar, char *str);
|
|
|
|
/* This function adds a waveform representing serial data to the
|
|
|
|
existing waveform (if any). The serial data starts offset microseconds
|
|
|
|
from the start of the waveform.
|
|
|
|
|
|
|
|
Returns the new total number of pulses in the current waveform if OK,
|
|
|
|
otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_TOO_MANY_CHARS, or
|
|
|
|
PI_TOO_MANY_PULSES.
|
|
|
|
|
|
|
|
NOTES:
|
|
|
|
|
|
|
|
The serial data is formatted as one start bit, eight data bits, and one
|
|
|
|
stop bit.
|
|
|
|
|
|
|
|
It is legal to add serial data streams with different baud rates to
|
|
|
|
the same waveform.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int wave_create(void);
|
|
|
|
/* This function creates a waveform from the data provided by the prior
|
|
|
|
calls to the wave_add_* functions. Upon success a positive wave id
|
|
|
|
is returned.
|
|
|
|
|
|
|
|
The data provided by the wave_add_* functions is consumed by this
|
|
|
|
function.
|
|
|
|
|
|
|
|
As many waveforms may be created as there is space available. The
|
|
|
|
wave id is passed to wave_send_* to specify the waveform to transmit.
|
|
|
|
|
|
|
|
Normal usage would be
|
|
|
|
|
|
|
|
Step 1. wave_clear to clear all waveforms and added data.
|
|
|
|
|
|
|
|
Step 2. wave_add_* calls to supply the waveform data.
|
|
|
|
|
|
|
|
Step 3. wave_create to create the waveform and get a unique id
|
|
|
|
|
|
|
|
Repeat steps 2 and 3 as needed.
|
|
|
|
|
|
|
|
Step 4. wave_send_* with the id of the waveform to transmit.
|
|
|
|
|
|
|
|
A waveform comprises one or more pulses. Each pulse consists of a
|
2014-01-21 20:04:59 +01:00
|
|
|
gpioPulse_t structure.
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
uint32_t gpioOn;
|
|
|
|
uint32_t gpioOff;
|
|
|
|
uint32_t usDelay;
|
|
|
|
} gpioPulse_t;
|
|
|
|
|
|
|
|
The fields specify
|
|
|
|
|
|
|
|
1) the gpios to be switched on at the start of the pulse.
|
|
|
|
2) the gpios to be switched off at the start of the pulse.
|
|
|
|
3) the delay in microseconds before the next pulse.
|
|
|
|
|
|
|
|
Any or all the fields can be zero. It doesn't make any sense to
|
|
|
|
set all the fields to zero (the pulse will be ignored).
|
|
|
|
|
|
|
|
When a waveform is started each pulse is executed in order with the
|
|
|
|
specified delay between the pulse and the next.
|
|
|
|
|
2014-04-19 13:19:29 +02:00
|
|
|
Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM,
|
|
|
|
PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL.
|
2014-01-21 20:04:59 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2014-04-19 13:19:29 +02:00
|
|
|
int wave_delete(unsigned wave_id);
|
|
|
|
/* This function deletes all created waveforms with ids greater than or
|
|
|
|
equal to wave_id.
|
2014-01-21 20:04:59 +01:00
|
|
|
|
2014-04-19 13:19:29 +02:00
|
|
|
Wave ids are allocated in order, 0, 1, 2, etc.
|
|
|
|
|
|
|
|
Returns 0 if OK, otherwise PI_BAD_WAVE_ID.
|
2014-01-21 20:04:59 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
int wave_tx_start(void);
|
2014-04-19 13:19:29 +02:00
|
|
|
/* This function is deprecated and should no longer be used. Use
|
|
|
|
wave_create/wave_send_* instead.
|
2014-01-21 20:04:59 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
int wave_tx_repeat(void);
|
2014-04-19 13:19:29 +02:00
|
|
|
/* This function is deprecated and should no longer be used. Use
|
|
|
|
wave_create/wave_send_* instead.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int wave_send_once(unsigned wave_id);
|
|
|
|
/* This function transmits the waveform with id wave_id. The waveform
|
|
|
|
is sent once.
|
2014-01-21 20:04:59 +01:00
|
|
|
|
|
|
|
Returns the number of DMA control blocks in the waveform if OK,
|
2014-04-19 13:19:29 +02:00
|
|
|
otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE.
|
2014-01-21 20:04:59 +01:00
|
|
|
*/
|
|
|
|
|
2014-04-19 13:19:29 +02:00
|
|
|
int wave_send_repeat(unsigned wave_id);
|
|
|
|
/* This function transmits the waveform with id wave_id. The waveform
|
|
|
|
cycles until cancelled (either by the sending of a new waveform or
|
|
|
|
by wave_tx_stop).
|
2014-01-21 20:04:59 +01:00
|
|
|
|
2014-04-19 13:19:29 +02:00
|
|
|
Returns the number of DMA control blocks in the waveform if OK,
|
|
|
|
otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE.
|
|
|
|
*/
|
2014-01-21 20:04:59 +01:00
|
|
|
|
|
|
|
|
2014-04-19 13:19:29 +02:00
|
|
|
int wave_tx_busy(void);
|
|
|
|
/* This function checks to see if a waveform is currently being
|
|
|
|
transmitted.
|
2014-01-21 20:04:59 +01:00
|
|
|
|
2014-04-19 13:19:29 +02:00
|
|
|
Returns 1 if a waveform is currently being transmitted, otherwise 0.
|
2014-01-21 20:04:59 +01:00
|
|
|
*/
|
|
|
|
|
2014-04-19 13:19:29 +02:00
|
|
|
int wave_tx_stop(void);
|
|
|
|
/* This function stops the transmission of the current waveform.
|
2014-01-21 20:04:59 +01:00
|
|
|
|
2014-04-19 13:19:29 +02:00
|
|
|
Returns 0 if OK.
|
2014-01-21 20:04:59 +01:00
|
|
|
|
2014-04-19 13:19:29 +02:00
|
|
|
This function is intended to stop a waveform started with the repeat mode.
|
2014-01-21 20:04:59 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
int wave_get_micros(void);
|
|
|
|
/* This function returns the length in microseconds of the current
|
|
|
|
waveform.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int wave_get_high_micros(void);
|
|
|
|
/* This function returns the length in microseconds of the longest waveform
|
|
|
|
created since the pigpio daemon was started..
|
|
|
|
*/
|
|
|
|
|
|
|
|
int wave_get_max_micros(void);
|
|
|
|
/* This function returns the maximum possible size of a waveform in
|
|
|
|
microseconds.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int wave_get_pulses(void);
|
|
|
|
/* This function returns the length in pulses of the current waveform.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int wave_get_high_pulses(void);
|
|
|
|
/* This function returns the length in pulses of the longest waveform
|
|
|
|
created since the pigpio daemon was started..
|
|
|
|
*/
|
|
|
|
|
|
|
|
int wave_get_max_pulses(void);
|
|
|
|
/* This function returns the maximum possible size of a waveform in pulses.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int wave_get_cbs(void);
|
|
|
|
/* This function returns the length in DMA control blocks of the current
|
|
|
|
waveform.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int wave_get_high_cbs(void);
|
|
|
|
/* This function returns the length in DMA control blocks of the longest
|
|
|
|
waveform created since the pigpio daemon was started..
|
|
|
|
*/
|
|
|
|
|
|
|
|
int wave_get_max_cbs(void);
|
|
|
|
/* This function returns the maximum possible size of a waveform in DMA
|
|
|
|
control blocks.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int gpio_trigger(unsigned gpio, unsigned pulseLen, unsigned level);
|
|
|
|
/* This function sends a trigger pulse to a gpio. The gpio is set to
|
|
|
|
level for pulseLen microseconds and then reset to not level.
|
|
|
|
|
|
|
|
Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL,
|
|
|
|
PI_BAD_PULSELEN, or PI_NOT_PERMITTED.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int store_script(char *script);
|
|
|
|
/* This function stores a script for later execution.
|
|
|
|
|
|
|
|
The function returns a script id if the script is valid,
|
|
|
|
otherwise PI_BAD_SCRIPT.
|
|
|
|
*/
|
|
|
|
|
2014-03-13 16:50:23 +01:00
|
|
|
int run_script(unsigned script_id, unsigned numPar, uint32_t *param);
|
2014-01-21 20:04:59 +01:00
|
|
|
/* This function runs a stored script.
|
|
|
|
|
2014-03-13 16:50:23 +01:00
|
|
|
The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or
|
|
|
|
PI_TOO_MANY_PARAM
|
|
|
|
|
|
|
|
param is an array of up to 10 parameters which may be referenced in
|
|
|
|
the script as param 0 to param 9..
|
|
|
|
*/
|
|
|
|
|
2014-04-19 13:19:29 +02:00
|
|
|
int script_status(unsigned script_id, uint32_t *param);
|
2014-03-13 16:50:23 +01:00
|
|
|
/* This function returns the run status of a stored script as well
|
|
|
|
as the current values of parameters 0 to 9.
|
|
|
|
|
|
|
|
The function returns greater than or equal to 0 if OK,
|
|
|
|
otherwise PI_BAD_SCRIPT_ID.
|
|
|
|
|
|
|
|
The run status may be
|
|
|
|
|
|
|
|
PI_SCRIPT_HALTED
|
|
|
|
PI_SCRIPT_RUNNING
|
|
|
|
PI_SCRIPT_WAITING
|
|
|
|
PI_SCRIPT_FAILED
|
|
|
|
|
|
|
|
The current value of script parameters 0 to 9 are returned in param.
|
2014-01-21 20:04:59 +01:00
|
|
|
*/
|
|
|
|
|
2014-01-29 00:07:05 +01:00
|
|
|
int stop_script(unsigned script_id);
|
2014-01-21 20:04:59 +01:00
|
|
|
/* This function stops a running script.
|
|
|
|
|
|
|
|
The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID.
|
|
|
|
*/
|
|
|
|
|
2014-01-29 00:07:05 +01:00
|
|
|
int delete_script(unsigned script_id);
|
2014-01-21 20:04:59 +01:00
|
|
|
/* This function deletes a stored script.
|
|
|
|
|
|
|
|
The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID.
|
|
|
|
*/
|
|
|
|
|
2014-06-12 19:31:00 +02:00
|
|
|
int bb_serial_read_open(unsigned user_gpio, unsigned baud);
|
|
|
|
/* This function opens a gpio for bit-banged reading of serial data.
|
2014-01-29 00:07:05 +01:00
|
|
|
|
|
|
|
Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD,
|
|
|
|
or PI_GPIO_IN_USE.
|
|
|
|
|
|
|
|
The serial data is returned in a cyclic buffer and is read using
|
2014-06-12 19:31:00 +02:00
|
|
|
bb_serial_read().
|
2014-01-29 00:07:05 +01:00
|
|
|
|
|
|
|
It is the caller's responsibility to read data from the cyclic buffer
|
|
|
|
in a timely fashion.
|
|
|
|
*/
|
|
|
|
|
2014-06-12 19:31:00 +02:00
|
|
|
int bb_serial_read(unsigned user_gpio, void *buf, size_t bufSize);
|
2014-01-29 00:07:05 +01:00
|
|
|
/* This function copies up to bufSize bytes of data read from the
|
2014-06-12 19:31:00 +02:00
|
|
|
bit-bang serial cyclic buffer to the buffer starting at buf.
|
2014-01-29 00:07:05 +01:00
|
|
|
|
|
|
|
Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO
|
|
|
|
or PI_NOT_SERIAL_GPIO.
|
|
|
|
*/
|
|
|
|
|
2014-06-12 19:31:00 +02:00
|
|
|
int bb_serial_read_close(unsigned user_gpio);
|
|
|
|
/* This function closes a gpio for bit-banged reading of serial data.
|
2014-01-29 00:07:05 +01:00
|
|
|
|
|
|
|
Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO.
|
|
|
|
*/
|
|
|
|
|
2014-06-12 19:31:00 +02:00
|
|
|
int i2c_open(unsigned bus, unsigned addr, unsigned flags);
|
|
|
|
/* This returns a handle for the device at address addr on I2C bus bus.
|
|
|
|
|
|
|
|
No flags are currently defined. This parameter should be set to zero.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int i2c_close(unsigned handle);
|
|
|
|
/* This closes the I2C device associated with the handle.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int i2c_read_device(unsigned handle, char *buf, unsigned count);
|
|
|
|
/* This reads count bytes from the raw device into buf.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int i2c_write_device(unsigned handle, char *buf, unsigned count);
|
|
|
|
/* This writes count bytes from buf to the raw device.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int i2c_write_quick(unsigned handle, unsigned bit);
|
|
|
|
/* This sends a single bit to the device (in the Rd/Wr bit).
|
|
|
|
|
|
|
|
Quick command. smbus 2.0 5.5.1
|
|
|
|
*/
|
|
|
|
|
|
|
|
int i2c_write_byte(unsigned handle, unsigned val);
|
|
|
|
/* This operation is the reverse of i2cReadByte: it sends a single byte
|
|
|
|
to a device.
|
|
|
|
|
|
|
|
Send byte. smbus 2.0 5.5.2
|
|
|
|
*/
|
|
|
|
|
|
|
|
int i2c_read_byte(unsigned handle);
|
|
|
|
/* This reads a single byte from a device, without specifying a device
|
|
|
|
register. Some devices are so simple that this interface is enough;
|
|
|
|
for others, it is a shorthand if you want to read the same register
|
|
|
|
as in the previous SMBus command.
|
|
|
|
|
|
|
|
Receive byte. smbus 2.0 5.5.3
|
|
|
|
*/
|
|
|
|
|
|
|
|
int i2c_write_byte_data(unsigned handle, unsigned reg, unsigned val);
|
|
|
|
/* This writes a single byte to a device, to a designated register.
|
|
|
|
This is the opposite of the i2cReadByte function.
|
|
|
|
|
|
|
|
Write byte. smbus 2.0 5.5.4
|
|
|
|
*/
|
|
|
|
|
|
|
|
int i2c_write_word_data(unsigned handle, unsigned reg, unsigned val);
|
|
|
|
/* This is the opposite of the i2cReadWordData operation. 16 bits
|
|
|
|
of data is written to a device, to the designated register.
|
|
|
|
|
|
|
|
Write word. smbus 2.0 5.5.4
|
|
|
|
*/
|
|
|
|
|
|
|
|
int i2c_read_byte_data(unsigned handle, unsigned reg);
|
|
|
|
/* This reads a single byte from a device, from a designated register.
|
|
|
|
|
|
|
|
Read byte. smbus 2.0 5.5.5
|
|
|
|
*/
|
|
|
|
|
|
|
|
int i2c_read_word_data(unsigned handle, unsigned reg);
|
|
|
|
/* This operation is very like i2cReadByte; again, data is read
|
|
|
|
from a device, from a designated register. But this time, the data
|
|
|
|
is a complete word (16 bits).
|
|
|
|
|
|
|
|
Read word. smbus 2.0 5.5.5
|
|
|
|
*/
|
|
|
|
|
|
|
|
int i2c_process_call(unsigned handle, unsigned reg, unsigned val);
|
|
|
|
/* This command selects a device register, sends 16 bits of data to it,
|
|
|
|
and reads 16 bits of data in return.
|
|
|
|
|
|
|
|
Process call. smbus 2.0 5.5.6
|
|
|
|
*/
|
|
|
|
|
|
|
|
int i2c_write_block_data(
|
|
|
|
unsigned handle, unsigned reg, char *buf, unsigned count);
|
|
|
|
/* The opposite of the i2cReadBlockData command, this writes up to
|
|
|
|
32 bytes to a device, to a designated register. The amount of data
|
|
|
|
is specified in the count byte.
|
|
|
|
|
|
|
|
Block write. smbus 2.0 5.5.7
|
|
|
|
*/
|
|
|
|
|
|
|
|
int i2c_read_block_data(unsigned handle, unsigned reg, char *buf);
|
|
|
|
/* This command reads a block of up to 32 bytes from a device, from a
|
|
|
|
designated register. The amount of returned data is set by the device.
|
|
|
|
|
|
|
|
Block read. smbus 2.0 5.5.7
|
|
|
|
*/
|
|
|
|
|
|
|
|
int i2c_block_process_call(
|
|
|
|
unsigned handle, unsigned reg, char *buf, unsigned count);
|
|
|
|
/* This command selects a device register, sends count bytes of data
|
|
|
|
to it, and reads a device specified number of bytes of data in return.
|
|
|
|
|
|
|
|
The smbus 2.0 documentation states that a minimum of 1 byte may be
|
|
|
|
sent and a minimum of 1 byte may be received. The total number of
|
|
|
|
bytes sent/received must be 32 or less.
|
|
|
|
|
|
|
|
Block write-block read. smbus 2.0 5.5.8
|
|
|
|
*/
|
|
|
|
|
|
|
|
int i2c_read_i2c_block_data(
|
|
|
|
unsigned handle, unsigned reg, char *buf, unsigned count);
|
|
|
|
/* This command reads a block of bytes from a device, from a
|
|
|
|
designated register. The count may be 1-32.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
int i2c_write_i2c_block_data(
|
|
|
|
unsigned handle, unsigned reg, char *buf, unsigned count);
|
|
|
|
/* The opposite of the i2cReadI2CBlockData command, this writes bytes to
|
|
|
|
a device, to a designated register.. Note that command lengths of 0, 2,
|
|
|
|
or more bytes are supported as they are indistinguishable from data.
|
|
|
|
Count may be 1-32.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int spi_open(unsigned channel, unsigned speed, unsigned flags);
|
|
|
|
/* This function returns a handle for the SPI device on channel.
|
|
|
|
Data will be transferred at speed bits per second.
|
|
|
|
|
|
|
|
The bottom two bits of flags define the SPI mode as follows.
|
|
|
|
bit bit
|
|
|
|
1 0
|
|
|
|
Mode POL PHA
|
|
|
|
0 0 0
|
|
|
|
1 0 1
|
|
|
|
2 1 0
|
|
|
|
3 1 1
|
|
|
|
|
|
|
|
The other bits in flags should be set to zero.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int spi_close(unsigned handle);
|
|
|
|
/* This functions closes the SPI device identified by the handle.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int spi_read(unsigned handle, char *buf, unsigned count);
|
|
|
|
/* This function reads count bytes of data from the SPI
|
|
|
|
device associated with the handle.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int spi_write(unsigned handle, char *buf, unsigned count);
|
|
|
|
/* This function writes count bytes of data from buf to the SPI
|
|
|
|
device associated with the handle.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int spi_xfer(unsigned handle, char *txBuf, char *rxBuf, unsigned count);
|
|
|
|
/* This function writes count bytes of data from txBuf to the SPI
|
|
|
|
device associated with the handle.
|
|
|
|
|
|
|
|
The data read from the device is written to rxBuf.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int serial_open(char *dev, unsigned baud, unsigned flags);
|
|
|
|
/* This function open the serial device named dev at baud bits per second.
|
|
|
|
|
|
|
|
No flags are currently defined. This parameter should be set to zero.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int serial_close(unsigned handle);
|
|
|
|
/* This function closes the serial device associated with handle.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int serial_write_byte(unsigned handle, unsigned val);
|
|
|
|
/* This function writes val to the serial port associated with handle.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int serial_read_byte(unsigned handle);
|
|
|
|
/* This function reads a byte from the serial port associated with handle.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int serial_write(unsigned handle, char *buf, unsigned count);
|
|
|
|
/* This function writes count bytes from buf to the the serial port
|
|
|
|
associated with handle.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int serial_read(unsigned handle, char *buf, unsigned count);
|
|
|
|
/* This function reads count bytes from the the serial port
|
|
|
|
associated with handle and writes them to buf.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int serial_data_available(unsigned handle);
|
|
|
|
/* Returns the number of bytes available to be read from the
|
|
|
|
device associated with handle.
|
|
|
|
*/
|
|
|
|
|
2014-01-29 00:07:05 +01:00
|
|
|
int callback(unsigned gpio, unsigned edge, CBFunc_t f);
|
2014-01-12 22:31:59 +01:00
|
|
|
/*
|
2014-01-21 20:04:59 +01:00
|
|
|
This function initialises a new callback.
|
|
|
|
|
|
|
|
The function returns a callback id if OK, otherwise pigif_bad_malloc,
|
|
|
|
pigif_duplicate_callback, or pigif_bad_callback.
|
|
|
|
|
|
|
|
The callback is called with the gpio, edge, and tick, whenever the
|
|
|
|
gpio has the identified edge.
|
2014-01-12 22:31:59 +01:00
|
|
|
*/
|
|
|
|
|
2014-01-29 00:07:05 +01:00
|
|
|
int callback_ex(unsigned gpio, unsigned edge, CBFuncEx_t f, void *user);
|
2014-01-12 22:31:59 +01:00
|
|
|
/*
|
2014-01-21 20:04:59 +01:00
|
|
|
This function initialises a new callback.
|
|
|
|
|
|
|
|
The function returns a callback id if OK, otherwise pigif_bad_malloc,
|
|
|
|
pigif_duplicate_callback, or pigif_bad_callback.
|
|
|
|
|
|
|
|
The callback is called with the gpio, edge, tick, and user, whenever
|
|
|
|
the gpio has the identified edge.
|
2014-01-12 22:31:59 +01:00
|
|
|
*/
|
|
|
|
|
2014-01-29 00:07:05 +01:00
|
|
|
int callback_cancel(unsigned id);
|
2014-01-12 22:31:59 +01:00
|
|
|
/*
|
2014-01-21 20:04:59 +01:00
|
|
|
This function cancels a callback identified by its id.
|
|
|
|
|
|
|
|
The function returns 0 if OK, otherwise pigif_callback_not_found.
|
2014-01-12 22:31:59 +01:00
|
|
|
*/
|
|
|
|
|
2014-01-29 00:07:05 +01:00
|
|
|
int wait_for_edge(unsigned gpio, unsigned edge, double timeout);
|
2014-01-12 22:31:59 +01:00
|
|
|
/*
|
2014-01-21 20:04:59 +01:00
|
|
|
This function waits for edge on the gpio for up to timeout
|
|
|
|
seconds.
|
|
|
|
|
|
|
|
The function returns 1 if the edge occurred, otherwise 0.
|
|
|
|
|
|
|
|
The function returns when the edge occurs or after the timeout.
|
2014-01-12 22:31:59 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|