~ruther/avr-device

d5a733ea988098cfb486dce640c8057b9b039906 — octycs 5 years ago c15bfe5
Allow overwriting enumeratedValues and add exemplary patch
5 files changed, 43 insertions(+), 5 deletions(-)

M README.md
A patch/attiny85.yaml
A patch/common/ac.yaml
A patch/common/ac/acsr.yaml
M patch/svdpatch.py
M README.md => README.md +11 -0
@@ 44,6 44,17 @@ Via the feature you can select which chip you want the register specifications f
### Adding a new Chip
To add a new chip, download the *atdf* from <http://packs.download.atmel.com/> and place it in `vendor/`.  Be sure to name it like the Rust module that should be generated.  Next, you need to integrate it into the base crate and build system.  Follow what was done in [this commit](https://github.com/Rahix/avr-device/commit/8b1679a89704f5a303a1578b261aa2aee53e1251).  Please adhere to the alphabetical sorting that is present so far.

If patches need to be applied, create a `<chipname>.yaml` in `patch/`. The patching format is compatible to the [YAML patching format of stm32](https://github.com/stm32-rs/stm32-rs/#device-and-peripheral-yaml-format), except that you do not need to provide the path to the svd file (`_svd: ...`) since it is generated in the build process. Additionally, the following patching was added:
```yaml
PERIPHERIAL:
    REGISTER:
        FIELD:
            # Replaces the enumeratedValues definition for this field.
            # If it does not exist yet, it is created.
            _replace_enum:
                NAME: [VALUE, DESCRIPTION]
```

## License
*avr-device* is licensed under either of


A patch/attiny85.yaml => patch/attiny85.yaml +2 -0
@@ 0,0 1,2 @@
_include:
    - "common/ac.yaml"

A patch/common/ac.yaml => patch/common/ac.yaml +2 -0
@@ 0,0 1,2 @@
_include:
    - "ac/acsr.yaml"

A patch/common/ac/acsr.yaml => patch/common/ac/acsr.yaml +11 -0
@@ 0,0 1,11 @@
AC:
    ACSR:
        _modify:
            ACIS:
                description: "Analog Comparator Interrupt Mode Select"
        ACIS:
            _replace_enum:
                ON_TOGGLE: [0, "Interrupt on Toggle"]
                # Leaving [1, 'Reserved'] out
                ON_FALLING_EDGE: [2, "Interrupt on Falling Edge"]
                ON_RISING_EDGE: [3, "Interrupt on Rising Edge"]

M patch/svdpatch.py => patch/svdpatch.py +17 -5
@@ 6,6 6,9 @@ Licensed under the MIT and Apache 2.0 licenses. See LICENSE files for details.

This script was adapted from stm32-rs (https://github.com/stm32-rs/stm32-rs/blob/master/scripts/svdpatch.py).
To be integrated into the build system, support for an input / output svd argument is added.

Additional changes:
    - Support for _replace_enum to overwrite existing <enumeratedValues>
"""

import copy


@@ 595,6 598,11 @@ def process_register_split(rtag, fspec):

def process_field_enum(pname, rtag, fspec, field, usage="read-write"):
    """Add an enumeratedValues given by field to all fspec in rtag."""
    replace_if_exists = False
    if "_replace_enum" in field:
        field = field["_replace_enum"]
        replace_if_exists = True

    derived = None
    for ftag in iter_fields(rtag, fspec):
        name = ftag.find('name').text


@@ 603,12 611,16 @@ def process_field_enum(pname, rtag, fspec, field, usage="read-write"):
            enum_name = enum.find('name').text
            enum_usage = enum.find('usage').text
            for ev in ftag.iter('enumeratedValues'):
                ev_usage = ev.find('usage').text
                ev_usage_tag = ev.find('usage')
                ev_usage = ev_usage_tag.text if ev_usage_tag is not None else 'read-write'
                if ev_usage == enum_usage or ev_usage == "read-write":
                    print(pname, fspec, field)
                    raise SvdPatchError(
                        "{}: field {} already has enumeratedValues for {}"
                        .format(pname, name, ev_usage))
                    if replace_if_exists:
                        ftag.remove(ev)
                    else:
                        print(pname, fspec, field)
                        raise SvdPatchError(
                            "{}: field {} already has enumeratedValues for {}. Use '_replace_enum' to overwrite."
                            .format(pname, name, ev_usage))
            ftag.append(enum)
            derived = make_derived_enumerated_values(enum_name)
        else:

Do not follow this link