You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this snippet, you |= two values, but if I used a number like 0x41 instead of 0x01 here, I could theoretically put the chip into sleep instead of correctly setting the clock source.
Now, in the event that I wanted to set the clock source as 0x07, which I think is valid, and then later change it back to 0x01, I could not with your code.
Consider redoing your assignments to something that clears the bits for the field in the register before OR-ing them.
new_val = (new_val & 0xF8) | (source & 0x07);
would be a much safer way of preventing accidental changes to registers/configs, I think. Nearly every register config function should probably be updated like this.
The text was updated successfully, but these errors were encountered:
Hi again. I can't help but notice that the way you assign values to registers is not friendly or... safe?
In this snippet, you
|=
two values, but if I used a number like 0x41 instead of 0x01 here, I could theoretically put the chip into sleep instead of correctly setting the clock source.Now, in the event that I wanted to set the clock source as 0x07, which I think is valid, and then later change it back to 0x01, I could not with your code.
Consider redoing your assignments to something that clears the bits for the field in the register before OR-ing them.
would be a much safer way of preventing accidental changes to registers/configs, I think. Nearly every register config function should probably be updated like this.
The text was updated successfully, but these errors were encountered: