Here’s the answer I posted in the micro:bit topic (I think the question was added to an existing thread on your behalf). I’m posting my reply here too. I’m also adding just a few details that weren’t covered there:
I haven’t done this sort of thing, but it looks like this guide is helpful: https://www.hackster.io/wallarug/makecode-creating-custom-boards-92d933.
I think the
config.ts is a map of the symbolic pin names from the simulator to the actual hardware pin names.
I’m using an example from https://github.com/microsoft/pxt-maker/blob/master/libs/adafruit-trinket-m. Here’s an example of how I think it fits together…There are several symbols that are used and the are in multiple files.
A2 , and
SDA are all symbols that are used when programming (
D0 is digital in/out 0.
A2 is Analog in 2, etc.). Often a pin can do multiple functions — in this case a single pin does all three of these things, but is usually only used for one at a time. If I’m doing digital work, I’ll think of it as
D0 . If I’m doing analog work, I’d think of it as
- In some places it’s important to be aware that this one thing serves all three purposes, so the name
A2_D0_SDA is used too.
- The actual pin on the hardware isn’t named with any of these. It was selected by the people who made the processor (who didn’t know how the processor would be used and didn’t use names like
D0 ). The hardware uses a name like
The project’s pxt.json indicates it uses the
samd processor, so that’s where the
DAL part will come from. The dal.d.ts for the
PA08 = 8 .
So, the story:
- Someone decided to make a board. They selected a
samd processor and figured out which pins would be used for which functions (this is also related to what the particular processor can do). They may have identified that they’ll use “Pin 8” of “Port A” as a
A2 , and
samd module already existed and had a variety of names defined to make it easy for basic hardware code to work with Port A Pin 8 via
PA08 , but it doesn’t know that it’ll be used as
D0 on this specific board.
- The board designer created a schematic and then a picture of what the board will look like for the simulator. That picture, boardhd.svg, includes a “label” on the place where the pin will connect (it’s invisible data in the .svg file). The person who made the picture picked a really descriptive name that explains all the pin can do:
A2_D0_SDA . That’s a bit clunky for programmers who only think about one use at a time, like
- The boardhd.svg was uploaded to the board designer, which creates initial versions of config.ts and board.json.
- board.json and boardhd.svg are all about the simulator. board.json does two things: 1) It indicates the x,y coordinates for where
A2_D0_SDA is in the SVG (so wires in the simulator will go to the right place in the drawing) and 2) Gives simpler, additional names for
A2_D0_SDA , like
D0 , ‘A2’, and
SDA . (Ex:
"D0": "A2_D0_SDA", ).
- config.ts is about the actual hardware. It explains how the names like
D0 correspond to a real pin on the processor. There wasn’t enough detail to fill in hardware details in config.ts, so it’ll initially have incomplete parts, like
export const PIN_D0 = DAL.?; . The
? needs to be filled in with the name of the actual hardware pin, so it’d need to be changed to:
export const PIN_D0 = DAL.PA08; (Again, this is based on the initial choices when the board was designed…The designer decided to use Port A’s Pin 8 for the concept of
D0 on their board)
A lot of that’s speculation…If anyone has any confirmation or correction it’d be appreciated.
- DAL is an acronym for Device Abstraction Layer. I’m this is because the higher layer things in MakeCode are “abstract” and apply to lots of different devices. This is the layer that translates them to bare metal.
- Maker supports a variety of cores: nRF52, samd, samd51, and stm32 See: https://github.com/microsoft/pxt-maker/tree/master/libs . There’s a
core--???? directory for each processor that includes a
dal.d.ts with the mapping for the
DAL object for that processor.