UNPKG

it8951

Version:

Raspberry Pi node.js module for e-papers controlled by IT8951

130 lines 3.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SPI = exports.PIN_VALUE = void 0; /** * Internal class for SPI connection * @internal * @packageDocumentation */ // eslint-disable-next-line @typescript-eslint/no-var-requires const it8951 = require('../build/Release/spi'); // eslint-disable-line node/no-unpublished-require /** * Pin asignments for the non SPI pins in use. As long as bcm2835 is used these are hardware pins. * * @enum {number} */ var PINS; (function (PINS) { /** * Chip select. */ PINS[PINS["CS"] = 8] = "CS"; /** * Ready pin. Pulls high when it8951 is ready to recieve communication. */ PINS[PINS["READY"] = 24] = "READY"; /** * Reset pin, pull low to reset controller. */ PINS[PINS["RESET"] = 17] = "RESET"; })(PINS || (PINS = {})); /** * Possible pin values when using {@link setPin} or {@link readPin} * * @enum {number} */ var PIN_VALUE; (function (PIN_VALUE) { /** * Pin low, i.e. no voltage. */ PIN_VALUE[PIN_VALUE["LOW"] = 0] = "LOW"; /** * Pin high, i.e. 3.3v on specified pin. */ PIN_VALUE[PIN_VALUE["HIGH"] = 1] = "HIGH"; })(PIN_VALUE = exports.PIN_VALUE || (exports.PIN_VALUE = {})); /** * The SPI class is a convenience class for sending data over SPI. In practice, it only exposes the methods needed for the main {@link IT8951} class. * * @export * @class SPI */ class SPI { /** * Creates an instance of SPI. * * This will initialise the c++ code, then set chip select pin high and trigger a controller reset. */ constructor() { it8951.init(); this.setPin(PINS.CS, PIN_VALUE.HIGH); this.reset(); } /** * Reset the controller. */ reset() { return it8951.reset(); } /** * Write the words in `data` over the SPI interface. * * @param data Array of words to write. */ writeWords(data) { this.setPin(PINS.CS, PIN_VALUE.LOW); this.waitForReady(); it8951.writeWords(data); this.setPin(PINS.CS, PIN_VALUE.HIGH); } /** * Reads `length` number of words from the SPI interface. * * @param length Number of words to read. */ readWords(length) { const data = new Uint16Array(length); this.setPin(PINS.CS, PIN_VALUE.LOW); this.waitForReady(); const response = it8951.readWords(data, length); this.setPin(PINS.CS, PIN_VALUE.HIGH); return response; } /** * Writes a sequence of bytes over the SPI interface. * * @param data Array of bytes to write. */ writeBytes(data) { this.setPin(PINS.CS, PIN_VALUE.LOW); this.waitForReady(); it8951.writeBytes(data); this.setPin(PINS.CS, PIN_VALUE.HIGH); } /** * Read pin `pin`. * * @param pin Hardware pin number to read */ readPin(pin) { return it8951.readPin(pin); } /** * Set pin `pin` to `value`. * * @param pin Hardware pin number to set * @param value Value to set */ setPin(pin, value) { it8951.setPin(pin, value); } /** * Synchronously blocks until the SPI is ready for new messages. */ waitForReady() { it8951.waitForReady(); } } exports.SPI = SPI; //# sourceMappingURL=spi.js.map