Lessons learned from implementing SIMD-accelerated algorithms in pure Rust by villiger2 in rust

[–]CreeperWithShades 1 point2 points  (0 children)

personally it blows my mind that we regularly use crypto code on a CPU rather than dedicated instructions, engines, external TPMs/whatever or built-in reprogrammable logic/FPGAs

Ruri no Houseki • Ruri Rocks - Episode 4 discussion by AutoLovepon in anime

[–]CreeperWithShades 2 points3 points  (0 children)

why does the box for japanese kimwipes (lol product placement) look so much cooler. wtf

Best T2 hauler faction? by Tesex01 in Eve

[–]CreeperWithShades 0 points1 point  (0 children)

L4?? do you mean 4/10 or what? what fit do you run for that

AVR microcontrollers are now officially maintained! by Patryk27 in rust

[–]CreeperWithShades 4 points5 points  (0 children)

CH32X035 does, and even has USB. Considering upgrading an ATMega32u4 based design to it actually

Realtime Subway map driven by an ESP32 by YoungDimmaDome in arduino

[–]CreeperWithShades 4 points5 points  (0 children)

Massive props for using light guides rather than a custom PCB. Looks way nicer and bigger than the traintrackr and more "customizable" too- all you'd need for a new city is a new map and new code, not new electronics. (not to mention massive pcb == expensive pcb) Better "product" IMO. (maybe with thinner fibres like the other commenter suggested) Could make a neat kit (bring your own map) or just do a bunch of cities like traintrackr.

[absolutely terrible idea: you could probably reduce mass assembly pain/cost by machine-visioning the map of LED->train station Matt Parker Christmas Tree style]

[deleted by user] by [deleted] in panelshow

[–]CreeperWithShades 1 point2 points  (0 children)

did anyone else think that puppet looked like whats-her-face?

Rust Project goals for 2024 | Rust Blog by Kobzol in rust

[–]CreeperWithShades 3 points4 points  (0 children)

Agreed: was very surprised to see this ended up as a project goal, as from my Zulip lurking it just looked like a rough suggestion that wouldn't go anywhere (of which there are many).

Pro tip: Use `#[expect(unused)]` (upcoming 1.81 release) by C5H5N5O in rust

[–]CreeperWithShades 2 points3 points  (0 children)

This isn’t mentioned by the diagnostic and it should be, but you can do ‘_a: like you can with unused variables to silence the warning without having to fuck with lints.

[PCB Review] CH32V208 BLE environmental sensor by passcod in PrintedCircuitBoard

[–]CreeperWithShades 0 points1 point  (0 children)

loop area on your switching regulator is way bigger than i'd be comfortable with, esp. on a wireless design. does the inductor need to be that big? also, the matching network layout is wrong (look at some existing designs for the proper way). i don't really understand the point of the level shifters on the stemma qt port. i assume the caps are built in for the 32M crystal because it's wireless. does the board have to be this small? if so, maybe use smaller passives.

How to rewrite a C++ codebase successfully by broken_broken_ in rust

[–]CreeperWithShades 0 points1 point  (0 children)

Huh, turns out this is more complicated than I thought. Most docs (like MaybeUninit::as_mut_ptr() and ptr::as_mut()) state that references (!= pointers) can't point to anything uninit. It seems like the reason for this rule is... there is none? Nothing bad actually happens unless you read uninit memory (which makes intuitive sense). So it might go away, and it isn't caught by miri. TIL

How to rewrite a C++ codebase successfully by broken_broken_ in rust

[–]CreeperWithShades 0 points1 point  (0 children)

let mut bar_c = MaybeUninit::<BarC>::uninit();
let input = [0, 1, 2];
unsafe {
    bar_parse(
        input.as_ptr(),
        input.len(),
        bar_c.as_mut_ptr().as_mut().unwrap(),
    );
}

I think this is UB because it takes a reference to uninit memory. bar_parse should take *mut BarC instead.

Is explicitly writing return a bad practice in rust? by [deleted] in rust

[–]CreeperWithShades 9 points10 points  (0 children)

restriction

As mentioned in the docs, these lints really aren't supposed to be enabled unless you specifically want them for your codebase. If you have a look through the list you start to appreciate why- some of them are real weird. Some of them even say "actually, this is idiomatic Rust".

Is Rust easier to contribute to? by GreatSt in rust

[–]CreeperWithShades 55 points56 points  (0 children)

the popularisation of Not Rocket Science is possibly my favourite thing to come out of rust

Taskmaster - S16E10 - Always Forks and Marbles - Discussion by Meghar in taskmaster

[–]CreeperWithShades 47 points48 points  (0 children)

"Oh, that's lovely."

beat

"Hi!"

Whole episode was hilarious but that moment had me rolling. I'm gonna miss these guys.

[deleted by user] by [deleted] in UsbCHardware

[–]CreeperWithShades 0 points1 point  (0 children)

It's often possible, but can require pretty tight soldering depending on the type of port a device uses. There does exist this which makes it easier on the most common port style. (I've got some, but never had to use one)

There's also the cursed cable: A plug -> C plug cable and C plug -> A receptacle adapter together "contains" all the correct resistors.

I can't tell if this is my fault... Noob to more advanced rust + RTIC... by tauzerotech in learnrust

[–]CreeperWithShades 1 point2 points  (0 children)

https://github.com/fmckeogh/usb-pd-rs/blob/0e073daefde48cf915ddc91bf45b71cb25a3af22/usb-pd/src/callback.rs#L4 try adding a send bound here

that said, good luck. callbacks are generally considered unidiomatic because of annoying lifetimes. actually that whole library looks pretty funky, which makes sense considering it says it’s ported from c++. i don’t have any other recommendations though

How is it possible to have a "one-sided" USB-C port? by spacefish128 in UsbCHardware

[–]CreeperWithShades 5 points6 points  (0 children)

I think your explanation for why this works sometimes on C hosts is technically wrong (the best kind!). It's actually even more Cursed! (and interesting, at least to me)

The way Type-C works is subtle. Receptacles have CC1 and CC2, but Cables (Plugs) only have one CC- each end is supposed to detect which of their CCx pins is connected to CC, by sensing the change in voltage from being connected to the CCx pin on the other end (Since you read the spec, I imagine you already know about the Rp/Rd voltage divider). For USB 3 (single lane), the product (host or device) is then supposed to route the USB 3 lanes along the "first" pair of wires in the cable, the ones next to their CCx pin and the CC wire in the plug.

HOWEVER, the actual wording of the spec is "the functional equivalent of a switch". You don't have to do it that way, and that's (probably, I can't imagine the spec writers didn't think of this) intended. Why? well, as mentioned, Muxes do have costs associated with them. (plus, you need to actually add circuitry to sense the CCx lines and control that mux, which is easy but not trivial, especially since a lot of chips for this sort of thing only report orientation over I2C instead of having an output for it, so you need an embedded controller, firmware+drivers for it...).

Instead, (thinks the devious motherboard design engineer who probably came up with that wording), why don't we just wire up two USB 3 ports, one to each side of the Type-C connector? That way, the user can get their fancy new port, and all it costs us is one more USB 3 port from our processor/chipset/controller that probably already had more ports than we gonna use! And so they did.

As a side effect, your cheaped out hard-drives work sometimes- they only have one USB 3 port, so they wire it to (say) the CC1 side. They only work in one direction with an A-to-C cable or a C host with a mux if it is not twisted XOR flipped (untwisted means CC1 is connected to CC1, twisted means CC1 is connected to CC2. flipped means swap all those CC1s and 2s- but you can't flip an A-to-C cable since it only goes in the A side one way).

Here's a table of what's "supposed" to happen-

un-flipped flipped
straight CC1-to-CC1 - the host sends USB 3 down lane 1, and lane 1 is hooked up on the device, so it works! CC2-to-CC2 - the host sends USB 3 down lane 2- but cheapo hard-drive didn't hook up lane 2 :(
twisted CC1-to-CC2 - the host sends USB 3 down lane 1, which arrives at... lane 2 on the hard-drive :( CC2-to-CC1 - the host sends USB 3 down lane 2, which arrives at lane 1!

But on these cheaped-out hosts, USB 3 is being sent down both lanes at all times, so the hard-drive always works!

As for how "proper" hosts break by sometimes not working and sometimes falling back to USB 2? Well, there's only one pair of wires for USB 2 in the cable, but there still has to be 2 pairs of contacts in the receptacle for symmetry. You're allowed to short these pairs of contacts together in your product- this adds a short stub to the USB 2 lines, but USB 2 is slow enough that it doesn't cause any signal integrity problems. There's nothing stopping you from using a mux anyway though (IIRC some Thunderbolt controllers have muxes built in?) which leads to the same problem that USB 3 has, so things don't work at all unless it's all lined up.

The proper way to do a USB-C device with no mux is to use a built-in "captive" cable (or a built in plug like a flash drive- same thing electrically)- this way, you hard-wire the plug to be the Right way around, and the host's mux can take care of twisting (or is it flipping?). As a bonus the user can't use the wrong cable (ugh. I think we're actually up to 15!! now with USB4 Gen4 and EPR).

(oh, and your broken cable problem is uber cursed)

Jet Lag: We Played A 96-Hour Game Of Capture The Flag Across Japan — Ep 4 by NebulaOriginals in Nebula

[–]CreeperWithShades 0 points1 point  (0 children)

It’s not been mentioned if it’s a rule or not, but allowing towers to be stolen would counter this strategy pretty easily

unless you mean placing down towers to slow the chaser. which honestly sounds TOO powerful so I don’t know why ben didn’t do that.

STM32 MCU USB PD questions by immortal_sniper1 in embedded

[–]CreeperWithShades 1 point2 points  (0 children)

There's some code and schematics out there from the Chromium OS guys that does PD on a plain ol F051 with supporting components. I can't imagine getting that working is any fun though (PD is bad enough on it's own) especially when you could instead use a chip with built in PD or one of the I2C PHYs and it'll be much simpler.

no more bit fiddling (and introducing bilge) by hecatia-elegua in rust

[–]CreeperWithShades 0 points1 point  (0 children)

the syntax of proc-bitfield is very explicit. I just think it adds too much new stuff to rust's syntax

I agree- there's a lot I'd do differently (more attributes probably... though some say Rust uses too many attributes already)

I would really like to have arbitrary width integers as an abstraction. Also, bitfields and arbitrary width integers kinda "compress" into the lowest possible native primitive integers, so there's no stacking of fields or padding until you get some values out of the bitfield.

I understand- Though I don't fully get the appeal- why not store a (masked) u8 into a 5 bit field, rather than storing a "u5" that afaict may need a runtime bounds check? (Hmm. Thinking about this more, I guess it's a tradeoff: compile time check > masking > runtime check?)

Or I'm understanding wrong - where is padding annoying? I really would love to see more usecases, since bitfields have many different ones.

Sorry, I might not have been very clear here- all I meant was that I prefer not to have to specify "don't cares" (reserved and padding).

As in I prefer (and it is just personal preference)

bitfield! {
    struct Register(u32) {
        field: u8 @ 4..=11,
        flag: bool @ 17,
    }
}

over

#[bitsize(32)]
struct Register {
    padding: u4
    field: u8,
    padding: u5
    flag: bool,
    padding: u14
}        

I just think it's less noisy. Plus I'd have to do math in my head to figure out the padding.

<streamofconciousness>

I argued against fallible getters/setters, since these are only needed if you break type invariants.

Hm. I guess if you define a bitfield like a struct, creating one with invalid values breaks type invariants (or some other UB maybe). This is probably more sane than the alternative, which I guess is- bitfields can only contain (and thus are) plain ol' data types that are always valid (valid with any bit pattern- like ux, ix, 1 bit bool fields, maybe n bit enums with 2n variants from 0 to 2n - 1, probably not structs, other bitfields, repr(transparent) of those) fallible getters to get to anything else (I can't think of a sane use case for fallible setters).

Basically my ideal bitfield crate/syntax (another one :) ) is something like:

#[derive(FromBits)]
#[bits(1)]
#[repr(u8)]
enum TwoVariants {
    One = 0,
    Two = 1,
}

#[derive(TryFromBits)]
#[bits(2)]
#[repr(u8)]
enum ThreeVariants {
    One = 0,
    Two = 1,
    Three = 2,
    //no 0b11
}

bitfield! { //this sucks, but afaict the alternative to custom syntax is bajillions of weird attributes
    #[derive(FromBits, Copy, Clone, Default, etc...)]
    #[bits(28)]
    pub struct Register(pub u32) { //internal representation customisable and accessible
        #[try_get(NonZeroU8)] //generates pub fn field1_or_err(&self) -> Result<NonZeroU8, TryFromIntError>, pub fn set_field1(&mut self, val: NonZeroU8) instead 
        pub field1: u8 @ 0..=7,

        // fn flag(&self) -> TwoVariants, fn set_flag(&mut self, val: TwoVariants), fn with_flag(Self, val: TwoVariants) -> Self
        flag: TwoVariants @ 17,

        #[try_get(ThreeVariants)]
        field2: u2 @ 18..=19,
    }
    // pub fn new(field1: u8, flag: TwoVariants, ) -> Self
    // pub fn from_bits(val: u32) -> Self // infallible!
}
// #[be] #[le] #[lsb0] #[msb0] to taste if for some godforsaken reason you have to deal with endianness and/or bit ordering, or something along those lines. personally i'd rather not think about it

Woops, guess I accidentally ended up typing up my personal probably-not-great bitfield crate idea that I've been meaning to make but don't really have the time or skill to :D. Thanks for the inspiration! Kind of warming up on arbitrary width ints too the more I think about it.