I have been considering this, but I have not implemented it yet.
In fact, I think there are three different ways to implement this.....
A) The first way I considered was to use an actual hardware feedback loop.
This would be a true constant-voltage drive. However, it turns out to
be somewhat difficult to implement, and the FET would have to absorb the
extra voltage, making it heat up and possibly damage it.
B) The second way is to use a very very fast PWM signal to achieve something
similar. Since the gate on the FET is basically a capacitor, it would smooth
out the PWM signal. However, I don't think that would work well because the
transition region for the FET can vary from transistor to transistor, so without
a feedback loop there is no way to know exactly what the output voltage would be.
And, even if it worked, the FET would still heat up a lot.
C) The third way is to stay at the same PWM rate as before, but simply reduce the
time we spend in the "on" state per cycle if the voltage is too high.
Basically, if your led is made for 3.8 volt, but the battery is currently at 4.0 volt,
we would turn the PWM to 3.8/4.0 = 95%. The LED would still get hit with the full 4.0
voltage, but hopefully it wouldn't over-heat and die since it's not on 100%.
Doing it this way would prevent the FET from over-heating, but I also don't know how well it
works. LEDs are non-linear and turning it off for 5% of the time might not be enough to
protect it from dying. It might also affect the brightness and color of the LEDs in ways
that could be annoying. (Or not, I simply don't know yet.)
For my setup, I use resistors to bring down the voltage a bit to match the LEDs, but I
use the nominal voltage of the battery (3.7 volts) for the resistor calculations. Since
the voltage of the battery is often higher than this when fully charged, I was thinking
that using one of the solutions above might be good. But as I said: I have not actually
tried this yet. Option (C) would be fairly easy to implement though.