HPi 0.9.0 → 0.10.0
raw patch · 2 files changed
+45/−4 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ System.RaspberryPi.GPIO: setClockPWM :: Word32 -> IO ()
+ System.RaspberryPi.GPIO: setDataPWM :: Word8 -> Word32 -> IO ()
+ System.RaspberryPi.GPIO: setModePWM :: Word8 -> Word8 -> Word8 -> IO ()
+ System.RaspberryPi.GPIO: setRangePWM :: Word8 -> Word32 -> IO ()
Files
- HPi.cabal +3/−3
- System/RaspberryPi/GPIO.hs +42/−1
HPi.cabal view
@@ -2,15 +2,15 @@ -- see http://haskell.org/cabal/users-guide/ name: HPi-version: 0.9.0-synopsis: GPIO, I2C and SPI functions for the Raspberry Pi.+version: 0.10.0+synopsis: GPIO, I2C, SPI, and PWM functions for the Raspberry Pi. description: This package is a FFI wrapper around the bcm2835 library by Mike McCauley, it also includes a few utility functions for easier use of the imported functions. homepage: https://github.com/WJWH/HPi license: BSD3 license-file: LICENSE author: Wander Hillen maintainer: wjw.hillen@gmail.com-copyright: (c) 2013-2015 Wander Hillen+copyright: (c) 2013-2024 Wander Hillen category: System build-type: Simple cabal-version: >=1.10
System/RaspberryPi/GPIO.hs view
@@ -36,7 +36,16 @@ setDataModeSPI, transferAUXSPI, transferSPI, - transferManySPI + transferManySPI, + -- *PWM specific functions + -- |Allows control of 2 independent PWM channels. A limited subset of GPIO + -- pins can be connected to one of these 2 channels, allowing PWM control + -- of GPIO pins. You have to set the desired pin into a particular Alt Fun + -- to PWM output. + setClockPWM, + setModePWM, + setRangePWM, + setDataPWM ) where -- FFI wrapper over the I2C portions of the BCM2835 library by Mike McCauley, also some utility functions to @@ -164,6 +173,19 @@ --Sets the SPI clock divider and therefore the SPI clock speed. foreign import ccall unsafe "bcm2835.h bcm2835_aux_spi_setClockDivider" c_setClockDividerAUXSPI :: CUShort -> IO () +------------------------------------------- PWM functions -------------------------------------------------------------------------- +-- sets the PWM clock +foreign import ccall unsafe "bcm2835.h bcm2835_pwm_set_clock" c_setClockPWM :: CUInt -> IO () + +-- sets the PWM pulse ratio to emit to DATA/RANGE +foreign import ccall unsafe "bcm2835.h bcm2835_pwm_set_data" c_setDataPWM :: CUChar -> CUInt -> IO () + +-- sets the mode of the given PWM channel +foreign import ccall unsafe "bcm2835.h bcm2835_pwm_set_mode" c_setModePWM :: CUChar -> CUChar -> CUChar -> IO () + +-- sets the maximum range of the PWM output +foreign import ccall unsafe "bcm2835.h bcm2835_pwm_set_range" c_setRangePWM :: CUChar -> CUInt -> IO () + ------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------ Exportable functions -------------------------------------------------------------------- @@ -371,3 +393,22 @@ -- on MOSI, and simultaneously clocks in data from MISO. Returns the read data byte from the slave. transferAUXSPI :: Word8 -> IO Word8 transferAUXSPI input = fromIntegral <$> c_transferAUXSPI (fromIntegral input) + +-------------------------------------------- PWM functions ------------------------------------------------------------------------- + +-- |Sets the PWM clock divisor, to control the basic PWM pulse widths. +setClockPWM :: Word32 -> IO () +setClockPWM a = c_setClockPWM $ fromIntegral a + +-- |Sets the mode of the given PWM channel, allowing you to control the PWM mode and enable/disable that channel +setModePWM :: Word8 -> Word8 -> Word8 -> IO () +setModePWM a b c = c_setModePWM (fromIntegral a) (fromIntegral b) (fromIntegral c) + +-- |Sets the maximum range of the PWM output. The data value can vary between 0 and this range to control PWM output +setRangePWM :: Word8 -> Word32 -> IO () +setRangePWM a b = c_setRangePWM (fromIntegral a) (fromIntegral b) + +-- |Sets the PWM pulse ratio to emit to DATA/RANGE, where RANGE is set by 'setRangePWM'. +setDataPWM :: Word8 -> Word32 -> IO () +setDataPWM a b = c_setDataPWM (fromIntegral a) (fromIntegral b) +