From 07116d93a009343081bb9c5b468e67f3b1a24f69 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Tue, 2 Apr 2024 23:43:03 +0200 Subject: [PATCH] Provide access to the fuse/lock bit configuration table Synthesize a Python list, consisting of the individual table entries as a dictionary. The dictionary, in turn, contains a table with the individual values. Quiet complex. --- src/libavrdude.i | 72 ++++++++++++++++++++++++++++++++++++++++++ src/python/swigtest.py | 2 ++ 2 files changed, 74 insertions(+) diff --git a/src/libavrdude.i b/src/libavrdude.i index 7eef7def..aa150f60 100644 --- a/src/libavrdude.i +++ b/src/libavrdude.i @@ -163,6 +163,73 @@ const char *ldata_string(LNODEID p) { return (const char *)ldata(p); } +PyObject *get_config_table(const char *name) { + int idx = upidxname(name); + if (idx == -1) + return Py_None; + + const uPcore_t *up = uP_table + idx; + int nitems = up->nconfigs; + + // found: construct a list object + PyObject *list = PyList_New(nitems); + + if (list == NULL) { + return NULL; + } + + // now, add list elements + const Configitem_t *cfg = up->cfgtable; + + for (int i = 0; i < nitems; i++) { + PyObject* dict = PyDict_New(); + if (dict == NULL) { + return NULL; + } + PyDict_SetItem(dict, PyUnicode_FromString("name"), + PyUnicode_FromString(cfg->name)); + int nvalues = cfg->nvalues; + PyObject *vlist = PyList_New(nvalues); + if (vlist == NULL) { + return NULL; + } + for (int j = 0; j < nvalues; j++) { + PyObject* vdict = PyDict_New(); + if (vdict == NULL) { + return NULL; + } + PyDict_SetItem(vdict, PyUnicode_FromString("value"), + PyLong_FromLong(cfg->vlist[j].value)); + PyDict_SetItem(vdict, PyUnicode_FromString("label"), + PyUnicode_FromString(cfg->vlist[j].label)); + PyDict_SetItem(vdict, PyUnicode_FromString("vcomment"), + PyUnicode_FromString(cfg->vlist[j].vcomment)); + + PyList_SetItem(vlist, j, vdict); + } + PyDict_SetItem(dict, PyUnicode_FromString("vlist"), + vlist); + PyDict_SetItem(dict, PyUnicode_FromString("memstr"), + PyUnicode_FromString(cfg->memstr)); + PyDict_SetItem(dict, PyUnicode_FromString("memoffset"), + PyLong_FromLong(cfg->memoffset)); + PyDict_SetItem(dict, PyUnicode_FromString("mask"), + PyLong_FromLong(cfg->mask)); + PyDict_SetItem(dict, PyUnicode_FromString("lsh"), + PyLong_FromLong(cfg->lsh)); + PyDict_SetItem(dict, PyUnicode_FromString("initval"), + PyLong_FromLong(cfg->initval)); + PyDict_SetItem(dict, PyUnicode_FromString("ccomment"), + PyUnicode_FromString(cfg->ccomment)); + + PyList_SetItem(list, i, dict); + + cfg++; + } + + return list; +} + %} // globals from above are mapped to Python @@ -638,4 +705,9 @@ int fileio_fmt_autodetect(const char *fname); int fileio(int oprwv, const char *filename, FILEFMT format, const AVRPART *p, const char *memstr, int size); +// avrintel stuff - configuration values for various AVRs + +%feature("autodoc", "get_config_table(name: str) -> list") get_config_table; +PyObject *get_config_table(const char *name); + %feature("autodoc", "1"); diff --git a/src/python/swigtest.py b/src/python/swigtest.py index 9366d7ef..4b40e0c6 100644 --- a/src/python/swigtest.py +++ b/src/python/swigtest.py @@ -23,6 +23,8 @@ # ad.fileio(ad.FIO_WRITE, "test.hex", ad.fileio_format("i"), p, "flash", -1) +# cfg=ad.get_config_table('atmega128') + # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or