ChanServ changed the topic of #zig to: zig programming language | ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
<skyfex>
And then @offsetOf(PinCnf, "drive") returns 0
<andrewrk>
what would you expect it to return?
dimenus has quit [Ping timeout: 268 seconds]
<andrewrk>
maybe it should be renamed to @byteOffsetOf
<skyfex>
Hmm, I haven't tested it enough, seems I get the same if I set dir/input/pull to u2 as well
<andrewrk>
oh, there's an extra byte in here I didn't see
<andrewrk>
it should return 1 for drive
<andrewrk>
oh wait, I know what's going on
<andrewrk>
ok so if you walk over the fields 1 by 1 and notice when you hit a byte boundary
<andrewrk>
there's a byte boundary at offset 0
<andrewrk>
then we see 1 bit (bit offset 1), 1 bit (bit offset 2), 4 bits (bit offset 6), 4 bits (bit offset 10), 3 bits (bit offset 13), 2 bits (bit offset 15)
<andrewrk>
none of those are on a byte boundary
<andrewrk>
so the whole thing is represented as a u16 and masking/shifting is done to load/store
<andrewrk>
so the offset of all the fields is 0, which is the offset of the u16 where the bit fields are inside
<andrewrk>
if you explain what you need to use @offsetOf for, maybe I can suggest the best way to accomplish your goal
<skyfex>
Odd, but I guess that makes sense in a way
<jjido>
OffsetOf is little help with packed isn't it
<skyfex>
I wasn't really after byte offset anyway, I was just trying it out. What I'd really be interested in is bit offset
<andrewrk>
we could have that
<andrewrk>
maybe we rename @offsetOf to @byteOffsetOf and add @bitOffsetOf
<andrewrk>
jjido, yes, the problem is you need a special kind of pointer to point to a bit field - a pointer that has the bit offset from the address in the type
<skyfex>
But hopefully, if packed structs are implemented well enough, you wouldn't need it. But if it's possible to specify all of a microcontrollers register with packed structs, it would be nice to be able to get their offsets from there, instead of having to define a whole bunch of constants in addition
<skyfex>
Just in case
<andrewrk>
I see
<andrewrk>
yeah, that would make sense, and it's a straightforward builtin function to add
<skyfex>
FYI, I got a piece of Zig code to run on the micro:bit / nRF51822 on monday.
<jjido>
You could have offsetOf and an additional bitShift (relative to offset) for packed struct
<andrewrk>
awesome! what cpu arch is that?
<skyfex>
Although I had to use GCC to link.. some issue with the linker script and LLVM
<skyfex>
ARM Cortex M0
<andrewrk>
I'd be curious to reproduce the linker issue - I could get a bug report filed for the LLD project. it's pretty active
<andrewrk>
I could also try it with llvm6 which has a lot of LLD improvements
<skyfex>
I can put up my example on github.. it's quite small, so should be useful for reproduction
<andrewrk>
I'd appreciate that
<skyfex>
And I hope I can make a decent example and writeup to illustrate how Zig could be useful on microcontrollers. Not sure if I should wait for 0.2 or not though.. depends on what issues I find
<andrewrk>
I'm interested to work with you on working out all the major issues you run into, such as this linker thing
<skyfex>
Ah yeah, like i wrote in the Github comment, specifying the type for enum tags would be great
<andrewrk>
the enum tag type should be reasonably easy to implement too
<skyfex>
Then I could generate a really nice struct definition of the registers from the XML spec
<andrewrk>
there was some confusion on that issue, but now I know how to proceed
<skyfex>
cool. I was worried that the packing was incorrect, but since it's not I can continue to play around with mapping registers to struct, but without enums for now
<skyfex>
i would like to play around a bit with io and fmt over UART as well, before I publish anything. That might lead to some valuable feedback