Copyright | © Patrick Pelletier, 2017 |
---|---|
License | BSD3 |
Maintainer | code@funwithsoftware.org |
Stability | experimental |
Portability | Raspberry Pi |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
This is a Haskell binding to the wiringPi library.
The functions here correspond directly to the functions in the C library.
To use this library, you must either run as root, or set the WIRINGPI_GPIOMEM
environment variable. However, if you set WIRINGPI_GPIOMEM
, then
PWM does not work,
so to use PWM you must be root.
- type Pin = CInt
- data Value
- data Mode
- = INPUT
- | OUTPUT
- | PWM_OUTPUT
- | GPIO_CLOCK
- data Pud
- data PwmMode
- type PwmValue = Word16
- wiringPiSetup :: IO ()
- wiringPiSetupGpio :: IO ()
- wiringPiSetupPhys :: IO ()
- wiringPiSetupSys :: IO ()
- pinMode :: Pin -> Mode -> IO ()
- pullUpDnControl :: Pin -> Pud -> IO ()
- digitalRead :: Pin -> IO Value
- digitalWrite :: Pin -> Value -> IO ()
- pwmWrite :: Pin -> PwmValue -> IO ()
- digitalWriteByte :: Word8 -> IO ()
- pwmSetMode :: PwmMode -> IO ()
- pwmSetRange :: PwmValue -> IO ()
- pwmSetClock :: PwmValue -> IO ()
- piBoardRev :: IO Int
- wpiPinToGpio :: Pin -> IO Pin
- physPinToGpio :: Pin -> IO Pin
Types
Represents a pin number. The meaning of the pin number depends on which setup function was called.
Digital logic level.
Pin mode, used with pinMode
.
INPUT | digital input |
OUTPUT | digital output |
PWM_OUTPUT | pulse-width modulation; only supported on wiringPi pin 1 |
GPIO_CLOCK | clock output; only supported on wiringPi pin 7 |
Use with pullUpDnControl
to enable internal pull-up or pull-down
resistor.
Argument to pwmSetMode
to set "balanced" mode or "mark-space" mode.
PWM_MODE_BAL | balanced mode |
PWM_MODE_MS | mark-space mode |
Value used with pwmWrite
. Typically ranges from 0-1024, but the
range can be increased up to 4096 by calling pwmSetRange
.
Setup functions
See WiringPi Setup functions.
You must call one of these functions, only once, before calling any
other wiringPi functions. The pin numbering scheme depends on which
setup function you call. On error, the program will be terminated,
unless the environment variable WIRINGPI_CODES
is set, in which
case an exception will be thrown.
wiringPiSetup :: IO () Source
wiringPiSetupGpio :: IO () Source
Use Broadcom chip's GPIO numbers. These are the numbers on the Adafruit cobbler.
wiringPiSetupPhys :: IO () Source
Use physical pin numbers on the P1 connector.
wiringPiSetupSys :: IO () Source
Use Broadcom chip's GPIO numbers. Accesses the GPIO via
/sys/class/GPIO
. A bunch of functionality is not available
in this mode.
Core functions
pullUpDnControl :: Pin -> Pud -> IO () Source
digitalRead :: Pin -> IO Value Source
digitalWrite :: Pin -> Value -> IO () Source
pwmWrite :: Pin -> PwmValue -> IO () Source
Default range is 0-1024, but it can be changed with pwmSetRange
.
Additional functions
digitalWriteByte :: Word8 -> IO () Source
Write 8 bits to the 8 pins that have wiringPi pin numbers 0-7.
pwmSetMode :: PwmMode -> IO () Source
pwmSetRange :: PwmValue -> IO () Source
Change the range used by pwmWrite
. Default is 1024.
Maxium is 4096.
pwmSetClock :: PwmValue -> IO () Source
Change the PWM divisor. Range is 2-4095.
piBoardRev :: IO Int Source
wpiPinToGpio :: Pin -> IO Pin Source
physPinToGpio :: Pin -> IO Pin Source