HPi 0.5.1 → 0.6.0
raw patch · 2 files changed
+46/−25 lines, 2 files
Files
- HPi.cabal +25/−25
- System/RaspberryPi/GPIO.hs +21/−0
HPi.cabal view
@@ -1,26 +1,26 @@--- Initial HPi.cabal generated by cabal init. For further documentation, --- see http://haskell.org/cabal/users-guide/ - -name: HPi -version: 0.5.1 -synopsis: GPIO, I2C and SPI 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 -category: System -build-type: Simple -cabal-version: >=1.8 - -library - exposed-modules: System.RaspberryPi.GPIO - -- other-modules: - build-depends: base < 5, bytestring < 0.11 - extra-libraries: bcm2835 - -source-repository head - type: git +-- Initial HPi.cabal generated by cabal init. For further documentation,+-- see http://haskell.org/cabal/users-guide/++name: HPi+version: 0.6.0+synopsis: GPIO, I2C and SPI 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+category: System+build-type: Simple+cabal-version: >=1.8++library+ exposed-modules: System.RaspberryPi.GPIO+ -- other-modules:+ build-depends: base < 5, bytestring < 0.11+ extra-libraries: bcm2835++source-repository head+ type: git location: git://github.com/WJWH/HPi.git
System/RaspberryPi/GPIO.hs view
@@ -8,6 +8,7 @@ PinMode(..), LogicLevel, Address, + SPIBitOrder(..), SPIPin(..), CPOL, CPHA, @@ -27,7 +28,9 @@ -- *SPI specific functions withSPI, chipSelectSPI, + setBitOrderSPI, setChipSelectPolaritySPI, + setClockDividerSPI, setDataModeSPI, transferSPI, transferManySPI @@ -73,6 +76,9 @@ -- |Either high or low. type LogicLevel = Bool +-- |Specifies the SPI data bit ordering. +data SPIBitOrder = LSBFirst | MSBFirst + -- |This describes which Chip Select pins are asserted (used in SPI communications). data SPIPin = CS0 | CS1 | CSBOTH | CSNONE deriving (Eq, Show, Enum) @@ -134,8 +140,12 @@ --Changes the chip select pins foreign import ccall unsafe "bcm2835.h bcm2835_spi_chipSelect" c_chipSelectSPI :: CUChar -> IO () +--Set the bit order to be used for transmit and receive. +foreign import ccall unsafe "bcm2835.h bcm2835_spi_setBitOrder" c_setBitOrder :: CUChar -> IO () --Sets whether SPI Chip Select pulls pins high or low. foreign import ccall unsafe "bcm2835.h bcm2835_spi_setChipSelectPolarity" c_setChipSelectPolarity :: CUChar -> CUChar -> IO () +--Sets the SPI clock divider and therefore the SPI clock speed. +foreign import ccall unsafe "bcm2835.h bcm2835_spi_setClockDivider" c_setClockDividerSPI :: CUShort -> IO () --Sets the data mode used (phase/polarity) foreign import ccall unsafe "bcm2835.h bcm2835_spi_setDataMode" c_setDataModeSPI :: CUChar -> IO () @@ -285,6 +295,17 @@ -- asserted during the transfer. chipSelectSPI :: SPIPin -> IO () chipSelectSPI pin = c_chipSelectSPI (fromIntegral . fromEnum $ pin) + +-- |Sets the SPI clock divider and therefore the SPI clock speed. +setClockDividerSPI :: Word16 -> IO () +setClockDividerSPI a = c_setClockDividerSPI $ fromIntegral a + +-- |Set the bit order to be used for transmit and receive. The bcm2835 SPI0 only supports MSBFirst, +-- so if you select LSBFirst, the bytes will be reversed in software. +-- The library defaults to MSBFirst. +setBitOrderSPI :: SPIBitOrder -> IO () +setBitOrderSPI LSBFirst = c_setBitOrder 0 +setBitOrderSPI MSBFirst = c_setBitOrder 1 -- |Sets the chip select pin polarity for a given pin(s). When a transfer is made with 'transferSPI' or 'transferManySPI', the -- currently selected chip select pin(s) will be asserted to the LogicLevel supplied. When transfers are not happening, the chip