Added early battery undervoltage cutoff

- Added early battery undervoltage cutoff. Improves battery lifespan by
not letting the voltage go so low and the RTC will continue working
since the battery's own PCM hasn't kicked in yet
- Slightly reduced power consumption by going into power save sleep
instead of idle sleep if no other peripherals are in use
- Various code optimisations