UNPKG

mcp23017-promise

Version:

MCP23017 library with promises.

145 lines (144 loc) 4.82 kB
import { BusInterface } from "async-i2c-bus"; export declare const A0: number; export declare const A1: number; export declare const A2: number; export declare const A3: number; export declare const A4: number; export declare const A5: number; export declare const A6: number; export declare const A7: number; export declare const B0: number; export declare const B1: number; export declare const B2: number; export declare const B3: number; export declare const B4: number; export declare const B5: number; export declare const B6: number; export declare const B7: number; /** Direction of the I/O pins */ export declare enum Direction { /** Output pin */ OUT = 0, /** Input pin without pull-up */ IN = 1, /** Input pin with pull-up */ IN_UP = 2 } /** Interupt mode */ export declare enum InteruptMode { /** No interupt (used to reset) */ INT_None = 0, /** Interupt when not one */ INT_One = 1, /** Interupt when not zero */ INT_Zero = 2, /** Interupt on change */ INT_Change = 3 } /** An interupt definition */ export interface InteruptDefinition { /** Pin number */ pin: number; /** Interupt mode of the pin */ mode: InteruptMode; /** Callback if any */ callback?: (val: number) => void; } /** Interupt handler to use as an abstract type */ export interface InteruptHandler { /** Map from pin number to callback */ [pin: number]: (val: number) => void; } /** Pin value */ export declare enum Level { /** Low or 0 */ LOW = 0, /** High or 1 */ HIGH = 1 } /** Options for the MCP23017 object */ export interface IMCP23017Options { /** Address of the chip on the I2C bus */ address?: number; /** Use of the interleaved (default) or separate bank mode */ separate?: boolean; } export declare const IOCON_INTPOL: number; export declare const IOCON_ODR: number; export declare const IOCON_HAEN: number; export declare const IOCON_DISSLW: number; export declare const IOCON_SEQOP: number; export declare const IOCON_MIRROR: number; export declare const IOCON_BANK: number; /** Options for the driver */ export interface Options { /** Address of the MCP (0x20 if not provided) */ address?: number; /** Should the two banks be seaparate or interleaved (default false) */ separate?: boolean; } /** This class drives a single MCP23017 GPIO extender */ export declare class MCP23017 { private device; private separate; private bank; private cache; /** Constructor. * * @param bus an instance of i2c bus. May be closed at this point * @param options options for the driver. */ constructor(bus: BusInterface, options?: Options); /** Initialize the class * * Must be called with an open bus */ init(): Promise<void>; /** Reads the configuration byte of the chip * @return the value of the configuration as a byte in a promise. */ readConfigByte(): Promise<number>; /** Change the way register banks are organize. * @param separate set to true for registers organized as two * independent banks and false for interleaved (default) * @return a promisse fullfilled when the operation is performed. */ setSeparate(separate: boolean): Promise<void>; /** Sets the direction of a set of GPI/O pins and eventually pull-up status. * @param pins: the set of pins (number used as a bit set) * @param direction: the direction of the pin (can be IN OUT or IN_UP) * @return a promisse fullfilled when the operation is performed. */ setDirection(pins: number, direction: Direction): Promise<void>; /** Set the polarity of the output (ie XOR with it) * @param polarity of each pin as a bit array */ setPolarity(pins: number): Promise<void>; /** Reads the GPIO * @return the value of the GPIO Pin in a promise. */ read(): Promise<number>; /** Modify the GPIO * @param set: bits to set as a bit field * @param unset: bits to set as a bit field */ write(set: number, unset: number): Promise<void>; /** Register changes to the interupt handling * @param intDefs: a list of interupt handling description that * will be (dis)activated * @param handler: an optional interupt handler that was in place * @return the new interupt handler. */ register(intDefs: InteruptDefinition[], handler?: InteruptHandler): Promise<InteruptHandler>; /** Handle interupts received. * @param handler: an interupt handler built during the registration. */ handle(handler: InteruptHandler): Promise<void>; private readCache; private initCache; private readBuffer; private writeByte; private writeWord; private writeBanks; private readBanks; }