Closed pelikhan closed 12 months ago
Let’s chat about unifying how we define boards. It’s a mix of board.json or this kind of code oriented approach.
code looks better but the json does have some nice checks too.
From: Michał Moskal @.> Sent: Friday, June 23, 2023 1:44:44 PM To: microsoft/devicescript @.> Cc: Peli de Halleux @.>; Author @.> Subject: Re: [microsoft/devicescript] Define shield in code and not .json (Issue #474)
This seems to be supported. Here's an example:
import * as ds from @./core" import { ST7735Driver } from @./drivers" import { Image } from @./graphics" import { configureHardware, startBuzzer, startGamepad, startRelay, } from @./servers" import { spi } from @./spi" import { pins as pins0 } from @./pico"
/**
@devsWhenUsed */ export class ArcadeRP2040 { constructor() { configureHardware({ log: { pinTX: pins0.P20, }, jacdac: { pin: pins0.P11, }, }) }
startGamepad() { return startGamepad({ activeHigh: true, pinA: pins0.P2, pinB: pins0.P3, pinDown: pins0.P12, pinLeft: pins0.P13, pinMenu: pins0.P16, pinRight: pins0.P14, pinUp: pins0.P15, }) }
startBuzzer(): ds.Buzzer { return startBuzzer({ pin: pins0.P8, name: "speaker" }) }
startVibrationMotor(): ds.Relay { return startRelay({ pin: pins0.P4 }) }
async startDisplay() { spi.configure({ mosi: pins0.P7, sck: pins0.P6, hz: 8_000_000, })
pins0.P0.setMode(ds.GPIOMode.OutputHigh)
const d = new ST7735Driver(Image.alloc(160, 128, 4), {
dc: pins0.P9,
cs: pins0.P5,
reset: pins0.P10,
frmctr1: 0x0e_14_ff,
flip: true,
spi: spi,
})
await d.init()
return d
} }
interface BoardPins { /**
@devsGPIO 18 */ P18: ds.IOPin
/**
@devsGPIO 19 */ P19: ds.IOPin
/**
@devsGPIO 21 */ P21: ds.IOPin
/**
@devsGPIO 17 */ GP1: ds.IOPin
/**
@devsGPIO 26 */ ADC1: ds.AnalogInPin & ds.IOPin
/**
— Reply to this email directly, view it on GitHubhttps://github.com/microsoft/devicescript/issues/474#issuecomment-1604932501, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AA73QKPFVLXQZUK6I4I7ABDXMX53ZANCNFSM6AAAAAAZBEFMZU. You are receiving this because you authored the thread.Message ID: @.***>
in many shield cases, the MCU can be different (e.g. pico vs pico-w) so we would have to have a different approach to define pins statically.
It seems that this feature would require to be able to lookup pins by name in the static configuration of servers.
This seems to be supported. Here's an example: