Flashlight Firmware Repository

It turns if you remove the code pertaining to switching to the 2nd mode group, you can get the code down to 830 bytes, a 174 byte reduction! Finally, I can squeeze in some extra blinky modes to BLF-A6 for an egg timer and SOS mode.

I was wondering how I could share this modified code in the repository. Do I post the code on the forum somewhere or upload straight on Launchpad (made a Launchpad account, but still not sure how to upload)?

TK - pretty cool technique for random # generator, and sure does make it compact, as long as those 256 bytes contains code, which it does.

It’s funny you mention that. In the blf-a6 directory, there’s a file called tk-otc.c which is specifically created for people who want to exchange the runtime config options for extra space. :slight_smile: I think I may have forgotten to apply some recent blf-a6 changes to tk-otc though, so its code may be a little behind.

If you’d like to upload to Launchpad, that’s easiest for me. But you can also just post the code somewhere and I can add it. The Launchpad method is done using bzr’s “push” command. For example: bzr push lp:~myaccount/flashlight-firmware/my-branch

After that, either create a merge proposal or tell me that there’s a branch waiting. :slight_smile:

Update: I merged the pending blf-a6 updates into tk-otc. The resulting build sizes are 1002 bytes versus 706 bytes. So, almost 300 bytes saved for others to fill with custom code. :slight_smile: I also made a stable maintenance branch for blf-a6, so it can get bugfixes without having to pull in the entire refactoring project I started:
https://code.launchpad.net/~toykeeper/flashlight-firmware/blf-a6-final

Is there a list of OTC and voltage sense calibrations for different drivers? Maybe it could be done with #if’s like you have done for the attiny 25 code.

Yes, though I’ve currently got those measurements in the middle of a re-organization of sorts. It’s moving from a single file for all measurements to an individual file per driver per calibration type.

Check battcheck/readings.txt, battcheck/otc-readings.txt, and battcheck/readings/* to see values from existing drivers.

The mechanism being used at the moment is to #include “…/tk-calibration.h” for all this stuff, so you can edit that single file and have it apply to everything you build from then on. The detailed voltage values there can be generated by battcheck.py; you don’t have to measure every exact value in the list; just one high value and one low value, and the script will calculate the rest.

(BTW, I don’t like putting “tk-” at the beginning of each include, but C doesn’t really have namespaces and I don’t want to run into naming collisions, so I prefixed a namespace-like identifier)

Thanks, I never did run battcheck and set the ADC levels when I put your cypreus2 code into my AX6, and it looks like the values are way off where they should be, in the dangerous direction.

Hi, anyone can help me what is the problem with my attiny13a. It’s a second batch of attiny13a that i bought from ebay, 10 pcs. The first batch that i bought earlier this year from the same seller all works well but this 2nd batch all 10 gives an error when i try to use this command avrdude -p t13 -c usbasp -n

avrdude: error: programm enable: target doesn’t answer. 1
avrdude: initialization failed, rc=–1
Double check connections and try again, or use -F to override
this check.

I checked the connections and they are properly connected. To be sure that my usbasp is not the problem I programmed again attiny13a from the 1st batch and they work well.
What is the problem with the 2nd batch of attiny13a that i bought, are they all dead?

They could have spi or reset disabled or be counterfeit chips.

How do i enable reset or spi?
If it’s counterfeit then here is where i bought it http://www.ebay.com/itm/10PCS-NEW-SOP-8-ATTINY13A-SU-TINY13A-SU-SMD-IC-/381375008462 to warn others not to buy from this ebay seller survy2014. But i did not see any negative feedback for this item on his feedback section. He has already sold 56 10pcs of this and i did not see any negative feedback.

A high voltage programmer or fuse doctor / fuse reseter would be needed to fix reset, spi. But new genuine chips will come with it all be enabled and ready to flash.

Did you ever, even once, get a different error (without “target doesn’t answer”) from those 10 chips?

No, always the same error
avrdude: error: programm enable: target doesn’t answer. 1
avrdude: initialization failed, rc=–1 Double check connections and try again, or use -F to override this check.

Sounds like the same exact problem I had from an eBay seller: polida2008. These chips are probably pre-programmed left over inventory with the reset disabled - probably why they are so cheap. Not that they were ever used, as mounted on a board, but they were programmed for a certain application. Richard at MtnE has the package: Atmel's AVR Dragon, that will disable that, and make them programmable once again. Can't be sure that's your problem but sounds that way.

I didn’t even realise that tk-otc was the single mode group version of BLF-A6, having never looked at it. Somehow you’ve managed to squeeze out another 120 bytes!

I’m not too familiar with bzr and Launchpad, so I’ve posted the code here instead.
This version has:
config_star code removed (before I discovered it was not really necessary)
Single mode group with 6 modes
Memory selection by 16 clicks
20s turbo timeout

Hidden modes

  • Strobe
  • Turbo
  • Biking strobe
  • Battery check (10% steps with ADC values measured from my Attiny13A and % to voltage conversion from HKJ’s tests for the efest 10440)
  • SOS mode
  • Egg timer

Thanks. I added that to the blf-a6-final branch, since it appears to be based on that code. The main/trunk branch has done some refactoring to move common code into shared headers, so this mod might not build quite right there. In any case, it’s online here now:

http://bazaar.launchpad.net/~toykeeper/flashlight-firmware/blf-a6-final/files/head:/ToyKeeper/blf-a6/testedandbaked/

Thanks TK!

I have a question, how do you disable the output on pin 6 of attiny13a in blf a6 firmware. The reason i want to disable the pin 6 is i am only using the pin 5 for output on one 7135 and no connection on pin 6 (no FET or 7135). But the problem is i am getting an occasional blinking when going from high mode to moon mode or even after turning on the light where it goes to moon initially. Maybe the reason i am getting the blink is because the pin 6 is not disabled? So how can i disable it in the firmware?

    DDRB |= (1 << PWM_PIN);     // enable main channel
    DDRB |= (1 << ALT_PWM_PIN); // enable second channel

delete the first line

Thanks, i’ll try that.

Edit: I already deleted that line. There is still blinking between the transition from high to moon mode and also whenever i turn on the light. Maybe i have a bad attiny13a or 7135?

I have a question what code would I need to make a 0805 LED blink on pin 3 while the light was off say once every 5 seconds for example?

I can make it turn on with:

DDRB = (1 << PWM_PIN) | (1 << RED_PIN);
PORTB |= (1 << RED_PIN);



P.S. e-switch driver

The pre-flash is more of a hardware issue. It shows up on some drivers but not others. I’m not sure why, but no code changes I could think of had any effect on it.