Skip to content

Commit 6ce606f

Browse files
committed
feat: update pinInfo property format
1 parent 858f1c1 commit 6ce606f

File tree

3 files changed

+67
-44
lines changed

3 files changed

+67
-44
lines changed

src/arduino-uno-element.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { ElementPin } from './pin';
21
import { customElement, html, LitElement, property, svg } from 'lit-element';
32
import { pinsFemalePattern } from './patterns/pins-female';
3+
import { analog, ElementPin } from './pin';
44

55
@customElement('wokwi-arduino-uno')
66
export class ArduinoUnoElement extends LitElement {
@@ -10,37 +10,37 @@ export class ArduinoUnoElement extends LitElement {
1010
@property() ledPower = false;
1111

1212
readonly pinInfo: ElementPin[] = [
13-
{ name: 'A5.2', x: 87, y: 9, functions: ['analog', 'i2c'], signals: ['SCL'] },
14-
{ name: 'A4.2', x: 97, y: 9, functions: ['analog', 'i2c'], signals: ['SDA'] },
15-
{ name: 'AREF', x: 106, y: 9, functions: [], signals: [] },
16-
{ name: 'GND.1', x: 115.5, y: 9, functions: ['power'], signals: ['GND'] },
17-
{ name: '13', x: 125, y: 9, functions: ['gpio', 'spi'], signals: ['SCK'] },
18-
{ name: '12', x: 134.5, y: 9, functions: ['gpio', 'spi'], signals: ['MISO'] },
19-
{ name: '11', x: 144, y: 9, functions: ['gpio', 'pwm', 'spi'], signals: ['MOSI'] },
20-
{ name: '10', x: 153.5, y: 9, functions: ['gpio', 'pwm', 'spi'], signals: ['SS'] },
21-
{ name: '9', x: 163, y: 9, functions: ['gpio', 'pwm'], signals: [] },
22-
{ name: '8', x: 173, y: 9, functions: ['gpio'], signals: [] },
23-
{ name: '7', x: 189, y: 9, functions: ['gpio'], signals: [] },
24-
{ name: '6', x: 198.5, y: 9, functions: ['gpio', 'pwm'], signals: [] },
25-
{ name: '5', x: 208, y: 9, functions: ['gpio', 'pwm'], signals: [] },
26-
{ name: '4', x: 217.5, y: 9, functions: ['gpio'], signals: [] },
27-
{ name: '3', x: 227, y: 9, functions: ['gpio', 'pwm'], signals: [] },
28-
{ name: '2', x: 236.5, y: 9, functions: ['gpio'], signals: [] },
29-
{ name: '1', x: 246, y: 9, functions: ['gpio', 'usart'], signals: ['TX'] },
30-
{ name: '0', x: 255.5, y: 9, functions: ['gpio', 'usart'], signals: ['RX'] },
31-
{ name: 'IOREF', x: 131, y: 191.5, functions: [], signals: [] },
32-
{ name: 'RESET', x: 140.5, y: 191.5, functions: [], signals: [] },
33-
{ name: '3.3V', x: 150, y: 191.5, functions: ['power'], signals: [] },
34-
{ name: '5V', x: 160, y: 191.5, functions: ['power'], signals: [] },
35-
{ name: 'GND.2', x: 169.5, y: 191.5, functions: ['power'], signals: ['GND'] },
36-
{ name: 'GND.3', x: 179, y: 191.5, functions: ['power'], signals: ['GND'] },
37-
{ name: 'VIN', x: 188.5, y: 191.5, functions: ['power'], signals: [] },
38-
{ name: 'A0', x: 208, y: 191.5, functions: ['gpio', 'analog'], signals: [] },
39-
{ name: 'A1', x: 217.5, y: 191.5, functions: ['gpio', 'analog'], signals: [] },
40-
{ name: 'A2', x: 227, y: 191.5, functions: ['gpio', 'analog'], signals: [] },
41-
{ name: 'A3', x: 236.5, y: 191.5, functions: ['gpio', 'analog'], signals: [] },
42-
{ name: 'A4', x: 246, y: 191.5, functions: ['gpio', 'analog', 'i2c'], signals: ['SDA'] },
43-
{ name: 'A5', x: 255.5, y: 191.5, functions: ['gpio', 'analog', 'i2c'], signals: ['SCL'] },
13+
{ name: 'A5.2', x: 87, y: 9, signals: [analog(5), { type: 'i2c', signal: 'SCL' }] },
14+
{ name: 'A4.2', x: 97, y: 9, signals: [analog(4), { type: 'i2c', signal: 'SDA' }] },
15+
{ name: 'AREF', x: 106, y: 9, signals: [] },
16+
{ name: 'GND.1', x: 115.5, y: 9, signals: [{ type: 'power', signal: 'GND' }] },
17+
{ name: '13', x: 125, y: 9, signals: [{ type: 'spi', signal: 'SCK' }] },
18+
{ name: '12', x: 134.5, y: 9, signals: [{ type: 'spi', signal: 'MISO' }] },
19+
{ name: '11', x: 144, y: 9, signals: [{ type: 'spi', signal: 'MOSI' }, { type: 'pwm' }] },
20+
{ name: '10', x: 153.5, y: 9, signals: [{ type: 'spi', signal: 'SS' }, { type: 'pwm' }] },
21+
{ name: '9', x: 163, y: 9, signals: [{ type: 'pwm' }] },
22+
{ name: '8', x: 173, y: 9, signals: [] },
23+
{ name: '7', x: 189, y: 9, signals: [] },
24+
{ name: '6', x: 198.5, y: 9, signals: [{ type: 'pwm' }] },
25+
{ name: '5', x: 208, y: 9, signals: [{ type: 'pwm' }] },
26+
{ name: '4', x: 217.5, y: 9, signals: [] },
27+
{ name: '3', x: 227, y: 9, signals: [{ type: 'pwm' }] },
28+
{ name: '2', x: 236.5, y: 9, signals: [] },
29+
{ name: '1', x: 246, y: 9, signals: [{ type: 'usart', signal: 'TX' }] },
30+
{ name: '0', x: 255.5, y: 9, signals: [{ type: 'usart', signal: 'RX' }] },
31+
{ name: 'IOREF', x: 131, y: 191.5, signals: [] },
32+
{ name: 'RESET', x: 140.5, y: 191.5, signals: [] },
33+
{ name: '3.3V', x: 150, y: 191.5, signals: [{ type: 'power', signal: 'VCC', voltage: 3.3 }] },
34+
{ name: '5V', x: 160, y: 191.5, signals: [{ type: 'power', signal: 'VCC', voltage: 5 }] },
35+
{ name: 'GND.2', x: 169.5, y: 191.5, signals: [{ type: 'power', signal: 'GND' }] },
36+
{ name: 'GND.3', x: 179, y: 191.5, signals: [{ type: 'power', signal: 'GND' }] },
37+
{ name: 'VIN', x: 188.5, y: 191.5, signals: [{ type: 'power', signal: 'VCC' }] },
38+
{ name: 'A0', x: 208, y: 191.5, signals: [analog(0)] },
39+
{ name: 'A1', x: 217.5, y: 191.5, signals: [analog(1)] },
40+
{ name: 'A2', x: 227, y: 191.5, signals: [analog(2)] },
41+
{ name: 'A3', x: 236.5, y: 191.5, signals: [analog(3)] },
42+
{ name: 'A4', x: 246, y: 191.5, signals: [analog(4), { type: 'i2c', signal: 'SCL' }] },
43+
{ name: 'A5', x: 255.5, y: 191.5, signals: [analog(5), { type: 'i2c', signal: 'SDA' }] },
4444
];
4545

4646
render() {

src/led-element.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export class LEDElement extends LitElement {
1919
@property() label = '';
2020

2121
readonly pinInfo: ElementPin[] = [
22-
{ name: 'A', x: 24, y: 42, functions: [], signals: [], description: 'Anode' },
23-
{ name: 'C', x: 16, y: 42, functions: [], signals: [], description: 'Cathode' },
22+
{ name: 'A', x: 24, y: 42, signals: [], description: 'Anode' },
23+
{ name: 'C', x: 16, y: 42, signals: [], description: 'Cathode' },
2424
];
2525

2626
static get styles() {

src/pin.ts

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,31 @@
1-
export type PinFunction = 'power' | 'i2c' | 'spi' | 'gpio' | 'pwm' | 'analog' | 'dac' | 'usart';
1+
export type PinSignalInfo =
2+
| {
3+
type: 'i2c';
4+
signal: 'SDA' | 'SCL';
5+
bus?: number;
6+
}
7+
| {
8+
type: 'spi';
9+
signal: 'SCK' | 'MOSI' | 'MISO' | 'SS';
10+
bus?: number;
11+
}
12+
| {
13+
type: 'usart';
14+
signal: 'RX' | 'TX';
15+
bus?: number;
16+
}
17+
| {
18+
type: 'power';
19+
signal: 'GND' | 'VCC';
20+
voltage?: number;
21+
}
22+
| {
23+
type: 'pwm';
24+
}
25+
| {
26+
type: 'analog';
27+
channel?: number;
28+
};
229

330
export interface ElementPin {
431
/**
@@ -14,18 +41,14 @@ export interface ElementPin {
1441
/** The y-coordinate of the pin, relative to the element's origin */
1542
y: number;
1643

17-
/** The functions of this pin. Leave empty for generic pins without a designated function. **/
18-
functions: PinFunction[];
19-
20-
/**
21-
* List of signals carried by this pin. This is useful for pins such as I²C or SPI pins, where there are designated
22-
* 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
23-
* protocol signals.
24-
*/
25-
signals: string[];
44+
/** The signals for this pin. Leave empty for generic pins without a designated signals. **/
45+
signals: PinSignalInfo[];
2646

2747
/**
2848
* Optional pin description
2949
*/
3050
description?: string;
3151
}
52+
53+
/** Helper function for creating analog PinSignalInfo objects */
54+
export const analog = (channel: number) => ({ type: 'analog', channel } as PinSignalInfo);

0 commit comments

Comments
 (0)