Skip to content
Snippets Groups Projects
Verified Commit fc1aab68 authored by Jakub Vaněk's avatar Jakub Vaněk
Browse files

Automate updating of firmware version strings

parent caebafb8
No related branches found
No related tags found
1 merge request!14Automate updating of firmware version strings
Pipeline #109890 passed
......@@ -5,7 +5,9 @@ Constants for easier acces to the cube hardware components, sensors and motors
from micropython import const
from lib.hw_defs.pins import ICM_IRQ_PIN
from brick_ll import FW_DATE as FW_VERSION
from brick_ll import FW_COMMIT
class Sensor:
NO_SENSOR: Sensor = const(0)
NXT: Sensor = const(1)
......@@ -38,7 +40,7 @@ class Port:
S3: Port = const(2)
S4: Port = const(3)
S_COUNT: Port = const(4)
class Button:
POWER: Button = const(0)
LEFT: Button = const(1)
......@@ -87,5 +89,3 @@ I2C_MULTICUBE_FREQ = const(100000)
ESP_BAUDRATE = const(115200) # bps
ESP32_COMMAND_PIN = const(8)
FW_VERSION = "6.11.2024" # Firmware version
\ No newline at end of file
#include <py/runtime.h>
#include <py/objstr.h>
#include "i2c_locking.h"
#include "battery.h"
#include "ICM_api.h"
#include "buttons.h"
#include "led.h"
#include "opencube_fw_version.h"
STATIC mp_obj_t i2c_lock_fun(void) {
opencube_lock_i2c_or_raise();
......@@ -16,6 +18,9 @@ STATIC mp_obj_t i2c_unlock_fun(void) {
MP_DEFINE_CONST_FUN_OBJ_0(i2c_lock_fun_obj, i2c_lock_fun);
MP_DEFINE_CONST_FUN_OBJ_0(i2c_unlock_fun_obj, i2c_unlock_fun);
MP_DEFINE_STR_OBJ(fw_date, OPENCUBE_FW_DATE);
MP_DEFINE_STR_OBJ(fw_commit, OPENCUBE_FW_COMMIT);
static const mp_rom_map_elem_t brick_globals_dict[] = {
{MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_bricks_ll)},
{MP_ROM_QSTR(MP_QSTR_Battery), MP_ROM_PTR(&opencube_battery_type)},
......@@ -25,6 +30,8 @@ static const mp_rom_map_elem_t brick_globals_dict[] = {
{MP_ROM_QSTR(MP_QSTR_lock_i2c), MP_ROM_PTR(&i2c_lock_fun_obj)},
{MP_ROM_QSTR(MP_QSTR_unlock_i2c), MP_ROM_PTR(&i2c_unlock_fun_obj)},
{MP_ROM_QSTR(MP_QSTR_InternalI2CBusyError), MP_ROM_PTR(&mp_type_InternalI2CBusyError)},
{MP_ROM_QSTR(MP_QSTR_FW_DATE), MP_ROM_PTR(&fw_date)},
{MP_ROM_QSTR(MP_QSTR_FW_COMMIT), MP_ROM_PTR(&fw_commit)},
};
MP_DEFINE_CONST_DICT(brick_globals_dict_obj, brick_globals_dict);
......
#!/usr/bin/env python3
import sys
import subprocess
import datetime
import os
def main():
if len(sys.argv) != 2:
print(f"Usage: {sys.argv[0]} <header path>", file=sys.stderr)
sys.exit(1)
header_path = sys.argv[1]
now = datetime.datetime.now()
date = now.strftime("%d.%m.%Y")
commit = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode().strip()
header_content = f"""#ifndef OPENCUBE_FW_VERSION_H
#define OPENCUBE_FW_VERSION_H
#define OPENCUBE_FW_DATE "{date}"
#define OPENCUBE_FW_COMMIT "{commit}"
#endif // OPENCUBE_FW_VERSION_H
"""
if os.path.exists(header_path):
with open(header_path, "r") as fp:
existing_header_content = fp.read()
if existing_header_content == header_content:
return
with open(header_path, "w") as fp:
fp.write(header_content)
if __name__ == '__main__':
main()
......@@ -12,11 +12,13 @@ target_sources(usermod_opencube_brick INTERFACE
${CMAKE_CURRENT_LIST_DIR}/led.c
${CMAKE_CURRENT_LIST_DIR}/led.h
${CMAKE_CURRENT_LIST_DIR}/brick_api.c
${CMAKE_CURRENT_BINARY_DIR}/opencube_brick_generated/opencube_fw_version.h
)
# Add the current directory as an include directory.
target_include_directories(usermod_opencube_brick INTERFACE
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_BINARY_DIR}/opencube_brick_generated
)
target_link_libraries(usermod_opencube_brick INTERFACE
......@@ -25,4 +27,12 @@ target_link_libraries(usermod_opencube_brick INTERFACE
)
# Link our INTERFACE library to the usermod target.
target_link_libraries(usermod INTERFACE usermod_opencube_brick)
\ No newline at end of file
target_link_libraries(usermod INTERFACE usermod_opencube_brick)
add_custom_target(opencube_fw_version
COMMENT "Generating version header"
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/opencube_brick_generated
COMMAND python3 ${CMAKE_CURRENT_LIST_DIR}/generate_info.py ${CMAKE_CURRENT_BINARY_DIR}/opencube_brick_generated/opencube_fw_version.h
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/opencube_brick_generated/opencube_fw_version.h
)
......@@ -133,3 +133,14 @@ def unlock_i2c():
Unlock the I2C bus.
"""
pass
FW_DATE: str
'''
Build date of the OpenCube firmware
'''
FW_COMMIT: str
'''
Commit from which the OpenCube firmware was built
'''
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment