Ok here it is:
I present bistro-HD (alpha release).
It's called HD because it packs a bunch of new features into non-existent space. (The previous version was >2040 byte out of 2048 available in an attiny25).
E-switch operation, OTSM, voltage-read from VCC pin, QUADRUPLEDOWN (TM) layout (just kidding about the TM, but yes that's 4 PWM channels), and you can have that all at once in an attiny25, and with three channels there's still 200 bytes left to spare.
This version is designed for developmental drivers and so it comes with much overhauled layout and build option configurations that should make it easy to customize.
This was all started with just trying to get OTSM into bistro, but somehow became much more.
For any not following along OTSM is a replacement for the off-time-cap method. It uses a real electronic clock (the watchdog) run by capacitor power to measure off-click times for a couple of seconds. Click lengths are now defined in actual seconds, and old voodoo like changing a resistor from 19.1k to 20k wont affect it. It still needs a little more hardware testing to see just how small the pieces can be kept in the real world. Flashy Mike and Mike C did the initial feasibility tests which really brought this forward and I've added some new technical improvements in this version I think.
Of course this would not be without Toy Keeper who wrote the great original bistro, and many others probably. This version also includes TA's modes for tipples.
So here are my notes I've made as I was adding changes:
/* Flintrock Updates Feb 2017, Bistro-HD release.
* Implements OTSM "off-time sleep mode" to determine click length based on watchdog timer with mcu powered by CAP.
* -CLick lengths are now defined in bistro.c using real fractional seconds.
* They will not change with temperature or resistor values (but they may fail if the cap isn't strong enough).
* -Senses pin fall on pin 7, goes into watchdog wake loop; counts time. Final wake on pin rise,
* -Added powersaving (idle sleep timer) in main loop delays to reduce cap drain while detecting power-off.
* (rough global timer implemented with it but commented out for now).
* -Included option to charge OTC CAP as a secondary OTSM cap, probably less effective than primary cap since it
spills over pin diode. Untested, but it should work.
* -Uses BOD disable to reduce average click sleep power to ~8uA (4 is possible for longer sleeps) on supported chips.
* -For good results requires BODS capable chip revision
(see datasheet page 36, attiny45's seem like best bet, but I have a revision G 25)
* -For best results also requires V version of the chip (not actually verified working/attainable in right revision).
* Adds Vcc inverted voltage read option, with calibration table, allows voltage read of 1S lights without R1/R2 divider hardware.
* Implemented 4th PWM channel.
* -Now can define and use any combination of 4 PWM pins. (PWM1: pb1, PWM2: pb0, PWM3: pb4, PWM4: pb3)
* -PWM disabled on zero-mode to achieve full off on the non phase-correct channel.
* Now supports E-switches.
* -Long press for off, short and mid for short and mid, like clicky.
* -Presently just any tap for on. Could add a timeout double tap?
* -E-switch can share pin with divider/otsm (ex: 4 channel light)
* (but could still be distinguished in functionality with future voltage sense development).
* -Added eswitch lockout toggle (Menu option 9) (except if shared with voltage/OTSM pin, for now).
* Added define to use Vcc as a refernce for reading the voltage divider (not the same as reading Vcc).
* This should be used for LDO builds if OTSM is read from the voltage pin, and R1/R2 should keep on voltage > 1.8V.
* Algorithm-generated calibration tables now allow voltage adjustment with one or two configs in fr-calibration.h
* -For traditional voltage read, one measurement should be enough for from-scratch calibration (I hope)
* and small adjustments are probably fine for, well small adjustments.
* New fr-attiny.h simplifies layout definitions and provides more easily-customizable layouts for future boards.
* Added BODS to voltage shutdown (and E-switch poweroff) to protect low batteries longer (~4uA for supported chips).
* #define VOLTAGE_CAL results in a battcheck-like build, blinks ADC value,
produces VCC or divider values according to config
* Implements space savings (required for the other features, but some left over):
* -implement TK size optimizations
* -Save variables now stored in array for looped save/restore/toggle instructions (big savings).
* -implement 0 termination of mode group definitions,
* Side effect: could now have a couple of very long ( >8) groups without much memory cost at all.
* -Big overhaul to count_modes code, saves a few bytes.
* -Many more size optimizations, especially in new ISR's
* Includes a blink_value function for debugging, blink_value(255) blinks strobe 2 __ 5 __ 5 strobe for example.
* (It's optimized out if not used, well, seems that requires the right linker flags.)
Note: Disabling OFFTIM3 no longer disables timing mechanism. OTSM or OTC can be used for long/short only builds.
although it's not clear how much sense that makes. If you want to save space, you'll still want to disable OTSM and OTC.
If you just want to turn off 3-way mode, you can just set the default menu option.
With all new features disabled (99% of them anyway), compiles to ~ 1742 bytes (so 300 bytes reduction).
Including every new feature at once (except debug options), in QUADRUPLEDOWN_LAYOUT with ESWITCH, OTC, and VCC read, it's 2002
bytes. (eswitch and OTSM is smaller because eswitch and otsm use the same coding, OTC requires extra.
Divider read is still possible with this layout too and saves 16 bytes)
A more standard tripple build with OTSM and VCC read is 1828 bytes, but there are many combinations. That leaves quite a bit of space.
modegroup.h ramp and modegroup definitions are now separated out int modegroup.h This allows separation of code development from modegroup
development and allows different modegroups to be defined for different builds, either adding defines or using separate files.
Bugs: There are MANY combinations of features and layouts that can be compiled in and the new features have very interconnected logic.
I've tried to think about how to make them all work in any combination, and test many or most I hope, but there are probably
exceptions/bugs. Particulary making eswitch and OTC (for clicky) work at the same time took some last minute thought, sinc
e-switch was built around OTSM. But it >>should<< work now. In principle you can have eswitch, OTSM and voltage read on the
same pin, separate pins, separate switch pins with OTC for the clicky, etc. The fallback fastpresses mode still exists too and
does off-time without any cap (it could use some updates for reliability). So there are sort of 4 ways to measure off time.