Skip to content

rp2xxx: Remove SchmittTrigger, use Enabled#635

Merged
tact1m4n3 merged 7 commits intoZigEmbeddedGroup:mainfrom
Gnyblast:main
Aug 13, 2025
Merged

rp2xxx: Remove SchmittTrigger, use Enabled#635
tact1m4n3 merged 7 commits intoZigEmbeddedGroup:mainfrom
Gnyblast:main

Conversation

@Gnyblast
Copy link
Contributor

@Gnyblast Gnyblast commented Aug 4, 2025

Code:

const pin_config = rp2xxx.pins.GlobalConfiguration{
    .GPIO29 = .{
        .name = "relay",
        .direction = .out,
    },
    .GPIO28 = .{
        .name = "sensor",
        .direction = .in,
    },
    .GPIO27 = .{
        .name = "capacitor",
        .direction = .in,
    },
    .GPIO4 = .{
        .name = "SDA",
        .function = .I2C0_SDA,
        .schmitt_trigger = .enabled,
        .slew_rate = .slow,
    },
    .GPIO5 = .{
        .name = "SCL",
        .function = .I2C0_SCL,
        .schmitt_trigger = .enabled,
        .slew_rate = .slow,
    },
};

pub fn main() void {
    pin_config.apply();
}

Causing:

install
└─ install generated to light-mcu.uf2
   └─ run elf2uf2 (light-mcu.uf2)
      └─ zig build-exe light-mcu ReleaseSmall thumb-freestanding-eabi 1 errors
/home/guney/.cache/zig/p/mz_port_raspberrypi_rp2xxx-0.0.0-wCvtidmzDQDWXpsuqBY_8dkz96PsJ_rrMKX04haxvjRt/src/hal/pins.zig:944:60: error: expected type 'hal.gpio.Enabled', found 'hal.gpio.SchmittTrigger'
                    gpio.num(gpio_num).set_schmitt_trigger(enabled);

When I dig into the code base. I realized that gpio config uses SchmittTrigger but set_schmitt_trigger in pins.zig uses Enabled so if you pass SchmittTrigger enum the pins.zig fails, if you pass Enabled then gpio.zig fails.

I honestly couldn't see if there was a purpose of having them twice(ish), but looks like causing trouble if I'm not really doing something completely stupid.

@Grazfather Grazfather changed the title Remove Enabled, use SchmittTrigger rp2xxx: Remove Enabled, use SchmittTrigger Aug 4, 2025
Copy link
Collaborator

@Grazfather Grazfather left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I noticed set_input_enabled uses a bool. We might want to use this enum there for consistency.

@Gnyblast
Copy link
Contributor Author

Gnyblast commented Aug 5, 2025

Isn't it looking a bit weird in terms of code readability? I mean SchmittTrigger related methods are asking for SchmittTrigger enums but for a set_input_enabled method which has nothing to do with SchmittTrigger, the parameter named SchmittTrigger looked a bit confusing to me.

    pub inline fn set_input_enabled(pin: Pin, enabled: SchmittTrigger) void {
        const pads_reg = pin.get_pads_reg();
        pads_reg.modify(.{ .IE = @intFromEnum(enabled) });
    }

@Gnyblast
Copy link
Contributor Author

Gnyblast commented Aug 5, 2025

Maybe we should have kept the Enabled enum and then use it for both SchmittTrigger related methods and all other methods that takes enabled bool including also: set_output_disabled.

@Grazfather
Copy link
Collaborator

Yes that is what I was suggesting.

@Gnyblast Gnyblast changed the title rp2xxx: Remove Enabled, use SchmittTrigger rp2xxx: Remove SchmittTrigger, use Enabled Aug 6, 2025
@tact1m4n3
Copy link
Collaborator

I'd say to keep Enabled for set_schmitt_trigger for now and leave the others as they are.

@Gnyblast
Copy link
Contributor Author

So what's the final verdict? Enabled should be used in set_input_enabled or not?

@tact1m4n3
Copy link
Collaborator

Imo no

…ymore

- Removed all Enabled enum usage in schmitt trigger and turned them to be bool only
- Only GPIO confing uses now the Enabled enum for user-friendly readability
@Gnyblast Gnyblast requested a review from tact1m4n3 August 13, 2025 09:04
Copy link
Collaborator

@tact1m4n3 tact1m4n3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor changes and we're good to go

- Remove switch and use logical eval
@Gnyblast
Copy link
Contributor Author

A few minor changes and we're good to go

All done I guess.

@tact1m4n3
Copy link
Collaborator

Nice! Thank you!

Copy link
Collaborator

@tact1m4n3 tact1m4n3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a typo :)

@tact1m4n3 tact1m4n3 merged commit 90d33ed into ZigEmbeddedGroup:main Aug 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants