{
    "$id": "https://github.com/google/cyanobyte/spec/cyanobyte.schema.json",
    "$schema": "http://json-schema.org/draft-07/schema#",
    "description": "This file is used to validate whether a given document meets the CyanoByte specification.",
    "properties": {
        "cyanobyte": {
            "description": "The version of the CyanoByte specification this file follows.",
            "type": "string"
        },
        "extensions": {
            "description": "Reserved for custom parameters",
            "type": "object"
        },
        "fields": {
            "description": "Subcomponents of a register",
            "items": {
                "description": "Outer object",
                "patternProperties": {
                    "^.*$": {
                        "description": "Chip function",
                        "properties": {
                            "bitEnd": {
                                "description": "What is the ending bit?",
                                "type": "integer"
                            },
                            "bitStart": {
                                "description": "What is the starting bit?",
                                "type": "integer"
                            },
                            "description": {
                                "description": "Description of the function",
                                "type": "string"
                            },
                            "enum": {
                                "description": "List of values",
                                "items": {
                                    "description": "Enum value",
                                    "properties": {
                                        "title": {
                                            "description": "Enum title",
                                            "type": "string"
                                        },
                                        "value": {
                                            "description": "Enum value",
                                            "type": "integer"
                                        }
                                    },
                                    "type": "object"
                                },
                                "type": "object"
                            },
                            "readWrite": {
                                "description": "Can you read and/or write to this register",
                                "enum": [
                                    "R",
                                    "R/W",
                                    "W",
                                    "n"
                                ],
                                "type": "string"
                            },
                            "register": {
                                "description": "Register of the function",
                                "type": "string"
                            },
                            "title": {
                                "description": "Title of the function",
                                "type": "string"
                            },
                            "type": {
                                "description": "What type of value is this?",
                                "enum": [
                                    "enum",
                                    "number"
                                ],
                                "type": "string"
                            }
                        },
                        "required": [
                            "title",
                            "description",
                            "readWrite"
                        ],
                        "type": "object"
                    }
                },
                "type": "object"
            },
            "type": "object"
        },
        "functions": {
            "description": "Chip functions",
            "items": {
                "description": "Outer object",
                "patternProperties": {
                    "^.*$": {
                        "description": "Chip function",
                        "properties": {
                            "computed": {
                                "description": "Properties for a computed element",
                                "items": {
                                    "description": "A computation",
                                    "patternProperties": {
                                        "^.*$": {
                                            "description": "Title of the computation",
                                            "properties": {
                                                "logic": {
                                                    "description": "Set of logical operations",
                                                    "type": "array"
                                                },
                                                "return": {
                                                    "description": "The variable or variable array to return",
                                                    "type": [
                                                        "string",
                                                        "array"
                                                    ]
                                                },
                                                "variables": {
                                                    "description": "All variables used in the computation",
                                                    "items": {
                                                        "description": "Variable name",
                                                        "patternProperties": {
                                                            "^.$": {
                                                                "description": "Variable name",
                                                                "enum": [
                                                                    "int8",
                                                                    "int16",
                                                                    "int32",
                                                                    "uint8",
                                                                    "uint16",
                                                                    "uint32"
                                                                ],
                                                                "type": "string"
                                                            }
                                                        },
                                                        "type": "object"
                                                    },
                                                    "type": "object"
                                                }
                                            },
                                            "type": "object"
                                        }
                                    },
                                    "type": "object"
                                },
                                "type": "object"
                            },
                            "description": {
                                "description": "Description of the function",
                                "type": "string"
                            },
                            "register": {
                                "description": "Register of the function",
                                "type": "string"
                            },
                            "title": {
                                "description": "Title of the function",
                                "type": "string"
                            }
                        },
                        "required": [
                            "title",
                            "description"
                        ],
                        "type": "object"
                    }
                },
                "type": "object"
            },
            "type": "object"
        },
        "i2c": {
            "description": "I2C settings",
            "properties": {
                "address": {
                    "description": "I2C Address of the component",
                    "oneOf": [
                        {
                            "type": "integer"
                        },
                        {
                            "items": {
                                "description": "Array of potentially valid device addresses",
                                "type": "integer"
                            },
                            "type": "array"
                        }
                    ]
                },
                "addressMask": {
                    "description": "Address mask for addresses that can be altered",
                    "type": "integer"
                },
                "addressType": {
                    "description": "Addressing type of the component.",
                    "enum": [
                        "7-bit",
                        "10-bit"
                    ],
                    "type": "string"
                },
                "endian": {
                    "description": "Endianness of the component",
                    "enum": [
                        "little",
                        "big"
                    ],
                    "type": "string"
                }
            },
            "required": [
                "addressType",
                "address",
                "addressMask"
            ],
            "type": "object"
        },
        "info": {
            "description": "Info block of the file",
            "properties": {
                "contact": {
                    "description": "Contact info for the maintainer.",
                    "properties": {
                        "email": {
                            "_format": "email",
                            "description": "Email address for the maintainer.",
                            "type": "string"
                        },
                        "name": {
                            "description": "Name of the maintainer.",
                            "type": "string"
                        },
                        "url": {
                            "_format": "uri",
                            "description": "URL of the maintainer organization.",
                            "type": "string"
                        }
                    },
                    "required": [
                        "name",
                        "url",
                        "email"
                    ],
                    "type": "object"
                },
                "copyright": {
                    "description": "Copyright info for the source code.",
                    "properties": {
                        "date": {
                            "description": "Year / years for the copyright.",
                            "type": "string"
                        },
                        "name": {
                            "description": "Name of the copyright holder.",
                            "type": "string"
                        }
                    },
                    "required": [
                        "name",
                        "date"
                    ],
                    "type": "object"
                },
                "description": {
                    "description": "A description of the document.",
                    "type": "string"
                },
                "license": {
                    "description": "License this document uses. TODO: Add validation other than it being a string.",
                    "properties": {
                        "name": {
                            "anyOf": [
                                {
                                    "type": "string"
                                },
                                {
                                    "enum": [
                                        "Apache-2.0",
                                        "MIT"
                                    ]
                                }
                            ],
                            "description": "A SPDX compliant license identifier"
                        },
                        "url": {
                            "description": "If the license name is not SPDX compliant, this can link to the license",
                            "type": "string"
                        }
                    },
                    "required": [
                        "name"
                    ],
                    "type": "object"
                },
                "package": {
                    "description": "Logical hierarchy of this device, typically organized as a reverse domain name.",
                    "type": "string"
                },
                "title": {
                    "description": "The title of the document. This should be used as the class name in the auto-generated code and therefore should be short (e.g. the part name).",
                    "type": "string"
                },
                "version": {
                    "description": "Version number for this document using kind of semver.",
                    "type": "string"
                }
            },
            "required": [
                "title",
                "description",
                "contact",
                "license",
                "version"
            ],
            "type": "object"
        },
        "registers": {
            "description": "Chip registers",
            "items": {
                "additionalProperties": false,
                "description": "Outer object",
                "patternProperties": {
                    "^.*$": {
                        "description": "Chip register",
                        "properties": {
                            "address": {
                                "description": "Address of the register",
                                "type": "integer"
                            },
                            "description": {
                                "description": "Description of the register",
                                "type": "string"
                            },
                            "length": {
                                "description": "Length of the register in bits",
                                "type": "integer"
                            },
                            "readWrite": {
                                "description": "Can you read and/or write to this register",
                                "enum": [
                                    "R",
                                    "R/W",
                                    "W",
                                    "n"
                                ],
                                "type": "string"
                            },
                            "signed": {
                                "description": "Whether the integer response should be signed when read",
                                "type": "boolean"
                            },
                            "title": {
                                "description": "Title of the register",
                                "type": "string"
                            }
                        },
                        "required": [
                            "title",
                            "description",
                            "address",
                            "length"
                        ],
                        "type": "object"
                    }
                },
                "type": "object"
            },
            "type": "object"
        }
    },
    "required": [
        "cyanobyte",
        "info"
    ],
    "title": "CyanoByte Specification Validator",
    "type": "object"
}