i2c-bus-0.1.0: source-lib/I2C.hs
--------------------------------------------------------------------------------
-- |
-- Module : I2C
-- SPDX-License-Identifier : MIT
-- Copyright : karamellpelle@hotmail.com
-- Maintainer : karamellpelle@hotmail.com
-- Stability : experimental
--
-- Main module for communication over the I2C bus. This module will typically
-- give you all that you need, unless you need access to low level functionality
-- provided by your backend.
--
-- == Example
--
-- > {-# LANGUAGE TemplateHaskell #-}
-- > import I2C
-- >
-- > $(chip "PCF8575")
-- >
-- > testPCF8575 :: IO ()
-- > testPCF8575 = do
-- > chip <- openChip @PCF8575 "/dev/i2c-1" 0x20
-- >
-- > forM_ [0..0x00FF] $ \ix -> do
-- > rawwrite @Word16LE chip ix
-- > threadDelay 400000
--
--------------------------------------------------------------------------------
module I2C
(
-- * Chip connection
Internal.Chip,
openChip,
closeChip,
I2CErr (..),
module I2C.Chip,
-- * Primitives
module I2C.Types,
-- * Read and write Storable
module I2C.Raw,
-- * Registers utilities
module I2C.Register,
-- * Template Haskell
module I2C.TH,
) where
import Relude
import I2C.Types
import I2C.Exception
import I2C.Chip
import I2C.Internal qualified as Internal
import I2C.Raw
import I2C.Register
import I2C.TH
--------------------------------------------------------------------------------
-- reexport functions as lifted IO
-- | Open a connection to a chip of type 't' based on bus identifier and hardware address on bus.
-- The bus identifier on Linux is typically something like @\/dev\/i2c-N@.
-- May throw 'I2CErr'.
openChip :: forall t m . (IsChip t, MonadIO m) =>
Text -> -- ^ Bus identifier
ChipAddress -> -- ^ /7 bit/ hardware address
m (Internal.Chip t)
openChip id addr = liftIO $ Internal.openChip id addr
-- | Close connection to chip.
-- Shall not throw 'I2CErr'.
closeChip :: forall t m . (IsChip t, MonadIO m) => Internal.Chip t -> m ()
closeChip chip = liftIO $ Internal.closeChip chip