capsules_extra

Module mcp230xx

Source
Expand description

SyscallDriver for the Microchip MCP230xx I2C GPIO extenders.

Paraphrased from the website for the MCP23008:

The MCP23008 device provides 8-bit, general purpose, parallel I/O expansion for I2C bus applications. The MCP23008 has three address pins and consists of multiple 8-bit configuration registers for input, output and polarity selection. The system master can enable the I/Os as either inputs or outputs by writing the I/O configuration bits. The data for each input or output is kept in the corresponding Input or Output register. The polarity of the Input Port register can be inverted with the Polarity Inversion register. All registers can be read by the system master.

This driver can support the MCP230xx series GPIO extenders with a configurable number of banks.

§Usage

This capsule can either be used inside of the kernel or as an input to the gpio_async capsule because it implements the gpio_async::Port trait.

Example usage:


// Configure the MCP230xx. Device address 0x20.
let mcp230xx_i2c = static_init!(
    capsules::virtual_i2c::I2CDevice,
    capsules::virtual_i2c::I2CDevice::new(i2c_mux, 0x20));
let mcp230xx_buffer = static_init!([u8; capsules::mcp230xx::BUFFER_LENGTH],
                                   [0; capsules::mcp230xx::BUFFER_LENGTH]);
let mcp230xx = static_init!(
    capsules::mcp230xx::MCP230xx<'static>,
    capsules::mcp230xx::MCP230xx::new(mcp230xx_i2c,
                                      Some(&sam4l::gpio::PA[04]),
                                      None,
                                      mcp230xx_buffer,
                                      8, // How many pins in a bank
                                      1, // How many pin banks on the chip
                                      ));
mcp230xx_i2c.set_client(mcp230xx);
sam4l::gpio::PA[04].set_client(mcp230xx);

// Create an array of the GPIO extenders so we can pass them to an
// administrative layer that provides a single interface to them all.
let async_gpio_ports = static_init!(
    [&'static capsules::mcp230xx::MCP230xx; 1],
    [mcp230xx]);

// `gpio_async` is the object that manages all of the extenders.
let gpio_async = static_init!(
    capsules::gpio_async::GPIOAsync<'static, capsules::mcp230xx::MCP230xx<'static>>,
    capsules::gpio_async::GPIOAsync::new(async_gpio_ports));
// Setup the clients correctly.
for port in async_gpio_ports.iter() {
    port.set_client(gpio_async);
}

Note that if interrupts are not needed, a None can be passed in when the mcp230xx object is created.

Structs§

Constants§