@typecad/mcu-atmega328p 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/dist/mcu.js ADDED
@@ -0,0 +1,143 @@
1
+ // ---------------------------------------------------------------------------
2
+ // @typecad/mcu-atmega328p — MCU hardware definition
3
+ // ---------------------------------------------------------------------------
4
+ import { MCU_PERIPHERALS } from './peripherals.js';
5
+ // ---------------------------------------------------------------------------
6
+ // Pin capability shorthands
7
+ // ---------------------------------------------------------------------------
8
+ const NO = false;
9
+ const YES = true;
10
+ /** Shorthand: digital I/O only, with internal pull-up. */
11
+ const DIGITAL = {
12
+ digitalInput: YES, digitalOutput: YES,
13
+ analogInput: NO, analogOutput: NO,
14
+ pwm: NO, interrupt: NO,
15
+ pullUp: YES, pullDown: NO,
16
+ touch: NO, openDrain: NO,
17
+ };
18
+ /** Shorthand: digital I/O + external-interrupt capable. */
19
+ const DIGITAL_INT = { ...DIGITAL, interrupt: YES };
20
+ /** Shorthand: digital I/O + PWM. */
21
+ const DIGITAL_PWM = { ...DIGITAL, pwm: YES };
22
+ /** Shorthand: digital I/O + PWM + interrupt. */
23
+ const DIGITAL_PWM_INT = { ...DIGITAL, pwm: YES, interrupt: YES };
24
+ /** Shorthand: digital I/O + analog input. */
25
+ const ANALOG_IN = { ...DIGITAL, analogInput: YES };
26
+ // ---------------------------------------------------------------------------
27
+ // ATmega328P MCU Definition
28
+ // ---------------------------------------------------------------------------
29
+ export const ATmega328P = {
30
+ id: 'atmega328p',
31
+ name: 'ATmega328P',
32
+ architecture: 'avr',
33
+ // ----- Memory ------------------------------------------------------------
34
+ memory: {
35
+ flash: 32_768, // 32 KB
36
+ sram: 2_048, // 2 KB
37
+ eeprom: 1_024, // 1 KB
38
+ },
39
+ // ----- Pins --------------------------------------------------------------
40
+ pins: {
41
+ all: [
42
+ // Port D pins (PD0–PD7)
43
+ { number: 0, gpio: 0, name: 'PD0', aliases: ['RX'], capabilities: DIGITAL_INT,
44
+ functions: [{ type: 'uart', instance: 0, role: 'rx' }],
45
+ alternateFunctions: ['UART0 RX'],
46
+ warnings: ['Using PD0 as GPIO will interfere with UART0 receive'],
47
+ unsafe: true, notes: 'UART RX pin' },
48
+ { number: 1, gpio: 1, name: 'PD1', aliases: ['TX'], capabilities: DIGITAL_INT,
49
+ functions: [{ type: 'uart', instance: 0, role: 'tx' }],
50
+ alternateFunctions: ['UART0 TX'],
51
+ warnings: ['Using PD1 as GPIO will interfere with UART0 transmit'],
52
+ unsafe: true, notes: 'UART TX pin' },
53
+ { number: 2, gpio: 2, name: 'PD2', capabilities: DIGITAL_INT },
54
+ { number: 3, gpio: 3, name: 'PD3', capabilities: DIGITAL_PWM_INT,
55
+ functions: [{ type: 'pwm', instance: 0, role: 'OC2B', timer: 'timer2' }] },
56
+ { number: 4, gpio: 4, name: 'PD4', capabilities: DIGITAL },
57
+ { number: 5, gpio: 5, name: 'PD5', capabilities: DIGITAL_PWM,
58
+ functions: [{ type: 'pwm', instance: 0, role: 'OC0B', timer: 'timer0' }] },
59
+ { number: 6, gpio: 6, name: 'PD6', capabilities: DIGITAL_PWM,
60
+ functions: [{ type: 'pwm', instance: 0, role: 'OC0A', timer: 'timer0' }] },
61
+ { number: 7, gpio: 7, name: 'PD7', capabilities: DIGITAL },
62
+ // Port B pins (PB0–PB5)
63
+ { number: 8, gpio: 8, name: 'PB0', capabilities: DIGITAL },
64
+ { number: 9, gpio: 9, name: 'PB1', capabilities: DIGITAL_PWM,
65
+ functions: [{ type: 'pwm', instance: 0, role: 'OC1A', timer: 'timer1' }] },
66
+ { number: 10, gpio: 10, name: 'PB2', aliases: ['SS'], capabilities: DIGITAL_PWM,
67
+ functions: [
68
+ { type: 'pwm', instance: 0, role: 'OC1B', timer: 'timer1' },
69
+ { type: 'spi', instance: 0, role: 'cs' },
70
+ ],
71
+ alternateFunctions: ['SPI0 CS'] },
72
+ { number: 11, gpio: 11, name: 'PB3', aliases: ['MOSI'], capabilities: DIGITAL_PWM,
73
+ functions: [
74
+ { type: 'pwm', instance: 0, role: 'OC2A', timer: 'timer2' },
75
+ { type: 'spi', instance: 0, role: 'mosi' },
76
+ ],
77
+ alternateFunctions: ['SPI0 MOSI'],
78
+ warnings: ['Using PB3 as GPIO will interfere with SPI0 MOSI'] },
79
+ { number: 12, gpio: 12, name: 'PB4', aliases: ['MISO'], capabilities: DIGITAL,
80
+ functions: [{ type: 'spi', instance: 0, role: 'miso' }],
81
+ alternateFunctions: ['SPI0 MISO'],
82
+ warnings: ['Using PB4 as GPIO will interfere with SPI0 MISO'] },
83
+ { number: 13, gpio: 13, name: 'PB5', aliases: ['SCK'], capabilities: DIGITAL,
84
+ functions: [{ type: 'spi', instance: 0, role: 'sck' }],
85
+ alternateFunctions: ['SPI0 SCK'],
86
+ warnings: ['PB5 is SPI0 SCK'] },
87
+ // Port C pins (PC0–PC5)
88
+ { number: 14, gpio: 14, name: 'PC0', capabilities: ANALOG_IN,
89
+ functions: [{ type: 'adc', instance: 0, role: 'ch0' }] },
90
+ { number: 15, gpio: 15, name: 'PC1', capabilities: ANALOG_IN,
91
+ functions: [{ type: 'adc', instance: 0, role: 'ch1' }] },
92
+ { number: 16, gpio: 16, name: 'PC2', capabilities: ANALOG_IN,
93
+ functions: [{ type: 'adc', instance: 0, role: 'ch2' }] },
94
+ { number: 17, gpio: 17, name: 'PC3', capabilities: ANALOG_IN,
95
+ functions: [{ type: 'adc', instance: 0, role: 'ch3' }] },
96
+ { number: 18, gpio: 18, name: 'PC4', aliases: ['SDA'], capabilities: ANALOG_IN,
97
+ functions: [
98
+ { type: 'adc', instance: 0, role: 'ch4' },
99
+ { type: 'i2c', instance: 0, role: 'sda' },
100
+ ],
101
+ alternateFunctions: ['I2C0 SDA', 'ADC ch4'],
102
+ warnings: ['Using PC4 as GPIO will interfere with I2C0 SDA'] },
103
+ { number: 19, gpio: 19, name: 'PC5', aliases: ['SCL'], capabilities: ANALOG_IN,
104
+ functions: [
105
+ { type: 'adc', instance: 0, role: 'ch5' },
106
+ { type: 'i2c', instance: 0, role: 'scl' },
107
+ ],
108
+ alternateFunctions: ['I2C0 SCL', 'ADC ch5'],
109
+ warnings: ['Using PC5 as GPIO will interfere with I2C0 SCL'] },
110
+ ],
111
+ digital: [
112
+ 'PD0', 'PD1', 'PD2', 'PD3', 'PD4', 'PD5', 'PD6', 'PD7',
113
+ 'PB0', 'PB1', 'PB2', 'PB3', 'PB4', 'PB5',
114
+ 'PC0', 'PC1', 'PC2', 'PC3', 'PC4', 'PC5',
115
+ ],
116
+ analog: ['PC0', 'PC1', 'PC2', 'PC3', 'PC4', 'PC5'],
117
+ pwm: ['PD3', 'PD5', 'PD6', 'PB1', 'PB2', 'PB3'],
118
+ unsafe: ['PD0', 'PD1'],
119
+ i2c: { 0: { sda: 'PC4', scl: 'PC5' } },
120
+ spi: { 0: { mosi: 'PB3', miso: 'PB4', sck: 'PB5', cs: 'PB2' } },
121
+ uart: {
122
+ 0: { tx: 'PD1', rx: 'PD0' },
123
+ 1: { tx: 'PD2', rx: 'PD3' },
124
+ },
125
+ },
126
+ // ----- Peripherals -------------------------------------------------------
127
+ peripherals: MCU_PERIPHERALS,
128
+ // ----- Features ----------------------------------------------------------
129
+ features: {
130
+ multicore: false,
131
+ coreCount: 1,
132
+ deepSleep: false,
133
+ watchdog: true,
134
+ externalInterrupts: true,
135
+ hardwareRng: false,
136
+ fpu: false,
137
+ },
138
+ // ----- Build config ------------------------------------------------------
139
+ build: {
140
+ extraFlags: ['-mmcu=atmega328p'],
141
+ },
142
+ };
143
+ export default ATmega328P;
@@ -0,0 +1,104 @@
1
+ import type { PeripheralInstance, ADCDefinition, PWMDefinition, TimerDefinition } from '@typecad/cuttlefish/api/schema';
2
+ import { I2CBus, SPIBus, SerialPort } from '@typecad/hal';
3
+ /**
4
+ * USART peripherals on the ATmega328P.
5
+ * The ATmega328P has a single USART with full-duplex TX/RX.
6
+ */
7
+ export declare const UART_INSTANCES: readonly PeripheralInstance[];
8
+ /**
9
+ * I2C/TWI peripherals on the ATmega328P.
10
+ * Single TWI peripheral with SDA/SCL on Port C.
11
+ */
12
+ export declare const I2C_INSTANCES: readonly PeripheralInstance[];
13
+ /**
14
+ * SPI peripherals on the ATmega328P.
15
+ * Single SPI peripheral in Master/Slave mode.
16
+ */
17
+ export declare const SPI_INSTANCES: readonly PeripheralInstance[];
18
+ /**
19
+ * ADC peripheral on the ATmega328P.
20
+ * 10-bit successive approximation ADC with 6 single-ended channels on PC0–PC5,
21
+ * plus internal channels for temperature sensor and bandgap reference.
22
+ *
23
+ * Note: referenceVoltage and referenceVoltages are board-dependent (determined
24
+ * by the board's power supply voltage). They are provided as chip-typical
25
+ * defaults (5V) and should be overridden by the board package if the board
26
+ * runs at a different voltage (e.g. 3.3V Pro Mini).
27
+ */
28
+ export declare const ADC_INSTANCES: readonly ADCDefinition[];
29
+ /**
30
+ * PWM capabilities on the ATmega328P.
31
+ * 6 PWM channels derived from Timer0 (2 ch), Timer1 (2 ch), Timer2 (2 ch).
32
+ * 8-bit resolution on Timer0/Timer2, up to 16-bit on Timer1 (but framework
33
+ * defaults often use 8-bit for all).
34
+ */
35
+ export declare const PWM_CAPABILITIES: PWMDefinition;
36
+ /**
37
+ * PWM output pin assignments.
38
+ * Maps each PWM output compare channel to its physical pin.
39
+ */
40
+ export declare const PWM_PIN_MAP: {
41
+ /** Timer0 Channel A — PD6 */
42
+ readonly OC0A: "PD6";
43
+ /** Timer0 Channel B — PD5 */
44
+ readonly OC0B: "PD5";
45
+ /** Timer1 Channel A — PB1 */
46
+ readonly OC1A: "PB1";
47
+ /** Timer1 Channel B — PB2 */
48
+ readonly OC1B: "PB2";
49
+ /** Timer2 Channel A — PB3 */
50
+ readonly OC2A: "PB3";
51
+ /** Timer2 Channel B — PD3 */
52
+ readonly OC2B: "PD3";
53
+ };
54
+ /**
55
+ * Hardware timers on the ATmega328P.
56
+ * Timer0 is typically reserved for system timing functions (millis/delay)
57
+ * (type: 'sys'). Timer1 and Timer2 are available for general application use.
58
+ */
59
+ export declare const TIMER_INSTANCES: readonly TimerDefinition[];
60
+ /**
61
+ * External interrupt pins on the ATmega328P.
62
+ * Only PD2 (INT0) and PD3 (INT1) support hardware external interrupts.
63
+ * Pin-change interrupts are available on all pins but are handled separately.
64
+ */
65
+ export declare const EXTERNAL_INTERRUPTS: readonly [{
66
+ readonly instance: 0;
67
+ readonly pin: "PD2";
68
+ }, {
69
+ readonly instance: 1;
70
+ readonly pin: "PD3";
71
+ }];
72
+ /**
73
+ * Complete hardware peripheral description for the ATmega328P.
74
+ * Board packages can import this and spread it into their BoardDefinition,
75
+ * overriding board-specific fields (aliases, reference voltages, etc.).
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * // In a board package:
80
+ * import { MCU_PERIPHERALS } from '@typecad/mcu-atmega328p';
81
+ *
82
+ * export const MyBoard: BoardDefinition = {
83
+ * // ...
84
+ * peripherals: {
85
+ * ...MCU_PERIPHERALS,
86
+ * aliases: { UART0: 'Serial', I2C0: 'Wire', SPI0: 'SPI' },
87
+ * },
88
+ * };
89
+ * ```
90
+ */
91
+ export declare const MCU_PERIPHERALS: {
92
+ readonly i2c: readonly PeripheralInstance[];
93
+ readonly spi: readonly PeripheralInstance[];
94
+ readonly uart: readonly PeripheralInstance[];
95
+ readonly adc: readonly ADCDefinition[];
96
+ readonly pwm: PWMDefinition;
97
+ readonly timers: readonly TimerDefinition[];
98
+ };
99
+ /** I2C bus instances */
100
+ export declare const I2C0: I2CBus;
101
+ /** SPI bus instances */
102
+ export declare const SPI0: SPIBus;
103
+ /** UART/Serial instances */
104
+ export declare const UART0: SerialPort;
@@ -0,0 +1,180 @@
1
+ // ---------------------------------------------------------------------------
2
+ // @typecad/mcu-atmega328p — Hardware peripheral descriptions
3
+ //
4
+ // Describes the peripherals built into the ATmega328P silicon.
5
+ // These are properties of the chip, not the board — every ATmega328P has
6
+ // exactly the same peripheral count regardless of what board it's on.
7
+ //
8
+ // Source: ATmega328P datasheet, Section 2 — Block Diagram / Peripheral Summary
9
+ // ---------------------------------------------------------------------------
10
+ import { I2CBus, SPIBus, SerialPort, i2cName, spiName, serialName, createHALInstances, } from '@typecad/hal';
11
+ // ---------------------------------------------------------------------------
12
+ // UART — 1 USART peripheral
13
+ // ---------------------------------------------------------------------------
14
+ /**
15
+ * USART peripherals on the ATmega328P.
16
+ * The ATmega328P has a single USART with full-duplex TX/RX.
17
+ */
18
+ export const UART_INSTANCES = [
19
+ { instance: 0, defaultPins: { tx: 'PD1', rx: 'PD0' } },
20
+ ];
21
+ // ---------------------------------------------------------------------------
22
+ // I2C (TWI) — 1 Two-Wire Interface
23
+ // ---------------------------------------------------------------------------
24
+ /**
25
+ * I2C/TWI peripherals on the ATmega328P.
26
+ * Single TWI peripheral with SDA/SCL on Port C.
27
+ */
28
+ export const I2C_INSTANCES = [
29
+ { instance: 0, defaultPins: { sda: 'PC4', scl: 'PC5' } },
30
+ ];
31
+ // ---------------------------------------------------------------------------
32
+ // SPI — 1 SPI peripheral
33
+ // ---------------------------------------------------------------------------
34
+ /**
35
+ * SPI peripherals on the ATmega328P.
36
+ * Single SPI peripheral in Master/Slave mode.
37
+ */
38
+ export const SPI_INSTANCES = [
39
+ { instance: 0, defaultPins: { mosi: 'PB3', miso: 'PB4', sck: 'PB5', cs: 'PB2' } },
40
+ ];
41
+ // ---------------------------------------------------------------------------
42
+ // ADC — 1 ADC with 6 (single-ended) channels on Port C
43
+ // ---------------------------------------------------------------------------
44
+ /**
45
+ * ADC peripheral on the ATmega328P.
46
+ * 10-bit successive approximation ADC with 6 single-ended channels on PC0–PC5,
47
+ * plus internal channels for temperature sensor and bandgap reference.
48
+ *
49
+ * Note: referenceVoltage and referenceVoltages are board-dependent (determined
50
+ * by the board's power supply voltage). They are provided as chip-typical
51
+ * defaults (5V) and should be overridden by the board package if the board
52
+ * runs at a different voltage (e.g. 3.3V Pro Mini).
53
+ */
54
+ export const ADC_INSTANCES = [
55
+ {
56
+ instance: 0,
57
+ channels: 6,
58
+ resolution: 10,
59
+ maxValue: 1023, // (1 << 10) - 1
60
+ referenceVoltage: 5.0, // chip-typical default; board may override
61
+ referenceVoltages: {
62
+ DEFAULT: 5.0, // VCC — board-dependent
63
+ INTERNAL: 1.1, // internal 1.1V bandgap reference
64
+ },
65
+ },
66
+ ];
67
+ // ---------------------------------------------------------------------------
68
+ // PWM — 6 channels from 3 timers
69
+ // ---------------------------------------------------------------------------
70
+ /**
71
+ * PWM capabilities on the ATmega328P.
72
+ * 6 PWM channels derived from Timer0 (2 ch), Timer1 (2 ch), Timer2 (2 ch).
73
+ * 8-bit resolution on Timer0/Timer2, up to 16-bit on Timer1 (but framework
74
+ * defaults often use 8-bit for all).
75
+ */
76
+ export const PWM_CAPABILITIES = {
77
+ channels: 6,
78
+ resolution: 8,
79
+ maxFrequency: 62_500, // at 16 MHz with default prescaler
80
+ };
81
+ /**
82
+ * PWM output pin assignments.
83
+ * Maps each PWM output compare channel to its physical pin.
84
+ */
85
+ export const PWM_PIN_MAP = {
86
+ /** Timer0 Channel A — PD6 */
87
+ OC0A: 'PD6',
88
+ /** Timer0 Channel B — PD5 */
89
+ OC0B: 'PD5',
90
+ /** Timer1 Channel A — PB1 */
91
+ OC1A: 'PB1',
92
+ /** Timer1 Channel B — PB2 */
93
+ OC1B: 'PB2',
94
+ /** Timer2 Channel A — PB3 */
95
+ OC2A: 'PB3',
96
+ /** Timer2 Channel B — PD3 */
97
+ OC2B: 'PD3',
98
+ };
99
+ // ---------------------------------------------------------------------------
100
+ // Timers — 3 hardware timers
101
+ // ---------------------------------------------------------------------------
102
+ /**
103
+ * Hardware timers on the ATmega328P.
104
+ * Timer0 is typically reserved for system timing functions (millis/delay)
105
+ * (type: 'sys'). Timer1 and Timer2 are available for general application use.
106
+ */
107
+ export const TIMER_INSTANCES = [
108
+ {
109
+ instance: 0,
110
+ type: 'sys',
111
+ bits: 8,
112
+ frequency: 16_000_000,
113
+ features: ['pwm', 'interrupt'],
114
+ },
115
+ {
116
+ instance: 1,
117
+ type: 'general',
118
+ bits: 16,
119
+ frequency: 16_000_000,
120
+ features: ['pwm', 'interrupt', 'capture', 'compare'],
121
+ },
122
+ {
123
+ instance: 2,
124
+ type: 'general',
125
+ bits: 8,
126
+ frequency: 16_000_000,
127
+ features: ['pwm', 'interrupt'],
128
+ },
129
+ ];
130
+ // ---------------------------------------------------------------------------
131
+ // External interrupts
132
+ // ---------------------------------------------------------------------------
133
+ /**
134
+ * External interrupt pins on the ATmega328P.
135
+ * Only PD2 (INT0) and PD3 (INT1) support hardware external interrupts.
136
+ * Pin-change interrupts are available on all pins but are handled separately.
137
+ */
138
+ export const EXTERNAL_INTERRUPTS = [
139
+ { instance: 0, pin: 'PD2' }, // INT0
140
+ { instance: 1, pin: 'PD3' }, // INT1
141
+ ];
142
+ // ---------------------------------------------------------------------------
143
+ // Aggregate MCU peripheral description
144
+ // ---------------------------------------------------------------------------
145
+ /**
146
+ * Complete hardware peripheral description for the ATmega328P.
147
+ * Board packages can import this and spread it into their BoardDefinition,
148
+ * overriding board-specific fields (aliases, reference voltages, etc.).
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * // In a board package:
153
+ * import { MCU_PERIPHERALS } from '@typecad/mcu-atmega328p';
154
+ *
155
+ * export const MyBoard: BoardDefinition = {
156
+ * // ...
157
+ * peripherals: {
158
+ * ...MCU_PERIPHERALS,
159
+ * aliases: { UART0: 'Serial', I2C0: 'Wire', SPI0: 'SPI' },
160
+ * },
161
+ * };
162
+ * ```
163
+ */
164
+ export const MCU_PERIPHERALS = {
165
+ i2c: [...I2C_INSTANCES],
166
+ spi: [...SPI_INSTANCES],
167
+ uart: [...UART_INSTANCES],
168
+ adc: [...ADC_INSTANCES],
169
+ pwm: PWM_CAPABILITIES,
170
+ timers: [...TIMER_INSTANCES],
171
+ };
172
+ // ---------------------------------------------------------------------------
173
+ // HAL object instances — auto-generated from peripheral definitions
174
+ // ---------------------------------------------------------------------------
175
+ /** I2C bus instances */
176
+ export const [I2C0] = createHALInstances(I2C_INSTANCES, i => new I2CBus(i2cName(i)));
177
+ /** SPI bus instances */
178
+ export const [SPI0] = createHALInstances(SPI_INSTANCES, i => new SPIBus(spiName(i)));
179
+ /** UART/Serial instances */
180
+ export const [UART0] = createHALInstances(UART_INSTANCES, i => new SerialPort(serialName(i)));
package/dist/pins.d.ts ADDED
@@ -0,0 +1,40 @@
1
+ import { Pin } from '@typecad/hal';
2
+ export declare const PD0: Pin;
3
+ export declare const PD1: Pin;
4
+ export declare const PD2: Pin;
5
+ export declare const PD3: Pin;
6
+ export declare const PD4: Pin;
7
+ export declare const PD5: Pin;
8
+ export declare const PD6: Pin;
9
+ export declare const PD7: Pin;
10
+ export declare const PB0: Pin;
11
+ export declare const PB1: Pin;
12
+ export declare const PB2: Pin;
13
+ export declare const PB3: Pin;
14
+ export declare const PB4: Pin;
15
+ export declare const PB5: Pin;
16
+ export declare const PB6: Pin;
17
+ export declare const PB7: Pin;
18
+ export declare const PC0: Pin;
19
+ export declare const PC1: Pin;
20
+ export declare const PC2: Pin;
21
+ export declare const PC3: Pin;
22
+ export declare const PC4: Pin;
23
+ export declare const PC5: Pin;
24
+ export declare const PC6: Pin;
25
+ /** I2C data line (PC4). */
26
+ export declare const SDA: Pin;
27
+ /** I2C clock line (PC5). */
28
+ export declare const SCL: Pin;
29
+ /** SPI master-out / slave-in (PB3). */
30
+ export declare const MOSI: Pin;
31
+ /** SPI master-in / slave-out (PB4). */
32
+ export declare const MISO: Pin;
33
+ /** SPI clock (PB5). */
34
+ export declare const SCK: Pin;
35
+ /** SPI slave select (PB2). */
36
+ export declare const SS: Pin;
37
+ /** UART transmit (PD1). */
38
+ export declare const TX: Pin;
39
+ /** UART receive (PD0). */
40
+ export declare const RX: Pin;
package/dist/pins.js ADDED
@@ -0,0 +1,63 @@
1
+ // ---------------------------------------------------------------------------
2
+ // @typecad/mcu-atmega328p — Datasheet pin definitions
3
+ //
4
+ // Each pin is a Pin instance created via Pin.fromPort() using the MCU port
5
+ // name from the ATmega328P datasheet. The port name is the canonical identity;
6
+ // framework-specific pin numbers are resolved at
7
+ // transpile time via the arduino-map.
8
+ // ---------------------------------------------------------------------------
9
+ import { Pin } from '@typecad/hal';
10
+ // ---------------------------------------------------------------------------
11
+ // Port D (PD0–PD7) — 8-bit bidirectional I/O port
12
+ // DIP-28 pins 2–6, 9–11
13
+ // ---------------------------------------------------------------------------
14
+ export const PD0 = Pin.fromPort('PD0');
15
+ export const PD1 = Pin.fromPort('PD1');
16
+ export const PD2 = Pin.fromPort('PD2');
17
+ export const PD3 = Pin.fromPort('PD3');
18
+ export const PD4 = Pin.fromPort('PD4');
19
+ export const PD5 = Pin.fromPort('PD5');
20
+ export const PD6 = Pin.fromPort('PD6');
21
+ export const PD7 = Pin.fromPort('PD7');
22
+ // ---------------------------------------------------------------------------
23
+ // Port B (PB0–PB7) — 8-bit bidirectional I/O port
24
+ // DIP-28 pins 12–19 (PB6/PB7 are crystal oscillator, not GPIO)
25
+ // ---------------------------------------------------------------------------
26
+ export const PB0 = Pin.fromPort('PB0');
27
+ export const PB1 = Pin.fromPort('PB1');
28
+ export const PB2 = Pin.fromPort('PB2');
29
+ export const PB3 = Pin.fromPort('PB3');
30
+ export const PB4 = Pin.fromPort('PB4');
31
+ export const PB5 = Pin.fromPort('PB5');
32
+ export const PB6 = Pin.fromPort('PB6');
33
+ export const PB7 = Pin.fromPort('PB7');
34
+ // ---------------------------------------------------------------------------
35
+ // Port C (PC0–PC6) — 7-bit bidirectional I/O port (PC6 is RESET on DIP-28)
36
+ // DIP-28 pins 23–28
37
+ // ---------------------------------------------------------------------------
38
+ export const PC0 = Pin.fromPort('PC0');
39
+ export const PC1 = Pin.fromPort('PC1');
40
+ export const PC2 = Pin.fromPort('PC2');
41
+ export const PC3 = Pin.fromPort('PC3');
42
+ export const PC4 = Pin.fromPort('PC4');
43
+ export const PC5 = Pin.fromPort('PC5');
44
+ export const PC6 = Pin.fromPort('PC6');
45
+ // ---------------------------------------------------------------------------
46
+ // Convenience aliases (Silicon-level defaults)
47
+ // ---------------------------------------------------------------------------
48
+ /** I2C data line (PC4). */
49
+ export const SDA = PC4;
50
+ /** I2C clock line (PC5). */
51
+ export const SCL = PC5;
52
+ /** SPI master-out / slave-in (PB3). */
53
+ export const MOSI = PB3;
54
+ /** SPI master-in / slave-out (PB4). */
55
+ export const MISO = PB4;
56
+ /** SPI clock (PB5). */
57
+ export const SCK = PB5;
58
+ /** SPI slave select (PB2). */
59
+ export const SS = PB2;
60
+ /** UART transmit (PD1). */
61
+ export const TX = PD1;
62
+ /** UART receive (PD0). */
63
+ export const RX = PD0;
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@typecad/mcu-atmega328p",
3
+ "version": "0.1.0-alpha.1",
4
+ "description": "TypeCAD MCU definition for ATmega328P — datasheet pins, Arduino pin mapping, peripheral capabilities",
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-atmega328p"
28
+ },
29
+ "homepage": "https://github.com/justind000/typecode/tree/main/packages/mcu-atmega328p",
30
+ "bugs": {
31
+ "url": "https://github.com/justind000/typecode/issues"
32
+ },
33
+ "keywords": [
34
+ "arduino",
35
+ "atmega328p",
36
+ "cpp",
37
+ "cuttlefish",
38
+ "embedded",
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
+ }
@@ -0,0 +1,42 @@
1
+ // ---------------------------------------------------------------------------
2
+ // @typecad/mcu-atmega328p — Arduino core pin mapping
3
+ //
4
+ // Maps MCU port names to Arduino framework pin numbers.
5
+ // Source: Arduino AVR core, variants/standard/pins_arduino.h
6
+ //
7
+ // This mapping is per-chip — an ATtiny85 has A2=PB4 while ATmega328P has
8
+ // A2=PC2. It lives in the MCU package, NOT in the framework package.
9
+ // ---------------------------------------------------------------------------
10
+
11
+ /**
12
+ * Arduino pin number for each MCU port name.
13
+ * Port name → Arduino digital/analog pin number.
14
+ */
15
+ export const ARDUINO_PIN_MAP: Readonly<Record<string, number>> = {
16
+ // Port D — Arduino digital pins 0–7
17
+ PD0: 0, PD1: 1, PD2: 2, PD3: 3,
18
+ PD4: 4, PD5: 5, PD6: 6, PD7: 7,
19
+
20
+ // Port B — Arduino digital pins 8–13
21
+ PB0: 8, PB1: 9, PB2: 10, PB3: 11,
22
+ PB4: 12, PB5: 13,
23
+
24
+ // Port C — Arduino analog pins A0–A5 (pin numbers 14–19)
25
+ PC0: 14, PC1: 15, PC2: 16, PC3: 17,
26
+ PC4: 18, PC5: 19,
27
+ };
28
+
29
+ /**
30
+ * The offset where analog pin numbering starts.
31
+ * Arduino analogRead(A0) maps to pin 14 on ATmega328P.
32
+ */
33
+ export const ARDUINO_ANALOG_OFFSET = 14;
34
+
35
+ /**
36
+ * Reverse map: Arduino pin number → MCU port name.
37
+ * Used by the transpiler to resolve bare names like D13 → PB5.
38
+ */
39
+ export const ARDUINO_PIN_REVERSE: Readonly<Record<number, string>> = {};
40
+ for (const [port, num] of Object.entries(ARDUINO_PIN_MAP)) {
41
+ (ARDUINO_PIN_REVERSE as Record<number, string>)[num] = port;
42
+ }
package/src/index.ts ADDED
@@ -0,0 +1,39 @@
1
+ // ---------------------------------------------------------------------------
2
+ // @typecad/mcu-atmega328p — MCU definition package
3
+ //
4
+ // Provides datasheet-level pin definitions, hardware peripheral descriptions,
5
+ // and framework pin mappings for the ATmega328P microcontroller.
6
+ // Board packages (e.g. board-arduino-uno) import from here and add
7
+ // board-specific aliases and wiring.
8
+ // ---------------------------------------------------------------------------
9
+
10
+ // Re-export all pin definitions
11
+ export * from './pins.js';
12
+
13
+ // Re-export hardware peripheral descriptions
14
+ export * from './peripherals.js';
15
+
16
+ // Re-export MCU definition
17
+ export * from './mcu.js';
18
+
19
+ // Re-export Arduino pin mapping (used by transpiler and framework strategy)
20
+ export * from './arduino-map.js';
21
+
22
+ /**
23
+ * Structured manifest consumed by the TypeCAD CLI for contract-based
24
+ * board generation. Provides pin names and peripheral instance names
25
+ * without requiring the CLI to text-scrape compiled output.
26
+ */
27
+ export const TypeCADManifest = {
28
+ /** All MCU port-level pin names (e.g. 'PB5', 'PC4'). */
29
+ pinNames: [
30
+ 'PD0', 'PD1', 'PD2', 'PD3', 'PD4', 'PD5', 'PD6', 'PD7',
31
+ 'PB0', 'PB1', 'PB2', 'PB3', 'PB4', 'PB5', 'PB6', 'PB7',
32
+ 'PC0', 'PC1', 'PC2', 'PC3', 'PC4', 'PC5', 'PC6'
33
+ ] as const,
34
+
35
+ /** All HAL peripheral instance names exported from this package. */
36
+ peripheralNames: ['I2C0', 'SPI0', 'UART0'] as const,
37
+ } as const;
38
+
39
+