File size: 7,661 Bytes
a77eee2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
{
  "version": "1.0",
  "status": "frozen",
  "frozen_on": "2026-09-14",
  "changelog": [
    "0.2: kept every 0.1 action and rule. Added optional fields, value enums, reason codes for report_error / ask_clarification, and category-to-action compatibility. See configs/rpi5_hardware_facts.json for the hardware facts and policies behind these rules.",
    "1.0 (2026-09-14): frozen for training. Actions, fields, enums, reason codes and rules are identical to 0.2; sensor_read stays reserved. Changes after this need a new version, regenerated labels and a new dataset release."
  ],
  "actions": {
    "gpio_read": {
      "description": "Read the digital state of a GPIO pin",
      "required": [
        "pin"
      ],
      "optional": [
        "parameters"
      ]
    },
    "gpio_write": {
      "description": "Set a GPIO output HIGH or LOW",
      "required": [
        "pin",
        "value"
      ],
      "optional": [
        "parameters"
      ]
    },
    "gpio_mode": {
      "description": "Configure a GPIO pin mode",
      "required": [
        "pin",
        "mode"
      ],
      "optional": [
        "parameters"
      ]
    },
    "gpio_pwm": {
      "description": "Set PWM output on a supported GPIO",
      "required": [
        "pin",
        "duty_cycle"
      ],
      "optional": [
        "parameters"
      ]
    },
    "gpio_pulse": {
      "description": "Set a GPIO state for a specified duration",
      "required": [
        "pin",
        "value",
        "duration_ms"
      ],
      "optional": []
    },
    "gpio_sequence": {
      "description": "Perform multiple GPIO operations in sequence",
      "required": [
        "operations"
      ],
      "optional": []
    },
    "sensor_read": {
      "description": "Read a sensor through the appropriate hardware interface",
      "required": [
        "pin"
      ],
      "optional": [
        "parameters"
      ],
      "status": "reserved: no generated examples yet, because bus-sensor semantics (I2C/SPI/UART addressing) are not finalised"
    },
    "ask_clarification": {
      "description": "Ask the user for missing information instead of guessing",
      "required": [],
      "optional": [
        "pin",
        "parameters"
      ]
    },
    "report_error": {
      "description": "Report an invalid or unavailable operation",
      "required": [],
      "optional": [
        "pin",
        "parameters"
      ]
    },
    "wait": {
      "description": "Wait for a specified duration",
      "required": [
        "duration_ms"
      ],
      "optional": []
    }
  },
  "fields": {
    "value": [
      "HIGH",
      "LOW"
    ],
    "mode": [
      "INPUT",
      "OUTPUT",
      "ALT"
    ],
    "parameters.pull": [
      "UP",
      "DOWN",
      "NONE"
    ],
    "parameters.drive_strength_ma": [
      2,
      4,
      8,
      12
    ],
    "parameters.pwm_type": [
      "hardware",
      "software"
    ],
    "parameters.function": "one key of documented_alt_functions in configs/rpi5_hardware_facts.json (required when mode is ALT)",
    "parameters.frequency_hz": "positive number (optional, gpio_pwm only)",
    "parameters.header_pin": "physical header pin number 1-40, present only when the user referred to a physical/header/board pin",
    "duty_cycle": "number from 0 to 100 inclusive (percent)",
    "duration_ms": "integer >= 1",
    "operations": "non-empty list of gpio_read / gpio_write / gpio_mode / gpio_pwm / gpio_pulse / wait actions",
    "sequence_operation_actions": [
      "gpio_read",
      "gpio_write",
      "gpio_mode",
      "gpio_pwm",
      "gpio_pulse",
      "wait"
    ]
  },
  "error_reasons": {
    "invalid_gpio": "The number is not GPIO0-27, e.g. GPIO28, GPIO999, GPIO -1, or a non-integer.",
    "reserved_gpio": "GPIO0/GPIO1: exist but are reserved for the ID EEPROM (F-RESERVED-ID-EEPROM).",
    "not_a_gpio": "A physical header pin that is 3V3, 5V or GND (F-POWER-PINS-NOT-GPIO).",
    "unsupported_function": "The GPIO exists, but the requested capability is not on that GPIO (F-ALT-TABLE, F-HW-PWM-PINS, F-PULLS, F-DRIVE-STRENGTH, F-INPUT-DIGITAL, F-OUTPUT-LEVELS, F-ONE-FUNCTION).",
    "unsupported_operation": "Outside the action vocabulary (arbitrary code, bus data transfer, network).",
    "invalid_parameter": "Parameter outside its logical domain (duty cycle outside 0-100, duration <= 0 or sub-millisecond, frequency <= 0).",
    "pin_not_available": "Pin is excluded by context.available_pins.",
    "unsafe_direct_drive": "Driving or powering a motor or other load directly from a GPIO (F-NO-DIRECT-MOTOR).",
    "unsafe_voltage": "Applying 5 V or higher to a GPIO (F-INPUT-3V3).",
    "unsafe_current": "Load current far above the documented GPIO current (F-GPIO-CURRENT), or an LED with no current-limiting resistor (F-LED-RESISTOR).",
    "unsafe_short_circuit": "Driving an output that is wired straight to GND or 3V3 (F-DRIVE-NOT-LIMIT).",
    "no_hardware_action": "Informational question; no hardware operation is performed (P-QUESTIONS)."
  },
  "clarification_reasons": {
    "missing_pin": "Device or operation named without a GPIO, and no mapping in context.",
    "ambiguous_device": "More than one mapped device matches the reference.",
    "missing_value": "Unclear whether HIGH or LOW is wanted.",
    "missing_duration": "Timed/repeated operation without a duration.",
    "missing_duty_cycle": "PWM requested without a duty cycle.",
    "ambiguous_value": "A value whose unit or scale is ambiguous (e.g. duty 0.5).",
    "conflicting_instructions": "The request contradicts itself or contradicts context.device_mappings.",
    "unknown_current_state": "Toggle requested without a known current state."
  },
  "category_actions": {
    "gpio_basic": [
      "gpio_read",
      "gpio_write"
    ],
    "gpio_read": [
      "gpio_read"
    ],
    "gpio_write": [
      "gpio_write"
    ],
    "gpio_mode": [
      "gpio_mode"
    ],
    "gpio_pwm": [
      "gpio_pwm"
    ],
    "gpio_timing": [
      "gpio_pulse",
      "wait"
    ],
    "gpio_sequence": [
      "gpio_sequence"
    ],
    "sensor": [
      "gpio_read",
      "sensor_read"
    ],
    "driver": [
      "gpio_write",
      "gpio_pwm",
      "gpio_pulse",
      "gpio_sequence",
      "gpio_mode"
    ],
    "clarification": [
      "ask_clarification"
    ],
    "error": [
      "report_error"
    ],
    "safety": [
      "report_error"
    ],
    "general_hardware": [
      "report_error"
    ]
  },
  "category_reasons": {
    "safety": [
      "unsafe_direct_drive",
      "unsafe_voltage",
      "unsafe_current",
      "unsafe_short_circuit"
    ],
    "general_hardware": [
      "no_hardware_action"
    ],
    "error": [
      "invalid_gpio",
      "reserved_gpio",
      "not_a_gpio",
      "unsupported_function",
      "unsupported_operation",
      "invalid_parameter",
      "pin_not_available"
    ]
  },
  "rules": [
    "Never invent a GPIO pin.",
    "If the required GPIO pin is unknown, use ask_clarification.",
    "Never invent a device-to-GPIO mapping.",
    "Invalid GPIO requests must use report_error.",
    "The LLM must never execute arbitrary code.",
    "All hardware actions must pass through the deterministic validator.",
    "GPIO numbering must be explicitly defined by the hardware layer.",
    "Hardware safety rules override model output.",
    "A physically valid GPIO is not automatically capable of every function; capabilities are per-pin (RP1 Table 4).",
    "Never substitute a different GPIO when the requested one cannot perform the operation.",
    "Unsafe electrical requests are refused with report_error even when the GPIO number is valid."
  ]
}