japaric-archived / photon-hal

Low level Rust bindings to particle's HAL (Hardware Abstraction Layer)
Apache License 2.0
9 stars 8 forks source link

Support system modes #16

Open dbrgn opened 7 years ago

dbrgn commented 7 years ago

Is there already a way to support system modes?

https://docs.particle.io/reference/firmware/photon/#system-modes

I tried to add bindings, but this is a bit above my knowledge level since it seems to set global state.

japaric commented 7 years ago

Hmm, I think the global variable is just there to prevent calling SYSTEM_MODE(AUTOMATIC); and also SYSTEM_MODE(MANUAL); from the same program. You could start by directly trying to call the set_system_mode function from main. If that works then we can add a Rusty mechanism to prevent calling that function twice.

japaric commented 7 years ago

Thinking about this a bit more. Since this is C++ this global state may also be being used to call set_system_mode before main runs. If that's the case then we can use something like .init_array to do the same from Rust. Better to look at the disassembly to figure out when set_system_mode is called.