Skip to content

Commit

Permalink
feat: add pinInfo property #34
Browse files Browse the repository at this point in the history
  • Loading branch information
urish committed Jul 29, 2020
1 parent de969e0 commit 858f1c1
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/arduino-uno-element.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ElementPin } from './pin';
import { customElement, html, LitElement, property, svg } from 'lit-element';
import { pinsFemalePattern } from './patterns/pins-female';

Expand All @@ -8,6 +9,40 @@ export class ArduinoUnoElement extends LitElement {
@property() ledTX = false;
@property() ledPower = false;

readonly pinInfo: ElementPin[] = [
{ name: 'A5.2', x: 87, y: 9, functions: ['analog', 'i2c'], signals: ['SCL'] },
{ name: 'A4.2', x: 97, y: 9, functions: ['analog', 'i2c'], signals: ['SDA'] },
{ name: 'AREF', x: 106, y: 9, functions: [], signals: [] },
{ name: 'GND.1', x: 115.5, y: 9, functions: ['power'], signals: ['GND'] },
{ name: '13', x: 125, y: 9, functions: ['gpio', 'spi'], signals: ['SCK'] },
{ name: '12', x: 134.5, y: 9, functions: ['gpio', 'spi'], signals: ['MISO'] },
{ name: '11', x: 144, y: 9, functions: ['gpio', 'pwm', 'spi'], signals: ['MOSI'] },
{ name: '10', x: 153.5, y: 9, functions: ['gpio', 'pwm', 'spi'], signals: ['SS'] },
{ name: '9', x: 163, y: 9, functions: ['gpio', 'pwm'], signals: [] },
{ name: '8', x: 173, y: 9, functions: ['gpio'], signals: [] },
{ name: '7', x: 189, y: 9, functions: ['gpio'], signals: [] },
{ name: '6', x: 198.5, y: 9, functions: ['gpio', 'pwm'], signals: [] },
{ name: '5', x: 208, y: 9, functions: ['gpio', 'pwm'], signals: [] },
{ name: '4', x: 217.5, y: 9, functions: ['gpio'], signals: [] },
{ name: '3', x: 227, y: 9, functions: ['gpio', 'pwm'], signals: [] },
{ name: '2', x: 236.5, y: 9, functions: ['gpio'], signals: [] },
{ name: '1', x: 246, y: 9, functions: ['gpio', 'usart'], signals: ['TX'] },
{ name: '0', x: 255.5, y: 9, functions: ['gpio', 'usart'], signals: ['RX'] },
{ name: 'IOREF', x: 131, y: 191.5, functions: [], signals: [] },
{ name: 'RESET', x: 140.5, y: 191.5, functions: [], signals: [] },
{ name: '3.3V', x: 150, y: 191.5, functions: ['power'], signals: [] },
{ name: '5V', x: 160, y: 191.5, functions: ['power'], signals: [] },
{ name: 'GND.2', x: 169.5, y: 191.5, functions: ['power'], signals: ['GND'] },
{ name: 'GND.3', x: 179, y: 191.5, functions: ['power'], signals: ['GND'] },
{ name: 'VIN', x: 188.5, y: 191.5, functions: ['power'], signals: [] },
{ name: 'A0', x: 208, y: 191.5, functions: ['gpio', 'analog'], signals: [] },
{ name: 'A1', x: 217.5, y: 191.5, functions: ['gpio', 'analog'], signals: [] },
{ name: 'A2', x: 227, y: 191.5, functions: ['gpio', 'analog'], signals: [] },
{ name: 'A3', x: 236.5, y: 191.5, functions: ['gpio', 'analog'], signals: [] },
{ name: 'A4', x: 246, y: 191.5, functions: ['gpio', 'analog', 'i2c'], signals: ['SDA'] },
{ name: 'A5', x: 255.5, y: 191.5, functions: ['gpio', 'analog', 'i2c'], signals: ['SCL'] },
];

render() {
const { ledPower, led13, ledRX, ledTX } = this;
return html`
Expand Down
6 changes: 6 additions & 0 deletions src/led-element.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { css, customElement, html, LitElement, property } from 'lit-element';
import { ElementPin } from './pin';

const lightColors: { [key: string]: string } = {
red: '#ff8080',
Expand All @@ -17,6 +18,11 @@ export class LEDElement extends LitElement {
@property() lightColor: string | null = null;
@property() label = '';

readonly pinInfo: ElementPin[] = [
{ name: 'A', x: 24, y: 42, functions: [], signals: [], description: 'Anode' },
{ name: 'C', x: 16, y: 42, functions: [], signals: [], description: 'Cathode' },
];

static get styles() {
return css`
:host {
Expand Down
31 changes: 31 additions & 0 deletions src/pin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export type PinFunction = 'power' | 'i2c' | 'spi' | 'gpio' | 'pwm' | 'analog' | 'dac' | 'usart';

export interface ElementPin {
/**
* A name that uniquely identifies the pin, e.g. `GND` or `VCC`.
* Pins that are connected internally must have the same name prefix, followed by a single dot,
* and a unique suffix (e.g. `GND.1` and `GND.2`).
*/
name: string;

/** The x-coordinate of the pin, relative to the element's origin */
x: number;

/** The y-coordinate of the pin, relative to the element's origin */
y: number;

/** The functions of this pin. Leave empty for generic pins without a designated function. **/
functions: PinFunction[];

/**
* List of signals carried by this pin. This is useful for pins such as I²C or SPI pins, where there are designated
* signal names (e.g. for I²C we have `SCL` and `SDA`). Set to an empty array if the pin isn't tied to specific
* protocol signals.
*/
signals: string[];

/**
* Optional pin description
*/
description?: string;
}

0 comments on commit 858f1c1

Please sign in to comment.