pi-lcd-0.1.0.0: Control an Adafruit character LCD and keypad kit on a Raspberry Pi

Copyright© Patrick Pelletier 2017
LicenseBSD3
Maintainercode@funwithsoftware.org
Safe HaskellSafe
LanguageHaskell2010

System.Hardware.PiLcd.Mcp23017

Contents

Description

This module lets you control an MCP23017 port expander (datasheet), such as the one used in the Adafruit LCD+Keypad Kit.

Synopsis

Creating a Port Expander

Note: the PortExpander caches register values, so it assumes no one else is going to be writing to the MCP23017 during the lifetime of the PortExpander.

data PortExpander Source #

Opaque type representing an MCP23017 port expander.

Read and write functions

These functions are used for reading and writing the MCP23017's registers. Generally, you would want to specify the i2cReadReg and i2cWriteReg functions from the System.Hardware.PiLcd.I2c module, partially applied to the I2cHandle and the chip's address on the I²C bus. However, by supplying SPI read and write functions instead, you could probably interface with an MCP23S17, although this has not been tested.

type ReadFunc = Word8 -> Int -> IO [Word8] Source #

Specifies a register number, and the number of consecutive bytes to read.

type WriteFunc = Word8 -> [Word8] -> IO () Source #

Specifies the register number, and the bytes to write.

Writing to registers

Each pair of 8-bit registers ("A" and "B") is treated as a 16-bit register, with "A" in the most significant 8 bits, and "B" in the least significant 8 bits. Each write function takes a mask operand, which specifies which bits to change. Bits which are "0" in the mask are left unchanged.

writeIoDir Source #

Arguments

:: PortExpander 
-> Word16

The value to write. A '1' bit indicates an input, and a '0' bit indicates an output.

-> Word16

Mask of bits to write.

-> IO () 

Write to I/O Direction Register. (§ 1.6.1 of datasheet)

writeIPol Source #

Arguments

:: PortExpander 
-> Word16

The value to write. A '1' bit means the input will be inverted.

-> Word16

Mask of bits to write.

-> IO () 

Write to Input Polarity Register. (§ 1.6.2 of datasheet)

writeGpPu Source #

Arguments

:: PortExpander 
-> Word16

The value to write. A '1' bit means the input will be pulled up with a 100 kΩ resistor.

-> Word16

Mask of bits to write.

-> IO () 

Write to Pull-Up Resistor Configuration Register. (§ 1.6.7 of datasheet)

writeGpio Source #

Arguments

:: PortExpander 
-> Word16

The value to write. This controls the value of the output pins.

-> Word16

Mask of bits to write.

-> IO () 

Write to Output Latch Register. (§ 1.6.11 of datasheet)

Reading from registers

readGpio :: PortExpander -> IO Word16 Source #

Read from the Port Register. (§ 1.6.10 of datasheet) Port A is in the most significant 8 bits, and Port B is in the least significant 8 bits.

readGpioA :: PortExpander -> IO Word8 Source #

Read from Port Register A. (§ 1.6.10 of datasheet)

readGpioB :: PortExpander -> IO Word8 Source #

Read from Port Register B. (§ 1.6.10 of datasheet)