@typecad/mcu-esp32c3 0.1.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +42 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +193 -0
- package/dist/peripherals.d.ts +58 -0
- package/dist/peripherals.js +69 -0
- package/dist/pins.d.ts +38 -0
- package/dist/pins.js +52 -0
- package/package.json +60 -0
- package/src/index.ts +226 -0
- package/src/peripherals.ts +99 -0
- package/src/pins.ts +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 typecad0
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# @typecad/mcu-esp32c3
|
|
2
|
+
|
|
3
|
+
MCU definition package for the **ESP32-C3** (single-core 32-bit RISC-V @ 160 MHz, Wi-Fi 4 + BLE 5). Provides datasheet-level pin definitions, hardware peripheral descriptions, and HAL instances used by the TypeCAD transpiler and board packages.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
MCU packages are the silicon layer — they define what pins exist on the chip and what peripherals are built into the silicon, independent of any board or framework. Board packages (e.g. [`@typecad/board-esp32c3`](../board-esp32c3)) import from here and add board-specific aliases.
|
|
8
|
+
|
|
9
|
+
## What's inside
|
|
10
|
+
|
|
11
|
+
- **`src/pins.ts`** — One `Pin.fromPort()` export per GPIO: `GPIO0`–`GPIO21`
|
|
12
|
+
- **`src/peripherals.ts`** — Hardware peripheral descriptions (I2C, SPI, UART, ADC, timers, PWM) and auto-generated HAL instances (`I2C0`, `SPI0`, `UART0`, `ADC`)
|
|
13
|
+
- **`src/mcu.ts`** — `MCU_PERIPHERALS` manifest consumed by board packages
|
|
14
|
+
|
|
15
|
+
## ESP32-C3 peripheral summary
|
|
16
|
+
|
|
17
|
+
| Peripheral | Count | Notes |
|
|
18
|
+
|---|---|---|
|
|
19
|
+
| **UART** | 2 | USART0–1 |
|
|
20
|
+
| **I2C** | 1 | I2C0 (GPIO matrix) |
|
|
21
|
+
| **SPI** | 3 | SPI0–2 (SPI0/1 for flash, SPI2 general-purpose) |
|
|
22
|
+
| **ADC** | 2 | ADC1 (5 channels), ADC2 (1 channel), 12-bit |
|
|
23
|
+
| **Timers** | 4 | 52-bit general-purpose timers |
|
|
24
|
+
| **PWM (LEDC)** | 6 channels | 4 low-speed + 2 high-speed |
|
|
25
|
+
|
|
26
|
+
## How board packages use this
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
// In @typecad/board-esp32c3
|
|
30
|
+
export * from '@typecad/mcu-esp32c3'; // silicon pins + peripherals
|
|
31
|
+
export * from '@typecad/hal'; // HAL utilities (delay, Pin, etc.)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Related packages
|
|
35
|
+
|
|
36
|
+
- [`@typecad/board-esp32c3`](../board-esp32c3) — board package using this MCU
|
|
37
|
+
- [`@typecad/hal`](../hal) — hardware abstraction layer
|
|
38
|
+
- [`@typecad/mcu-atmega328p`](../mcu-atmega328p) — example of a fully-documented MCU package
|
|
39
|
+
|
|
40
|
+
## License
|
|
41
|
+
|
|
42
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { MCUDefinition } from '@typecad/cuttlefish/api/schema';
|
|
2
|
+
export declare const ESP32C3: MCUDefinition;
|
|
3
|
+
export default ESP32C3;
|
|
4
|
+
export * from './pins.js';
|
|
5
|
+
export * from './peripherals.js';
|
|
6
|
+
/**
|
|
7
|
+
* Structured manifest consumed by the TypeCAD CLI for contract-based
|
|
8
|
+
* board generation. Provides pin names and peripheral instance names
|
|
9
|
+
* without requiring the CLI to text-scrape compiled output.
|
|
10
|
+
*/
|
|
11
|
+
export declare const TypeCADManifest: {
|
|
12
|
+
/** All MCU port-level pin names (e.g. 'GPIO0', 'GPIO1'). */
|
|
13
|
+
readonly pinNames: readonly ["GPIO0", "GPIO1", "GPIO2", "GPIO3", "GPIO4", "GPIO5", "GPIO6", "GPIO7", "GPIO8", "GPIO9", "GPIO10", "GPIO12", "GPIO13", "GPIO14", "GPIO15", "GPIO16", "GPIO17", "GPIO18", "GPIO19", "GPIO20", "GPIO21"];
|
|
14
|
+
/** All HAL peripheral instance names exported from this package. */
|
|
15
|
+
readonly peripheralNames: readonly ["I2C0", "SPI0", "UART0", "UART1"];
|
|
16
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// @typecad/mcu-esp32c3 — MCU definition manifest
|
|
3
|
+
//
|
|
4
|
+
// ESP32-C3 is a single-core RISC-V (RV32IMC) @ 160 MHz with Wi-Fi 4 + BLE 5
|
|
5
|
+
// (long range) and native USB Serial/JTAG. It has 22 GPIO (0-10, 12-21);
|
|
6
|
+
// GPIO 11 is consumed by internal flash Vpp and is not broken out. All GPIOs
|
|
7
|
+
// are bidirectional. No DAC. No PSRAM support.
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
import { MCU_PERIPHERALS } from './peripherals.js';
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
// Default capability flags for ESP32-C3
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
const NO = false;
|
|
14
|
+
const YES = true;
|
|
15
|
+
/** Full GPIO: digital I/O + pull-up + pull-down + PWM + interrupt. */
|
|
16
|
+
const FULL_GPIO = {
|
|
17
|
+
digitalInput: YES, digitalOutput: YES,
|
|
18
|
+
analogInput: NO, analogOutput: NO,
|
|
19
|
+
pwm: YES, interrupt: YES,
|
|
20
|
+
pullUp: YES, pullDown: YES,
|
|
21
|
+
touch: NO, openDrain: NO,
|
|
22
|
+
};
|
|
23
|
+
/** Full GPIO + analog input (ADC). */
|
|
24
|
+
const FULL_GPIO_ANALOG = { ...FULL_GPIO, analogInput: YES };
|
|
25
|
+
/** Full GPIO + analog input + touch. */
|
|
26
|
+
const FULL_GPIO_ANALOG_TOUCH = { ...FULL_GPIO, analogInput: YES, touch: YES };
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
// Helper: build ADC/touch peripheral-function references.
|
|
29
|
+
//
|
|
30
|
+
// ADC1 channels: GPIO0..GPIO4 -> ch0..ch4 (always usable).
|
|
31
|
+
// ADC2 channels: GPIO5 -> ch0 (NOT usable while Wi-Fi is on).
|
|
32
|
+
// Touch channels: GPIO0..GPIO5 -> T0..T5.
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
function adc(n, ch) {
|
|
35
|
+
return { type: 'adc', instance: n, role: `ch${ch}` };
|
|
36
|
+
}
|
|
37
|
+
function touch(ch) {
|
|
38
|
+
return { type: 'touch', instance: 0, role: `touch${ch}` };
|
|
39
|
+
}
|
|
40
|
+
// ---------------------------------------------------------------------------
|
|
41
|
+
// MCU definition
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
export const ESP32C3 = {
|
|
44
|
+
id: 'esp32-c3',
|
|
45
|
+
name: 'ESP32-C3',
|
|
46
|
+
architecture: 'esp32c3',
|
|
47
|
+
memory: {
|
|
48
|
+
flash: 384 * 1024, // usable app flash; remainder reserved by bootloader/OTADATA
|
|
49
|
+
sram: 400 * 1024, // 400 KB
|
|
50
|
+
eeprom: 0,
|
|
51
|
+
rtcMemory: 16 * 1024, // 16 KB RTC slow memory
|
|
52
|
+
},
|
|
53
|
+
pins: {
|
|
54
|
+
all: [
|
|
55
|
+
// ---- ADC1 + touch pins (GPIO0-GPIO4) ---------------------------------
|
|
56
|
+
{ number: 0, gpio: 0, name: 'GPIO0', capabilities: FULL_GPIO_ANALOG_TOUCH,
|
|
57
|
+
functions: [adc(1, 0), touch(0)],
|
|
58
|
+
alternateFunctions: ['ADC1_CH0', 'Touch0'] },
|
|
59
|
+
{ number: 1, gpio: 1, name: 'GPIO1', capabilities: FULL_GPIO_ANALOG_TOUCH,
|
|
60
|
+
functions: [adc(1, 1), touch(1)],
|
|
61
|
+
alternateFunctions: ['ADC1_CH1', 'Touch1'] },
|
|
62
|
+
{ number: 2, gpio: 2, name: 'GPIO2', capabilities: FULL_GPIO_ANALOG_TOUCH,
|
|
63
|
+
functions: [adc(1, 2), touch(2)],
|
|
64
|
+
alternateFunctions: ['ADC1_CH2', 'Touch2'],
|
|
65
|
+
warnings: ['GPIO2 is a strapping pin — boot mode select at boot'],
|
|
66
|
+
unsafe: true, notes: 'Boot strapping pin' },
|
|
67
|
+
{ number: 3, gpio: 3, name: 'GPIO3', capabilities: FULL_GPIO_ANALOG_TOUCH,
|
|
68
|
+
functions: [adc(1, 3), touch(3)],
|
|
69
|
+
alternateFunctions: ['ADC1_CH3', 'Touch3'] },
|
|
70
|
+
{ number: 4, gpio: 4, name: 'GPIO4', capabilities: FULL_GPIO_ANALOG_TOUCH,
|
|
71
|
+
functions: [adc(1, 4), touch(4), { type: 'spi', instance: 0, role: 'sck' }],
|
|
72
|
+
alternateFunctions: ['ADC1_CH4', 'Touch4', 'SPI0 SCK'] },
|
|
73
|
+
// ---- ADC2 pin (GPIO5) — Wi-Fi conflicted ------------------------------
|
|
74
|
+
{ number: 5, gpio: 5, name: 'GPIO5', capabilities: FULL_GPIO_ANALOG_TOUCH,
|
|
75
|
+
functions: [adc(2, 0), touch(5), { type: 'spi', instance: 0, role: 'miso' }],
|
|
76
|
+
alternateFunctions: ['ADC2_CH0', 'Touch5', 'SPI0 MISO'],
|
|
77
|
+
warnings: ['GPIO5 is ADC2 — ADC2 is unusable while Wi-Fi is enabled'] },
|
|
78
|
+
{ number: 6, gpio: 6, name: 'GPIO6', capabilities: FULL_GPIO,
|
|
79
|
+
functions: [{ type: 'spi', instance: 0, role: 'mosi' }],
|
|
80
|
+
alternateFunctions: ['SPI0 MOSI'] },
|
|
81
|
+
{ number: 7, gpio: 7, name: 'GPIO7', capabilities: FULL_GPIO,
|
|
82
|
+
functions: [{ type: 'spi', instance: 0, role: 'cs' }],
|
|
83
|
+
alternateFunctions: ['SPI0 CS'] },
|
|
84
|
+
{ number: 8, gpio: 8, name: 'GPIO8', capabilities: FULL_GPIO,
|
|
85
|
+
functions: [{ type: 'i2c', instance: 0, role: 'sda' }],
|
|
86
|
+
alternateFunctions: ['I2C0 SDA'],
|
|
87
|
+
warnings: ['GPIO8 is a strapping pin — controls VDD_SPI voltage at boot'],
|
|
88
|
+
unsafe: true, notes: 'Boot strapping pin' },
|
|
89
|
+
{ number: 9, gpio: 9, name: 'GPIO9', capabilities: FULL_GPIO,
|
|
90
|
+
functions: [{ type: 'i2c', instance: 0, role: 'scl' }],
|
|
91
|
+
alternateFunctions: ['I2C0 SCL'],
|
|
92
|
+
warnings: ['GPIO9 is a strapping pin — must be HIGH at boot (reset source)'],
|
|
93
|
+
unsafe: true, notes: 'Boot strapping pin' },
|
|
94
|
+
{ number: 10, gpio: 10, name: 'GPIO10', capabilities: FULL_GPIO,
|
|
95
|
+
alternateFunctions: ['FSPICS0'] },
|
|
96
|
+
// ---- GPIO 11 — internal flash Vpp, not broken out on the C3 ----------
|
|
97
|
+
{ number: 12, gpio: 12, name: 'GPIO12', capabilities: FULL_GPIO,
|
|
98
|
+
functions: [{ type: 'spi', instance: 1, role: 'sck' }],
|
|
99
|
+
alternateFunctions: ['FSPICLK'] },
|
|
100
|
+
{ number: 13, gpio: 13, name: 'GPIO13', capabilities: FULL_GPIO,
|
|
101
|
+
functions: [{ type: 'spi', instance: 1, role: 'mosi' }],
|
|
102
|
+
alternateFunctions: ['FSPID'] },
|
|
103
|
+
{ number: 14, gpio: 14, name: 'GPIO14', capabilities: FULL_GPIO,
|
|
104
|
+
functions: [{ type: 'spi', instance: 1, role: 'miso' }],
|
|
105
|
+
alternateFunctions: ['FSPIQ'] },
|
|
106
|
+
{ number: 15, gpio: 15, name: 'GPIO15', capabilities: FULL_GPIO,
|
|
107
|
+
functions: [{ type: 'spi', instance: 1, role: 'cs' }],
|
|
108
|
+
alternateFunctions: ['FSPICS1'] },
|
|
109
|
+
{ number: 16, gpio: 16, name: 'GPIO16', capabilities: FULL_GPIO,
|
|
110
|
+
alternateFunctions: [] },
|
|
111
|
+
{ number: 17, gpio: 17, name: 'GPIO17', capabilities: FULL_GPIO,
|
|
112
|
+
alternateFunctions: [] },
|
|
113
|
+
// ---- USB Serial/JTAG pins (unsafe) -----------------------------------
|
|
114
|
+
{ number: 18, gpio: 18, name: 'GPIO18', capabilities: FULL_GPIO,
|
|
115
|
+
functions: [{ type: 'usb', instance: 0, role: 'dm' }],
|
|
116
|
+
alternateFunctions: ['USB D-'],
|
|
117
|
+
warnings: ['GPIO18 is USB D- — using it as GPIO disables native USB Serial/JTAG'],
|
|
118
|
+
unsafe: true, notes: 'USB D- pin' },
|
|
119
|
+
{ number: 19, gpio: 19, name: 'GPIO19', capabilities: FULL_GPIO,
|
|
120
|
+
functions: [{ type: 'usb', instance: 0, role: 'dp' }],
|
|
121
|
+
alternateFunctions: ['USB D+'],
|
|
122
|
+
warnings: ['GPIO19 is USB D+ — using it as GPIO disables native USB Serial/JTAG'],
|
|
123
|
+
unsafe: true, notes: 'USB D+ pin' },
|
|
124
|
+
// ---- UART0 default pins ----------------------------------------------
|
|
125
|
+
{ number: 20, gpio: 20, name: 'GPIO20', capabilities: FULL_GPIO,
|
|
126
|
+
functions: [{ type: 'uart', instance: 0, role: 'rx' }],
|
|
127
|
+
alternateFunctions: ['UART0 RX'],
|
|
128
|
+
warnings: ['Using GPIO20 as GPIO will interfere with UART0 receive'] },
|
|
129
|
+
{ number: 21, gpio: 21, name: 'GPIO21', capabilities: FULL_GPIO,
|
|
130
|
+
functions: [{ type: 'uart', instance: 0, role: 'tx' }],
|
|
131
|
+
alternateFunctions: ['UART0 TX'],
|
|
132
|
+
warnings: ['Using GPIO21 as GPIO will interfere with UART0 transmit'] },
|
|
133
|
+
],
|
|
134
|
+
digital: [
|
|
135
|
+
'GPIO0', 'GPIO1', 'GPIO2', 'GPIO3', 'GPIO4', 'GPIO5', 'GPIO6', 'GPIO7',
|
|
136
|
+
'GPIO8', 'GPIO9', 'GPIO10',
|
|
137
|
+
'GPIO12', 'GPIO13', 'GPIO14', 'GPIO15', 'GPIO16', 'GPIO17',
|
|
138
|
+
'GPIO18', 'GPIO19', 'GPIO20', 'GPIO21',
|
|
139
|
+
],
|
|
140
|
+
analog: [
|
|
141
|
+
'GPIO0', 'GPIO1', 'GPIO2', 'GPIO3', 'GPIO4', // ADC1
|
|
142
|
+
'GPIO5', // ADC2
|
|
143
|
+
],
|
|
144
|
+
pwm: [
|
|
145
|
+
'GPIO0', 'GPIO1', 'GPIO2', 'GPIO3', 'GPIO4', 'GPIO5', 'GPIO6', 'GPIO7',
|
|
146
|
+
'GPIO8', 'GPIO9', 'GPIO10',
|
|
147
|
+
'GPIO12', 'GPIO13', 'GPIO14', 'GPIO15', 'GPIO16', 'GPIO17',
|
|
148
|
+
'GPIO18', 'GPIO19', 'GPIO20', 'GPIO21',
|
|
149
|
+
],
|
|
150
|
+
unsafe: ['GPIO2', 'GPIO8', 'GPIO9', 'GPIO18', 'GPIO19'],
|
|
151
|
+
i2c: { 0: { sda: 'GPIO8', scl: 'GPIO9' } },
|
|
152
|
+
spi: {
|
|
153
|
+
0: { mosi: 'GPIO6', miso: 'GPIO5', sck: 'GPIO4', cs: 'GPIO7' }, // GPSPI2 / VSPI
|
|
154
|
+
},
|
|
155
|
+
uart: {
|
|
156
|
+
0: { tx: 'GPIO21', rx: 'GPIO20' },
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
// ----- Peripherals -------------------------------------------------------
|
|
160
|
+
peripherals: MCU_PERIPHERALS,
|
|
161
|
+
features: {
|
|
162
|
+
multicore: false,
|
|
163
|
+
coreCount: 1,
|
|
164
|
+
deepSleep: true,
|
|
165
|
+
watchdog: true,
|
|
166
|
+
externalInterrupts: true,
|
|
167
|
+
hardwareRng: true,
|
|
168
|
+
fpu: false,
|
|
169
|
+
},
|
|
170
|
+
build: {
|
|
171
|
+
extraFlags: [],
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
export default ESP32C3;
|
|
175
|
+
// Re-exports
|
|
176
|
+
export * from './pins.js';
|
|
177
|
+
export * from './peripherals.js';
|
|
178
|
+
/**
|
|
179
|
+
* Structured manifest consumed by the TypeCAD CLI for contract-based
|
|
180
|
+
* board generation. Provides pin names and peripheral instance names
|
|
181
|
+
* without requiring the CLI to text-scrape compiled output.
|
|
182
|
+
*/
|
|
183
|
+
export const TypeCADManifest = {
|
|
184
|
+
/** All MCU port-level pin names (e.g. 'GPIO0', 'GPIO1'). */
|
|
185
|
+
pinNames: [
|
|
186
|
+
'GPIO0', 'GPIO1', 'GPIO2', 'GPIO3', 'GPIO4', 'GPIO5', 'GPIO6', 'GPIO7',
|
|
187
|
+
'GPIO8', 'GPIO9', 'GPIO10',
|
|
188
|
+
'GPIO12', 'GPIO13', 'GPIO14', 'GPIO15', 'GPIO16', 'GPIO17',
|
|
189
|
+
'GPIO18', 'GPIO19', 'GPIO20', 'GPIO21',
|
|
190
|
+
],
|
|
191
|
+
/** All HAL peripheral instance names exported from this package. */
|
|
192
|
+
peripheralNames: ['I2C0', 'SPI0', 'UART0', 'UART1'],
|
|
193
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { PeripheralInstance, ADCDefinition, PWMDefinition, TimerDefinition } from '@typecad/cuttlefish/api/schema';
|
|
2
|
+
import { I2CBus, SPIBus, SerialPort } from '@typecad/hal';
|
|
3
|
+
export declare const I2C_INSTANCES: readonly PeripheralInstance[];
|
|
4
|
+
export declare const SPI_INSTANCES: readonly PeripheralInstance[];
|
|
5
|
+
export declare const UART_INSTANCES: readonly PeripheralInstance[];
|
|
6
|
+
export declare const ADC_INSTANCES: readonly ADCDefinition[];
|
|
7
|
+
export declare const PWM_CAPABILITIES: PWMDefinition;
|
|
8
|
+
export declare const TOUCH_CAPABILITIES: {
|
|
9
|
+
channels: number;
|
|
10
|
+
pins: string[];
|
|
11
|
+
};
|
|
12
|
+
export declare const TIMER_INSTANCES: readonly TimerDefinition[];
|
|
13
|
+
export declare const WIFI_CAPABILITIES: {
|
|
14
|
+
readonly type: "wifi";
|
|
15
|
+
readonly supportsStation: true;
|
|
16
|
+
readonly supportsAp: true;
|
|
17
|
+
};
|
|
18
|
+
export declare const BLUETOOTH_CAPABILITIES: {
|
|
19
|
+
readonly type: "ble";
|
|
20
|
+
readonly version: "5.0";
|
|
21
|
+
};
|
|
22
|
+
export declare const USB_CAPABILITIES: {
|
|
23
|
+
readonly type: "otg";
|
|
24
|
+
readonly vid: "0x303A";
|
|
25
|
+
readonly pid: "0x0001";
|
|
26
|
+
};
|
|
27
|
+
export declare const MCU_PERIPHERALS: {
|
|
28
|
+
readonly i2c: readonly PeripheralInstance[];
|
|
29
|
+
readonly spi: readonly PeripheralInstance[];
|
|
30
|
+
readonly uart: readonly PeripheralInstance[];
|
|
31
|
+
readonly adc: readonly ADCDefinition[];
|
|
32
|
+
readonly pwm: PWMDefinition;
|
|
33
|
+
readonly touch: {
|
|
34
|
+
channels: number;
|
|
35
|
+
pins: string[];
|
|
36
|
+
};
|
|
37
|
+
readonly timers: readonly TimerDefinition[];
|
|
38
|
+
readonly wifi: {
|
|
39
|
+
readonly type: "wifi";
|
|
40
|
+
readonly supportsStation: true;
|
|
41
|
+
readonly supportsAp: true;
|
|
42
|
+
};
|
|
43
|
+
readonly bluetooth: {
|
|
44
|
+
readonly type: "ble";
|
|
45
|
+
readonly version: "5.0";
|
|
46
|
+
};
|
|
47
|
+
readonly usb: {
|
|
48
|
+
readonly type: "otg";
|
|
49
|
+
readonly vid: "0x303A";
|
|
50
|
+
readonly pid: "0x0001";
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
/** I2C bus instances */
|
|
54
|
+
export declare const I2C0: I2CBus;
|
|
55
|
+
/** SPI bus instances */
|
|
56
|
+
export declare const SPI0: SPIBus;
|
|
57
|
+
/** UART/Serial instances */
|
|
58
|
+
export declare const UART0: SerialPort, UART1: SerialPort;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// @typecad/mcu-esp32c3 — Hardware peripheral descriptions
|
|
3
|
+
//
|
|
4
|
+
// ESP32-C3 peripherals: 1× I2C, 1× SPI (GPSPI2), 2× UART, 2× ADC (12-bit),
|
|
5
|
+
// 6× capacitive-touch, 4× general-purpose timers, Wi-Fi 4, BLE 5 (long range),
|
|
6
|
+
// native USB Serial/JTAG (CDC). No DAC.
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
import { I2CBus, SPIBus, SerialPort, i2cName, spiName, serialName, createHALInstances, } from '@typecad/hal';
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
// Peripheral definitions
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
export const I2C_INSTANCES = [
|
|
13
|
+
{ instance: 0, defaultPins: { sda: 'GPIO8', scl: 'GPIO9' } },
|
|
14
|
+
];
|
|
15
|
+
export const SPI_INSTANCES = [
|
|
16
|
+
{ instance: 0, defaultPins: { mosi: 'GPIO6', miso: 'GPIO5', sck: 'GPIO4', cs: 'GPIO7' } }, // GPSPI2
|
|
17
|
+
];
|
|
18
|
+
export const UART_INSTANCES = [
|
|
19
|
+
{ instance: 0, defaultPins: { tx: 'GPIO21', rx: 'GPIO20' } },
|
|
20
|
+
{ instance: 1, defaultPins: { tx: 'GPIO21', rx: 'GPIO20' } },
|
|
21
|
+
];
|
|
22
|
+
export const ADC_INSTANCES = [
|
|
23
|
+
{ instance: 0, channels: 5, resolution: 12, referenceVoltage: 3.3, maxValue: 4095,
|
|
24
|
+
referenceVoltages: { DEFAULT: 3.3, INTERNAL: 1.1 } }, // ADC1 — usable with Wi-Fi active
|
|
25
|
+
{ instance: 1, channels: 1, resolution: 12, referenceVoltage: 3.3, maxValue: 4095,
|
|
26
|
+
referenceVoltages: { DEFAULT: 3.3, INTERNAL: 1.1 } }, // ADC2 — NOT usable with Wi-Fi active
|
|
27
|
+
];
|
|
28
|
+
export const PWM_CAPABILITIES = {
|
|
29
|
+
channels: 6,
|
|
30
|
+
resolution: 14,
|
|
31
|
+
maxFrequency: 40_000_000,
|
|
32
|
+
};
|
|
33
|
+
export const TOUCH_CAPABILITIES = {
|
|
34
|
+
channels: 6,
|
|
35
|
+
pins: ['GPIO0', 'GPIO1', 'GPIO2', 'GPIO3', 'GPIO4', 'GPIO5'],
|
|
36
|
+
};
|
|
37
|
+
export const TIMER_INSTANCES = [
|
|
38
|
+
{ instance: 0, type: 'general', bits: 64, features: ['interrupt'] },
|
|
39
|
+
{ instance: 1, type: 'general', bits: 64, features: ['interrupt'] },
|
|
40
|
+
{ instance: 2, type: 'general', bits: 64, features: ['interrupt'] },
|
|
41
|
+
{ instance: 3, type: 'general', bits: 64, features: ['interrupt'] },
|
|
42
|
+
];
|
|
43
|
+
export const WIFI_CAPABILITIES = { type: 'wifi', supportsStation: true, supportsAp: true };
|
|
44
|
+
export const BLUETOOTH_CAPABILITIES = { type: 'ble', version: '5.0' };
|
|
45
|
+
export const USB_CAPABILITIES = { type: 'otg', vid: '0x303A', pid: '0x0001' };
|
|
46
|
+
// ---------------------------------------------------------------------------
|
|
47
|
+
// Aggregate MCU peripheral description
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
export const MCU_PERIPHERALS = {
|
|
50
|
+
i2c: [...I2C_INSTANCES],
|
|
51
|
+
spi: [...SPI_INSTANCES],
|
|
52
|
+
uart: [...UART_INSTANCES],
|
|
53
|
+
adc: [...ADC_INSTANCES],
|
|
54
|
+
pwm: PWM_CAPABILITIES,
|
|
55
|
+
touch: TOUCH_CAPABILITIES,
|
|
56
|
+
timers: [...TIMER_INSTANCES],
|
|
57
|
+
wifi: WIFI_CAPABILITIES,
|
|
58
|
+
bluetooth: BLUETOOTH_CAPABILITIES,
|
|
59
|
+
usb: USB_CAPABILITIES,
|
|
60
|
+
};
|
|
61
|
+
// ---------------------------------------------------------------------------
|
|
62
|
+
// HAL object instances — auto-generated from peripheral definitions
|
|
63
|
+
// ---------------------------------------------------------------------------
|
|
64
|
+
/** I2C bus instances */
|
|
65
|
+
export const [I2C0] = createHALInstances(I2C_INSTANCES, i => new I2CBus(i2cName(i)));
|
|
66
|
+
/** SPI bus instances */
|
|
67
|
+
export const [SPI0] = createHALInstances(SPI_INSTANCES, i => new SPIBus(spiName(i)));
|
|
68
|
+
/** UART/Serial instances */
|
|
69
|
+
export const [UART0, UART1] = createHALInstances(UART_INSTANCES, i => new SerialPort(serialName(i)));
|
package/dist/pins.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Pin } from '@typecad/hal';
|
|
2
|
+
export declare const GPIO0: Pin;
|
|
3
|
+
export declare const GPIO1: Pin;
|
|
4
|
+
export declare const GPIO2: Pin;
|
|
5
|
+
export declare const GPIO3: Pin;
|
|
6
|
+
export declare const GPIO4: Pin;
|
|
7
|
+
export declare const GPIO5: Pin;
|
|
8
|
+
export declare const GPIO6: Pin;
|
|
9
|
+
export declare const GPIO7: Pin;
|
|
10
|
+
export declare const GPIO8: Pin;
|
|
11
|
+
export declare const GPIO9: Pin;
|
|
12
|
+
export declare const GPIO10: Pin;
|
|
13
|
+
export declare const GPIO12: Pin;
|
|
14
|
+
export declare const GPIO13: Pin;
|
|
15
|
+
export declare const GPIO14: Pin;
|
|
16
|
+
export declare const GPIO15: Pin;
|
|
17
|
+
export declare const GPIO16: Pin;
|
|
18
|
+
export declare const GPIO17: Pin;
|
|
19
|
+
export declare const GPIO18: Pin;
|
|
20
|
+
export declare const GPIO19: Pin;
|
|
21
|
+
export declare const GPIO20: Pin;
|
|
22
|
+
export declare const GPIO21: Pin;
|
|
23
|
+
/** I2C0 data line (GPIO8). */
|
|
24
|
+
export declare const SDA: Pin;
|
|
25
|
+
/** I2C0 clock line (GPIO9). */
|
|
26
|
+
export declare const SCL: Pin;
|
|
27
|
+
/** SPI0 MOSI (GPIO6). */
|
|
28
|
+
export declare const MOSI: Pin;
|
|
29
|
+
/** SPI0 MISO (GPIO5). */
|
|
30
|
+
export declare const MISO: Pin;
|
|
31
|
+
/** SPI0 clock (GPIO4). */
|
|
32
|
+
export declare const SCK: Pin;
|
|
33
|
+
/** SPI0 slave select (GPIO7). */
|
|
34
|
+
export declare const SS: Pin;
|
|
35
|
+
/** UART0 transmit (GPIO21). */
|
|
36
|
+
export declare const TX: Pin;
|
|
37
|
+
/** UART0 receive (GPIO20). */
|
|
38
|
+
export declare const RX: Pin;
|
package/dist/pins.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// @typecad/mcu-esp32c3 — Datasheet pin definitions
|
|
3
|
+
//
|
|
4
|
+
// Each pin is a Pin instance from @typecad/hal. The ESP32-C3 has 22 GPIO
|
|
5
|
+
// (0-10, 12-21); GPIO 11 is consumed by internal flash Vpp and is not broken
|
|
6
|
+
// out. All GPIOs are bidirectional (no input-only pins). DAC is not present.
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
import { Pin } from '@typecad/hal';
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
// Named GPIO constants (Pin instances)
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
export const GPIO0 = new Pin(0);
|
|
13
|
+
export const GPIO1 = new Pin(1);
|
|
14
|
+
export const GPIO2 = new Pin(2);
|
|
15
|
+
export const GPIO3 = new Pin(3);
|
|
16
|
+
export const GPIO4 = new Pin(4);
|
|
17
|
+
export const GPIO5 = new Pin(5);
|
|
18
|
+
export const GPIO6 = new Pin(6);
|
|
19
|
+
export const GPIO7 = new Pin(7);
|
|
20
|
+
export const GPIO8 = new Pin(8);
|
|
21
|
+
export const GPIO9 = new Pin(9);
|
|
22
|
+
export const GPIO10 = new Pin(10);
|
|
23
|
+
// GPIO 11 — internal flash Vpp, not broken out on the C3 package.
|
|
24
|
+
export const GPIO12 = new Pin(12);
|
|
25
|
+
export const GPIO13 = new Pin(13);
|
|
26
|
+
export const GPIO14 = new Pin(14);
|
|
27
|
+
export const GPIO15 = new Pin(15);
|
|
28
|
+
export const GPIO16 = new Pin(16);
|
|
29
|
+
export const GPIO17 = new Pin(17);
|
|
30
|
+
export const GPIO18 = new Pin(18);
|
|
31
|
+
export const GPIO19 = new Pin(19);
|
|
32
|
+
export const GPIO20 = new Pin(20);
|
|
33
|
+
export const GPIO21 = new Pin(21);
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
// Convenience aliases (Silicon-level defaults — match Arduino-ESP32 core)
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
/** I2C0 data line (GPIO8). */
|
|
38
|
+
export const SDA = GPIO8;
|
|
39
|
+
/** I2C0 clock line (GPIO9). */
|
|
40
|
+
export const SCL = GPIO9;
|
|
41
|
+
/** SPI0 MOSI (GPIO6). */
|
|
42
|
+
export const MOSI = GPIO6;
|
|
43
|
+
/** SPI0 MISO (GPIO5). */
|
|
44
|
+
export const MISO = GPIO5;
|
|
45
|
+
/** SPI0 clock (GPIO4). */
|
|
46
|
+
export const SCK = GPIO4;
|
|
47
|
+
/** SPI0 slave select (GPIO7). */
|
|
48
|
+
export const SS = GPIO7;
|
|
49
|
+
/** UART0 transmit (GPIO21). */
|
|
50
|
+
export const TX = GPIO21;
|
|
51
|
+
/** UART0 receive (GPIO20). */
|
|
52
|
+
export const RX = GPIO20;
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@typecad/mcu-esp32c3",
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
|
+
"description": "TypeCAD MCU definition for ESP32-C3 — datasheet pins, peripheral capabilities, and HAL instances",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"src"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"prepublishOnly": "npm run build"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@typecad/cuttlefish": "0.1.0-alpha.1",
|
|
18
|
+
"@typecad/hal": "0.1.0-alpha.1"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/justind000/typecode.git",
|
|
27
|
+
"directory": "packages/mcu-esp32c3"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/justind000/typecode/tree/main/packages/mcu-esp32c3",
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/justind000/typecode/issues"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"arduino",
|
|
35
|
+
"cpp",
|
|
36
|
+
"cuttlefish",
|
|
37
|
+
"embedded",
|
|
38
|
+
"esp32c3",
|
|
39
|
+
"firmware",
|
|
40
|
+
"mcu",
|
|
41
|
+
"microcontroller",
|
|
42
|
+
"peripherals",
|
|
43
|
+
"pins",
|
|
44
|
+
"silicon",
|
|
45
|
+
"typecad",
|
|
46
|
+
"typescript"
|
|
47
|
+
],
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=18"
|
|
50
|
+
},
|
|
51
|
+
"author": "typecad0",
|
|
52
|
+
"sideEffects": false,
|
|
53
|
+
"exports": {
|
|
54
|
+
".": {
|
|
55
|
+
"types": "./dist/index.d.ts",
|
|
56
|
+
"default": "./dist/index.js"
|
|
57
|
+
},
|
|
58
|
+
"./package.json": "./package.json"
|
|
59
|
+
}
|
|
60
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// @typecad/mcu-esp32c3 — MCU definition manifest
|
|
3
|
+
//
|
|
4
|
+
// ESP32-C3 is a single-core RISC-V (RV32IMC) @ 160 MHz with Wi-Fi 4 + BLE 5
|
|
5
|
+
// (long range) and native USB Serial/JTAG. It has 22 GPIO (0-10, 12-21);
|
|
6
|
+
// GPIO 11 is consumed by internal flash Vpp and is not broken out. All GPIOs
|
|
7
|
+
// are bidirectional. No DAC. No PSRAM support.
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
|
|
10
|
+
import type { MCUDefinition } from '@typecad/cuttlefish/api/schema';
|
|
11
|
+
import { MCU_PERIPHERALS } from './peripherals.js';
|
|
12
|
+
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
// Default capability flags for ESP32-C3
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
const NO = false as const;
|
|
18
|
+
const YES = true as const;
|
|
19
|
+
|
|
20
|
+
/** Full GPIO: digital I/O + pull-up + pull-down + PWM + interrupt. */
|
|
21
|
+
const FULL_GPIO = {
|
|
22
|
+
digitalInput: YES, digitalOutput: YES,
|
|
23
|
+
analogInput: NO, analogOutput: NO,
|
|
24
|
+
pwm: YES, interrupt: YES,
|
|
25
|
+
pullUp: YES, pullDown: YES,
|
|
26
|
+
touch: NO, openDrain: NO,
|
|
27
|
+
} as const;
|
|
28
|
+
|
|
29
|
+
/** Full GPIO + analog input (ADC). */
|
|
30
|
+
const FULL_GPIO_ANALOG = { ...FULL_GPIO, analogInput: YES } as const;
|
|
31
|
+
|
|
32
|
+
/** Full GPIO + analog input + touch. */
|
|
33
|
+
const FULL_GPIO_ANALOG_TOUCH = { ...FULL_GPIO, analogInput: YES, touch: YES } as const;
|
|
34
|
+
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
// Helper: build ADC/touch peripheral-function references.
|
|
37
|
+
//
|
|
38
|
+
// ADC1 channels: GPIO0..GPIO4 -> ch0..ch4 (always usable).
|
|
39
|
+
// ADC2 channels: GPIO5 -> ch0 (NOT usable while Wi-Fi is on).
|
|
40
|
+
// Touch channels: GPIO0..GPIO5 -> T0..T5.
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
|
|
43
|
+
function adc(n: number, ch: number) {
|
|
44
|
+
return { type: 'adc' as const, instance: n, role: `ch${ch}` };
|
|
45
|
+
}
|
|
46
|
+
function touch(ch: number) {
|
|
47
|
+
return { type: 'touch' as const, instance: 0, role: `touch${ch}` };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
// MCU definition
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
|
|
54
|
+
export const ESP32C3: MCUDefinition = {
|
|
55
|
+
id: 'esp32-c3',
|
|
56
|
+
name: 'ESP32-C3',
|
|
57
|
+
architecture: 'esp32c3',
|
|
58
|
+
memory: {
|
|
59
|
+
flash: 384 * 1024, // usable app flash; remainder reserved by bootloader/OTADATA
|
|
60
|
+
sram: 400 * 1024, // 400 KB
|
|
61
|
+
eeprom: 0,
|
|
62
|
+
rtcMemory: 16 * 1024, // 16 KB RTC slow memory
|
|
63
|
+
},
|
|
64
|
+
pins: {
|
|
65
|
+
all: [
|
|
66
|
+
// ---- ADC1 + touch pins (GPIO0-GPIO4) ---------------------------------
|
|
67
|
+
{ number: 0, gpio: 0, name: 'GPIO0', capabilities: FULL_GPIO_ANALOG_TOUCH,
|
|
68
|
+
functions: [adc(1, 0), touch(0)],
|
|
69
|
+
alternateFunctions: ['ADC1_CH0', 'Touch0'] },
|
|
70
|
+
|
|
71
|
+
{ number: 1, gpio: 1, name: 'GPIO1', capabilities: FULL_GPIO_ANALOG_TOUCH,
|
|
72
|
+
functions: [adc(1, 1), touch(1)],
|
|
73
|
+
alternateFunctions: ['ADC1_CH1', 'Touch1'] },
|
|
74
|
+
|
|
75
|
+
{ number: 2, gpio: 2, name: 'GPIO2', capabilities: FULL_GPIO_ANALOG_TOUCH,
|
|
76
|
+
functions: [adc(1, 2), touch(2)],
|
|
77
|
+
alternateFunctions: ['ADC1_CH2', 'Touch2'],
|
|
78
|
+
warnings: ['GPIO2 is a strapping pin — boot mode select at boot'],
|
|
79
|
+
unsafe: true, notes: 'Boot strapping pin' },
|
|
80
|
+
|
|
81
|
+
{ number: 3, gpio: 3, name: 'GPIO3', capabilities: FULL_GPIO_ANALOG_TOUCH,
|
|
82
|
+
functions: [adc(1, 3), touch(3)],
|
|
83
|
+
alternateFunctions: ['ADC1_CH3', 'Touch3'] },
|
|
84
|
+
|
|
85
|
+
{ number: 4, gpio: 4, name: 'GPIO4', capabilities: FULL_GPIO_ANALOG_TOUCH,
|
|
86
|
+
functions: [adc(1, 4), touch(4), { type: 'spi', instance: 0, role: 'sck' }],
|
|
87
|
+
alternateFunctions: ['ADC1_CH4', 'Touch4', 'SPI0 SCK'] },
|
|
88
|
+
|
|
89
|
+
// ---- ADC2 pin (GPIO5) — Wi-Fi conflicted ------------------------------
|
|
90
|
+
{ number: 5, gpio: 5, name: 'GPIO5', capabilities: FULL_GPIO_ANALOG_TOUCH,
|
|
91
|
+
functions: [adc(2, 0), touch(5), { type: 'spi', instance: 0, role: 'miso' }],
|
|
92
|
+
alternateFunctions: ['ADC2_CH0', 'Touch5', 'SPI0 MISO'],
|
|
93
|
+
warnings: ['GPIO5 is ADC2 — ADC2 is unusable while Wi-Fi is enabled'] },
|
|
94
|
+
|
|
95
|
+
{ number: 6, gpio: 6, name: 'GPIO6', capabilities: FULL_GPIO,
|
|
96
|
+
functions: [{ type: 'spi', instance: 0, role: 'mosi' }],
|
|
97
|
+
alternateFunctions: ['SPI0 MOSI'] },
|
|
98
|
+
|
|
99
|
+
{ number: 7, gpio: 7, name: 'GPIO7', capabilities: FULL_GPIO,
|
|
100
|
+
functions: [{ type: 'spi', instance: 0, role: 'cs' }],
|
|
101
|
+
alternateFunctions: ['SPI0 CS'] },
|
|
102
|
+
|
|
103
|
+
{ number: 8, gpio: 8, name: 'GPIO8', capabilities: FULL_GPIO,
|
|
104
|
+
functions: [{ type: 'i2c', instance: 0, role: 'sda' }],
|
|
105
|
+
alternateFunctions: ['I2C0 SDA'],
|
|
106
|
+
warnings: ['GPIO8 is a strapping pin — controls VDD_SPI voltage at boot'],
|
|
107
|
+
unsafe: true, notes: 'Boot strapping pin' },
|
|
108
|
+
|
|
109
|
+
{ number: 9, gpio: 9, name: 'GPIO9', capabilities: FULL_GPIO,
|
|
110
|
+
functions: [{ type: 'i2c', instance: 0, role: 'scl' }],
|
|
111
|
+
alternateFunctions: ['I2C0 SCL'],
|
|
112
|
+
warnings: ['GPIO9 is a strapping pin — must be HIGH at boot (reset source)'],
|
|
113
|
+
unsafe: true, notes: 'Boot strapping pin' },
|
|
114
|
+
|
|
115
|
+
{ number: 10, gpio: 10, name: 'GPIO10', capabilities: FULL_GPIO,
|
|
116
|
+
alternateFunctions: ['FSPICS0'] },
|
|
117
|
+
|
|
118
|
+
// ---- GPIO 11 — internal flash Vpp, not broken out on the C3 ----------
|
|
119
|
+
|
|
120
|
+
{ number: 12, gpio: 12, name: 'GPIO12', capabilities: FULL_GPIO,
|
|
121
|
+
functions: [{ type: 'spi', instance: 1, role: 'sck' }],
|
|
122
|
+
alternateFunctions: ['FSPICLK'] },
|
|
123
|
+
{ number: 13, gpio: 13, name: 'GPIO13', capabilities: FULL_GPIO,
|
|
124
|
+
functions: [{ type: 'spi', instance: 1, role: 'mosi' }],
|
|
125
|
+
alternateFunctions: ['FSPID'] },
|
|
126
|
+
{ number: 14, gpio: 14, name: 'GPIO14', capabilities: FULL_GPIO,
|
|
127
|
+
functions: [{ type: 'spi', instance: 1, role: 'miso' }],
|
|
128
|
+
alternateFunctions: ['FSPIQ'] },
|
|
129
|
+
{ number: 15, gpio: 15, name: 'GPIO15', capabilities: FULL_GPIO,
|
|
130
|
+
functions: [{ type: 'spi', instance: 1, role: 'cs' }],
|
|
131
|
+
alternateFunctions: ['FSPICS1'] },
|
|
132
|
+
{ number: 16, gpio: 16, name: 'GPIO16', capabilities: FULL_GPIO,
|
|
133
|
+
alternateFunctions: [] },
|
|
134
|
+
{ number: 17, gpio: 17, name: 'GPIO17', capabilities: FULL_GPIO,
|
|
135
|
+
alternateFunctions: [] },
|
|
136
|
+
|
|
137
|
+
// ---- USB Serial/JTAG pins (unsafe) -----------------------------------
|
|
138
|
+
{ number: 18, gpio: 18, name: 'GPIO18', capabilities: FULL_GPIO,
|
|
139
|
+
functions: [{ type: 'usb', instance: 0, role: 'dm' }],
|
|
140
|
+
alternateFunctions: ['USB D-'],
|
|
141
|
+
warnings: ['GPIO18 is USB D- — using it as GPIO disables native USB Serial/JTAG'],
|
|
142
|
+
unsafe: true, notes: 'USB D- pin' },
|
|
143
|
+
{ number: 19, gpio: 19, name: 'GPIO19', capabilities: FULL_GPIO,
|
|
144
|
+
functions: [{ type: 'usb', instance: 0, role: 'dp' }],
|
|
145
|
+
alternateFunctions: ['USB D+'],
|
|
146
|
+
warnings: ['GPIO19 is USB D+ — using it as GPIO disables native USB Serial/JTAG'],
|
|
147
|
+
unsafe: true, notes: 'USB D+ pin' },
|
|
148
|
+
|
|
149
|
+
// ---- UART0 default pins ----------------------------------------------
|
|
150
|
+
{ number: 20, gpio: 20, name: 'GPIO20', capabilities: FULL_GPIO,
|
|
151
|
+
functions: [{ type: 'uart', instance: 0, role: 'rx' }],
|
|
152
|
+
alternateFunctions: ['UART0 RX'],
|
|
153
|
+
warnings: ['Using GPIO20 as GPIO will interfere with UART0 receive'] },
|
|
154
|
+
{ number: 21, gpio: 21, name: 'GPIO21', capabilities: FULL_GPIO,
|
|
155
|
+
functions: [{ type: 'uart', instance: 0, role: 'tx' }],
|
|
156
|
+
alternateFunctions: ['UART0 TX'],
|
|
157
|
+
warnings: ['Using GPIO21 as GPIO will interfere with UART0 transmit'] },
|
|
158
|
+
],
|
|
159
|
+
|
|
160
|
+
digital: [
|
|
161
|
+
'GPIO0', 'GPIO1', 'GPIO2', 'GPIO3', 'GPIO4', 'GPIO5', 'GPIO6', 'GPIO7',
|
|
162
|
+
'GPIO8', 'GPIO9', 'GPIO10',
|
|
163
|
+
'GPIO12', 'GPIO13', 'GPIO14', 'GPIO15', 'GPIO16', 'GPIO17',
|
|
164
|
+
'GPIO18', 'GPIO19', 'GPIO20', 'GPIO21',
|
|
165
|
+
],
|
|
166
|
+
analog: [
|
|
167
|
+
'GPIO0', 'GPIO1', 'GPIO2', 'GPIO3', 'GPIO4', // ADC1
|
|
168
|
+
'GPIO5', // ADC2
|
|
169
|
+
],
|
|
170
|
+
pwm: [
|
|
171
|
+
'GPIO0', 'GPIO1', 'GPIO2', 'GPIO3', 'GPIO4', 'GPIO5', 'GPIO6', 'GPIO7',
|
|
172
|
+
'GPIO8', 'GPIO9', 'GPIO10',
|
|
173
|
+
'GPIO12', 'GPIO13', 'GPIO14', 'GPIO15', 'GPIO16', 'GPIO17',
|
|
174
|
+
'GPIO18', 'GPIO19', 'GPIO20', 'GPIO21',
|
|
175
|
+
],
|
|
176
|
+
unsafe: ['GPIO2', 'GPIO8', 'GPIO9', 'GPIO18', 'GPIO19'],
|
|
177
|
+
|
|
178
|
+
i2c: { 0: { sda: 'GPIO8', scl: 'GPIO9' } },
|
|
179
|
+
spi: {
|
|
180
|
+
0: { mosi: 'GPIO6', miso: 'GPIO5', sck: 'GPIO4', cs: 'GPIO7' }, // GPSPI2 / VSPI
|
|
181
|
+
},
|
|
182
|
+
uart: {
|
|
183
|
+
0: { tx: 'GPIO21', rx: 'GPIO20' },
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
|
|
187
|
+
// ----- Peripherals -------------------------------------------------------
|
|
188
|
+
peripherals: MCU_PERIPHERALS,
|
|
189
|
+
|
|
190
|
+
features: {
|
|
191
|
+
multicore: false,
|
|
192
|
+
coreCount: 1,
|
|
193
|
+
deepSleep: true,
|
|
194
|
+
watchdog: true,
|
|
195
|
+
externalInterrupts: true,
|
|
196
|
+
hardwareRng: true,
|
|
197
|
+
fpu: false,
|
|
198
|
+
},
|
|
199
|
+
build: {
|
|
200
|
+
extraFlags: [],
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
export default ESP32C3;
|
|
205
|
+
|
|
206
|
+
// Re-exports
|
|
207
|
+
export * from './pins.js';
|
|
208
|
+
export * from './peripherals.js';
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Structured manifest consumed by the TypeCAD CLI for contract-based
|
|
212
|
+
* board generation. Provides pin names and peripheral instance names
|
|
213
|
+
* without requiring the CLI to text-scrape compiled output.
|
|
214
|
+
*/
|
|
215
|
+
export const TypeCADManifest = {
|
|
216
|
+
/** All MCU port-level pin names (e.g. 'GPIO0', 'GPIO1'). */
|
|
217
|
+
pinNames: [
|
|
218
|
+
'GPIO0', 'GPIO1', 'GPIO2', 'GPIO3', 'GPIO4', 'GPIO5', 'GPIO6', 'GPIO7',
|
|
219
|
+
'GPIO8', 'GPIO9', 'GPIO10',
|
|
220
|
+
'GPIO12', 'GPIO13', 'GPIO14', 'GPIO15', 'GPIO16', 'GPIO17',
|
|
221
|
+
'GPIO18', 'GPIO19', 'GPIO20', 'GPIO21',
|
|
222
|
+
] as const,
|
|
223
|
+
|
|
224
|
+
/** All HAL peripheral instance names exported from this package. */
|
|
225
|
+
peripheralNames: ['I2C0', 'SPI0', 'UART0', 'UART1'] as const,
|
|
226
|
+
} as const;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// @typecad/mcu-esp32c3 — Hardware peripheral descriptions
|
|
3
|
+
//
|
|
4
|
+
// ESP32-C3 peripherals: 1× I2C, 1× SPI (GPSPI2), 2× UART, 2× ADC (12-bit),
|
|
5
|
+
// 6× capacitive-touch, 4× general-purpose timers, Wi-Fi 4, BLE 5 (long range),
|
|
6
|
+
// native USB Serial/JTAG (CDC). No DAC.
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
|
|
9
|
+
import type {
|
|
10
|
+
PeripheralInstance,
|
|
11
|
+
ADCDefinition,
|
|
12
|
+
PWMDefinition,
|
|
13
|
+
TimerDefinition,
|
|
14
|
+
} from '@typecad/cuttlefish/api/schema';
|
|
15
|
+
import {
|
|
16
|
+
I2CBus,
|
|
17
|
+
SPIBus,
|
|
18
|
+
SerialPort,
|
|
19
|
+
i2cName,
|
|
20
|
+
spiName,
|
|
21
|
+
serialName,
|
|
22
|
+
createHALInstances,
|
|
23
|
+
} from '@typecad/hal';
|
|
24
|
+
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
// Peripheral definitions
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
|
|
29
|
+
export const I2C_INSTANCES: readonly PeripheralInstance[] = [
|
|
30
|
+
{ instance: 0, defaultPins: { sda: 'GPIO8', scl: 'GPIO9' } },
|
|
31
|
+
] as const;
|
|
32
|
+
|
|
33
|
+
export const SPI_INSTANCES: readonly PeripheralInstance[] = [
|
|
34
|
+
{ instance: 0, defaultPins: { mosi: 'GPIO6', miso: 'GPIO5', sck: 'GPIO4', cs: 'GPIO7' } }, // GPSPI2
|
|
35
|
+
] as const;
|
|
36
|
+
|
|
37
|
+
export const UART_INSTANCES: readonly PeripheralInstance[] = [
|
|
38
|
+
{ instance: 0, defaultPins: { tx: 'GPIO21', rx: 'GPIO20' } },
|
|
39
|
+
{ instance: 1, defaultPins: { tx: 'GPIO21', rx: 'GPIO20' } },
|
|
40
|
+
] as const;
|
|
41
|
+
|
|
42
|
+
export const ADC_INSTANCES: readonly ADCDefinition[] = [
|
|
43
|
+
{ instance: 0, channels: 5, resolution: 12, referenceVoltage: 3.3, maxValue: 4095,
|
|
44
|
+
referenceVoltages: { DEFAULT: 3.3, INTERNAL: 1.1 } }, // ADC1 — usable with Wi-Fi active
|
|
45
|
+
{ instance: 1, channels: 1, resolution: 12, referenceVoltage: 3.3, maxValue: 4095,
|
|
46
|
+
referenceVoltages: { DEFAULT: 3.3, INTERNAL: 1.1 } }, // ADC2 — NOT usable with Wi-Fi active
|
|
47
|
+
] as const;
|
|
48
|
+
|
|
49
|
+
export const PWM_CAPABILITIES: PWMDefinition = {
|
|
50
|
+
channels: 6,
|
|
51
|
+
resolution: 14,
|
|
52
|
+
maxFrequency: 40_000_000,
|
|
53
|
+
} as const;
|
|
54
|
+
|
|
55
|
+
export const TOUCH_CAPABILITIES = {
|
|
56
|
+
channels: 6,
|
|
57
|
+
pins: ['GPIO0', 'GPIO1', 'GPIO2', 'GPIO3', 'GPIO4', 'GPIO5'],
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const TIMER_INSTANCES: readonly TimerDefinition[] = [
|
|
61
|
+
{ instance: 0, type: 'general', bits: 64, features: ['interrupt'] },
|
|
62
|
+
{ instance: 1, type: 'general', bits: 64, features: ['interrupt'] },
|
|
63
|
+
{ instance: 2, type: 'general', bits: 64, features: ['interrupt'] },
|
|
64
|
+
{ instance: 3, type: 'general', bits: 64, features: ['interrupt'] },
|
|
65
|
+
] as const;
|
|
66
|
+
|
|
67
|
+
export const WIFI_CAPABILITIES = { type: 'wifi', supportsStation: true, supportsAp: true } as const;
|
|
68
|
+
export const BLUETOOTH_CAPABILITIES = { type: 'ble', version: '5.0' } as const;
|
|
69
|
+
export const USB_CAPABILITIES = { type: 'otg', vid: '0x303A', pid: '0x0001' } as const;
|
|
70
|
+
|
|
71
|
+
// ---------------------------------------------------------------------------
|
|
72
|
+
// Aggregate MCU peripheral description
|
|
73
|
+
// ---------------------------------------------------------------------------
|
|
74
|
+
|
|
75
|
+
export const MCU_PERIPHERALS = {
|
|
76
|
+
i2c: [...I2C_INSTANCES],
|
|
77
|
+
spi: [...SPI_INSTANCES],
|
|
78
|
+
uart: [...UART_INSTANCES],
|
|
79
|
+
adc: [...ADC_INSTANCES],
|
|
80
|
+
pwm: PWM_CAPABILITIES,
|
|
81
|
+
touch: TOUCH_CAPABILITIES,
|
|
82
|
+
timers: [...TIMER_INSTANCES],
|
|
83
|
+
wifi: WIFI_CAPABILITIES,
|
|
84
|
+
bluetooth: BLUETOOTH_CAPABILITIES,
|
|
85
|
+
usb: USB_CAPABILITIES,
|
|
86
|
+
} as const;
|
|
87
|
+
|
|
88
|
+
// ---------------------------------------------------------------------------
|
|
89
|
+
// HAL object instances — auto-generated from peripheral definitions
|
|
90
|
+
// ---------------------------------------------------------------------------
|
|
91
|
+
|
|
92
|
+
/** I2C bus instances */
|
|
93
|
+
export const [I2C0] = createHALInstances(I2C_INSTANCES, i => new I2CBus(i2cName(i)));
|
|
94
|
+
|
|
95
|
+
/** SPI bus instances */
|
|
96
|
+
export const [SPI0] = createHALInstances(SPI_INSTANCES, i => new SPIBus(spiName(i)));
|
|
97
|
+
|
|
98
|
+
/** UART/Serial instances */
|
|
99
|
+
export const [UART0, UART1] = createHALInstances(UART_INSTANCES, i => new SerialPort(serialName(i)));
|
package/src/pins.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// @typecad/mcu-esp32c3 — Datasheet pin definitions
|
|
3
|
+
//
|
|
4
|
+
// Each pin is a Pin instance from @typecad/hal. The ESP32-C3 has 22 GPIO
|
|
5
|
+
// (0-10, 12-21); GPIO 11 is consumed by internal flash Vpp and is not broken
|
|
6
|
+
// out. All GPIOs are bidirectional (no input-only pins). DAC is not present.
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
|
|
9
|
+
import { Pin } from '@typecad/hal';
|
|
10
|
+
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
// Named GPIO constants (Pin instances)
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
|
|
15
|
+
export const GPIO0 = new Pin(0);
|
|
16
|
+
export const GPIO1 = new Pin(1);
|
|
17
|
+
export const GPIO2 = new Pin(2);
|
|
18
|
+
export const GPIO3 = new Pin(3);
|
|
19
|
+
export const GPIO4 = new Pin(4);
|
|
20
|
+
export const GPIO5 = new Pin(5);
|
|
21
|
+
export const GPIO6 = new Pin(6);
|
|
22
|
+
export const GPIO7 = new Pin(7);
|
|
23
|
+
export const GPIO8 = new Pin(8);
|
|
24
|
+
export const GPIO9 = new Pin(9);
|
|
25
|
+
export const GPIO10 = new Pin(10);
|
|
26
|
+
// GPIO 11 — internal flash Vpp, not broken out on the C3 package.
|
|
27
|
+
export const GPIO12 = new Pin(12);
|
|
28
|
+
export const GPIO13 = new Pin(13);
|
|
29
|
+
export const GPIO14 = new Pin(14);
|
|
30
|
+
export const GPIO15 = new Pin(15);
|
|
31
|
+
export const GPIO16 = new Pin(16);
|
|
32
|
+
export const GPIO17 = new Pin(17);
|
|
33
|
+
export const GPIO18 = new Pin(18);
|
|
34
|
+
export const GPIO19 = new Pin(19);
|
|
35
|
+
export const GPIO20 = new Pin(20);
|
|
36
|
+
export const GPIO21 = new Pin(21);
|
|
37
|
+
|
|
38
|
+
// ---------------------------------------------------------------------------
|
|
39
|
+
// Convenience aliases (Silicon-level defaults — match Arduino-ESP32 core)
|
|
40
|
+
// ---------------------------------------------------------------------------
|
|
41
|
+
|
|
42
|
+
/** I2C0 data line (GPIO8). */
|
|
43
|
+
export const SDA = GPIO8;
|
|
44
|
+
/** I2C0 clock line (GPIO9). */
|
|
45
|
+
export const SCL = GPIO9;
|
|
46
|
+
|
|
47
|
+
/** SPI0 MOSI (GPIO6). */
|
|
48
|
+
export const MOSI = GPIO6;
|
|
49
|
+
/** SPI0 MISO (GPIO5). */
|
|
50
|
+
export const MISO = GPIO5;
|
|
51
|
+
/** SPI0 clock (GPIO4). */
|
|
52
|
+
export const SCK = GPIO4;
|
|
53
|
+
/** SPI0 slave select (GPIO7). */
|
|
54
|
+
export const SS = GPIO7;
|
|
55
|
+
|
|
56
|
+
/** UART0 transmit (GPIO21). */
|
|
57
|
+
export const TX = GPIO21;
|
|
58
|
+
/** UART0 receive (GPIO20). */
|
|
59
|
+
export const RX = GPIO20;
|