Skip to content

Commit

Permalink
V450 module code (#151)
Browse files Browse the repository at this point in the history
Support for tinyAVR2 style chips and V4.50 board design
  • Loading branch information
stuartpittaway authored Dec 9, 2022
1 parent 4d9e853 commit 96431d3
Show file tree
Hide file tree
Showing 16 changed files with 1,305 additions and 506 deletions.
29 changes: 24 additions & 5 deletions ATTINYCellModule/GenerateBinaryFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,40 @@ def generatejson(target, source, env):
data['avrprog'] = []

# Add other signatures as needed for different AVR chips
# Make sure you lowercase the comparison!
if str(env["BOARD_MCU"]).lower()=="attiny841":
signature="1e9315"

if str(env["BOARD_MCU"]).lower()=="attiny1614":
signature="1e9422"

if str(env["BOARD_MCU"]).lower()=="attiny1624":
signature="1e942a"

if (signature==""):
raise Exception("Unknown chip signature")

# Delete entry if it currently exists
for i in range(len(data['avrprog'])):
if data['avrprog'][i]['board'] == board:
del data['avrprog'][i]
break

efuse=hex(int(env.GetProjectOption("board_fuses.efuse"), 2)).upper()[2:4]
hfuse=hex(int(env.GetProjectOption("board_fuses.hfuse"), 2)).upper()[2:4]
lfuse=hex(int(env.GetProjectOption("board_fuses.lfuse"), 2)).upper()[2:4]
if str(env["BOARD_MCU"]).lower()=="attiny1624":
#Add the new entry
data['avrprog'].append({'board': board, 'name': newfilename, 'ver': env["git_sha_short"],'mcu':signature,'efuse':0,'hfuse':0,'lfuse':0})

if str(env["BOARD_MCU"]).lower()=="attiny824":
#Add the new entry
data['avrprog'].append({'board': board, 'name': newfilename, 'ver': env["git_sha_short"],'mcu':signature,'efuse':0,'hfuse':0,'lfuse':0})

if str(env["BOARD_MCU"]).lower()=="attiny841":
efuse=hex(int(env.GetProjectOption("board_fuses.efuse"), 2)).upper()[2:4]
hfuse=hex(int(env.GetProjectOption("board_fuses.hfuse"), 2)).upper()[2:4]
lfuse=hex(int(env.GetProjectOption("board_fuses.lfuse"), 2)).upper()[2:4]

#Add the new entry
data['avrprog'].append({'board': board, 'name': newfilename, 'ver': env["git_sha_short"],'mcu':signature,'efuse':efuse,'hfuse':hfuse,'lfuse':lfuse})
#Add the new entry
data['avrprog'].append({'board': board, 'name': newfilename, 'ver': env["git_sha_short"],'mcu':signature,'efuse':efuse,'hfuse':hfuse,'lfuse':lfuse})

with open(manifestjson, 'w') as outfile:
json.dump(data, outfile, indent=4, sort_keys=True)
Expand Down
22 changes: 14 additions & 8 deletions ATTINYCellModule/buildscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@

platform = env.PioPlatform()

#print(env)
#print(platform)

my_flags = env.ParseFlags(env['BUILD_FLAGS'])
#print(my_flags)
defines = {k: v for (k, v) in my_flags.get("CPPDEFINES")}
#print(my_flags)
#print(defines.get("DIYBMSMODULEVERSION"))

efuse=hex(int(env.GetProjectOption("board_fuses.efuse"), 2)).upper()[2:4]
hfuse=hex(int(env.GetProjectOption("board_fuses.hfuse"), 2)).upper()[2:4]
lfuse=hex(int(env.GetProjectOption("board_fuses.lfuse"), 2)).upper()[2:4]
if env.get("BOARD")=="attiny841":
#print(env)
#print(platform)
efuse=hex(int(env.GetProjectOption("board_fuses.efuse"), 2)).upper()[2:4]
hfuse=hex(int(env.GetProjectOption("board_fuses.hfuse"), 2)).upper()[2:4]
lfuse=hex(int(env.GetProjectOption("board_fuses.lfuse"), 2)).upper()[2:4]
env.Replace(PROGNAME="module_fw_%s_%s_%s%s_e%s_h%s_l%s" % (env["PIOENV"],env.get("BOARD"), defines.get("DIYBMSMODULEVERSION"), "_SWAPR19R20" if "SWAPR19R20" in defines else "", efuse, hfuse, lfuse ))


env.Replace(PROGNAME="module_fw_%s_%s_%s%s_e%s_h%s_l%s" % (env["PIOENV"],env.get("BOARD"), defines.get("DIYBMSMODULEVERSION"), "_SWAPR19R20" if "SWAPR19R20" in defines else "", efuse, hfuse, lfuse ))
if str(env["BOARD_MCU"]).lower()=="attiny1614" or str(env["BOARD_MCU"]).lower()=="attiny1624":
efuse=0
hfuse=0
lfuse=0
env.Replace(PROGNAME="module_fw_%s_%s_%s%s_e%s_h%s_l%s" % (env["PIOENV"],env.get("BOARD"), defines.get("DIYBMSMODULEVERSION"), "", efuse, hfuse, lfuse ))

6 changes: 2 additions & 4 deletions ATTINYCellModule/include/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,18 @@ Attribution-NonCommercial-ShareAlike 2.0 UK: England & Wales (CC BY-NC-SA 2.0 UK
#ifndef DIYBMS_DEFINES_H // include guard
#define DIYBMS_DEFINES_H


#if (!defined(DIYBMSMODULEVERSION))
#if !defined(DIYBMSMODULEVERSION)
#error You need to specify the DIYBMSMODULEVERSION define
#endif

#if defined(DIYBMSMODULEVERSION) && DIYBMSMODULEVERSION > 440
#if defined(DIYBMSMODULEVERSION) && DIYBMSMODULEVERSION > 450
#error Incorrect value for DIYBMSMODULEVERSION
#endif


//This is where the data begins in EEPROM
#define EEPROM_CONFIG_ADDRESS 0

#define nop __asm__("nop\n\t");


// Only the lowest 4 bits can be used!
Expand Down
Loading

0 comments on commit 96431d3

Please sign in to comment.