STAR Firmware by JonnyC - Source Code and Explanation

TK, would it be easier to add mode memory to the STAR momentary FW? I feel like that’s all it would take to make it work as a dual-switch FW, and it already has dual-pwm

(of course, I think we’d all love it if you were to make your own dual-switch FW :wink: Soft-toggling memory would be really nice on a dual switch light, and better control of the second channel would be welcome as well)

You know, I’m not sure what the easiest option would be.

There should be room to add a bit of eeprom save/restore code to STAR_momentary, but I doubt there would be room to add much more.

The momentary switch code is significantly more complicated than clicky switch code and uses more room, so it’s kind of hard to fit both. However, I haven’t seriously tried so I’m not sure how hard it is.

If I can do it without so many interrupt handlers, maybe I can save enough room to fit both plus extras, but I get the feeling I’ll have to basically start from scratch in order to make any significant progress.

Question: Is there a way to have STAR dual-switch recognize when the e-switch is held while power is turned on? So that moon or strobe is accessible from off by holding the mode switch while the main power switch is clicked? Perhaps by checking e-switch status once outside of the main loop so it only checks it when power is first applied?

Sure, it should be very possible to have a different response for “power connected while switch is up” versus “power connected while switch is down”. I don’t think anyone has tried it, but it should be easy.

I haven’t been doing e-switch stuff lately, but have been itching to start on a FET+1 e-switch project. I definitely won’t have time for like a month though, and would need some extra parts.

If only we all had more time, right? :slight_smile:

I need to increase my own understanding of how the code actually functions. It’s probably my weakest point.

I tried combining my e-switch version with my NOINIT (power switch) in order to get full functionality on both switch's, but ran out of code space. I just ordered a few ATTiny45's - they have 4 * code and data space. There's been some successful porting effort goin on, so hoping I can get these up and running.

Update: Mission Accomplished! Got it working now on a ATtiny45. Some details here:, post #115.

Awesome. :slight_smile:

I’m hoping I can fit both by reducing the use of interrupts and volatile variables in the e-switch code. I’ll probably still need 2K to fit both the A6 code and the smooth ramping code though.

Ahh, yes. The only down side to the 25's now is the cost, but I really haven't done much shopping around yet. Mouser is a killer for shipping and NYS taxes, so $30 becomes $40 easy. Dunno yet where to go next. Would like to get temp sensor working, but also would love to get what I have now into a X6R, Convoy L4, Warsun X60, Y3, etc. We know of course, temp sensor and 25/45/85's have been implemented by or for BLFers, but no one apparently has posted any helpful details - obviously could be good reason why they can't, dunno.

Would this be the right one?

That is the larger size. You would need to bend the pin down slightly for most drivers, except the 22mm DD+7135 wight driver board. A direct drop in would be the SSU package on other boards/drivers. If you are willing to use the larger SU package, you can get 10 for $16.20 here:

These are what I'm using. They seem to work fine. As of last night, I have 3 of them up and working in different types of drivers. Of the 5 I have connected to a programmer, all 5 successfully connected..

Well at least it looks like it's worth looking around. These are the 25's with the same package as the 13A's:

ATtiny25V-10SSU (I ordered these from Mouser, qty 10 for $19.50, total order: $32.64, total payment: $39.63)




In the same Mouser order, I also ordered qty 3 of these: ATTINY85V-10SU for $2.42 each.

Just doing a search on the SSU part # on AliExpress found qty 10 for like $13-$14 which is a pretty good deal, just hope these haven't been pre-programmed with the reset bit set as an I/O pin - this happened to me for a qty 10 order of 13A's on eBay.

Tom E wrote:

I tried combining my e-switch version with my NOINIT (power switch) in order to get full functionality on both switch's, but ran out of code space. I just ordered a few ATTiny45's - they have 4 * code and data space. There's been some successful porting effort goin on, so hoping I can get these up and running.

Update: Mission Accomplished! Got it working now on a ATtiny45. Some details here:, post #115.

At the above link, Tom E wrote:

. . . I did get brown out detection OFF time method working, and it's working in the eswitch version. So, I have firmware that is 1074 bytes running on a 45, about 26% code space used, and has a fully functioning power clicky switch support with mode memory and OFF time support, as well as full e-switch support! Best Of Both . Dang, this is getting easy...

Using that Fuse calculator too, I am using these fuse values to enable this combo of features:

-Ulfuse:w:0xE2:m -Uhfuse:w:0xdf:m -Uefuse:w:0xfe:m

Basically, I melded the STAR_NOINIT stuff into my eswitch version. This is where I ran out of code space before, and why I got into the 25/45/85's, specially since ImA4Wheelr got it basically up initially.

For the fuses, I analyzed what was done for the full brown-out detection, and made the same settings for the 45 family. With the Fuse Calculator, it was pretty easy to do.

Really sounds complicated to combine those functionalities. Would love to try in a couple of lights if you at a point you wouldn't mind sharing it. Could it be used in a e-switch light to assist with lock out? Something like, the light can't be turned off with the momentary switch. Would force user to "lock out" to turn off. That way, the risk of forgetting to lock out is significantly reduced.

I wouldn't mind posting it as-is, just that it hasn't been tested in a light yet, so thought I'd wait, but of course, couldn't get to it as soon as I hoped.

It's here, ZIP'ed: Google Drive shared folder, file called: Let me know if you can access/dnld it ok.

Well, then it would work like a L4 (I believe), and that's what I was trying to avoid. My goal was full functionality from the side switch. If you can't turn it off from the side switch, it's not fully functional. I agree it would help from forgetting to lock out the light though - good point, but I would not want to sacrifice ON/OFF because of that.


Just installed it in my X6R. Swapped the 13A out for a 25V on the piggyback wight FET+1 driver, and it worked out pretty well - used a hot air gun, and the one I got doesn't target a part well, so other parts loosened up but didn't move around. Reflowing did the same thing. What I did was used solder wick to remove the old solder off the pad, then applied new solder paste - think it works out better this way.

Not sure what happened, but didn't find the fuse settings I used in previous testing (or messed them up??). I used these on the 25 and seems to work well:

-Ulfuse:w:0xE2:m -Uhfuse:w:0xDE:m -Uefuse:w:0xFE:m

Also, the brown-out NOINIT timing is a bit long. I would prefer it quicker - you have to have the light off for maybe 1-2 secs or so for it to keep the same mode.

Do you have an offtime capacitor on that? If so, make sure it isn’t charged, and the noinit thing might speed up. But then, if you have an OTC, it’s probably better to use that instead of noinit. :slight_smile:

True Smile. I think I'm using the OTC pad to solder the e-switch wire to. It was bugging me a few mins ago - couldn't recall if there's some setting brown out detection could work off of. Thought it worked better, maybe PCB design dependent - not sure.

Ohh - I set turbo timeout to 90 seconds and timed it on the bench with a TrustFire - was somewhere between 90 to 91 secs on my stopwatch - impressive! Wonder if it works more accurate configured at 8 Mhz. Only choices for internal clock is 6.4 Mhz and 8 Mhz, at least in the fuse setting app.

So, this was a 25V SSU (same package as a 13A) on a 17mm wight FET+1 driver. Didn't realize the X6R's tailcap switch is a fwd (tactical) clicky - works well, interesting...

Thank you Tom E for sharing your latest WIP. I as hoping to install and try it out this weekend but things came up. Hopefully, I will by the end of the week.

Ok, no prob. Couply of things for you and T_K (anyone else for that matter) on eswitch_NOINIT:

  • e-switch and power button share the same mode table, default is 5 modes with 1st 3 modes using the 7135
  • strobe is not accessible from the power switch - it's not in the table, special only for the e-switch
  • changing modes on the e-switch does not effect the stored mode, so the power switch saved mode is unaffected. I'm not sure if this is a good thing or bad thing, might be more confusing, but seems nice for some usages like tactical - you can program the power button to come up in Hi/turbo if you want, then change modes from the tail, and that will set a new default, including OFF. For now, I'm gonna leave it this way but not sure if this is the best. Might make a nice user configurable option.

I'm also thinking about more functionality, like using the long press to get strobe now, but treat is as an advanced mode set, so another long hold might be battery check, slow strobe, beacons, etc. A good thing I could do, for safety, is if the e-switch is permanently stuck, I could cycle thru the advanced modes and end it with OFF.

Exciting stuff Tom. You rock! I'll be happy to start helping work some more on the temp. sensor stuff, but it's got to wait until next week.

Tom, you keep putting things on my todo list. :slight_smile:

Have you ever tried using git/github or bzr/launchpad? They’re pretty helpful for tracking and generally dealing with code.

We use Git @work, but we have our own server repository. Been using github, but not for my own stuff. I know, really should... I gotta get better organized, overall. I'm off in way too many directions.