open-index/open-npm huggingface dataset:
npm package: @johntalton/eeprom
Description: Generic EEPROM abstraction over [`I2CBus`](https://github.com/johntalton/and-other-delights) interface.
Latest version: 1.1.1

# EEPROM

Generic EEPROM abstraction over [`I2CBus`](https://github.com/johntalton/and-other-delights) interface.


[![npm Version](http://img.shields.io/npm/v/@johntalton/eeprom.svg)](https://www.npmjs.com/package/@johntalton/eeprom)
![GitHub package.json version](https://img.shields.io/github/package-json/v/johntalton/eeprom)
[![CI](https://github.com/johntalton/eeprom/actions/workflows/CI.yml/badge.svg)](https://github.com/johntalton/eeprom/actions/workflows/CI.yml)

# File Systems

While most EEPROM are use as "raw" memeoy devices.  Simple File System implmentation can be used:

- [EEFS](https://github.com/johntaton/eefs) A implementation NASA EEFS that supports tradition filename style access
- [CyclicFS](https://github.com/johntaton/cyclic-fs) As circular buffer with versioned slots of fixed used defined size


# Paging and Alignment

EEPROMs typically are divided into "pages" of some small number of bytes (32 to 128 in most cases).

Further each underlying `I2CBus` implementation also have a maximum transfer bytes (implementation specific).

This library provides a way to abstract a single `read`/`write` requests to satisfy those requirements, by spanning over multiple `read`/`write` calls.

Most EEPROM also require that page writes end be aligned to a end boundary, thus writes that cross over page boundaries will also be chunked (even if the total bytes does not exceed a page size)

# Addressing

EEPROM in most cases have 16-bit addressing.  This library assume as much as splits the address into [ MSB, LSB ] and passes to the `I2CBus` (not all implementation can handle multi-byte addressing).

# Example

```javascript
import { EEPROM, DEFAULT_EEPROM_ADDRESS } from '@johntalton/eeprom'

const bus = /* I2CBus instance */

const abus = new I2CAddressedBus(bus, DEFAULT_EEPROM_ADDRESS)
const eeprom = new EEPROM(abus, { writePageSize: 64 })

// write a blob to offset 60
// with a boundary at 64 this will result in 2 writes
await eeprom.write(60, Uint32Array.from([ 1, 2, 3, 4 ]))

//
const ab = new ArrayBuffer(128)
const buffer = await eeprom.read(60, ab.byteLength, ab)
```

# Transaction

This library does not (yet?) provide a transactional safe way of calling `read` or `write`.  That is - multiple calls will occurred async and can be interrupted by other task executed by the user.
npm package: @johntalton/eslint-config
Description: Shared `eslint` configuration accross projects.
Author: johntalton@gmail.com
Latest version: 3.0.0

# eslint-config
Shared `eslint` configuration accross projects.

```shell
npm -D @johntalton/eslint-config
```

## Notes:

### Install Dependencies

```shell
npm i -D eslint-plugin-immutable eslint-plugin-import eslint-plugin-jsdoc eslint-plugin-mocha eslint-plugin-no-loops eslint-plugin-no-use-extend-native eslint-plugin-promise eslint-plugin-security eslint-plugin-spellcheck eslint-plugin-functional eslint-plugin-fp
```
```shell
npm i -D  @typescript-eslint/eslint-plugin
```

### Extend
example adding to the `package.json`
```JSON
//package.json
{
  ...
  "eslintConfig": {
    "extends": [
      "@johntalton/eslint-config/ts",
      "@johntalton/eslint-config/node"
    ],
    "env": { "node": true }
  }
}
```
npm package: @johntalton/excamera-i2cdriver
Description: Provides a JavaScript API for the I²C driver. Works well in the browser via [SerialPort](https://developer.mozilla.org/en-US/docs/Web/API/SerialPort)
Latest version: 3.1.4

# Excamera Labs I2CDriver

Provides a JavaScript API for the I²C driver. Works well in the browser via [SerialPort](https://developer.mozilla.org/en-US/docs/Web/API/SerialPort)

[![npm Version](http://img.shields.io/npm/v/@johntalton/excamera-i2cdriver.svg)](https://www.npmjs.com/package/@johntalton/excamera-i2cdriver)
![GitHub package.json version](https://img.shields.io/github/package-json/v/johntalton/excamera-i2cdriver)
[![CI](https://github.com/johntalton/excamera-i2cdriver/actions/workflows/CI.yml/badge.svg)](https://github.com/johntalton/excamera-i2cdriver/actions/workflows/CI.yml)


# Capture Mode

Capture mode is supported via function generator stream.

The `eventStreamFromReader` factory can be called with a `ReadableStream` to create state-machine stream that will `yield` the i²c events.

This can be used to replicate the excameras native visualization as the raw date is provided for each event. (alternatively constructing a function generator from lower level components)
npm package: @johntalton/ht16k33
Description: LED driver commonly used for many different type of displays
Latest version: 1.1.2

# HT16K33

LED driver commonly used for many different type of displays

[![npm Version](http://img.shields.io/npm/v/@johntalton/ht16k33.svg)](https://www.npmjs.com/package/@johntalton/ht16k33)
![GitHub package.json version](https://img.shields.io/github/package-json/v/johntalton/ht16k33)
[![CI](https://github.com/johntalton/ht16k33/actions/workflows/CI.yaml/badge.svg)](https://github.com/johntalton/ht16k33/actions/workflows/CI.yaml)


## Layout

The `setMemory` method takes in a "Layout", this is the direct chip specific setup. It is defined a the set of common (com0, com1..) and rows (row0, row1).

The Layout object has 8 (com0 .. com7) each having 16 rows (row0 .. row15) that are Boolean values for On or Off.

While setting these directly is supported, it is much easier to you a product specific defined Layout helper.

### Segmented

Layout helpers are defined for both 7 and 14 segmented displays are supported (Adafruit [here](https://www.adafruit.com/product/1002) and [here](https://www.adafruit.com/product/3089))

In addition several "fonts" are defined in terms of common A, B, C ...etc segmentation.

(see example)

### Matrix

Other Layouts, like for this [8x8 BiColor Matrix](https://www.adafruit.com/product/902) display are also provided.

```javascript

const layout = AdafruitMatrix8x8BiColor.toLayout([
  { x: 5, y: 5, color: 'yellow' }, // set 5,5 to yellow
  //... others
  // missing x,y will be set to "black" / unset
])
```

# Example

```javascript
import { I2CAddressedBus } from '@johntalton/and-other-delights'
import { HT16K33, BLINK } from '@johntalton/ht16k33'

const bus = /* byob - bring your own I2CBus */
const aBus = new I2CAddressedBus(bus, 0x70)
const device = new HT16K33(aBus)

await device.enableOscillator()
await device.setDisplay(true, BLINK.OFF)

// Layout helper can be used or set directly
// directly define the Layout values here
const customLayout = {
  /* set com/row values */
  com0: { row0: true, /* ... */ row15: false },
  com1: /* ...etc */
}
await device.setMemory(customLayout)

```

## Layout for 4 digit 7 segment display form ASCII font
```javascript
const device = /* .. init code from above */
// set the time for a 4 digit 7 segment display
// create encoding for desired text "1130"
// result is values for A,B,C,... etc segments and the colon
const encoded = Font7SegmentASCII.encode4Digit('1130', true)
// convert the encoded segment representation into a Product specific
// memory layout, in this case a classic Adafruit display:
// https://www.adafruit.com/product/1002
const layout = Adafruit4Digit7SegmentBackpack.toLayout(encoded)
// and now set it
await device.setMemory(layout)
```
npm package: @johntalton/i2c-bus-excamera-i2cdriver
Description: Provides API over the Excamera I2CDriver to provide a `I2CBus` interface.
Latest version: 4.0.2

# Excamera I2CDriver I2CBus

Provides API over the Excamera I2CDriver to provide a `I2CBus` interface.


[![npm Version](http://img.shields.io/npm/v/@johntalton/i2c-bus-excamera-i2cdriver.svg)](https://www.npmjs.com/package/@johntalton/i2c-bus-excamera-i2cdriver)
![GitHub package.json version](https://img.shields.io/github/package-json/v/johntalton/i2c-bus-excamera-i2cdriver)
[![CI](https://github.com/johntalton/i2c-bus-excamera-i2cdriver/actions/workflows/CI.yml/badge.svg)](https://github.com/johntalton/i2c-bus-excamera-i2cdriver/actions/workflows/CI.yml)

# I2CBus

While the [Excamera i2cDriver](https://github.com/johntalton/excamera-i2cdriver) itself provides a wider range of features to manage the I²C bus, this library provides a concrete implementation of the  [`I2CBus`](https://github.com/johntalton/and-other-delights) interface.

# Example

```javascript
import { ExcameraLabsI2CDriver, ExcameraLabsI2CDriverI2C } from '@johntalton/excamera-i2cdriver'
import { I2CBusExcameraI2CDriver } from '@johntalton/i2c-bus-excamera-i2cdriver'

// the i2cdriver is a serial device
// both the WebSerial and Node SerialPort can be used as a source
// the underlying code assumes only it is a ReadableWritablePair
const port = /* some ReadableWritablePair like a WebSerial port */

// using i2cdriver static methods directly to setup speed
// not required, used as example
await ExcameraLabsI2CDriver.setSpeed(port, 400)

// create an instance of the driver
const i2cdriver = ExcameraLabsI2CDriverI2C.from({ port })

// use to create a I2CBus
const bus = new I2CBusExcameraI2CDriver(i2cdriver)

// now the bus can be used in a wide range of drivers or other compatible implementations
// or directly as follows
for(const address of bus.scan()) {
  console.log('found address', address.toString(16))
}
```
npm package: @johntalton/i2c-bus-fivdi
Description: Providing a wrapper around node module `i2c-bus` (by [Fivdi](https://github.com/fivdi/i2c-bus/)) to expose an `I2CBus` (from [AOD](https://github.com/johntalton/and-other-delights)) compatible interface.
Latest version: 1.2.1

# i2c-bus-fivdi

Providing a wrapper around node module `i2c-bus` (by [Fivdi](https://github.com/fivdi/i2c-bus/)) to expose an `I2CBus` (from [AOD](https://github.com/johntalton/and-other-delights)) compatible interface.

[![npm Version](https://img.shields.io/npm/v/@johntalton/i2c-bus-fivdi.svg)](https://www.npmjs.com/package/@johntalton/i2c-bus-fivdi)
![GitHub package.json version](https://img.shields.io/github/package-json/v/johntalton/i2c-bus-fivdi)
[![CI](https://github.com/johntalton/i2c-bus-fivdi/actions/workflows/CI.yml/badge.svg)](https://github.com/johntalton/i2c-bus-fivdi/actions/workflows/CI.yml)

## Background

While AOD's `I2CBus` provide a more limited API compared to `i2c-bus`, it is also suitable for a wider range of underlining implementations (such as [MCP2221](https://github.com/johntalton/i2c-bus-mcp2221) and Excamera Labs [i2cDriver](https://github.com/johntalton/i2c-bus-excamera-i2cdriver) which are [WebSerial](https://developer.mozilla.org/en-US/docs/Web/API/Web_Serial_API) and [WebHID](https://developer.mozilla.org/en-US/docs/Web/API/WebHID_API) / NodeHID compatible implementations)

Also, `I2CBus` interface is defined in terms of `ArrayBuffer` and `ArrayBufferView` instead of the Node specific `Buffer`.  This allows for more flexibility in non-node environments, the browser.

## Example

Simple example to access [AHT20](https://github.com/johntalton/aht20) temperature sensor on a raspberry pi with I²C enabled on `/dev/i2c-1`

```javascript
import { FivdiBusProvider } from '@johntalton/i2c-bus-fivdi'
import { I2CAddressedBus } from '@johntalton/and-other-delights'
import { AHT20, DEFAULT_ADDRESS } from '@johntalton/aht20'

const I2C_BUS_NUMBER = 1 // reference to /dev/i2c-1

const bus = await FivdiBusProvider.openPromisified(I2C_BUS_NUMBER)
const abus = I2CAddressedBus.from(bus, DEFAULT_ADDRESS)
const device = AHT20.from(abus)

const { temperatureC } = await device.getMeasurement()

```
npm package: @johntalton/i2c-bus-mcp2221
Description: An [I²C interface](https://github.com/johntalton/and-other-delights) `I2CBus` implementation over [MCP2221](https://github.com/johntalton/mcp2221)
Author: johntalton@gmail.com
Latest version: 4.2.1

# I²C Bus MCP2221

An [I²C interface](https://github.com/johntalton/and-other-delights) `I2CBus` implementation over [MCP2221](https://github.com/johntalton/mcp2221)


[![npm Version](http://img.shields.io/npm/v/@johntalton/i2c-bus-mcp2221.svg)](https://www.npmjs.com/package/@johntalton/i2c-bus-mcp2221)
![GitHub package.json version](https://img.shields.io/github/package-json/v/johntalton/i2c-bus-mcp2221)
[![CI](https://github.com/johntalton/i2c-bus-mcp2221/actions/workflows/CI.yml/badge.svg)](https://github.com/johntalton/i2c-bus-mcp2221/actions/workflows/CI.yml)

# Example

```javascript
import { MCP2221 } from '@johntalton/mcp2221'
import { I2CBusMCP2221 } from '@johntalton/i2c-bus-mcp2221'

const hidDevice = /* navigator.hid.request ... */
const source = new WebHIDStreamSource(hidDevice) // or NodeHIDStreamSource
const device = MCP2221.from(source) // create device
const bus = I2CBusMCP2221.from(device) // create virtual bus from device

// bus.readI2CBlock(...) and friends
```
npm package: @johntalton/i2c-bus-soft
Description: Library to wrap [`I2CBus`](https://github.com/johntalton/and-other-delights) over top of GPIO abstraction.
Latest version: 1.0.1

# I2CBus Software over GPIO

Library to wrap [`I2CBus`](https://github.com/johntalton/and-other-delights) over top of GPIO abstraction.


[![npm Version](https://img.shields.io/npm/v/@johntalton/i2c-bus-soft.svg)](https://www.npmjs.com/package/@johntalton/i2c-bus-soft)
![GitHub package.json version](https://img.shields.io/github/package-json/v/johntalton/i2c-bus-soft)
[![CI](https://github.com/johntalton/i2c-bus-soft/actions/workflows/CI.yml/badge.svg)](https://github.com/johntalton/i2c-bus-soft/actions/workflows/CI.yml)

# Motivation

Because 🤷🏻‍♂️,  but also:

To further understanding and testing of I²C bus interactions and expose unique capabilities.

And to provide a `I2CBus` abstraction that is capable of being the source bus for a wider range of sensors implemented overtop of this API.

Primary testing of the has been done over the following configuration:

[`SerialPort`](https://serialport.io/) -> [Excamera I2CDriver](https://github.com/johntalton/excamera-i2cdriver) -> [`i2c-bus-excamera`](https://github.com/johntalton/i2c-bus-excamera-i2cdriver) -> [`pcf8574`](https://github.com/johntalton/pcf8574) -> `i2c-bus-soft` -> device<sup>*</sup>

<sup>*</sup> where devices include [EEPROM](https://github.com/johntalton/eeprom) / [AHT20](https://github.com/johntalton/aht20) / [DS1841](https://github.com/johntalton/DS1841) and others

The `pcf8574` acts as the primary GPIO interface as it naturally floats HIGH and does not have the concept of input/output direction.  This lends itself to I²C control.  However it is itself a `I2CBus` device, that is running overtop of the Excamera Serial i2cDriver.



# Example
```javascript
import { I2CBusGPIO } from '@johntalton/i2c-bus-soft'

/*
	using some custom GPIO device implement the set/get interface
	(note true maps to Floating/HIGH while false is LOW)
*/
const gpioBus = new I2CBusGPIO({
	/**
	 * @param {boolean} scl
	 * @param {boolean} sda
	 */
	async set(scl, sda) {
		// set scl and sda according to parameters
	},

	async get() {
		// return scl and sda as boolean values
		return { scl, sda }
	}
})

// now the bus can be used as normal I2CBus
// such as to scan
const devices = await gpioBus.scan()
for (const device of devices) {
	console.log('found device at', '0x' + device.toString(16).toUpperCase().padStart(2, '0'))
}

// or using a attached device
const adt = new ADT7410(new I2CAddressedBus(gpioBus, 0x48))
const id = await adt.getId()
const temp = await adt.getTemperature()

```

# Using the PCF8574

Using pin 6/7 used for SDA/SCL respectively

```javascript
import { I2CBusGPIO } from '@johntalton/i2c-bus-soft'
import { PCF8574 } from '@johntalton/pcf8574'

const device = new PCF8574(/* some other bus */)

const gpioBus = new I2CBusGPIO({
	async set(scl, sda) {
		await device.writePort({ p6: sda, p7: scl })
	},

	async get() {
		const { p6, p7 } = await device.readPort()
		return { scl, sda }
	}
})
```