Skip to content

Commit

Permalink
feature has same id as peripheral name
Browse files Browse the repository at this point in the history
Features shall have a name that is understandable by end user. Now features has the same id as peripheral name. Peripheral name is used in debugger view as well.

Fixed duplicated feature in 'all' feature
  • Loading branch information
pellico committed Sep 10, 2024
1 parent 0f95693 commit a89f625
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
12 changes: 9 additions & 3 deletions templates/rust/Cargo_toml.tera
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,22 @@ cortex-m = "0.7.6"


[features]
{%- set_global all_peripheral_features = [] -%} {# array of all features #}
{%- for peri_mod_name, peri in ir.device.peripheral_mod %}
{%- if peri.is_derived_from %} {% continue %} {% endif %} {# module that are derived doesn't have a module #}
{{peri.module_id}} = []
{%- set feature_name = peri.name | lower -%}
{% set_global all_peripheral_features = all_peripheral_features | concat(with=feature_name) %}
{{feature_name}} = []
{%- endfor %}
{% if ir_csfr %}
{%- for peri_mod_name, peri in ir_csfr.device.peripheral_mod %}
{{peri.module_id}} = []
{%- set feature_name = peri.name | lower %}
{{feature_name}} = []
{%- endfor %}
{%- endif %}
all = [{%- for peri_mod_name, peri in ir.device.peripheral_mod -%}"{{peri.module_id}}",{%- endfor -%}]
{# collect all module id and remove duplicated#}
{%- set_global all_peripheral_features = all_peripheral_features | unique -%}
all = ["{{all_peripheral_features | join(sep='" ,"')}}"]
{%- if tracing %}
tracing = ["dep:phf"]
tracing_dummy = []
Expand Down
27 changes: 17 additions & 10 deletions templates/rust/lib.tera
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,34 @@ pub mod tracing;
{% for peri_mod_name, peri in ir.device.peripheral_mod -%}
{%- if peri.is_derived_from %} {% continue %} {% endif %} {# module that are derived doesn't have a module #}
{%- set module_name = peri.module_id -%}
#[cfg(feature = "{{module_name}}")]
{%- set feature_name = peri.name | lower -%}
#[cfg(feature = "{{feature_name}}")]
pub mod {{module_name}};
{% endfor -%} {# for peri_mod_name, peri in ir.peripheral_mod #}
{% if ir_csfr %}
{% for peri_mod_name, peri in ir_csfr.device.peripheral_mod -%}
{%- set module_name = peri.module_id -%}
#[cfg(feature = "{{module_name}}")]
{%- set feature_name = peri.name | lower -%}
#[cfg(feature = "{{feature_name}}")]
pub mod {{module_name}};
#[cfg(feature = "{{module_name}}")]
#[cfg(feature = "{{feature_name}}")]
pub use {{module_name}} as csfr_cpu;
{% endfor -%}
{% endif %}

{% for name,p in ir.device.peripheral_mod %}
{%- set module_name = p.module_id -%}
{% set peri_struct = p.struct_id -%}
{%- set feature_name = p.name | lower -%}
{%- if not p.is_derived_from -%}
#[cfg(feature = "{{module_name}}")] {# Peripheral definition #}
#[cfg(feature = "{{feature_name}}")] {# Peripheral definition #}
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct {{ peri_struct }}{ptr:*mut u8}
{%- endif -%}
{# Peripheral instances #}
{%- set module_struct = p.struct_id -%}
{%- set full_path_struct = "self::" ~ module_struct -%}
#[cfg(feature = "{{module_name}}")]
#[cfg(feature = "{{feature_name}}")]
{%- if p.base_addr | length == 1 %}
pub const {{name | upper}}: {{full_path_struct}} = {{full_path_struct}}{ptr:{{p.base_addr[0] | to_hex }}u32 as _};
{% else %}
Expand All @@ -63,7 +66,8 @@ pub const {{name | upper}}:[{{full_path_struct}};{{ p.base_addr | length }}] = [
{%- set full_path_struct = "self::" ~ module_struct -%}
{% for name,p in ir_csfr.device.peripheral_mod %}
{%- set module_name = p.module_id -%}
{% if not loop.last %}feature = "{{module_name}}",{% else %}feature = "{{module_name}}"))]
{%- set feature_name = p.name | lower -%}
{% if not loop.last %}feature = "{{feature_name}}",{% else %}feature = "{{feature_name}}"))]
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct {{ module_struct }}{ptr:*mut u8}
{% endif %}
Expand All @@ -73,7 +77,8 @@ pub struct {{ module_struct }}{ptr:*mut u8}
{%- set full_path_struct = "self::" ~ module_struct -%}
{% for name,p in ir_csfr.device.peripheral_mod %}
{%- set module_name = p.module_id -%}
{% if not loop.last %}feature = "{{module_name}}",{% else %}feature = "{{module_name}}"))]
{%- set feature_name = p.name | lower -%}
{% if not loop.last %}feature = "{{feature_name}}",{% else %}feature = "{{feature_name}}"))]
{%- if p.base_addr | length == 1 %}
pub const {{"csfr_cpu" | upper}}: {{full_path_struct}} = {{full_path_struct}}{ptr:{{p.base_addr[0] | to_hex }}u32 as _};
{% else %}
Expand Down Expand Up @@ -149,8 +154,9 @@ pub struct Peripherals {
{% for name,p in ir.device.peripheral_mod %}
{%- set module_name = p.module_id -%}
{%- set module_struct = p.struct_id -%}
{%- set feature_name = p.name | lower -%}
{%- set full_path_struct = "self::" ~ module_struct -%}
#[cfg(feature = "{{module_name}}")]
#[cfg(feature = "{{feature_name}}")]
{%- if p.base_addr | length == 1 %}
pub {{name | upper}}: {{full_path_struct}},
{% else %}
Expand All @@ -162,7 +168,7 @@ pub struct Peripherals {
{%- set module_name = p.module_id -%}
{%- set module_struct = p.struct_id -%}
{%- set full_path_struct = module_name ~ "::" ~ module_struct -%}
#[cfg(feature = "{{module_name}}")]
#[cfg(feature = "{{feature_name}}")]
{%- if p.base_addr | length == 1 %}
pub {{name | upper}}: {{full_path_struct}},
{% else %}
Expand Down Expand Up @@ -192,7 +198,8 @@ impl Peripherals {
{%- set module_name = p.module_id -%}
{%- set module_struct = p.struct_id -%}
{%- set full_path_struct = module_name ~ "::" ~ module_struct %}
#[cfg(feature = "{{module_name}}")]
{%- set feature_name = p.name | lower -%}
#[cfg(feature = "{{feature_name}}")]
{{name | upper}}: crate::{{name | upper}},
{%- endfor %}

Expand Down

0 comments on commit a89f625

Please sign in to comment.